From dcbc3d69286e123106f0c7398bfbfc3bf080aa3d Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Thu, 5 Feb 2015 21:57:04 +0000 Subject: [PATCH] Start of a connection state machine, start of a TLV framework. --- Makefile | 12 ++++++------ crypto.cc | 3 ++- crypto.h | 5 +++++ tlv.cc | 8 ++++++++ tlv.h | 18 ++++++++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tlv.cc create mode 100644 tlv.h diff --git a/Makefile b/Makefile index 5020223..e5fe7ab 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,11 @@ all: auth-server gen-key gen-keypair %.o: %.cc g++ -std=c++11 -c -o $@ $< -auth-server: auth-server.o crypto.o - g++ -o auth-server auth-server.o crypto.o nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a +auth-server: auth-server.o crypto.o tlv.o + g++ -o auth-server auth-server.o crypto.o tlv.o nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a -gen-key: gen-key.o crypto.o - g++ -o gen-key gen-key.o crypto.o nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a +gen-key: gen-key.o crypto.o tlv.o + g++ -o gen-key gen-key.o crypto.o tlv.o nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a -gen-keypair: gen-keypair.o crypto.o - g++ -o gen-keypair gen-keypair.o crypto.o nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a +gen-keypair: gen-keypair.o crypto.o tlv.o + g++ -o gen-keypair gen-keypair.o crypto.o tlv.o nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a diff --git a/crypto.cc b/crypto.cc index f39cb15..314dd7e 100644 --- a/crypto.cc +++ b/crypto.cc @@ -89,7 +89,8 @@ void CryptoPubServer::Loop() { CryptoPubServerConnection::CryptoPubServerConnection(const int fd, const std::string secret_key) : CryptoBase(fd), - secret_key_(secret_key) { + secret_key_(secret_key), + state_(AWAITING_HANDSHAKE) { } void CryptoPubServerConnection::OnReadable() { diff --git a/crypto.h b/crypto.h index 447a464..e3a50a4 100644 --- a/crypto.h +++ b/crypto.h @@ -23,6 +23,11 @@ class CryptoPubServerConnection : public CryptoBase { private: const std::string secret_key_; const std::string ephemeral_secret_key_; + const std::string client_public_key_; + enum { + AWAITING_HANDSHAKE, + READY, + } state_; }; class CryptoPubServer : public CryptoBase { diff --git a/tlv.cc b/tlv.cc new file mode 100644 index 0000000..44f5441 --- /dev/null +++ b/tlv.cc @@ -0,0 +1,8 @@ +#include "tlv.h" + +TLVNode::TLVNode(const uint16_t type) + : type_(type) {} + +TLVNode::TLVNode(const uint16_t type, const std::string value) + : type_(type), + value_(value) {} diff --git a/tlv.h b/tlv.h new file mode 100644 index 0000000..0da9304 --- /dev/null +++ b/tlv.h @@ -0,0 +1,18 @@ +#include + +#include +#include + +class TLVNode { + public: + TLVNode(const uint16_t type); + TLVNode(const uint16_t type, const std::string value); + + static TLVNode* Decode(const std::string& input); + void Encode(std::string *output); + + private: + const uint16_t type_; + const std::string value_; + std::list children_; +};