sessionworker.hh 5.12 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
class SessionWorkerImpl;
class RSM_PUBLIC SessionWorker : public QObject
{
  Q_OBJECT
 private:
  // Private implementation
  SessionWorkerImpl* p;

20
21
  void processPrompts();

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

 public slots:
35
36
37
38

  /**
   * Set the remote host to connect to
   */
39
  void setHost(QString host);
40
41
42
  /**
   * Set the Log verbosity
   */
43
  void setLogVerbosity(SessionVerbosity level);
44
45
46
  /**
   * Set the ssh port number
   */
47
  void setPort(int port);
48
49
50
51
  /**
   * Set the user
   * Defaults to system user
   */
52
  void setUser(QString name);
53
54
55
  /**
   * Perform hand-shake to connect to host.
   */
56
  void connect();
57
58
59
  /**
   * Disconnect ssh session
   */
60
  void disconnect();
61
62
63
64
65
66
67
68
  /**
   * 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().
   */
69
  void verifyKnownHost();
70
71
72
73
  /**
   * Performs a request to accept/save the host's public key,
   * updating the known_hosts
   */
74
  void acceptHostPublicKeyUpdate();
75
76
77
78
79
80
  /**
   * Attempts to authenticate using public key or password.
   * Can emit authenticationError(QString message).
   * Can emit authenticationSucceeded() upon acceptance of public key.
   * Can emit passworedRequested().
   */
81
  void authenticate();
82
83
84
85
86
87
  /**
   * 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.
   */
88
89
  void authenticateWithPassword(QString pswd);

90
91
  void authenticatePrompts(QStringList responses);

92
93
94
95
96
97
  /**
   * Requests remote execution of command
   * @param command - QString command to execute
   */
  void requestExec(QString command);

98
 signals:
99
100
  void connectionFailed(QString message);
  void connectionSuccessful();
101
  void disconnectSuccessful();
102
  void verifyKnownHostSuccessful();
103
104
105

  void interactiveAuthenticationRequested(QString instruction, QString name,
                                          QStringList prompts);
106
107
108
109
110
  /**
   * @brief getServerPublicKeyFailed
   * Signal is emitted when the remote host does not have or provide a public
   * key. Recommended to disconnect from session
   */
111
  void getServerPublicKeyFailed();
112
113
114
115
116
117
  /**
   * @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
   */
118
  void hostUnknown(QString host_hash);
119
120
121
122
123
124
125
  /**
   * @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
   */
126
  void hostPublicKeyChanged(QString host_hash);
127
128
129
130
131
  /**
   * @brief hostPublicKeyUnavailable
   * Signal is emitted when the remote host does not have a public key.
   * Recommended to disconnect from session.
   */
132
  void hostPublicKeyUnavailable();
133
134
135
136
137
  /**
   * @brief knownHostError
   * This signal is emitted when an unknown error occurs retrieving known_hosts.
   * @param message
   */
138
  void knownHostError(QString message);
139
140
141
142
143
  /**
   * @brief updateKnownHostsFailed
   * Signal is emitted upon accepting public key update that fails to update
   * client known_hosts.
   */
144
  void updateKnownHostsFailed();
145
146
147
148
149
150
  /**
   * @brief authenticationError
   * Signal is emitted when the user's authentication method password/pubkey
   * fails.
   * @param message
   */
151
  void authenticationError(QString message);
152
153
154
155
  /**
   * @brief authenticationSucceeded
   * Signal is emitted indicating successful authentication again remote host.
   */
156
  void authenticationSucceeded();
157
158
159
160
161
162
  /**
   * @brief passwordRequested
   * Signal is emitted when public key authentication fails and password is
   * asked for. Recommend  prompt user for password and
   * authenticateWithPassword().
   */
163
  void passwordRequested();
164
165
166
167
168
169
  /**
   * @brief loginBannerIssued
   * Signal is emitted after authentication has succeeded and if a banner is
   * available on the remote host.
   * @param message
   */
170
  void loginBannerIssued(QString message);
171
172
173
174
  /**
   * @brief execOutputReady
   * Signal is emitted if a requestExec was performed with standard output.
   */
175
  void execOutputReady();
176
177
178
179
180
  /**
   * @brief execFailed
   * Signal is emitted if requestExec fails in someway.
   * @param message
   */
181
  void execFailed(QString message);
182
183
184
185
  /**
   * @brief execFinished
   * Signal is emitted when requestExec() has completed.
   */
186
  void execFinished();
187
188
189
190

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