26 #if !defined(POLARSSL_CONFIG_FILE)
29 #include POLARSSL_CONFIG_FILE
32 #if defined(POLARSSL_SSL_SRV_C)
36 #if defined(POLARSSL_ECP_C)
40 #if defined(POLARSSL_PLATFORM_C)
43 #define polarssl_malloc malloc
44 #define polarssl_free free
50 #if defined(POLARSSL_HAVE_TIME)
54 #if defined(POLARSSL_SSL_SESSION_TICKETS)
63 static int ssl_save_session(
const ssl_session *session,
64 unsigned char *buf,
size_t buf_len,
67 unsigned char *p = buf;
68 size_t left = buf_len;
69 #if defined(POLARSSL_X509_CRT_PARSE_C)
80 #if defined(POLARSSL_X509_CRT_PARSE_C)
86 if( left < 3 + cert_len )
89 *p++ = (
unsigned char)( cert_len >> 16 & 0xFF );
90 *p++ = (
unsigned char)( cert_len >> 8 & 0xFF );
91 *p++ = (
unsigned char)( cert_len & 0xFF );
108 const unsigned char *buf,
size_t len )
110 const unsigned char *p = buf;
111 const unsigned char *
const end = buf + len;
112 #if defined(POLARSSL_X509_CRT_PARSE_C)
122 #if defined(POLARSSL_X509_CRT_PARSE_C)
126 cert_len = ( p[0] << 16 ) | ( p[1] << 8 ) | p[2];
137 if( p + cert_len > end )
177 static int ssl_write_ticket(
ssl_context *ssl,
size_t *tlen )
180 unsigned char *
const start = ssl->
out_msg + 10;
181 unsigned char *p = start;
182 unsigned char *state;
183 unsigned char iv[16];
184 size_t clear_len, enc_len, pad_len, i;
196 if( ( ret = ssl->
f_rng( ssl->
p_rng, p, 16 ) ) != 0 )
214 SSL_DEBUG_BUF( 3,
"session ticket cleartext", state, clear_len );
217 pad_len = 16 - clear_len % 16;
218 enc_len = clear_len + pad_len;
219 for( i = clear_len; i < enc_len; i++ )
220 state[i] = (
unsigned char) pad_len;
224 enc_len, iv, state, state ) ) != 0 )
230 *p++ = (
unsigned char)( ( enc_len >> 8 ) & 0xFF );
231 *p++ = (
unsigned char)( ( enc_len ) & 0xFF );
240 SSL_DEBUG_BUF( 3,
"session ticket structure", start, *tlen );
254 unsigned char *key_name = buf;
255 unsigned char *iv = buf + 16;
256 unsigned char *enc_len_p = iv + 16;
257 unsigned char *ticket = enc_len_p + 2;
259 unsigned char computed_mac[32];
260 size_t enc_len, clear_len, i;
261 unsigned char pad_len, diff;
265 if( len < 34 || ssl->ticket_keys == NULL )
268 enc_len = ( enc_len_p[0] << 8 ) | enc_len_p[1];
269 mac = ticket + enc_len;
271 if( len != enc_len + 66 )
276 for( i = 0; i < 16; i++ )
284 for( i = 0; i < 32; i++ )
285 diff |= mac[i] ^ computed_mac[i];
294 enc_len, iv, ticket, ticket ) ) != 0 )
300 pad_len = ticket[enc_len - 1];
303 for( i = 2; i < pad_len; i++ )
304 if( ticket[enc_len - i] != pad_len )
309 clear_len = enc_len - pad_len;
311 SSL_DEBUG_BUF( 3,
"session ticket cleartext", ticket, clear_len );
314 if( ( ret = ssl_load_session( &session, ticket, clear_len ) ) != 0 )
321 #if defined(POLARSSL_HAVE_TIME)
346 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
352 const unsigned char*
name,
size_t len )
358 ret = ssl->
f_sni( ssl->
p_sni, ssl, name, len );
366 static int ssl_parse_servername_ext(
ssl_context *ssl,
367 const unsigned char *buf,
371 size_t servername_list_size, hostname_len;
372 const unsigned char *p;
376 servername_list_size = ( ( buf[0] << 8 ) | ( buf[1] ) );
377 if( servername_list_size + 2 != len )
384 while( servername_list_size > 0 )
386 hostname_len = ( ( p[1] << 8 ) | p[2] );
387 if( hostname_len + 3 > servername_list_size )
395 ret = ssl_sni_wrapper( ssl, p + 3, hostname_len );
406 servername_list_size -= hostname_len + 3;
407 p += hostname_len + 3;
410 if( servername_list_size != 0 )
420 static int ssl_parse_renegotiation_info(
ssl_context *ssl,
421 const unsigned char *buf,
428 if( len != 1 || buf[0] != 0x0 )
430 SSL_DEBUG_MSG( 1, (
"non-zero length renegotiated connection field" ) );
448 SSL_DEBUG_MSG( 1, (
"non-matching renegotiated connection field" ) );
460 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
461 static int ssl_parse_signature_algorithms_ext(
ssl_context *ssl,
462 const unsigned char *buf,
465 size_t sig_alg_list_size;
466 const unsigned char *p;
468 sig_alg_list_size = ( ( buf[0] << 8 ) | ( buf[1] ) );
469 if( sig_alg_list_size + 2 != len ||
470 sig_alg_list_size %2 != 0 )
477 while( sig_alg_list_size > 0 )
483 #if defined(POLARSSL_SHA512_C)
495 #if defined(POLARSSL_SHA256_C)
518 sig_alg_list_size -= 2;
522 SSL_DEBUG_MSG( 3, (
"client hello v3, signature_algorithm ext: %d",
529 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
530 static int ssl_parse_supported_elliptic_curves(
ssl_context *ssl,
531 const unsigned char *buf,
534 size_t list_size, our_size;
535 const unsigned char *p;
538 list_size = ( ( buf[0] << 8 ) | ( buf[1] ) );
539 if( list_size + 2 != len ||
548 our_size = list_size / 2 + 1;
552 if( ( curves =
polarssl_malloc( our_size *
sizeof( *curves ) ) ) == NULL )
556 memset( (
void *) curves, 0, our_size *
sizeof( *curves ) );
560 while( list_size > 0 && our_size > 1 )
564 if( curve_info != NULL )
566 *curves++ = curve_info;
577 static int ssl_parse_supported_point_formats(
ssl_context *ssl,
578 const unsigned char *buf,
582 const unsigned char *p;
585 if( list_size + 1 != len )
592 while( list_size > 0 )
610 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
611 static int ssl_parse_max_fragment_length_ext(
ssl_context *ssl,
612 const unsigned char *buf,
627 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
628 static int ssl_parse_truncated_hmac_ext(
ssl_context *ssl,
629 const unsigned char *buf,
646 #if defined(POLARSSL_SSL_SESSION_TICKETS)
647 static int ssl_parse_session_ticket_ext(
ssl_context *ssl,
673 if( ( ret = ssl_parse_ticket( ssl, buf, len ) ) != 0 )
679 SSL_DEBUG_MSG( 3, (
"session successfully restored from ticket" ) );
690 #if defined(POLARSSL_SSL_ALPN)
692 unsigned char *buf,
size_t len )
694 size_t list_len, cur_len;
695 const unsigned char *theirs, *start, *end;
714 list_len = ( buf[0] << 8 ) | buf[1];
715 if( list_len != len - 2 )
723 for( ours = ssl->
alpn_list; *ours != NULL; ours++ )
725 for( theirs = start; theirs != end; theirs += cur_len )
737 if( cur_len == strlen( *ours ) &&
738 memcmp( theirs, *ours, cur_len ) == 0 )
757 #if defined(POLARSSL_X509_CRT_PARSE_C)
761 #if defined(POLARSSL_ECDSA_C)
762 static int ssl_key_matches_curves(
pk_context *pk,
768 while( *crv != NULL )
770 if( (*crv)->grp_id == grp_id )
789 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
799 for( cur = list; cur != NULL; cur = cur->
next )
818 #if defined(POLARSSL_ECDSA_C)
841 static int ssl_ciphersuite_match(
ssl_context *ssl,
int suite_id,
847 if( suite_info == NULL )
849 SSL_DEBUG_MSG( 1, (
"ciphersuite info for %04x not found", suite_id ) );
857 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
864 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
868 ssl->
f_psk == NULL &&
874 #if defined(POLARSSL_X509_CRT_PARSE_C)
882 if( ssl_pick_cert( ssl, suite_info ) != 0 )
886 *ciphersuite_info = suite_info;
890 #if defined(POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
891 static int ssl_parse_client_hello_v2(
ssl_context *ssl )
896 unsigned int ciph_len, sess_len, chal_len;
897 unsigned char *buf, *p;
898 const int *ciphersuites;
905 SSL_DEBUG_MSG( 1, (
"client hello v2 illegal for renegotiation" ) );
920 ( ( buf[0] & 0x7F ) << 8 ) | buf[1] ) );
921 SSL_DEBUG_MSG( 3, (
"client hello v2, max. version: [%d:%d]",
941 n = ( ( buf[0] << 8 ) | buf[1] ) & 0x7FFF;
943 if( n < 17 || n > 512 )
955 SSL_DEBUG_MSG( 1, (
"client only supports ssl smaller than minimum"
956 " [%d:%d] < [%d:%d]",
989 ciph_len = ( buf[0] << 8 ) | buf[1];
990 sess_len = ( buf[2] << 8 ) | buf[3];
991 chal_len = ( buf[4] << 8 ) | buf[5];
993 SSL_DEBUG_MSG( 3, (
"ciph_len: %d, sess_len: %d, chal_len: %d",
994 ciph_len, sess_len, chal_len ) );
999 if( ciph_len < 3 || ( ciph_len % 3 ) != 0 )
1011 if( chal_len < 8 || chal_len > 32 )
1017 if( n != 6 + ciph_len + sess_len + chal_len )
1024 buf + 6, ciph_len );
1026 buf + 6 + ciph_len, sess_len );
1028 buf + 6 + ciph_len + sess_len, chal_len );
1030 p = buf + 6 + ciph_len;
1043 for( i = 0, p = buf + 6; i < ciph_len; i += 3, p += 3 )
1047 SSL_DEBUG_MSG( 3, (
"received TLS_EMPTY_RENEGOTIATION_INFO " ) );
1050 SSL_DEBUG_MSG( 1, (
"received RENEGOTIATION SCSV during renegotiation" ) );
1063 ciphersuite_info = NULL;
1064 #if defined(POLARSSL_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
1065 for( j = 0, p = buf + 6; j < ciph_len; j += 3, p += 3 )
1067 for( i = 0; ciphersuites[i] != 0; i++ )
1069 for( i = 0; ciphersuites[i] != 0; i++ )
1071 for( j = 0, p = buf + 6; j < ciph_len; j += 3, p += 3 )
1075 p[1] != ( ( ciphersuites[i] >> 8 ) & 0xFF ) ||
1076 p[2] != ( ( ciphersuites[i] ) & 0xFF ) )
1079 if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i],
1080 &ciphersuite_info ) ) != 0 )
1083 if( ciphersuite_info != NULL )
1084 goto have_ciphersuite_v2;
1092 have_ciphersuite_v2:
1103 SSL_DEBUG_MSG( 1, (
"legacy renegotiation, breaking off handshake" ) );
1120 static int ssl_parse_client_hello(
ssl_context *ssl )
1125 unsigned int ciph_len, sess_len;
1126 unsigned int comp_len;
1127 unsigned int ext_len = 0;
1128 unsigned char *buf, *p, *ext;
1129 int renegotiation_info_seen = 0;
1130 int handshake_failure = 0;
1131 const int *ciphersuites;
1145 #if defined(POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
1146 if( ( buf[0] & 0x80 ) != 0 )
1147 return ssl_parse_client_hello_v2( ssl );
1155 ( buf[3] << 8 ) | buf[4] ) );
1156 SSL_DEBUG_MSG( 3, (
"client hello v3, protocol ver: [%d:%d]",
1179 n = ( buf[3] << 8 ) | buf[4];
1221 ( buf[1] << 16 ) | ( buf[2] << 8 ) | buf[3] ) );
1222 SSL_DEBUG_MSG( 3, (
"client hello v3, max. version: [%d:%d]",
1243 SSL_DEBUG_MSG( 1, (
"client only supports ssl smaller than minimum"
1244 " [%d:%d] < [%d:%d]",
1267 if( buf[1] != 0 || n != (
unsigned int) 4 + ( ( buf[2] << 8 ) | buf[3] ) )
1293 ciph_len = ( buf[39 + sess_len] << 8 )
1294 | ( buf[40 + sess_len] );
1296 if( ciph_len < 2 || ( ciph_len % 2 ) != 0 )
1305 comp_len = buf[41 + sess_len + ciph_len];
1307 if( comp_len < 1 || comp_len > 16 )
1316 if( n > 42 + sess_len + ciph_len + comp_len )
1318 ext_len = ( buf[42 + sess_len + ciph_len + comp_len] << 8 )
1319 | ( buf[43 + sess_len + ciph_len + comp_len] );
1321 if( ( ext_len > 0 && ext_len < 4 ) ||
1322 n != 44 + sess_len + ciph_len + comp_len + ext_len )
1325 SSL_DEBUG_BUF( 3,
"Ext", buf + 44 + sess_len + ciph_len + comp_len, ext_len);
1331 #if defined(POLARSSL_ZLIB_SUPPORT)
1332 for( i = 0; i < comp_len; ++i )
1345 buf + 38, sess_len );
1347 buf + 41 + sess_len, ciph_len );
1349 buf + 42 + sess_len + ciph_len, comp_len );
1354 for( i = 0, p = buf + 41 + sess_len; i < ciph_len; i += 2, p += 2 )
1358 SSL_DEBUG_MSG( 3, (
"received TLS_EMPTY_RENEGOTIATION_INFO " ) );
1361 SSL_DEBUG_MSG( 1, (
"received RENEGOTIATION SCSV during renegotiation" ) );
1373 ext = buf + 44 + sess_len + ciph_len + comp_len;
1377 unsigned int ext_id = ( ( ext[0] << 8 )
1379 unsigned int ext_size = ( ( ext[2] << 8 )
1382 if( ext_size + 4 > ext_len )
1389 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
1392 if( ssl->
f_sni == NULL )
1395 ret = ssl_parse_servername_ext( ssl, ext + 4, ext_size );
1403 renegotiation_info_seen = 1;
1405 ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size );
1410 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1412 SSL_DEBUG_MSG( 3, (
"found signature_algorithms extension" ) );
1416 ret = ssl_parse_signature_algorithms_ext( ssl, ext + 4, ext_size );
1422 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
1424 SSL_DEBUG_MSG( 3, (
"found supported elliptic curves extension" ) );
1426 ret = ssl_parse_supported_elliptic_curves( ssl, ext + 4, ext_size );
1432 SSL_DEBUG_MSG( 3, (
"found supported point formats extension" ) );
1435 ret = ssl_parse_supported_point_formats( ssl, ext + 4, ext_size );
1441 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
1443 SSL_DEBUG_MSG( 3, (
"found max fragment length extension" ) );
1445 ret = ssl_parse_max_fragment_length_ext( ssl, ext + 4, ext_size );
1451 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
1455 ret = ssl_parse_truncated_hmac_ext( ssl, ext + 4, ext_size );
1461 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1465 ret = ssl_parse_session_ticket_ext( ssl, ext + 4, ext_size );
1471 #if defined(POLARSSL_SSL_ALPN)
1475 ret = ssl_parse_alpn_ext( ssl, ext + 4, ext_size );
1482 SSL_DEBUG_MSG( 3, (
"unknown extension found: %d (ignoring)",
1486 ext_len -= 4 + ext_size;
1487 ext += 4 + ext_size;
1489 if( ext_len > 0 && ext_len < 4 )
1502 SSL_DEBUG_MSG( 1, (
"legacy renegotiation, breaking off handshake" ) );
1503 handshake_failure = 1;
1507 renegotiation_info_seen == 0 )
1509 SSL_DEBUG_MSG( 1, (
"renegotiation_info extension missing (secure)" ) );
1510 handshake_failure = 1;
1517 handshake_failure = 1;
1521 renegotiation_info_seen == 1 )
1523 SSL_DEBUG_MSG( 1, (
"renegotiation_info extension present (legacy)" ) );
1524 handshake_failure = 1;
1527 if( handshake_failure == 1 )
1541 ciphersuite_info = NULL;
1542 #if defined(POLARSSL_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
1543 for( j = 0, p = buf + 41 + sess_len; j < ciph_len; j += 2, p += 2 )
1545 for( i = 0; ciphersuites[i] != 0; i++ )
1547 for( i = 0; ciphersuites[i] != 0; i++ )
1549 for( j = 0, p = buf + 41 + sess_len; j < ciph_len; j += 2, p += 2 )
1552 if( p[0] != ( ( ciphersuites[i] >> 8 ) & 0xFF ) ||
1553 p[1] != ( ( ciphersuites[i] ) & 0xFF ) )
1556 if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i],
1557 &ciphersuite_info ) ) != 0 )
1560 if( ciphersuite_info != NULL )
1561 goto have_ciphersuite;
1585 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
1586 static void ssl_write_truncated_hmac_ext(
ssl_context *ssl,
1590 unsigned char *p = buf;
1598 SSL_DEBUG_MSG( 3, (
"server hello, adding truncated hmac extension" ) );
1610 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1611 static void ssl_write_session_ticket_ext(
ssl_context *ssl,
1615 unsigned char *p = buf;
1623 SSL_DEBUG_MSG( 3, (
"server hello, adding session ticket extension" ) );
1635 static void ssl_write_renegotiation_ext(
ssl_context *ssl,
1639 unsigned char *p = buf;
1647 SSL_DEBUG_MSG( 3, (
"server hello, secure renegotiation extension" ) );
1664 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
1665 static void ssl_write_max_fragment_length_ext(
ssl_context *ssl,
1669 unsigned char *p = buf;
1677 SSL_DEBUG_MSG( 3, (
"server hello, max_fragment_length extension" ) );
1691 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
1692 static void ssl_write_supported_point_formats_ext(
ssl_context *ssl,
1696 unsigned char *p = buf;
1706 SSL_DEBUG_MSG( 3, (
"server hello, supported_point_formats extension" ) );
1721 #if defined(POLARSSL_SSL_ALPN )
1723 unsigned char *buf,
size_t *olen )
1731 SSL_DEBUG_MSG( 3, (
"server hello, adding alpn extension" ) );
1740 buf[0] = (
unsigned char)( (
TLS_EXT_ALPN >> 8 ) & 0xFF );
1745 buf[2] = (
unsigned char)( ( ( *olen - 4 ) >> 8 ) & 0xFF );
1746 buf[3] = (
unsigned char)( ( ( *olen - 4 ) ) & 0xFF );
1748 buf[4] = (
unsigned char)( ( ( *olen - 6 ) >> 8 ) & 0xFF );
1749 buf[5] = (
unsigned char)( ( ( *olen - 6 ) ) & 0xFF );
1751 buf[6] = (
unsigned char)( ( ( *olen - 7 ) ) & 0xFF );
1757 static int ssl_write_server_hello(
ssl_context *ssl )
1759 #if defined(POLARSSL_HAVE_TIME)
1763 size_t olen, ext_len = 0, n;
1764 unsigned char *buf, *p;
1768 if( ssl->
f_rng == NULL )
1787 SSL_DEBUG_MSG( 3, (
"server hello, chosen version: [%d:%d]",
1790 #if defined(POLARSSL_HAVE_TIME)
1792 *p++ = (
unsigned char)( t >> 24 );
1793 *p++ = (
unsigned char)( t >> 16 );
1794 *p++ = (
unsigned char)( t >> 8 );
1795 *p++ = (
unsigned char)( t );
1797 SSL_DEBUG_MSG( 3, (
"server hello, current time: %lu", t ) );
1799 if( ( ret = ssl->
f_rng( ssl->
p_rng, p, 4 ) ) != 0 )
1805 if( ( ret = ssl->
f_rng( ssl->
p_rng, p, 28 ) ) != 0 )
1812 SSL_DEBUG_BUF( 3,
"server hello, random bytes", buf + 6, 32 );
1825 SSL_DEBUG_MSG( 3, (
"session successfully restored from cache" ) );
1837 #if defined(POLARSSL_HAVE_TIME)
1841 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1883 SSL_DEBUG_MSG( 3, (
"server hello, session id len.: %d", n ) );
1884 SSL_DEBUG_BUF( 3,
"server hello, session id", buf + 39, n );
1900 ssl_write_renegotiation_ext( ssl, p + 2 + ext_len, &olen );
1903 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
1904 ssl_write_max_fragment_length_ext( ssl, p + 2 + ext_len, &olen );
1908 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
1909 ssl_write_truncated_hmac_ext( ssl, p + 2 + ext_len, &olen );
1913 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1914 ssl_write_session_ticket_ext( ssl, p + 2 + ext_len, &olen );
1918 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
1919 ssl_write_supported_point_formats_ext( ssl, p + 2 + ext_len, &olen );
1923 #if defined(POLARSSL_SSL_ALPN)
1924 ssl_write_alpn_ext( ssl, p + 2 + ext_len, &olen );
1928 SSL_DEBUG_MSG( 3, (
"server hello, total extension length: %d", ext_len ) );
1932 *p++ = (
unsigned char)( ( ext_len >> 8 ) & 0xFF );
1933 *p++ = (
unsigned char)( ( ext_len ) & 0xFF );
1948 #if !defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) && \
1949 !defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
1950 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
1951 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1952 static int ssl_write_certificate_request(
ssl_context *ssl )
1964 SSL_DEBUG_MSG( 2, (
"<= skip write certificate request" ) );
1973 static int ssl_write_certificate_request(
ssl_context *ssl )
1977 size_t dn_size, total_dn_size;
1978 size_t ct_len, sa_len;
1979 unsigned char *buf, *p;
1992 SSL_DEBUG_MSG( 2, (
"<= skip write certificate request" ) );
2019 #if defined(POLARSSL_RSA_C)
2022 #if defined(POLARSSL_ECDSA_C)
2026 p[0] = (
unsigned char) ct_len++;
2030 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
2061 #if defined(POLARSSL_RSA_C)
2065 #if defined(POLARSSL_ECDSA_C)
2070 p[0] = (
unsigned char)( sa_len >> 8 );
2071 p[1] = (
unsigned char)( sa_len );
2085 while( crt != NULL && crt->
version != 0 )
2087 if( p - buf > 4096 )
2091 *p++ = (
unsigned char)( dn_size >> 8 );
2092 *p++ = (
unsigned char)( dn_size );
2098 total_dn_size += 2 + dn_size;
2105 ssl->
out_msg[4 + ct_len + sa_len] = (
unsigned char)( total_dn_size >> 8 );
2106 ssl->
out_msg[5 + ct_len + sa_len] = (
unsigned char)( total_dn_size );
2119 #if defined(POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
2120 defined(POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
2121 static int ssl_get_ecdh_params_from_cert(
ssl_context *ssl )
2144 static int ssl_write_server_key_exchange(
ssl_context *ssl )
2151 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
2152 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
2153 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
2154 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
2155 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
2156 unsigned char *p = ssl->
out_msg + 4;
2157 unsigned char *dig_signed = p;
2158 size_t dig_signed_len = 0, len;
2159 ((void) dig_signed);
2160 ((void) dig_signed_len);
2165 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) || \
2166 defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) || \
2167 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
2172 SSL_DEBUG_MSG( 2, (
"<= skip write server key exchange" ) );
2178 #if defined(POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
2179 defined(POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
2183 ssl_get_ecdh_params_from_cert( ssl );
2185 SSL_DEBUG_MSG( 2, (
"<= skip write server key exchange" ) );
2191 #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
2192 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
2205 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
2206 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
2235 dig_signed_len = len;
2248 #if defined(POLARSSL_KEY_EXCHANGE__SOME__ECDHE_ENABLED)
2262 #if defined(POLARSSL_SSL_SET_CURVES)
2268 if( (*curve)->grp_id == *gid )
2269 goto curve_matching_done;
2271 curve_matching_done:
2276 if( *curve == NULL )
2285 (*curve)->grp_id ) ) != 0 )
2292 p, SSL_MAX_CONTENT_LEN - n,
2300 dig_signed_len = len;
2309 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
2310 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
2311 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
2316 size_t signature_len = 0;
2317 unsigned int hashlen = 0;
2318 unsigned char hash[64];
2324 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
2337 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
2338 defined(POLARSSL_SSL_PROTO_TLS1_1)
2353 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
2354 defined(POLARSSL_SSL_PROTO_TLS1_1)
2375 md5_update( &md5, dig_signed, dig_signed_len );
2388 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
2389 defined(POLARSSL_SSL_PROTO_TLS1_2)
2412 md_update( &ctx, dig_signed, dig_signed_len );
2430 SSL_DEBUG_BUF( 3,
"parameters hash", hash, hashlen != 0 ? hashlen :
2442 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
2453 p + 2 , &signature_len,
2460 *(p++) = (
unsigned char)( signature_len >> 8 );
2461 *(p++) = (
unsigned char)( signature_len );
2490 static int ssl_write_server_hello_done(
ssl_context *ssl )
2513 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
2514 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
2515 static int ssl_parse_client_dh_public(
ssl_context *ssl,
unsigned char **p,
2516 const unsigned char *end )
2530 n = ( (*p)[0] << 8 ) | (*p)[1];
2554 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) || \
2555 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
2556 static int ssl_parse_encrypted_pms(
ssl_context *ssl,
2557 const unsigned char *p,
2558 const unsigned char *end,
2574 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
2575 defined(POLARSSL_SSL_PROTO_TLS1_2)
2578 if( *p++ != ( ( len >> 8 ) & 0xFF ) ||
2579 *p++ != ( ( len ) & 0xFF ) )
2587 if( p + len != end )
2622 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
2623 static int ssl_parse_client_psk_identity(
ssl_context *ssl,
unsigned char **p,
2624 const unsigned char *end )
2629 if( ssl->
f_psk == NULL &&
2646 n = ( (*p)[0] << 8 ) | (*p)[1];
2649 if( n < 1 || n > 65535 || *p + n > end )
2655 if( ssl->
f_psk != NULL )
2657 if( ( ret != ssl->
f_psk( ssl->
p_psk, ssl, *p, n ) ) != 0 )
2692 static int ssl_parse_client_key_exchange(
ssl_context *ssl )
2719 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED)
2722 unsigned char *p = ssl->
in_msg + 4;
2725 if( ( ret = ssl_parse_client_dh_public( ssl, &p, end ) ) != 0 )
2752 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
2753 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
2754 defined(POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
2755 defined(POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
2787 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
2790 unsigned char *p = ssl->
in_msg + 4;
2793 if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 )
2795 SSL_DEBUG_RET( 1, (
"ssl_parse_client_psk_identity" ), ret );
2814 #if defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
2817 unsigned char *p = ssl->
in_msg + 4;
2820 if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 )
2822 SSL_DEBUG_RET( 1, (
"ssl_parse_client_psk_identity" ), ret );
2826 if( ( ret = ssl_parse_encrypted_pms( ssl, p, end, 2 ) ) != 0 )
2841 #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
2844 unsigned char *p = ssl->
in_msg + 4;
2847 if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 )
2849 SSL_DEBUG_RET( 1, (
"ssl_parse_client_psk_identity" ), ret );
2852 if( ( ret = ssl_parse_client_dh_public( ssl, &p, end ) ) != 0 )
2873 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
2876 unsigned char *p = ssl->
in_msg + 4;
2879 if( ( ret = ssl_parse_client_psk_identity( ssl, &p, end ) ) != 0 )
2881 SSL_DEBUG_RET( 1, (
"ssl_parse_client_psk_identity" ), ret );
2886 p, end - p ) ) != 0 )
2903 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED)
2906 if( ( ret = ssl_parse_encrypted_pms( ssl,
2911 SSL_DEBUG_RET( 1, (
"ssl_parse_parse_encrypted_pms_secret" ), ret );
2935 #if !defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) && \
2936 !defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
2937 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
2938 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
2939 static int ssl_parse_certificate_verify(
ssl_context *ssl )
2960 static int ssl_parse_certificate_verify(
ssl_context *ssl )
2963 size_t sa_len, sig_len;
2964 unsigned char hash[48];
2965 unsigned char *hash_start = hash;
2967 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
3022 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
3023 defined(POLARSSL_SSL_PROTO_TLS1_1)
3043 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
3053 SSL_DEBUG_MSG( 1, (
"peer not adhering to requested sig_alg"
3054 " for verify message" ) );
3069 SSL_DEBUG_MSG( 1, (
"peer not adhering to requested sig_alg"
3070 " for verify message" ) );
3090 sig_len = ( ssl->
in_msg[4 + sa_len] << 8 ) | ssl->
in_msg[5 + sa_len];
3092 if( sa_len + sig_len + 6 != ssl->
in_hslen )
3099 md_alg, hash_start, hashlen,
3100 ssl->
in_msg + 6 + sa_len, sig_len ) ) != 0 )
3114 #if defined(POLARSSL_SSL_SESSION_TICKETS)
3115 static int ssl_write_new_session_ticket(
ssl_context *ssl )
3137 ssl->
out_msg[4] = ( lifetime >> 24 ) & 0xFF;
3138 ssl->
out_msg[5] = ( lifetime >> 16 ) & 0xFF;
3139 ssl->
out_msg[6] = ( lifetime >> 8 ) & 0xFF;
3140 ssl->
out_msg[7] = ( lifetime ) & 0xFF;
3142 if( ( ret = ssl_write_ticket( ssl, &tlen ) ) != 0 )
3148 ssl->
out_msg[8] = (
unsigned char)( ( tlen >> 8 ) & 0xFF );
3149 ssl->
out_msg[9] = (
unsigned char)( ( tlen ) & 0xFF );
3186 switch( ssl->
state )
3196 ret = ssl_parse_client_hello( ssl );
3207 ret = ssl_write_server_hello( ssl );
3215 ret = ssl_write_server_key_exchange( ssl );
3219 ret = ssl_write_certificate_request( ssl );
3223 ret = ssl_write_server_hello_done( ssl );
3238 ret = ssl_parse_client_key_exchange( ssl );
3242 ret = ssl_parse_certificate_verify( ssl );
3259 #if defined(POLARSSL_SSL_SESSION_TICKETS)
3261 ret = ssl_write_new_session_ticket( ssl );
const ecp_curve_info ** curves
#define SSL_HS_CLIENT_KEY_EXCHANGE
#define SSL_CERT_TYPE_ECDSA_SIGN
int ssl_ciphersuite_uses_ec(const ssl_ciphersuite_t *info)
int ecdh_make_params(ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Setup and write the ServerKeyExhange parameters.
#define SSL_ALERT_LEVEL_FATAL
static size_t pk_get_len(const pk_context *ctx)
Get the length in bytes of the underlying key.
int ssl_send_alert_message(ssl_context *ssl, unsigned char level, unsigned char message)
Send an alert message.
int(* f_rng)(void *, unsigned char *, size_t)
#define TLS_EXT_SERVERNAME_HOSTNAME
#define SSL_DEBUG_RET(level, text, ret)
#define POLARSSL_ERR_SSL_PK_TYPE_MISMATCH
Public key type mismatch (eg, asked for RSA key exchange and presented EC key)
#define POLARSSL_ECP_PF_COMPRESSED
Compressed point format.
pk_type_t ssl_pk_alg_from_sig(unsigned char sig)
#define POLARSSL_MPI_MAX_SIZE
Maximum number of bytes for usable MPIs.
int ecdh_calc_secret(ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Derive and export the shared secret.
char peer_verify_data[36]
#define SSL_HS_CLIENT_HELLO
x509_buf raw
The raw certificate data (DER).
int(* f_sni)(void *, ssl_context *, const unsigned char *, size_t)
void sha1(const unsigned char *input, size_t ilen, unsigned char output[20])
Output = SHA-1( input buffer )
void(* calc_verify)(ssl_context *, unsigned char *)
void sha1_finish(sha1_context *ctx, unsigned char output[20])
SHA-1 final digest.
int md_starts(md_context_t *ctx)
Set-up the given context for a new message digest.
#define SSL_HS_SERVER_KEY_EXCHANGE
#define TLS_EXT_TRUNCATED_HMAC
Elliptic curves over GF(p)
int ecdh_read_public(ecdh_context *ctx, const unsigned char *buf, size_t blen)
Parse and import the client's public value.
#define SSL_HS_NEW_SESSION_TICKET
ssl_session * session_negotiate
int ssl_parse_certificate(ssl_context *ssl)
ssl_key_cert * sni_key_cert
#define SSL_SESSION_TICKETS_DISABLED
const int * ciphersuite_list[4]
int ssl_parse_finished(ssl_context *ssl)
void sha256_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[32], int is224)
Output = HMAC-SHA-256( hmac key, input buffer )
int md_init_ctx(md_context_t *ctx, const md_info_t *md_info)
Initialises and fills the message digest context structure with the appropriate values.
int pk_decrypt(pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Decrypt message.
#define SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY
#define SSL_RENEGOTIATION
unsigned char premaster[POLARSSL_PREMASTER_SIZE]
void ssl_session_free(ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
int x509_crt_parse(x509_crt *chain, const unsigned char *buf, size_t buflen)
Parse one or more certificates and add them to the chained list.
#define POLARSSL_ECP_PF_UNCOMPRESSED
Uncompressed point format.
int ssl_write_finished(ssl_context *ssl)
void x509_crt_free(x509_crt *crt)
Unallocate all certificate data.
Configuration options (set of defines)
#define SSL_DEBUG_MSG(level, args)
#define SSL_TRUNC_HMAC_ENABLED
void ssl_handshake_wrapup(ssl_context *ssl)
int ecdh_get_params(ecdh_context *ctx, const ecp_keypair *key, ecdh_side side)
Setup an ECDH context from an EC key.
void md5_finish(md5_context *ctx, unsigned char output[16])
MD5 final digest.
#define pk_ec(pk)
Quick access to an EC context inside a PK context.
int ssl_handshake_server_step(ssl_context *ssl)
#define SSL_LEGACY_NO_RENEGOTIATION
unsigned char mac_key[16]
#define SSL_MAJOR_VERSION_3
#define POLARSSL_ERR_SSL_INVALID_MAC
Verification of the message MAC failed.
pk_type_t ssl_get_ciphersuite_sig_pk_alg(const ssl_ciphersuite_t *info)
struct _x509_crt * next
Next certificate in the CA-chain.
#define POLARSSL_ECP_DP_MAX
Number of supported curves (plus one for NONE).
#define TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT
const md_info_t * md_info_from_type(md_type_t md_type)
Returns the message digest information associated with the given digest type.
#define SSL_HS_CERTIFICATE_REQUEST
#define SSL_CERT_TYPE_RSA_SIGN
ssl_handshake_params * handshake
#define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE
Our own certificate(s) is/are too large to send in an SSL message.
#define SSL_MSG_HANDSHAKE
void(* update_checksum)(ssl_context *, const unsigned char *, size_t)
int ssl_write_certificate(ssl_context *ssl)
#define SSL_ALERT_MSG_PROTOCOL_VERSION
#define POLARSSL_ERR_SSL_NO_RNG
No RNG was provided to the SSL module.
#define SSL_TRUNC_HMAC_DISABLED
Container for an X.509 certificate.
#define SSL_ALERT_MSG_UNRECOGNIZED_NAME
#define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS
Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret...
int aes_crypt_cbc(aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes) ...
struct _ssl_session ssl_session
#define SSL_MINOR_VERSION_0
int pk_verify(pk_context *ctx, md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature.
#define POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION
Handshake protocol not within min/max boundaries.
ssl_key_cert * key_cert
Current key/cert or key/cert list.
#define SSL_HS_SERVER_HELLO_DONE
void x509_crt_init(x509_crt *crt)
Initialize a certificate (chain)
unsigned char * p
ASN1 data, e.g.
key_exchange_type_t key_exchange
Curve information for use by other modules.
int pk_can_do(pk_context *ctx, pk_type_t type)
Tell if a context can do the operation given by type.
void md5_starts(md5_context *ctx)
MD5 context setup.
unsigned char ssl_sig_from_pk(pk_context *pk)
#define SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL
int ssl_flush_output(ssl_context *ssl)
int ssl_ciphersuite_uses_psk(const ssl_ciphersuite_t *info)
#define POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED
Session ticket has expired.
#define TLS_EXT_SESSION_TICKET
#define SSL_HS_SERVER_HELLO
#define SSL_COMPRESS_DEFLATE
#define SSL_MINOR_VERSION_3
#define TLS_EXT_RENEGOTIATION_INFO
int ssl_check_cert_usage(const x509_crt *cert, const ssl_ciphersuite_t *ciphersuite, int cert_endpoint)
pk_type_t
Public key types.
int ssl_parse_change_cipher_spec(ssl_context *ssl)
void sha1_starts(sha1_context *ctx)
SHA-1 context setup.
#define POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO
Processing of the ClientHello handshake message failed.
#define SSL_EMPTY_RENEGOTIATION_INFO
renegotiation info ext
This structure is used for storing ciphersuite information.
int ecp_use_known_dp(ecp_group *grp, ecp_group_id index)
Set a group using well-known domain parameters.
#define SSL_DEBUG_BUF(level, text, buf, len)
#define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE
Processing of the ClientKeyExchange handshake message failed.
#define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED
The own private key or pre-shared key is not set, but needed.
#define SSL_INITIAL_HANDSHAKE
int allow_legacy_renegotiation
#define SSL_COMPRESS_NULL
const ssl_ciphersuite_t * ssl_ciphersuite_from_id(int ciphersuite_id)
int ssl_read_record(ssl_context *ssl)
size_t len
ASN1 length, e.g.
ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
#define SSL_MAX_FRAG_LEN_INVALID
#define TLS_EXT_MAX_FRAGMENT_LENGTH
#define SSL_MAX_FRAG_LEN_NONE
#define SSL_HS_CERTIFICATE_VERIFY
#define TLS_EXT_SERVERNAME
int pk_sign(pk_context *ctx, md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Make signature.
#define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP
Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public.
#define SSL_DEBUG_MPI(level, text, X)
size_t mpi_size(const mpi *X)
Return the total size in bytes.
int mpi_copy(mpi *X, const mpi *Y)
Copy the contents of Y into X.
#define SSL_LEGACY_BREAK_HANDSHAKE
pk_context pk
Container for the public key context.
ssl_transform * transform_negotiate
#define SSL_LEGACY_RENEGOTIATION
#define SSL_SECURE_RENEGOTIATION
#define POLARSSL_ERR_SSL_UNKNOWN_IDENTITY
Unknown identity received (eg, PSK identity)
#define POLARSSL_ERR_SSL_MALLOC_FAILED
Memory allocation failed.
void sha1_update(sha1_context *ctx, const unsigned char *input, size_t ilen)
SHA-1 process buffer.
#define TLS_EXT_SUPPORTED_POINT_FORMATS
void md5_update(md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 process buffer.
int ssl_write_change_cipher_spec(ssl_context *ssl)
int(* f_get_cache)(void *, ssl_session *)
#define SSL_DEBUG_ECP(level, text, X)
int ssl_derive_keys(ssl_context *ssl)
static pk_context * ssl_own_key(ssl_context *ssl)
int md_finish(md_context_t *ctx, unsigned char *output)
Generic message digest final digest.
const ecp_curve_info * ecp_curve_info_from_tls_id(uint16_t tls_id)
Get curve information from a TLS NamedCurve value.
int ssl_psk_derive_premaster(ssl_context *ssl, key_exchange_type_t key_ex)
int version
The X.509 version.
static int safer_memcmp(const void *a, const void *b, size_t n)
int md_free_ctx(md_context_t *ctx)
Free the message-specific context of ctx.
int ssl_send_fatal_handshake_failure(ssl_context *ssl)
ssl_ticket_keys * ticket_keys
#define SSL_MAX_CONTENT_LEN
Size of the input / output buffer.
unsigned char * psk_identity
const char * ssl_get_ciphersuite_name(const int ciphersuite_id)
Return the name of the ciphersuite associated with the given ID.
unsigned char key_name[16]
#define TLS_EXT_SUPPORTED_ELLIPTIC_CURVES
void md5(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD5( input buffer )
#define POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE
The requested feature is not available.
x509_buf subject_raw
The raw subject data (DER).
int md_update(md_context_t *ctx, const unsigned char *input, size_t ilen)
Generic message digest process buffer.
#define POLARSSL_ERR_SSL_BAD_INPUT_DATA
Bad input parameters to function.
int ssl_fetch_input(ssl_context *ssl, size_t nb_want)
int dhm_make_params(dhm_context *ctx, int x_size, unsigned char *output, size_t *olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Setup and write the ServerKeyExchange parameters.
int(* f_psk)(void *, ssl_context *, const unsigned char *, size_t)
int ssl_write_record(ssl_context *ssl)
#define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY
Processing of the CertificateVerify handshake message failed.
int dhm_read_public(dhm_context *ctx, const unsigned char *input, size_t ilen)
Import the peer's public value G^Y.
unsigned char randbytes[64]
Generic message digest context.
#define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN
The server has no ciphersuites in common with the client.
void ssl_optimize_checksum(ssl_context *ssl, const ssl_ciphersuite_t *ciphersuite_info)
md_type_t ssl_md_alg_from_hash(unsigned char hash)
int dhm_calc_secret(dhm_context *ctx, unsigned char *output, size_t *olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Derive and export the shared secret (G^Y)^X mod P.