From 8fcc2825c5aa7d6c359bba63eb883088a7650c86 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 4 Jan 2015 17:43:34 +0000 Subject: Add DTLS-SRTP key establishment from RFC 5764 (required for WebRTC). Github issue 27. Refactor server hello handling to make it easier to handle other extensions. The manual specified that 224 bit NIST primes were disabled by default for TLS but they were not. Additionaly disable the 256k1 curve and reorder the remaining curves by size. Rewrite the max fragment length extension code to roughly what an ideal compiler would have turned the original code into, using a switch instead of a lookup into a small constant std::map. --- src/lib/tls/tls_session.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/lib/tls/tls_session.cpp') diff --git a/src/lib/tls/tls_session.cpp b/src/lib/tls/tls_session.cpp index 37d6a2c67..5080d9f79 100644 --- a/src/lib/tls/tls_session.cpp +++ b/src/lib/tls/tls_session.cpp @@ -1,6 +1,6 @@ /* * TLS Session State -* (C) 2011-2012 Jack Lloyd +* (C) 2011-2012,2015 Jack Lloyd * * Released under the terms of the Botan license */ @@ -26,7 +26,8 @@ Session::Session(const std::vector& session_identifier, const std::vector& certs, const std::vector& ticket, const Server_Information& server_info, - const std::string& srp_identifier) : + const std::string& srp_identifier, + u16bit srtp_profile) : m_start_time(std::chrono::system_clock::now()), m_identifier(session_identifier), m_session_ticket(ticket), @@ -35,6 +36,7 @@ Session::Session(const std::vector& session_identifier, m_ciphersuite(ciphersuite), m_compression_method(compression_method), m_connection_side(side), + m_srtp_profile(srtp_profile), m_fragment_size(fragment_size), m_peer_certs(certs), m_server_info(server_info), @@ -44,7 +46,7 @@ Session::Session(const std::vector& session_identifier, Session::Session(const std::string& pem) { - secure_vector der = PEM_Code::decode_check_label(pem, "SSL SESSION"); + secure_vector der = PEM_Code::decode_check_label(pem, "TLS SESSION"); *this = Session(&der[0], der.size()); } @@ -60,15 +62,15 @@ Session::Session(const byte ber[], size_t ber_len) ASN1_String srp_identifier_str; byte major_version = 0, minor_version = 0; - std::vector peer_cert_bits; size_t start_time = 0; + size_t srtp_profile = 0; BER_Decoder(ber, ber_len) .start_cons(SEQUENCE) .decode_and_check(static_cast(TLS_SESSION_PARAM_STRUCT_VERSION), - "Unknown version in session structure") + "Unknown version in serialized TLS session") .decode_integer_type(start_time) .decode_integer_type(major_version) .decode_integer_type(minor_version) @@ -84,12 +86,14 @@ Session::Session(const byte ber[], size_t ber_len) .decode(server_service) .decode(server_port) .decode(srp_identifier_str) + .decode(srtp_profile) .end_cons() .verify_end(); m_version = Protocol_Version(major_version, minor_version); m_start_time = std::chrono::system_clock::from_time_t(start_time); m_connection_side = static_cast(side_code); + m_srtp_profile = srtp_profile; m_server_info = Server_Information(server_hostname.value(), server_service.value(), @@ -130,13 +134,14 @@ secure_vector Session::DER_encode() const .encode(ASN1_String(m_server_info.service(), UTF8_STRING)) .encode(static_cast(m_server_info.port())) .encode(ASN1_String(m_srp_identifier, UTF8_STRING)) + .encode(static_cast(m_srtp_profile)) .end_cons() .get_contents(); } std::string Session::PEM_encode() const { - return PEM_Code::encode(this->DER_encode(), "SSL SESSION"); + return PEM_Code::encode(this->DER_encode(), "TLS SESSION"); } std::chrono::seconds Session::session_age() const -- cgit v1.2.3