diff options
author | lloyd <[email protected]> | 2011-12-29 17:18:56 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-12-29 17:18:56 +0000 |
commit | b500ef1a58f977f5ce5869e7160615f7b44876e7 (patch) | |
tree | 025f3a6ee8b7da533178c2f7b3a351cb94750211 /src/tls/tls_extensions.h | |
parent | caa9dfa12cf69bb4ab88c399e61e856fedb24900 (diff) |
Add support for sending server name indicator in client hello
Add support for sending and reading the SRP identifier extension.
Add some helper classes for managing TLS extensions
Add ciphersuite codes for SRP key exchange.
Diffstat (limited to 'src/tls/tls_extensions.h')
-rw-r--r-- | src/tls/tls_extensions.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/tls/tls_extensions.h b/src/tls/tls_extensions.h new file mode 100644 index 000000000..01a4253b3 --- /dev/null +++ b/src/tls/tls_extensions.h @@ -0,0 +1,109 @@ +/* +* TLS Extensions +* (C) 2011 Jack Lloyd +* +* Released under the terms of the Botan license +*/ + +#ifndef BOTAN_TLS_EXTENSIONS_H__ +#define BOTAN_TLS_EXTENSIONS_H__ + +#include <botan/secmem.h> +#include <botan/tls_magic.h> +#include <vector> +#include <string> + +namespace Botan { + +class TLS_Data_Reader; + +/** +* Base class representing a TLS extension of some kind +*/ +class TLS_Extension + { + public: + virtual TLS_Handshake_Extension_Type type() const = 0; + virtual MemoryVector<byte> serialize() const = 0; + + virtual bool empty() const = 0; + + virtual ~TLS_Extension() {} + }; + +/** +* Server Name Indicator extension (RFC 3546) +*/ +class Server_Name_Indicator : public TLS_Extension + { + public: + TLS_Handshake_Extension_Type type() const + { return TLSEXT_SERVER_NAME_INDICATION; } + + Server_Name_Indicator(const std::string& host_name) : + sni_host_name(host_name) {} + + Server_Name_Indicator(TLS_Data_Reader& reader); + + std::string host_name() const { return sni_host_name; } + + MemoryVector<byte> serialize() const; + + bool empty() const { return sni_host_name == ""; } + private: + std::string sni_host_name; + }; + +/** +* SRP identifier extension (RFC 5054) +*/ +class SRP_Identifier : public TLS_Extension + { + public: + TLS_Handshake_Extension_Type type() const + { return TLSEXT_SRP_IDENTIFIER; } + + SRP_Identifier(const std::string& identifier) : + srp_identifier(identifier) {} + + SRP_Identifier(TLS_Data_Reader& reader); + + std::string identifier() const { return srp_identifier; } + + MemoryVector<byte> serialize() const; + + bool empty() const { return srp_identifier == ""; } + private: + std::string srp_identifier; + }; + +/** +* Represents a block of extensions in a hello message +*/ +class TLS_Extensions + { + public: + size_t count() const { return extensions.size(); } + + TLS_Extension* at(size_t idx) { return extensions.at(idx); } + + void push_back(TLS_Extension* extn) + { extensions.push_back(extn); } + + MemoryVector<byte> serialize() const; + + TLS_Extensions() {} + + TLS_Extensions(TLS_Data_Reader& reader); // deserialize + + ~TLS_Extensions(); + private: + TLS_Extensions(const TLS_Extensions&) {} + TLS_Extensions& operator=(const TLS_Extensions&) { return (*this); } + + std::vector<TLS_Extension*> extensions; + }; + +} + +#endif |