@@ -471,34 +471,6 @@ int s2n_parse_client_hello(struct s2n_connection *conn)
471
471
conn -> session_id_len = conn -> client_hello .session_id .size ;
472
472
POSIX_CHECKED_MEMCPY (conn -> session_id , conn -> client_hello .session_id .data , conn -> session_id_len );
473
473
474
- /* Set default key exchange curve.
475
- * This is going to be our fallback if the client has no preference.
476
- *
477
- * P-256 is our preferred fallback option because the TLS1.3 RFC requires
478
- * all implementations to support it:
479
- *
480
- * https://tools.ietf.org/rfc/rfc8446#section-9.1
481
- * A TLS-compliant application MUST support key exchange with secp256r1 (NIST P-256)
482
- * and SHOULD support key exchange with X25519 [RFC7748]
483
- *
484
- *= https://www.rfc-editor.org/rfc/rfc4492#section-4
485
- *# A client that proposes ECC cipher suites may choose not to include these extensions.
486
- *# In this case, the server is free to choose any one of the elliptic curves or point formats listed in Section 5.
487
- *
488
- */
489
- const struct s2n_ecc_preferences * ecc_pref = NULL ;
490
- POSIX_GUARD (s2n_connection_get_ecc_preferences (conn , & ecc_pref ));
491
- POSIX_ENSURE_REF (ecc_pref );
492
- POSIX_ENSURE_GT (ecc_pref -> count , 0 );
493
- if (s2n_ecc_preferences_includes_curve (ecc_pref , TLS_EC_CURVE_SECP_256_R1 )) {
494
- conn -> kex_params .server_ecc_evp_params .negotiated_curve = & s2n_ecc_curve_secp256r1 ;
495
- } else {
496
- /* If P-256 isn't allowed by the current security policy, instead choose
497
- * the first / most preferred curve.
498
- */
499
- conn -> kex_params .server_ecc_evp_params .negotiated_curve = ecc_pref -> ecc_curves [0 ];
500
- }
501
-
502
474
POSIX_GUARD_RESULT (s2n_client_hello_verify_for_retry (conn ,
503
475
& previous_hello_retry , & conn -> client_hello , previous_client_random ));
504
476
return S2N_SUCCESS ;
@@ -565,6 +537,34 @@ int s2n_process_client_hello(struct s2n_connection *conn)
565
537
conn -> actual_protocol_version = MIN (conn -> server_protocol_version , S2N_TLS12 );
566
538
}
567
539
540
+ /* Set default key exchange curve.
541
+ * This is going to be our fallback if the client has no preference.
542
+ *
543
+ * P-256 is our preferred fallback option because the TLS1.3 RFC requires
544
+ * all implementations to support it:
545
+ *
546
+ * https://tools.ietf.org/rfc/rfc8446#section-9.1
547
+ * A TLS-compliant application MUST support key exchange with secp256r1 (NIST P-256)
548
+ * and SHOULD support key exchange with X25519 [RFC7748]
549
+ *
550
+ *= https://www.rfc-editor.org/rfc/rfc4492#section-4
551
+ *# A client that proposes ECC cipher suites may choose not to include these extensions.
552
+ *# In this case, the server is free to choose any one of the elliptic curves or point formats listed in Section 5.
553
+ *
554
+ */
555
+ const struct s2n_ecc_preferences * ecc_pref = NULL ;
556
+ POSIX_GUARD (s2n_connection_get_ecc_preferences (conn , & ecc_pref ));
557
+ POSIX_ENSURE_REF (ecc_pref );
558
+ POSIX_ENSURE_GT (ecc_pref -> count , 0 );
559
+ if (s2n_ecc_preferences_includes_curve (ecc_pref , TLS_EC_CURVE_SECP_256_R1 )) {
560
+ conn -> kex_params .server_ecc_evp_params .negotiated_curve = & s2n_ecc_curve_secp256r1 ;
561
+ } else {
562
+ /* If P-256 isn't allowed by the current security policy, instead choose
563
+ * the first / most preferred curve.
564
+ */
565
+ conn -> kex_params .server_ecc_evp_params .negotiated_curve = ecc_pref -> ecc_curves [0 ];
566
+ }
567
+
568
568
POSIX_GUARD (s2n_extension_list_process (S2N_EXTENSION_LIST_CLIENT_HELLO , conn , & conn -> client_hello .extensions ));
569
569
570
570
/* After parsing extensions, select a curve and corresponding keyshare to use */
@@ -594,7 +594,8 @@ int s2n_process_client_hello(struct s2n_connection *conn)
594
594
POSIX_CHECKED_MEMCPY (previous_cipher_suite_iana , conn -> secure -> cipher_suite -> iana_value , S2N_TLS_CIPHER_SUITE_LEN );
595
595
596
596
/* Now choose the ciphers we have certs for. */
597
- POSIX_GUARD (s2n_set_cipher_as_tls_server (conn , client_hello -> cipher_suites .data , client_hello -> cipher_suites .size / 2 ));
597
+ POSIX_GUARD (s2n_set_cipher_as_tls_server (conn , client_hello -> cipher_suites .data ,
598
+ client_hello -> cipher_suites .size / 2 ));
598
599
599
600
/* Check if this is the second client hello in a hello retry handshake */
600
601
if (s2n_is_hello_retry_handshake (conn ) && conn -> handshake .message_number > 0 ) {
@@ -671,6 +672,12 @@ int s2n_client_hello_recv(struct s2n_connection *conn)
671
672
/* Mark the client hello callback as invoked to avoid calling it again. */
672
673
conn -> client_hello .callback_invoked = true;
673
674
675
+ /* Do NOT move this null check. A test exists to assert that a server connection can get
676
+ * as far as the client hello callback without using its config. To do this we need a
677
+ * specific error for a null config just before the client hello callback. The test's
678
+ * assertions are weakened if this check is moved. */
679
+ POSIX_ENSURE (conn -> config , S2N_ERR_CONFIG_NULL_BEFORE_CH_CALLBACK );
680
+
674
681
/* Call client_hello_cb if exists, letting application to modify s2n_connection or swap s2n_config */
675
682
if (conn -> config -> client_hello_cb ) {
676
683
int rc = conn -> config -> client_hello_cb (conn , conn -> config -> client_hello_cb_ctx );
@@ -854,7 +861,8 @@ int s2n_sslv2_client_hello_recv(struct s2n_connection *conn)
854
861
/* Find potential certificate matches before we choose the cipher. */
855
862
POSIX_GUARD (s2n_conn_find_name_matching_certs (conn ));
856
863
857
- POSIX_GUARD (s2n_set_cipher_as_sslv2_server (conn , client_hello -> cipher_suites .data , client_hello -> cipher_suites .size / S2N_SSLv2_CIPHER_SUITE_LEN ));
864
+ POSIX_GUARD (s2n_set_cipher_as_sslv2_server (conn , client_hello -> cipher_suites .data ,
865
+ client_hello -> cipher_suites .size / S2N_SSLv2_CIPHER_SUITE_LEN ));
858
866
POSIX_GUARD_RESULT (s2n_signature_algorithm_select (conn ));
859
867
POSIX_GUARD (s2n_select_certs_for_server_auth (conn , & conn -> handshake_params .our_chain_and_key ));
860
868
0 commit comments