|
44 | 44 | #define COMPRESSION_METHODS 0x00, 0x01, 0x02, 0x03, 0x04
|
45 | 45 | #define COMPRESSION_METHODS_LEN 0x05
|
46 | 46 |
|
47 |
| -#define CIPHER_SUITES_MAX_LENGTH (UINT16_MAX - 2) |
| 47 | +#define CIPHER_SUITES_MAX_LENGTH ((1 << 16) - 2) |
48 | 48 | #define NUM_OF_CIPHER_SUITES_TO_DROP 150
|
49 |
| -#define MAX_CIPHER_SUITE_COUNT (CIPHER_SUITES_MAX_LENGTH / S2N_TLS_CIPHER_SUITE_LEN) |
| 49 | +/** |
| 50 | + * S2N-TLS automatically includes TLS_EMPTY_RENEGOTIATION_INFO_SCSV in TLS 1.2 ClientHello, |
| 51 | + * so we subtract 1 from the maximum number of cipher suites to reserve space for it. |
| 52 | + */ |
| 53 | +#define MAX_CIPHER_SUITE_COUNT ((CIPHER_SUITES_MAX_LENGTH / S2N_TLS_CIPHER_SUITE_LEN) - 1) |
50 | 54 | /* Drop 150 cipher suites from max, so that the total handshake message length won't exceed 64KB */
|
51 | 55 | #define REDUCED_CIPHER_SUITE_COUNT (MAX_CIPHER_SUITE_COUNT - NUM_OF_CIPHER_SUITES_TO_DROP)
|
52 | 56 |
|
@@ -1961,18 +1965,20 @@ int main(int argc, char **argv)
|
1961 | 1965 |
|
1962 | 1966 | /* Test: large Client Hellos */
|
1963 | 1967 | {
|
1964 |
| - uint32_t cipher_suites_counts[] = { REDUCED_CIPHER_SUITE_COUNT, MAX_CIPHER_SUITE_COUNT }; |
| 1968 | + uint16_t cipher_suites_counts[] = { REDUCED_CIPHER_SUITE_COUNT, MAX_CIPHER_SUITE_COUNT }; |
1965 | 1969 |
|
1966 | 1970 | for (size_t i = 0; i < s2n_array_len(cipher_suites_counts); i++) {
|
1967 | 1971 | DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new(), s2n_config_ptr_free);
|
1968 | 1972 | EXPECT_NOT_NULL(server_config);
|
1969 | 1973 |
|
1970 | 1974 | EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
|
1971 | 1975 |
|
1972 |
| - struct s2n_cipher_suite *test_cipher_suites[] = { 0 }; |
| 1976 | + uint16_t cipher_suites_count = cipher_suites_counts[i]; |
| 1977 | + |
| 1978 | + struct s2n_cipher_suite *test_cipher_suites[cipher_suites_count]; |
1973 | 1979 |
|
1974 |
| - for (size_t i = 0; i < cipher_suites_counts[i]; i++) { |
1975 |
| - test_cipher_suites[i] = &s2n_rsa_with_aes_128_gcm_sha256; |
| 1980 | + for (size_t j = 0; j < cipher_suites_count; j++) { |
| 1981 | + test_cipher_suites[j] = &s2n_rsa_with_aes_128_gcm_sha256; |
1976 | 1982 | }
|
1977 | 1983 |
|
1978 | 1984 | const struct s2n_cipher_preferences test_cipher_suites_preferences = {
|
@@ -2012,7 +2018,10 @@ int main(int argc, char **argv)
|
2012 | 2018 | */
|
2013 | 2019 | EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate(client, &blocked), S2N_ERR_IO_BLOCKED);
|
2014 | 2020 |
|
2015 |
| - if ((cipher_suites_counts[i] * S2N_TLS_CIPHER_SUITE_LEN) < CIPHER_SUITES_MAX_LENGTH) { |
| 2021 | + /* Add one extra cipher suite length to account for TLS_EMPTY_RENEGOTIATION_INFO_SCSV */ |
| 2022 | + uint16_t cipher_suites_length = (cipher_suites_count + 1) * S2N_TLS_CIPHER_SUITE_LEN; |
| 2023 | + |
| 2024 | + if (cipher_suites_length < CIPHER_SUITES_MAX_LENGTH) { |
2016 | 2025 | /**
|
2017 | 2026 | * The Client Hello message size should be less than S2N_MAXIMUM_HANDSHAKE_MESSAGE_LENGTH, even with
|
2018 | 2027 | * the five bytes record header.
|
|
0 commit comments