sessionworker.hh 4.87 KB
Newer Older
1
2
3
4
5
6
#ifndef RSM_RSMCORE_SESSIONWORKER_HH_
#define RSM_RSMCORE_SESSIONWORKER_HH_

#include <QObject>

#include "rsmcore/declspec.hh"
7
#include "rsmcore/sessionlog.hh"
8
9
10

namespace rsm
{
11
/** Forward declaration of private implementation */
12
13
14
15
16
17
18
19
20
class SessionWorkerImpl;
class RSM_PUBLIC SessionWorker : public QObject
{
  Q_OBJECT
 private:
  // Private implementation
  SessionWorkerImpl* p;

 public:
21
22
23
  /**
   * Basic Constructor
   */
24
  SessionWorker(QObject* parent = nullptr);
25
26
27
  /**
   * Contructs with host name
   */
28
29
  SessionWorker(QString host, QObject* parent = nullptr);
  ~SessionWorker();
30
  QByteArray readExecOutput();
31
32

 public slots:
33
34
35
36

  /**
   * Set the remote host to connect to
   */
37
  void setHost(QString host);
38
39
40
  /**
   * Set the Log verbosity
   */
41
  void setLogVerbosity(SessionVerbosity level);
42
43
44
  /**
   * Set the ssh port number
   */
45
  void setPort(int port);
46
47
48
49
  /**
   * Set the user
   * Defaults to system user
   */
50
  void setUser(QString name);
51
52
53
  /**
   * Perform hand-shake to connect to host.
   */
54
  void connect();
55
56
57
  /**
   * Disconnect ssh session
   */
58
  void disconnect();
59
60
61
62
63
64
65
66
  /**
   * Perform known host verification.
   * Checks known_host file to validate remote host SHA
   * Can emit hostUnknown(QString host_hash).
   * Can emit hostPublicKeyChanged(QString host_hash).
   * Can emit hostPublicKeyUnavailable().
   * Can emit knownHostError().
   */
67
  void verifyKnownHost();
68
69
70
71
  /**
   * Performs a request to accept/save the host's public key,
   * updating the known_hosts
   */
72
  void acceptHostPublicKeyUpdate();
73
74
75
76
77
78
  /**
   * Attempts to authenticate using public key or password.
   * Can emit authenticationError(QString message).
   * Can emit authenticationSucceeded() upon acceptance of public key.
   * Can emit passworedRequested().
   */
79
  void authenticate();
80
81
82
83
84
85
  /**
   * Attempts to authenticate with username and password.
   * Can emit authenticationError(QString message).
   * Can emit authenticationSuccessed() upon acceptance of password.
   * Can emit loginBannerIssued(QString message) give availability.
   */
86
87
  void authenticateWithPassword(QString pswd);

88
89
90
91
92
93
  /**
   * Requests remote execution of command
   * @param command - QString command to execute
   */
  void requestExec(QString command);

94
 signals:
95
96
97
  void connectionFailed(QString message);
  void connectionSuccessful();
  void verifyKnownHostSuccessful();
98
99
100
101
102
  /**
   * @brief getServerPublicKeyFailed
   * Signal is emitted when the remote host does not have or provide a public
   * key. Recommended to disconnect from session
   */
103
  void getServerPublicKeyFailed();
104
105
106
107
108
109
  /**
   * @brief hostUnknown
   * Signal is emitted when the remote host's public key is not in known_hosts
   * on this client. Recommend prompt for user action/acceptance of host.
   * @param host_hash
   */
110
  void hostUnknown(QString host_hash);
111
112
113
114
115
116
117
  /**
   * @brief hostPublicKeyChanged
   * Signal is emitted when the host is known, but the key differs from that in
   * known_hosts. This could be a man-in-the-middle attack. Recommended
   * disconnect from session.
   * @param host_hash
   */
118
  void hostPublicKeyChanged(QString host_hash);
119
120
121
122
123
  /**
   * @brief hostPublicKeyUnavailable
   * Signal is emitted when the remote host does not have a public key.
   * Recommended to disconnect from session.
   */
124
  void hostPublicKeyUnavailable();
125
126
127
128
129
  /**
   * @brief knownHostError
   * This signal is emitted when an unknown error occurs retrieving known_hosts.
   * @param message
   */
130
  void knownHostError(QString message);
131
132
133
134
135
  /**
   * @brief updateKnownHostsFailed
   * Signal is emitted upon accepting public key update that fails to update
   * client known_hosts.
   */
136
  void updateKnownHostsFailed();
137
138
139
140
141
142
  /**
   * @brief authenticationError
   * Signal is emitted when the user's authentication method password/pubkey
   * fails.
   * @param message
   */
143
  void authenticationError(QString message);
144
145
146
147
  /**
   * @brief authenticationSucceeded
   * Signal is emitted indicating successful authentication again remote host.
   */
148
  void authenticationSucceeded();
149
150
151
152
153
154
  /**
   * @brief passwordRequested
   * Signal is emitted when public key authentication fails and password is
   * asked for. Recommend  prompt user for password and
   * authenticateWithPassword().
   */
155
  void passwordRequested();
156
157
158
159
160
161
  /**
   * @brief loginBannerIssued
   * Signal is emitted after authentication has succeeded and if a banner is
   * available on the remote host.
   * @param message
   */
162
  void loginBannerIssued(QString message);
163
164
165
166
  /**
   * @brief execOutputReady
   * Signal is emitted if a requestExec was performed with standard output.
   */
167
  void execOutputReady();
168
169
170
171
172
  /**
   * @brief execFailed
   * Signal is emitted if requestExec fails in someway.
   * @param message
   */
173
  void execFailed(QString message);
174
175
176
177
  /**
   * @brief execFinished
   * Signal is emitted when requestExec() has completed.
   */
178
  void execFinished();
179
180
181
182

};  // class SessionWorker
}  // namespace rsm
#endif /* RSM_RSMCORE_SESSIONWORKER_HH_*/