Merge branch 'mbedtls-2.16' into baremetal
This commit is contained in:
commit
fce6f836ba
27 changed files with 639 additions and 375 deletions
|
@ -263,8 +263,14 @@ int main( void )
|
|||
#endif /* MBEDTLS_SSL_CACHE_C */
|
||||
|
||||
#if defined(SNI_OPTION)
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
#define SNI_CRL ",crl"
|
||||
#else
|
||||
#define SNI_CRL ""
|
||||
#endif
|
||||
|
||||
#define USAGE_SNI \
|
||||
" sni=%%s name1,cert1,key1,ca1,crl1,auth1[,...]\n" \
|
||||
" sni=%%s name1,cert1,key1,ca1"SNI_CRL",auth1[,...]\n" \
|
||||
" default: disabled\n"
|
||||
#else
|
||||
#define USAGE_SNI ""
|
||||
|
@ -600,11 +606,14 @@ static int get_auth_mode( const char *s )
|
|||
* Used by sni_parse and psk_parse to handle coma-separated lists
|
||||
*/
|
||||
#define GET_ITEM( dst ) \
|
||||
dst = p; \
|
||||
while( *p != ',' ) \
|
||||
if( ++p > end ) \
|
||||
goto error; \
|
||||
*p++ = '\0';
|
||||
do \
|
||||
{ \
|
||||
(dst) = p; \
|
||||
while( *p != ',' ) \
|
||||
if( ++p > end ) \
|
||||
goto error; \
|
||||
*p++ = '\0'; \
|
||||
} while( 0 )
|
||||
|
||||
#if defined(SNI_OPTION)
|
||||
typedef struct _sni_entry sni_entry;
|
||||
|
@ -633,10 +642,10 @@ void sni_free( sni_entry *head )
|
|||
|
||||
mbedtls_x509_crt_free( cur->ca );
|
||||
mbedtls_free( cur->ca );
|
||||
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
mbedtls_x509_crl_free( cur->crl );
|
||||
mbedtls_free( cur->crl );
|
||||
|
||||
#endif
|
||||
next = cur->next;
|
||||
mbedtls_free( cur );
|
||||
cur = next;
|
||||
|
@ -655,7 +664,10 @@ sni_entry *sni_parse( char *sni_string )
|
|||
sni_entry *cur = NULL, *new = NULL;
|
||||
char *p = sni_string;
|
||||
char *end = p;
|
||||
char *crt_file, *key_file, *ca_file, *crl_file, *auth_str;
|
||||
char *crt_file, *key_file, *ca_file, *auth_str;
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
char *crl_file;
|
||||
#endif
|
||||
|
||||
while( *end != '\0' )
|
||||
++end;
|
||||
|
@ -673,7 +685,9 @@ sni_entry *sni_parse( char *sni_string )
|
|||
GET_ITEM( crt_file );
|
||||
GET_ITEM( key_file );
|
||||
GET_ITEM( ca_file );
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
GET_ITEM( crl_file );
|
||||
#endif
|
||||
GET_ITEM( auth_str );
|
||||
|
||||
if( ( new->cert = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) ) ) == NULL ||
|
||||
|
@ -698,6 +712,7 @@ sni_entry *sni_parse( char *sni_string )
|
|||
goto error;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
if( strcmp( crl_file, "-" ) != 0 )
|
||||
{
|
||||
if( ( new->crl = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl ) ) ) == NULL )
|
||||
|
@ -708,6 +723,7 @@ sni_entry *sni_parse( char *sni_string )
|
|||
if( mbedtls_x509_crl_parse_file( new->crl, crl_file ) != 0 )
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( strcmp( auth_str, "-" ) != 0 )
|
||||
{
|
||||
|
@ -761,15 +777,18 @@ int sni_callback( void *p_info, mbedtls_ssl_context *ssl,
|
|||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
|
||||
#define HEX2NUM( c ) \
|
||||
if( c >= '0' && c <= '9' ) \
|
||||
c -= '0'; \
|
||||
else if( c >= 'a' && c <= 'f' ) \
|
||||
c -= 'a' - 10; \
|
||||
else if( c >= 'A' && c <= 'F' ) \
|
||||
c -= 'A' - 10; \
|
||||
else \
|
||||
return( -1 );
|
||||
#define HEX2NUM( c ) \
|
||||
do \
|
||||
{ \
|
||||
if( (c) >= '0' && (c) <= '9' ) \
|
||||
(c) -= '0'; \
|
||||
else if( (c) >= 'a' && (c) <= 'f' ) \
|
||||
(c) -= 'a' - 10; \
|
||||
else if( (c) >= 'A' && (c) <= 'F' ) \
|
||||
(c) -= 'A' - 10; \
|
||||
else \
|
||||
return( -1 ); \
|
||||
} while( 0 )
|
||||
|
||||
/*
|
||||
* Convert a hex string to bytes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue