|
|
90a1d9 |
From 29ee67c205855e848a0a26e6d0e4f65b6b943e0a Mon Sep 17 00:00:00 2001
|
|
|
90a1d9 |
From: Daiki Ueno <ueno@gnu.org>
|
|
|
90a1d9 |
Date: Sat, 22 Aug 2020 17:19:39 +0200
|
|
|
90a1d9 |
Subject: [PATCH] handshake: reject no_renegotiation alert if handshake is
|
|
|
90a1d9 |
incomplete
|
|
|
90a1d9 |
|
|
|
90a1d9 |
If the initial handshake is incomplete and the server sends a
|
|
|
90a1d9 |
no_renegotiation alert, the client should treat it as a fatal error
|
|
|
90a1d9 |
even if its level is warning. Otherwise the same handshake
|
|
|
90a1d9 |
state (e.g., DHE parameters) are reused in the next gnutls_handshake
|
|
|
90a1d9 |
call, if it is called in the loop idiom:
|
|
|
90a1d9 |
|
|
|
90a1d9 |
do {
|
|
|
90a1d9 |
ret = gnutls_handshake(session);
|
|
|
90a1d9 |
} while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
|
|
|
90a1d9 |
|
|
|
90a1d9 |
Signed-off-by: Daiki Ueno <ueno@gnu.org>
|
|
|
90a1d9 |
---
|
|
|
90a1d9 |
...a04b3d3f7dcc0ab4571cf0df3b67ab7e1005e9e7a8 | Bin 0 -> 671 bytes
|
|
|
90a1d9 |
...1da801fb3c6d1f7f846f227721e221adea08aa319c | Bin 0 -> 729 bytes
|
|
|
90a1d9 |
lib/gnutls_int.h | 1 +
|
|
|
90a1d9 |
lib/handshake.c | 48 +++++++++++++-----
|
|
|
90a1d9 |
4 files changed, 36 insertions(+), 13 deletions(-)
|
|
|
90a1d9 |
create mode 100644 fuzz/gnutls_client_fuzzer.in/00ea40761ce11e769f1817a04b3d3f7dcc0ab4571cf0df3b67ab7e1005e9e7a8
|
|
|
90a1d9 |
create mode 100644 fuzz/gnutls_psk_client_fuzzer.in/b16434290b77e13d7a983d1da801fb3c6d1f7f846f227721e221adea08aa319c
|
|
|
90a1d9 |
|
|
|
90a1d9 |
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
|
|
|
90a1d9 |
index bb6c19713..31cec5c0c 100644
|
|
|
90a1d9 |
--- a/lib/gnutls_int.h
|
|
|
90a1d9 |
+++ b/lib/gnutls_int.h
|
|
|
90a1d9 |
@@ -1370,6 +1370,7 @@ typedef struct {
|
|
|
90a1d9 |
#define HSK_RECORD_SIZE_LIMIT_RECEIVED (1<<26) /* server: record_size_limit extension was seen but not accepted yet */
|
|
|
90a1d9 |
#define HSK_OCSP_REQUESTED (1<<27) /* server: client requested OCSP stapling */
|
|
|
90a1d9 |
#define HSK_CLIENT_OCSP_REQUESTED (1<<28) /* client: server requested OCSP stapling */
|
|
|
90a1d9 |
+#define HSK_SERVER_HELLO_RECEIVED (1<<29) /* client: Server Hello message has been received */
|
|
|
90a1d9 |
|
|
|
90a1d9 |
/* The hsk_flags are for use within the ongoing handshake;
|
|
|
90a1d9 |
* they are reset to zero prior to handshake start by gnutls_handshake. */
|
|
|
90a1d9 |
diff --git a/lib/handshake.c b/lib/handshake.c
|
|
|
90a1d9 |
index b40f84b3d..ce2d160e2 100644
|
|
|
90a1d9 |
--- a/lib/handshake.c
|
|
|
90a1d9 |
+++ b/lib/handshake.c
|
|
|
90a1d9 |
@@ -2061,6 +2061,8 @@ read_server_hello(gnutls_session_t session,
|
|
|
90a1d9 |
if (ret < 0)
|
|
|
90a1d9 |
return gnutls_assert_val(ret);
|
|
|
90a1d9 |
|
|
|
90a1d9 |
+ session->internals.hsk_flags |= HSK_SERVER_HELLO_RECEIVED;
|
|
|
90a1d9 |
+
|
|
|
90a1d9 |
return 0;
|
|
|
90a1d9 |
}
|
|
|
90a1d9 |
|
|
|
90a1d9 |
@@ -2585,16 +2587,42 @@ int gnutls_rehandshake(gnutls_session_t session)
|
|
|
90a1d9 |
return 0;
|
|
|
90a1d9 |
}
|
|
|
90a1d9 |
|
|
|
90a1d9 |
+/* This function checks whether the error code should be treated fatal
|
|
|
90a1d9 |
+ * or not, and also does the necessary state transition. In
|
|
|
90a1d9 |
+ * particular, in the case of a rehandshake abort it resets the
|
|
|
90a1d9 |
+ * handshake's internal state.
|
|
|
90a1d9 |
+ */
|
|
|
90a1d9 |
inline static int
|
|
|
90a1d9 |
_gnutls_abort_handshake(gnutls_session_t session, int ret)
|
|
|
90a1d9 |
{
|
|
|
90a1d9 |
- if (((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) &&
|
|
|
90a1d9 |
- (gnutls_alert_get(session) == GNUTLS_A_NO_RENEGOTIATION))
|
|
|
90a1d9 |
- || ret == GNUTLS_E_GOT_APPLICATION_DATA)
|
|
|
90a1d9 |
- return 0;
|
|
|
90a1d9 |
+ switch (ret) {
|
|
|
90a1d9 |
+ case GNUTLS_E_WARNING_ALERT_RECEIVED:
|
|
|
90a1d9 |
+ if (gnutls_alert_get(session) == GNUTLS_A_NO_RENEGOTIATION) {
|
|
|
90a1d9 |
+ /* The server always toleretes a "no_renegotiation" alert. */
|
|
|
90a1d9 |
+ if (session->security_parameters.entity == GNUTLS_SERVER) {
|
|
|
90a1d9 |
+ STATE = STATE0;
|
|
|
90a1d9 |
+ return ret;
|
|
|
90a1d9 |
+ }
|
|
|
90a1d9 |
+
|
|
|
90a1d9 |
+ /* The client should tolerete a "no_renegotiation" alert only if:
|
|
|
90a1d9 |
+ * - the initial handshake has completed, or
|
|
|
90a1d9 |
+ * - a Server Hello is not yet received
|
|
|
90a1d9 |
+ */
|
|
|
90a1d9 |
+ if (session->internals.initial_negotiation_completed ||
|
|
|
90a1d9 |
+ !(session->internals.hsk_flags & HSK_SERVER_HELLO_RECEIVED)) {
|
|
|
90a1d9 |
+ STATE = STATE0;
|
|
|
90a1d9 |
+ return ret;
|
|
|
90a1d9 |
+ }
|
|
|
90a1d9 |
|
|
|
90a1d9 |
- /* this doesn't matter */
|
|
|
90a1d9 |
- return GNUTLS_E_INTERNAL_ERROR;
|
|
|
90a1d9 |
+ return gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
|
|
|
90a1d9 |
+ }
|
|
|
90a1d9 |
+ return ret;
|
|
|
90a1d9 |
+ case GNUTLS_E_GOT_APPLICATION_DATA:
|
|
|
90a1d9 |
+ STATE = STATE0;
|
|
|
90a1d9 |
+ return ret;
|
|
|
90a1d9 |
+ default:
|
|
|
90a1d9 |
+ return ret;
|
|
|
90a1d9 |
+ }
|
|
|
90a1d9 |
}
|
|
|
90a1d9 |
|
|
|
90a1d9 |
|
|
|
90a1d9 |
@@ -2756,13 +2784,7 @@ int gnutls_handshake(gnutls_session_t session)
|
|
|
90a1d9 |
}
|
|
|
90a1d9 |
|
|
|
90a1d9 |
if (ret < 0) {
|
|
|
90a1d9 |
- /* In the case of a rehandshake abort
|
|
|
90a1d9 |
- * we should reset the handshake's internal state.
|
|
|
90a1d9 |
- */
|
|
|
90a1d9 |
- if (_gnutls_abort_handshake(session, ret) == 0)
|
|
|
90a1d9 |
- STATE = STATE0;
|
|
|
90a1d9 |
-
|
|
|
90a1d9 |
- return ret;
|
|
|
90a1d9 |
+ return _gnutls_abort_handshake(session, ret);
|
|
|
90a1d9 |
}
|
|
|
90a1d9 |
|
|
|
90a1d9 |
/* clear handshake buffer */
|
|
|
90a1d9 |
--
|
|
|
90a1d9 |
2.26.2
|
|
|
90a1d9 |
|