Lines Matching +full:layer +full:- +full:depth
2 * TLSv1 client - read handshake message
3 * Copyright (c) 2006-2015, Jouni Malinen <j@w1.fi>
32 return (((conn->flags & TLS_CONN_DISABLE_TLSv1_0) && in tls_version_disabled()
34 ((conn->flags & TLS_CONN_DISABLE_TLSv1_1) && in tls_version_disabled()
36 ((conn->flags & TLS_CONN_DISABLE_TLSv1_2) && in tls_version_disabled()
51 if (end - pos < 4) { in tls_process_server_hello_extensions()
53 return -1; in tls_process_server_hello_extensions()
61 if (elen > end - pos) { in tls_process_server_hello_extensions()
63 return -1; in tls_process_server_hello_extensions()
91 return -1; in tls_process_server_hello()
106 return -1; in tls_process_server_hello()
113 left -= 4; in tls_process_server_hello()
118 /* body - ServerHello */ in tls_process_server_hello()
124 if (end - pos < 2) in tls_process_server_hello()
133 return -1; in tls_process_server_hello()
139 conn->rl.tls_version = tls_version; in tls_process_server_hello()
142 if (end - pos < TLS_RANDOM_LEN) in tls_process_server_hello()
145 os_memcpy(conn->server_random, pos, TLS_RANDOM_LEN); in tls_process_server_hello()
148 conn->server_random, TLS_RANDOM_LEN); in tls_process_server_hello()
151 if (end - pos < 1) in tls_process_server_hello()
153 if (end - pos < 1 + *pos || *pos > TLS_SESSION_ID_MAX_LEN) in tls_process_server_hello()
155 if (conn->session_id_len && conn->session_id_len == *pos && in tls_process_server_hello()
156 os_memcmp(conn->session_id, pos + 1, conn->session_id_len) == 0) { in tls_process_server_hello()
157 pos += 1 + conn->session_id_len; in tls_process_server_hello()
159 conn->session_resumed = 1; in tls_process_server_hello()
161 conn->session_id_len = *pos; in tls_process_server_hello()
163 os_memcpy(conn->session_id, pos, conn->session_id_len); in tls_process_server_hello()
164 pos += conn->session_id_len; in tls_process_server_hello()
167 conn->session_id, conn->session_id_len); in tls_process_server_hello()
170 if (end - pos < 2) in tls_process_server_hello()
174 for (i = 0; i < conn->num_cipher_suites; i++) { in tls_process_server_hello()
175 if (cipher_suite == conn->cipher_suites[i]) in tls_process_server_hello()
178 if (i == conn->num_cipher_suites) { in tls_process_server_hello()
183 return -1; in tls_process_server_hello()
186 if (conn->session_resumed && cipher_suite != conn->prev_cipher_suite) { in tls_process_server_hello()
189 "0x%04x)", cipher_suite, conn->prev_cipher_suite); in tls_process_server_hello()
192 return -1; in tls_process_server_hello()
195 if (tlsv1_record_set_cipher_suite(&conn->rl, cipher_suite) < 0) { in tls_process_server_hello()
197 "record layer"); in tls_process_server_hello()
200 return -1; in tls_process_server_hello()
203 conn->prev_cipher_suite = cipher_suite; in tls_process_server_hello()
206 if (end - pos < 1) in tls_process_server_hello()
213 return -1; in tls_process_server_hello()
217 if (end - pos >= 2) { in tls_process_server_hello()
222 if (end - pos < ext_len) { in tls_process_server_hello()
225 ext_len, (unsigned int) (end - pos)); in tls_process_server_hello()
236 "end of ServerHello", pos, end - pos); in tls_process_server_hello()
240 if (conn->session_ticket_included && conn->session_ticket_cb) { in tls_process_server_hello()
243 int res = conn->session_ticket_cb( in tls_process_server_hello()
244 conn->session_ticket_cb_ctx, NULL, 0, in tls_process_server_hello()
245 conn->client_random, conn->server_random, in tls_process_server_hello()
246 conn->master_secret); in tls_process_server_hello()
252 return -1; in tls_process_server_hello()
254 conn->use_session_ticket = !!res; in tls_process_server_hello()
257 if ((conn->session_resumed || conn->use_session_ticket) && in tls_process_server_hello()
262 return -1; in tls_process_server_hello()
265 *in_len = end - in_data; in tls_process_server_hello()
267 conn->state = (conn->session_resumed || conn->use_session_ticket) ? in tls_process_server_hello()
275 return -1; in tls_process_server_hello()
279 static void tls_peer_cert_event(struct tlsv1_client *conn, int depth, in tls_peer_cert_event() argument
289 if (!conn->event_cb) in tls_peer_cert_event()
293 if ((conn->cred && conn->cred->cert_probe) || conn->cert_in_cb) { in tls_peer_cert_event()
294 cert_buf = wpabuf_alloc_copy(cert->cert_start, in tls_peer_cert_event()
295 cert->cert_len); in tls_peer_cert_event()
311 ev.peer_cert.depth = depth; in tls_peer_cert_event()
312 x509_name_string(&cert->subject, subject, sizeof(subject)); in tls_peer_cert_event()
315 if (cert->extensions_present & X509_EXT_CERTIFICATE_POLICY) { in tls_peer_cert_event()
316 if (cert->certificate_policy & X509_EXT_CERT_POLICY_TOD_STRICT) in tls_peer_cert_event()
318 else if (cert->certificate_policy & in tls_peer_cert_event()
323 conn->event_cb(conn->cb_ctx, TLS_PEER_CERTIFICATE, &ev); in tls_peer_cert_event()
328 static void tls_cert_chain_failure_event(struct tlsv1_client *conn, int depth, in tls_cert_chain_failure_event() argument
337 if (!conn->event_cb || !cert) in tls_cert_chain_failure_event()
341 ev.cert_fail.depth = depth; in tls_cert_chain_failure_event()
342 x509_name_string(&cert->subject, subject, sizeof(subject)); in tls_cert_chain_failure_event()
346 cert_buf = wpabuf_alloc_copy(cert->cert_start, in tls_cert_chain_failure_event()
347 cert->cert_len); in tls_cert_chain_failure_event()
349 conn->event_cb(conn->cb_ctx, TLS_CERT_CHAIN_FAILURE, &ev); in tls_cert_chain_failure_event()
368 return -1; in tls_process_certificate()
378 return -1; in tls_process_certificate()
384 left -= 4; in tls_process_certificate()
391 return -1; in tls_process_certificate()
410 return -1; in tls_process_certificate()
418 * opaque ASN.1Cert<2^24-1>; in tls_process_certificate()
421 * ASN.1Cert certificate_list<1..2^24-1>; in tls_process_certificate()
427 if (end - pos < 3) { in tls_process_certificate()
431 return -1; in tls_process_certificate()
437 if ((size_t) (end - pos) != list_len) { in tls_process_certificate()
441 (unsigned long) (end - pos)); in tls_process_certificate()
443 return -1; in tls_process_certificate()
448 if (end - pos < 3) { in tls_process_certificate()
454 return -1; in tls_process_certificate()
460 if ((size_t) (end - pos) < cert_len) { in tls_process_certificate()
464 (unsigned long) (end - pos)); in tls_process_certificate()
468 return -1; in tls_process_certificate()
475 crypto_public_key_free(conn->server_rsa_key); in tls_process_certificate()
477 &conn->server_rsa_key)) { in tls_process_certificate()
483 return -1; in tls_process_certificate()
494 return -1; in tls_process_certificate()
502 last->next = cert; in tls_process_certificate()
509 if (conn->cred && conn->cred->server_cert_only && chain) { in tls_process_certificate()
515 x509_name_string(&chain->subject, buf, sizeof(buf)); in tls_process_certificate()
517 if (sha256_vector(1, &chain->cert_start, &chain->cert_len, in tls_process_certificate()
519 os_memcmp(conn->cred->srv_cert_hash, hash, in tls_process_certificate()
525 if (conn->event_cb) { in tls_process_certificate()
533 conn->event_cb(conn->cb_ctx, in tls_process_certificate()
539 return -1; in tls_process_certificate()
541 } else if (conn->cred && conn->cred->cert_probe) { in tls_process_certificate()
543 "TLSv1: Reject server certificate on probe-only run"); in tls_process_certificate()
544 if (conn->event_cb) { in tls_process_certificate()
553 x509_name_string(&chain->subject, buf, in tls_process_certificate()
557 conn->event_cb(conn->cb_ctx, TLS_CERT_CHAIN_FAILURE, in tls_process_certificate()
563 return -1; in tls_process_certificate()
564 } else if (conn->cred && conn->cred->ca_cert_verify && in tls_process_certificate()
566 conn->cred->trusted_certs, chain, &reason, in tls_process_certificate()
567 !!(conn->flags & TLS_CONN_DISABLE_TIME_CHECKS)) in tls_process_certificate()
609 return -1; in tls_process_certificate()
612 if (conn->cred && !conn->cred->server_cert_only && chain && in tls_process_certificate()
613 (chain->extensions_present & X509_EXT_EXT_KEY_USAGE) && in tls_process_certificate()
614 !(chain->ext_key_usage & in tls_process_certificate()
622 return -1; in tls_process_certificate()
625 if (conn->flags & TLS_CONN_REQUEST_OCSP) { in tls_process_certificate()
626 x509_certificate_chain_free(conn->server_cert); in tls_process_certificate()
627 conn->server_cert = chain; in tls_process_certificate()
632 *in_len = end - in_data; in tls_process_certificate()
634 conn->state = SERVER_KEY_EXCHANGE; in tls_process_certificate()
653 bits = (len - i - 1) * 8; in count_bits()
678 if (end - pos < 3) in tlsv1_process_diffie_hellman()
683 if (val == 0 || val > (size_t) (end - pos)) { in tlsv1_process_diffie_hellman()
687 conn->dh_p_len = val; in tlsv1_process_diffie_hellman()
688 bits = count_bits(pos, conn->dh_p_len); in tlsv1_process_diffie_hellman()
690 wpa_printf(MSG_INFO, "TLSv1: Reject under 768-bit DH prime (insecure; only %u bits)", in tlsv1_process_diffie_hellman()
693 pos, conn->dh_p_len); in tlsv1_process_diffie_hellman()
696 conn->dh_p = os_memdup(pos, conn->dh_p_len); in tlsv1_process_diffie_hellman()
697 if (conn->dh_p == NULL) in tlsv1_process_diffie_hellman()
699 pos += conn->dh_p_len; in tlsv1_process_diffie_hellman()
701 conn->dh_p, conn->dh_p_len); in tlsv1_process_diffie_hellman()
703 if (end - pos < 3) in tlsv1_process_diffie_hellman()
707 if (val == 0 || val > (size_t) (end - pos)) in tlsv1_process_diffie_hellman()
709 conn->dh_g_len = val; in tlsv1_process_diffie_hellman()
710 conn->dh_g = os_memdup(pos, conn->dh_g_len); in tlsv1_process_diffie_hellman()
711 if (conn->dh_g == NULL) in tlsv1_process_diffie_hellman()
713 pos += conn->dh_g_len; in tlsv1_process_diffie_hellman()
715 conn->dh_g, conn->dh_g_len); in tlsv1_process_diffie_hellman()
716 if (conn->dh_g_len == 1 && conn->dh_g[0] < 2) in tlsv1_process_diffie_hellman()
719 if (end - pos < 3) in tlsv1_process_diffie_hellman()
723 if (val == 0 || val > (size_t) (end - pos)) in tlsv1_process_diffie_hellman()
725 conn->dh_ys_len = val; in tlsv1_process_diffie_hellman()
726 conn->dh_ys = os_memdup(pos, conn->dh_ys_len); in tlsv1_process_diffie_hellman()
727 if (conn->dh_ys == NULL) in tlsv1_process_diffie_hellman()
729 pos += conn->dh_ys_len; in tlsv1_process_diffie_hellman()
731 conn->dh_ys, conn->dh_ys_len); in tlsv1_process_diffie_hellman()
738 if (conn->rl.tls_version == TLS_VERSION_1_2) { in tlsv1_process_diffie_hellman()
750 if (end - pos < 2) in tlsv1_process_diffie_hellman()
762 conn->rl.tls_version, pos[0], in tlsv1_process_diffie_hellman()
763 conn->client_random, in tlsv1_process_diffie_hellman()
764 conn->server_random, server_params, in tlsv1_process_diffie_hellman()
765 server_params_end - server_params, hash); in tlsv1_process_diffie_hellman()
772 conn->rl.tls_version, conn->client_random, in tlsv1_process_diffie_hellman()
773 conn->server_random, server_params, in tlsv1_process_diffie_hellman()
774 server_params_end - server_params, hash, in tlsv1_process_diffie_hellman()
783 if (tls_verify_signature(conn->rl.tls_version, in tlsv1_process_diffie_hellman()
784 conn->server_rsa_key, in tlsv1_process_diffie_hellman()
785 hash, hlen, pos, end - pos, in tlsv1_process_diffie_hellman()
795 return -1; in tlsv1_process_diffie_hellman()
806 /* opaque OCSPResponse<1..2^24-1>; */ in tls_process_certificate_status_ocsp_response()
807 if (end - pos < 3) { in tls_process_certificate_status_ocsp_response()
814 if (end - pos < ocsp_resp_len) { in tls_process_certificate_status_ocsp_response()
832 int depth; in tls_process_certificate_status() local
840 return -1; in tls_process_certificate_status()
851 return -1; in tls_process_certificate_status()
857 left -= 4; in tls_process_certificate_status()
864 return -1; in tls_process_certificate_status()
875 return -1; in tls_process_certificate_status()
889 if (end - pos < 1) { in tls_process_certificate_status()
892 return -1; in tls_process_certificate_status()
900 conn, pos, end - pos); in tls_process_certificate_status()
908 * opaque OCSPResponse<0..2^24-1>; in tls_process_certificate_status()
911 * OCSPResponse ocsp_response_list<1..2^24-1>; in tls_process_certificate_status()
914 if (end - pos < 3) { in tls_process_certificate_status()
922 if (end - pos < resp_len) { in tls_process_certificate_status()
931 while (end - pos >= 3) { in tls_process_certificate_status()
934 if (resp_len > end - pos) { in tls_process_certificate_status()
937 resp_len, (int) (end - pos)); in tls_process_certificate_status()
944 conn, pos - 3, resp_len + 3); in tls_process_certificate_status()
966 for (cert = conn->server_cert, depth = 0; cert; in tls_process_certificate_status()
967 cert = cert->next, depth++) { in tls_process_certificate_status()
968 if (cert->ocsp_revoked) { in tls_process_certificate_status()
970 conn, depth, cert, TLS_FAIL_REVOKED, in tls_process_certificate_status()
974 return -1; in tls_process_certificate_status()
977 if (conn->flags & TLS_CONN_REQUIRE_OCSP_ALL) { in tls_process_certificate_status()
983 for (cert = conn->server_cert, depth = 0; cert; in tls_process_certificate_status()
984 cert = cert->next, depth++) { in tls_process_certificate_status()
985 if (!cert->ocsp_good) { in tls_process_certificate_status()
989 conn, depth, cert, in tls_process_certificate_status()
992 return -1; in tls_process_certificate_status()
994 if (cert->issuer_trusted) in tls_process_certificate_status()
999 if ((conn->flags & TLS_CONN_REQUIRE_OCSP) && res != TLS_OCSP_GOOD) { in tls_process_certificate_status()
1003 if (conn->server_cert) in tls_process_certificate_status()
1005 conn, 0, conn->server_cert, in tls_process_certificate_status()
1008 return -1; in tls_process_certificate_status()
1011 conn->ocsp_resp_received = 1; in tls_process_certificate_status()
1014 *in_len = end - in_data; in tls_process_certificate_status()
1016 conn->state = SERVER_KEY_EXCHANGE; in tls_process_certificate_status()
1035 return -1; in tls_process_server_key_exchange()
1045 return -1; in tls_process_server_key_exchange()
1051 left -= 4; in tls_process_server_key_exchange()
1058 return -1; in tls_process_server_key_exchange()
1063 if ((conn->flags & TLS_CONN_REQUEST_OCSP) && in tls_process_server_key_exchange()
1077 (conn->flags & TLS_CONN_REQUEST_OCSP) ? in tls_process_server_key_exchange()
1081 return -1; in tls_process_server_key_exchange()
1086 if (!tls_server_key_exchange_allowed(conn->rl.cipher_suite)) { in tls_process_server_key_exchange()
1091 return -1; in tls_process_server_key_exchange()
1095 suite = tls_get_cipher_suite(conn->rl.cipher_suite); in tls_process_server_key_exchange()
1096 if (suite && (suite->key_exchange == TLS_KEY_X_DH_anon || in tls_process_server_key_exchange()
1097 suite->key_exchange == TLS_KEY_X_DHE_RSA)) { in tls_process_server_key_exchange()
1099 suite->key_exchange) < 0) { in tls_process_server_key_exchange()
1102 return -1; in tls_process_server_key_exchange()
1108 return -1; in tls_process_server_key_exchange()
1111 *in_len = end - in_data; in tls_process_server_key_exchange()
1113 conn->state = SERVER_CERTIFICATE_REQUEST; in tls_process_server_key_exchange()
1131 return -1; in tls_process_certificate_request()
1141 return -1; in tls_process_certificate_request()
1147 left -= 4; in tls_process_certificate_request()
1154 return -1; in tls_process_certificate_request()
1168 return -1; in tls_process_certificate_request()
1173 conn->certificate_requested = 1; in tls_process_certificate_request()
1175 *in_len = end - in_data; in tls_process_certificate_request()
1177 conn->state = SERVER_HELLO_DONE; in tls_process_certificate_request()
1195 return -1; in tls_process_server_hello_done()
1205 return -1; in tls_process_server_hello_done()
1211 left -= 4; in tls_process_server_hello_done()
1218 return -1; in tls_process_server_hello_done()
1227 return -1; in tls_process_server_hello_done()
1232 if ((conn->flags & TLS_CONN_REQUIRE_OCSP) && in tls_process_server_hello_done()
1233 !conn->ocsp_resp_received) { in tls_process_server_hello_done()
1235 "TLSv1: No OCSP response received - reject handshake"); in tls_process_server_hello_done()
1238 return -1; in tls_process_server_hello_done()
1241 *in_len = end - in_data; in tls_process_server_hello_done()
1243 conn->state = CLIENT_KEY_EXCHANGE; in tls_process_server_hello_done()
1259 if (conn->use_session_ticket) { in tls_process_server_change_cipher_spec()
1263 conn->use_session_ticket = 0; in tls_process_server_change_cipher_spec()
1266 res = conn->session_ticket_cb( in tls_process_server_change_cipher_spec()
1267 conn->session_ticket_cb_ctx, NULL, 0, NULL, in tls_process_server_change_cipher_spec()
1274 return -1; in tls_process_server_change_cipher_spec()
1277 conn->state = SERVER_CERTIFICATE; in tls_process_server_change_cipher_spec()
1283 return -1; in tls_process_server_change_cipher_spec()
1292 return -1; in tls_process_server_change_cipher_spec()
1300 return -1; in tls_process_server_change_cipher_spec()
1304 if (tlsv1_record_change_read_cipher(&conn->rl) < 0) { in tls_process_server_change_cipher_spec()
1306 "for record layer"); in tls_process_server_change_cipher_spec()
1309 return -1; in tls_process_server_change_cipher_spec()
1312 *in_len = pos + 1 - in_data; in tls_process_server_change_cipher_spec()
1314 conn->state = SERVER_FINISHED; in tls_process_server_change_cipher_spec()
1333 return -1; in tls_process_server_finished()
1345 return -1; in tls_process_server_finished()
1353 return -1; in tls_process_server_finished()
1359 left -= 4; in tls_process_server_finished()
1367 return -1; in tls_process_server_finished()
1376 return -1; in tls_process_server_finished()
1382 if (conn->rl.tls_version >= TLS_VERSION_1_2) { in tls_process_server_finished()
1384 if (conn->verify.sha256_server == NULL || in tls_process_server_finished()
1385 crypto_hash_finish(conn->verify.sha256_server, hash, &hlen) in tls_process_server_finished()
1389 conn->verify.sha256_server = NULL; in tls_process_server_finished()
1390 return -1; in tls_process_server_finished()
1392 conn->verify.sha256_server = NULL; in tls_process_server_finished()
1397 if (conn->verify.md5_server == NULL || in tls_process_server_finished()
1398 crypto_hash_finish(conn->verify.md5_server, hash, &hlen) < 0) { in tls_process_server_finished()
1401 conn->verify.md5_server = NULL; in tls_process_server_finished()
1402 crypto_hash_finish(conn->verify.sha1_server, NULL, NULL); in tls_process_server_finished()
1403 conn->verify.sha1_server = NULL; in tls_process_server_finished()
1404 return -1; in tls_process_server_finished()
1406 conn->verify.md5_server = NULL; in tls_process_server_finished()
1408 if (conn->verify.sha1_server == NULL || in tls_process_server_finished()
1409 crypto_hash_finish(conn->verify.sha1_server, hash + MD5_MAC_LEN, in tls_process_server_finished()
1411 conn->verify.sha1_server = NULL; in tls_process_server_finished()
1414 return -1; in tls_process_server_finished()
1416 conn->verify.sha1_server = NULL; in tls_process_server_finished()
1423 if (tls_prf(conn->rl.tls_version, in tls_process_server_finished()
1424 conn->master_secret, TLS_MASTER_SECRET_LEN, in tls_process_server_finished()
1430 return -1; in tls_process_server_finished()
1439 return -1; in tls_process_server_finished()
1444 *in_len = end - in_data; in tls_process_server_finished()
1446 conn->state = (conn->session_resumed || conn->use_session_ticket) ? in tls_process_server_finished()
1465 return -1; in tls_process_application_data()
1493 return -1; in tlsv1_client_process_handshake()
1498 conn->state = FAILED; in tlsv1_client_process_handshake()
1499 return -1; in tlsv1_client_process_handshake()
1505 if (hr_len > *len - 4) { in tlsv1_client_process_handshake()
1509 return -1; in tlsv1_client_process_handshake()
1516 switch (conn->state) { in tlsv1_client_process_handshake()
1519 return -1; in tlsv1_client_process_handshake()
1523 return -1; in tlsv1_client_process_handshake()
1527 return -1; in tlsv1_client_process_handshake()
1531 return -1; in tlsv1_client_process_handshake()
1535 return -1; in tlsv1_client_process_handshake()
1539 return -1; in tlsv1_client_process_handshake()
1543 return -1; in tlsv1_client_process_handshake()
1549 return -1; in tlsv1_client_process_handshake()
1554 conn->state); in tlsv1_client_process_handshake()
1555 return -1; in tlsv1_client_process_handshake()
1559 tls_verify_hash_add(&conn->verify, buf, *len); in tlsv1_client_process_handshake()