sessionworker.hh 4.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
#ifndef RSM_RSMCORE_SESSIONWORKER_HH_
#define RSM_RSMCORE_SESSIONWORKER_HH_

#include <QObject>

#include "rsmcore/declspec.hh"

namespace rsm
{
10
/** Forward declaration of private implementation */
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class SessionWorkerImpl;
class RSM_PUBLIC SessionWorker : public QObject
{
  Q_OBJECT
 private:
  // Private implementation
  SessionWorkerImpl* p;

 public:
  enum class Verbosity
  {
    None,
    Warning,
    Protocal,
    Packet,
    Functions
  };

29
30
31
  /**
   * Basic Constructor
   */
32
  SessionWorker(QObject* parent = nullptr);
33
34
35
  /**
   * Contructs with host name
   */
36
37
  SessionWorker(QString host, QObject* parent = nullptr);
  ~SessionWorker();
38
  QByteArray readExecOutput();
39
40

 public slots:
41
42
43
44

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

96
97
98
99
100
101
  /**
   * Requests remote execution of command
   * @param command - QString command to execute
   */
  void requestExec(QString command);

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

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