diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 089d17ea7..b32205259 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2939,6 +2939,28 @@ static int ssl_parse_record_header( ssl_context *ssl ) return( POLARSSL_ERR_SSL_INVALID_RECORD ); } +#if defined(POLARSSL_SSL_PROTO_DTLS) + if( ssl->transport == SSL_TRANSPORT_DATAGRAM ) + { + /* Drop unexpected ChangeCipherSpec messages */ + if( ssl->in_msgtype == SSL_MSG_CHANGE_CIPHER_SPEC && + ssl->state != SSL_CLIENT_CHANGE_CIPHER_SPEC && + ssl->state != SSL_SERVER_CHANGE_CIPHER_SPEC ) + { + SSL_DEBUG_MSG( 1, ( "dropping unexpected ChangeCipherSpec" ) ); + return( POLARSSL_ERR_SSL_INVALID_RECORD ); + } + + /* Drop unexpected ApplicationData records */ + if( ssl->in_msgtype == SSL_MSG_APPLICATION_DATA && + ssl->state != SSL_HANDSHAKE_OVER ) + { + SSL_DEBUG_MSG( 1, ( "dropping unexpected ApplicationData" ) ); + return( POLARSSL_ERR_SSL_INVALID_RECORD ); + } + } +#endif + /* Check version */ if( major_ver != ssl->major_ver ) { @@ -3284,20 +3306,6 @@ read_record_header: } } -#if defined(POLARSSL_SSL_PROTO_DTLS) - if( ssl->transport == SSL_TRANSPORT_DATAGRAM ) - { - /* Drop unexpected ChangeCipherSpec messages */ - if( ssl->in_msgtype == SSL_MSG_CHANGE_CIPHER_SPEC && - ssl->state != SSL_CLIENT_CHANGE_CIPHER_SPEC && - ssl->state != SSL_SERVER_CHANGE_CIPHER_SPEC ) - { - SSL_DEBUG_MSG( 2, ( "dropping unexpected ChangeCipherSpec" ) ); - return( POLARSSL_ERR_NET_WANT_READ ); - } - } -#endif - SSL_DEBUG_MSG( 2, ( "<= read record" ) ); return( 0 ); diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 21130e6a3..759c8f58a 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -959,7 +959,8 @@ run_test "Renegotiation: DTLS, client-initiated" \ run_test "Renegotiation: DTLS, server-initiated" \ "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \ - "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1" \ + "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \ + read_timeout=1000 max_resend=2" \ 0 \ -c "client hello, adding renegotiation extension" \ -s "received TLS_EMPTY_RENEGOTIATION_INFO" \