2015-02-05 16:36:25 +00:00
|
|
|
#include <sys/epoll.h>
|
|
|
|
|
|
2015-02-05 12:55:48 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
class CryptoBase {
|
|
|
|
|
public:
|
2015-02-05 16:36:25 +00:00
|
|
|
CryptoBase(const int fd);
|
|
|
|
|
virtual ~CryptoBase();
|
|
|
|
|
|
2015-02-05 13:02:42 +00:00
|
|
|
static void GenKey(std::string* key);
|
|
|
|
|
static void GenKeyPair(std::string* secret_key, std::string* public_key);
|
2015-02-05 20:57:01 +00:00
|
|
|
virtual void OnReadable() = 0;
|
2015-02-05 16:36:25 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
const int fd_;
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-05 20:57:01 +00:00
|
|
|
class CryptoPubServerConnection : public CryptoBase {
|
2015-02-05 16:36:25 +00:00
|
|
|
public:
|
2015-02-05 20:57:01 +00:00
|
|
|
CryptoPubServerConnection(const int fd, const std::string secret_key);
|
|
|
|
|
void OnReadable();
|
2015-02-05 16:36:25 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const std::string secret_key_;
|
|
|
|
|
const std::string ephemeral_secret_key_;
|
2015-02-05 21:57:04 +00:00
|
|
|
const std::string client_public_key_;
|
|
|
|
|
enum {
|
|
|
|
|
AWAITING_HANDSHAKE,
|
|
|
|
|
READY,
|
|
|
|
|
} state_;
|
2015-02-05 16:36:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CryptoPubServer : public CryptoBase {
|
|
|
|
|
public:
|
|
|
|
|
CryptoPubServer(const int fd, const std::string secret_key);
|
|
|
|
|
~CryptoPubServer();
|
2015-02-05 20:57:01 +00:00
|
|
|
void OnReadable();
|
2015-02-05 16:36:25 +00:00
|
|
|
void Loop();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const std::string secret_key_;
|
|
|
|
|
const int epoll_fd_;
|
2015-02-05 12:55:48 +00:00
|
|
|
};
|