mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-02 04:35:43 +01:00
Implement initial negotiation of EtM
Not implemented yet: - actually using EtM - conditions on renegotiation
This commit is contained in:
parent
b3c6a97b31
commit
699cafaea2
9 changed files with 308 additions and 2 deletions
|
|
@ -359,6 +359,32 @@ static void ssl_write_truncated_hmac_ext( ssl_context *ssl,
|
|||
}
|
||||
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
static void ssl_write_encrypt_then_mac_ext( ssl_context *ssl,
|
||||
unsigned char *buf, size_t *olen )
|
||||
{
|
||||
unsigned char *p = buf;
|
||||
|
||||
if( ssl->encrypt_then_mac == SSL_ETM_DISABLED ||
|
||||
ssl->max_minor_ver == SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
*olen = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
SSL_DEBUG_MSG( 3, ( "client hello, adding encrypt_then_mac "
|
||||
"extension" ) );
|
||||
|
||||
*p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC >> 8 ) & 0xFF );
|
||||
*p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC ) & 0xFF );
|
||||
|
||||
*p++ = 0x00;
|
||||
*p++ = 0x00;
|
||||
|
||||
*olen = 4;
|
||||
}
|
||||
#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
static void ssl_write_extended_ms_ext( ssl_context *ssl,
|
||||
unsigned char *buf, size_t *olen )
|
||||
|
|
@ -688,6 +714,11 @@ static int ssl_write_client_hello( ssl_context *ssl )
|
|||
ext_len += olen;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
ssl_write_encrypt_then_mac_ext( ssl, p + 2 + ext_len, &olen );
|
||||
ext_len += olen;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
ssl_write_extended_ms_ext( ssl, p + 2 + ext_len, &olen );
|
||||
ext_len += olen;
|
||||
|
|
@ -811,6 +842,26 @@ static int ssl_parse_truncated_hmac_ext( ssl_context *ssl,
|
|||
}
|
||||
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
static int ssl_parse_encrypt_then_mac_ext( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
size_t len )
|
||||
{
|
||||
if( ssl->encrypt_then_mac == SSL_ETM_DISABLED ||
|
||||
ssl->minor_ver == SSL_MINOR_VERSION_0 ||
|
||||
len != 0 )
|
||||
{
|
||||
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
|
||||
}
|
||||
|
||||
((void) buf);
|
||||
|
||||
ssl->session_negotiate->encrypt_then_mac = SSL_ETM_ENABLED;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
static int ssl_parse_extended_ms_ext( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
|
|
@ -1203,6 +1254,19 @@ static int ssl_parse_server_hello( ssl_context *ssl )
|
|||
break;
|
||||
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
case TLS_EXT_ENCRYPT_THEN_MAC:
|
||||
SSL_DEBUG_MSG( 3, ( "found encrypt_then_mac extension" ) );
|
||||
|
||||
if( ( ret = ssl_parse_encrypt_then_mac_ext( ssl,
|
||||
ext + 4, ext_size ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
break;
|
||||
#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
case TLS_EXT_EXTENDED_MASTER_SECRET:
|
||||
SSL_DEBUG_MSG( 3, ( "found extended_master_secret extension" ) );
|
||||
|
|
|
|||
|
|
@ -635,6 +635,29 @@ static int ssl_parse_truncated_hmac_ext( ssl_context *ssl,
|
|||
}
|
||||
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
static int ssl_parse_encrypt_then_mac_ext( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
size_t len )
|
||||
{
|
||||
if( len != 0 )
|
||||
{
|
||||
SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
|
||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
}
|
||||
|
||||
((void) buf);
|
||||
|
||||
if( ssl->encrypt_then_mac == SSL_ETM_ENABLED &&
|
||||
ssl->minor_ver != SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
ssl->session_negotiate->encrypt_then_mac = SSL_ETM_ENABLED;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
static int ssl_parse_extended_ms_ext( ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
|
|
@ -1523,6 +1546,16 @@ static int ssl_parse_client_hello( ssl_context *ssl )
|
|||
break;
|
||||
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
case TLS_EXT_ENCRYPT_THEN_MAC:
|
||||
SSL_DEBUG_MSG( 3, ( "found encrypt then mac extension" ) );
|
||||
|
||||
ret = ssl_parse_encrypt_then_mac_ext( ssl, ext + 4, ext_size );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
break;
|
||||
#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
case TLS_EXT_EXTENDED_MASTER_SECRET:
|
||||
SSL_DEBUG_MSG( 3, ( "found extended master secret extension" ) );
|
||||
|
|
@ -1682,6 +1715,32 @@ static void ssl_write_truncated_hmac_ext( ssl_context *ssl,
|
|||
}
|
||||
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
static void ssl_write_encrypt_then_mac_ext( ssl_context *ssl,
|
||||
unsigned char *buf,
|
||||
size_t *olen )
|
||||
{
|
||||
unsigned char *p = buf;
|
||||
|
||||
if( ssl->session_negotiate->encrypt_then_mac == SSL_EXTENDED_MS_DISABLED ||
|
||||
ssl->minor_ver == SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
*olen = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
SSL_DEBUG_MSG( 3, ( "server hello, adding encrypt then mac extension" ) );
|
||||
|
||||
*p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC >> 8 ) & 0xFF );
|
||||
*p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC ) & 0xFF );
|
||||
|
||||
*p++ = 0x00;
|
||||
*p++ = 0x00;
|
||||
|
||||
*olen = 4;
|
||||
}
|
||||
#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
static void ssl_write_extended_ms_ext( ssl_context *ssl,
|
||||
unsigned char *buf,
|
||||
|
|
@ -2012,6 +2071,11 @@ static int ssl_write_server_hello( ssl_context *ssl )
|
|||
ext_len += olen;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
ssl_write_encrypt_then_mac_ext( ssl, p + 2 + ext_len, &olen );
|
||||
ext_len += olen;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
ssl_write_extended_ms_ext( ssl, p + 2 + ext_len, &olen );
|
||||
ext_len += olen;
|
||||
|
|
|
|||
|
|
@ -1071,6 +1071,15 @@ static int ssl_encrypt_buf( ssl_context *ssl )
|
|||
|
||||
SSL_DEBUG_MSG( 2, ( "=> encrypt buf" ) );
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
if( ssl->session_out != NULL &&
|
||||
ssl->session_out->encrypt_then_mac == SSL_ETM_ENABLED )
|
||||
{
|
||||
// WIP
|
||||
SSL_DEBUG_MSG( 3, ( "using encrypt then mac" ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add MAC before encrypt, except for AEAD modes
|
||||
*/
|
||||
|
|
@ -3474,6 +3483,10 @@ int ssl_init( ssl_context *ssl )
|
|||
memset( ssl-> in_ctr, 0, SSL_BUFFER_LEN );
|
||||
memset( ssl->out_ctr, 0, SSL_BUFFER_LEN );
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
ssl->encrypt_then_mac = SSL_ETM_ENABLED;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
ssl->extended_ms = SSL_EXTENDED_MS_ENABLED;
|
||||
#endif
|
||||
|
|
@ -4025,6 +4038,13 @@ void ssl_set_fallback( ssl_context *ssl, char fallback )
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
|
||||
void ssl_set_encrypt_then_mac( ssl_context *ssl, char etm )
|
||||
{
|
||||
ssl->encrypt_then_mac = etm;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
|
||||
void ssl_set_extended_master_secret( ssl_context *ssl, char ems )
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue