aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-03-03 04:05:28 +0000
committerlloyd <[email protected]>2012-03-03 04:05:28 +0000
commit0cb5c24b007ba8cea9eb05f31548b078e2b1dea3 (patch)
tree05246766e6ee7048d5d6267876112ab57c3596cd
parent03ff8576e98e22aef25439d991c3fd8a1db71237 (diff)
Move the handshake serialization code to Record_Writer
-rw-r--r--src/tls/c_hello.cpp29
-rw-r--r--src/tls/c_kex.cpp3
-rw-r--r--src/tls/cert_req.cpp5
-rw-r--r--src/tls/cert_ver.cpp3
-rw-r--r--src/tls/finished.cpp3
-rw-r--r--src/tls/next_protocol.cpp3
-rw-r--r--src/tls/rec_wri.cpp20
-rw-r--r--src/tls/s_hello.cpp6
-rw-r--r--src/tls/s_kex.cpp3
-rw-r--r--src/tls/tls_messages.h6
-rw-r--r--src/tls/tls_record.h2
11 files changed, 44 insertions, 39 deletions
diff --git a/src/tls/c_hello.cpp b/src/tls/c_hello.cpp
index ecb6f43d6..59e0670df 100644
--- a/src/tls/c_hello.cpp
+++ b/src/tls/c_hello.cpp
@@ -27,34 +27,11 @@ MemoryVector<byte> make_hello_random(RandomNumberGenerator& rng)
}
/*
-* Encode and send a Handshake message
-*/
-void Handshake_Message::send(Record_Writer& writer, Handshake_Hash& hash) const
- {
- MemoryVector<byte> buf = serialize();
- MemoryVector<byte> send_buf(4);
-
- const size_t buf_size = buf.size();
-
- send_buf[0] = type();
-
- for(size_t i = 1; i != 4; ++i)
- send_buf[i] = get_byte<u32bit>(i, buf_size);
-
- send_buf += buf;
-
- hash.update(send_buf);
-
- writer.send(HANDSHAKE, &send_buf[0], send_buf.size());
- }
-
-/*
* Create a new Hello Request message
*/
Hello_Request::Hello_Request(Record_Writer& writer)
{
- Handshake_Hash dummy; // FIXME: *UGLY*
- send(writer, dummy);
+ writer.send(*this);
}
/*
@@ -105,7 +82,7 @@ Client_Hello::Client_Hello(Record_Writer& writer,
for(size_t j = 0; j != sigs.size(); ++j)
m_supported_algos.push_back(std::make_pair(hashes[i], sigs[j]));
- send(writer, hash);
+ hash.update(writer.send(*this));
}
/*
@@ -130,7 +107,7 @@ Client_Hello::Client_Hello(Record_Writer& writer,
// set m_supported_algos + m_supported_curves here?
- send(writer, hash);
+ hash.update(writer.send(*this));
}
Client_Hello::Client_Hello(const MemoryRegion<byte>& buf, Handshake_Type type)
diff --git a/src/tls/c_kex.cpp b/src/tls/c_kex.cpp
index 58e458e81..e0ebfb865 100644
--- a/src/tls/c_kex.cpp
+++ b/src/tls/c_kex.cpp
@@ -8,6 +8,7 @@
#include <botan/internal/tls_messages.h>
#include <botan/internal/tls_reader.h>
#include <botan/internal/tls_extensions.h>
+#include <botan/tls_record.h>
#include <botan/internal/assert.h>
#include <botan/credentials_manager.h>
#include <botan/pubkey.h>
@@ -211,7 +212,7 @@ Client_Key_Exchange::Client_Key_Exchange(Record_Writer& writer,
pub_key->algo_name());
}
- send(writer, state->hash);
+ state->hash.update(writer.send(*this));
}
/*
diff --git a/src/tls/cert_req.cpp b/src/tls/cert_req.cpp
index f400a36d2..063cc5902 100644
--- a/src/tls/cert_req.cpp
+++ b/src/tls/cert_req.cpp
@@ -8,6 +8,7 @@
#include <botan/internal/tls_messages.h>
#include <botan/internal/tls_reader.h>
#include <botan/internal/tls_extensions.h>
+#include <botan/tls_record.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/loadstor.h>
@@ -74,7 +75,7 @@ Certificate_Req::Certificate_Req(Record_Writer& writer,
m_supported_algos.push_back(std::make_pair(hashes[i], sigs[j]));
}
- send(writer, hash);
+ hash.update(writer.send(*this));
}
/**
@@ -176,7 +177,7 @@ Certificate::Certificate(Record_Writer& writer,
const std::vector<X509_Certificate>& cert_list)
{
certs = cert_list;
- send(writer, hash);
+ hash.update(writer.send(*this));
}
/**
diff --git a/src/tls/cert_ver.cpp b/src/tls/cert_ver.cpp
index 791635b17..388e16c88 100644
--- a/src/tls/cert_ver.cpp
+++ b/src/tls/cert_ver.cpp
@@ -8,6 +8,7 @@
#include <botan/internal/tls_messages.h>
#include <botan/internal/tls_reader.h>
#include <botan/internal/tls_extensions.h>
+#include <botan/tls_record.h>
#include <botan/internal/assert.h>
#include <memory>
@@ -45,7 +46,7 @@ Certificate_Verify::Certificate_Verify(Record_Writer& writer,
signature = signer.sign_message(state->hash.get_contents(), rng);
}
- send(writer, state->hash);
+ state->hash.update(writer.send(*this));
}
/*
diff --git a/src/tls/finished.cpp b/src/tls/finished.cpp
index 18cc51b96..3c1c5684c 100644
--- a/src/tls/finished.cpp
+++ b/src/tls/finished.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/internal/tls_messages.h>
+#include <botan/tls_record.h>
#include <memory>
namespace Botan {
@@ -70,7 +71,7 @@ Finished::Finished(Record_Writer& writer,
Connection_Side side)
{
verification_data = finished_compute_verify(state, side);
- send(writer, state->hash);
+ state->hash.update(writer.send(*this));
}
/*
diff --git a/src/tls/next_protocol.cpp b/src/tls/next_protocol.cpp
index 97b072440..17b77fb6e 100644
--- a/src/tls/next_protocol.cpp
+++ b/src/tls/next_protocol.cpp
@@ -8,6 +8,7 @@
#include <botan/internal/tls_messages.h>
#include <botan/internal/tls_extensions.h>
#include <botan/internal/tls_reader.h>
+#include <botan/tls_record.h>
namespace Botan {
@@ -18,7 +19,7 @@ Next_Protocol::Next_Protocol(Record_Writer& writer,
const std::string& protocol) :
m_protocol(protocol)
{
- send(writer, hash);
+ hash.update(writer.send(*this));
}
Next_Protocol::Next_Protocol(const MemoryRegion<byte>& buf)
diff --git a/src/tls/rec_wri.cpp b/src/tls/rec_wri.cpp
index 602d25397..cc7c6f79a 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>
@@ -144,6 +145,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
*/
diff --git a/src/tls/s_hello.cpp b/src/tls/s_hello.cpp
index 0ad78fc5b..9bcbdb5e9 100644
--- a/src/tls/s_hello.cpp
+++ b/src/tls/s_hello.cpp
@@ -51,7 +51,7 @@ Server_Hello::Server_Hello(Record_Writer& writer,
comp_method = policy.choose_compression(c_hello.compression_methods());
- send(writer, hash);
+ hash.update(writer.send(*this));
}
/*
@@ -80,7 +80,7 @@ Server_Hello::Server_Hello(Record_Writer& writer,
m_next_protocol(client_has_npn),
m_next_protocols(next_protocols)
{
- send(writer, hash);
+ hash.update(writer.send(*this));
}
/*
@@ -174,7 +174,7 @@ MemoryVector<byte> Server_Hello::serialize() const
Server_Hello_Done::Server_Hello_Done(Record_Writer& writer,
Handshake_Hash& hash)
{
- send(writer, hash);
+ hash.update(writer.send(*this));
}
/*
diff --git a/src/tls/s_kex.cpp b/src/tls/s_kex.cpp
index f25205e99..6707d2611 100644
--- a/src/tls/s_kex.cpp
+++ b/src/tls/s_kex.cpp
@@ -8,6 +8,7 @@
#include <botan/internal/tls_messages.h>
#include <botan/internal/tls_reader.h>
#include <botan/internal/tls_extensions.h>
+#include <botan/tls_record.h>
#include <botan/internal/assert.h>
#include <botan/credentials_manager.h>
#include <botan/loadstor.h>
@@ -105,7 +106,7 @@ Server_Key_Exchange::Server_Key_Exchange(Record_Writer& writer,
m_signature = signer.signature(rng);
}
- send(writer, state->hash);
+ state->hash.update(writer.send(*this));
}
/**
diff --git a/src/tls/tls_messages.h b/src/tls/tls_messages.h
index 7162ece1a..3352c2a62 100644
--- a/src/tls/tls_messages.h
+++ b/src/tls/tls_messages.h
@@ -33,14 +33,14 @@ class Record_Reader;
class Handshake_Message
{
public:
- void send(Record_Writer& writer, Handshake_Hash& hash) const;
-
+ virtual MemoryVector<byte> serialize() const = 0;
virtual Handshake_Type type() const = 0;
+ Handshake_Message() {}
virtual ~Handshake_Message() {}
private:
+ Handshake_Message(const Handshake_Message&) {}
Handshake_Message& operator=(const Handshake_Message&) { return (*this); }
- virtual MemoryVector<byte> serialize() const = 0;
};
MemoryVector<byte> make_hello_random(RandomNumberGenerator& rng);
diff --git a/src/tls/tls_record.h b/src/tls/tls_record.h
index 3bc58a0da..fb27db5e2 100644
--- a/src/tls/tls_record.h
+++ b/src/tls/tls_record.h
@@ -46,6 +46,8 @@ class BOTAN_DLL Record_Writer
void send(byte type, const byte input[], size_t length);
void send(byte type, byte val) { send(type, &val, 1); }
+ MemoryVector<byte> send(class Handshake_Message& msg);
+
void send_alert(const Alert& alert);
void activate(Connection_Side side,