mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge remote-tracking branch 'tls/development' into development
Merge Mbed TLS at f790a6cbee
into Mbed Crypto.
Resolve conflicts by performing the following:
- Reject changes to README.md
- Don't add crypto as a submodule
- Remove test/ssl_cert_test from programs/Makefile
- Add cipher.nist_kw test to tests/CMakeLists.txt
- Reject removal of crypto-specific all.sh tests
- Reject update to SSL-specific portion of component_test_valgrind
in all.sh
- Reject addition of ssl-opt.sh testing to component_test_m32_o1 in
all.sh
* tls/development: (87 commits)
Call mbedtls_cipher_free() to reset a cipher context
Don't call mbedtls_cipher_setkey twice
Update crypto submodule
Minor fixes in get certificate policies oid test
Add certificate policy oid x509 extension
cpp_dummy_build: Add missing header psa_util.h
Clarify comment mangled by an earlier refactoring
Add an "out-of-box" component
Run ssl-opt.sh on 32-bit runtime
Don't use debug level 1 for informational messages
Skip uncritical unsupported extensions
Give credit to OSS-Fuzz for #2404
all.sh: remove component_test_new_ecdh_context
Remove crypto-only related components from all.sh
Remove ssl_cert_test sample app
Make CRT callback tests more robust
Rename constant in client2.c
Document and test flags in x509_verify
Fix style issues and a typo
Fix a rebase error
...
This commit is contained in:
@ -85,7 +85,6 @@ APPS = \
|
||||
random/gen_entropy$(EXEXT) \
|
||||
random/gen_random_havege$(EXEXT) \
|
||||
random/gen_random_ctr_drbg$(EXEXT) \
|
||||
test/ssl_cert_test$(EXEXT) \
|
||||
test/benchmark$(EXEXT) \
|
||||
test/selftest$(EXEXT) \
|
||||
test/udp_proxy$(EXEXT) \
|
||||
@ -277,10 +276,6 @@ ssl/mini_client$(EXEXT): ssl/mini_client.c $(DEP)
|
||||
echo " CC ssl/mini_client.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/mini_client.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
test/ssl_cert_test$(EXEXT): test/ssl_cert_test.c $(DEP)
|
||||
echo " CC test/ssl_cert_test.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/ssl_cert_test.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
test/benchmark$(EXEXT): test/benchmark.c $(DEP)
|
||||
echo " CC test/benchmark.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/benchmark.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
@ -97,8 +97,6 @@ In addition to providing options for testing client-side features, the `ssl_clie
|
||||
|
||||
* [`test/selftest.c`](test/selftest.c): runs the self-test function in each library module.
|
||||
|
||||
* [`test/ssl_cert_test.c`](test/ssl_cert_test.c): demonstrates how to verify X.509 certificates, and (for RSA keys only) how to check that each certificate matches the corresponding private key. This program requires some test data which is not provided.
|
||||
|
||||
* [`test/udp_proxy.c`](test/udp_proxy.c): a UDP proxy that can inject certain failures (delay, duplicate, drop). Useful for testing DTLS.
|
||||
|
||||
* [`test/zeroize.c`](test/zeroize.c): a test program for `mbedtls_platform_zeroize`, used by [`tests/scripts/test_zeroize.gdb`](tests/scripts/test_zeroize.gdb).
|
||||
|
@ -35,6 +35,8 @@
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_fprintf fprintf
|
||||
#define mbedtls_snprintf snprintf
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_exit exit
|
||||
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
||||
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
||||
@ -80,6 +82,7 @@ int main( void )
|
||||
#define DFL_REQUEST_PAGE "/"
|
||||
#define DFL_REQUEST_SIZE -1
|
||||
#define DFL_DEBUG_LEVEL 0
|
||||
#define DFL_CONTEXT_CRT_CB 0
|
||||
#define DFL_NBIO 0
|
||||
#define DFL_EVENT 0
|
||||
#define DFL_READ_TIMEOUT 0
|
||||
@ -122,10 +125,22 @@ int main( void )
|
||||
#define DFL_FALLBACK -1
|
||||
#define DFL_EXTENDED_MS -1
|
||||
#define DFL_ETM -1
|
||||
#define DFL_CA_CALLBACK 0
|
||||
|
||||
|
||||
#define GET_REQUEST "GET %s HTTP/1.0\r\nExtra-header: "
|
||||
#define GET_REQUEST_END "\r\n\r\n"
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#define USAGE_CONTEXT_CRT_CB \
|
||||
" context_crt_cb=%%d This determines whether the CRT verification callback is bound\n" \
|
||||
" to the SSL configuration of the SSL context.\n" \
|
||||
" Possible values:\n"\
|
||||
" - 0 (default): Use CRT callback bound to configuration\n" \
|
||||
" - 1: Use CRT callback bound to SSL context\n"
|
||||
#else
|
||||
#define USAGE_CONTEXT_CRT_CB ""
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
#define USAGE_IO \
|
||||
@ -174,6 +189,14 @@ int main( void )
|
||||
#define USAGE_PSK ""
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
#define USAGE_CA_CALLBACK \
|
||||
" ca_callback=%%d default: 0 (disabled)\n" \
|
||||
" Enable this to use the trusted certificate callback function\n"
|
||||
#else
|
||||
#define USAGE_CA_CALLBACK ""
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||
#define USAGE_TICKETS \
|
||||
" tickets=%%d default: 1 (enabled)\n"
|
||||
@ -312,6 +335,7 @@ int main( void )
|
||||
" options: none, optional, required\n" \
|
||||
USAGE_IO \
|
||||
USAGE_KEY_OPAQUE \
|
||||
USAGE_CA_CALLBACK \
|
||||
"\n" \
|
||||
USAGE_PSK \
|
||||
USAGE_ECJPAKE \
|
||||
@ -326,6 +350,7 @@ int main( void )
|
||||
USAGE_TICKETS \
|
||||
USAGE_MAX_FRAG_LEN \
|
||||
USAGE_TRUNC_HMAC \
|
||||
USAGE_CONTEXT_CRT_CB \
|
||||
USAGE_ALPN \
|
||||
USAGE_FALLBACK \
|
||||
USAGE_EMS \
|
||||
@ -385,6 +410,9 @@ struct options
|
||||
int key_opaque; /* handle private key as if it were opaque */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int psk_opaque;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback; /* Use callback for trusted certificate list */
|
||||
#endif
|
||||
const char *psk; /* the pre-shared key */
|
||||
const char *psk_identity; /* the pre-shared key identity */
|
||||
@ -419,6 +447,7 @@ struct options
|
||||
int dgram_packing; /* allow/forbid datagram packing */
|
||||
int extended_ms; /* negotiate extended master secret? */
|
||||
int etm; /* negotiate encrypt then mac? */
|
||||
int context_crt_cb; /* use context-specific CRT verify callback */
|
||||
} opt;
|
||||
|
||||
int query_config( const char *config );
|
||||
@ -439,6 +468,62 @@ static void my_debug( void *ctx, int level,
|
||||
fflush( (FILE *) ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback( void *data, mbedtls_x509_crt const *child,
|
||||
mbedtls_x509_crt **candidates )
|
||||
{
|
||||
int ret = 0;
|
||||
mbedtls_x509_crt *ca = (mbedtls_x509_crt *) data;
|
||||
mbedtls_x509_crt *first;
|
||||
|
||||
/* This is a test-only implementation of the CA callback
|
||||
* which always returns the entire list of trusted certificates.
|
||||
* Production implementations managing a large number of CAs
|
||||
* should use an efficient presentation and lookup for the
|
||||
* set of trusted certificates (such as a hashtable) and only
|
||||
* return those trusted certificates which satisfy basic
|
||||
* parental checks, such as the matching of child `Issuer`
|
||||
* and parent `Subject` field or matching key identifiers. */
|
||||
((void) child);
|
||||
|
||||
first = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
|
||||
if( first == NULL )
|
||||
{
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
mbedtls_x509_crt_init( first );
|
||||
|
||||
if( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) != 0 )
|
||||
{
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
while( ca->next != NULL )
|
||||
{
|
||||
ca = ca->next;
|
||||
if( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) != 0 )
|
||||
{
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_x509_crt_free( first );
|
||||
mbedtls_free( first );
|
||||
first = NULL;
|
||||
}
|
||||
|
||||
*candidates = first;
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
|
||||
/*
|
||||
* Test recv/send functions that make sure each try returns
|
||||
* WANT_READ/WANT_WRITE at least once before sucesseding
|
||||
@ -685,6 +770,7 @@ int main( int argc, char *argv[] )
|
||||
opt.debug_level = DFL_DEBUG_LEVEL;
|
||||
opt.nbio = DFL_NBIO;
|
||||
opt.event = DFL_EVENT;
|
||||
opt.context_crt_cb = DFL_CONTEXT_CRT_CB;
|
||||
opt.read_timeout = DFL_READ_TIMEOUT;
|
||||
opt.max_resend = DFL_MAX_RESEND;
|
||||
opt.request_page = DFL_REQUEST_PAGE;
|
||||
@ -697,6 +783,9 @@ int main( int argc, char *argv[] )
|
||||
opt.psk = DFL_PSK;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
opt.psk_opaque = DFL_PSK_OPAQUE;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
opt.ca_callback = DFL_CA_CALLBACK;
|
||||
#endif
|
||||
opt.psk_identity = DFL_PSK_IDENTITY;
|
||||
opt.ecjpake_pw = DFL_ECJPAKE_PW;
|
||||
@ -759,6 +848,12 @@ int main( int argc, char *argv[] )
|
||||
if( opt.debug_level < 0 || opt.debug_level > 65535 )
|
||||
goto usage;
|
||||
}
|
||||
else if( strcmp( p, "context_crt_cb" ) == 0 )
|
||||
{
|
||||
opt.context_crt_cb = atoi( q );
|
||||
if( opt.context_crt_cb != 0 && opt.context_crt_cb != 1 )
|
||||
goto usage;
|
||||
}
|
||||
else if( strcmp( p, "nbio" ) == 0 )
|
||||
{
|
||||
opt.nbio = atoi( q );
|
||||
@ -805,6 +900,10 @@ int main( int argc, char *argv[] )
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
else if( strcmp( p, "psk_opaque" ) == 0 )
|
||||
opt.psk_opaque = atoi( q );
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
else if( strcmp( p, "ca_callback" ) == 0)
|
||||
opt.ca_callback = atoi( q );
|
||||
#endif
|
||||
else if( strcmp( p, "psk_identity" ) == 0 )
|
||||
opt.psk_identity = q;
|
||||
@ -1511,7 +1610,9 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_ssl_conf_sig_hashes( &conf, ssl_sig_hashes_for_test );
|
||||
}
|
||||
|
||||
mbedtls_ssl_conf_verify( &conf, my_verify, NULL );
|
||||
if( opt.context_crt_cb == 0 )
|
||||
mbedtls_ssl_conf_verify( &conf, my_verify, NULL );
|
||||
|
||||
memset( peer_crt_info, 0, sizeof( peer_crt_info ) );
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
@ -1600,7 +1701,12 @@ int main( int argc, char *argv[] )
|
||||
if( strcmp( opt.ca_path, "none" ) != 0 &&
|
||||
strcmp( opt.ca_file, "none" ) != 0 )
|
||||
{
|
||||
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
if( opt.ca_callback != 0 )
|
||||
mbedtls_ssl_conf_ca_cb( &conf, ca_callback, &cacert );
|
||||
else
|
||||
#endif
|
||||
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||
}
|
||||
if( strcmp( opt.crt_file, "none" ) != 0 &&
|
||||
strcmp( opt.key_file, "none" ) != 0 )
|
||||
@ -1715,6 +1821,11 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
if( opt.context_crt_cb == 1 )
|
||||
mbedtls_ssl_set_verify( &ssl, my_verify, NULL );
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
if( opt.nbio == 2 )
|
||||
mbedtls_ssl_set_bio( &ssl, &server_fd, my_send, my_recv, NULL );
|
||||
else
|
||||
|
@ -110,9 +110,9 @@ int main( void )
|
||||
|
||||
#if defined(MBEDTLS_BASE64_C)
|
||||
#define USAGE_AUTH \
|
||||
" authentication=%%d default: 0 (disabled)\n" \
|
||||
" user_name=%%s default: \"user\"\n" \
|
||||
" user_pwd=%%s default: \"password\"\n"
|
||||
" authentication=%%d default: 0 (disabled)\n" \
|
||||
" user_name=%%s default: \"" DFL_USER_NAME "\"\n" \
|
||||
" user_pwd=%%s default: \"" DFL_USER_PWD "\"\n"
|
||||
#else
|
||||
#define USAGE_AUTH \
|
||||
" authentication options disabled. (Require MBEDTLS_BASE64_C)\n"
|
||||
@ -129,17 +129,17 @@ int main( void )
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#define USAGE \
|
||||
"\n usage: ssl_mail_client param=<>...\n" \
|
||||
"\n acceptable parameters:\n" \
|
||||
" server_name=%%s default: localhost\n" \
|
||||
" server_port=%%d default: 4433\n" \
|
||||
" debug_level=%%d default: 0 (disabled)\n" \
|
||||
"\n usage: ssl_mail_client param=<>...\n" \
|
||||
"\n acceptable parameters:\n" \
|
||||
" server_name=%%s default: " DFL_SERVER_NAME "\n" \
|
||||
" server_port=%%d default: " DFL_SERVER_PORT "\n" \
|
||||
" debug_level=%%d default: 0 (disabled)\n" \
|
||||
" mode=%%d default: 0 (SSL/TLS) (1 for STARTTLS)\n" \
|
||||
USAGE_AUTH \
|
||||
" mail_from=%%s default: \"\"\n" \
|
||||
" mail_to=%%s default: \"\"\n" \
|
||||
USAGE_IO \
|
||||
" force_ciphersuite=<name> default: all enabled\n"\
|
||||
USAGE_AUTH \
|
||||
" mail_from=%%s default: \"\"\n" \
|
||||
" mail_to=%%s default: \"\"\n" \
|
||||
USAGE_IO \
|
||||
" force_ciphersuite=<name> default: all enabled\n" \
|
||||
" acceptable ciphersuite names:\n"
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
@ -324,7 +324,7 @@ static int write_and_get_response( mbedtls_net_context *sock_fd, unsigned char *
|
||||
mbedtls_printf("\n%s", buf);
|
||||
if( len && ( ret = mbedtls_net_send( sock_fd, buf, len ) ) <= 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
|
||||
mbedtls_printf( " failed\n ! mbedtls_net_send returned %d\n\n", ret );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ static int write_and_get_response( mbedtls_net_context *sock_fd, unsigned char *
|
||||
|
||||
if( ret <= 0 )
|
||||
{
|
||||
mbedtls_printf( "failed\n ! read returned %d\n\n", ret );
|
||||
mbedtls_printf( "failed\n ! mbedtls_net_recv returned %d\n\n", ret );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_time time
|
||||
#define mbedtls_time_t time_t
|
||||
@ -166,6 +167,7 @@ int main( void )
|
||||
#define DFL_DGRAM_PACKING 1
|
||||
#define DFL_EXTENDED_MS -1
|
||||
#define DFL_ETM -1
|
||||
#define DFL_CA_CALLBACK 0
|
||||
|
||||
#define LONG_RESPONSE "<p>01-blah-blah-blah-blah-blah-blah-blah-blah-blah\r\n" \
|
||||
"02-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah\r\n" \
|
||||
@ -264,7 +266,13 @@ int main( void )
|
||||
#else
|
||||
#define USAGE_PSK ""
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
#define USAGE_CA_CALLBACK \
|
||||
" ca_callback=%%d default: 0 (disabled)\n" \
|
||||
" Enable this to use the trusted certificate callback function\n"
|
||||
#else
|
||||
#define USAGE_CA_CALLBACK ""
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||
#define USAGE_TICKETS \
|
||||
" tickets=%%d default: 1 (enabled)\n" \
|
||||
@ -420,6 +428,7 @@ int main( void )
|
||||
USAGE_SNI \
|
||||
"\n" \
|
||||
USAGE_PSK \
|
||||
USAGE_CA_CALLBACK \
|
||||
USAGE_ECJPAKE \
|
||||
"\n" \
|
||||
" allow_legacy=%%d default: (library default: no)\n" \
|
||||
@ -506,6 +515,9 @@ struct options
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int psk_opaque;
|
||||
int psk_list_opaque;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback; /* Use callback for trusted certificate list */
|
||||
#endif
|
||||
const char *psk; /* the pre-shared key */
|
||||
const char *psk_identity; /* the pre-shared key identity */
|
||||
@ -564,6 +576,62 @@ static void my_debug( void *ctx, int level,
|
||||
fflush( (FILE *) ctx );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback( void *data, mbedtls_x509_crt const *child,
|
||||
mbedtls_x509_crt **candidates)
|
||||
{
|
||||
int ret = 0;
|
||||
mbedtls_x509_crt *ca = (mbedtls_x509_crt *) data;
|
||||
mbedtls_x509_crt *first;
|
||||
|
||||
/* This is a test-only implementation of the CA callback
|
||||
* which always returns the entire list of trusted certificates.
|
||||
* Production implementations managing a large number of CAs
|
||||
* should use an efficient presentation and lookup for the
|
||||
* set of trusted certificates (such as a hashtable) and only
|
||||
* return those trusted certificates which satisfy basic
|
||||
* parental checks, such as the matching of child `Issuer`
|
||||
* and parent `Subject` field. */
|
||||
((void) child);
|
||||
|
||||
first = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );
|
||||
if( first == NULL )
|
||||
{
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
mbedtls_x509_crt_init( first );
|
||||
|
||||
if( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) != 0 )
|
||||
{
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
while( ca->next != NULL )
|
||||
{
|
||||
ca = ca->next;
|
||||
if( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) != 0 )
|
||||
{
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_x509_crt_free( first );
|
||||
mbedtls_free( first );
|
||||
first = NULL;
|
||||
}
|
||||
|
||||
*candidates = first;
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
|
||||
/*
|
||||
* Test recv/send functions that make sure each try returns
|
||||
* WANT_READ/WANT_WRITE at least once before sucesseding
|
||||
@ -1457,6 +1525,9 @@ int main( int argc, char *argv[] )
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
opt.psk_opaque = DFL_PSK_OPAQUE;
|
||||
opt.psk_list_opaque = DFL_PSK_LIST_OPAQUE;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
opt.ca_callback = DFL_CA_CALLBACK;
|
||||
#endif
|
||||
opt.psk_identity = DFL_PSK_IDENTITY;
|
||||
opt.psk_list = DFL_PSK_LIST;
|
||||
@ -1591,6 +1662,10 @@ int main( int argc, char *argv[] )
|
||||
opt.psk_opaque = atoi( q );
|
||||
else if( strcmp( p, "psk_list_opaque" ) == 0 )
|
||||
opt.psk_list_opaque = atoi( q );
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
else if( strcmp( p, "ca_callback" ) == 0)
|
||||
opt.ca_callback = atoi( q );
|
||||
#endif
|
||||
else if( strcmp( p, "psk_identity" ) == 0 )
|
||||
opt.psk_identity = q;
|
||||
@ -2570,7 +2645,12 @@ int main( int argc, char *argv[] )
|
||||
if( strcmp( opt.ca_path, "none" ) != 0 &&
|
||||
strcmp( opt.ca_file, "none" ) != 0 )
|
||||
{
|
||||
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
if( opt.ca_callback != 0 )
|
||||
mbedtls_ssl_conf_ca_cb( &conf, ca_callback, &cacert);
|
||||
else
|
||||
#endif
|
||||
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||
}
|
||||
if( key_cert_init )
|
||||
{
|
||||
|
@ -21,9 +21,6 @@ if(TEST_CPP)
|
||||
target_link_libraries(cpp_dummy_build ${libs})
|
||||
endif()
|
||||
|
||||
add_executable(ssl_cert_test ssl_cert_test.c)
|
||||
target_link_libraries(ssl_cert_test ${libs})
|
||||
|
||||
add_executable(udp_proxy udp_proxy.c)
|
||||
target_link_libraries(udp_proxy ${libs})
|
||||
|
||||
@ -34,6 +31,6 @@ add_executable(query_compile_time_config query_compile_time_config.c)
|
||||
target_sources(query_compile_time_config PUBLIC query_config.c)
|
||||
target_link_libraries(query_compile_time_config ${libs})
|
||||
|
||||
install(TARGETS selftest benchmark ssl_cert_test udp_proxy query_compile_time_config
|
||||
install(TARGETS selftest benchmark udp_proxy query_compile_time_config
|
||||
DESTINATION "bin"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
|
@ -80,6 +80,7 @@
|
||||
#include "mbedtls/platform_time.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/poly1305.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "mbedtls/ripemd160.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/rsa_internal.h"
|
||||
|
@ -1506,6 +1506,14 @@ int query_config( const char *config )
|
||||
}
|
||||
#endif /* MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION */
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
if( strcmp( "MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK", config ) == 0 )
|
||||
{
|
||||
MACRO_EXPANSION_TO_STR( MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
|
||||
|
||||
#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
|
||||
if( strcmp( "MBEDTLS_X509_CHECK_KEY_USAGE", config ) == 0 )
|
||||
{
|
||||
|
@ -1,274 +0,0 @@
|
||||
/*
|
||||
* SSL certificate functionality tests
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_snprintf snprintf
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_exit exit
|
||||
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
||||
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||
defined(MBEDTLS_FS_IO) && defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
#include "mbedtls/certs.h"
|
||||
#include "mbedtls/x509_crt.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#define MAX_CLIENT_CERTS 8
|
||||
|
||||
#if !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
int main( void )
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_RSA_C and/or MBEDTLS_X509_CRT_PARSE_C "
|
||||
"MBEDTLS_FS_IO and/or MBEDTLS_X509_CRL_PARSE_C "
|
||||
"not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
const char *client_certificates[MAX_CLIENT_CERTS] =
|
||||
{
|
||||
"client1.crt",
|
||||
"client2.crt",
|
||||
"server1.crt",
|
||||
"server2.crt",
|
||||
"cert_sha224.crt",
|
||||
"cert_sha256.crt",
|
||||
"cert_sha384.crt",
|
||||
"cert_sha512.crt"
|
||||
};
|
||||
|
||||
const char *client_private_keys[MAX_CLIENT_CERTS] =
|
||||
{
|
||||
"client1.key",
|
||||
"client2.key",
|
||||
"server1.key",
|
||||
"server2.key",
|
||||
"cert_digest.key",
|
||||
"cert_digest.key",
|
||||
"cert_digest.key",
|
||||
"cert_digest.key"
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
#include "mbedtls/platform_util.h"
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
mbedtls_printf( "%s:%i: Input param failed - %s\n",
|
||||
file, line, failure_condition );
|
||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
#endif
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int ret = 1, i;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
mbedtls_x509_crt cacert;
|
||||
mbedtls_x509_crl crl;
|
||||
char buf[10240];
|
||||
|
||||
mbedtls_x509_crt_init( &cacert );
|
||||
mbedtls_x509_crl_init( &crl );
|
||||
|
||||
/*
|
||||
* 1.1. Load the trusted CA
|
||||
*/
|
||||
mbedtls_printf( "\n . Loading the CA root certificate ..." );
|
||||
fflush( stdout );
|
||||
|
||||
/*
|
||||
* Alternatively, you may load the CA certificates from a .pem or
|
||||
* .crt file by calling mbedtls_x509_crt_parse_file( &cacert, "myca.crt" ).
|
||||
*/
|
||||
ret = mbedtls_x509_crt_parse_file( &cacert, "ssl/test-ca/test-ca.crt" );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
mbedtls_x509_crt_info( buf, 1024, "CRT: ", &cacert );
|
||||
mbedtls_printf("%s\n", buf );
|
||||
|
||||
/*
|
||||
* 1.2. Load the CRL
|
||||
*/
|
||||
mbedtls_printf( " . Loading the CRL ..." );
|
||||
fflush( stdout );
|
||||
|
||||
ret = mbedtls_x509_crl_parse_file( &crl, "ssl/test-ca/crl.pem" );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_x509_crl_parse_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
mbedtls_x509_crl_info( buf, 1024, "CRL: ", &crl );
|
||||
mbedtls_printf("%s\n", buf );
|
||||
|
||||
for( i = 0; i < MAX_CLIENT_CERTS; i++ )
|
||||
{
|
||||
/*
|
||||
* 1.3. Load own certificate
|
||||
*/
|
||||
char name[512];
|
||||
uint32_t flags;
|
||||
mbedtls_x509_crt clicert;
|
||||
mbedtls_pk_context pk;
|
||||
|
||||
mbedtls_x509_crt_init( &clicert );
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
mbedtls_snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]);
|
||||
|
||||
mbedtls_printf( " . Loading the client certificate %s...", name );
|
||||
fflush( stdout );
|
||||
|
||||
ret = mbedtls_x509_crt_parse_file( &clicert, name );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* 1.4. Verify certificate validity with CA certificate
|
||||
*/
|
||||
mbedtls_printf( " . Verify the client certificate with CA certificate..." );
|
||||
fflush( stdout );
|
||||
|
||||
ret = mbedtls_x509_crt_verify( &clicert, &cacert, &crl, NULL, &flags, NULL,
|
||||
NULL );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED )
|
||||
{
|
||||
char vrfy_buf[512];
|
||||
|
||||
mbedtls_printf( " failed\n" );
|
||||
mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags );
|
||||
mbedtls_printf( "%s\n", vrfy_buf );
|
||||
}
|
||||
else
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_x509_crt_verify returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* 1.5. Load own private key
|
||||
*/
|
||||
mbedtls_snprintf(name, 512, "ssl/test-ca/%s", client_private_keys[i]);
|
||||
|
||||
mbedtls_printf( " . Loading the client private key %s...", name );
|
||||
fflush( stdout );
|
||||
|
||||
ret = mbedtls_pk_parse_keyfile( &pk, name, NULL );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* 1.6. Verify certificate validity with private key
|
||||
*/
|
||||
mbedtls_printf( " . Verify the client certificate with private key..." );
|
||||
fflush( stdout );
|
||||
|
||||
|
||||
/* EC NOT IMPLEMENTED YET */
|
||||
if( ! mbedtls_pk_can_do( &clicert.pk, MBEDTLS_PK_RSA ) )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! certificate's key is not RSA\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_mpi_cmp_mpi(&mbedtls_pk_rsa( pk )->N, &mbedtls_pk_rsa( clicert.pk )->N);
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_mpi_cmp_mpi for N returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_mpi_cmp_mpi(&mbedtls_pk_rsa( pk )->E, &mbedtls_pk_rsa( clicert.pk )->E);
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_mpi_cmp_mpi for E returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_rsa_check_privkey( mbedtls_pk_rsa( pk ) );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_rsa_check_privkey returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
mbedtls_x509_crt_free( &clicert );
|
||||
mbedtls_pk_free( &pk );
|
||||
}
|
||||
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
exit:
|
||||
mbedtls_x509_crt_free( &cacert );
|
||||
mbedtls_x509_crl_free( &crl );
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
return( exit_code );
|
||||
}
|
||||
#endif /* MBEDTLS_RSA_C && MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_FS_IO &&
|
||||
MBEDTLS_X509_CRL_PARSE_C */
|
Reference in New Issue
Block a user