aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-07-05 15:09:33 +0000
committerlloyd <[email protected]>2012-07-05 15:09:33 +0000
commit2f94d5c85d3eb05a3d2f83e7783fb8d1bc2d5536 (patch)
tree03c2dfe5bc79f9c753a7b24086e811c641e0f6b3 /src
parentefa00d7ffddc9a41b1fe74ed863bc7debfc44359 (diff)
Record_Writer needs a PRNG for the IV generation. Share the reference
with the channel object instead of calling the global object.
Diffstat (limited to 'src')
-rw-r--r--src/tls/rec_wri.cpp9
-rw-r--r--src/tls/tls_channel.cpp5
-rw-r--r--src/tls/tls_channel.h3
-rw-r--r--src/tls/tls_client.cpp2
-rw-r--r--src/tls/tls_record.h17
-rw-r--r--src/tls/tls_server.cpp2
6 files changed, 22 insertions, 16 deletions
diff --git a/src/tls/rec_wri.cpp b/src/tls/rec_wri.cpp
index d18ab6594..082cdd880 100644
--- a/src/tls/rec_wri.cpp
+++ b/src/tls/rec_wri.cpp
@@ -22,10 +22,12 @@ namespace TLS {
/*
* Record_Writer Constructor
*/
-Record_Writer::Record_Writer(std::function<void (const byte[], size_t)> out) :
+Record_Writer::Record_Writer(std::function<void (const byte[], size_t)> out,
+ RandomNumberGenerator& rng) :
m_output_fn(out),
m_writebuf(TLS_HEADER_SIZE + MAX_CIPHERTEXT_SIZE),
- m_mac(nullptr)
+ m_mac(nullptr),
+ m_rng(rng)
{
reset();
set_maximum_fragment_size(0);
@@ -258,8 +260,7 @@ void Record_Writer::send_record(byte type, const byte input[], size_t length)
if(m_iv_size)
{
- RandomNumberGenerator& rng = global_state().global_rng();
- rng.randomize(buf_write_ptr, m_iv_size);
+ m_rng.randomize(buf_write_ptr, m_iv_size);
buf_write_ptr += m_iv_size;
}
diff --git a/src/tls/tls_channel.cpp b/src/tls/tls_channel.cpp
index fe1376d6e..e3188cafa 100644
--- a/src/tls/tls_channel.cpp
+++ b/src/tls/tls_channel.cpp
@@ -19,12 +19,13 @@ namespace TLS {
Channel::Channel(std::function<void (const byte[], size_t)> socket_output_fn,
std::function<void (const byte[], size_t, Alert)> proc_fn,
std::function<bool (const Session&)> handshake_complete,
- Session_Manager& session_manager) :
+ Session_Manager& session_manager,
+ RandomNumberGenerator& rng) :
m_proc_fn(proc_fn),
m_handshake_fn(handshake_complete),
m_state(nullptr),
m_session_manager(session_manager),
- m_writer(socket_output_fn),
+ m_writer(socket_output_fn, rng),
m_handshake_completed(false),
m_connection_closed(false),
m_peer_supports_heartbeats(false),
diff --git a/src/tls/tls_channel.h b/src/tls/tls_channel.h
index 4551a377e..5e66d00db 100644
--- a/src/tls/tls_channel.h
+++ b/src/tls/tls_channel.h
@@ -86,7 +86,8 @@ class BOTAN_DLL Channel
Channel(std::function<void (const byte[], size_t)> socket_output_fn,
std::function<void (const byte[], size_t, Alert)> proc_fn,
std::function<bool (const Session&)> handshake_complete,
- Session_Manager& session_manager);
+ Session_Manager& session_manager,
+ RandomNumberGenerator& rng);
virtual ~Channel();
protected:
diff --git a/src/tls/tls_client.cpp b/src/tls/tls_client.cpp
index 1f427ea14..db967cee3 100644
--- a/src/tls/tls_client.cpp
+++ b/src/tls/tls_client.cpp
@@ -27,7 +27,7 @@ Client::Client(std::function<void (const byte[], size_t)> output_fn,
RandomNumberGenerator& rng,
const std::string& hostname,
std::function<std::string (std::vector<std::string>)> next_protocol) :
- Channel(output_fn, proc_fn, handshake_fn, session_manager),
+ Channel(output_fn, proc_fn, handshake_fn, session_manager, rng),
m_policy(policy),
m_rng(rng),
m_creds(creds),
diff --git a/src/tls/tls_record.h b/src/tls/tls_record.h
index 9b1f7e0f7..0b67f9a63 100644
--- a/src/tls/tls_record.h
+++ b/src/tls/tls_record.h
@@ -50,13 +50,15 @@ class BOTAN_DLL Record_Writer
void set_maximum_fragment_size(size_t max_fragment);
- Record_Writer(std::function<void (const byte[], size_t)> output_fn);
+ Record_Writer(std::function<void (const byte[], size_t)> output_fn,
+ RandomNumberGenerator& rng);
+
+ Record_Writer(const Record_Writer&) = delete;
+
+ Record_Writer& operator=(const Record_Writer&) = delete;
~Record_Writer() { delete m_mac; }
private:
- Record_Writer(const Record_Writer&) {}
- Record_Writer& operator=(const Record_Writer&) { return (*this); }
-
void send_record(byte type, const byte input[], size_t length);
std::function<void (const byte[], size_t)> m_output_fn;
@@ -65,6 +67,7 @@ class BOTAN_DLL Record_Writer
Pipe m_cipher;
MessageAuthenticationCode* m_mac;
+ RandomNumberGenerator& m_rng;
size_t m_block_size, m_mac_size, m_iv_size, m_max_fragment;
@@ -109,11 +112,11 @@ class BOTAN_DLL Record_Reader
Record_Reader();
+ Record_Reader(const Record_Reader&) = delete;
+ Record_Reader& operator=(const Record_Reader&) = delete;
+
~Record_Reader() { delete m_mac; }
private:
- Record_Reader(const Record_Reader&) {}
- Record_Reader& operator=(const Record_Reader&) { return (*this); }
-
size_t fill_buffer_to(const byte*& input,
size_t& input_size,
size_t& input_consumed,
diff --git a/src/tls/tls_server.cpp b/src/tls/tls_server.cpp
index 91596b065..d2a51fabd 100644
--- a/src/tls/tls_server.cpp
+++ b/src/tls/tls_server.cpp
@@ -192,7 +192,7 @@ Server::Server(std::function<void (const byte[], size_t)> output_fn,
const Policy& policy,
RandomNumberGenerator& rng,
const std::vector<std::string>& next_protocols) :
- Channel(output_fn, proc_fn, handshake_fn, session_manager),
+ Channel(output_fn, proc_fn, handshake_fn, session_manager, rng),
m_policy(policy),
m_rng(rng),
m_creds(creds),