Add negotiation of Extended Master Secret

(But not the actual thing yet.)
This commit is contained in:
Manuel Pégourié-Gonnard 2014-10-20 18:40:56 +02:00
parent 178f9d6e19
commit 367381fddd
8 changed files with 264 additions and 0 deletions

View file

@ -96,6 +96,7 @@ int main( int argc, char *argv[] )
#define DFL_TICKETS SSL_SESSION_TICKETS_ENABLED
#define DFL_ALPN_STRING NULL
#define DFL_FALLBACK -1
#define DFL_EXTENDED_MS -1
#define GET_REQUEST "GET %s HTTP/1.0\r\nExtra-header: "
#define GET_REQUEST_END "\r\n\r\n"
@ -134,6 +135,7 @@ struct options
int tickets; /* enable / disable session tickets */
const char *alpn_string; /* ALPN supported protocols */
int fallback; /* is this a fallback connection? */
char extended_ms; /* negotiate extended master secret? */
} opt;
static void my_debug( void *ctx, int level, const char *str )
@ -293,6 +295,13 @@ static int my_verify( void *data, x509_crt *crt, int depth, int *flags )
#define USAGE_FALLBACK ""
#endif
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
#define USAGE_EMS \
" extended_ms=0/1 default: (library default: on)\n"
#else
#define USAGE_EMS ""
#endif
#define USAGE \
"\n usage: ssl_client2 param=<>...\n" \
"\n acceptable parameters:\n" \
@ -323,6 +332,7 @@ static int my_verify( void *data, x509_crt *crt, int depth, int *flags )
USAGE_TRUNC_HMAC \
USAGE_ALPN \
USAGE_FALLBACK \
USAGE_EMS \
"\n" \
" min_version=%%s default: \"\" (ssl3)\n" \
" max_version=%%s default: \"\" (tls1_2)\n" \
@ -424,6 +434,7 @@ int main( int argc, char *argv[] )
opt.tickets = DFL_TICKETS;
opt.alpn_string = DFL_ALPN_STRING;
opt.fallback = DFL_FALLBACK;
opt.extended_ms = DFL_EXTENDED_MS;
for( i = 1; i < argc; i++ )
{
@ -539,6 +550,15 @@ int main( int argc, char *argv[] )
default: goto usage;
}
}
else if( strcmp( p, "extended_ms" ) == 0 )
{
switch( atoi( q ) )
{
case 0: opt.extended_ms = SSL_EXTENDED_MS_DISABLED; break;
case 1: opt.extended_ms = SSL_EXTENDED_MS_ENABLED; break;
default: goto usage;
}
}
else if( strcmp( p, "min_version" ) == 0 )
{
if( strcmp( q, "ssl3" ) == 0 )
@ -902,6 +922,11 @@ int main( int argc, char *argv[] )
}
#endif
#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
if( opt.extended_ms != DFL_EXTENDED_MS )
ssl_set_extended_master_secret( &ssl, opt.extended_ms );
#endif
#if defined(POLARSSL_SSL_ALPN)
if( opt.alpn_string != NULL )
if( ( ret = ssl_set_alpn_protocols( &ssl, alpn_list ) ) != 0 )