aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_handshake_io.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-03 16:26:13 +0000
committerlloyd <[email protected]>2012-08-03 16:26:13 +0000
commit2d6888083bc497302e88c7eea6f930479cba0407 (patch)
tree38b399eecaa2bb9c6ab763bb4d00cde09e6751bd /src/tls/tls_handshake_io.h
parent3b8478fbf7aced5b1ab5d56757b6ca70f37e7557 (diff)
Add preliminary IO handler for datagram handshakes. Does not fragment
outbound messages to MTU. Reassembly likely doesn't work, and is very vulnerable to DoS attacks.
Diffstat (limited to 'src/tls/tls_handshake_io.h')
-rw-r--r--src/tls/tls_handshake_io.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/tls/tls_handshake_io.h b/src/tls/tls_handshake_io.h
index f71b2c034..039f92121 100644
--- a/src/tls/tls_handshake_io.h
+++ b/src/tls/tls_handshake_io.h
@@ -12,6 +12,7 @@
#include <botan/loadstor.h>
#include <vector>
#include <deque>
+#include <map>
#include <utility>
namespace Botan {
@@ -80,6 +81,56 @@ class Stream_Handshake_IO : public Handshake_IO
Record_Writer& m_writer;
};
+/**
+* Handshake IO for datagram-based handshakes
+*/
+class Datagram_Handshake_IO : public Handshake_IO
+ {
+ public:
+ Datagram_Handshake_IO(Record_Writer& writer) : m_writer(writer) {}
+
+ std::vector<byte> send(Handshake_Message& msg) override;
+
+ std::vector<byte> format(
+ const std::vector<byte>& handshake_msg,
+ Handshake_Type handshake_type) override;
+
+ void add_input(const byte rec_type,
+ const byte record[],
+ size_t record_size) override;
+
+ bool empty() const override;
+
+ bool have_full_record() const override;
+
+ std::pair<Handshake_Type, std::vector<byte>> get_next_record() override;
+ private:
+ class Handshake_Reassembly
+ {
+ public:
+ void add_fragment(const byte fragment[],
+ size_t fragment_length,
+ size_t fragment_offset,
+ byte msg_type,
+ size_t msg_length);
+
+ bool complete() const;
+
+ std::pair<Handshake_Type, std::vector<byte>> message() const;
+ private:
+ byte m_msg_type = HANDSHAKE_NONE;
+ size_t m_msg_length = 0;
+
+ std::vector<byte> m_buffer;
+ };
+
+ std::map<u16bit, Handshake_Reassembly> m_messages;
+
+ u16bit m_in_message_seq = 0;
+ u16bit m_out_message_seq = 0;
+ Record_Writer& m_writer;
+ };
+
}
}