static enum ssl_hs_wait_t do_process_client_hello(SSL *ssl, SSL_HANDSHAKE *hs) { if (!tls13_check_message_type(ssl, SSL3_MT_CLIENT_HELLO)) { return ssl_hs_error; } struct ssl_early_callback_ctx client_hello; if (!ssl_early_callback_init(ssl, &client_hello, ssl->init_msg, ssl->init_num)) { OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED); ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); return ssl_hs_error; } assert(ssl->s3->have_version); /* Load the client random. */ if (client_hello.random_len != SSL3_RANDOM_SIZE) { OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); return -1; } memcpy(ssl->s3->client_random, client_hello.random, client_hello.random_len); SSL_set_session(ssl, NULL); if (!ssl_get_new_session(ssl, 1 /* server */)) { ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return ssl_hs_error; } if (ssl->ctx->dos_protection_cb != NULL && ssl->ctx->dos_protection_cb(&client_hello) == 0) { /* Connection rejected for DOS reasons. */ OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED); ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ACCESS_DENIED); return ssl_hs_error; } /* TLS 1.3 requires the peer only advertise the null compression. */ if (client_hello.compression_methods_len != 1 || client_hello.compression_methods[0] != 0) { OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMPRESSION_LIST); ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); return ssl_hs_error; } /* TLS extensions. */ if (!ssl_parse_clienthello_tlsext(ssl, &client_hello)) { OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT); return ssl_hs_error; } hs->state = state_select_parameters; return ssl_hs_ok; }
static enum ssl_hs_wait_t do_process_client_hello(SSL *ssl, SSL_HANDSHAKE *hs) { if (!tls13_check_message_type(ssl, SSL3_MT_CLIENT_HELLO)) { return ssl_hs_error; } struct ssl_early_callback_ctx client_hello; if (!ssl_early_callback_init(ssl, &client_hello, ssl->init_msg, ssl->init_num)) { OPENSSL_PUT_ERROR(SSL, SSL_R_CLIENTHELLO_PARSE_FAILED); ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); return ssl_hs_error; } assert(ssl->s3->have_version); /* Load the client random. */ if (client_hello.random_len != SSL3_RANDOM_SIZE) { OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); return -1; } memcpy(ssl->s3->client_random, client_hello.random, client_hello.random_len); uint8_t alert = SSL_AD_DECODE_ERROR; SSL_SESSION *session = NULL; CBS pre_shared_key; if (ssl_early_callback_get_extension(&client_hello, &pre_shared_key, TLSEXT_TYPE_pre_shared_key) && !ssl_ext_pre_shared_key_parse_clienthello(ssl, &session, &alert, &pre_shared_key)) { ssl3_send_alert(ssl, SSL3_AL_FATAL, alert); return 0; } uint16_t resumption_cipher; if (session != NULL && /* We currently only support ECDHE-PSK resumption. */ ((session->ticket_flags & SSL_TICKET_ALLOW_DHE_RESUMPTION) == 0 || /* Only resume if the session's version matches. */ session->ssl_version != ssl->version || !ssl_cipher_get_ecdhe_psk_cipher(session->cipher, &resumption_cipher) || !ssl_client_cipher_list_contains_cipher(&client_hello, resumption_cipher))) { SSL_SESSION_free(session); session = NULL; } if (session == NULL) { if (!ssl_get_new_session(ssl, 1 /* server */)) { ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return ssl_hs_error; } } else { /* Only authentication information carries over in TLS 1.3. */ ssl->s3->new_session = SSL_SESSION_dup(session, SSL_SESSION_DUP_AUTH_ONLY); if (ssl->s3->new_session == NULL) { ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return ssl_hs_error; } ssl->s3->session_reused = 1; SSL_SESSION_free(session); } if (ssl->ctx->dos_protection_cb != NULL && ssl->ctx->dos_protection_cb(&client_hello) == 0) { /* Connection rejected for DOS reasons. */ OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED); ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return ssl_hs_error; } /* TLS 1.3 requires the peer only advertise the null compression. */ if (client_hello.compression_methods_len != 1 || client_hello.compression_methods[0] != 0) { OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMPRESSION_LIST); ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER); return ssl_hs_error; } /* TLS extensions. */ if (!ssl_parse_clienthello_tlsext(ssl, &client_hello)) { OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT); return ssl_hs_error; } hs->state = state_select_parameters; return ssl_hs_ok; }