diff options
Diffstat (limited to 'src/lib/tls/tls_handshake_io.cpp')
-rw-r--r-- | src/lib/tls/tls_handshake_io.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/lib/tls/tls_handshake_io.cpp b/src/lib/tls/tls_handshake_io.cpp index 8834e0008..acc30b102 100644 --- a/src/lib/tls/tls_handshake_io.cpp +++ b/src/lib/tls/tls_handshake_io.cpp @@ -46,16 +46,17 @@ Protocol_Version Stream_Handshake_IO::initial_record_version() const return Protocol_Version::TLS_V10; } -void Stream_Handshake_IO::add_record(const std::vector<uint8_t>& record, +void Stream_Handshake_IO::add_record(const uint8_t record[], + size_t record_len, Record_Type record_type, uint64_t) { if(record_type == HANDSHAKE) { - m_queue.insert(m_queue.end(), record.begin(), record.end()); + m_queue.insert(m_queue.end(), record, record + record_len); } else if(record_type == CHANGE_CIPHER_SPEC) { - if(record.size() != 1 || record[0] != 1) + if(record_len != 1 || record[0] != 1) throw Decoding_Error("Invalid ChangeCipherSpec"); // Pretend it's a regular handshake message of zero length @@ -181,7 +182,8 @@ bool Datagram_Handshake_IO::timeout_check() return true; } -void Datagram_Handshake_IO::add_record(const std::vector<uint8_t>& record, +void Datagram_Handshake_IO::add_record(const uint8_t record[], + size_t record_len, Record_Type record_type, uint64_t record_sequence) { @@ -189,7 +191,7 @@ void Datagram_Handshake_IO::add_record(const std::vector<uint8_t>& record, if(record_type == CHANGE_CIPHER_SPEC) { - if(record.size() != 1 || record[0] != 1) + if(record_len != 1 || record[0] != 1) throw Decoding_Error("Invalid ChangeCipherSpec"); // TODO: check this is otherwise empty @@ -199,28 +201,25 @@ void Datagram_Handshake_IO::add_record(const std::vector<uint8_t>& record, const size_t DTLS_HANDSHAKE_HEADER_LEN = 12; - const uint8_t* record_bits = record.data(); - size_t record_size = record.size(); - - while(record_size) + while(record_len) { - if(record_size < DTLS_HANDSHAKE_HEADER_LEN) + if(record_len < DTLS_HANDSHAKE_HEADER_LEN) return; // completely bogus? at least degenerate/weird - const uint8_t msg_type = record_bits[0]; - const size_t msg_len = load_be24(&record_bits[1]); - const uint16_t message_seq = load_be<uint16_t>(&record_bits[4], 0); - const size_t fragment_offset = load_be24(&record_bits[6]); - const size_t fragment_length = load_be24(&record_bits[9]); + const uint8_t msg_type = record[0]; + const size_t msg_len = load_be24(&record[1]); + const uint16_t message_seq = load_be<uint16_t>(&record[4], 0); + const size_t fragment_offset = load_be24(&record[6]); + const size_t fragment_length = load_be24(&record[9]); const size_t total_size = DTLS_HANDSHAKE_HEADER_LEN + fragment_length; - if(record_size < total_size) + if(record_len < total_size) throw Decoding_Error("Bad lengths in DTLS header"); if(message_seq >= m_in_message_seq) { - m_messages[message_seq].add_fragment(&record_bits[DTLS_HANDSHAKE_HEADER_LEN], + m_messages[message_seq].add_fragment(&record[DTLS_HANDSHAKE_HEADER_LEN], fragment_length, fragment_offset, epoch, @@ -232,8 +231,8 @@ void Datagram_Handshake_IO::add_record(const std::vector<uint8_t>& record, // TODO: detect retransmitted flight } - record_bits += total_size; - record_size -= total_size; + record += total_size; + record_len -= total_size; } } |