2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* ====================================================================
11 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
13 * Portions of the attached software ("Contribution") are developed by
14 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
16 * The Contribution is licensed pursuant to the OpenSSL open source
17 * license provided above.
19 * ECC cipher suite support in OpenSSL originally written by
20 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
23 /* ====================================================================
24 * Copyright 2005 Nokia. All rights reserved.
26 * The portions of the attached software ("Contribution") is developed by
27 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
30 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
31 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
32 * support (see RFC 4279) to OpenSSL.
34 * No patent licenses or other rights except those expressly stated in
35 * the OpenSSL open source license shall be deemed granted or received
36 * expressly, by implication, estoppel, or otherwise.
38 * No assurances are provided by Nokia that the Contribution does not
39 * infringe the patent or other intellectual property rights of any third
40 * party or that the license provides you with all the necessary rights
41 * to make use of the Contribution.
43 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
44 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
45 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
46 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
51 #include "../ssl_locl.h"
52 #include "statem_locl.h"
53 #include <openssl/buffer.h>
54 #include <openssl/rand.h>
55 #include <openssl/objects.h>
56 #include <openssl/evp.h>
57 #include <openssl/md5.h>
58 #include <openssl/dh.h>
59 #include <openssl/bn.h>
60 #include <openssl/engine.h>
62 static ossl_inline
int cert_req_allowed(SSL
*s
);
63 static int key_exchange_expected(SSL
*s
);
64 static int ca_dn_cmp(const X509_NAME
*const *a
, const X509_NAME
*const *b
);
65 static int ssl_cipher_list_to_bytes(SSL
*s
, STACK_OF(SSL_CIPHER
) *sk
,
69 * Is a CertificateRequest message allowed at the moment or not?
75 static ossl_inline
int cert_req_allowed(SSL
*s
)
77 /* TLS does not like anon-DH with client cert */
78 if ((s
->version
> SSL3_VERSION
79 && (s
->s3
->tmp
.new_cipher
->algorithm_auth
& SSL_aNULL
))
80 || (s
->s3
->tmp
.new_cipher
->algorithm_auth
& (SSL_aSRP
| SSL_aPSK
)))
87 * Should we expect the ServerKeyExchange message or not?
93 static int key_exchange_expected(SSL
*s
)
95 long alg_k
= s
->s3
->tmp
.new_cipher
->algorithm_mkey
;
98 * Can't skip server key exchange if this is an ephemeral
99 * ciphersuite or for SRP
101 if (alg_k
& (SSL_kDHE
| SSL_kECDHE
| SSL_kDHEPSK
| SSL_kECDHEPSK
110 * ossl_statem_client_read_transition() encapsulates the logic for the allowed
111 * handshake state transitions when a TLS1.3 client is reading messages from the
112 * server. The message type that the server has sent is provided in |mt|. The
113 * current state is in |s->statem.hand_state|.
115 * Return values are 1 for success (transition allowed) and 0 on error
116 * (transition not allowed)
118 static int ossl_statem_client13_read_transition(SSL
*s
, int mt
)
120 OSSL_STATEM
*st
= &s
->statem
;
123 * TODO(TLS1.3): This is still based on the TLSv1.2 state machine. Over time
124 * we will update this to look more like real TLSv1.3
128 * Note: There is no case for TLS_ST_CW_CLNT_HELLO, because we haven't
129 * yet negotiated TLSv1.3 at that point so that is handled by
130 * ossl_statem_client_read_transition()
133 switch (st
->hand_state
) {
137 case TLS_ST_CR_SRVR_HELLO
:
139 if (mt
== SSL3_MT_CHANGE_CIPHER_SPEC
) {
140 st
->hand_state
= TLS_ST_CR_CHANGE
;
144 if (mt
== SSL3_MT_CERTIFICATE
) {
145 st
->hand_state
= TLS_ST_CR_CERT
;
153 * The CertificateStatus message is optional even if
154 * |tlsext_status_expected| is set
156 if (s
->tlsext_status_expected
&& mt
== SSL3_MT_CERTIFICATE_STATUS
) {
157 st
->hand_state
= TLS_ST_CR_CERT_STATUS
;
162 case TLS_ST_CR_CERT_STATUS
:
163 if (mt
== SSL3_MT_CERTIFICATE_REQUEST
) {
164 if (cert_req_allowed(s
)) {
165 st
->hand_state
= TLS_ST_CR_CERT_REQ
;
172 case TLS_ST_CR_CERT_REQ
:
173 if (mt
== SSL3_MT_SERVER_DONE
) {
174 st
->hand_state
= TLS_ST_CR_SRVR_DONE
;
179 case TLS_ST_CW_FINISHED
:
180 if (mt
== SSL3_MT_CHANGE_CIPHER_SPEC
) {
181 st
->hand_state
= TLS_ST_CR_CHANGE
;
186 case TLS_ST_CR_CHANGE
:
187 if (mt
== SSL3_MT_FINISHED
) {
188 st
->hand_state
= TLS_ST_CR_FINISHED
;
195 /* No valid transition found */
196 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL3_AD_UNEXPECTED_MESSAGE
);
197 SSLerr(SSL_F_OSSL_STATEM_CLIENT13_READ_TRANSITION
,
198 SSL_R_UNEXPECTED_MESSAGE
);
203 * ossl_statem_client_read_transition() encapsulates the logic for the allowed
204 * handshake state transitions when the client is reading messages from the
205 * server. The message type that the server has sent is provided in |mt|. The
206 * current state is in |s->statem.hand_state|.
208 * Return values are 1 for success (transition allowed) and 0 on error
209 * (transition not allowed)
211 int ossl_statem_client_read_transition(SSL
*s
, int mt
)
213 OSSL_STATEM
*st
= &s
->statem
;
217 * Note that after a ClientHello we don't know what version we are going
218 * to negotiate yet, so we don't take this branch until later
220 if (s
->method
->version
== TLS1_3_VERSION
)
221 return ossl_statem_client13_read_transition(s
, mt
);
223 switch (st
->hand_state
) {
227 case TLS_ST_CW_CLNT_HELLO
:
228 if (mt
== SSL3_MT_SERVER_HELLO
) {
229 st
->hand_state
= TLS_ST_CR_SRVR_HELLO
;
233 if (SSL_IS_DTLS(s
)) {
234 if (mt
== DTLS1_MT_HELLO_VERIFY_REQUEST
) {
235 st
->hand_state
= DTLS_ST_CR_HELLO_VERIFY_REQUEST
;
241 case TLS_ST_CR_SRVR_HELLO
:
243 if (s
->tlsext_ticket_expected
) {
244 if (mt
== SSL3_MT_NEWSESSION_TICKET
) {
245 st
->hand_state
= TLS_ST_CR_SESSION_TICKET
;
248 } else if (mt
== SSL3_MT_CHANGE_CIPHER_SPEC
) {
249 st
->hand_state
= TLS_ST_CR_CHANGE
;
253 if (SSL_IS_DTLS(s
) && mt
== DTLS1_MT_HELLO_VERIFY_REQUEST
) {
254 st
->hand_state
= DTLS_ST_CR_HELLO_VERIFY_REQUEST
;
256 } else if (s
->version
>= TLS1_VERSION
257 && s
->tls_session_secret_cb
!= NULL
258 && s
->session
->tlsext_tick
!= NULL
259 && mt
== SSL3_MT_CHANGE_CIPHER_SPEC
) {
261 * Normally, we can tell if the server is resuming the session
262 * from the session ID. EAP-FAST (RFC 4851), however, relies on
263 * the next server message after the ServerHello to determine if
264 * the server is resuming.
267 st
->hand_state
= TLS_ST_CR_CHANGE
;
269 } else if (!(s
->s3
->tmp
.new_cipher
->algorithm_auth
270 & (SSL_aNULL
| SSL_aSRP
| SSL_aPSK
))) {
271 if (mt
== SSL3_MT_CERTIFICATE
) {
272 st
->hand_state
= TLS_ST_CR_CERT
;
276 ske_expected
= key_exchange_expected(s
);
277 /* SKE is optional for some PSK ciphersuites */
279 || ((s
->s3
->tmp
.new_cipher
->algorithm_mkey
& SSL_PSK
)
280 && mt
== SSL3_MT_SERVER_KEY_EXCHANGE
)) {
281 if (mt
== SSL3_MT_SERVER_KEY_EXCHANGE
) {
282 st
->hand_state
= TLS_ST_CR_KEY_EXCH
;
285 } else if (mt
== SSL3_MT_CERTIFICATE_REQUEST
286 && cert_req_allowed(s
)) {
287 st
->hand_state
= TLS_ST_CR_CERT_REQ
;
289 } else if (mt
== SSL3_MT_SERVER_DONE
) {
290 st
->hand_state
= TLS_ST_CR_SRVR_DONE
;
299 * The CertificateStatus message is optional even if
300 * |tlsext_status_expected| is set
302 if (s
->tlsext_status_expected
&& mt
== SSL3_MT_CERTIFICATE_STATUS
) {
303 st
->hand_state
= TLS_ST_CR_CERT_STATUS
;
308 case TLS_ST_CR_CERT_STATUS
:
309 ske_expected
= key_exchange_expected(s
);
310 /* SKE is optional for some PSK ciphersuites */
311 if (ske_expected
|| ((s
->s3
->tmp
.new_cipher
->algorithm_mkey
& SSL_PSK
)
312 && mt
== SSL3_MT_SERVER_KEY_EXCHANGE
)) {
313 if (mt
== SSL3_MT_SERVER_KEY_EXCHANGE
) {
314 st
->hand_state
= TLS_ST_CR_KEY_EXCH
;
321 case TLS_ST_CR_KEY_EXCH
:
322 if (mt
== SSL3_MT_CERTIFICATE_REQUEST
) {
323 if (cert_req_allowed(s
)) {
324 st
->hand_state
= TLS_ST_CR_CERT_REQ
;
331 case TLS_ST_CR_CERT_REQ
:
332 if (mt
== SSL3_MT_SERVER_DONE
) {
333 st
->hand_state
= TLS_ST_CR_SRVR_DONE
;
338 case TLS_ST_CW_FINISHED
:
339 if (s
->tlsext_ticket_expected
) {
340 if (mt
== SSL3_MT_NEWSESSION_TICKET
) {
341 st
->hand_state
= TLS_ST_CR_SESSION_TICKET
;
344 } else if (mt
== SSL3_MT_CHANGE_CIPHER_SPEC
) {
345 st
->hand_state
= TLS_ST_CR_CHANGE
;
350 case TLS_ST_CR_SESSION_TICKET
:
351 if (mt
== SSL3_MT_CHANGE_CIPHER_SPEC
) {
352 st
->hand_state
= TLS_ST_CR_CHANGE
;
357 case TLS_ST_CR_CHANGE
:
358 if (mt
== SSL3_MT_FINISHED
) {
359 st
->hand_state
= TLS_ST_CR_FINISHED
;
366 /* No valid transition found */
367 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL3_AD_UNEXPECTED_MESSAGE
);
368 SSLerr(SSL_F_OSSL_STATEM_CLIENT_READ_TRANSITION
, SSL_R_UNEXPECTED_MESSAGE
);
373 * ossl_statem_client13_write_transition() works out what handshake state to
374 * move to next when the TLSv1.3 client is writing messages to be sent to the
377 static WRITE_TRAN
ossl_statem_client13_write_transition(SSL
*s
)
379 OSSL_STATEM
*st
= &s
->statem
;
382 * TODO(TLS1.3): This is still based on the TLSv1.2 state machine. Over time
383 * we will update this to look more like real TLSv1.3
387 * Note: There are no cases for TLS_ST_BEFORE or TLS_ST_CW_CLNT_HELLO,
388 * because we haven't negotiated TLSv1.3 yet at that point. They are
389 * handled by ossl_statem_client_write_transition().
391 switch (st
->hand_state
) {
393 /* Shouldn't happen */
394 return WRITE_TRAN_ERROR
;
396 case TLS_ST_CR_SRVR_DONE
:
397 st
->hand_state
= (s
->s3
->tmp
.cert_req
!= 0) ? TLS_ST_CW_CERT
399 return WRITE_TRAN_CONTINUE
;
402 /* If a non-empty Certificate we also send CertificateVerify */
403 st
->hand_state
= (s
->s3
->tmp
.cert_req
== 1) ? TLS_ST_CW_CERT_VRFY
405 return WRITE_TRAN_CONTINUE
;
407 case TLS_ST_CW_CERT_VRFY
:
408 st
->hand_state
= TLS_ST_CW_CHANGE
;
409 return WRITE_TRAN_CONTINUE
;
411 case TLS_ST_CW_CHANGE
:
412 st
->hand_state
= TLS_ST_CW_FINISHED
;
413 return WRITE_TRAN_CONTINUE
;
415 case TLS_ST_CW_FINISHED
:
417 st
->hand_state
= TLS_ST_OK
;
418 ossl_statem_set_in_init(s
, 0);
419 return WRITE_TRAN_CONTINUE
;
421 return WRITE_TRAN_FINISHED
;
423 case TLS_ST_CR_FINISHED
:
425 st
->hand_state
= TLS_ST_CW_CHANGE
;
426 return WRITE_TRAN_CONTINUE
;
428 st
->hand_state
= TLS_ST_OK
;
429 ossl_statem_set_in_init(s
, 0);
430 return WRITE_TRAN_CONTINUE
;
435 * ossl_statem_client_write_transition() works out what handshake state to
436 * move to next when the client is writing messages to be sent to the server.
438 WRITE_TRAN
ossl_statem_client_write_transition(SSL
*s
)
440 OSSL_STATEM
*st
= &s
->statem
;
443 * Note that immediately before/after a ClientHello we don't know what
444 * version we are going to negotiate yet, so we don't take this branch until
447 if (s
->method
->version
== TLS1_3_VERSION
)
448 return ossl_statem_client13_write_transition(s
);
450 switch (st
->hand_state
) {
452 /* Shouldn't happen */
453 return WRITE_TRAN_ERROR
;
456 /* Renegotiation - fall through */
458 st
->hand_state
= TLS_ST_CW_CLNT_HELLO
;
459 return WRITE_TRAN_CONTINUE
;
461 case TLS_ST_CW_CLNT_HELLO
:
463 * No transition at the end of writing because we don't know what
466 return WRITE_TRAN_FINISHED
;
468 case DTLS_ST_CR_HELLO_VERIFY_REQUEST
:
469 st
->hand_state
= TLS_ST_CW_CLNT_HELLO
;
470 return WRITE_TRAN_CONTINUE
;
472 case TLS_ST_CR_SRVR_DONE
:
473 if (s
->s3
->tmp
.cert_req
)
474 st
->hand_state
= TLS_ST_CW_CERT
;
476 st
->hand_state
= TLS_ST_CW_KEY_EXCH
;
477 return WRITE_TRAN_CONTINUE
;
480 st
->hand_state
= TLS_ST_CW_KEY_EXCH
;
481 return WRITE_TRAN_CONTINUE
;
483 case TLS_ST_CW_KEY_EXCH
:
485 * For TLS, cert_req is set to 2, so a cert chain of nothing is
486 * sent, but no verify packet is sent
489 * XXX: For now, we do not support client authentication in ECDH
490 * cipher suites with ECDH (rather than ECDSA) certificates. We
491 * need to skip the certificate verify message when client's
492 * ECDH public key is sent inside the client certificate.
494 if (s
->s3
->tmp
.cert_req
== 1) {
495 st
->hand_state
= TLS_ST_CW_CERT_VRFY
;
497 st
->hand_state
= TLS_ST_CW_CHANGE
;
499 if (s
->s3
->flags
& TLS1_FLAGS_SKIP_CERT_VERIFY
) {
500 st
->hand_state
= TLS_ST_CW_CHANGE
;
502 return WRITE_TRAN_CONTINUE
;
504 case TLS_ST_CW_CERT_VRFY
:
505 st
->hand_state
= TLS_ST_CW_CHANGE
;
506 return WRITE_TRAN_CONTINUE
;
508 case TLS_ST_CW_CHANGE
:
509 #if defined(OPENSSL_NO_NEXTPROTONEG)
510 st
->hand_state
= TLS_ST_CW_FINISHED
;
512 if (!SSL_IS_DTLS(s
) && s
->s3
->next_proto_neg_seen
)
513 st
->hand_state
= TLS_ST_CW_NEXT_PROTO
;
515 st
->hand_state
= TLS_ST_CW_FINISHED
;
517 return WRITE_TRAN_CONTINUE
;
519 #if !defined(OPENSSL_NO_NEXTPROTONEG)
520 case TLS_ST_CW_NEXT_PROTO
:
521 st
->hand_state
= TLS_ST_CW_FINISHED
;
522 return WRITE_TRAN_CONTINUE
;
525 case TLS_ST_CW_FINISHED
:
527 st
->hand_state
= TLS_ST_OK
;
528 ossl_statem_set_in_init(s
, 0);
529 return WRITE_TRAN_CONTINUE
;
531 return WRITE_TRAN_FINISHED
;
534 case TLS_ST_CR_FINISHED
:
536 st
->hand_state
= TLS_ST_CW_CHANGE
;
537 return WRITE_TRAN_CONTINUE
;
539 st
->hand_state
= TLS_ST_OK
;
540 ossl_statem_set_in_init(s
, 0);
541 return WRITE_TRAN_CONTINUE
;
547 * Perform any pre work that needs to be done prior to sending a message from
548 * the client to the server.
550 WORK_STATE
ossl_statem_client_pre_work(SSL
*s
, WORK_STATE wst
)
552 OSSL_STATEM
*st
= &s
->statem
;
554 switch (st
->hand_state
) {
556 /* No pre work to be done */
559 case TLS_ST_CW_CLNT_HELLO
:
561 if (SSL_IS_DTLS(s
)) {
562 /* every DTLS ClientHello resets Finished MAC */
563 if (!ssl3_init_finished_mac(s
)) {
564 ossl_statem_set_error(s
);
570 case TLS_ST_CW_CHANGE
:
571 if (SSL_IS_DTLS(s
)) {
574 * We're into the last flight so we don't retransmit these
575 * messages unless we need to.
579 #ifndef OPENSSL_NO_SCTP
580 if (BIO_dgram_is_sctp(SSL_get_wbio(s
)))
581 return dtls_wait_for_dry(s
);
587 return tls_finish_handshake(s
, wst
);
590 return WORK_FINISHED_CONTINUE
;
594 * Perform any work that needs to be done after sending a message from the
595 * client to the server.
597 WORK_STATE
ossl_statem_client_post_work(SSL
*s
, WORK_STATE wst
)
599 OSSL_STATEM
*st
= &s
->statem
;
603 switch (st
->hand_state
) {
605 /* No post work to be done */
608 case TLS_ST_CW_CLNT_HELLO
:
609 if (wst
== WORK_MORE_A
&& statem_flush(s
) != 1)
612 if (SSL_IS_DTLS(s
)) {
613 /* Treat the next message as the first packet */
618 case TLS_ST_CW_KEY_EXCH
:
619 if (tls_client_key_exchange_post_work(s
) == 0)
623 case TLS_ST_CW_CHANGE
:
624 s
->session
->cipher
= s
->s3
->tmp
.new_cipher
;
625 #ifdef OPENSSL_NO_COMP
626 s
->session
->compress_meth
= 0;
628 if (s
->s3
->tmp
.new_compression
== NULL
)
629 s
->session
->compress_meth
= 0;
631 s
->session
->compress_meth
= s
->s3
->tmp
.new_compression
->id
;
633 if (!s
->method
->ssl3_enc
->setup_key_block(s
))
636 if (!s
->method
->ssl3_enc
->change_cipher_state(s
,
637 SSL3_CHANGE_CIPHER_CLIENT_WRITE
))
640 if (SSL_IS_DTLS(s
)) {
641 #ifndef OPENSSL_NO_SCTP
644 * Change to new shared key of SCTP-Auth, will be ignored if
647 BIO_ctrl(SSL_get_wbio(s
), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY
,
652 dtls1_reset_seq_numbers(s
, SSL3_CC_WRITE
);
656 case TLS_ST_CW_FINISHED
:
657 #ifndef OPENSSL_NO_SCTP
658 if (wst
== WORK_MORE_A
&& SSL_IS_DTLS(s
) && s
->hit
== 0) {
660 * Change to new shared key of SCTP-Auth, will be ignored if
663 BIO_ctrl(SSL_get_wbio(s
), BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY
,
667 if (statem_flush(s
) != 1)
672 return WORK_FINISHED_CONTINUE
;
676 * Get the message construction function and message type for sending from the
679 * Valid return values are:
683 int ossl_statem_client_construct_message(SSL
*s
, WPACKET
*pkt
,
684 confunc_f
*confunc
, int *mt
)
686 OSSL_STATEM
*st
= &s
->statem
;
688 switch (st
->hand_state
) {
690 /* Shouldn't happen */
693 case TLS_ST_CW_CHANGE
:
695 *confunc
= dtls_construct_change_cipher_spec
;
697 *confunc
= tls_construct_change_cipher_spec
;
698 *mt
= SSL3_MT_CHANGE_CIPHER_SPEC
;
701 case TLS_ST_CW_CLNT_HELLO
:
702 *confunc
= tls_construct_client_hello
;
703 *mt
= SSL3_MT_CLIENT_HELLO
;
707 *confunc
= tls_construct_client_certificate
;
708 *mt
= SSL3_MT_CERTIFICATE
;
711 case TLS_ST_CW_KEY_EXCH
:
712 *confunc
= tls_construct_client_key_exchange
;
713 *mt
= SSL3_MT_CLIENT_KEY_EXCHANGE
;
716 case TLS_ST_CW_CERT_VRFY
:
717 *confunc
= tls_construct_client_verify
;
718 *mt
= SSL3_MT_CERTIFICATE_VERIFY
;
721 #if !defined(OPENSSL_NO_NEXTPROTONEG)
722 case TLS_ST_CW_NEXT_PROTO
:
723 *confunc
= tls_construct_next_proto
;
724 *mt
= SSL3_MT_NEXT_PROTO
;
727 case TLS_ST_CW_FINISHED
:
728 *confunc
= tls_construct_finished
;
729 *mt
= SSL3_MT_FINISHED
;
737 * Returns the maximum allowed length for the current message that we are
738 * reading. Excludes the message header.
740 size_t ossl_statem_client_max_message_size(SSL
*s
)
742 OSSL_STATEM
*st
= &s
->statem
;
744 switch (st
->hand_state
) {
746 /* Shouldn't happen */
749 case TLS_ST_CR_SRVR_HELLO
:
750 return SERVER_HELLO_MAX_LENGTH
;
752 case DTLS_ST_CR_HELLO_VERIFY_REQUEST
:
753 return HELLO_VERIFY_REQUEST_MAX_LENGTH
;
756 return s
->max_cert_list
;
758 case TLS_ST_CR_CERT_STATUS
:
759 return SSL3_RT_MAX_PLAIN_LENGTH
;
761 case TLS_ST_CR_KEY_EXCH
:
762 return SERVER_KEY_EXCH_MAX_LENGTH
;
764 case TLS_ST_CR_CERT_REQ
:
766 * Set to s->max_cert_list for compatibility with previous releases. In
767 * practice these messages can get quite long if servers are configured
768 * to provide a long list of acceptable CAs
770 return s
->max_cert_list
;
772 case TLS_ST_CR_SRVR_DONE
:
773 return SERVER_HELLO_DONE_MAX_LENGTH
;
775 case TLS_ST_CR_CHANGE
:
776 if (s
->version
== DTLS1_BAD_VER
)
778 return CCS_MAX_LENGTH
;
780 case TLS_ST_CR_SESSION_TICKET
:
781 return SSL3_RT_MAX_PLAIN_LENGTH
;
783 case TLS_ST_CR_FINISHED
:
784 return FINISHED_MAX_LENGTH
;
789 * Process a message that the client has been received from the server.
791 MSG_PROCESS_RETURN
ossl_statem_client_process_message(SSL
*s
, PACKET
*pkt
)
793 OSSL_STATEM
*st
= &s
->statem
;
795 switch (st
->hand_state
) {
797 /* Shouldn't happen */
798 return MSG_PROCESS_ERROR
;
800 case TLS_ST_CR_SRVR_HELLO
:
801 return tls_process_server_hello(s
, pkt
);
803 case DTLS_ST_CR_HELLO_VERIFY_REQUEST
:
804 return dtls_process_hello_verify(s
, pkt
);
807 return tls_process_server_certificate(s
, pkt
);
809 case TLS_ST_CR_CERT_STATUS
:
810 return tls_process_cert_status(s
, pkt
);
812 case TLS_ST_CR_KEY_EXCH
:
813 return tls_process_key_exchange(s
, pkt
);
815 case TLS_ST_CR_CERT_REQ
:
816 return tls_process_certificate_request(s
, pkt
);
818 case TLS_ST_CR_SRVR_DONE
:
819 return tls_process_server_done(s
, pkt
);
821 case TLS_ST_CR_CHANGE
:
822 return tls_process_change_cipher_spec(s
, pkt
);
824 case TLS_ST_CR_SESSION_TICKET
:
825 return tls_process_new_session_ticket(s
, pkt
);
827 case TLS_ST_CR_FINISHED
:
828 return tls_process_finished(s
, pkt
);
833 * Perform any further processing required following the receipt of a message
836 WORK_STATE
ossl_statem_client_post_process_message(SSL
*s
, WORK_STATE wst
)
838 OSSL_STATEM
*st
= &s
->statem
;
840 switch (st
->hand_state
) {
842 /* Shouldn't happen */
845 case TLS_ST_CR_CERT_REQ
:
846 return tls_prepare_client_certificate(s
, wst
);
848 #ifndef OPENSSL_NO_SCTP
849 case TLS_ST_CR_SRVR_DONE
:
850 /* We only get here if we are using SCTP and we are renegotiating */
851 if (BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s
))) {
852 s
->s3
->in_read_app_data
= 2;
853 s
->rwstate
= SSL_READING
;
854 BIO_clear_retry_flags(SSL_get_rbio(s
));
855 BIO_set_retry_read(SSL_get_rbio(s
));
856 ossl_statem_set_sctp_read_sock(s
, 1);
859 ossl_statem_set_sctp_read_sock(s
, 0);
860 return WORK_FINISHED_STOP
;
865 int tls_construct_client_hello(SSL
*s
, WPACKET
*pkt
)
870 int al
= SSL_AD_HANDSHAKE_FAILURE
;
871 #ifndef OPENSSL_NO_COMP
874 SSL_SESSION
*sess
= s
->session
;
877 if (!WPACKET_set_max_size(pkt
, SSL3_RT_MAX_PLAIN_LENGTH
)) {
878 /* Should not happen */
879 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
883 /* Work out what SSL/TLS/DTLS version to use */
884 protverr
= ssl_set_client_hello_version(s
);
886 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, protverr
);
890 if ((sess
== NULL
) || !ssl_version_supported(s
, sess
->ssl_version
) ||
892 * In the case of EAP-FAST, we can have a pre-shared
893 * "ticket" without a session ID.
895 (!sess
->session_id_length
&& !sess
->tlsext_tick
) ||
896 (sess
->not_resumable
)) {
897 if (!ssl_get_new_session(s
, 0))
900 /* else use the pre-loaded session */
902 p
= s
->s3
->client_random
;
905 * for DTLS if client_random is initialized, reuse it, we are
906 * required to use same upon reply to HelloVerify
908 if (SSL_IS_DTLS(s
)) {
911 for (idx
= 0; idx
< sizeof(s
->s3
->client_random
); idx
++) {
920 if (i
&& ssl_fill_hello_random(s
, 0, p
, sizeof(s
->s3
->client_random
)) <= 0)
924 * version indicates the negotiated version: for example from
925 * an SSLv2/v3 compatible client hello). The client_version
926 * field is the maximum version we permit and it is also
927 * used in RSA encrypted premaster secrets. Some servers can
928 * choke if we initially report a higher version then
929 * renegotiate to a lower one in the premaster secret. This
930 * didn't happen with TLS 1.0 as most servers supported it
931 * but it can with TLS 1.1 or later if the server only supports
934 * Possible scenario with previous logic:
935 * 1. Client hello indicates TLS 1.2
936 * 2. Server hello says TLS 1.0
937 * 3. RSA encrypted premaster secret uses 1.2.
938 * 4. Handshake proceeds using TLS 1.0.
939 * 5. Server sends hello request to renegotiate.
940 * 6. Client hello indicates TLS v1.0 as we now
941 * know that is maximum server supports.
942 * 7. Server chokes on RSA encrypted premaster secret
943 * containing version 1.0.
945 * For interoperability it should be OK to always use the
946 * maximum version we support in client hello and then rely
947 * on the checking of version to ensure the servers isn't
948 * being inconsistent: for example initially negotiating with
949 * TLS 1.0 and renegotiating with TLS 1.2. We do this by using
950 * client_version in client hello and not resetting it to
951 * the negotiated version.
953 * For TLS 1.3 we always set the ClientHello version to 1.2 and rely on the
954 * supported_versions extension for the real supported versions.
956 client_version
= SSL_IS_TLS13(s
) ? TLS1_2_VERSION
: s
->client_version
;
957 if (!WPACKET_put_bytes_u16(pkt
, client_version
)
958 || !WPACKET_memcpy(pkt
, s
->s3
->client_random
, SSL3_RANDOM_SIZE
)) {
959 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
967 sess_id_len
= s
->session
->session_id_length
;
968 if (sess_id_len
> sizeof(s
->session
->session_id
)
969 || !WPACKET_start_sub_packet_u8(pkt
)
970 || (sess_id_len
!= 0 && !WPACKET_memcpy(pkt
, s
->session
->session_id
,
972 || !WPACKET_close(pkt
)) {
973 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
977 /* cookie stuff for DTLS */
978 if (SSL_IS_DTLS(s
)) {
979 if (s
->d1
->cookie_len
> sizeof(s
->d1
->cookie
)
980 || !WPACKET_sub_memcpy_u8(pkt
, s
->d1
->cookie
,
981 s
->d1
->cookie_len
)) {
982 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
987 /* Ciphers supported */
988 if (!WPACKET_start_sub_packet_u16(pkt
)) {
989 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
992 /* ssl_cipher_list_to_bytes() raises SSLerr if appropriate */
993 if (!ssl_cipher_list_to_bytes(s
, SSL_get_ciphers(s
), pkt
))
995 if (!WPACKET_close(pkt
)) {
996 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
1001 if (!WPACKET_start_sub_packet_u8(pkt
)) {
1002 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
1005 #ifndef OPENSSL_NO_COMP
1006 if (ssl_allow_compression(s
) && s
->ctx
->comp_methods
) {
1007 int compnum
= sk_SSL_COMP_num(s
->ctx
->comp_methods
);
1008 for (i
= 0; i
< compnum
; i
++) {
1009 comp
= sk_SSL_COMP_value(s
->ctx
->comp_methods
, i
);
1010 if (!WPACKET_put_bytes_u8(pkt
, comp
->id
)) {
1011 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
1017 /* Add the NULL method */
1018 if (!WPACKET_put_bytes_u8(pkt
, 0) || !WPACKET_close(pkt
)) {
1019 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
1023 /* TLS extensions */
1024 if (ssl_prepare_clienthello_tlsext(s
) <= 0) {
1025 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, SSL_R_CLIENTHELLO_TLSEXT
);
1028 if (!WPACKET_start_sub_packet_u16(pkt
)
1030 * If extensions are of zero length then we don't even add the
1031 * extensions length bytes
1033 || !WPACKET_set_flags(pkt
, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH
)
1034 || !ssl_add_clienthello_tlsext(s
, pkt
, &al
)
1035 || !WPACKET_close(pkt
)) {
1036 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
1037 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO
, ERR_R_INTERNAL_ERROR
);
1044 MSG_PROCESS_RETURN
dtls_process_hello_verify(SSL
*s
, PACKET
*pkt
)
1050 if (!PACKET_forward(pkt
, 2)
1051 || !PACKET_get_length_prefixed_1(pkt
, &cookiepkt
)) {
1052 al
= SSL_AD_DECODE_ERROR
;
1053 SSLerr(SSL_F_DTLS_PROCESS_HELLO_VERIFY
, SSL_R_LENGTH_MISMATCH
);
1057 cookie_len
= PACKET_remaining(&cookiepkt
);
1058 if (cookie_len
> sizeof(s
->d1
->cookie
)) {
1059 al
= SSL_AD_ILLEGAL_PARAMETER
;
1060 SSLerr(SSL_F_DTLS_PROCESS_HELLO_VERIFY
, SSL_R_LENGTH_TOO_LONG
);
1064 if (!PACKET_copy_bytes(&cookiepkt
, s
->d1
->cookie
, cookie_len
)) {
1065 al
= SSL_AD_DECODE_ERROR
;
1066 SSLerr(SSL_F_DTLS_PROCESS_HELLO_VERIFY
, SSL_R_LENGTH_MISMATCH
);
1069 s
->d1
->cookie_len
= cookie_len
;
1071 return MSG_PROCESS_FINISHED_READING
;
1073 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
1074 ossl_statem_set_error(s
);
1075 return MSG_PROCESS_ERROR
;
1078 MSG_PROCESS_RETURN
tls_process_server_hello(SSL
*s
, PACKET
*pkt
)
1080 STACK_OF(SSL_CIPHER
) *sk
;
1081 const SSL_CIPHER
*c
;
1083 size_t session_id_len
;
1084 const unsigned char *cipherchars
;
1085 int i
, al
= SSL_AD_INTERNAL_ERROR
;
1086 unsigned int compression
;
1087 unsigned int sversion
;
1089 #ifndef OPENSSL_NO_COMP
1093 if (!PACKET_get_net_2(pkt
, &sversion
)) {
1094 al
= SSL_AD_DECODE_ERROR
;
1095 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_LENGTH_MISMATCH
);
1099 protverr
= ssl_choose_client_version(s
, sversion
);
1100 if (protverr
!= 0) {
1101 al
= SSL_AD_PROTOCOL_VERSION
;
1102 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, protverr
);
1106 /* load the server hello data */
1107 /* load the server random */
1108 if (!PACKET_copy_bytes(pkt
, s
->s3
->server_random
, SSL3_RANDOM_SIZE
)) {
1109 al
= SSL_AD_DECODE_ERROR
;
1110 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_LENGTH_MISMATCH
);
1116 /* Get the session-id. */
1117 if (!PACKET_get_length_prefixed_1(pkt
, &session_id
)) {
1118 al
= SSL_AD_DECODE_ERROR
;
1119 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_LENGTH_MISMATCH
);
1122 session_id_len
= PACKET_remaining(&session_id
);
1123 if (session_id_len
> sizeof s
->session
->session_id
1124 || session_id_len
> SSL3_SESSION_ID_SIZE
) {
1125 al
= SSL_AD_ILLEGAL_PARAMETER
;
1126 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_SSL3_SESSION_ID_TOO_LONG
);
1130 if (!PACKET_get_bytes(pkt
, &cipherchars
, TLS_CIPHER_LEN
)) {
1131 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_LENGTH_MISMATCH
);
1132 al
= SSL_AD_DECODE_ERROR
;
1137 * Check if we can resume the session based on external pre-shared secret.
1138 * EAP-FAST (RFC 4851) supports two types of session resumption.
1139 * Resumption based on server-side state works with session IDs.
1140 * Resumption based on pre-shared Protected Access Credentials (PACs)
1141 * works by overriding the SessionTicket extension at the application
1142 * layer, and does not send a session ID. (We do not know whether EAP-FAST
1143 * servers would honour the session ID.) Therefore, the session ID alone
1144 * is not a reliable indicator of session resumption, so we first check if
1145 * we can resume, and later peek at the next handshake message to see if the
1146 * server wants to resume.
1148 if (s
->version
>= TLS1_VERSION
&& s
->tls_session_secret_cb
&&
1149 s
->session
->tlsext_tick
) {
1150 const SSL_CIPHER
*pref_cipher
= NULL
;
1152 * s->session->master_key_length is a size_t, but this is an int for
1153 * backwards compat reasons
1155 int master_key_length
;
1156 master_key_length
= sizeof(s
->session
->master_key
);
1157 if (s
->tls_session_secret_cb(s
, s
->session
->master_key
,
1160 s
->tls_session_secret_cb_arg
)
1161 && master_key_length
> 0) {
1162 s
->session
->master_key_length
= master_key_length
;
1163 s
->session
->cipher
= pref_cipher
?
1164 pref_cipher
: ssl_get_cipher_by_char(s
, cipherchars
);
1166 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, ERR_R_INTERNAL_ERROR
);
1167 al
= SSL_AD_INTERNAL_ERROR
;
1172 if (session_id_len
!= 0 && session_id_len
== s
->session
->session_id_length
1173 && memcmp(PACKET_data(&session_id
), s
->session
->session_id
,
1174 session_id_len
) == 0) {
1175 if (s
->sid_ctx_length
!= s
->session
->sid_ctx_length
1176 || memcmp(s
->session
->sid_ctx
, s
->sid_ctx
, s
->sid_ctx_length
)) {
1177 /* actually a client application bug */
1178 al
= SSL_AD_ILLEGAL_PARAMETER
;
1179 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
,
1180 SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT
);
1186 * If we were trying for session-id reuse but the server
1187 * didn't echo the ID, make a new SSL_SESSION.
1188 * In the case of EAP-FAST and PAC, we do not send a session ID,
1189 * so the PAC-based session secret is always preserved. It'll be
1190 * overwritten if the server refuses resumption.
1192 if (s
->session
->session_id_length
> 0) {
1193 s
->ctx
->stats
.sess_miss
++;
1194 if (!ssl_get_new_session(s
, 0)) {
1199 s
->session
->ssl_version
= s
->version
;
1200 s
->session
->session_id_length
= session_id_len
;
1201 /* session_id_len could be 0 */
1202 memcpy(s
->session
->session_id
, PACKET_data(&session_id
),
1206 /* Session version and negotiated protocol version should match */
1207 if (s
->version
!= s
->session
->ssl_version
) {
1208 al
= SSL_AD_PROTOCOL_VERSION
;
1210 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
,
1211 SSL_R_SSL_SESSION_VERSION_MISMATCH
);
1215 c
= ssl_get_cipher_by_char(s
, cipherchars
);
1217 /* unknown cipher */
1218 al
= SSL_AD_ILLEGAL_PARAMETER
;
1219 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_UNKNOWN_CIPHER_RETURNED
);
1223 * Now that we know the version, update the check to see if it's an allowed
1226 s
->s3
->tmp
.min_ver
= s
->version
;
1227 s
->s3
->tmp
.max_ver
= s
->version
;
1229 * If it is a disabled cipher we either didn't send it in client hello,
1230 * or it's not allowed for the selected protocol. So we return an error.
1232 if (ssl_cipher_disabled(s
, c
, SSL_SECOP_CIPHER_CHECK
)) {
1233 al
= SSL_AD_ILLEGAL_PARAMETER
;
1234 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_WRONG_CIPHER_RETURNED
);
1238 sk
= ssl_get_ciphers_by_id(s
);
1239 i
= sk_SSL_CIPHER_find(sk
, c
);
1241 /* we did not say we would use this cipher */
1242 al
= SSL_AD_ILLEGAL_PARAMETER
;
1243 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_WRONG_CIPHER_RETURNED
);
1248 * Depending on the session caching (internal/external), the cipher
1249 * and/or cipher_id values may not be set. Make sure that cipher_id is
1250 * set and use it for comparison.
1252 if (s
->session
->cipher
)
1253 s
->session
->cipher_id
= s
->session
->cipher
->id
;
1254 if (s
->hit
&& (s
->session
->cipher_id
!= c
->id
)) {
1255 al
= SSL_AD_ILLEGAL_PARAMETER
;
1256 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
,
1257 SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED
);
1260 s
->s3
->tmp
.new_cipher
= c
;
1261 /* lets get the compression algorithm */
1263 if (!PACKET_get_1(pkt
, &compression
)) {
1264 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_LENGTH_MISMATCH
);
1265 al
= SSL_AD_DECODE_ERROR
;
1268 #ifdef OPENSSL_NO_COMP
1269 if (compression
!= 0) {
1270 al
= SSL_AD_ILLEGAL_PARAMETER
;
1271 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
,
1272 SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM
);
1276 * If compression is disabled we'd better not try to resume a session
1277 * using compression.
1279 if (s
->session
->compress_meth
!= 0) {
1280 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_INCONSISTENT_COMPRESSION
);
1284 if (s
->hit
&& compression
!= s
->session
->compress_meth
) {
1285 al
= SSL_AD_ILLEGAL_PARAMETER
;
1286 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
,
1287 SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED
);
1290 if (compression
== 0)
1292 else if (!ssl_allow_compression(s
)) {
1293 al
= SSL_AD_ILLEGAL_PARAMETER
;
1294 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_COMPRESSION_DISABLED
);
1297 comp
= ssl3_comp_find(s
->ctx
->comp_methods
, compression
);
1300 if (compression
!= 0 && comp
== NULL
) {
1301 al
= SSL_AD_ILLEGAL_PARAMETER
;
1302 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
,
1303 SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM
);
1306 s
->s3
->tmp
.new_compression
= comp
;
1310 /* TLS extensions */
1311 if (!ssl_parse_serverhello_tlsext(s
, pkt
)) {
1312 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_PARSE_TLSEXT
);
1316 if (PACKET_remaining(pkt
) != 0) {
1317 /* wrong packet length */
1318 al
= SSL_AD_DECODE_ERROR
;
1319 SSLerr(SSL_F_TLS_PROCESS_SERVER_HELLO
, SSL_R_BAD_PACKET_LENGTH
);
1322 #ifndef OPENSSL_NO_SCTP
1323 if (SSL_IS_DTLS(s
) && s
->hit
) {
1324 unsigned char sctpauthkey
[64];
1325 char labelbuffer
[sizeof(DTLS1_SCTP_AUTH_LABEL
)];
1328 * Add new shared key for SCTP-Auth, will be ignored if
1331 memcpy(labelbuffer
, DTLS1_SCTP_AUTH_LABEL
,
1332 sizeof(DTLS1_SCTP_AUTH_LABEL
));
1334 if (SSL_export_keying_material(s
, sctpauthkey
,
1335 sizeof(sctpauthkey
),
1337 sizeof(labelbuffer
), NULL
, 0, 0) <= 0)
1340 BIO_ctrl(SSL_get_wbio(s
),
1341 BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY
,
1342 sizeof(sctpauthkey
), sctpauthkey
);
1346 return MSG_PROCESS_CONTINUE_READING
;
1348 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
1350 ossl_statem_set_error(s
);
1351 return MSG_PROCESS_ERROR
;
1354 MSG_PROCESS_RETURN
tls_process_server_certificate(SSL
*s
, PACKET
*pkt
)
1356 int al
, i
, ret
= MSG_PROCESS_ERROR
, exp_idx
;
1357 unsigned long cert_list_len
, cert_len
;
1359 const unsigned char *certstart
, *certbytes
;
1360 STACK_OF(X509
) *sk
= NULL
;
1361 EVP_PKEY
*pkey
= NULL
;
1363 if ((sk
= sk_X509_new_null()) == NULL
) {
1364 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
, ERR_R_MALLOC_FAILURE
);
1368 if (!PACKET_get_net_3(pkt
, &cert_list_len
)
1369 || PACKET_remaining(pkt
) != cert_list_len
) {
1370 al
= SSL_AD_DECODE_ERROR
;
1371 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
, SSL_R_LENGTH_MISMATCH
);
1374 while (PACKET_remaining(pkt
)) {
1375 if (!PACKET_get_net_3(pkt
, &cert_len
)
1376 || !PACKET_get_bytes(pkt
, &certbytes
, cert_len
)) {
1377 al
= SSL_AD_DECODE_ERROR
;
1378 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
,
1379 SSL_R_CERT_LENGTH_MISMATCH
);
1383 certstart
= certbytes
;
1384 x
= d2i_X509(NULL
, (const unsigned char **)&certbytes
, cert_len
);
1386 al
= SSL_AD_BAD_CERTIFICATE
;
1387 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
, ERR_R_ASN1_LIB
);
1390 if (certbytes
!= (certstart
+ cert_len
)) {
1391 al
= SSL_AD_DECODE_ERROR
;
1392 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
,
1393 SSL_R_CERT_LENGTH_MISMATCH
);
1396 if (!sk_X509_push(sk
, x
)) {
1397 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
, ERR_R_MALLOC_FAILURE
);
1403 i
= ssl_verify_cert_chain(s
, sk
);
1405 * The documented interface is that SSL_VERIFY_PEER should be set in order
1406 * for client side verification of the server certificate to take place.
1407 * However, historically the code has only checked that *any* flag is set
1408 * to cause server verification to take place. Use of the other flags makes
1409 * no sense in client mode. An attempt to clean up the semantics was
1410 * reverted because at least one application *only* set
1411 * SSL_VERIFY_FAIL_IF_NO_PEER_CERT. Prior to the clean up this still caused
1412 * server verification to take place, after the clean up it silently did
1413 * nothing. SSL_CTX_set_verify()/SSL_set_verify() cannot validate the flags
1414 * sent to them because they are void functions. Therefore, we now use the
1415 * (less clean) historic behaviour of performing validation if any flag is
1416 * set. The *documented* interface remains the same.
1418 if (s
->verify_mode
!= SSL_VERIFY_NONE
&& i
<= 0) {
1419 al
= ssl_verify_alarm_type(s
->verify_result
);
1420 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
,
1421 SSL_R_CERTIFICATE_VERIFY_FAILED
);
1424 ERR_clear_error(); /* but we keep s->verify_result */
1426 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
, i
);
1427 al
= SSL_AD_HANDSHAKE_FAILURE
;
1431 s
->session
->peer_chain
= sk
;
1433 * Inconsistency alert: cert_chain does include the peer's certificate,
1434 * which we don't include in statem_srvr.c
1436 x
= sk_X509_value(sk
, 0);
1439 * VRS 19990621: possible memory leak; sk=null ==> !sk_pop_free() @end
1442 pkey
= X509_get0_pubkey(x
);
1444 if (pkey
== NULL
|| EVP_PKEY_missing_parameters(pkey
)) {
1447 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
,
1448 SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS
);
1452 i
= ssl_cert_type(x
, pkey
);
1456 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
,
1457 SSL_R_UNKNOWN_CERTIFICATE_TYPE
);
1461 exp_idx
= ssl_cipher_get_cert_index(s
->s3
->tmp
.new_cipher
);
1462 if (exp_idx
>= 0 && i
!= exp_idx
1463 && (exp_idx
!= SSL_PKEY_GOST_EC
||
1464 (i
!= SSL_PKEY_GOST12_512
&& i
!= SSL_PKEY_GOST12_256
1465 && i
!= SSL_PKEY_GOST01
))) {
1467 al
= SSL_AD_ILLEGAL_PARAMETER
;
1468 SSLerr(SSL_F_TLS_PROCESS_SERVER_CERTIFICATE
,
1469 SSL_R_WRONG_CERTIFICATE_TYPE
);
1472 s
->session
->peer_type
= i
;
1474 X509_free(s
->session
->peer
);
1476 s
->session
->peer
= x
;
1477 s
->session
->verify_result
= s
->verify_result
;
1480 ret
= MSG_PROCESS_CONTINUE_READING
;
1484 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
1486 ossl_statem_set_error(s
);
1489 sk_X509_pop_free(sk
, X509_free
);
1493 static int tls_process_ske_psk_preamble(SSL
*s
, PACKET
*pkt
, int *al
)
1495 #ifndef OPENSSL_NO_PSK
1496 PACKET psk_identity_hint
;
1498 /* PSK ciphersuites are preceded by an identity hint */
1500 if (!PACKET_get_length_prefixed_2(pkt
, &psk_identity_hint
)) {
1501 *al
= SSL_AD_DECODE_ERROR
;
1502 SSLerr(SSL_F_TLS_PROCESS_SKE_PSK_PREAMBLE
, SSL_R_LENGTH_MISMATCH
);
1507 * Store PSK identity hint for later use, hint is used in
1508 * tls_construct_client_key_exchange. Assume that the maximum length of
1509 * a PSK identity hint can be as long as the maximum length of a PSK
1512 if (PACKET_remaining(&psk_identity_hint
) > PSK_MAX_IDENTITY_LEN
) {
1513 *al
= SSL_AD_HANDSHAKE_FAILURE
;
1514 SSLerr(SSL_F_TLS_PROCESS_SKE_PSK_PREAMBLE
, SSL_R_DATA_LENGTH_TOO_LONG
);
1518 if (PACKET_remaining(&psk_identity_hint
) == 0) {
1519 OPENSSL_free(s
->session
->psk_identity_hint
);
1520 s
->session
->psk_identity_hint
= NULL
;
1521 } else if (!PACKET_strndup(&psk_identity_hint
,
1522 &s
->session
->psk_identity_hint
)) {
1523 *al
= SSL_AD_INTERNAL_ERROR
;
1529 SSLerr(SSL_F_TLS_PROCESS_SKE_PSK_PREAMBLE
, ERR_R_INTERNAL_ERROR
);
1530 *al
= SSL_AD_INTERNAL_ERROR
;
1535 static int tls_process_ske_srp(SSL
*s
, PACKET
*pkt
, EVP_PKEY
**pkey
, int *al
)
1537 #ifndef OPENSSL_NO_SRP
1538 PACKET prime
, generator
, salt
, server_pub
;
1540 if (!PACKET_get_length_prefixed_2(pkt
, &prime
)
1541 || !PACKET_get_length_prefixed_2(pkt
, &generator
)
1542 || !PACKET_get_length_prefixed_1(pkt
, &salt
)
1543 || !PACKET_get_length_prefixed_2(pkt
, &server_pub
)) {
1544 *al
= SSL_AD_DECODE_ERROR
;
1545 SSLerr(SSL_F_TLS_PROCESS_SKE_SRP
, SSL_R_LENGTH_MISMATCH
);
1549 /* TODO(size_t): Convert BN_bin2bn() calls */
1551 BN_bin2bn(PACKET_data(&prime
),
1552 (int)PACKET_remaining(&prime
), NULL
)) == NULL
1554 BN_bin2bn(PACKET_data(&generator
),
1555 (int)PACKET_remaining(&generator
), NULL
)) == NULL
1557 BN_bin2bn(PACKET_data(&salt
),
1558 (int)PACKET_remaining(&salt
), NULL
)) == NULL
1560 BN_bin2bn(PACKET_data(&server_pub
),
1561 (int)PACKET_remaining(&server_pub
), NULL
)) == NULL
) {
1562 *al
= SSL_AD_INTERNAL_ERROR
;
1563 SSLerr(SSL_F_TLS_PROCESS_SKE_SRP
, ERR_R_BN_LIB
);
1567 if (!srp_verify_server_param(s
, al
)) {
1568 *al
= SSL_AD_DECODE_ERROR
;
1569 SSLerr(SSL_F_TLS_PROCESS_SKE_SRP
, SSL_R_BAD_SRP_PARAMETERS
);
1573 /* We must check if there is a certificate */
1574 if (s
->s3
->tmp
.new_cipher
->algorithm_auth
& (SSL_aRSA
| SSL_aDSS
))
1575 *pkey
= X509_get0_pubkey(s
->session
->peer
);
1579 SSLerr(SSL_F_TLS_PROCESS_SKE_SRP
, ERR_R_INTERNAL_ERROR
);
1580 *al
= SSL_AD_INTERNAL_ERROR
;
1585 static int tls_process_ske_dhe(SSL
*s
, PACKET
*pkt
, EVP_PKEY
**pkey
, int *al
)
1587 #ifndef OPENSSL_NO_DH
1588 PACKET prime
, generator
, pub_key
;
1589 EVP_PKEY
*peer_tmp
= NULL
;
1592 BIGNUM
*p
= NULL
, *g
= NULL
, *bnpub_key
= NULL
;
1594 if (!PACKET_get_length_prefixed_2(pkt
, &prime
)
1595 || !PACKET_get_length_prefixed_2(pkt
, &generator
)
1596 || !PACKET_get_length_prefixed_2(pkt
, &pub_key
)) {
1597 *al
= SSL_AD_DECODE_ERROR
;
1598 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, SSL_R_LENGTH_MISMATCH
);
1602 peer_tmp
= EVP_PKEY_new();
1605 if (peer_tmp
== NULL
|| dh
== NULL
) {
1606 *al
= SSL_AD_INTERNAL_ERROR
;
1607 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, ERR_R_MALLOC_FAILURE
);
1611 /* TODO(size_t): Convert these calls */
1612 p
= BN_bin2bn(PACKET_data(&prime
), (int)PACKET_remaining(&prime
), NULL
);
1613 g
= BN_bin2bn(PACKET_data(&generator
), (int)PACKET_remaining(&generator
),
1615 bnpub_key
= BN_bin2bn(PACKET_data(&pub_key
),
1616 (int)PACKET_remaining(&pub_key
), NULL
);
1617 if (p
== NULL
|| g
== NULL
|| bnpub_key
== NULL
) {
1618 *al
= SSL_AD_INTERNAL_ERROR
;
1619 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, ERR_R_BN_LIB
);
1623 if (BN_is_zero(p
) || BN_is_zero(g
) || BN_is_zero(bnpub_key
)) {
1624 *al
= SSL_AD_DECODE_ERROR
;
1625 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, SSL_R_BAD_DH_VALUE
);
1629 if (!DH_set0_pqg(dh
, p
, NULL
, g
)) {
1630 *al
= SSL_AD_INTERNAL_ERROR
;
1631 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, ERR_R_BN_LIB
);
1636 if (!DH_set0_key(dh
, bnpub_key
, NULL
)) {
1637 *al
= SSL_AD_INTERNAL_ERROR
;
1638 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, ERR_R_BN_LIB
);
1643 if (!ssl_security(s
, SSL_SECOP_TMP_DH
, DH_security_bits(dh
), 0, dh
)) {
1644 *al
= SSL_AD_HANDSHAKE_FAILURE
;
1645 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, SSL_R_DH_KEY_TOO_SMALL
);
1649 if (EVP_PKEY_assign_DH(peer_tmp
, dh
) == 0) {
1650 *al
= SSL_AD_INTERNAL_ERROR
;
1651 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, ERR_R_EVP_LIB
);
1655 s
->s3
->peer_tmp
= peer_tmp
;
1658 * FIXME: This makes assumptions about which ciphersuites come with
1659 * public keys. We should have a less ad-hoc way of doing this
1661 if (s
->s3
->tmp
.new_cipher
->algorithm_auth
& (SSL_aRSA
| SSL_aDSS
))
1662 *pkey
= X509_get0_pubkey(s
->session
->peer
);
1663 /* else anonymous DH, so no certificate or pkey. */
1672 EVP_PKEY_free(peer_tmp
);
1676 SSLerr(SSL_F_TLS_PROCESS_SKE_DHE
, ERR_R_INTERNAL_ERROR
);
1677 *al
= SSL_AD_INTERNAL_ERROR
;
1682 static int tls_process_ske_ecdhe(SSL
*s
, PACKET
*pkt
, EVP_PKEY
**pkey
, int *al
)
1684 #ifndef OPENSSL_NO_EC
1686 const unsigned char *ecparams
;
1688 unsigned int curve_flags
;
1689 EVP_PKEY_CTX
*pctx
= NULL
;
1692 * Extract elliptic curve parameters and the server's ephemeral ECDH
1693 * public key. For now we only support named (not generic) curves and
1694 * ECParameters in this case is just three bytes.
1696 if (!PACKET_get_bytes(pkt
, &ecparams
, 3)) {
1697 *al
= SSL_AD_DECODE_ERROR
;
1698 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, SSL_R_LENGTH_TOO_SHORT
);
1702 * Check curve is one of our preferences, if not server has sent an
1703 * invalid curve. ECParameters is 3 bytes.
1705 if (!tls1_check_curve(s
, ecparams
, 3)) {
1706 *al
= SSL_AD_DECODE_ERROR
;
1707 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, SSL_R_WRONG_CURVE
);
1711 curve_nid
= tls1_ec_curve_id2nid(*(ecparams
+ 2), &curve_flags
);
1713 if (curve_nid
== 0) {
1714 *al
= SSL_AD_INTERNAL_ERROR
;
1715 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
,
1716 SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS
);
1720 if ((curve_flags
& TLS_CURVE_TYPE
) == TLS_CURVE_CUSTOM
) {
1721 EVP_PKEY
*key
= EVP_PKEY_new();
1723 if (key
== NULL
|| !EVP_PKEY_set_type(key
, curve_nid
)) {
1724 *al
= SSL_AD_INTERNAL_ERROR
;
1725 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, ERR_R_EVP_LIB
);
1729 s
->s3
->peer_tmp
= key
;
1731 /* Set up EVP_PKEY with named curve as parameters */
1732 pctx
= EVP_PKEY_CTX_new_id(EVP_PKEY_EC
, NULL
);
1734 || EVP_PKEY_paramgen_init(pctx
) <= 0
1735 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx
, curve_nid
) <= 0
1736 || EVP_PKEY_paramgen(pctx
, &s
->s3
->peer_tmp
) <= 0) {
1737 *al
= SSL_AD_INTERNAL_ERROR
;
1738 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, ERR_R_EVP_LIB
);
1739 EVP_PKEY_CTX_free(pctx
);
1742 EVP_PKEY_CTX_free(pctx
);
1746 if (!PACKET_get_length_prefixed_1(pkt
, &encoded_pt
)) {
1747 *al
= SSL_AD_DECODE_ERROR
;
1748 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, SSL_R_LENGTH_MISMATCH
);
1752 if (!EVP_PKEY_set1_tls_encodedpoint(s
->s3
->peer_tmp
,
1753 PACKET_data(&encoded_pt
),
1754 PACKET_remaining(&encoded_pt
))) {
1755 *al
= SSL_AD_DECODE_ERROR
;
1756 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, SSL_R_BAD_ECPOINT
);
1761 * The ECC/TLS specification does not mention the use of DSA to sign
1762 * ECParameters in the server key exchange message. We do support RSA
1765 if (s
->s3
->tmp
.new_cipher
->algorithm_auth
& SSL_aECDSA
)
1766 *pkey
= X509_get0_pubkey(s
->session
->peer
);
1767 else if (s
->s3
->tmp
.new_cipher
->algorithm_auth
& SSL_aRSA
)
1768 *pkey
= X509_get0_pubkey(s
->session
->peer
);
1769 /* else anonymous ECDH, so no certificate or pkey. */
1773 SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE
, ERR_R_INTERNAL_ERROR
);
1774 *al
= SSL_AD_INTERNAL_ERROR
;
1779 MSG_PROCESS_RETURN
tls_process_key_exchange(SSL
*s
, PACKET
*pkt
)
1783 EVP_PKEY
*pkey
= NULL
;
1784 PACKET save_param_start
, signature
;
1786 alg_k
= s
->s3
->tmp
.new_cipher
->algorithm_mkey
;
1788 save_param_start
= *pkt
;
1790 #if !defined(OPENSSL_NO_EC) || !defined(OPENSSL_NO_DH)
1791 EVP_PKEY_free(s
->s3
->peer_tmp
);
1792 s
->s3
->peer_tmp
= NULL
;
1795 if (alg_k
& SSL_PSK
) {
1796 if (!tls_process_ske_psk_preamble(s
, pkt
, &al
))
1800 /* Nothing else to do for plain PSK or RSAPSK */
1801 if (alg_k
& (SSL_kPSK
| SSL_kRSAPSK
)) {
1802 } else if (alg_k
& SSL_kSRP
) {
1803 if (!tls_process_ske_srp(s
, pkt
, &pkey
, &al
))
1805 } else if (alg_k
& (SSL_kDHE
| SSL_kDHEPSK
)) {
1806 if (!tls_process_ske_dhe(s
, pkt
, &pkey
, &al
))
1808 } else if (alg_k
& (SSL_kECDHE
| SSL_kECDHEPSK
)) {
1809 if (!tls_process_ske_ecdhe(s
, pkt
, &pkey
, &al
))
1812 al
= SSL_AD_UNEXPECTED_MESSAGE
;
1813 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, SSL_R_UNEXPECTED_MESSAGE
);
1817 /* if it was signed, check the signature */
1821 const EVP_MD
*md
= NULL
;
1825 * |pkt| now points to the beginning of the signature, so the difference
1826 * equals the length of the parameters.
1828 if (!PACKET_get_sub_packet(&save_param_start
, ¶ms
,
1829 PACKET_remaining(&save_param_start
) -
1830 PACKET_remaining(pkt
))) {
1831 al
= SSL_AD_INTERNAL_ERROR
;
1832 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, ERR_R_INTERNAL_ERROR
);
1836 if (SSL_USE_SIGALGS(s
)) {
1837 const unsigned char *sigalgs
;
1839 if (!PACKET_get_bytes(pkt
, &sigalgs
, 2)) {
1840 al
= SSL_AD_DECODE_ERROR
;
1841 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, SSL_R_LENGTH_TOO_SHORT
);
1844 rv
= tls12_check_peer_sigalg(&md
, s
, sigalgs
, pkey
);
1846 al
= SSL_AD_INTERNAL_ERROR
;
1848 } else if (rv
== 0) {
1849 al
= SSL_AD_DECODE_ERROR
;
1853 fprintf(stderr
, "USING TLSv1.2 HASH %s\n", EVP_MD_name(md
));
1855 } else if (EVP_PKEY_id(pkey
) == EVP_PKEY_RSA
) {
1856 md
= EVP_md5_sha1();
1861 if (!PACKET_get_length_prefixed_2(pkt
, &signature
)
1862 || PACKET_remaining(pkt
) != 0) {
1863 al
= SSL_AD_DECODE_ERROR
;
1864 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, SSL_R_LENGTH_MISMATCH
);
1867 maxsig
= EVP_PKEY_size(pkey
);
1869 al
= SSL_AD_INTERNAL_ERROR
;
1870 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, ERR_R_INTERNAL_ERROR
);
1875 * Check signature length
1877 if (PACKET_remaining(&signature
) > (size_t)maxsig
) {
1878 /* wrong packet length */
1879 al
= SSL_AD_DECODE_ERROR
;
1880 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
,
1881 SSL_R_WRONG_SIGNATURE_LENGTH
);
1885 md_ctx
= EVP_MD_CTX_new();
1886 if (md_ctx
== NULL
) {
1887 al
= SSL_AD_INTERNAL_ERROR
;
1888 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, ERR_R_MALLOC_FAILURE
);
1892 if (EVP_VerifyInit_ex(md_ctx
, md
, NULL
) <= 0
1893 || EVP_VerifyUpdate(md_ctx
, &(s
->s3
->client_random
[0]),
1894 SSL3_RANDOM_SIZE
) <= 0
1895 || EVP_VerifyUpdate(md_ctx
, &(s
->s3
->server_random
[0]),
1896 SSL3_RANDOM_SIZE
) <= 0
1897 || EVP_VerifyUpdate(md_ctx
, PACKET_data(¶ms
),
1898 PACKET_remaining(¶ms
)) <= 0) {
1899 EVP_MD_CTX_free(md_ctx
);
1900 al
= SSL_AD_INTERNAL_ERROR
;
1901 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, ERR_R_EVP_LIB
);
1904 /* TODO(size_t): Convert this call */
1905 if (EVP_VerifyFinal(md_ctx
, PACKET_data(&signature
),
1906 (unsigned int)PACKET_remaining(&signature
),
1909 EVP_MD_CTX_free(md_ctx
);
1910 al
= SSL_AD_DECRYPT_ERROR
;
1911 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, SSL_R_BAD_SIGNATURE
);
1914 EVP_MD_CTX_free(md_ctx
);
1916 /* aNULL, aSRP or PSK do not need public keys */
1917 if (!(s
->s3
->tmp
.new_cipher
->algorithm_auth
& (SSL_aNULL
| SSL_aSRP
))
1918 && !(alg_k
& SSL_PSK
)) {
1919 /* Might be wrong key type, check it */
1920 if (ssl3_check_cert_and_algorithm(s
)) {
1921 /* Otherwise this shouldn't happen */
1922 al
= SSL_AD_INTERNAL_ERROR
;
1923 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, ERR_R_INTERNAL_ERROR
);
1925 al
= SSL_AD_DECODE_ERROR
;
1929 /* still data left over */
1930 if (PACKET_remaining(pkt
) != 0) {
1931 al
= SSL_AD_DECODE_ERROR
;
1932 SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE
, SSL_R_EXTRA_DATA_IN_MESSAGE
);
1937 return MSG_PROCESS_CONTINUE_READING
;
1940 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
1941 ossl_statem_set_error(s
);
1942 return MSG_PROCESS_ERROR
;
1945 MSG_PROCESS_RETURN
tls_process_certificate_request(SSL
*s
, PACKET
*pkt
)
1947 int ret
= MSG_PROCESS_ERROR
;
1948 unsigned int list_len
, ctype_num
, i
, name_len
;
1949 X509_NAME
*xn
= NULL
;
1950 const unsigned char *data
;
1951 const unsigned char *namestart
, *namebytes
;
1952 STACK_OF(X509_NAME
) *ca_sk
= NULL
;
1954 if ((ca_sk
= sk_X509_NAME_new(ca_dn_cmp
)) == NULL
) {
1955 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, ERR_R_MALLOC_FAILURE
);
1959 /* get the certificate types */
1960 if (!PACKET_get_1(pkt
, &ctype_num
)
1961 || !PACKET_get_bytes(pkt
, &data
, ctype_num
)) {
1962 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
1963 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, SSL_R_LENGTH_MISMATCH
);
1966 OPENSSL_free(s
->cert
->ctypes
);
1967 s
->cert
->ctypes
= NULL
;
1968 if (ctype_num
> SSL3_CT_NUMBER
) {
1969 /* If we exceed static buffer copy all to cert structure */
1970 s
->cert
->ctypes
= OPENSSL_malloc(ctype_num
);
1971 if (s
->cert
->ctypes
== NULL
) {
1972 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, ERR_R_MALLOC_FAILURE
);
1975 memcpy(s
->cert
->ctypes
, data
, ctype_num
);
1976 s
->cert
->ctype_num
= ctype_num
;
1977 ctype_num
= SSL3_CT_NUMBER
;
1979 for (i
= 0; i
< ctype_num
; i
++)
1980 s
->s3
->tmp
.ctype
[i
] = data
[i
];
1982 if (SSL_USE_SIGALGS(s
)) {
1983 if (!PACKET_get_net_2(pkt
, &list_len
)
1984 || !PACKET_get_bytes(pkt
, &data
, list_len
)) {
1985 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
1986 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
,
1987 SSL_R_LENGTH_MISMATCH
);
1991 /* Clear certificate digests and validity flags */
1992 for (i
= 0; i
< SSL_PKEY_NUM
; i
++) {
1993 s
->s3
->tmp
.md
[i
] = NULL
;
1994 s
->s3
->tmp
.valid_flags
[i
] = 0;
1996 if ((list_len
& 1) || !tls1_save_sigalgs(s
, data
, list_len
)) {
1997 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
1998 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
,
1999 SSL_R_SIGNATURE_ALGORITHMS_ERROR
);
2002 if (!tls1_process_sigalgs(s
)) {
2003 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2004 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, ERR_R_MALLOC_FAILURE
);
2008 ssl_set_default_md(s
);
2011 /* get the CA RDNs */
2012 if (!PACKET_get_net_2(pkt
, &list_len
)
2013 || PACKET_remaining(pkt
) != list_len
) {
2014 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
2015 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, SSL_R_LENGTH_MISMATCH
);
2019 while (PACKET_remaining(pkt
)) {
2020 if (!PACKET_get_net_2(pkt
, &name_len
)
2021 || !PACKET_get_bytes(pkt
, &namebytes
, name_len
)) {
2022 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
2023 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
,
2024 SSL_R_LENGTH_MISMATCH
);
2028 namestart
= namebytes
;
2030 if ((xn
= d2i_X509_NAME(NULL
, (const unsigned char **)&namebytes
,
2031 name_len
)) == NULL
) {
2032 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
2033 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, ERR_R_ASN1_LIB
);
2037 if (namebytes
!= (namestart
+ name_len
)) {
2038 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
2039 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
,
2040 SSL_R_CA_DN_LENGTH_MISMATCH
);
2043 if (!sk_X509_NAME_push(ca_sk
, xn
)) {
2044 SSLerr(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST
, ERR_R_MALLOC_FAILURE
);
2050 /* we should setup a certificate to return.... */
2051 s
->s3
->tmp
.cert_req
= 1;
2052 s
->s3
->tmp
.ctype_num
= ctype_num
;
2053 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
, X509_NAME_free
);
2054 s
->s3
->tmp
.ca_names
= ca_sk
;
2057 ret
= MSG_PROCESS_CONTINUE_PROCESSING
;
2060 ossl_statem_set_error(s
);
2063 sk_X509_NAME_pop_free(ca_sk
, X509_NAME_free
);
2067 static int ca_dn_cmp(const X509_NAME
*const *a
, const X509_NAME
*const *b
)
2069 return (X509_NAME_cmp(*a
, *b
));
2072 MSG_PROCESS_RETURN
tls_process_new_session_ticket(SSL
*s
, PACKET
*pkt
)
2075 unsigned int ticklen
;
2076 unsigned long ticket_lifetime_hint
;
2077 unsigned int sess_len
;
2079 if (!PACKET_get_net_4(pkt
, &ticket_lifetime_hint
)
2080 || !PACKET_get_net_2(pkt
, &ticklen
)
2081 || PACKET_remaining(pkt
) != ticklen
) {
2082 al
= SSL_AD_DECODE_ERROR
;
2083 SSLerr(SSL_F_TLS_PROCESS_NEW_SESSION_TICKET
, SSL_R_LENGTH_MISMATCH
);
2087 /* Server is allowed to change its mind and send an empty ticket. */
2089 return MSG_PROCESS_CONTINUE_READING
;
2091 if (s
->session
->session_id_length
> 0) {
2092 int i
= s
->session_ctx
->session_cache_mode
;
2093 SSL_SESSION
*new_sess
;
2095 * We reused an existing session, so we need to replace it with a new
2098 if (i
& SSL_SESS_CACHE_CLIENT
) {
2100 * Remove the old session from the cache. We carry on if this fails
2102 SSL_CTX_remove_session(s
->session_ctx
, s
->session
);
2105 if ((new_sess
= ssl_session_dup(s
->session
, 0)) == 0) {
2106 al
= SSL_AD_INTERNAL_ERROR
;
2107 SSLerr(SSL_F_TLS_PROCESS_NEW_SESSION_TICKET
, ERR_R_MALLOC_FAILURE
);
2111 SSL_SESSION_free(s
->session
);
2112 s
->session
= new_sess
;
2115 OPENSSL_free(s
->session
->tlsext_tick
);
2116 s
->session
->tlsext_ticklen
= 0;
2118 s
->session
->tlsext_tick
= OPENSSL_malloc(ticklen
);
2119 if (s
->session
->tlsext_tick
== NULL
) {
2120 SSLerr(SSL_F_TLS_PROCESS_NEW_SESSION_TICKET
, ERR_R_MALLOC_FAILURE
);
2123 if (!PACKET_copy_bytes(pkt
, s
->session
->tlsext_tick
, ticklen
)) {
2124 al
= SSL_AD_DECODE_ERROR
;
2125 SSLerr(SSL_F_TLS_PROCESS_NEW_SESSION_TICKET
, SSL_R_LENGTH_MISMATCH
);
2129 s
->session
->tlsext_tick_lifetime_hint
= ticket_lifetime_hint
;
2130 s
->session
->tlsext_ticklen
= ticklen
;
2132 * There are two ways to detect a resumed ticket session. One is to set
2133 * an appropriate session ID and then the server must return a match in
2134 * ServerHello. This allows the normal client session ID matching to work
2135 * and we know much earlier that the ticket has been accepted. The
2136 * other way is to set zero length session ID when the ticket is
2137 * presented and rely on the handshake to determine session resumption.
2138 * We choose the former approach because this fits in with assumptions
2139 * elsewhere in OpenSSL. The session ID is set to the SHA256 (or SHA1 is
2140 * SHA256 is disabled) hash of the ticket.
2143 * TODO(size_t): we use sess_len here because EVP_Digest expects an int
2144 * but s->session->session_id_length is a size_t
2146 if (!EVP_Digest(s
->session
->tlsext_tick
, ticklen
,
2147 s
->session
->session_id
, &sess_len
,
2148 EVP_sha256(), NULL
)) {
2149 SSLerr(SSL_F_TLS_PROCESS_NEW_SESSION_TICKET
, ERR_R_EVP_LIB
);
2152 s
->session
->session_id_length
= sess_len
;
2153 return MSG_PROCESS_CONTINUE_READING
;
2155 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
2157 ossl_statem_set_error(s
);
2158 return MSG_PROCESS_ERROR
;
2161 MSG_PROCESS_RETURN
tls_process_cert_status(SSL
*s
, PACKET
*pkt
)
2167 if (!PACKET_get_1(pkt
, &type
)
2168 || type
!= TLSEXT_STATUSTYPE_ocsp
) {
2169 al
= SSL_AD_DECODE_ERROR
;
2170 SSLerr(SSL_F_TLS_PROCESS_CERT_STATUS
, SSL_R_UNSUPPORTED_STATUS_TYPE
);
2173 if (!PACKET_get_net_3_len(pkt
, &resplen
)
2174 || PACKET_remaining(pkt
) != resplen
) {
2175 al
= SSL_AD_DECODE_ERROR
;
2176 SSLerr(SSL_F_TLS_PROCESS_CERT_STATUS
, SSL_R_LENGTH_MISMATCH
);
2179 s
->tlsext_ocsp_resp
= OPENSSL_malloc(resplen
);
2180 if (s
->tlsext_ocsp_resp
== NULL
) {
2181 al
= SSL_AD_INTERNAL_ERROR
;
2182 SSLerr(SSL_F_TLS_PROCESS_CERT_STATUS
, ERR_R_MALLOC_FAILURE
);
2185 if (!PACKET_copy_bytes(pkt
, s
->tlsext_ocsp_resp
, resplen
)) {
2186 al
= SSL_AD_DECODE_ERROR
;
2187 SSLerr(SSL_F_TLS_PROCESS_CERT_STATUS
, SSL_R_LENGTH_MISMATCH
);
2190 s
->tlsext_ocsp_resplen
= resplen
;
2191 return MSG_PROCESS_CONTINUE_READING
;
2193 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
2194 ossl_statem_set_error(s
);
2195 return MSG_PROCESS_ERROR
;
2198 MSG_PROCESS_RETURN
tls_process_server_done(SSL
*s
, PACKET
*pkt
)
2200 if (PACKET_remaining(pkt
) > 0) {
2201 /* should contain no data */
2202 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_DECODE_ERROR
);
2203 SSLerr(SSL_F_TLS_PROCESS_SERVER_DONE
, SSL_R_LENGTH_MISMATCH
);
2204 ossl_statem_set_error(s
);
2205 return MSG_PROCESS_ERROR
;
2207 #ifndef OPENSSL_NO_SRP
2208 if (s
->s3
->tmp
.new_cipher
->algorithm_mkey
& SSL_kSRP
) {
2209 if (SRP_Calc_A_param(s
) <= 0) {
2210 SSLerr(SSL_F_TLS_PROCESS_SERVER_DONE
, SSL_R_SRP_A_CALC
);
2211 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2212 ossl_statem_set_error(s
);
2213 return MSG_PROCESS_ERROR
;
2219 * at this point we check that we have the required stuff from
2222 if (!ssl3_check_cert_and_algorithm(s
)) {
2223 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_HANDSHAKE_FAILURE
);
2224 ossl_statem_set_error(s
);
2225 return MSG_PROCESS_ERROR
;
2229 * Call the ocsp status callback if needed. The |tlsext_ocsp_resp| and
2230 * |tlsext_ocsp_resplen| values will be set if we actually received a status
2231 * message, or NULL and -1 otherwise
2233 if (s
->tlsext_status_type
!= -1 && s
->ctx
->tlsext_status_cb
!= NULL
) {
2235 ret
= s
->ctx
->tlsext_status_cb(s
, s
->ctx
->tlsext_status_arg
);
2237 ssl3_send_alert(s
, SSL3_AL_FATAL
,
2238 SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE
);
2239 SSLerr(SSL_F_TLS_PROCESS_SERVER_DONE
,
2240 SSL_R_INVALID_STATUS_RESPONSE
);
2241 return MSG_PROCESS_ERROR
;
2244 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2245 SSLerr(SSL_F_TLS_PROCESS_SERVER_DONE
, ERR_R_MALLOC_FAILURE
);
2246 return MSG_PROCESS_ERROR
;
2249 #ifndef OPENSSL_NO_CT
2250 if (s
->ct_validation_callback
!= NULL
) {
2251 /* Note we validate the SCTs whether or not we abort on error */
2252 if (!ssl_validate_ct(s
) && (s
->verify_mode
& SSL_VERIFY_PEER
)) {
2253 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_HANDSHAKE_FAILURE
);
2254 return MSG_PROCESS_ERROR
;
2259 #ifndef OPENSSL_NO_SCTP
2260 /* Only applies to renegotiation */
2261 if (SSL_IS_DTLS(s
) && BIO_dgram_is_sctp(SSL_get_wbio(s
))
2262 && s
->renegotiate
!= 0)
2263 return MSG_PROCESS_CONTINUE_PROCESSING
;
2266 return MSG_PROCESS_FINISHED_READING
;
2269 static int tls_construct_cke_psk_preamble(SSL
*s
, WPACKET
*pkt
, int *al
)
2271 #ifndef OPENSSL_NO_PSK
2274 * The callback needs PSK_MAX_IDENTITY_LEN + 1 bytes to return a
2275 * \0-terminated identity. The last byte is for us for simulating
2278 char identity
[PSK_MAX_IDENTITY_LEN
+ 1];
2279 size_t identitylen
= 0;
2280 unsigned char psk
[PSK_MAX_PSK_LEN
];
2281 unsigned char *tmppsk
= NULL
;
2282 char *tmpidentity
= NULL
;
2285 if (s
->psk_client_callback
== NULL
) {
2286 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
, SSL_R_PSK_NO_CLIENT_CB
);
2287 *al
= SSL_AD_INTERNAL_ERROR
;
2291 memset(identity
, 0, sizeof(identity
));
2293 psklen
= s
->psk_client_callback(s
, s
->session
->psk_identity_hint
,
2294 identity
, sizeof(identity
) - 1,
2297 if (psklen
> PSK_MAX_PSK_LEN
) {
2298 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
, ERR_R_INTERNAL_ERROR
);
2299 *al
= SSL_AD_HANDSHAKE_FAILURE
;
2301 } else if (psklen
== 0) {
2302 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
,
2303 SSL_R_PSK_IDENTITY_NOT_FOUND
);
2304 *al
= SSL_AD_HANDSHAKE_FAILURE
;
2308 identitylen
= strlen(identity
);
2309 if (identitylen
> PSK_MAX_IDENTITY_LEN
) {
2310 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
, ERR_R_INTERNAL_ERROR
);
2311 *al
= SSL_AD_HANDSHAKE_FAILURE
;
2315 tmppsk
= OPENSSL_memdup(psk
, psklen
);
2316 tmpidentity
= OPENSSL_strdup(identity
);
2317 if (tmppsk
== NULL
|| tmpidentity
== NULL
) {
2318 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
, ERR_R_MALLOC_FAILURE
);
2319 *al
= SSL_AD_INTERNAL_ERROR
;
2323 OPENSSL_free(s
->s3
->tmp
.psk
);
2324 s
->s3
->tmp
.psk
= tmppsk
;
2325 s
->s3
->tmp
.psklen
= psklen
;
2327 OPENSSL_free(s
->session
->psk_identity
);
2328 s
->session
->psk_identity
= tmpidentity
;
2331 if (!WPACKET_sub_memcpy_u16(pkt
, identity
, identitylen
)) {
2332 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
, ERR_R_INTERNAL_ERROR
);
2333 *al
= SSL_AD_INTERNAL_ERROR
;
2340 OPENSSL_cleanse(psk
, psklen
);
2341 OPENSSL_cleanse(identity
, sizeof(identity
));
2342 OPENSSL_clear_free(tmppsk
, psklen
);
2343 OPENSSL_clear_free(tmpidentity
, identitylen
);
2347 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE
, ERR_R_INTERNAL_ERROR
);
2348 *al
= SSL_AD_INTERNAL_ERROR
;
2353 static int tls_construct_cke_rsa(SSL
*s
, WPACKET
*pkt
, int *al
)
2355 #ifndef OPENSSL_NO_RSA
2356 unsigned char *encdata
= NULL
;
2357 EVP_PKEY
*pkey
= NULL
;
2358 EVP_PKEY_CTX
*pctx
= NULL
;
2360 unsigned char *pms
= NULL
;
2363 if (s
->session
->peer
== NULL
) {
2365 * We should always have a server certificate with SSL_kRSA.
2367 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_INTERNAL_ERROR
);
2371 pkey
= X509_get0_pubkey(s
->session
->peer
);
2372 if (EVP_PKEY_get0_RSA(pkey
) == NULL
) {
2373 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_INTERNAL_ERROR
);
2377 pmslen
= SSL_MAX_MASTER_KEY_LENGTH
;
2378 pms
= OPENSSL_malloc(pmslen
);
2380 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_MALLOC_FAILURE
);
2381 *al
= SSL_AD_INTERNAL_ERROR
;
2385 pms
[0] = s
->client_version
>> 8;
2386 pms
[1] = s
->client_version
& 0xff;
2387 /* TODO(size_t): Convert this function */
2388 if (RAND_bytes(pms
+ 2, (int)(pmslen
- 2)) <= 0) {
2392 /* Fix buf for TLS and beyond */
2393 if (s
->version
> SSL3_VERSION
&& !WPACKET_start_sub_packet_u16(pkt
)) {
2394 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_INTERNAL_ERROR
);
2397 pctx
= EVP_PKEY_CTX_new(pkey
, NULL
);
2398 if (pctx
== NULL
|| EVP_PKEY_encrypt_init(pctx
) <= 0
2399 || EVP_PKEY_encrypt(pctx
, NULL
, &enclen
, pms
, pmslen
) <= 0) {
2400 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_EVP_LIB
);
2403 if (!WPACKET_allocate_bytes(pkt
, enclen
, &encdata
)
2404 || EVP_PKEY_encrypt(pctx
, encdata
, &enclen
, pms
, pmslen
) <= 0) {
2405 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, SSL_R_BAD_RSA_ENCRYPT
);
2408 EVP_PKEY_CTX_free(pctx
);
2411 if (s
->options
& SSL_OP_PKCS1_CHECK_1
)
2413 if (s
->options
& SSL_OP_PKCS1_CHECK_2
)
2417 /* Fix buf for TLS and beyond */
2418 if (s
->version
> SSL3_VERSION
&& !WPACKET_close(pkt
)) {
2419 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_INTERNAL_ERROR
);
2423 s
->s3
->tmp
.pms
= pms
;
2424 s
->s3
->tmp
.pmslen
= pmslen
;
2428 OPENSSL_clear_free(pms
, pmslen
);
2429 EVP_PKEY_CTX_free(pctx
);
2433 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA
, ERR_R_INTERNAL_ERROR
);
2434 *al
= SSL_AD_INTERNAL_ERROR
;
2439 static int tls_construct_cke_dhe(SSL
*s
, WPACKET
*pkt
, int *al
)
2441 #ifndef OPENSSL_NO_DH
2443 const BIGNUM
*pub_key
;
2444 EVP_PKEY
*ckey
= NULL
, *skey
= NULL
;
2445 unsigned char *keybytes
= NULL
;
2447 skey
= s
->s3
->peer_tmp
;
2451 ckey
= ssl_generate_pkey(skey
);
2452 dh_clnt
= EVP_PKEY_get0_DH(ckey
);
2454 if (dh_clnt
== NULL
|| ssl_derive(s
, ckey
, skey
, 0) == 0)
2457 /* send off the data */
2458 DH_get0_key(dh_clnt
, &pub_key
, NULL
);
2459 if (!WPACKET_sub_allocate_bytes_u16(pkt
, BN_num_bytes(pub_key
), &keybytes
))
2462 BN_bn2bin(pub_key
, keybytes
);
2463 EVP_PKEY_free(ckey
);
2467 EVP_PKEY_free(ckey
);
2469 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_DHE
, ERR_R_INTERNAL_ERROR
);
2470 *al
= SSL_AD_INTERNAL_ERROR
;
2474 static int tls_construct_cke_ecdhe(SSL
*s
, WPACKET
*pkt
, int *al
)
2476 #ifndef OPENSSL_NO_EC
2477 unsigned char *encodedPoint
= NULL
;
2478 size_t encoded_pt_len
= 0;
2479 EVP_PKEY
*ckey
= NULL
, *skey
= NULL
;
2482 skey
= s
->s3
->peer_tmp
;
2484 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_ECDHE
, ERR_R_INTERNAL_ERROR
);
2488 ckey
= ssl_generate_pkey(skey
);
2490 if (ssl_derive(s
, ckey
, skey
, 0) == 0) {
2491 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_ECDHE
, ERR_R_EVP_LIB
);
2495 /* Generate encoding of client key */
2496 encoded_pt_len
= EVP_PKEY_get1_tls_encodedpoint(ckey
, &encodedPoint
);
2498 if (encoded_pt_len
== 0) {
2499 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_ECDHE
, ERR_R_EC_LIB
);
2503 if (!WPACKET_sub_memcpy_u8(pkt
, encodedPoint
, encoded_pt_len
)) {
2504 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_ECDHE
, ERR_R_INTERNAL_ERROR
);
2510 OPENSSL_free(encodedPoint
);
2511 EVP_PKEY_free(ckey
);
2514 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_ECDHE
, ERR_R_INTERNAL_ERROR
);
2515 *al
= SSL_AD_INTERNAL_ERROR
;
2520 static int tls_construct_cke_gost(SSL
*s
, WPACKET
*pkt
, int *al
)
2522 #ifndef OPENSSL_NO_GOST
2523 /* GOST key exchange message creation */
2524 EVP_PKEY_CTX
*pkey_ctx
= NULL
;
2527 unsigned int md_len
;
2528 unsigned char shared_ukm
[32], tmp
[256];
2529 EVP_MD_CTX
*ukm_hash
= NULL
;
2530 int dgst_nid
= NID_id_GostR3411_94
;
2531 unsigned char *pms
= NULL
;
2534 if ((s
->s3
->tmp
.new_cipher
->algorithm_auth
& SSL_aGOST12
) != 0)
2535 dgst_nid
= NID_id_GostR3411_2012_256
;
2538 * Get server sertificate PKEY and create ctx from it
2540 peer_cert
= s
->session
->peer
;
2542 *al
= SSL_AD_HANDSHAKE_FAILURE
;
2543 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
,
2544 SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER
);
2548 pkey_ctx
= EVP_PKEY_CTX_new(X509_get0_pubkey(peer_cert
), NULL
);
2549 if (pkey_ctx
== NULL
) {
2550 *al
= SSL_AD_INTERNAL_ERROR
;
2551 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, ERR_R_MALLOC_FAILURE
);
2555 * If we have send a certificate, and certificate key
2556 * parameters match those of server certificate, use
2557 * certificate key for key exchange
2560 /* Otherwise, generate ephemeral key pair */
2562 pms
= OPENSSL_malloc(pmslen
);
2564 *al
= SSL_AD_INTERNAL_ERROR
;
2565 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, ERR_R_MALLOC_FAILURE
);
2569 if (EVP_PKEY_encrypt_init(pkey_ctx
) <= 0
2570 /* Generate session key
2571 * TODO(size_t): Convert this function
2573 || RAND_bytes(pms
, (int)pmslen
) <= 0) {
2574 *al
= SSL_AD_INTERNAL_ERROR
;
2575 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, ERR_R_INTERNAL_ERROR
);
2579 * Compute shared IV and store it in algorithm-specific context
2582 ukm_hash
= EVP_MD_CTX_new();
2583 if (ukm_hash
== NULL
2584 || EVP_DigestInit(ukm_hash
, EVP_get_digestbynid(dgst_nid
)) <= 0
2585 || EVP_DigestUpdate(ukm_hash
, s
->s3
->client_random
,
2586 SSL3_RANDOM_SIZE
) <= 0
2587 || EVP_DigestUpdate(ukm_hash
, s
->s3
->server_random
,
2588 SSL3_RANDOM_SIZE
) <= 0
2589 || EVP_DigestFinal_ex(ukm_hash
, shared_ukm
, &md_len
) <= 0) {
2590 *al
= SSL_AD_INTERNAL_ERROR
;
2591 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, ERR_R_INTERNAL_ERROR
);
2594 EVP_MD_CTX_free(ukm_hash
);
2596 if (EVP_PKEY_CTX_ctrl(pkey_ctx
, -1, EVP_PKEY_OP_ENCRYPT
,
2597 EVP_PKEY_CTRL_SET_IV
, 8, shared_ukm
) < 0) {
2598 *al
= SSL_AD_INTERNAL_ERROR
;
2599 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, SSL_R_LIBRARY_BUG
);
2602 /* Make GOST keytransport blob message */
2604 * Encapsulate it into sequence
2607 if (EVP_PKEY_encrypt(pkey_ctx
, tmp
, &msglen
, pms
, pmslen
) <= 0) {
2608 *al
= SSL_AD_INTERNAL_ERROR
;
2609 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, SSL_R_LIBRARY_BUG
);
2613 if (!WPACKET_put_bytes_u8(pkt
, V_ASN1_SEQUENCE
| V_ASN1_CONSTRUCTED
)
2614 || (msglen
>= 0x80 && !WPACKET_put_bytes_u8(pkt
, 0x81))
2615 || !WPACKET_sub_memcpy_u8(pkt
, tmp
, msglen
)) {
2616 *al
= SSL_AD_INTERNAL_ERROR
;
2617 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, ERR_R_INTERNAL_ERROR
);
2621 EVP_PKEY_CTX_free(pkey_ctx
);
2622 s
->s3
->tmp
.pms
= pms
;
2623 s
->s3
->tmp
.pmslen
= pmslen
;
2627 EVP_PKEY_CTX_free(pkey_ctx
);
2628 OPENSSL_clear_free(pms
, pmslen
);
2629 EVP_MD_CTX_free(ukm_hash
);
2632 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_GOST
, ERR_R_INTERNAL_ERROR
);
2633 *al
= SSL_AD_INTERNAL_ERROR
;
2638 static int tls_construct_cke_srp(SSL
*s
, WPACKET
*pkt
, int *al
)
2640 #ifndef OPENSSL_NO_SRP
2641 unsigned char *abytes
= NULL
;
2643 if (s
->srp_ctx
.A
== NULL
2644 || !WPACKET_sub_allocate_bytes_u16(pkt
, BN_num_bytes(s
->srp_ctx
.A
),
2646 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_SRP
, ERR_R_INTERNAL_ERROR
);
2649 BN_bn2bin(s
->srp_ctx
.A
, abytes
);
2651 OPENSSL_free(s
->session
->srp_username
);
2652 s
->session
->srp_username
= OPENSSL_strdup(s
->srp_ctx
.login
);
2653 if (s
->session
->srp_username
== NULL
) {
2654 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_SRP
, ERR_R_MALLOC_FAILURE
);
2660 SSLerr(SSL_F_TLS_CONSTRUCT_CKE_SRP
, ERR_R_INTERNAL_ERROR
);
2661 *al
= SSL_AD_INTERNAL_ERROR
;
2666 int tls_construct_client_key_exchange(SSL
*s
, WPACKET
*pkt
)
2668 unsigned long alg_k
;
2671 alg_k
= s
->s3
->tmp
.new_cipher
->algorithm_mkey
;
2673 if ((alg_k
& SSL_PSK
)
2674 && !tls_construct_cke_psk_preamble(s
, pkt
, &al
))
2677 if (alg_k
& (SSL_kRSA
| SSL_kRSAPSK
)) {
2678 if (!tls_construct_cke_rsa(s
, pkt
, &al
))
2680 } else if (alg_k
& (SSL_kDHE
| SSL_kDHEPSK
)) {
2681 if (!tls_construct_cke_dhe(s
, pkt
, &al
))
2683 } else if (alg_k
& (SSL_kECDHE
| SSL_kECDHEPSK
)) {
2684 if (!tls_construct_cke_ecdhe(s
, pkt
, &al
))
2686 } else if (alg_k
& SSL_kGOST
) {
2687 if (!tls_construct_cke_gost(s
, pkt
, &al
))
2689 } else if (alg_k
& SSL_kSRP
) {
2690 if (!tls_construct_cke_srp(s
, pkt
, &al
))
2692 } else if (!(alg_k
& SSL_kPSK
)) {
2693 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_HANDSHAKE_FAILURE
);
2694 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE
, ERR_R_INTERNAL_ERROR
);
2701 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
2702 OPENSSL_clear_free(s
->s3
->tmp
.pms
, s
->s3
->tmp
.pmslen
);
2703 s
->s3
->tmp
.pms
= NULL
;
2704 #ifndef OPENSSL_NO_PSK
2705 OPENSSL_clear_free(s
->s3
->tmp
.psk
, s
->s3
->tmp
.psklen
);
2706 s
->s3
->tmp
.psk
= NULL
;
2711 int tls_client_key_exchange_post_work(SSL
*s
)
2713 unsigned char *pms
= NULL
;
2716 pms
= s
->s3
->tmp
.pms
;
2717 pmslen
= s
->s3
->tmp
.pmslen
;
2719 #ifndef OPENSSL_NO_SRP
2721 if (s
->s3
->tmp
.new_cipher
->algorithm_mkey
& SSL_kSRP
) {
2722 if (!srp_generate_client_master_secret(s
)) {
2723 SSLerr(SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK
,
2724 ERR_R_INTERNAL_ERROR
);
2731 if (pms
== NULL
&& !(s
->s3
->tmp
.new_cipher
->algorithm_mkey
& SSL_kPSK
)) {
2732 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2733 SSLerr(SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK
, ERR_R_MALLOC_FAILURE
);
2736 if (!ssl_generate_master_secret(s
, pms
, pmslen
, 1)) {
2737 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2738 SSLerr(SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK
, ERR_R_INTERNAL_ERROR
);
2739 /* ssl_generate_master_secret frees the pms even on error */
2747 #ifndef OPENSSL_NO_SCTP
2748 if (SSL_IS_DTLS(s
)) {
2749 unsigned char sctpauthkey
[64];
2750 char labelbuffer
[sizeof(DTLS1_SCTP_AUTH_LABEL
)];
2753 * Add new shared key for SCTP-Auth, will be ignored if no SCTP
2756 memcpy(labelbuffer
, DTLS1_SCTP_AUTH_LABEL
,
2757 sizeof(DTLS1_SCTP_AUTH_LABEL
));
2759 if (SSL_export_keying_material(s
, sctpauthkey
,
2760 sizeof(sctpauthkey
), labelbuffer
,
2761 sizeof(labelbuffer
), NULL
, 0, 0) <= 0)
2764 BIO_ctrl(SSL_get_wbio(s
), BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY
,
2765 sizeof(sctpauthkey
), sctpauthkey
);
2771 OPENSSL_clear_free(pms
, pmslen
);
2772 s
->s3
->tmp
.pms
= NULL
;
2776 int tls_construct_client_verify(SSL
*s
, WPACKET
*pkt
)
2779 const EVP_MD
*md
= s
->s3
->tmp
.md
[s
->cert
->key
- s
->cert
->pkeys
];
2780 EVP_MD_CTX
*mctx
= NULL
;
2784 unsigned char *sig
= NULL
;
2786 mctx
= EVP_MD_CTX_new();
2788 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY
, ERR_R_MALLOC_FAILURE
);
2791 pkey
= s
->cert
->key
->privatekey
;
2793 hdatalen
= BIO_get_mem_data(s
->s3
->handshake_buffer
, &hdata
);
2794 if (hdatalen
<= 0) {
2795 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY
, ERR_R_INTERNAL_ERROR
);
2799 if (SSL_USE_SIGALGS(s
)&& !tls12_get_sigandhash(pkt
, pkey
, md
)) {
2800 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY
, ERR_R_INTERNAL_ERROR
);
2804 fprintf(stderr
, "Using client alg %s\n", EVP_MD_name(md
));
2806 sig
= OPENSSL_malloc(EVP_PKEY_size(pkey
));
2808 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY
, ERR_R_MALLOC_FAILURE
);
2811 if (!EVP_SignInit_ex(mctx
, md
, NULL
)
2812 || !EVP_SignUpdate(mctx
, hdata
, hdatalen
)
2813 || (s
->version
== SSL3_VERSION
2814 && !EVP_MD_CTX_ctrl(mctx
, EVP_CTRL_SSL3_MASTER_SECRET
,
2815 (int)s
->session
->master_key_length
,
2816 s
->session
->master_key
))
2817 || !EVP_SignFinal(mctx
, sig
, &u
, pkey
)) {
2818 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY
, ERR_R_EVP_LIB
);
2821 #ifndef OPENSSL_NO_GOST
2823 int pktype
= EVP_PKEY_id(pkey
);
2824 if (pktype
== NID_id_GostR3410_2001
2825 || pktype
== NID_id_GostR3410_2012_256
2826 || pktype
== NID_id_GostR3410_2012_512
)
2827 BUF_reverse(sig
, NULL
, u
);
2831 if (!WPACKET_sub_memcpy_u16(pkt
, sig
, u
)) {
2832 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY
, ERR_R_INTERNAL_ERROR
);
2836 /* Digest cached records and discard handshake buffer */
2837 if (!ssl3_digest_cached_records(s
, 0))
2841 EVP_MD_CTX_free(mctx
);
2845 EVP_MD_CTX_free(mctx
);
2846 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2851 * Check a certificate can be used for client authentication. Currently check
2852 * cert exists, if we have a suitable digest for TLS 1.2 if static DH client
2853 * certificates can be used and optionally checks suitability for Suite B.
2855 static int ssl3_check_client_certificate(SSL
*s
)
2857 if (!s
->cert
|| !s
->cert
->key
->x509
|| !s
->cert
->key
->privatekey
)
2859 /* If no suitable signature algorithm can't use certificate */
2860 if (SSL_USE_SIGALGS(s
) && !s
->s3
->tmp
.md
[s
->cert
->key
- s
->cert
->pkeys
])
2863 * If strict mode check suitability of chain before using it. This also
2864 * adjusts suite B digest if necessary.
2866 if (s
->cert
->cert_flags
& SSL_CERT_FLAGS_CHECK_TLS_STRICT
&&
2867 !tls1_check_chain(s
, NULL
, NULL
, NULL
, -2))
2872 WORK_STATE
tls_prepare_client_certificate(SSL
*s
, WORK_STATE wst
)
2875 EVP_PKEY
*pkey
= NULL
;
2878 if (wst
== WORK_MORE_A
) {
2879 /* Let cert callback update client certificates if required */
2880 if (s
->cert
->cert_cb
) {
2881 i
= s
->cert
->cert_cb(s
, s
->cert
->cert_cb_arg
);
2883 s
->rwstate
= SSL_X509_LOOKUP
;
2887 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2888 ossl_statem_set_error(s
);
2891 s
->rwstate
= SSL_NOTHING
;
2893 if (ssl3_check_client_certificate(s
))
2894 return WORK_FINISHED_CONTINUE
;
2896 /* Fall through to WORK_MORE_B */
2900 /* We need to get a client cert */
2901 if (wst
== WORK_MORE_B
) {
2903 * If we get an error, we need to ssl->rwstate=SSL_X509_LOOKUP;
2904 * return(-1); We then get retied later
2906 i
= ssl_do_client_cert_cb(s
, &x509
, &pkey
);
2908 s
->rwstate
= SSL_X509_LOOKUP
;
2911 s
->rwstate
= SSL_NOTHING
;
2912 if ((i
== 1) && (pkey
!= NULL
) && (x509
!= NULL
)) {
2913 if (!SSL_use_certificate(s
, x509
) || !SSL_use_PrivateKey(s
, pkey
))
2915 } else if (i
== 1) {
2917 SSLerr(SSL_F_TLS_PREPARE_CLIENT_CERTIFICATE
,
2918 SSL_R_BAD_DATA_RETURNED_BY_CALLBACK
);
2922 EVP_PKEY_free(pkey
);
2923 if (i
&& !ssl3_check_client_certificate(s
))
2926 if (s
->version
== SSL3_VERSION
) {
2927 s
->s3
->tmp
.cert_req
= 0;
2928 ssl3_send_alert(s
, SSL3_AL_WARNING
, SSL_AD_NO_CERTIFICATE
);
2929 return WORK_FINISHED_CONTINUE
;
2931 s
->s3
->tmp
.cert_req
= 2;
2932 if (!ssl3_digest_cached_records(s
, 0)) {
2933 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2934 ossl_statem_set_error(s
);
2940 return WORK_FINISHED_CONTINUE
;
2943 /* Shouldn't ever get here */
2947 int tls_construct_client_certificate(SSL
*s
, WPACKET
*pkt
)
2949 if (!ssl3_output_cert_chain(s
, pkt
,
2950 (s
->s3
->tmp
.cert_req
== 2) ? NULL
2952 SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_CERTIFICATE
, ERR_R_INTERNAL_ERROR
);
2953 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
2960 #define has_bits(i,m) (((i)&(m)) == (m))
2962 int ssl3_check_cert_and_algorithm(SSL
*s
)
2965 #ifndef OPENSSL_NO_EC
2969 EVP_PKEY
*pkey
= NULL
;
2970 int al
= SSL_AD_HANDSHAKE_FAILURE
;
2972 alg_k
= s
->s3
->tmp
.new_cipher
->algorithm_mkey
;
2973 alg_a
= s
->s3
->tmp
.new_cipher
->algorithm_auth
;
2975 /* we don't have a certificate */
2976 if ((alg_a
& SSL_aNULL
) || (alg_k
& SSL_kPSK
))
2979 /* This is the passed certificate */
2981 #ifndef OPENSSL_NO_EC
2982 idx
= s
->session
->peer_type
;
2983 if (idx
== SSL_PKEY_ECC
) {
2984 if (ssl_check_srvr_ecc_cert_and_alg(s
->session
->peer
, s
) == 0) {
2986 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM
, SSL_R_BAD_ECC_CERT
);
2991 } else if (alg_a
& SSL_aECDSA
) {
2992 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM
,
2993 SSL_R_MISSING_ECDSA_SIGNING_CERT
);
2997 pkey
= X509_get0_pubkey(s
->session
->peer
);
2998 i
= X509_certificate_type(s
->session
->peer
, pkey
);
3000 /* Check that we have a certificate if we require one */
3001 if ((alg_a
& SSL_aRSA
) && !has_bits(i
, EVP_PK_RSA
| EVP_PKT_SIGN
)) {
3002 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM
,
3003 SSL_R_MISSING_RSA_SIGNING_CERT
);
3006 #ifndef OPENSSL_NO_DSA
3007 else if ((alg_a
& SSL_aDSS
) && !has_bits(i
, EVP_PK_DSA
| EVP_PKT_SIGN
)) {
3008 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM
,
3009 SSL_R_MISSING_DSA_SIGNING_CERT
);
3013 #ifndef OPENSSL_NO_RSA
3014 if (alg_k
& (SSL_kRSA
| SSL_kRSAPSK
) &&
3015 !has_bits(i
, EVP_PK_RSA
| EVP_PKT_ENC
)) {
3016 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM
,
3017 SSL_R_MISSING_RSA_ENCRYPTING_CERT
);
3021 #ifndef OPENSSL_NO_DH
3022 if ((alg_k
& SSL_kDHE
) && (s
->s3
->peer_tmp
== NULL
)) {
3023 al
= SSL_AD_INTERNAL_ERROR
;
3024 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM
, ERR_R_INTERNAL_ERROR
);
3031 ssl3_send_alert(s
, SSL3_AL_FATAL
, al
);
3035 #ifndef OPENSSL_NO_NEXTPROTONEG
3036 int tls_construct_next_proto(SSL
*s
, WPACKET
*pkt
)
3038 size_t len
, padding_len
;
3039 unsigned char *padding
= NULL
;
3041 len
= s
->next_proto_negotiated_len
;
3042 padding_len
= 32 - ((len
+ 2) % 32);
3044 if (!WPACKET_sub_memcpy_u8(pkt
, s
->next_proto_negotiated
, len
)
3045 || !WPACKET_sub_allocate_bytes_u8(pkt
, padding_len
, &padding
)) {
3046 SSLerr(SSL_F_TLS_CONSTRUCT_NEXT_PROTO
, ERR_R_INTERNAL_ERROR
);
3050 memset(padding
, 0, padding_len
);
3054 ssl3_send_alert(s
, SSL3_AL_FATAL
, SSL_AD_INTERNAL_ERROR
);
3059 int ssl_do_client_cert_cb(SSL
*s
, X509
**px509
, EVP_PKEY
**ppkey
)
3062 #ifndef OPENSSL_NO_ENGINE
3063 if (s
->ctx
->client_cert_engine
) {
3064 i
= ENGINE_load_ssl_client_cert(s
->ctx
->client_cert_engine
, s
,
3065 SSL_get_client_CA_list(s
),
3066 px509
, ppkey
, NULL
, NULL
, NULL
);
3071 if (s
->ctx
->client_cert_cb
)
3072 i
= s
->ctx
->client_cert_cb(s
, px509
, ppkey
);
3076 int ssl_cipher_list_to_bytes(SSL
*s
, STACK_OF(SSL_CIPHER
) *sk
, WPACKET
*pkt
)
3079 size_t totlen
= 0, len
, maxlen
;
3080 int empty_reneg_info_scsv
= !s
->renegotiate
;
3081 /* Set disabled masks for this session */
3082 ssl_set_client_disabled(s
);
3087 #ifdef OPENSSL_MAX_TLS1_2_CIPHER_LENGTH
3088 # if OPENSSL_MAX_TLS1_2_CIPHER_LENGTH < 6
3089 # error Max cipher length too short
3092 * Some servers hang if client hello > 256 bytes as hack workaround
3093 * chop number of supported ciphers to keep it well below this if we
3096 if (TLS1_get_version(s
) >= TLS1_2_VERSION
)
3097 maxlen
= OPENSSL_MAX_TLS1_2_CIPHER_LENGTH
& ~1;
3100 /* Maximum length that can be stored in 2 bytes. Length must be even */
3103 if (empty_reneg_info_scsv
)
3105 if (s
->mode
& SSL_MODE_SEND_FALLBACK_SCSV
)
3108 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
) && totlen
< maxlen
; i
++) {
3109 const SSL_CIPHER
*c
;
3111 c
= sk_SSL_CIPHER_value(sk
, i
);
3112 /* Skip disabled ciphers */
3113 if (ssl_cipher_disabled(s
, c
, SSL_SECOP_CIPHER_SUPPORTED
))
3116 if (!s
->method
->put_cipher_by_char(c
, pkt
, &len
)) {
3117 SSLerr(SSL_F_SSL_CIPHER_LIST_TO_BYTES
, ERR_R_INTERNAL_ERROR
);
3125 SSLerr(SSL_F_SSL_CIPHER_LIST_TO_BYTES
, SSL_R_NO_CIPHERS_AVAILABLE
);
3130 if (empty_reneg_info_scsv
) {
3131 static SSL_CIPHER scsv
= {
3132 0, NULL
, SSL3_CK_SCSV
, 0, 0, 0, 0, 0, 0, 0, 0, 0
3134 if (!s
->method
->put_cipher_by_char(&scsv
, pkt
, &len
)) {
3135 SSLerr(SSL_F_SSL_CIPHER_LIST_TO_BYTES
, ERR_R_INTERNAL_ERROR
);
3139 if (s
->mode
& SSL_MODE_SEND_FALLBACK_SCSV
) {
3140 static SSL_CIPHER scsv
= {
3141 0, NULL
, SSL3_CK_FALLBACK_SCSV
, 0, 0, 0, 0, 0, 0, 0, 0, 0
3143 if (!s
->method
->put_cipher_by_char(&scsv
, pkt
, &len
)) {
3144 SSLerr(SSL_F_SSL_CIPHER_LIST_TO_BYTES
, ERR_R_INTERNAL_ERROR
);