aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_extensions.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-30 18:51:01 +0000
committerlloyd <[email protected]>2011-12-30 18:51:01 +0000
commit766f5eeb5c99936e7ddcf3e4c82095f087b6e928 (patch)
tree17b95459926b1064b538889a1b7c732ff2298470 /src/tls/tls_extensions.cpp
parent07b11b4b3d9c7ef289050252c29bc8174d102148 (diff)
Add support for the maximum fragment length extension. No hooks for it
on the client side at the moment. Tested with gnutls-cli --recordsize. Save the fragment size and the secure renegotiation flags in the session state.
Diffstat (limited to 'src/tls/tls_extensions.cpp')
-rw-r--r--src/tls/tls_extensions.cpp59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/tls/tls_extensions.cpp b/src/tls/tls_extensions.cpp
index 1b3858a5a..b793971c5 100644
--- a/src/tls/tls_extensions.cpp
+++ b/src/tls/tls_extensions.cpp
@@ -13,15 +13,17 @@ namespace Botan {
namespace {
TLS_Extension* make_extension(TLS_Data_Reader& reader,
- u16bit extension_code,
- u16bit extension_size)
+ u16bit code,
+ u16bit size)
{
- if(extension_code == TLSEXT_SERVER_NAME_INDICATION)
- return new Server_Name_Indicator(reader, extension_size);
- else if(extension_code == TLSEXT_SRP_IDENTIFIER)
- return new SRP_Identifier(reader, extension_size);
- else if(extension_code == TLSEXT_SAFE_RENEGOTIATION)
- return new Renegotation_Extension(reader, extension_size);
+ if(code == TLSEXT_SERVER_NAME_INDICATION)
+ return new Server_Name_Indicator(reader, size);
+ else if(code == TLSEXT_MAX_FRAGMENT_LENGTH)
+ return new Maximum_Fragment_Length(reader, size);
+ else if(code == TLSEXT_SRP_IDENTIFIER)
+ return new SRP_Identifier(reader, size);
+ else if(code == TLSEXT_SAFE_RENEGOTIATION)
+ return new Renegotation_Extension(reader, size);
else
return 0; // not known
}
@@ -184,4 +186,45 @@ MemoryVector<byte> Renegotation_Extension::serialize() const
return buf;
}
+size_t Maximum_Fragment_Length::fragment_size() const
+ {
+ switch(val)
+ {
+ case 1:
+ return 512;
+ case 2:
+ return 1024;
+ case 3:
+ return 2048;
+ case 4:
+ return 4096;
+ default:
+ throw TLS_Exception(ILLEGAL_PARAMETER,
+ "Bad value in maximum fragment extension");
+ }
+ }
+
+Maximum_Fragment_Length::Maximum_Fragment_Length(size_t max_fragment)
+ {
+ if(max_fragment == 512)
+ val = 1;
+ else if(max_fragment == 1024)
+ val = 2;
+ else if(max_fragment == 2048)
+ val = 3;
+ else if(max_fragment == 4096)
+ val = 4;
+ else
+ throw std::invalid_argument("Bad setting " + to_string(max_fragment) +
+ " for maximum fragment size");
+ }
+
+Maximum_Fragment_Length::Maximum_Fragment_Length(TLS_Data_Reader& reader,
+ u16bit extension_size)
+ {
+ if(extension_size != 1)
+ throw Decoding_Error("Bad size for maximum fragment extension");
+ val = reader.get_byte();
+ }
+
}