X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=ssl%2Fstatem%2Fstatem_clnt.c;h=6a05b9dd240466b04b3c45ebe296eab7fb45c36b;hp=5e5983a24f858607c0e43cba2dd4aeb73f290347;hb=c8e2f98c97ff3327784843946c2d62761572e5d5;hpb=229185e668514e17bce9b22c38303e3cc3c9eb7a diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c index 5e5983a24f..6a05b9dd24 100644 --- a/ssl/statem/statem_clnt.c +++ b/ssl/statem/statem_clnt.c @@ -504,17 +504,17 @@ WORK_STATE ossl_statem_client_post_work(SSL *s, WORK_STATE wst) } /* - * Construct a message to be sent from the client to the server. + * Get the message construction function and message type for sending from the + * client * * Valid return values are: * 1: Success * 0: Error */ -int ossl_statem_client_construct_message(SSL *s, WPACKET *pkt) +int ossl_statem_client_construct_message(SSL *s, WPACKET *pkt, + confunc_f *confunc, int *mt) { OSSL_STATEM *st = &s->statem; - int (*confunc) (SSL *s, WPACKET *pkt) = NULL; - int mt; switch (st->hand_state) { default: @@ -523,51 +523,44 @@ int ossl_statem_client_construct_message(SSL *s, WPACKET *pkt) case TLS_ST_CW_CHANGE: if (SSL_IS_DTLS(s)) - confunc = dtls_construct_change_cipher_spec; + *confunc = dtls_construct_change_cipher_spec; else - confunc = tls_construct_change_cipher_spec; - mt = SSL3_MT_CHANGE_CIPHER_SPEC; + *confunc = tls_construct_change_cipher_spec; + *mt = SSL3_MT_CHANGE_CIPHER_SPEC; break; case TLS_ST_CW_CLNT_HELLO: - confunc = tls_construct_client_hello; - mt = SSL3_MT_CLIENT_HELLO; + *confunc = tls_construct_client_hello; + *mt = SSL3_MT_CLIENT_HELLO; break; case TLS_ST_CW_CERT: - confunc = tls_construct_client_certificate; - mt = SSL3_MT_CERTIFICATE; + *confunc = tls_construct_client_certificate; + *mt = SSL3_MT_CERTIFICATE; break; case TLS_ST_CW_KEY_EXCH: - confunc = tls_construct_client_key_exchange; - mt = SSL3_MT_CLIENT_KEY_EXCHANGE; + *confunc = tls_construct_client_key_exchange; + *mt = SSL3_MT_CLIENT_KEY_EXCHANGE; break; case TLS_ST_CW_CERT_VRFY: - confunc = tls_construct_client_verify; - mt = SSL3_MT_CERTIFICATE_VERIFY; + *confunc = tls_construct_client_verify; + *mt = SSL3_MT_CERTIFICATE_VERIFY; break; #if !defined(OPENSSL_NO_NEXTPROTONEG) case TLS_ST_CW_NEXT_PROTO: - confunc = tls_construct_next_proto; - mt = SSL3_MT_NEXT_PROTO; + *confunc = tls_construct_next_proto; + *mt = SSL3_MT_NEXT_PROTO; break; #endif case TLS_ST_CW_FINISHED: - confunc = tls_construct_finished; - mt = SSL3_MT_FINISHED; + *confunc = tls_construct_finished; + *mt = SSL3_MT_FINISHED; break; } - if (!ssl_set_handshake_header(s, pkt, mt) - || !confunc(s, pkt) - || !ssl_close_construct_packet(s, pkt, mt)) { - SSLerr(SSL_F_OSSL_STATEM_CLIENT_CONSTRUCT_MESSAGE, - ERR_R_INTERNAL_ERROR); - return 0; - } return 1; } @@ -575,7 +568,7 @@ int ossl_statem_client_construct_message(SSL *s, WPACKET *pkt) * Returns the maximum allowed length for the current message that we are * reading. Excludes the message header. */ -unsigned long ossl_statem_client_max_message_size(SSL *s) +size_t ossl_statem_client_max_message_size(SSL *s) { OSSL_STATEM *st = &s->statem; @@ -703,8 +696,8 @@ WORK_STATE ossl_statem_client_post_process_message(SSL *s, WORK_STATE wst) int tls_construct_client_hello(SSL *s, WPACKET *pkt) { unsigned char *p; - int i; - int protverr; + size_t sess_id_len; + int i, protverr; int al = SSL_AD_HANDSHAKE_FAILURE; #ifndef OPENSSL_NO_COMP SSL_COMP *comp; @@ -795,12 +788,13 @@ int tls_construct_client_hello(SSL *s, WPACKET *pkt) /* Session ID */ if (s->new_session) - i = 0; + sess_id_len = 0; else - i = s->session->session_id_length; - if (i > (int)sizeof(s->session->session_id) + sess_id_len = s->session->session_id_length; + if (sess_id_len > sizeof(s->session->session_id) || !WPACKET_start_sub_packet_u8(pkt) - || (i != 0 && !WPACKET_memcpy(pkt, s->session->session_id, i)) + || (sess_id_len != 0 && !WPACKET_memcpy(pkt, s->session->session_id, + sess_id_len)) || !WPACKET_close(pkt)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); return 0; @@ -876,7 +870,7 @@ int tls_construct_client_hello(SSL *s, WPACKET *pkt) MSG_PROCESS_RETURN dtls_process_hello_verify(SSL *s, PACKET *pkt) { int al; - unsigned int cookie_len; + size_t cookie_len; PACKET cookiepkt; if (!PACKET_forward(pkt, 2) @@ -980,11 +974,18 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt) if (s->version >= TLS1_VERSION && s->tls_session_secret_cb && s->session->tlsext_tick) { const SSL_CIPHER *pref_cipher = NULL; - s->session->master_key_length = sizeof(s->session->master_key); + /* + * s->session->master_key_length is a size_t, but this is an int for + * backwards compat reasons + */ + int master_key_length; + master_key_length = sizeof(s->session->master_key); if (s->tls_session_secret_cb(s, s->session->master_key, - &s->session->master_key_length, + &master_key_length, NULL, &pref_cipher, - s->tls_session_secret_cb_arg)) { + s->tls_session_secret_cb_arg) + && master_key_length > 0) { + s->session->master_key_length = master_key_length; s->session->cipher = pref_cipher ? pref_cipher : ssl_get_cipher_by_char(s, cipherchars); } else { @@ -1226,7 +1227,21 @@ MSG_PROCESS_RETURN tls_process_server_certificate(SSL *s, PACKET *pkt) } i = ssl_verify_cert_chain(s, sk); - if ((s->verify_mode & SSL_VERIFY_PEER) && i <= 0) { + /* + * The documented interface is that SSL_VERIFY_PEER should be set in order + * for client side verification of the server certificate to take place. + * However, historically the code has only checked that *any* flag is set + * to cause server verification to take place. Use of the other flags makes + * no sense in client mode. An attempt to clean up the semantics was + * reverted because at least one application *only* set + * SSL_VERIFY_FAIL_IF_NO_PEER_CERT. Prior to the clean up this still caused + * server verification to take place, after the clean up it silently did + * nothing. SSL_CTX_set_verify()/SSL_set_verify() cannot validate the flags + * sent to them because they are void functions. Therefore, we now use the + * (less clean) historic behaviour of performing validation if any flag is + * set. The *documented* interface remains the same. + */ + if (s->verify_mode != SSL_VERIFY_NONE && i <= 0) { al = ssl_verify_alarm_type(s->verify_result); SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE, SSL_R_CERTIFICATE_VERIFY_FAILED); @@ -1357,18 +1372,19 @@ static int tls_process_ske_srp(SSL *s, PACKET *pkt, EVP_PKEY **pkey, int *al) return 0; } + /* TODO(size_t): Convert BN_bin2bn() calls */ if ((s->srp_ctx.N = BN_bin2bn(PACKET_data(&prime), - PACKET_remaining(&prime), NULL)) == NULL + (int)PACKET_remaining(&prime), NULL)) == NULL || (s->srp_ctx.g = BN_bin2bn(PACKET_data(&generator), - PACKET_remaining(&generator), NULL)) == NULL + (int)PACKET_remaining(&generator), NULL)) == NULL || (s->srp_ctx.s = BN_bin2bn(PACKET_data(&salt), - PACKET_remaining(&salt), NULL)) == NULL + (int)PACKET_remaining(&salt), NULL)) == NULL || (s->srp_ctx.B = BN_bin2bn(PACKET_data(&server_pub), - PACKET_remaining(&server_pub), NULL)) == NULL) { + (int)PACKET_remaining(&server_pub), NULL)) == NULL) { *al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_SKE_SRP, ERR_R_BN_LIB); return 0; @@ -1418,10 +1434,12 @@ static int tls_process_ske_dhe(SSL *s, PACKET *pkt, EVP_PKEY **pkey, int *al) goto err; } - p = BN_bin2bn(PACKET_data(&prime), PACKET_remaining(&prime), NULL); - g = BN_bin2bn(PACKET_data(&generator), PACKET_remaining(&generator), NULL); - bnpub_key = BN_bin2bn(PACKET_data(&pub_key), PACKET_remaining(&pub_key), - NULL); + /* TODO(size_t): Convert these calls */ + p = BN_bin2bn(PACKET_data(&prime), (int)PACKET_remaining(&prime), NULL); + g = BN_bin2bn(PACKET_data(&generator), (int)PACKET_remaining(&generator), + NULL); + bnpub_key = BN_bin2bn(PACKET_data(&pub_key), + (int)PACKET_remaining(&pub_key), NULL); if (p == NULL || g == NULL || bnpub_key == NULL) { *al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_BN_LIB); @@ -1709,8 +1727,10 @@ MSG_PROCESS_RETURN tls_process_key_exchange(SSL *s, PACKET *pkt) SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_EVP_LIB); goto err; } + /* TODO(size_t): Convert this call */ if (EVP_VerifyFinal(md_ctx, PACKET_data(&signature), - PACKET_remaining(&signature), pkey) <= 0) { + (unsigned int)PACKET_remaining(&signature), + pkey) <= 0) { /* bad signature */ EVP_MD_CTX_free(md_ctx); al = SSL_AD_DECRYPT_ERROR; @@ -1779,7 +1799,7 @@ MSG_PROCESS_RETURN tls_process_certificate_request(SSL *s, PACKET *pkt) goto err; } memcpy(s->cert->ctypes, data, ctype_num); - s->cert->ctype_num = (size_t)ctype_num; + s->cert->ctype_num = ctype_num; ctype_num = SSL3_CT_NUMBER; } for (i = 0; i < ctype_num; i++) @@ -1880,6 +1900,7 @@ MSG_PROCESS_RETURN tls_process_new_session_ticket(SSL *s, PACKET *pkt) int al; unsigned int ticklen; unsigned long ticket_lifetime_hint; + unsigned int sess_len; if (!PACKET_get_net_4(pkt, &ticket_lifetime_hint) || !PACKET_get_net_2(pkt, &ticklen) @@ -1944,12 +1965,17 @@ MSG_PROCESS_RETURN tls_process_new_session_ticket(SSL *s, PACKET *pkt) * elsewhere in OpenSSL. The session ID is set to the SHA256 (or SHA1 is * SHA256 is disabled) hash of the ticket. */ + /* + * TODO(size_t): we use sess_len here because EVP_Digest expects an int + * but s->session->session_id_length is a size_t + */ if (!EVP_Digest(s->session->tlsext_tick, ticklen, - s->session->session_id, &s->session->session_id_length, + s->session->session_id, &sess_len, EVP_sha256(), NULL)) { SSLerr(SSL_F_TLS_PROCESS_NEW_SESSION_TICKET, ERR_R_EVP_LIB); goto err; } + s->session->session_id_length = sess_len; return MSG_PROCESS_CONTINUE_READING; f_err: ssl3_send_alert(s, SSL3_AL_FATAL, al); @@ -1961,7 +1987,7 @@ MSG_PROCESS_RETURN tls_process_new_session_ticket(SSL *s, PACKET *pkt) MSG_PROCESS_RETURN tls_process_cert_status(SSL *s, PACKET *pkt) { int al; - unsigned long resplen; + size_t resplen; unsigned int type; if (!PACKET_get_1(pkt, &type) @@ -1970,7 +1996,7 @@ MSG_PROCESS_RETURN tls_process_cert_status(SSL *s, PACKET *pkt) SSLerr(SSL_F_TLS_PROCESS_CERT_STATUS, SSL_R_UNSUPPORTED_STATUS_TYPE); goto f_err; } - if (!PACKET_get_net_3(pkt, &resplen) + if (!PACKET_get_net_3_len(pkt, &resplen) || PACKET_remaining(pkt) != resplen) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CERT_STATUS, SSL_R_LENGTH_MISMATCH); @@ -2184,7 +2210,8 @@ static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al) pms[0] = s->client_version >> 8; pms[1] = s->client_version & 0xff; - if (RAND_bytes(pms + 2, pmslen - 2) <= 0) { + /* TODO(size_t): Convert this function */ + if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) { goto err; } @@ -2274,7 +2301,7 @@ static int tls_construct_cke_ecdhe(SSL *s, WPACKET *pkt, int *al) { #ifndef OPENSSL_NO_EC unsigned char *encodedPoint = NULL; - int encoded_pt_len = 0; + size_t encoded_pt_len = 0; EVP_PKEY *ckey = NULL, *skey = NULL; int ret = 0; @@ -2366,8 +2393,10 @@ static int tls_construct_cke_gost(SSL *s, WPACKET *pkt, int *al) } if (EVP_PKEY_encrypt_init(pkey_ctx) <= 0 - /* Generate session key */ - || RAND_bytes(pms, pmslen) <= 0) { + /* Generate session key + * TODO(size_t): Convert this function + */ + || RAND_bytes(pms, (int)pmslen) <= 0) { *al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST, ERR_R_INTERNAL_ERROR); goto err; @@ -2608,7 +2637,7 @@ int tls_construct_client_verify(SSL *s, WPACKET *pkt) || !EVP_SignUpdate(mctx, hdata, hdatalen) || (s->version == SSL3_VERSION && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET, - s->session->master_key_length, + (int)s->session->master_key_length, s->session->master_key)) || !EVP_SignFinal(mctx, sig, &u, pkey)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB); @@ -2743,8 +2772,8 @@ WORK_STATE tls_prepare_client_certificate(SSL *s, WORK_STATE wst) int tls_construct_client_certificate(SSL *s, WPACKET *pkt) { if (!ssl3_output_cert_chain(s, pkt, - (s->s3->tmp.cert_req == - 2) ? NULL : s->cert->key)) { + (s->s3->tmp.cert_req == 2) ? NULL + : s->cert->key)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_CERTIFICATE, ERR_R_INTERNAL_ERROR); ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return 0;