Debian Codegraph @

crt/s2n/tests/testlib/s2n_security_policy_testlib.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include "crypto/s2n_fips.h"
17 #include "s2n_testlib.h"
18 #include "utils/s2n_safety.h"
19
20 extern const struct s2n_ecc_named_curve s2n_unsupported_curve;
21
22 const struct s2n_ecc_named_curve *const ecc_pref_list_for_retry[] = {
23 &s2n_unsupported_curve,
24 #if EVP_APIS_SUPPORTED
25 &s2n_ecc_curve_x25519,
26 #endif
27 &s2n_ecc_curve_secp256r1,
28 &s2n_ecc_curve_secp384r1,
29 &s2n_ecc_curve_secp521r1,
30 };
31 const struct s2n_ecc_preferences ecc_preferences_for_retry = {
32 .count = s2n_array_len(ecc_pref_list_for_retry),
33 .ecc_curves = ecc_pref_list_for_retry,
34 };
35
36 /* Supports only ECC, however client's first ECC Curve is s2n_unsupported_curve, which will always force a HRR */
37 const struct s2n_security_policy security_policy_test_tls13_retry = {
38 .minimum_protocol_version = S2N_TLS10,
39 .cipher_preferences = &cipher_preferences_20190801,
40 .kem_preferences = &kem_preferences_null,
41 .signature_preferences = &s2n_signature_preferences_20200207,
42 .certificate_signature_preferences = &s2n_certificate_signature_preferences_20201110,
43 .ecc_preferences = &ecc_preferences_for_retry,
44 };
45
46 /* Supports both PQ and ECC, however client's first ECC Curve is s2n_unsupported_curve, which will always force a HRR */
47 const struct s2n_security_policy security_policy_test_tls13_retry_with_pq = {
48 .minimum_protocol_version = S2N_TLS10,
49 .cipher_preferences = &cipher_preferences_20190801,
50 .kem_preferences = &kem_preferences_pq_tls_1_3_ietf_2024_10,
51 .signature_preferences = &s2n_signature_preferences_20200207,
52 .certificate_signature_preferences = &s2n_certificate_signature_preferences_20201110,
53 .ecc_preferences = &ecc_preferences_for_retry,
54 };
55
56 /*
57 * DEPRECATED: Do not use for new tests. Instead set an explicit security policy.
58 * This method was used to preserve existing test behaviors when updating the default behavior
59 * in https://github.com/aws/s2n-tls/pull/5549
60 */
61 S2N_RESULT s2n_config_set_tls12_security_policy(struct s2n_config *config)
62 {
63 if (s2n_is_in_fips_mode()) {
64 RESULT_GUARD_POSIX(s2n_config_set_cipher_preferences(config, "20240502"));
65 } else {
66 RESULT_GUARD_POSIX(s2n_config_set_cipher_preferences(config, "20240501"));
67 }
68 return S2N_RESULT_OK;
69 }
70
71 /*
72 * DEPRECATED: Do not use for new tests. Instead set an explicit security policy.
73 * This method was used to preserve existing test behaviors when updating the default behavior
74 * in https://github.com/aws/s2n-tls/pull/5549
75 */
76 S2N_RESULT s2n_connection_set_tls12_security_policy(struct s2n_connection *connection)
77 {
78 if (s2n_is_in_fips_mode()) {
79 RESULT_GUARD_POSIX(s2n_connection_set_cipher_preferences(connection, "20240502"));
80 } else {
81 RESULT_GUARD_POSIX(s2n_connection_set_cipher_preferences(connection, "20240501"));
82 }
83 return S2N_RESULT_OK;
84 }