28 #if defined(POLARSSL_SSL_CLI_C)
33 #if defined(POLARSSL_MEMORY_C)
36 #define polarssl_malloc malloc
37 #define polarssl_free free
43 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
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" ) );
639 SSL_DEBUG_MSG( 1, (
"non-matching renegotiated connection field" ) );
651 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
652 static int ssl_parse_max_fragment_length_ext(
ssl_context *ssl,
653 const unsigned char *buf,
671 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
672 static int ssl_parse_truncated_hmac_ext(
ssl_context *ssl,
673 const unsigned char *buf,
690 #if defined(POLARSSL_SSL_SESSION_TICKETS)
691 static int ssl_parse_session_ticket_ext(
ssl_context *ssl,
692 const unsigned char *buf,
709 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
710 static int ssl_parse_supported_point_formats_ext(
ssl_context *ssl,
711 const unsigned char *buf,
715 const unsigned char *p;
718 if( list_size + 1 != len )
725 while( list_size > 0 )
743 static int ssl_parse_server_hello(
ssl_context *ssl )
748 unsigned char *buf, *ext;
749 int renegotiation_info_seen = 0;
750 int handshake_failure = 0;
751 #if defined(POLARSSL_DEBUG_C)
799 SSL_DEBUG_MSG( 1, (
"server only supports ssl smaller than minimum"
809 #if defined(POLARSSL_DEBUG_C)
810 t = ( (uint32_t) buf[6] << 24 )
811 | ( (uint32_t) buf[7] << 16 )
812 | ( (uint32_t) buf[8] << 8 )
813 | ( (uint32_t) buf[9] );
814 SSL_DEBUG_MSG( 3, (
"server hello, current time: %lu", t ) );
821 SSL_DEBUG_BUF( 3,
"server hello, random bytes", buf + 6, 32 );
839 ext_len = ( ( buf[42 + n] << 8 )
842 if( ( ext_len > 0 && ext_len < 4 ) ||
850 i = ( buf[39 + n] << 8 ) | buf[40 + n];
866 SSL_DEBUG_MSG( 3, (
"server hello, session id len.: %d", n ) );
881 #if defined(POLARSSL_HAVE_TIME)
903 SSL_DEBUG_MSG( 3, (
"server hello, chosen ciphersuite: %d", i ) );
904 SSL_DEBUG_MSG( 3, (
"server hello, compress alg.: %d", buf[41 + n] ) );
923 #
if defined(POLARSSL_ZLIB_SUPPORT)
935 SSL_DEBUG_MSG( 2, (
"server hello, total extension length: %d", ext_len ) );
939 unsigned int ext_id = ( ( ext[0] << 8 )
941 unsigned int ext_size = ( ( ext[2] << 8 )
944 if( ext_size + 4 > ext_len )
954 renegotiation_info_seen = 1;
956 if( ( ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size ) ) != 0 )
961 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
963 SSL_DEBUG_MSG( 3, (
"found max_fragment_length extension" ) );
965 if( ( ret = ssl_parse_max_fragment_length_ext( ssl,
966 ext + 4, ext_size ) ) != 0 )
974 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
978 if( ( ret = ssl_parse_truncated_hmac_ext( ssl,
979 ext + 4, ext_size ) ) != 0 )
987 #if defined(POLARSSL_SSL_SESSION_TICKETS)
991 if( ( ret = ssl_parse_session_ticket_ext( ssl,
992 ext + 4, ext_size ) ) != 0 )
1000 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
1002 SSL_DEBUG_MSG( 3, (
"found supported_point_formats extension" ) );
1004 if( ( ret = ssl_parse_supported_point_formats_ext( ssl,
1005 ext + 4, ext_size ) ) != 0 )
1014 SSL_DEBUG_MSG( 3, (
"unknown extension found: %d (ignoring)",
1018 ext_len -= 4 + ext_size;
1019 ext += 4 + ext_size;
1021 if( ext_len > 0 && ext_len < 4 )
1034 SSL_DEBUG_MSG( 1, (
"legacy renegotiation, breaking off handshake" ) );
1035 handshake_failure = 1;
1039 renegotiation_info_seen == 0 )
1041 SSL_DEBUG_MSG( 1, (
"renegotiation_info extension missing (secure)" ) );
1042 handshake_failure = 1;
1049 handshake_failure = 1;
1053 renegotiation_info_seen == 1 )
1055 SSL_DEBUG_MSG( 1, (
"renegotiation_info extension present (legacy)" ) );
1056 handshake_failure = 1;
1059 if( handshake_failure == 1 )
1072 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1073 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
1074 static int ssl_parse_server_dh_params(
ssl_context *ssl,
unsigned char **p,
1075 unsigned char *end )
1097 SSL_DEBUG_MSG( 1, (
"bad server key exchange message (DHM length)" ) );
1110 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1111 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
1112 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
1113 static int ssl_parse_server_ecdh_params(
ssl_context *ssl,
1115 unsigned char *end )
1128 (
const unsigned char **) p, end ) ) != 0 )
1140 SSL_DEBUG_MSG( 1, (
"bad server key exchange message (ECDH length)" ) );
1152 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1153 static int ssl_parse_server_psk_hint(
ssl_context *ssl,
1155 unsigned char *end )
1166 len = (*p)[0] << 8 | (*p)[1];
1169 if( (*p) + len > end )
1171 SSL_DEBUG_MSG( 1, (
"bad server key exchange message (psk_identity_hint length)" ) );
1184 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) || \
1185 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
1189 static int ssl_write_encrypted_pms(
ssl_context *ssl,
1190 size_t offset,
size_t *olen,
1207 if( ( ret = ssl->
f_rng( ssl->
p_rng, p + 2, 46 ) ) != 0 )
1227 ssl->
out_msg + offset + len_bytes, olen,
1235 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
1236 defined(POLARSSL_SSL_PROTO_TLS1_2)
1237 if( len_bytes == 2 )
1239 ssl->
out_msg[offset+0] = (
unsigned char)( *olen >> 8 );
1240 ssl->
out_msg[offset+1] = (
unsigned char)( *olen );
1250 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1251 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1252 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1253 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1254 static int ssl_parse_signature_algorithm(
ssl_context *ssl,
1270 if( (*p) + 2 > end )
1279 "HashAlgorithm %d", *(p)[0] ) );
1289 "SignatureAlgorithm %d", (*p)[1] ) );
1293 SSL_DEBUG_MSG( 2, (
"Server used SignatureAlgorithm %d", (*p)[1] ) );
1294 SSL_DEBUG_MSG( 2, (
"Server used HashAlgorithm %d", (*p)[0] ) );
1304 static int ssl_parse_server_key_exchange(
ssl_context *ssl )
1308 unsigned char *p, *end;
1309 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1310 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1311 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1312 size_t sig_len, params_len;
1313 unsigned char hash[64];
1321 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED)
1324 SSL_DEBUG_MSG( 2, (
"<= skip parse server key exchange" ) );
1365 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1371 if( ssl_parse_server_psk_hint( ssl, &p, end ) != 0 )
1379 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) || \
1380 defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
1387 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1388 defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
1392 if( ssl_parse_server_dh_params( ssl, &p, end ) != 0 )
1401 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1402 defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
1403 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1408 if( ssl_parse_server_ecdh_params( ssl, &p, end ) != 0 )
1423 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
1424 defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1425 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1430 params_len = p - ( ssl->
in_msg + 4 );
1435 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1438 if( ssl_parse_signature_algorithm( ssl, &p, end,
1439 &md_alg, &pk_alg ) != 0 )
1453 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
1454 defined(POLARSSL_SSL_PROTO_TLS1_1)
1473 sig_len = ( p[0] << 8 ) | p[1];
1476 if( end != p + sig_len )
1487 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
1488 defined(POLARSSL_SSL_PROTO_TLS1_1)
1522 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
1523 defined(POLARSSL_SSL_PROTO_TLS1_2)
1558 SSL_DEBUG_BUF( 3,
"parameters hash", hash, hashlen != 0 ? hashlen :
1571 md_alg, hash, hashlen, p, sig_len ) ) != 0 )
1589 static int ssl_parse_certificate_request(
ssl_context *ssl )
1592 unsigned char *buf, *p;
1593 size_t n = 0, m = 0;
1594 size_t cert_type_len = 0, dn_len = 0;
1648 cert_type_len = buf[4];
1658 while( cert_type_len > 0 )
1660 #if defined(POLARSSL_RSA_C)
1669 #if defined(POLARSSL_ECDSA_C)
1686 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
1691 size_t sig_alg_len = ( ( buf[5 + n] << 8 )
1708 dn_len = ( ( buf[5 + m + n] << 8 )
1709 | ( buf[6 + m + n] ) );
1724 static int ssl_parse_server_hello_done(
ssl_context *ssl )
1760 static int ssl_write_client_key_exchange(
ssl_context *ssl )
1768 #if defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED)
1776 ssl->
out_msg[4] = (
unsigned char)( n >> 8 );
1777 ssl->
out_msg[5] = (
unsigned char)( n );
1808 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
1809 defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1845 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1859 ssl->
out_msg[i++] = (
unsigned char)( n >> 8 );
1860 ssl->
out_msg[i++] = (
unsigned char)( n );
1865 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
1872 #if defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
1875 if( ( ret = ssl_write_encrypted_pms( ssl, i, &n, 2 ) ) != 0 )
1880 #if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
1887 ssl->
out_msg[i++] = (
unsigned char)( n >> 8 );
1888 ssl->
out_msg[i++] = (
unsigned char)( n );
1902 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
1935 #if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED)
1939 if( ( ret = ssl_write_encrypted_pms( ssl, i, &n, 0 ) ) != 0 )
1945 ((void) ciphersuite_info);
1973 #if !defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) && \
1974 !defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
1975 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
1976 !defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
1977 static int ssl_write_certificate_verify(
ssl_context *ssl )
1997 static int ssl_write_certificate_verify(
ssl_context *ssl )
2001 size_t n = 0, offset = 0;
2002 unsigned char hash[48];
2003 unsigned char *hash_start = hash;
2005 unsigned int hashlen;
2036 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
2037 defined(POLARSSL_SSL_PROTO_TLS1_1)
2068 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
2111 ssl->
out_msg + 6 + offset, &n,
2118 ssl->
out_msg[4 + offset] = (
unsigned char)( n >> 8 );
2119 ssl->
out_msg[5 + offset] = (
unsigned char)( n );
2141 #if defined(POLARSSL_SSL_SESSION_TICKETS)
2142 static int ssl_parse_new_session_ticket(
ssl_context *ssl )
2147 unsigned char *ticket;
2182 lifetime = ( ssl->
in_msg[4] << 24 ) | ( ssl->
in_msg[5] << 16 ) |
2185 ticket_len = ( ssl->
in_msg[8] << 8 ) | ( ssl->
in_msg[9] );
2187 if( ticket_len + 10 != ssl->
in_hslen )
2202 if( ticket_len == 0)
2215 memcpy( ticket, ssl->
in_msg + 10, ticket_len );
2226 SSL_DEBUG_MSG( 3, (
"ticket in use, discarding session id" ) );
2250 switch( ssl->
state )
2260 ret = ssl_write_client_hello( ssl );
2271 ret = ssl_parse_server_hello( ssl );
2279 ret = ssl_parse_server_key_exchange( ssl );
2283 ret = ssl_parse_certificate_request( ssl );
2287 ret = ssl_parse_server_hello_done( ssl );
2302 ret = ssl_write_client_key_exchange( ssl );
2306 ret = ssl_write_certificate_verify( ssl );
2323 #if defined(POLARSSL_SSL_SESSION_TICKETS)
2325 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)
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)
#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.