aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_channel.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-01-05 23:01:06 +0000
committerlloyd <[email protected]>2012-01-05 23:01:06 +0000
commitf452ca334eeb469d13d816c43227a7ea2f49efeb (patch)
tree51b21923652a596d3d04f6e24ff601e32ff97eb6 /src/tls/tls_channel.cpp
parent74226be019b1a66f8eae9a6516f2eb28a53fb9e2 (diff)
Make record reading faster (less copying, no queue at all), at the
expense of significant complexity. Needs careful testing for corner cases and malicious inputs, but seems to work well with randomly chosen segmentations in a correctly formatted stream at least.
Diffstat (limited to 'src/tls/tls_channel.cpp')
-rw-r--r--src/tls/tls_channel.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/tls/tls_channel.cpp b/src/tls/tls_channel.cpp
index 73c4fd4ab..7fda4bc86 100644
--- a/src/tls/tls_channel.cpp
+++ b/src/tls/tls_channel.cpp
@@ -1,6 +1,6 @@
/*
* TLS Channels
-* (C) 2011 Jack Lloyd
+* (C) 2011-2012 Jack Lloyd
*
* Released under the terms of the Botan license
*/
@@ -8,6 +8,7 @@
#include <botan/tls_channel.h>
#include <botan/internal/tls_alerts.h>
#include <botan/internal/tls_handshake_state.h>
+#include <botan/internal/assert.h>
#include <botan/loadstor.h>
namespace Botan {
@@ -42,17 +43,21 @@ size_t TLS_Channel::received_data(const byte buf[], size_t buf_size)
{
try
{
- reader.add_input(buf, buf_size);
+ while(buf_size)
+ {
+ byte rec_type = CONNECTION_CLOSED;
+ MemoryVector<byte> record;
+ size_t consumed = 0;
- byte rec_type = CONNECTION_CLOSED;
- MemoryVector<byte> record;
+ const size_t needed = reader.add_input(buf, buf_size,
+ consumed,
+ rec_type, record);
- while(!reader.currently_empty())
- {
- const size_t bytes_needed = reader.get_record(rec_type, record);
+ buf += consumed;
+ buf_size -= consumed;
- if(bytes_needed > 0)
- return bytes_needed;
+ if(buf_size == 0 && needed != 0)
+ return needed; // need more data to complete record
if(rec_type == APPLICATION_DATA)
{
@@ -95,7 +100,8 @@ size_t TLS_Channel::received_data(const byte buf[], size_t buf_size)
}
}
else
- throw Unexpected_Message("Unknown message type received");
+ throw Unexpected_Message("Unknown TLS message type " +
+ to_string(rec_type) + " received");
}
return 0; // on a record boundary