mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-28 00:21:48 +03:00
More granular define selections within code to allow for smaller code
sizes
This commit is contained in:
@ -39,6 +39,19 @@
|
||||
#include "polarssl/base64.h"
|
||||
#include "polarssl/x509write.h"
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_X509_WRITE_C) || !defined(POLARSSL_FS_IO)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_X509_WRITE_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
||||
#define MODE_NONE 0
|
||||
#define MODE_PRIVATE 1
|
||||
#define MODE_PUBLIC 2
|
||||
@ -157,18 +170,6 @@ void write_private_key( rsa_context *rsa, char *output_file )
|
||||
" output_file=%%s defeult: keyfile.pem\n" \
|
||||
"\n"
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 0;
|
||||
@ -336,4 +337,4 @@ exit:
|
||||
return( ret );
|
||||
}
|
||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C &&
|
||||
POLARSSL_X509_PARSE_C && POLARSSL_FS_IO */
|
||||
POLARSSL_X509_WRITE_C && POLARSSL_FS_IO */
|
||||
|
@ -57,7 +57,7 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_CTR_DRBG_C) || !defined(POLARSSL_X509_PARSE_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
@ -66,7 +66,8 @@ int main( int argc, char *argv[] )
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_PARSE_C "
|
||||
"not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
@ -92,6 +92,7 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
/*
|
||||
* Enabled if debug_level > 1 in code below
|
||||
*/
|
||||
@ -130,7 +131,9 @@ int my_verify( void *data, x509_cert *crt, int depth, int *flags )
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
#if defined(POLARSSL_FS_IO)
|
||||
#define USAGE_IO \
|
||||
" ca_file=%%s The single file containing the top-level CA(s) you fully trust\n" \
|
||||
@ -144,6 +147,17 @@ int my_verify( void *data, x509_cert *crt, int depth, int *flags )
|
||||
#define USAGE_IO \
|
||||
" No file operations available (POLARSSL_FS_IO not defined)\n"
|
||||
#endif /* POLARSSL_FS_IO */
|
||||
#else
|
||||
#define USAGE_IO ""
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
#define USAGE_PSK \
|
||||
" psk=%%s default: \"\" (in hex, without 0x)\n" \
|
||||
" psk_identity=%%s default: \"Client_identity\"\n"
|
||||
#else
|
||||
#define USAGE_PSK ""
|
||||
#endif /* POLARSSL_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
#define USAGE \
|
||||
"\n usage: ssl_client2 param=<>...\n" \
|
||||
@ -162,25 +176,22 @@ int my_verify( void *data, x509_cert *crt, int depth, int *flags )
|
||||
" options: ssl3, tls1, tls1_1, tls1_2\n" \
|
||||
" auth_mode=%%s default: \"optional\"\n" \
|
||||
" options: none, optional, required\n" \
|
||||
" psk=%%s default: \"\" (in hex, without 0x)\n" \
|
||||
" psk_identity=%%s default: \"Client_identity\"\n" \
|
||||
USAGE_PSK \
|
||||
"\n" \
|
||||
" force_ciphersuite=<name> default: all enabled\n"\
|
||||
" acceptable ciphersuite names:\n"
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||
#if !defined(POLARSSL_ENTROPY_C) || \
|
||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
printf("POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_NET_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
@ -188,16 +199,20 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 0, len, server_fd, i;
|
||||
unsigned char buf[1024];
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
unsigned char psk[256];
|
||||
size_t psk_len = 0;
|
||||
#endif
|
||||
char *pers = "ssl_client2";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
ssl_context ssl;
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
x509_cert cacert;
|
||||
x509_cert clicert;
|
||||
rsa_context rsa;
|
||||
#endif
|
||||
char *p, *q;
|
||||
const int *list;
|
||||
|
||||
@ -206,9 +221,11 @@ int main( int argc, char *argv[] )
|
||||
*/
|
||||
server_fd = 0;
|
||||
memset( &ssl, 0, sizeof( ssl_context ) );
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
||||
memset( &clicert, 0, sizeof( x509_cert ) );
|
||||
memset( &rsa, 0, sizeof( rsa_context ) );
|
||||
#endif
|
||||
|
||||
if( argc == 0 )
|
||||
{
|
||||
@ -221,7 +238,11 @@ int main( int argc, char *argv[] )
|
||||
list = ssl_list_ciphersuites();
|
||||
while( *list )
|
||||
{
|
||||
printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
|
||||
printf(" %-40s", ssl_get_ciphersuite_name( *list ) );
|
||||
list++;
|
||||
if( !*list )
|
||||
break;
|
||||
printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
|
||||
list++;
|
||||
}
|
||||
printf("\n");
|
||||
@ -370,6 +391,7 @@ int main( int argc, char *argv[] )
|
||||
goto usage;
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
/*
|
||||
* Unhexify the pre-shared key if any is given
|
||||
*/
|
||||
@ -417,6 +439,7 @@ int main( int argc, char *argv[] )
|
||||
psk[ j / 2 ] |= c;
|
||||
}
|
||||
}
|
||||
#endif /* POLARSSL_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
/*
|
||||
* 0. Initialize the RNG and the session data
|
||||
@ -434,6 +457,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
printf( " ok\n" );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
/*
|
||||
* 1.1. Load the trusted CA
|
||||
*/
|
||||
@ -445,7 +469,7 @@ int main( int argc, char *argv[] )
|
||||
ret = x509parse_crtpath( &cacert, opt.ca_path );
|
||||
else if( strlen( opt.ca_file ) )
|
||||
ret = x509parse_crtfile( &cacert, opt.ca_file );
|
||||
else
|
||||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &cacert, (unsigned char *) test_ca_crt,
|
||||
@ -475,7 +499,7 @@ int main( int argc, char *argv[] )
|
||||
#if defined(POLARSSL_FS_IO)
|
||||
if( strlen( opt.crt_file ) )
|
||||
ret = x509parse_crtfile( &clicert, opt.crt_file );
|
||||
else
|
||||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &clicert, (unsigned char *) test_cli_crt,
|
||||
@ -513,6 +537,7 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
/*
|
||||
* 2. Start the connection
|
||||
@ -544,8 +569,10 @@ int main( int argc, char *argv[] )
|
||||
|
||||
printf( " ok\n" );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
if( opt.debug_level > 0 )
|
||||
ssl_set_verify( &ssl, my_verify, NULL );
|
||||
#endif
|
||||
|
||||
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
||||
ssl_set_authmode( &ssl, opt.auth_mode );
|
||||
@ -561,10 +588,16 @@ int main( int argc, char *argv[] )
|
||||
ssl_set_renegotiation( &ssl, opt.renegotiation );
|
||||
ssl_legacy_renegotiation( &ssl, opt.allow_legacy );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
ssl_set_ca_chain( &ssl, &cacert, NULL, opt.server_name );
|
||||
ssl_set_own_cert( &ssl, &clicert, &rsa );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
ssl_set_psk( &ssl, psk, psk_len, (unsigned char *) opt.psk_identity,
|
||||
strlen( opt.psk_identity ) );
|
||||
#endif
|
||||
|
||||
ssl_set_hostname( &ssl, opt.server_name );
|
||||
|
||||
if( opt.min_version != -1 )
|
||||
@ -590,6 +623,7 @@ int main( int argc, char *argv[] )
|
||||
printf( " ok\n [ Ciphersuite is %s ]\n",
|
||||
ssl_get_ciphersuite( &ssl ) );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
/*
|
||||
* 5. Verify the server certificate
|
||||
*/
|
||||
@ -623,6 +657,7 @@ int main( int argc, char *argv[] )
|
||||
ssl_get_peer_cert( &ssl ) );
|
||||
printf( "%s\n", buf );
|
||||
}
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
/*
|
||||
* 6. Write the GET request
|
||||
@ -694,9 +729,11 @@ exit:
|
||||
|
||||
if( server_fd )
|
||||
net_close( server_fd );
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
x509_free( &clicert );
|
||||
x509_free( &cacert );
|
||||
rsa_free( &rsa );
|
||||
#endif
|
||||
ssl_free( &ssl );
|
||||
|
||||
memset( &ssl, 0, sizeof( ssl ) );
|
||||
|
@ -55,7 +55,8 @@
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
|
||||
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_SSL_TLS_C) || \
|
||||
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C) || \
|
||||
!defined(POLARSSL_X509_PARSE_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
@ -64,7 +65,7 @@ int main( int argc, char *argv[] )
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
|
||||
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_PARSE_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
|
@ -104,7 +104,7 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_CTR_DRBG_C) || !defined(POLARSSL_X509_PARSE_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
@ -113,7 +113,8 @@ int main( int argc, char *argv[] )
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_PARSE_C "
|
||||
"not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
@ -67,8 +67,9 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
|
||||
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_SSL_TLS_C) || \
|
||||
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C) || \
|
||||
!defined(POLARSSL_X509_PARSE_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
@ -77,7 +78,7 @@ int main( int argc, char *argv[] )
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
|
||||
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_PARSE_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
@ -98,6 +98,7 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
#if defined(POLARSSL_FS_IO)
|
||||
#define USAGE_IO \
|
||||
" ca_file=%%s The single file containing the top-level CA(s) you fully trust\n" \
|
||||
@ -109,8 +110,21 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
" key_file=%%s default: \"\" (pre-loaded)\n"
|
||||
#else
|
||||
#define USAGE_IO \
|
||||
" No file operations available (POLARSSL_FS_IO not defined)\n"
|
||||
"\n" \
|
||||
" No file operations available (POLARSSL_FS_IO not defined)\n" \
|
||||
"\n"
|
||||
#endif /* POLARSSL_FS_IO */
|
||||
#else
|
||||
#define USAGE_IO ""
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
#define USAGE_PSK \
|
||||
" psk=%%s default: \"\" (in hex, without 0x)\n" \
|
||||
" psk_identity=%%s default: \"Client_identity\"\n"
|
||||
#else
|
||||
#define USAGE_PSK ""
|
||||
#endif /* POLARSSL_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
#define USAGE \
|
||||
"\n usage: ssl_server2 param=<>...\n" \
|
||||
@ -125,25 +139,22 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
" options: ssl3, tls1, tls1_1, tls1_2\n" \
|
||||
" auth_mode=%%s default: \"optional\"\n" \
|
||||
" options: none, optional, required\n" \
|
||||
" psk=%%s default: \"\" (in hex, without 0x)\n" \
|
||||
" psk_identity=%%s default: \"Client_identity\"\n" \
|
||||
USAGE_PSK \
|
||||
"\n" \
|
||||
" force_ciphersuite=<name> default: all enabled\n"\
|
||||
" acceptable ciphersuite names:\n"
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||
#if !defined(POLARSSL_ENTROPY_C) || \
|
||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
|
||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
printf("POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_NET_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
@ -153,16 +164,20 @@ int main( int argc, char *argv[] )
|
||||
int listen_fd;
|
||||
int client_fd = -1;
|
||||
unsigned char buf[1024];
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
unsigned char psk[256];
|
||||
size_t psk_len = 0;
|
||||
#endif
|
||||
char *pers = "ssl_server2";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
ssl_context ssl;
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
x509_cert cacert;
|
||||
x509_cert srvcert;
|
||||
rsa_context rsa;
|
||||
#endif
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
ssl_cache_context cache;
|
||||
#endif
|
||||
@ -175,9 +190,11 @@ int main( int argc, char *argv[] )
|
||||
* Make sure memory references are valid.
|
||||
*/
|
||||
listen_fd = 0;
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||
memset( &rsa, 0, sizeof( rsa_context ) );
|
||||
#endif
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
ssl_cache_init( &cache );
|
||||
#endif
|
||||
@ -193,7 +210,11 @@ int main( int argc, char *argv[] )
|
||||
list = ssl_list_ciphersuites();
|
||||
while( *list )
|
||||
{
|
||||
printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
|
||||
printf(" %-40s", ssl_get_ciphersuite_name( *list ) );
|
||||
list++;
|
||||
if( !*list )
|
||||
break;
|
||||
printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
|
||||
list++;
|
||||
}
|
||||
printf("\n");
|
||||
@ -297,6 +318,7 @@ int main( int argc, char *argv[] )
|
||||
goto usage;
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
/*
|
||||
* Unhexify the pre-shared key if any is given
|
||||
*/
|
||||
@ -344,6 +366,7 @@ int main( int argc, char *argv[] )
|
||||
psk[ j / 2 ] |= c;
|
||||
}
|
||||
}
|
||||
#endif /* POLARSSL_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
/*
|
||||
* 0. Initialize the RNG and the session data
|
||||
@ -361,6 +384,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
printf( " ok\n" );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
/*
|
||||
* 1.1. Load the trusted CA
|
||||
*/
|
||||
@ -438,6 +462,7 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
/*
|
||||
* 2. Setup the listening TCP socket
|
||||
@ -482,10 +507,15 @@ int main( int argc, char *argv[] )
|
||||
ssl_set_renegotiation( &ssl, opt.renegotiation );
|
||||
ssl_legacy_renegotiation( &ssl, opt.allow_legacy );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
ssl_set_ca_chain( &ssl, &cacert, NULL, NULL );
|
||||
ssl_set_own_cert( &ssl, &srvcert, &rsa );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
|
||||
ssl_set_psk( &ssl, psk, psk_len, (unsigned char *) opt.psk_identity,
|
||||
strlen( opt.psk_identity ) );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_DHM_C)
|
||||
/*
|
||||
@ -574,6 +604,7 @@ reset:
|
||||
printf( " ok\n [ Ciphersuite is %s ]\n",
|
||||
ssl_get_ciphersuite( &ssl ) );
|
||||
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
/*
|
||||
* 5. Verify the server certificate
|
||||
*/
|
||||
@ -607,6 +638,7 @@ reset:
|
||||
ssl_get_peer_cert( &ssl ) );
|
||||
printf( "%s\n", buf );
|
||||
}
|
||||
#endif /* POLARSSL_X509_PARSE_C */
|
||||
|
||||
/*
|
||||
* 6. Read the HTTP Request
|
||||
@ -693,9 +725,12 @@ exit:
|
||||
#endif
|
||||
|
||||
net_close( client_fd );
|
||||
#if defined(POLARSSL_X509_PARSE_C)
|
||||
x509_free( &srvcert );
|
||||
x509_free( &cacert );
|
||||
rsa_free( &rsa );
|
||||
#endif
|
||||
|
||||
ssl_free( &ssl );
|
||||
|
||||
#if defined(POLARSSL_SSL_CACHE_C)
|
||||
|
@ -45,6 +45,18 @@
|
||||
#include "polarssl/entropy.h"
|
||||
#include "polarssl/ctr_drbg.h"
|
||||
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
||||
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret;
|
||||
@ -241,3 +253,5 @@ exit:
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C &&
|
||||
POLARSSL_X509_PARSE_C && POLARSSL_FS_IO */
|
||||
|
@ -65,16 +65,6 @@
|
||||
#define DFL_SESSION_LIFETIME 86400
|
||||
#define DFL_FORCE_CIPHER 0
|
||||
|
||||
/*
|
||||
* server-specific data
|
||||
*/
|
||||
char *dhm_G = "4";
|
||||
char *dhm_P =
|
||||
"E4004C1F94182000103D883A448B3F802CE4B44A83301270002C20D0321CFD00" \
|
||||
"11CCEF784C26A400F43DFB901BCA7538F2C6B176001CF5A0FD16D2C48B1D0C1C" \
|
||||
"F6AC8E1DA6BCC3B4E1F96B0564965300FFA1D0B601EB2800F489AA512C4B248C" \
|
||||
"01F76949A60BB7F00A40B1EAB64BDD48E8A700D60B7F1200FA8E77B0A979DABF";
|
||||
|
||||
int server_fd = -1;
|
||||
|
||||
/*
|
||||
@ -127,7 +117,8 @@ void my_debug( void *ctx, int level, const char *str )
|
||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
|
||||
!defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C) || \
|
||||
!defined(POLARSSL_X509_PARSE_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
@ -136,7 +127,8 @@ int main( int argc, char *argv[] )
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||
"POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
|
||||
"POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
"POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C and/or "
|
||||
"POLARSSL_X509_PARSE_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
@ -260,7 +252,6 @@ static int ssl_test( struct options *opt )
|
||||
}
|
||||
|
||||
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
|
||||
ssl_set_dh_param( &ssl, dhm_P, dhm_G );
|
||||
ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
|
||||
ssl_set_own_cert( &ssl, &srvcert, &rsa );
|
||||
}
|
||||
|
Reference in New Issue
Block a user