Skip to content

Commit b40bd4c

Browse files
author
Boquan Fang
committed
fix test and find out the default cipher tls1.2 will write
1 parent 585b993 commit b40bd4c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

tests/unit/s2n_client_hello_test.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@
4444
#define COMPRESSION_METHODS 0x00, 0x01, 0x02, 0x03, 0x04
4545
#define COMPRESSION_METHODS_LEN 0x05
4646

47-
#define CIPHER_SUITES_MAX_LENGTH (UINT16_MAX - 2)
47+
#define CIPHER_SUITES_MAX_LENGTH ((1 << 16) - 2)
4848
#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)
5054
/* Drop 150 cipher suites from max, so that the total handshake message length won't exceed 64KB */
5155
#define REDUCED_CIPHER_SUITE_COUNT (MAX_CIPHER_SUITE_COUNT - NUM_OF_CIPHER_SUITES_TO_DROP)
5256

@@ -1961,18 +1965,20 @@ int main(int argc, char **argv)
19611965

19621966
/* Test: large Client Hellos */
19631967
{
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 };
19651969

19661970
for (size_t i = 0; i < s2n_array_len(cipher_suites_counts); i++) {
19671971
DEFER_CLEANUP(struct s2n_config *server_config = s2n_config_new(), s2n_config_ptr_free);
19681972
EXPECT_NOT_NULL(server_config);
19691973

19701974
EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
19711975

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];
19731979

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;
19761982
}
19771983

19781984
const struct s2n_cipher_preferences test_cipher_suites_preferences = {
@@ -2012,7 +2018,10 @@ int main(int argc, char **argv)
20122018
*/
20132019
EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate(client, &blocked), S2N_ERR_IO_BLOCKED);
20142020

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) {
20162025
/**
20172026
* The Client Hello message size should be less than S2N_MAXIMUM_HANDSHAKE_MESSAGE_LENGTH, even with
20182027
* the five bytes record header.

tls/extensions/s2n_extension_type.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,13 @@ int s2n_extension_send(const s2n_extension_type *extension_type, struct s2n_conn
117117
/**
118118
* Reset the tainted flag in the out stuffer (handshake.io stuffer).
119119
*
120-
* Some extension send methods use stuffer raw access functions that
121-
* make the stuffer tainted, preventing further resizing of handshake.io.
120+
* Some extension send functions call s2n_stuffer_raw_write(), which
121+
* makes the stuffer tainted, preventing further resizing of the handshake.io stuffer.
122122
* We need to reset this flag after each extension is sent, because handshake.io
123123
* might need to be resized to send subsequent extensions.
124124
*
125-
* This is safe because the handshake.io stuffer is wiped after each handshake message.
126-
* No raw pointer is written to the connection, so raw pointers are not accessable
127-
* after the extension send method.
125+
* This is safe because the outstanding pointer from s2n_stuffer_raw_write() is scoped to
126+
* the send function of each extension, and it is never stored in s2n_connection.
128127
*/
129128
out->tainted = false;
130129

0 commit comments

Comments
 (0)