#ifndef RSM_RSMCORE_SESSIONWORKER_HH_ #define RSM_RSMCORE_SESSIONWORKER_HH_ #include #include "rsmcore/declspec.hh" namespace rsm { /** Forward declaration of private implementation */ class SessionWorkerImpl; class RSM_PUBLIC SessionWorker : public QObject { Q_OBJECT private: // Private implementation SessionWorkerImpl* p; public: enum class Verbosity { None, Warning, Protocal, Packet, Functions }; /** * Basic Constructor */ SessionWorker(QObject* parent = nullptr); /** * Contructs with host name */ SessionWorker(QString host, QObject* parent = nullptr); ~SessionWorker(); QByteArray readExecOutput(); public slots: /** * Set the remote host to connect to */ void setHost(QString host); /** * Set the Log verbosity */ void setLogVerbosity(Verbosity 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); /** * Requests remote execution of command * @param command - QString command to execute */ void requestExec(QString command); signals: /** * @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(); }; // class SessionWorker } // namespace rsm #endif /* RSM_RSMCORE_SESSIONWORKER_HH_*/