| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tls/policy/s2n_policy_defaults.h" |
| 17 |
|
| 18 |
#include "s2n_test.h" |
| 19 |
#include "testlib/s2n_testlib.h" |
| 20 |
|
| 21 |
S2N_RESULT s2n_test_strict_compatibility(uint64_t start, uint64_t end, |
| 22 |
struct s2n_test_cert_chain_list *cert_chains) |
| 23 |
{ |
| 24 |
for (size_t client_i = start; client_i <= end; client_i++) { |
| 25 |
for (size_t server_i = start; server_i <= end; server_i++) { |
| 26 |
for (size_t cert_i = 0; cert_i < cert_chains->count; cert_i++) { |
| 27 |
DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free); |
| 28 |
EXPECT_NOT_NULL(config); |
| 29 |
EXPECT_SUCCESS(s2n_config_set_unsafe_for_testing(config)); |
| 30 |
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(config, |
| 31 |
cert_chains->chains[cert_i].chain)); |
| 32 |
EXPECT_SUCCESS(s2n_config_set_client_auth_type(config, S2N_CERT_AUTH_REQUIRED)); |
| 33 |
|
| 34 |
DEFER_CLEANUP(struct s2n_connection *client = s2n_connection_new(S2N_CLIENT), |
| 35 |
s2n_connection_ptr_free); |
| 36 |
EXPECT_SUCCESS(s2n_connection_set_config(client, config)); |
| 37 |
EXPECT_SUCCESS(s2n_connection_set_security_policy(client, |
| 38 |
s2n_security_policy_get(S2N_POLICY_STRICT, client_i))); |
| 39 |
|
| 40 |
DEFER_CLEANUP(struct s2n_connection *server = s2n_connection_new(S2N_SERVER), |
| 41 |
s2n_connection_ptr_free); |
| 42 |
EXPECT_SUCCESS(s2n_connection_set_config(server, config)); |
| 43 |
EXPECT_SUCCESS(s2n_connection_set_security_policy(server, |
| 44 |
s2n_security_policy_get(S2N_POLICY_STRICT, server_i))); |
| 45 |
|
| 46 |
DEFER_CLEANUP(struct s2n_test_io_stuffer_pair io_pair, s2n_io_stuffer_pair_free); |
| 47 |
EXPECT_OK(s2n_io_stuffer_pair_init(&io_pair)); |
| 48 |
EXPECT_OK(s2n_connections_set_io_stuffer_pair(client, server, &io_pair)); |
| 49 |
EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server, client)); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
EXPECT_FALSE(IS_HELLO_RETRY_HANDSHAKE(server)); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
return S2N_RESULT_OK; |
| 59 |
} |
| 60 |
|
| 61 |
int main(int argc, char **argv) |
| 62 |
{ |
| 63 |
BEGIN_TEST(); |
| 64 |
|
| 65 |
|
| 66 |
{ |
| 67 |
|
| 68 |
for (size_t policy_i = 0; policy_i < UINT8_MAX; policy_i++) { |
| 69 |
bool first_null_found = false; |
| 70 |
uint64_t versions_found = 0; |
| 71 |
|
| 72 |
for (size_t version_i = 0; version_i < UINT8_MAX; version_i++) { |
| 73 |
const struct s2n_security_policy *policy = s2n_security_policy_get(policy_i, version_i); |
| 74 |
|
| 75 |
|
| 76 |
if (version_i == 0 || policy_i == 0) { |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
EXPECT_NULL_WITH_ERRNO(policy, S2N_ERR_INVALID_SECURITY_POLICY); |
| 81 |
continue; |
| 82 |
} else if (policy_i >= S2N_MAX_DEFAULT_POLICIES) { |
| 83 |
EXPECT_NULL_WITH_ERRNO(policy, S2N_ERR_INVALID_SECURITY_POLICY); |
| 84 |
continue; |
| 85 |
} else if (version_i >= S2N_MAX_POLICY_VERSIONS) { |
| 86 |
EXPECT_NULL_WITH_ERRNO(policy, S2N_ERR_INVALID_SECURITY_POLICY); |
| 87 |
continue; |
| 88 |
} |
| 89 |
|
| 90 |
if (policy) { |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
EXPECT_FALSE(first_null_found); |
| 95 |
versions_found++; |
| 96 |
} else if (first_null_found) { |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
EXPECT_NULL_WITH_ERRNO(policy, S2N_ERR_INVALID_SECURITY_POLICY); |
| 101 |
} else { |
| 102 |
|
| 103 |
first_null_found = true; |
| 104 |
EXPECT_NULL_WITH_ERRNO(policy, S2N_ERR_INVALID_SECURITY_POLICY); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
if (policy_i > 0 && policy_i < S2N_MAX_DEFAULT_POLICIES) { |
| 109 |
|
| 110 |
EXPECT_TRUE(versions_found > 0); |
| 111 |
|
| 112 |
EXPECT_TRUE(first_null_found); |
| 113 |
} |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
{ |
| 121 |
EXPECT_NOT_NULL(s2n_security_policy_get(S2N_POLICY_STRICT, S2N_STRICT_2025_08_20)); |
| 122 |
EXPECT_NOT_NULL(s2n_security_policy_get(S2N_POLICY_COMPATIBLE, S2N_COMPAT_2025_08_20)); |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
if (s2n_is_tls13_fully_supported()) { |
| 128 |
DEFER_CLEANUP(struct s2n_test_cert_chain_list cert_chains = { 0 }, s2n_test_cert_chains_free); |
| 129 |
EXPECT_OK(s2n_test_cert_chains_init(&cert_chains)); |
| 130 |
|
| 131 |
EXPECT_OK(s2n_test_strict_compatibility(1, S2N_STRICT_LATEST_1, &cert_chains)); |
| 132 |
}; |
| 133 |
|
| 134 |
END_TEST(); |
| 135 |
} |