28 #if defined(POLARSSL_SSL_CLI_C)
33 #if defined(POLARSSL_MEMORY_C)
36 #define polarssl_malloc malloc
37 #define polarssl_free free
45 typedef UINT32 uint32_t;
50 #if defined(POLARSSL_HAVE_TIME)
54 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
55 static void ssl_write_hostname_ext(
ssl_context *ssl,
59 unsigned char *p = buf;
66 SSL_DEBUG_MSG( 3, (
"client hello, adding server name extension: %s",
90 *p++ = (
unsigned char)( ( (ssl->
hostname_len + 5) >> 8 ) & 0xFF );
91 *p++ = (
unsigned char)( ( (ssl->
hostname_len + 5) ) & 0xFF );
93 *p++ = (
unsigned char)( ( (ssl->
hostname_len + 3) >> 8 ) & 0xFF );
94 *p++ = (
unsigned char)( ( (ssl->
hostname_len + 3) ) & 0xFF );
97 *p++ = (
unsigned char)( ( ssl->
hostname_len >> 8 ) & 0xFF );
106 static void ssl_write_renegotiation_ext(
ssl_context *ssl,
110 unsigned char *p = buf;
117 SSL_DEBUG_MSG( 3, (
"client hello, adding renegotiation extension" ) );
134 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
135 static void ssl_write_signature_algorithms_ext(
ssl_context *ssl,
139 unsigned char *p = buf;
140 unsigned char *sig_alg_list = buf + 6;
141 size_t sig_alg_len = 0;
148 SSL_DEBUG_MSG( 3, (
"client hello, adding signature_algorithms extension" ) );
153 #if defined(POLARSSL_RSA_C)
154 #if defined(POLARSSL_SHA512_C)
160 #if defined(POLARSSL_SHA256_C)
166 #if defined(POLARSSL_SHA1_C)
170 #if defined(POLARSSL_MD5_C)
175 #if defined(POLARSSL_ECDSA_C)
176 #if defined(POLARSSL_SHA512_C)
182 #if defined(POLARSSL_SHA256_C)
188 #if defined(POLARSSL_SHA1_C)
192 #if defined(POLARSSL_MD5_C)
218 *p++ = (
unsigned char)( ( ( sig_alg_len + 2 ) >> 8 ) & 0xFF );
219 *p++ = (
unsigned char)( ( ( sig_alg_len + 2 ) ) & 0xFF );
221 *p++ = (
unsigned char)( ( sig_alg_len >> 8 ) & 0xFF );
222 *p++ = (
unsigned char)( ( sig_alg_len ) & 0xFF );
224 *olen = 6 + sig_alg_len;
228 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
229 static void ssl_write_supported_elliptic_curves_ext(
ssl_context *ssl,
233 unsigned char *p = buf;
234 unsigned char elliptic_curve_list[20];
235 size_t elliptic_curve_len = 0;
241 SSL_DEBUG_MSG( 3, (
"client hello, adding supported_elliptic_curves extension" ) );
247 elliptic_curve_list[elliptic_curve_len++] = curve->
tls_id >> 8;
248 elliptic_curve_list[elliptic_curve_len++] = curve->
tls_id & 0xFF;
251 if( elliptic_curve_len == 0 )
257 *p++ = (
unsigned char)( ( ( elliptic_curve_len + 2 ) >> 8 ) & 0xFF );
258 *p++ = (
unsigned char)( ( ( elliptic_curve_len + 2 ) ) & 0xFF );
260 *p++ = (
unsigned char)( ( ( elliptic_curve_len ) >> 8 ) & 0xFF );
261 *p++ = (
unsigned char)( ( ( elliptic_curve_len ) ) & 0xFF );
263 memcpy( p, elliptic_curve_list, elliptic_curve_len );
265 *olen = 6 + elliptic_curve_len;
268 static void ssl_write_supported_point_formats_ext(
ssl_context *ssl,
272 unsigned char *p = buf;
277 SSL_DEBUG_MSG( 3, (
"client hello, adding supported_point_formats extension" ) );
292 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
293 static void ssl_write_max_fragment_length_ext(
ssl_context *ssl,
297 unsigned char *p = buf;
304 SSL_DEBUG_MSG( 3, (
"client hello, adding max_fragment_length extension" ) );
318 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
319 static void ssl_write_truncated_hmac_ext(
ssl_context *ssl,
320 unsigned char *buf,
size_t *olen )
322 unsigned char *p = buf;
330 SSL_DEBUG_MSG( 3, (
"client hello, adding truncated_hmac extension" ) );
342 #if defined(POLARSSL_SSL_SESSION_TICKETS)
343 static void ssl_write_session_ticket_ext(
ssl_context *ssl,
344 unsigned char *buf,
size_t *olen )
346 unsigned char *p = buf;
355 SSL_DEBUG_MSG( 3, (
"client hello, adding session ticket extension" ) );
360 *p++ = (
unsigned char)( ( tlen >> 8 ) & 0xFF );
361 *p++ = (
unsigned char)( ( tlen ) & 0xFF );
371 SSL_DEBUG_MSG( 3, (
"sending session ticket of length %d", tlen ) );
379 static int ssl_write_client_hello(
ssl_context *ssl )
382 size_t i, n, olen, ext_len = 0;
384 unsigned char *p, *q;
385 #if defined(POLARSSL_HAVE_TIME)
388 const int *ciphersuites;
421 #if defined(POLARSSL_HAVE_TIME)
423 *p++ = (
unsigned char)( t >> 24 );
424 *p++ = (
unsigned char)( t >> 16 );
425 *p++ = (
unsigned char)( t >> 8 );
426 *p++ = (
unsigned char)( t );
428 SSL_DEBUG_MSG( 3, (
"client hello, current time: %lu", t ) );
430 if( ( ret = ssl->
f_rng( ssl->
p_rng, p, 4 ) ) != 0 )
436 if( ( ret = ssl->
f_rng( ssl->
p_rng, p, 28 ) ) != 0 )
443 SSL_DEBUG_BUF( 3,
"client hello, random bytes", buf + 6, 32 );
463 #if defined(POLARSSL_SSL_SESSION_TICKETS)
481 *p++ = (
unsigned char) n;
483 for( i = 0; i < n; i++ )
486 SSL_DEBUG_MSG( 3, (
"client hello, session id len.: %d", n ) );
506 for( i = 0; ciphersuites[i] != 0; i++ )
510 if( ciphersuite_info == NULL )
521 *p++ = (
unsigned char)( ciphersuites[i] >> 8 );
522 *p++ = (
unsigned char)( ciphersuites[i] );
525 *q++ = (
unsigned char)( n >> 7 );
526 *q++ = (
unsigned char)( n << 1 );
528 SSL_DEBUG_MSG( 3, (
"client hello, got %d ciphersuites", n ) );
531 #if defined(POLARSSL_ZLIB_SUPPORT)
532 SSL_DEBUG_MSG( 3, (
"client hello, compress len.: %d", 2 ) );
540 SSL_DEBUG_MSG( 3, (
"client hello, compress len.: %d", 1 ) );
549 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
550 ssl_write_hostname_ext( ssl, p + 2 + ext_len, &olen );
554 ssl_write_renegotiation_ext( ssl, p + 2 + ext_len, &olen );
557 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
558 ssl_write_signature_algorithms_ext( ssl, p + 2 + ext_len, &olen );
562 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
563 ssl_write_supported_elliptic_curves_ext( ssl, p + 2 + ext_len, &olen );
566 ssl_write_supported_point_formats_ext( ssl, p + 2 + ext_len, &olen );
570 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
571 ssl_write_max_fragment_length_ext( ssl, p + 2 + ext_len, &olen );
575 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
576 ssl_write_truncated_hmac_ext( ssl, p + 2 + ext_len, &olen );
580 #if defined(POLARSSL_SSL_SESSION_TICKETS)
581 ssl_write_session_ticket_ext( ssl, p + 2 + ext_len, &olen );
585 SSL_DEBUG_MSG( 3, (
"client hello, total extension length: %d",
588 *p++ = (
unsigned char)( ( ext_len >> 8 ) & 0xFF );
589 *p++ = (
unsigned char)( ( ext_len ) & 0xFF );
609 static int ssl_parse_renegotiation_info(
ssl_context *ssl,
610 const unsigned char *buf,
617 if( len != 1 || buf[0] != 0x0 )
619 SSL_DEBUG_MSG( 1, (
"non-zero length renegotiated connection field" ) );
637 SSL_DEBUG_MSG( 1, (
"non-matching renegotiated connection field" ) );
649 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
650 static int ssl_parse_max_fragment_length_ext(
ssl_context *ssl,
651 const unsigned char *buf,
669 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
670 static int ssl_parse_truncated_hmac_ext(
ssl_context *ssl,
671 const unsigned char *buf,
688 #if defined(POLARSSL_SSL_SESSION_TICKETS)
689 static int ssl_parse_session_ticket_ext(
ssl_context *ssl,
690 const unsigned char *buf,
707 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
708 static int ssl_parse_supported_point_formats_ext(
ssl_context *ssl,
709 const unsigned char *buf,
713 const unsigned char *p;
716 if( list_size + 1 != len )
723 while( list_size > 0 )
741 static int ssl_parse_server_hello(
ssl_context *ssl )
746 unsigned char *buf, *ext;
747 int renegotiation_info_seen = 0;
748 int handshake_failure = 0;
749 #if defined(POLARSSL_DEBUG_C)
797 SSL_DEBUG_MSG( 1, (
"server only supports ssl smaller than minimum"
807 #if defined(POLARSSL_DEBUG_C)
808 t = ( (uint32_t) buf[6] << 24 )
809 | ( (uint32_t) buf[7] << 16 )
810 | ( (uint32_t) buf[8] << 8 )
811 | ( (uint32_t) buf[9] );
812 SSL_DEBUG_MSG( 3, (
"server hello, current time: %lu", t ) );
819 SSL_DEBUG_BUF( 3,
"server hello, random bytes", buf + 6, 32 );
837 ext_len = ( ( buf[42 + n] << 8 )
840 if( ( ext_len > 0 && ext_len < 4 ) ||
848 i = ( buf[39 + n] << 8 ) | buf[40 + n];
864 SSL_DEBUG_MSG( 3, (
"server hello, session id len.: %d", n ) );
879 #if defined(POLARSSL_HAVE_TIME)
901 SSL_DEBUG_MSG( 3, (
"server hello, chosen ciphersuite: %d", i ) );
902 SSL_DEBUG_MSG( 3, (
"server hello, compress alg.: %d", buf[41 + n] ) );
921 #
if defined(POLARSSL_ZLIB_SUPPORT)
933 SSL_DEBUG_MSG( 2, (
"server hello, total extension length: %d", ext_len ) );
937 unsigned int ext_id = ( ( ext[0] << 8 )
939 unsigned int ext_size = ( ( ext[2] << 8 )
942 if( ext_size + 4 > ext_len )
952 renegotiation_info_seen = 1;
954 if( ( ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size ) ) != 0 )
959 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
961 SSL_DEBUG_MSG( 3, (
"found max_fragment_length extension" ) );
963 if( ( ret = ssl_parse_max_fragment_length_ext( ssl,
964 ext + 4, ext_size ) ) != 0 )
972 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
976 if( ( ret = ssl_parse_truncated_hmac_ext( ssl,
977 ext + 4, ext_size ) ) != 0 )
985 #if defined(POLARSSL_SSL_SESSION_TICKETS)
989 if( ( ret = ssl_parse_session_ticket_ext( ssl,
990 ext + 4, ext_size ) ) != 0 )
998 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
1000 SSL_DEBUG_MSG( 3, (
"found supported_point_formats extension" ) );
1002 if( ( ret = ssl_parse_supported_point_formats_ext( ssl,
1003 ext + 4, ext_size ) ) != 0 )
1012 SSL_DEBUG_MSG( 3, (
"unknown extension found: %d (ignoring)",
1016 ext_len -= 4 + ext_size;
1017 ext += 4 + ext_size;
1019 if( ext_len > 0 && ext_len < 4 )
1032 SSL_DEBUG_MSG( 1, (
"legacy renegotiation, breaking off handshake" ) );
1033 handshake_failure = 1;
1037 renegotiation_info_seen == 0 )
1039 SSL_DEBUG_MSG( 1, (
"renegotiation_info extension missing (secure)" ) );
1040 handshake_failure = 1;
1047 handshake_failure = 1;
1051 renegotiation_info_seen == 1 )
1053 SSL_DEBUG_MSG( 1, (
"renegotiation_info extension present (legacy)" ) );
1054 handshake_failure = 1;
1057 if( handshake_failure == 1 )
1070 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1071 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
1072 static int ssl_parse_server_dh_params(
ssl_context *ssl,
unsigned char **p,
1073 unsigned char *end )
1095 SSL_DEBUG_MSG( 1, (
"bad server key exchange message (DHM length)" ) );
1108 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1109 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
1110 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
1111 static int ssl_parse_server_ecdh_params(
ssl_context *ssl,
1113 unsigned char *end )
1126 (
const unsigned char **) p, end ) ) != 0 )
1138 SSL_DEBUG_MSG( 1, (
"bad server key exchange message (ECDH length)" ) );
1150 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1151 static int ssl_parse_server_psk_hint(
ssl_context *ssl,
1153 unsigned char *end )
1164 len = (*p)[0] << 8 | (*p)[1];
1167 if( (*p) + len > end )
1169 SSL_DEBUG_MSG( 1, (
"bad server key exchange message (psk_identity_hint length)" ) );
1182 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) || \
1183 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
1187 static int ssl_write_encrypted_pms(
ssl_context *ssl,
1188 size_t offset,
size_t *olen,
1205 if( ( ret = ssl->
f_rng( ssl->
p_rng, p + 2, 46 ) ) != 0 )
1225 ssl->
out_msg + offset + len_bytes, olen,
1233 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
1234 defined(POLARSSL_SSL_PROTO_TLS1_2)
1235 if( len_bytes == 2 )
1237 ssl->
out_msg[offset+0] = (
unsigned char)( *olen >> 8 );
1238 ssl->
out_msg[offset+1] = (
unsigned char)( *olen );
1248 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1249 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1250 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1251 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1252 static int ssl_parse_signature_algorithm(
ssl_context *ssl,
1268 if( (*p) + 2 > end )
1277 "HashAlgorithm %d", *(p)[0] ) );
1287 "SignatureAlgorithm %d", (*p)[1] ) );
1291 SSL_DEBUG_MSG( 2, (
"Server used SignatureAlgorithm %d", (*p)[1] ) );
1292 SSL_DEBUG_MSG( 2, (
"Server used HashAlgorithm %d", (*p)[0] ) );
1302 static int ssl_parse_server_key_exchange(
ssl_context *ssl )
1306 unsigned char *p, *end;
1307 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1308 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1309 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1310 size_t sig_len, params_len;
1311 unsigned char hash[64];
1319 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED)
1322 SSL_DEBUG_MSG( 2, (
"<= skip parse server key exchange" ) );
1363 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1369 if( ssl_parse_server_psk_hint( ssl, &p, end ) != 0 )
1377 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) || \
1378 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
1385 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1386 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
1390 if( ssl_parse_server_dh_params( ssl, &p, end ) != 0 )
1399 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1400 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
1401 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1406 if( ssl_parse_server_ecdh_params( ssl, &p, end ) != 0 )
1421 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1422 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1423 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1428 params_len = p - ( ssl->
in_msg + 4 );
1433 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1436 if( ssl_parse_signature_algorithm( ssl, &p, end,
1437 &md_alg, &pk_alg ) != 0 )
1451 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
1452 defined(POLARSSL_SSL_PROTO_TLS1_1)
1471 sig_len = ( p[0] << 8 ) | p[1];
1474 if( end != p + sig_len )
1485 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
1486 defined(POLARSSL_SSL_PROTO_TLS1_1)
1520 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
1521 defined(POLARSSL_SSL_PROTO_TLS1_2)
1556 SSL_DEBUG_BUF( 3,
"parameters hash", hash, hashlen != 0 ? hashlen :
1569 md_alg, hash, hashlen, p, sig_len ) ) != 0 )
1587 static int ssl_parse_certificate_request(
ssl_context *ssl )
1590 unsigned char *buf, *p;
1591 size_t n = 0, m = 0;
1592 size_t cert_type_len = 0, dn_len = 0;
1646 cert_type_len = buf[4];
1656 while( cert_type_len > 0 )
1658 #if defined(POLARSSL_RSA_C)
1667 #if defined(POLARSSL_ECDSA_C)
1684 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1689 size_t sig_alg_len = ( ( buf[5 + n] << 8 )
1706 dn_len = ( ( buf[5 + m + n] << 8 )
1707 | ( buf[6 + m + n] ) );
1722 static int ssl_parse_server_hello_done(
ssl_context *ssl )
1758 static int ssl_write_client_key_exchange(
ssl_context *ssl )
1766 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED)
1774 ssl->
out_msg[4] = (
unsigned char)( n >> 8 );
1775 ssl->
out_msg[5] = (
unsigned char)( n );
1806 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1807 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1843 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1857 ssl->
out_msg[i++] = (
unsigned char)( n >> 8 );
1858 ssl->
out_msg[i++] = (
unsigned char)( n );
1863 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
1870 #if defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
1873 if( ( ret = ssl_write_encrypted_pms( ssl, i, &n, 2 ) ) != 0 )
1878 #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
1885 ssl->
out_msg[i++] = (
unsigned char)( n >> 8 );
1886 ssl->
out_msg[i++] = (
unsigned char)( n );
1900 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
1933 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED)
1937 if( ( ret = ssl_write_encrypted_pms( ssl, i, &n, 0 ) ) != 0 )
1943 ((void) ciphersuite_info);
1971 #if !defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) && \
1972 !defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
1973 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
1974 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1975 static int ssl_write_certificate_verify(
ssl_context *ssl )
1995 static int ssl_write_certificate_verify(
ssl_context *ssl )
1999 size_t n = 0, offset = 0;
2000 unsigned char hash[48];
2001 unsigned char *hash_start = hash;
2003 unsigned int hashlen;
2034 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
2035 defined(POLARSSL_SSL_PROTO_TLS1_1)
2066 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
2109 ssl->
out_msg + 6 + offset, &n,
2116 ssl->
out_msg[4 + offset] = (
unsigned char)( n >> 8 );
2117 ssl->
out_msg[5 + offset] = (
unsigned char)( n );
2139 #if defined(POLARSSL_SSL_SESSION_TICKETS)
2140 static int ssl_parse_new_session_ticket(
ssl_context *ssl )
2145 unsigned char *ticket;
2180 lifetime = ( ssl->
in_msg[4] << 24 ) | ( ssl->
in_msg[5] << 16 ) |
2183 ticket_len = ( ssl->
in_msg[8] << 8 ) | ( ssl->
in_msg[9] );
2185 if( ticket_len + 10 != ssl->
in_hslen )
2200 if( ticket_len == 0)
2213 memcpy( ticket, ssl->
in_msg + 10, ticket_len );
2224 SSL_DEBUG_MSG( 3, (
"ticket in use, discarding session id" ) );
2248 switch( ssl->
state )
2258 ret = ssl_write_client_hello( ssl );
2269 ret = ssl_parse_server_hello( ssl );
2277 ret = ssl_parse_server_key_exchange( ssl );
2281 ret = ssl_parse_certificate_request( ssl );
2285 ret = ssl_parse_server_hello_done( ssl );
2300 ret = ssl_write_client_key_exchange( ssl );
2304 ret = ssl_write_certificate_verify( ssl );
2321 #if defined(POLARSSL_SSL_SESSION_TICKETS)
2323 ret = ssl_parse_new_session_ticket( ssl );
#define SSL_HS_CLIENT_KEY_EXCHANGE
#define SSL_CERT_TYPE_ECDSA_SIGN
#define SSL_ALERT_LEVEL_FATAL
int ecdh_make_public(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 export the client's public value.
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 POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE
Processing of the ServerKeyExchange handshake message failed.
#define SSL_DEBUG_RET(level, text, ret)
void *(* polarssl_malloc)(size_t len)
#define POLARSSL_ERR_SSL_PK_TYPE_MISMATCH
Public key type mismatch (eg, asked for RSA key exchange and presented EC key)
#define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE
Processing of the ServerHelloDone handshake message failed.
#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
const ecp_curve_info * ecp_curve_list(void)
Return the list of supported curves with associated info.
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
#define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO
Processing of the ServerHello handshake message failed.
#define SSL_HS_NEW_SESSION_TICKET
ssl_session * session_negotiate
int ssl_parse_certificate(ssl_context *ssl)
#define SSL_SESSION_TICKETS_DISABLED
const int * ciphersuite_list[4]
int ssl_parse_finished(ssl_context *ssl)
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.
#define SSL_RENEGOTIATION
unsigned char premaster[POLARSSL_PREMASTER_SIZE]
#define POLARSSL_ECP_PF_UNCOMPRESSED
Uncompressed point format.
#define POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET
Processing of the NewSessionTicket handshake message failed.
int ssl_write_finished(ssl_context *ssl)
Configuration options (set of defines)
#define SSL_DEBUG_MSG(level, args)
#define SSL_TRUNC_HMAC_ENABLED
void ssl_handshake_wrapup(ssl_context *ssl)
void md5_finish(md5_context *ctx, unsigned char output[16])
MD5 final digest.
#define SSL_MAX_MAJOR_VERSION
#define SSL_LEGACY_NO_RENEGOTIATION
#define SSL_MAJOR_VERSION_3
pk_type_t ssl_get_ciphersuite_sig_pk_alg(const ssl_ciphersuite_t *info)
int dhm_read_params(dhm_context *ctx, unsigned char **p, const unsigned char *end)
Parse the ServerKeyExchange parameters.
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_CERT_TYPE_RSA_SIGN
#define SSL_HS_CERTIFICATE_REQUEST
ssl_handshake_params * handshake
#define SSL_MSG_HANDSHAKE
int ssl_write_certificate(ssl_context *ssl)
#define SSL_ALERT_MSG_PROTOCOL_VERSION
#define SSL_TRUNC_HMAC_DISABLED
#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.
#define SSL_HS_SERVER_HELLO_DONE
static x509_crt * ssl_own_cert(ssl_context *ssl)
void(* polarssl_free)(void *ptr)
int ssl_handshake_client_step(ssl_context *ssl)
#define POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE
An unexpected message was received from our peer.
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)
int ssl_flush_output(ssl_context *ssl)
#define TLS_EXT_SESSION_TICKET
#define SSL_HS_SERVER_HELLO
#define SSL_COMPRESS_DEFLATE
#define SSL_MINOR_VERSION_3
#define TLS_EXT_RENEGOTIATION_INFO
pk_type_t
Public key types.
#define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST
Processing of the CertificateRequest handshake message failed.
int ssl_parse_change_cipher_spec(ssl_context *ssl)
int ecdh_read_params(ecdh_context *ctx, const unsigned char **buf, const unsigned char *end)
Parse the ServerKeyExhange parameters.
void sha1_starts(sha1_context *ctx)
SHA-1 context setup.
#define SSL_EMPTY_RENEGOTIATION_INFO
renegotiation info ext
This structure is used for storing ciphersuite information.
#define SSL_DEBUG_BUF(level, text, buf, len)
#define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED
The own private key or pre-shared key is not set, but needed.
#define SSL_INITIAL_HANDSHAKE
#define SSL_MAX_MINOR_VERSION
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)
#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.
int dhm_make_public(dhm_context *ctx, int x_size, unsigned char *output, size_t olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Create own private value X and export G^X.
#define SSL_DEBUG_MPI(level, text, X)
size_t mpi_size(const mpi *X)
Return the total size in bytes.
#define SSL_LEGACY_BREAK_HANDSHAKE
int pk_encrypt(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)
Encrypt message.
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_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)
#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.
int ssl_psk_derive_premaster(ssl_context *ssl, key_exchange_type_t key_ex)
int md_free_ctx(md_context_t *ctx)
Free the message-specific context of ctx.
int ssl_send_fatal_handshake_failure(ssl_context *ssl)
#define SSL_MAX_CONTENT_LEN
Size of the input / output buffer.
unsigned char * psk_identity
#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.
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_write_record(ssl_context *ssl)
unsigned char randbytes[64]
Generic message digest context.
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.