mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 06:14:20 +01:00
d36e33fc07
mbedtls_ssl_set_alpn_protocols mbedtls_ssl_set_arc4_support mbedtls_ssl_set_authmode mbedtls_ssl_set_ciphersuites mbedtls_ssl_set_ciphersuites_for_version mbedtls_ssl_set_curves mbedtls_ssl_set_dbg mbedtls_ssl_set_dh_param mbedtls_ssl_set_dh_param_ctx mbedtls_ssl_set_dtls_anti_replay mbedtls_ssl_set_dtls_badmac_limit mbedtls_ssl_set_dtls_cookies mbedtls_ssl_set_encrypt_then_mac mbedtls_ssl_set_endpoint mbedtls_ssl_set_extended_master_secret mbedtls_ssl_set_handshake_timeout mbedtls_ssl_legacy_renegotiation mbedtls_ssl_set_max_version mbedtls_ssl_set_min_version mbedtls_ssl_set_psk_cb mbedtls_ssl_set_renegotiation mbedtls_ssl_set_renegotiation_enforced mbedtls_ssl_set_renegotiation_period mbedtls_ssl_set_session_cache mbedtls_ssl_set_session_ticket_lifetime mbedtls_ssl_set_sni mbedtls_ssl_set_transport mbedtls_ssl_set_truncated_hmac mbedtls_ssl_set_verify
187 lines
4.9 KiB
Plaintext
187 lines
4.9 KiB
Plaintext
/* BEGIN_HEADER */
|
|
#include "mbedtls/debug.h"
|
|
|
|
struct buffer_data
|
|
{
|
|
char buf[2000];
|
|
char *ptr;
|
|
};
|
|
|
|
void string_debug(void *data, int level, const char *str)
|
|
{
|
|
struct buffer_data *buffer = (struct buffer_data *) data;
|
|
((void) level);
|
|
|
|
memcpy(buffer->ptr, str, strlen(str));
|
|
buffer->ptr += strlen(str);
|
|
|
|
/* Detect if debug messages output partial lines and mark them */
|
|
if( *(buffer->ptr - 1) != '\n' )
|
|
{
|
|
*buffer->ptr = '*';
|
|
buffer->ptr++;
|
|
}
|
|
}
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:MBEDTLS_DEBUG_C:MBEDTLS_SSL_TLS_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
void debug_print_msg_threshold( int threshold, int level, char *file, int line,
|
|
char *result_str )
|
|
{
|
|
mbedtls_ssl_context ssl;
|
|
mbedtls_ssl_config conf;
|
|
struct buffer_data buffer;
|
|
|
|
mbedtls_ssl_init( &ssl );
|
|
mbedtls_ssl_config_init( &conf );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
mbedtls_debug_set_log_mode( MBEDTLS_DEBUG_LOG_FULL );
|
|
mbedtls_debug_set_threshold( threshold );
|
|
mbedtls_ssl_set_dbg( &conf, string_debug, &buffer);
|
|
|
|
mbedtls_debug_print_msg( &ssl, level, file, line,
|
|
mbedtls_debug_fmt("Text message, 2 == %d", 2 ) );
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
exit:
|
|
mbedtls_ssl_free( &ssl );
|
|
mbedtls_ssl_config_free( &conf );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void mbedtls_debug_print_ret( int mode, char *file, int line, char *text, int value,
|
|
char *result_str )
|
|
{
|
|
mbedtls_ssl_context ssl;
|
|
mbedtls_ssl_config conf;
|
|
struct buffer_data buffer;
|
|
|
|
mbedtls_ssl_init( &ssl );
|
|
mbedtls_ssl_config_init( &conf );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
mbedtls_ssl_set_dbg( &conf, string_debug, &buffer);
|
|
|
|
mbedtls_debug_print_ret( &ssl, 0, file, line, text, value);
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
exit:
|
|
mbedtls_ssl_free( &ssl );
|
|
mbedtls_ssl_config_free( &conf );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void mbedtls_debug_print_buf( int mode, char *file, int line, char *text,
|
|
char *data_string, char *result_str )
|
|
{
|
|
unsigned char data[10000];
|
|
mbedtls_ssl_context ssl;
|
|
mbedtls_ssl_config conf;
|
|
struct buffer_data buffer;
|
|
size_t data_len;
|
|
|
|
mbedtls_ssl_init( &ssl );
|
|
mbedtls_ssl_config_init( &conf );
|
|
memset( &data, 0, sizeof( data ) );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
data_len = unhexify( data, data_string );
|
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
mbedtls_ssl_set_dbg( &conf, string_debug, &buffer);
|
|
|
|
mbedtls_debug_print_buf( &ssl, 0, file, line, text, data, data_len );
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
exit:
|
|
mbedtls_ssl_free( &ssl );
|
|
mbedtls_ssl_config_free( &conf );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
|
void mbedtls_debug_print_crt( int mode, char *crt_file, char *file, int line,
|
|
char *prefix, char *result_str )
|
|
{
|
|
mbedtls_x509_crt crt;
|
|
mbedtls_ssl_context ssl;
|
|
mbedtls_ssl_config conf;
|
|
struct buffer_data buffer;
|
|
|
|
mbedtls_ssl_init( &ssl );
|
|
mbedtls_ssl_config_init( &conf );
|
|
mbedtls_x509_crt_init( &crt );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
mbedtls_ssl_set_dbg( &conf, string_debug, &buffer);
|
|
|
|
TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
|
|
mbedtls_debug_print_crt( &ssl, 0, file, line, prefix, &crt);
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
exit:
|
|
mbedtls_x509_crt_free( &crt );
|
|
mbedtls_ssl_free( &ssl );
|
|
mbedtls_ssl_config_free( &conf );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
|
|
void mbedtls_debug_print_mpi( int mode, int radix, char *value, char *file, int line,
|
|
char *prefix, char *result_str )
|
|
{
|
|
mbedtls_ssl_context ssl;
|
|
mbedtls_ssl_config conf;
|
|
struct buffer_data buffer;
|
|
mbedtls_mpi val;
|
|
|
|
mbedtls_ssl_init( &ssl );
|
|
mbedtls_ssl_config_init( &conf );
|
|
mbedtls_mpi_init( &val );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
TEST_ASSERT( mbedtls_mpi_read_string( &val, radix, value ) == 0 );
|
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
mbedtls_ssl_set_dbg( &conf, string_debug, &buffer);
|
|
|
|
mbedtls_debug_print_mpi( &ssl, 0, file, line, prefix, &val);
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
exit:
|
|
mbedtls_mpi_free( &val );
|
|
mbedtls_ssl_free( &ssl );
|
|
mbedtls_ssl_config_free( &conf );
|
|
}
|
|
/* END_CASE */
|