sessioncontroller.hh 6.73 KB
Newer Older
1
2
3
4
5
6
#ifndef RSM_RSMCORE_SESSIONCONTROLLER_HH_
#define RSM_RSMCORE_SESSIONCONTROLLER_HH_

#include <QObject>

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

9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace rsm
{
/** Forward declaration of private implementation */
class SessionControllerImpl;
class RSM_PUBLIC SessionController : public QObject
{
  Q_OBJECT
 private:
  // Private implementation
  SessionControllerImpl* p;

 public:
  SessionController(QObject* parent = nullptr);
  ~SessionController();
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

  QByteArray readExecOutput();
 public slots:

  /**
   * Set the remote host to connect to
   */
  void setHost(QString host);
  /**
   * Set the Log verbosity
   */
  void setLogVerbosity(SessionVerbosity level);
  /**
   * Set the ssh port number
   */
  void setPort(int port);
  /**
   * Set the user
   * Defaults to system user
   */
  void setUser(QString name);
  /**
   * Perform hand-shake to connect to host.
   */
  void connect();
  /**
   * Disconnect ssh session
   */
  void disconnect();
  /**
   * 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().
   */
  void verifyKnownHost();
  /**
   * Performs a request to accept/save the host's public key,
   * updating the known_hosts
   */
  void acceptHostPublicKeyUpdate();
  /**
   * Attempts to authenticate using public key or password.
   * Can emit authenticationError(QString message).
   * Can emit authenticationSucceeded() upon acceptance of public key.
   * Can emit passworedRequested().
   */
  void authenticate();
  /**
   * 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.
   */
  void authenticateWithPassword(QString pswd);

81
82
  void authenticatePrompts(QStringList responses);

83
84
85
86
87
88
89
90
91
92
  /**
   * Requests remote execution of command
   * @param command - QString command to execute
   */
  void requestExec(QString command);

 signals:

  void connectionFailed(QString message);
  void connectionSuccessful();
93
  void disconnectSuccessful();
94
  void verifyKnownHostSuccessful();
95
96
97

  void interactiveAuthenticationRequested(QString instruction, QString name,
                                          QStringList prompts);
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  /**
   * @brief getServerPublicKeyFailed
   * Signal is emitted when the remote host does not have or provide a public
   * key. Recommended to disconnect from session
   */
  void getServerPublicKeyFailed();
  /**
   * @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
   */
  void hostUnknown(QString host_hash);
  /**
   * @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
   */
  void hostPublicKeyChanged(QString host_hash);
  /**
   * @brief hostPublicKeyUnavailable
   * Signal is emitted when the remote host does not have a public key.
   * Recommended to disconnect from session.
   */
  void hostPublicKeyUnavailable();
  /**
   * @brief knownHostError
   * This signal is emitted when an unknown error occurs retrieving known_hosts.
   * @param message
   */
  void knownHostError(QString message);
  /**
   * @brief updateKnownHostsFailed
   * Signal is emitted upon accepting public key update that fails to update
   * client known_hosts.
   */
  void updateKnownHostsFailed();
  /**
   * @brief authenticationError
   * Signal is emitted when the user's authentication method password/pubkey
   * fails.
   * @param message
   */
  void authenticationError(QString message);
  /**
   * @brief authenticationSucceeded
   * Signal is emitted indicating successful authentication again remote host.
   */
  void authenticationSucceeded();
  /**
   * @brief passwordRequested
   * Signal is emitted when public key authentication fails and password is
   * asked for. Recommend  prompt user for password and
   * authenticateWithPassword().
   */
  void passwordRequested();
  /**
   * @brief loginBannerIssued
   * Signal is emitted after authentication has succeeded and if a banner is
   * available on the remote host.
   * @param message
   */
  void loginBannerIssued(QString message);
  /**
   * @brief execOutputReady
   * Signal is emitted if a requestExec was performed with standard output.
   */
  void execOutputReady();
  /**
   * @brief execFailed
   * Signal is emitted if requestExec fails in someway.
   * @param message
   */
  void execFailed(QString message);
  /**
   * @brief execFinished
   * Signal is emitted when requestExec() has completed.
   */
  void execFinished();

  /**
   * Set the remote host to connect to
   */
  void setHostRequested(QString host);
  /**
   * Set the Log verbosity
   */
  void setLogVerbosityRequested(SessionVerbosity level);
  /**
   * Set the ssh port number
   */
  void setPortRequested(int port);
  /**
   * Set the user
   * Defaults to system user
   */
  void setUserRequested(QString name);
  /**
   * Perform hand-shake to connect to host.
   */
  void connectRequested();
  /**
   * Disconnect ssh session
   */
  void disconnectRequested();
  /**
   * 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().
   */
  void verifyKnownHostRequested();
  /**
   * Performs a request to accept/save the host's public key,
   * updating the known_hosts
   */
  void acceptHostPublicKeyUpdateRequested();
  /**
   * Attempts to authenticate using public key or password.
   * Can emit authenticationError(QString message).
   * Can emit authenticationSucceeded() upon acceptance of public key.
   * Can emit passworedRequested().
   */
  void authenticateRequested();
  /**
   * 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.
   */
  void authenticateWithPasswordRequested(QString pswd);

234
235
  void authenticatePromptsRequested(QStringList responses);

236
237
238
239
240
  /**
   * Requests remote execution of command
   * @param command - QString command to execute
   */
  void requestExecRequested(QString command);
241
242
243
244
245
};  // class SessionController

}  // namespace rsm

#endif /* RSM_RSMCORE_SESSIONCONTROLLER_HH_ */