From 54400bc4ad012a9704d729fade5c1ea5372eb1fb Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 18 Jan 2017 13:47:02 +0100 Subject: Refuse to receive data during handshake This prevents buggy applications from receiving non-authenticated data that may have arrived during the handshake. Relates #158 Signed-off-by: Nikos Mavrogiannopoulos --- lib/record.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/record.c b/lib/record.c index e10fa46433..133f23e145 100644 --- a/lib/record.c +++ b/lib/record.c @@ -1771,6 +1771,14 @@ int gnutls_record_uncork(gnutls_session_t session, unsigned int flags) ssize_t gnutls_record_recv(gnutls_session_t session, void *data, size_t data_size) { + if (unlikely(!session->internals.initial_negotiation_completed)) { + /* this is to protect buggy applications from sending unencrypted + * data. We allow sending however, if we are in false start handshake + * state. */ + if (session->internals.recv_state != RECV_STATE_FALSE_START) + return gnutls_assert_val(GNUTLS_E_UNAVAILABLE_DURING_HANDSHAKE); + } + return _gnutls_recv_int(session, GNUTLS_APPLICATION_DATA, data, data_size, NULL, session->internals.record_timeout_ms); -- cgit v1.2.1