diff options
author | lloyd <[email protected]> | 2012-01-04 15:08:20 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-01-04 15:08:20 +0000 |
commit | c926d5e919245f25d1730f4f4d565f691647e99f (patch) | |
tree | b3ed5b8e686b74ffb4a1d65eeb9fea69e44f1fc3 /src/tls/tls_extensions.cpp | |
parent | 7fbfe2369388ad58df4e2f30c833168cebec924b (diff) |
Add support for next protocol negotiation. Client only currently;
tested with google.com:443
Diffstat (limited to 'src/tls/tls_extensions.cpp')
-rw-r--r-- | src/tls/tls_extensions.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/tls/tls_extensions.cpp b/src/tls/tls_extensions.cpp index a08597d21..a6ab13f46 100644 --- a/src/tls/tls_extensions.cpp +++ b/src/tls/tls_extensions.cpp @@ -1,6 +1,6 @@ /* * TLS Extensions -* (C) 2011 Jack Lloyd +* (C) 2011,2012 Jack Lloyd * * Released under the terms of the Botan license */ @@ -9,6 +9,8 @@ #include <botan/internal/tls_reader.h> #include <botan/tls_exceptn.h> +#include <stdio.h> + namespace Botan { namespace { @@ -25,6 +27,8 @@ TLS_Extension* make_extension(TLS_Data_Reader& reader, return new SRP_Identifier(reader, size); else if(code == TLSEXT_SAFE_RENEGOTIATION) return new Renegotation_Extension(reader, size); + else if(code == TLSEXT_NEXT_PROTOCOL) + return new Next_Protocol_Negotiation(reader, size); else return 0; // not known } @@ -228,4 +232,45 @@ Maximum_Fragment_Length::Maximum_Fragment_Length(TLS_Data_Reader& reader, val = reader.get_byte(); } +Next_Protocol_Negotiation::Next_Protocol_Negotiation(TLS_Data_Reader& reader, + u16bit extension_size) + { + if(extension_size == 0) + return; // empty extension + + size_t bytes_remaining = extension_size; + + while(bytes_remaining) + { + const std::string p = reader.get_string(1, 0, 255); + + printf("Protocol option %s\n", p.c_str()); + + if(bytes_remaining < p.size() + 1) + throw Decoding_Error("Bad encoding for next protocol extension"); + + bytes_remaining -= (p.size() + 1); + + m_protocols.push_back(p); + } + } + +MemoryVector<byte> Next_Protocol_Negotiation::serialize() const + { + MemoryVector<byte> buf; + + for(size_t i = 0; i != m_protocols.size(); ++i) + { + const std::string p = m_protocols[i]; + + if(p != "") + append_tls_length_value(buf, + reinterpret_cast<const byte*>(p.data()), + p.size(), + 1); + } + + return buf; + } + } |