sessionworker.hh 5.09 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
  void authenticatePrompts(QStringList responses);

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

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

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

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