Home | History | Annotate | Download | only in wpa_supplicant

Lines Matching full:conn

90 static int tls_derive_keys(struct tlsv1_client *conn,
93 static int tls_process_server_key_exchange(struct tlsv1_client *conn, u8 ct,
95 static int tls_process_certificate_request(struct tlsv1_client *conn, u8 ct,
97 static int tls_process_server_hello_done(struct tlsv1_client *conn, u8 ct,
101 static void tls_alert(struct tlsv1_client *conn, u8 level, u8 description)
103 conn->alert_level = level;
104 conn->alert_description = description;
108 static void tls_verify_hash_add(struct tlsv1_client *conn, const u8 *buf,
111 if (conn->verify_md5_client && conn->verify_sha1_client) {
112 crypto_hash_update(conn->verify_md5_client, buf, len);
113 crypto_hash_update(conn->verify_sha1_client, buf, len);
115 if (conn->verify_md5_server && conn->verify_sha1_server) {
116 crypto_hash_update(conn->verify_md5_server, buf, len);
117 crypto_hash_update(conn->verify_sha1_server, buf, len);
119 if (conn->verify_md5_cert && conn->verify_sha1_cert) {
120 crypto_hash_update(conn->verify_md5_cert, buf, len);
121 crypto_hash_update(conn->verify_sha1_cert, buf, len);
126 static u8 * tls_send_alert(struct tlsv1_client *conn,
165 static u8 * tls_send_client_hello(struct tlsv1_client *conn,
176 WPA_PUT_BE32(conn->client_random, now.sec);
177 if (os_get_random(conn->client_random + 4, TLS_RANDOM_LEN - 4)) {
183 conn->client_random, TLS_RANDOM_LEN);
185 len = 100 + conn->num_cipher_suites * 2 + conn->client_hello_ext_len;
208 os_memcpy(pos, conn->client_random, TLS_RANDOM_LEN);
211 *pos++ = conn->session_id_len;
212 os_memcpy(pos, conn->session_id, conn->session_id_len);
213 pos += conn->session_id_len;
215 WPA_PUT_BE16(pos, 2 * conn->num_cipher_suites);
217 for (i = 0; i < conn->num_cipher_suites; i++) {
218 WPA_PUT_BE16(pos, conn->cipher_suites[i]);
225 if (conn->client_hello_ext) {
226 os_memcpy(pos, conn->client_hello_ext,
227 conn->client_hello_ext_len);
228 pos += conn->client_hello_ext_len;
232 tls_verify_hash_add(conn, hs_start, pos - hs_start);
234 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
237 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
243 conn->state = SERVER_HELLO;
249 static int tls_process_server_hello(struct tlsv1_client *conn, u8 ct,
259 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
274 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
299 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
309 os_memcpy(conn->server_random, pos, TLS_RANDOM_LEN);
312 conn->server_random, TLS_RANDOM_LEN);
319 if (conn->session_id_len && conn->session_id_len == *pos &&
320 os_memcmp(conn->session_id, pos + 1, conn->session_id_len) == 0) {
321 pos += 1 + conn->session_id_len;
323 conn->session_resumed = 1;
325 conn->session_id_len = *pos;
327 os_memcpy(conn->session_id, pos, conn->session_id_len);
328 pos += conn->session_id_len;
331 conn->session_id, conn->session_id_len);
338 for (i = 0; i < conn->num_cipher_suites; i++) {
339 if (cipher_suite == conn->cipher_suites[i])
342 if (i == conn->num_cipher_suites) {
345 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
350 if (conn->session_resumed && cipher_suite != conn->prev_cipher_suite) {
353 "0x%04x)", cipher_suite, conn->prev_cipher_suite);
354 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
359 if (tlsv1_record_set_cipher_suite(&conn->rl, cipher_suite) < 0) {
362 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
367 conn->prev_cipher_suite = cipher_suite;
369 if (conn->session_resumed || conn->ticket_key)
370 tls_derive_keys(conn, NULL, 0);
378 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
392 conn->state = (conn->session_resumed || conn->ticket) ?
399 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
404 static int tls_server_key_exchange_allowed(struct tlsv1_client *conn)
409 suite = tls_get_cipher_suite(conn->rl.cipher_suite);
429 static int tls_process_certificate(struct tlsv1_client *conn, u8 ct,
441 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
452 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
465 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
470 return tls_process_server_key_exchange(conn, ct, in_data,
473 return tls_process_certificate_request(conn, ct, in_data,
476 return tls_process_server_hello_done(conn, ct, in_data,
483 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
505 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
517 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
526 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
540 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
550 crypto_public_key_free(conn->server_rsa_key);
552 &conn->server_rsa_key)) {
555 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
566 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
582 if (x509_certificate_chain_validate(conn->trusted_certs, chain,
610 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, tls_reason);
619 conn->state = SERVER_KEY_EXCHANGE;
625 static void tlsv1_client_free_dh(struct tlsv1_client *conn)
627 os_free(conn->dh_p);
628 os_free(conn->dh_g);
629 os_free(conn->dh_ys);
630 conn->dh_p = conn->dh_g = conn->dh_ys = NULL;
634 static int tlsv1_process_diffie_hellman(struct tlsv1_client *conn,
639 tlsv1_client_free_dh(conn);
646 conn->dh_p_len = WPA_GET_BE16(pos);
648 if (conn->dh_p_len == 0 || end - pos < (int) conn->dh_p_len)
650 conn->dh_p = os_malloc(conn->dh_p_len);
651 if (conn->dh_p == NULL)
653 os_memcpy(conn->dh_p, pos, conn->dh_p_len);
654 pos += conn->dh_p_len;
656 conn->dh_p, conn->dh_p_len);
660 conn->dh_g_len = WPA_GET_BE16(pos);
662 if (conn->dh_g_len == 0 || end - pos < (int) conn->dh_g_len)
664 conn->dh_g = os_malloc(conn->dh_g_len);
665 if (conn->dh_g == NULL)
667 os_memcpy(conn->dh_g, pos, conn->dh_g_len);
668 pos += conn->dh_g_len;
670 conn->dh_g, conn->dh_g_len);
671 if (conn->dh_g_len == 1 && conn->dh_g[0] < 2)
676 conn->dh_ys_len = WPA_GET_BE16(pos);
678 if (conn->dh_ys_len == 0 || end - pos < (int) conn->dh_ys_len)
680 conn->dh_ys = os_malloc(conn->dh_ys_len);
681 if (conn->dh_ys == NULL)
683 os_memcpy(conn->dh_ys, pos, conn->dh_ys_len);
684 pos += conn->dh_ys_len;
686 conn->dh_ys, conn->dh_ys_len);
691 tlsv1_client_free_dh(conn);
696 static int tls_process_server_key_exchange(struct tlsv1_client *conn, u8 ct,
707 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
718 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
731 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
738 return tls_process_certificate_request(conn, ct, in_data,
741 return tls_process_server_hello_done(conn, ct, in_data,
747 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
754 if (!tls_server_key_exchange_allowed(conn)) {
757 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
763 suite = tls_get_cipher_suite(conn->rl.cipher_suite);
765 if (tlsv1_process_diffie_hellman(conn, pos, len) < 0) {
766 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
772 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
779 conn->state = SERVER_CERTIFICATE_REQUEST;
785 static int tls_process_certificate_request(struct tlsv1_client *conn, u8 ct,
795 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
806 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
819 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
826 return tls_process_server_hello_done(conn, ct, in_data,
832 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
839 conn->certificate_requested = 1;
843 conn->state = SERVER_HELLO_DONE;
849 static int tls_process_server_hello_done(struct tlsv1_client *conn, u8 ct,
859 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
870 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
883 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
891 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
900 conn->state = CLIENT_KEY_EXCHANGE;
906 static int tls_process_server_change_cipher_spec(struct tlsv1_client *conn,
916 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
926 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
933 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
939 if (tlsv1_record_change_read_cipher(&conn->rl) < 0) {
942 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
949 conn->state = SERVER_FINISHED;
955 static int tls_process_server_finished(struct tlsv1_client *conn, u8 ct,
966 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
978 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
986 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1000 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1009 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1017 if (conn->verify_md5_server == NULL ||
1018 crypto_hash_finish(conn->verify_md5_server, hash, &hlen) < 0) {
1019 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1021 conn->verify_md5_server = NULL;
1022 crypto_hash_finish(conn->verify_sha1_server, NULL, NULL);
1023 conn->verify_sha1_server = NULL;
1026 conn->verify_md5_server = NULL;
1028 if (conn->verify_sha1_server == NULL ||
1029 crypto_hash_finish(conn->verify_sha1_server, hash + MD5_MAC_LEN,
1031 conn->verify_sha1_server = NULL;
1032 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1036 conn->verify_sha1_server = NULL;
1038 if (tls_prf(conn->master_secret, TLS_MASTER_SECRET_LEN,
1042 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1058 conn->state = (conn->session_resumed || conn->ticket) ?
1075 static int tls_derive_keys(struct tlsv1_client *conn,
1087 os_memcpy(seed, conn->client_random, TLS_RANDOM_LEN);
1088 os_memcpy(seed + TLS_RANDOM_LEN, conn->server_random,
1092 conn->master_secret, TLS_MASTER_SECRET_LEN)) {
1098 conn->master_secret, TLS_MASTER_SECRET_LEN);
1101 os_memcpy(seed, conn->server_random, TLS_RANDOM_LEN);
1102 os_memcpy(seed + TLS_RANDOM_LEN, conn->client_random, TLS_RANDOM_LEN);
1103 key_block_len = 2 * (conn->rl.hash_size + conn->rl.key_material_len +
1104 conn->rl.iv_size);
1105 if (tls_prf(conn->master_secret, TLS_MASTER_SECRET_LEN,
1117 os_memcpy(conn->rl.write_mac_secret, pos, conn->rl.hash_size);
1118 pos += conn->rl.hash_size;
1120 os_memcpy(conn->rl.read_mac_secret, pos, conn->rl.hash_size);
1121 pos += conn->rl.hash_size;
1124 os_memcpy(conn->rl.write_key, pos, conn->rl.key_material_len);
1125 pos += conn->rl.key_material_len;
1127 os_memcpy(conn->rl.read_key, pos, conn->rl.key_material_len);
1128 pos += conn->rl.key_material_len;
1131 os_memcpy(conn->rl.write_iv, pos, conn->rl.iv_size);
1132 pos += conn->rl.iv_size;
1134 os_memcpy(conn->rl.read_iv, pos, conn->rl.iv_size);
1135 pos += conn->rl.iv_size;
1141 static int tls_write_client_certificate(struct tlsv1_client *conn,
1167 cert = conn->client_cert;
1174 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1185 cert = x509_certificate_get_subject(conn->trusted_certs,
1188 if (cert == conn->client_cert || cert == NULL) {
1202 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
1205 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1211 tls_verify_hash_add(conn, hs_start, pos - hs_start);
1219 static int tlsv1_key_x_anon_dh(struct tlsv1_client *conn, u8 **pos, u8 *end)
1226 csecret_len = conn->dh_p_len;
1231 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1238 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1244 if (os_memcmp(csecret, conn->dh_p, csecret_len) > 0)
1256 dh_yc_len = conn->dh_p_len;
1261 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1266 crypto_mod_exp(conn->dh_g, conn->dh_g_len,
1268 conn->dh_p, conn->dh_p_len,
1279 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1289 shared_len = conn->dh_p_len;
1294 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1301 crypto_mod_exp(conn->dh_ys, conn->dh_ys_len,
1303 conn->dh_p, conn->dh_p_len,
1310 if (tls_derive_keys(conn, shared, shared_len)) {
1312 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1319 tlsv1_client_free_dh(conn);
1322 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_INTERNAL_ERROR);
1328 static int tlsv1_key_x_rsa(struct tlsv1_client *conn, u8 **pos, u8 *end)
1335 tls_derive_keys(conn, pre_master_secret,
1338 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1344 if (conn->server_rsa_key == NULL) {
1347 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1356 conn->server_rsa_key,
1362 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1375 static int tls_write_client_key_exchange(struct tlsv1_client *conn,
1383 suite = tls_get_cipher_suite(conn->rl.cipher_suite);
1407 if (tlsv1_key_x_anon_dh(conn, &pos, end) < 0)
1410 if (tlsv1_key_x_rsa(conn, &pos, end) < 0)
1416 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
1419 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1424 tls_verify_hash_add(conn, hs_start, pos - hs_start);
1432 static int tls_write_client_certificate_verify(struct tlsv1_client *conn,
1479 if (conn->verify_md5_cert == NULL ||
1480 crypto_hash_finish(conn->verify_md5_cert, hpos, &hlen) < 0)
1482 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1484 conn->verify_md5_cert = NULL;
1485 crypto_hash_finish(conn->verify_sha1_cert, NULL, NULL);
1486 conn->verify_sha1_cert = NULL;
1491 crypto_hash_finish(conn->verify_md5_cert, NULL, NULL);
1493 conn->verify_md5_cert = NULL;
1495 if (conn->verify_sha1_cert == NULL ||
1496 crypto_hash_finish(conn->verify_sha1_cert, hpos, &hlen) < 0) {
1497 conn->verify_sha1_cert = NULL;
1498 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1502 conn->verify_sha1_cert = NULL;
1523 if (crypto_private_key_sign_pkcs1(conn->client_key, hash, hlen,
1526 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1536 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
1539 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1545 tls_verify_hash_add(conn, hs_start, pos - hs_start);
1553 static int tls_write_client_change_cipher_spec(struct tlsv1_client *conn,
1565 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC,
1568 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1573 if (tlsv1_record_change_write_cipher(&conn->rl) < 0) {
1576 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1587 static int tls_write_client_finished(struct tlsv1_client *conn,
1602 if (conn->verify_md5_client == NULL ||
1603 crypto_hash_finish(conn->verify_md5_client, hash, &hlen) < 0) {
1604 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1606 conn->verify_md5_client = NULL;
1607 crypto_hash_finish(conn->verify_sha1_client, NULL, NULL);
1608 conn->verify_sha1_client = NULL;
1611 conn->verify_md5_client = NULL;
1613 if (conn->verify_sha1_client == NULL ||
1614 crypto_hash_finish(conn->verify_sha1_client, hash + MD5_MAC_LEN,
1616 conn->verify_sha1_client = NULL;
1617 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1621 conn->verify_sha1_client = NULL;
1623 if (tls_prf(conn->master_secret, TLS_MASTER_SECRET_LEN,
1627 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1646 tls_verify_hash_add(conn, hs_start, pos - hs_start);
1648 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
1651 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1664 static size_t tls_client_cert_chain_der_len(struct tlsv1_client *conn)
1669 cert = conn->client_cert;
1674 cert = x509_certificate_get_subject(conn->trusted_certs,
1682 static u8 * tls_send_client_key_exchange(struct tlsv1_client *conn,
1691 if (conn->certificate_requested)
1692 msglen += tls_client_cert_chain_der_len(conn);
1701 if (conn->certificate_requested) {
1702 if (tls_write_client_certificate(conn, &pos, end) < 0) {
1708 if (tls_write_client_key_exchange(conn, &pos, end) < 0 ||
1709 (conn->certificate_requested && conn->client_key &&
1710 tls_write_client_certificate_verify(conn, &pos, end) < 0) ||
1711 tls_write_client_change_cipher_spec(conn, &pos, end) < 0 ||
1712 tls_write_client_finished(conn, &pos, end) < 0) {
1719 conn->state = SERVER_CHANGE_CIPHER_SPEC;
1725 static u8 * tls_send_change_cipher_spec(struct tlsv1_client *conn,
1739 if (tls_write_client_change_cipher_spec(conn, &pos, end) < 0 ||
1740 tls_write_client_finished(conn, &pos, end) < 0) {
1749 conn->state = ESTABLISHED;
1755 static int tlsv1_client_process_handshake(struct tlsv1_client *conn, u8 ct,
1763 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1772 switch (conn->state) {
1774 if (tls_process_server_hello(conn, ct, buf, len))
1778 if (tls_process_certificate(conn, ct, buf, len))
1782 if (tls_process_server_key_exchange(conn, ct, buf, len))
1786 if (tls_process_certificate_request(conn, ct, buf, len))
1790 if (tls_process_server_hello_done(conn, ct, buf, len))
1794 if (tls_process_server_change_cipher_spec(conn, ct, buf, len))
1798 if (tls_process_server_finished(conn, ct, buf, len))
1804 conn->state);
1809 tls_verify_hash_add(conn, buf, *len);
1817 * @conn: TLSv1 client connection data from tlsv1_client_init()
1823 u8 * tlsv1_client_handshake(struct tlsv1_client *conn,
1831 if (conn->state == CLIENT_HELLO) {
1834 return tls_send_client_hello(conn, out_len);
1849 if (tlsv1_record_receive(&conn->rl, pos, end - pos,
1853 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, alert);
1865 if (tlsv1_client_process_handshake(conn, ct, in_pos,
1877 switch (conn->state) {
1879 msg = tls_send_client_key_exchange(conn, out_len);
1882 msg = tls_send_change_cipher_spec(conn, out_len);
1887 conn->state = ESTABLISHED;
1894 "generating reply", conn->state);
1900 if (conn->alert_level) {
1901 conn->state = FAILED;
1903 msg = tls_send_alert(conn, conn->alert_level,
1904 conn->alert_description, out_len);
1913 * @conn: TLSv1 client connection data from tlsv1_client_init()
1923 int tlsv1_client_encrypt(struct tlsv1_client *conn,
1934 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_APPLICATION_DATA,
1937 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1948 * @conn: TLSv1 client connection data from tlsv1_client_init()
1958 int tlsv1_client_decrypt(struct tlsv1_client *conn,
1976 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1982 res = tlsv1_record_receive(&conn->rl, pos, in_end - pos,
1987 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, alert);
1994 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
2031 static void tlsv1_client_free_verify_hashes(struct tlsv1_client *conn)
2033 crypto_hash_finish(conn->verify_md5_client, NULL, NULL);
2034 crypto_hash_finish(conn->verify_md5_server, NULL, NULL);
2035 crypto_hash_finish(conn->verify_md5_cert, NULL, NULL);
2036 crypto_hash_finish(conn->verify_sha1_client, NULL, NULL);
2037 crypto_hash_finish(conn->verify_sha1_server, NULL, NULL);
2038 crypto_hash_finish(conn->verify_sha1_cert, NULL, NULL);
2039 conn->verify_md5_client = NULL;
2040 conn->verify_md5_server = NULL;
2041 conn->verify_md5_cert = NULL;
2042 conn->verify_sha1_client = NULL;
2043 conn->verify_sha1_server = NULL;
2044 conn->verify_sha1_cert = NULL;
2048 static int tlsv1_client_init_verify_hashes(struct tlsv1_client *conn)
2050 conn->verify_md5_client = crypto_hash_init(CRYPTO_HASH_ALG_MD5, NULL,
2052 conn->verify_md5_server = crypto_hash_init(CRYPTO_HASH_ALG_MD5, NULL,
2054 conn->verify_md5_cert = crypto_hash_init(CRYPTO_HASH_ALG_MD5, NULL, 0);
2055 conn->verify_sha1_client = crypto_hash_init(CRYPTO_HASH_ALG_SHA1, NULL,
2057 conn->verify_sha1_server = crypto_hash_init(CRYPTO_HASH_ALG_SHA1, NULL,
2059 conn->verify_sha1_cert = crypto_hash_init(CRYPTO_HASH_ALG_SHA1, NULL,
2061 if (conn->verify_md5_client == NULL ||
2062 conn->verify_md5_server == NULL ||
2063 conn->verify_md5_cert == NULL ||
2064 conn->verify_sha1_client == NULL ||
2065 conn->verify_sha1_server == NULL ||
2066 conn->verify_sha1_cert == NULL) {
2067 tlsv1_client_free_verify_hashes(conn);
2080 struct tlsv1_client *conn;
2084 conn = os_zalloc(sizeof(*conn));
2085 if (conn == NULL)
2088 conn->state = CLIENT_HELLO;
2090 if (tlsv1_client_init_verify_hashes(conn) < 0) {
2093 os_free(conn);
2098 suites = conn->cipher_suites;
2106 conn->num_cipher_suites = count;
2108 return conn;
2114 * @conn: TLSv1 client connection data from tlsv1_client_init()
2116 void tlsv1_client_deinit(struct tlsv1_client *conn)
2118 crypto_public_key_free(conn->server_rsa_key);
2119 tlsv1_record_set_cipher_suite(&conn->rl, TLS_NULL_WITH_NULL_NULL);
2120 tlsv1_record_change_write_cipher(&conn->rl);
2121 tlsv1_record_change_read_cipher(&conn->rl);
2122 tlsv1_client_free_verify_hashes(conn);
2123 os_free(conn->client_hello_ext);
2124 tlsv1_client_free_dh(conn);
2125 x509_certificate_chain_free(conn->trusted_certs);
2126 x509_certificate_chain_free(conn->client_cert);
2127 crypto_private_key_free(conn->client_key);
2128 os_free(conn);
2134 * @conn: TLSv1 client connection data from tlsv1_client_init()
2137 int tlsv1_client_established(struct tlsv1_client *conn)
2139 return conn->state == ESTABLISHED;
2145 * @conn: TLSv1 client connection data from tlsv1_client_init()
2153 int tlsv1_client_prf(struct tlsv1_client *conn, const char *label,
2158 if (conn->state != ESTABLISHED)
2162 os_memcpy(seed, conn->server_random, TLS_RANDOM_LEN);
2163 os_memcpy(seed + TLS_RANDOM_LEN, conn->client_random,
2166 os_memcpy(seed, conn->client_random, TLS_RANDOM_LEN);
2167 os_memcpy(seed + TLS_RANDOM_LEN, conn->server_random,
2171 return tls_prf(conn->master_secret, TLS_MASTER_SECRET_LEN,
2178 * @conn: TLSv1 client connection data from tlsv1_client_init()
2185 int tlsv1_client_get_cipher(struct tlsv1_client *conn, char *buf,
2190 switch (conn->rl.cipher_suite) {
2214 * @conn: TLSv1 client connection data from tlsv1_client_init()
2217 int tlsv1_client_shutdown(struct tlsv1_client *conn)
2219 conn->state = CLIENT_HELLO;
2221 tlsv1_client_free_verify_hashes(conn);
2222 if (tlsv1_client_init_verify_hashes(conn) < 0) {
2228 tlsv1_record_set_cipher_suite(&conn->rl, TLS_NULL_WITH_NULL_NULL);
2229 tlsv1_record_change_write_cipher(&conn->rl);
2230 tlsv1_record_change_read_cipher(&conn->rl);
2232 conn->certificate_requested = 0;
2233 crypto_public_key_free(conn->server_rsa_key);
2234 conn->server_rsa_key = NULL;
2235 conn->session_resumed = 0;
2243 * @conn: TLSv1 client connection data from tlsv1_client_init()
2246 int tlsv1_client_resumed(struct tlsv1_client *conn)
2248 return !!conn->session_resumed;
2254 * @conn: TLSv1 client connection data from tlsv1_client_init()
2260 int tlsv1_client_hello_ext(struct tlsv1_client *conn, int ext_type,
2265 conn->ticket = 0;
2266 os_free(conn->client_hello_ext);
2267 conn->client_hello_ext = NULL;
2268 conn->client_hello_ext_len = 0;
2273 pos = conn->client_hello_ext = os_malloc(6 + data_len);
2284 conn->client_hello_ext_len = 6 + data_len;
2287 conn->ticket = 1;
2297 * @conn: TLSv1 client connection data from tlsv1_client_init()
2301 int tlsv1_client_get_keys(struct tlsv1_client *conn, struct tls_keys *keys)
2304 if (conn->state == CLIENT_HELLO)
2307 keys->client_random = conn->client_random;
2310 if (conn->state != SERVER_HELLO) {
2311 keys->server_random = conn->server_random;
2313 keys->master_key = conn->master_secret;
2323 * @conn: TLSv1 client connection data from tlsv1_client_init()
2328 int tlsv1_client_set_master_key(struct tlsv1_client *conn,
2335 os_memcpy(conn->master_secret, key, key_len);
2336 conn->ticket_key = 1;
2344 * @conn: TLSv1 client connection data from tlsv1_client_init()
2348 int tlsv1_client_get_keyblock_size(struct tlsv1_client *conn)
2350 if (conn->state == CLIENT_HELLO || conn->state == SERVER_HELLO)
2353 return 2 * (conn->rl.hash_size + conn->rl.key_material_len +
2354 conn->rl.iv_size);
2360 * @conn: TLSv1 client connection data from tlsv1_client_init()
2365 int tlsv1_client_set_cipher_list(struct tlsv1_client *conn, u8 *ciphers)
2374 suites = conn->cipher_suites;
2380 conn->num_cipher_suites = count;
2514 * @conn: TLSv1 client connection data from tlsv1_client_init()
2521 int tlsv1_client_set_ca_cert(struct tlsv1_client *conn, const char *cert,
2525 if (tlsv1_client_set_cert_chain(&conn->trusted_certs, cert,
2542 * @conn: TLSv1 client connection data from tlsv1_client_init()
2548 int tlsv1_client_set_client_cert(struct tlsv1_client *conn, const char *cert,
2551 return tlsv1_client_set_cert_chain(&conn->client_cert, cert,
2556 static int tlsv1_client_set_key(struct tlsv1_client *conn,
2559 conn->client_key = crypto_private_key_import(key, len);
2560 if (conn->client_key == NULL) {
2570 * @conn: TLSv1 client connection data from tlsv1_client_init()
2578 int tlsv1_client_set_private_key(struct tlsv1_client *conn,
2584 crypto_private_key_free(conn->client_key);
2585 conn->client_key = NULL;
2588 return tlsv1_client_set_key(conn, private_key_blob,
2603 ret = tlsv1_client_set_key(conn, buf, len);