diff options
author | lloyd <[email protected]> | 2012-12-10 17:40:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-12-10 17:40:34 +0000 |
commit | bf8b7ddc2855c93264ee7ce59eac609d369fdb9f (patch) | |
tree | 2348ac484d06e74a7055da0da5d32de2aa6f88fc /src/tls/tls_record.cpp | |
parent | 12c128c1fbb483ae9042b47fc544adf0e55d0693 (diff) |
Add a Record struct to combine the record contents, type, sequence #,
and version into a single value.
Diffstat (limited to 'src/tls/tls_record.cpp')
-rw-r--r-- | src/tls/tls_record.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/tls/tls_record.cpp b/src/tls/tls_record.cpp index fab966e72..7032e09ac 100644 --- a/src/tls/tls_record.cpp +++ b/src/tls/tls_record.cpp @@ -270,10 +270,7 @@ size_t read_record(std::vector<byte>& readbuf, const byte input[], size_t input_sz, size_t& consumed, - byte& msg_type, - std::vector<byte>& msg, - Protocol_Version& record_version, - u64bit& record_sequence, + Record& record, Connection_Sequence_Numbers* sequence_numbers, std::function<Connection_Cipher_State* (u16bit)> get_cipherstate) { @@ -309,6 +306,7 @@ size_t read_record(std::vector<byte>& readbuf, BOTAN_ASSERT_EQUAL(readbuf.size(), (record_len + 2), "Have the entire SSLv2 hello"); +#if 0 msg_type = HANDSHAKE; msg.resize(record_len + 4); @@ -320,13 +318,13 @@ size_t read_record(std::vector<byte>& readbuf, msg[3] = readbuf[1]; copy_mem(&msg[4], &readbuf[2], readbuf.size() - 2); - +#endif readbuf.clear(); return 0; } } - record_version = Protocol_Version(readbuf[1], readbuf[2]); + Protocol_Version record_version = Protocol_Version(readbuf[1], readbuf[2]); const bool is_dtls = record_version.is_datagram_protocol(); @@ -359,6 +357,9 @@ size_t read_record(std::vector<byte>& readbuf, readbuf.size(), "Have the full record"); + Record_Type record_type = static_cast<Record_Type>(readbuf[0]); + + u64bit record_sequence = 0; u16bit epoch = 0; if(is_dtls) @@ -385,8 +386,11 @@ size_t read_record(std::vector<byte>& readbuf, if(epoch == 0) // Unencrypted initial handshake { - msg_type = readbuf[0]; - msg.assign(&record_contents[0], &record_contents[record_len]); + record = Record(record_sequence, + record_version, + record_type, + &readbuf[header_size], + record_len); readbuf.clear(); return 0; // got a full record @@ -461,10 +465,11 @@ size_t read_record(std::vector<byte>& readbuf, cipherstate->mac()->update(record_version.minor_version()); } - const u16bit plain_length = record_len - mac_pad_iv_size; + const byte* plaintext_block = &record_contents[iv_size]; + const u16bit plaintext_length = record_len - mac_pad_iv_size; - cipherstate->mac()->update_be(plain_length); - cipherstate->mac()->update(&record_contents[iv_size], plain_length); + cipherstate->mac()->update_be(plaintext_length); + cipherstate->mac()->update(plaintext_block, plaintext_length); std::vector<byte> mac_buf(mac_size); cipherstate->mac()->final(&mac_buf[0]); @@ -481,9 +486,11 @@ size_t read_record(std::vector<byte>& readbuf, if(sequence_numbers) sequence_numbers->read_accept(record_sequence); - msg_type = readbuf[0]; - msg.assign(&record_contents[iv_size], - &record_contents[iv_size + plain_length]); + record = Record(record_sequence, + record_version, + record_type, + plaintext_block, + plaintext_length); readbuf.clear(); return 0; |