SVCS - Русская документация
Загрузка...
Поиск...
Не найдено
SSHSession.hxx
См. документацию.
1
15#pragma once
16
17#if defined(__GNUC__)
18#pragma GCC diagnostic push
19#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20#endif
21
22#include "SSHConfig.hxx"
24#include <libssh/libssh.h>
25#include <libssh/server.h>
26#include <memory>
27#include <string>
28#include <functional>
29#include <chrono>
30
31namespace svcs::server::ssh {
32
44class SSHSession {
45public:
59 using CommandHandler = std::function<bool(const std::string&, ssh_channel)>;
60
74 SSHSession(ssh_session session,
75 const SSHConfig& config,
76 CommandHandler handler);
77
85 ~SSHSession();
86
87 // Запрещаем копирование
88 SSHSession(const SSHSession&) = delete;
89 SSHSession& operator=(const SSHSession&) = delete;
90
91 // Разрешаем перемещение
92 SSHSession(SSHSession&& other) noexcept;
93 SSHSession& operator=(SSHSession&& other) noexcept;
94
104 bool process();
105
115 bool isAlive() const;
116
126 std::string getUsername() const { return username_; }
127
137 std::string getClientIp() const;
138
148 std::chrono::system_clock::time_point getStartTime() const { return start_time_; }
149
157 void close();
158
159private:
160 bool authenticate();
161 bool handleCommand();
162 bool validatePublicKey(ssh_key key);
163 bool validatePassword(const std::string& username, const std::string& password);
164 std::vector<std::string> loadAuthorizedKeys(const std::string& username) const;
165 std::string getPasswordHash(const std::string& username) const;
166
167private:
168 ssh_session session_;
169 SSHConfig config_;
170 CommandHandler handler_;
171 std::string username_;
172 bool authenticated_ = false;
173 std::chrono::system_clock::time_point start_time_;
174 bool owns_session_ = true;
175};
176
177}
178
179#if defined(__GNUC__)
180#pragma GCC diagnostic pop
181#endif
Cross-platform network utilities.
Конфигурация SSH сервера