diff options
author | lloyd <[email protected]> | 2010-03-30 02:50:15 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-30 02:50:15 +0000 |
commit | 2c0cd825b6368f61afdba0eab8c8697d25451787 (patch) | |
tree | 2217e60d38aa34d9bf8fde1f3e17bc48d5e8303c /src/ssl/rec_wri.cpp | |
parent | 6d141cd765d840d8bbfdaaa8154494d3c9ecce50 (diff) |
Add support for TLS v1.1's per-record random IV. Tested against GnuTLS server.
Diffstat (limited to 'src/ssl/rec_wri.cpp')
-rw-r--r-- | src/ssl/rec_wri.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/ssl/rec_wri.cpp b/src/ssl/rec_wri.cpp index dc51a06b0..092ecdfe1 100644 --- a/src/ssl/rec_wri.cpp +++ b/src/ssl/rec_wri.cpp @@ -9,6 +9,7 @@ #include <botan/handshake_hash.h> #include <botan/lookup.h> #include <botan/loadstor.h> +#include <botan/libstate.h> namespace Botan { @@ -35,6 +36,7 @@ void Record_Writer::reset() major = minor = buf_type = 0; block_size = 0; mac_size = 0; + iv_size = 0; seq_no = 0; } @@ -44,7 +46,7 @@ void Record_Writer::reset() */ void Record_Writer::set_version(Version_Code version) { - if(version != SSL_V3 && version != TLS_V10) + if(version != SSL_V3 && version != TLS_V10 && version != TLS_V11) throw Invalid_Argument("Record_Writer: Invalid protocol version"); major = (version >> 8) & 0xFF; @@ -86,11 +88,17 @@ void Record_Writer::set_keys(const CipherSuite& suite, const SessionKeys& keys, cipher_key, iv, ENCRYPTION) ); block_size = block_size_of(cipher_algo); + + if(major == 3 && minor >= 2) + iv_size = block_size; + else + iv_size = 0; } else if(have_stream_cipher(cipher_algo)) { cipher.append(get_cipher(cipher_algo, cipher_key, ENCRYPTION)); block_size = 0; + iv_size = 0; } else throw Invalid_Argument("Record_Writer: Unknown cipher " + cipher_algo); @@ -202,6 +210,18 @@ void Record_Writer::send_record(byte type, const byte buf[], u32bit length) SecureVector<byte> buf_mac = mac.read_all(Pipe::LAST_MESSAGE); cipher.start_msg(); + + if(iv_size) + { + RandomNumberGenerator& rng = global_state().global_rng(); + + SecureVector<byte> random_iv(iv_size); + + rng.randomize(&random_iv[0], random_iv.size()); + + cipher.write(random_iv); + } + cipher.write(buf, length); cipher.write(buf_mac); |