Servertalk implementation wip, added optional support for pub-key authenticated encryption (via libsodium), not backwards compatible.

This commit is contained in:
KimLS
2016-10-23 17:55:19 -07:00
parent e29ca88a76
commit 1d1df3bf7a
25 changed files with 822 additions and 449 deletions
+51
View File
@@ -0,0 +1,51 @@
#pragma once
#include "tcp_connection.h"
#include "servertalk_common.h"
#include "packet.h"
#include <vector>
#include <sodium.h>
namespace EQ
{
namespace Net
{
class ServertalkServer;
class ServertalkServerConnection
{
public:
ServertalkServerConnection(std::shared_ptr<EQ::Net::TCPConnection> c, ServertalkServer *parent, bool encrypted);
~ServertalkServerConnection();
std::string GetIdentifier() const {
return m_identifier;
}
private:
void OnRead(TCPConnection* c, const unsigned char* data, size_t sz);
void ProcessReadBuffer();
void OnDisconnect(TCPConnection* c);
void SendHello();
void InternalSend(ServertalkPacketType type, EQ::Net::Packet &p);
void ProcessHandshake(EQ::Net::Packet &p);
void ProcessMessage(EQ::Net::Packet &p);
std::shared_ptr<EQ::Net::TCPConnection> m_connection;
ServertalkServer *m_parent;
std::vector<char> m_buffer;
std::string m_identifier;
bool m_encrypted;
#ifdef ENABLE_SECURITY
unsigned char m_public_key_ours[crypto_box_PUBLICKEYBYTES];
unsigned char m_private_key_ours[crypto_box_SECRETKEYBYTES];
unsigned char m_nonce_ours[crypto_box_NONCEBYTES];
unsigned char m_public_key_theirs[crypto_box_PUBLICKEYBYTES];
unsigned char m_nonce_theirs[crypto_box_NONCEBYTES];
unsigned char m_shared_key[crypto_box_BEFORENMBYTES];
#endif
};
}
}