Lines Matching defs:conn
22 static int tls_process_server_key_exchange(struct tlsv1_client *conn, u8 ct,
24 static int tls_process_certificate_request(struct tlsv1_client *conn, u8 ct,
26 static int tls_process_server_hello_done(struct tlsv1_client *conn, u8 ct,
30 static int tls_version_disabled(struct tlsv1_client *conn, u16 ver)
32 return (((conn->flags & TLS_CONN_DISABLE_TLSv1_0) &&
34 ((conn->flags & TLS_CONN_DISABLE_TLSv1_1) &&
36 ((conn->flags & TLS_CONN_DISABLE_TLSv1_2) &&
41 static int tls_process_server_hello_extensions(struct tlsv1_client *conn,
78 static int tls_process_server_hello(struct tlsv1_client *conn, u8 ct,
89 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
104 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
128 tls_version_disabled(conn, tls_version)) {
131 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
139 conn->rl.tls_version = tls_version;
145 os_memcpy(conn->server_random, pos, TLS_RANDOM_LEN);
148 conn->server_random, TLS_RANDOM_LEN);
155 if (conn->session_id_len && conn->session_id_len == *pos &&
156 os_memcmp(conn->session_id, pos + 1, conn->session_id_len) == 0) {
157 pos += 1 + conn->session_id_len;
159 conn->session_resumed = 1;
161 conn->session_id_len = *pos;
163 os_memcpy(conn->session_id, pos, conn->session_id_len);
164 pos += conn->session_id_len;
167 conn->session_id, conn->session_id_len);
174 for (i = 0; i < conn->num_cipher_suites; i++) {
175 if (cipher_suite == conn->cipher_suites[i])
178 if (i == conn->num_cipher_suites) {
181 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
186 if (conn->session_resumed && cipher_suite != conn->prev_cipher_suite) {
189 "0x%04x)", cipher_suite, conn->prev_cipher_suite);
190 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
195 if (tlsv1_record_set_cipher_suite(&conn->rl, cipher_suite) < 0) {
198 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
203 conn->prev_cipher_suite = cipher_suite;
211 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
229 if (tls_process_server_hello_extensions(conn, pos, ext_len))
240 if (conn->session_ticket_included && conn->session_ticket_cb) {
243 int res = conn->session_ticket_cb(
244 conn->session_ticket_cb_ctx, NULL, 0,
245 conn->client_random, conn->server_random,
246 conn->master_secret);
250 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
254 conn->use_session_ticket = !!res;
257 if ((conn->session_resumed || conn->use_session_ticket) &&
258 tls_derive_keys(conn, NULL, 0)) {
260 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
267 conn->state = (conn->session_resumed || conn->use_session_ticket) ?
274 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
279 static void tls_peer_cert_event(struct tlsv1_client *conn, int depth,
289 if (!conn->event_cb)
293 if ((conn->cred && conn->cred->cert_probe) || conn->cert_in_cb) {
323 conn->event_cb(conn->cb_ctx, TLS_PEER_CERTIFICATE, &ev);
328 static void tls_cert_chain_failure_event(struct tlsv1_client *conn, int depth,
337 if (!conn->event_cb || !cert)
349 conn->event_cb(conn->cb_ctx, TLS_CERT_CHAIN_FAILURE, &ev);
354 static int tls_process_certificate(struct tlsv1_client *conn, u8 ct,
366 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
377 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
390 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
395 return tls_process_server_key_exchange(conn, ct, in_data,
398 return tls_process_certificate_request(conn, ct, in_data,
401 return tls_process_server_hello_done(conn, ct, in_data,
408 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
430 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
442 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
451 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
465 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
475 crypto_public_key_free(conn->server_rsa_key);
477 &conn->server_rsa_key)) {
480 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
491 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
497 tls_peer_cert_event(conn, idx, cert);
509 if (conn->cred && conn->cred->server_cert_only && chain) {
519 os_memcmp(conn->cred->srv_cert_hash, hash,
525 if (conn->event_cb) {
533 conn->event_cb(conn->cb_ctx,
536 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
541 } else if (conn->cred && conn->cred->cert_probe) {
544 if (conn->event_cb) {
557 conn->event_cb(conn->cb_ctx, TLS_CERT_CHAIN_FAILURE,
560 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
564 } else if (conn->cred && conn->cred->ca_cert_verify &&
566 conn->cred->trusted_certs, chain, &reason,
567 !!(conn->flags & TLS_CONN_DISABLE_TIME_CHECKS))
576 conn, 0, chain, TLS_FAIL_BAD_CERTIFICATE,
585 conn, 0, chain, TLS_FAIL_REVOKED,
591 conn, 0, chain, TLS_FAIL_EXPIRED,
600 conn, 0, chain, TLS_FAIL_UNTRUSTED,
607 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, tls_reason);
612 if (conn->cred && !conn->cred->server_cert_only && chain &&
617 conn, 0, chain, TLS_FAIL_BAD_CERTIFICATE,
619 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
625 if (conn->flags & TLS_CONN_REQUEST_OCSP) {
626 x509_certificate_chain_free(conn->server_cert);
627 conn->server_cert = chain;
634 conn->state = SERVER_KEY_EXCHANGE;
664 static int tlsv1_process_diffie_hellman(struct tlsv1_client *conn,
673 tlsv1_client_free_dh(conn);
687 conn->dh_p_len = val;
688 bits = count_bits(pos, conn->dh_p_len);
693 pos, conn->dh_p_len);
696 conn->dh_p = os_memdup(pos, conn->dh_p_len);
697 if (conn->dh_p == NULL)
699 pos += conn->dh_p_len;
701 conn->dh_p, conn->dh_p_len);
709 conn->dh_g_len = val;
710 conn->dh_g = os_memdup(pos, conn->dh_g_len);
711 if (conn->dh_g == NULL)
713 pos += conn->dh_g_len;
715 conn->dh_g, conn->dh_g_len);
716 if (conn->dh_g_len == 1 && conn->dh_g[0] < 2)
725 conn->dh_ys_len = val;
726 conn->dh_ys = os_memdup(pos, conn->dh_ys_len);
727 if (conn->dh_ys == NULL)
729 pos += conn->dh_ys_len;
731 conn->dh_ys, conn->dh_ys_len);
738 if (conn->rl.tls_version == TLS_VERSION_1_2) {
762 conn->rl.tls_version, pos[0],
763 conn->client_random,
764 conn->server_random, server_params,
772 conn->rl.tls_version, conn->client_random,
773 conn->server_random, server_params,
783 if (tls_verify_signature(conn->rl.tls_version,
784 conn->server_rsa_key,
794 tlsv1_client_free_dh(conn);
800 tls_process_certificate_status_ocsp_response(struct tlsv1_client *conn,
809 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
816 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
820 return tls_process_ocsp_response(conn, pos, ocsp_resp_len);
824 static int tls_process_certificate_status(struct tlsv1_client *conn, u8 ct,
838 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
850 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
863 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
873 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
891 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
900 conn, pos, end - pos);
944 conn, pos - 3, resp_len + 3);
964 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
966 for (cert = conn->server_cert, depth = 0; cert;
970 conn, depth, cert, TLS_FAIL_REVOKED,
977 if (conn->flags & TLS_CONN_REQUIRE_OCSP_ALL) {
983 for (cert = conn->server_cert, depth = 0; cert;
986 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
989 conn, depth, cert,
999 if ((conn->flags & TLS_CONN_REQUIRE_OCSP) && res != TLS_OCSP_GOOD) {
1000 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1003 if (conn->server_cert)
1005 conn, 0, conn->server_cert,
1011 conn->ocsp_resp_received = 1;
1016 conn->state = SERVER_KEY_EXCHANGE;
1022 static int tls_process_server_key_exchange(struct tlsv1_client *conn, u8 ct,
1033 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1044 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1057 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1063 if ((conn->flags & TLS_CONN_REQUEST_OCSP) &&
1065 return tls_process_certificate_status(conn, ct, in_data,
1068 return tls_process_certificate_request(conn, ct, in_data,
1071 return tls_process_server_hello_done(conn, ct, in_data,
1077 (conn->flags & TLS_CONN_REQUEST_OCSP) ?
1079 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1086 if (!tls_server_key_exchange_allowed(conn->rl.cipher_suite)) {
1089 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1095 suite = tls_get_cipher_suite(conn->rl.cipher_suite);
1098 if (tlsv1_process_diffie_hellman(conn, pos, len,
1100 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1106 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1113 conn->state = SERVER_CERTIFICATE_REQUEST;
1119 static int tls_process_certificate_request(struct tlsv1_client *conn, u8 ct,
1129 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1140 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1153 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1160 return tls_process_server_hello_done(conn, ct, in_data,
1166 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1173 conn->certificate_requested = 1;
1177 conn->state = SERVER_HELLO_DONE;
1183 static int tls_process_server_hello_done(struct tlsv1_client *conn, u8 ct,
1193 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1204 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1217 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1225 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1232 if ((conn->flags & TLS_CONN_REQUIRE_OCSP) &&
1233 !conn->ocsp_resp_received) {
1236 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1243 conn->state = CLIENT_KEY_EXCHANGE;
1249 static int tls_process_server_change_cipher_spec(struct tlsv1_client *conn,
1259 if (conn->use_session_ticket) {
1263 conn->use_session_ticket = 0;
1266 res = conn->session_ticket_cb(
1267 conn->session_ticket_cb_ctx, NULL, 0, NULL,
1272 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1277 conn->state = SERVER_CERTIFICATE;
1278 return tls_process_certificate(conn, ct, in_data,
1281 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1291 tls_alert(conn, TLS_ALERT_LEVEL_FATAL, TLS_ALERT_DECODE_ERROR);
1298 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1304 if (tlsv1_record_change_read_cipher(&conn->rl) < 0) {
1307 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1314 conn->state = SERVER_FINISHED;
1320 static int tls_process_server_finished(struct tlsv1_client *conn, u8 ct,
1331 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1343 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1351 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1365 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1374 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1382 if (conn->rl.tls_version >= TLS_VERSION_1_2) {
1384 if (conn->verify.sha256_server == NULL ||
1385 crypto_hash_finish(conn->verify.sha256_server, hash, &hlen)
1387 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1389 conn->verify.sha256_server = NULL;
1392 conn->verify.sha256_server = NULL;
1397 if (conn->verify.md5_server == NULL ||
1398 crypto_hash_finish(conn->verify.md5_server, hash, &hlen) < 0) {
1399 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1401 conn->verify.md5_server = NULL;
1402 crypto_hash_finish(conn->verify.sha1_server, NULL, NULL);
1403 conn->verify.sha1_server = NULL;
1406 conn->verify.md5_server = NULL;
1408 if (conn->verify.sha1_server == NULL ||
1409 crypto_hash_finish(conn->verify.sha1_server, hash + MD5_MAC_LEN,
1411 conn->verify.sha1_server = NULL;
1412 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1416 conn->verify.sha1_server = NULL;
1423 if (tls_prf(conn->rl.tls_version,
1424 conn->master_secret, TLS_MASTER_SECRET_LEN,
1428 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1437 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1446 conn->state = (conn->session_resumed || conn->use_session_ticket) ?
1453 static int tls_process_application_data(struct tlsv1_client *conn, u8 ct,
1463 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1484 int tlsv1_client_process_handshake(struct tlsv1_client *conn, u8 ct,
1491 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1498 conn->state = FAILED;
1507 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
1516 switch (conn->state) {
1518 if (tls_process_server_hello(conn, ct, buf, len))
1522 if (tls_process_certificate(conn, ct, buf, len))
1526 if (tls_process_server_key_exchange(conn, ct, buf, len))
1530 if (tls_process_certificate_request(conn, ct, buf, len))
1534 if (tls_process_server_hello_done(conn, ct, buf, len))
1538 if (tls_process_server_change_cipher_spec(conn, ct, buf, len))
1542 if (tls_process_server_finished(conn, ct, buf, len))
1547 tls_process_application_data(conn, ct, buf, len, out_data,
1554 conn->state);
1559 tls_verify_hash_add(&conn->verify, buf, *len);