diff options
author | lloyd <[email protected]> | 2012-03-30 01:41:04 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-03-30 01:41:04 +0000 |
commit | 4ff6063a9605c71cc734a594ddecbdb0d17541bf (patch) | |
tree | 845fa57d5f9e24fc39f5fa847296e4b778e6a894 /src/tls/rec_wri.cpp | |
parent | 8a31da4d60490753031267b18957c0c599bbee3b (diff) | |
parent | 4c12fa5de1b59f2c58f974412231a19c4dc7c10f (diff) |
propagate from branch 'net.randombit.botan.tls-state-machine' (head 63b88a65b699c95ef839bc18336bceccfbfabd2e)
to branch 'net.randombit.botan.cxx11' (head 1adcc46808b403b8f6bf1669f022e65f9c30e8ea)
Diffstat (limited to 'src/tls/rec_wri.cpp')
-rw-r--r-- | src/tls/rec_wri.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/tls/rec_wri.cpp b/src/tls/rec_wri.cpp index 633b63720..3a54d7931 100644 --- a/src/tls/rec_wri.cpp +++ b/src/tls/rec_wri.cpp @@ -6,6 +6,7 @@ */ #include <botan/tls_record.h> +#include <botan/internal/tls_messages.h> #include <botan/internal/tls_session_key.h> #include <botan/internal/tls_handshake_hash.h> #include <botan/lookup.h> @@ -22,9 +23,10 @@ namespace TLS { * Record_Writer Constructor */ Record_Writer::Record_Writer(std::function<void (const byte[], size_t)> out) : - m_output_fn(out), m_writebuf(TLS_HEADER_SIZE + MAX_CIPHERTEXT_SIZE) + m_output_fn(out), + m_writebuf(TLS_HEADER_SIZE + MAX_CIPHERTEXT_SIZE), + m_mac(0) { - m_mac = 0; reset(); set_maximum_fragment_size(0); } @@ -144,6 +146,25 @@ void Record_Writer::activate(Connection_Side side, throw Invalid_Argument("Record_Writer: Unknown hash " + mac_algo); } +MemoryVector<byte> Record_Writer::send(Handshake_Message& msg) + { + const MemoryVector<byte> buf = msg.serialize(); + MemoryVector<byte> send_buf(4); + + const size_t buf_size = buf.size(); + + send_buf[0] = msg.type(); + + for(size_t i = 1; i != 4; ++i) + send_buf[i] = get_byte<u32bit>(i, buf_size); + + send_buf += buf; + + send(HANDSHAKE, &send_buf[0], send_buf.size()); + + return send_buf; + } + /* * Send one or more records to the other side */ @@ -190,16 +211,15 @@ void Record_Writer::send_record(byte type, const byte input[], size_t length) if(m_mac_size == 0) // initial unencrypted handshake records { - const byte header[TLS_HEADER_SIZE] = { - type, - m_version.major_version(), - m_version.minor_version(), - get_byte<u16bit>(0, length), - get_byte<u16bit>(1, length) - }; - - m_output_fn(header, TLS_HEADER_SIZE); - m_output_fn(input, length); + m_writebuf[0] = type; + m_writebuf[1] = m_version.major_version(); + m_writebuf[2] = m_version.minor_version(); + m_writebuf[3] = get_byte<u16bit>(0, length); + m_writebuf[4] = get_byte<u16bit>(1, length); + + copy_mem(&m_writebuf[TLS_HEADER_SIZE], input, length); + + m_output_fn(&m_writebuf[0], TLS_HEADER_SIZE + length); return; } |