Debian Codegraph @

crt/s2n/tests/unit/s2n_client_extensions_test.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 <errno.h>
17 #include <fcntl.h>
18 #include <stdint.h>
19 #include <unistd.h>
20
21 #include "api/s2n.h"
22 #include "crypto/s2n_pq.h"
23 #include "s2n_test.h"
24 #include "testlib/s2n_testlib.h"
25 #include "tls/s2n_connection.h"
26 #include "tls/s2n_handshake.h"
27 #include "tls/s2n_kem.h"
28 #include "tls/s2n_tls.h"
29 #include "tls/s2n_tls_parameters.h"
30
31 #define ZERO_TO_THIRTY_ONE 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, \
32 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
33
34 static uint8_t server_ocsp_status_bytes[] = {
35 /* clang-format off */
36 0x30, 0x82, 0x06, 0x45, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x06, 0x3e, 0x30, 0x82, 0x06, 0x3a, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, 0x06, 0x2b, 0x30, 0x82, 0x06, 0x27, 0x30, 0x81, 0xeb, 0xa1, 0x70, 0x30, 0x6e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x4c, 0x31, 0x31, 0x30, 0x2f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x28, 0x53, 0x74, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6d, 0x20, 0x4c, 0x74, 0x64, 0x2e, 0x20, 0x28, 0x53, 0x74, 0x61, 0x72, 0x74, 0x20, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c, 0x20, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x29, 0x31, 0x2c, 0x30, 0x2a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x23, 0x53, 0x74, 0x61, 0x72,
37 0x74, 0x43, 0x6f, 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x31, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x18, 0x0f, 0x32, 0x30, 0x31, 0x35, 0x30, 0x32, 0x32, 0x37, 0x30, 0x36, 0x34, 0x36, 0x34, 0x35, 0x5a, 0x30, 0x66, 0x30, 0x64, 0x30, 0x3c, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0x65, 0x68, 0x87, 0x4f, 0x40, 0x75, 0x0f, 0x01, 0x6a, 0x34, 0x75, 0x62, 0x5e, 0x1f, 0x5c, 0x93, 0xe5, 0xa2, 0x6d, 0x58, 0x04, 0x14, 0xeb, 0x42, 0x34, 0xd0, 0x98, 0xb0, 0xab, 0x9f, 0xf4, 0x1b, 0x6b, 0x08, 0xf7, 0xcc, 0x64, 0x2e, 0xef, 0x0e, 0x2c, 0x45, 0x02, 0x03, 0x0f, 0x87, 0x2c, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30,
38 0x31, 0x35, 0x30, 0x32, 0x32, 0x37, 0x30, 0x36, 0x34, 0x36, 0x34, 0x35, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, 0x31, 0x35, 0x30, 0x33, 0x30, 0x31, 0x30, 0x36, 0x34, 0x36, 0x34, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x3c, 0x16, 0x25, 0xa2, 0x0f, 0x46, 0xc2, 0xa6, 0xac, 0xb1, 0x6e, 0x54, 0xc8, 0xf1, 0x7f, 0xa9, 0xbe, 0x58, 0xf0, 0xdb, 0x81, 0x37, 0x23, 0x76, 0x65, 0x56, 0x90, 0x15, 0xb1, 0x30, 0x6f, 0x43, 0xe2, 0x59, 0x0d, 0x97, 0xa8, 0xa6, 0x05, 0x25, 0xe7, 0x94, 0x21, 0xd5, 0xda, 0x4b, 0x55, 0x13, 0xc7, 0xdf, 0x5d, 0xf6, 0x31, 0xe8, 0x2f, 0x0d, 0xa0, 0xac, 0xd4, 0xfe, 0xf8, 0x22, 0xe7, 0x12, 0xf4, 0x32, 0xcd, 0x53,
39 0x03, 0x56, 0x98, 0x0a, 0xf8, 0x9e, 0xda, 0x2c, 0x0a, 0x43, 0x66, 0x6e, 0x0e, 0x9c, 0x9b, 0xf2, 0x0c, 0x66, 0x65, 0x1c, 0x65, 0xc4, 0xf0, 0x82, 0xc3, 0x17, 0x3d, 0x27, 0x11, 0xcc, 0xac, 0x37, 0xe3, 0xa8, 0x35, 0x46, 0x26, 0xcd, 0x08, 0x04, 0xfa, 0xb4, 0xdf, 0x9d, 0x12, 0xdf, 0x45, 0x8d, 0xf2, 0xef, 0x1a, 0xd1, 0x53, 0x50, 0x9a, 0xe3, 0xe8, 0x22, 0xda, 0xec, 0xeb, 0xc0, 0xa8, 0xea, 0xc4, 0x83, 0xc4, 0x47, 0xf2, 0x05, 0x3c, 0x14, 0x11, 0x3b, 0x25, 0xdc, 0xb9, 0x09, 0x5c, 0xd7, 0x74, 0x88, 0x96, 0x82, 0x4d, 0xbb, 0x8b, 0x7f, 0x6a, 0xbf, 0xa1, 0x44, 0x1b, 0x89, 0x67, 0xce, 0x45, 0xab, 0xca, 0xef, 0x48, 0xa6, 0x80, 0x76, 0x7d, 0xbe, 0xb7, 0x8a, 0xdf, 0x7a, 0x32, 0x8c, 0xa5, 0x86, 0x4e, 0x26, 0xf7, 0x15, 0x63, 0xbb,
40 0xb1, 0xcc, 0xe0, 0x32, 0x82, 0x02, 0x5d, 0x2b, 0x60, 0x39, 0xdb, 0xd2, 0x04, 0x56, 0xb4, 0x7e, 0xe6, 0x3a, 0x69, 0x0c, 0x8a, 0xf0, 0x00, 0xf4, 0x56, 0xb0, 0xa7, 0x1a, 0x37, 0x05, 0x4b, 0xeb, 0x8c, 0x87, 0x05, 0x37, 0x92, 0xf7, 0x93, 0x5d, 0x93, 0x32, 0x7d, 0x6e, 0xa6, 0xda, 0x10, 0x4b, 0x49, 0xae, 0x86, 0xe4, 0xb4, 0x4d, 0x98, 0x42, 0x3e, 0xd3, 0x42, 0x46, 0x5d, 0xdd, 0x2f, 0x97, 0xd4, 0xb9, 0x7f, 0xbe, 0xa0, 0x82, 0x04, 0x21, 0x30, 0x82, 0x04, 0x1d, 0x30, 0x82, 0x04, 0x19, 0x30, 0x82, 0x03, 0x01, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x15, 0xfa, 0xa9, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x81, 0x8c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
41 0x06, 0x13, 0x02, 0x49, 0x4c, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x53, 0x74, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6d, 0x20, 0x4c, 0x74, 0x64, 0x2e, 0x31, 0x2b, 0x30, 0x29, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x22, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x31, 0x38, 0x30, 0x36, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x2f, 0x53, 0x74, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x31, 0x20, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61,
42 0x74, 0x65, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x31, 0x32, 0x32, 0x31, 0x38, 0x33, 0x35, 0x33, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x31, 0x36, 0x33, 0x34, 0x5a, 0x30, 0x6e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x4c, 0x31, 0x31, 0x30, 0x2f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x28, 0x53, 0x74, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6d, 0x20, 0x4c, 0x74, 0x64, 0x2e, 0x20, 0x28, 0x53, 0x74, 0x61, 0x72, 0x74, 0x20, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x72, 0x63, 0x69, 0x61, 0x6c, 0x20, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x29, 0x31, 0x2c, 0x30, 0x2a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
43 0x23, 0x53, 0x74, 0x61, 0x72, 0x74, 0x43, 0x6f, 0x6d, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x31, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb9, 0x56, 0x1b, 0x4c, 0x45, 0x31, 0x87, 0x17, 0x17, 0x80, 0x84, 0xe9, 0x6e, 0x17, 0x8d, 0xf2, 0x25, 0x5e, 0x18, 0xed, 0x8d, 0x8e, 0xcc, 0x7c, 0x2b, 0x7b, 0x51, 0xa6, 0xc1, 0xc2, 0xe6, 0xbf, 0x0a, 0xa3, 0x60, 0x30, 0x66, 0xf1, 0x32, 0xfe, 0x10, 0xae, 0x97, 0xb5, 0x0e, 0x99, 0xfa, 0x24, 0xb8, 0x3f, 0xc5,
44 0x3d, 0xd2, 0x77, 0x74, 0x96, 0x38, 0x7d, 0x14, 0xe1, 0xc3, 0xa9, 0xb6, 0xa4, 0x93, 0x3e, 0x2a, 0xc1, 0x24, 0x13, 0xd0, 0x85, 0x57, 0x0a, 0x95, 0xb8, 0x14, 0x74, 0x14, 0xa0, 0xbc, 0x00, 0x7c, 0x7b, 0xcf, 0x22, 0x24, 0x46, 0xef, 0x7f, 0x1a, 0x15, 0x6d, 0x7e, 0xa1, 0xc5, 0x77, 0xfc, 0x5f, 0x0f, 0xac, 0xdf, 0xd4, 0x2e, 0xb0, 0xf5, 0x97, 0x49, 0x90, 0xcb, 0x2f, 0x5c, 0xef, 0xeb, 0xce, 0xef, 0x4d, 0x1b, 0xdc, 0x7a, 0xe5, 0xc1, 0x07, 0x5c, 0x5a, 0x99, 0xa9, 0x31, 0x71, 0xf2, 0xb0, 0x84, 0x5b, 0x4f, 0xf0, 0x86, 0x4e, 0x97, 0x3f, 0xcf, 0xe3, 0x2f, 0x9d, 0x75, 0x11, 0xff, 0x87, 0xa3, 0xe9, 0x43, 0x41, 0x0c, 0x90, 0xa4, 0x49, 0x3a, 0x30, 0x6b, 0x69, 0x44, 0x35, 0x93, 0x40, 0xa9, 0xca, 0x96, 0xf0, 0x2b, 0x66, 0xce, 0x67,
45 0xf0, 0x28, 0xdf, 0x29, 0x80, 0xa6, 0xaa, 0xee, 0x8d, 0x5d, 0x5d, 0x45, 0x2b, 0x8b, 0x0e, 0xb9, 0x3f, 0x92, 0x3c, 0xc1, 0xe2, 0x3f, 0xcc, 0xcb, 0xdb, 0xe7, 0xff, 0xcb, 0x11, 0x4d, 0x08, 0xfa, 0x7a, 0x6a, 0x3c, 0x40, 0x4f, 0x82, 0x5d, 0x1a, 0x0e, 0x71, 0x59, 0x35, 0xcf, 0x62, 0x3a, 0x8c, 0x7b, 0x59, 0x67, 0x00, 0x14, 0xed, 0x06, 0x22, 0xf6, 0x08, 0x9a, 0x94, 0x47, 0xa7, 0xa1, 0x90, 0x10, 0xf7, 0xfe, 0x58, 0xf8, 0x41, 0x29, 0xa2, 0x76, 0x5e, 0xa3, 0x67, 0x82, 0x4d, 0x1c, 0x3b, 0xb2, 0xfd, 0xa3, 0x08, 0x53, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x81, 0xa0, 0x30, 0x81, 0x9d, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x03, 0xa8,
46 0x30, 0x1e, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x17, 0x30, 0x15, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x05, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x45, 0xe0, 0xa3, 0x66, 0x95, 0x41, 0x4c, 0x5d, 0xd4, 0x49, 0xbc, 0x00, 0xe3, 0x3c, 0xdc, 0xdb, 0xd2, 0x34, 0x3e, 0x17, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xeb, 0x42, 0x34, 0xd0, 0x98, 0xb0, 0xab, 0x9f, 0xf4, 0x1b, 0x6b, 0x08, 0xf7, 0xcc, 0x64, 0x2e, 0xef, 0x0e, 0x2c, 0x45, 0x30, 0x23, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x1c, 0x30, 0x1a, 0x86, 0x18, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e,
47 0x73, 0x74, 0x61, 0x72, 0x74, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x42, 0xcd, 0x4c, 0x03, 0xd2, 0x9a, 0x55, 0xb2, 0xd6, 0x3e, 0x90, 0x4c, 0x89, 0x27, 0xd0, 0xcf, 0x87, 0xf6, 0x91, 0x9b, 0x86, 0x6a, 0x6d, 0x76, 0xd9, 0x5e, 0xbc, 0xc8, 0xfe, 0x74, 0xbe, 0x97, 0x29, 0xd1, 0xac, 0x92, 0x9b, 0x9e, 0x48, 0xab, 0xb1, 0xf4, 0xbe, 0xd5, 0x3f, 0xa8, 0x4c, 0xce, 0x0e, 0x2f, 0x39, 0x96, 0x4b, 0xde, 0xda, 0xac, 0x40, 0xce, 0xbb, 0x93, 0xdb, 0x1c, 0x39, 0x02, 0x03, 0x25, 0x32, 0x45, 0xde, 0x94, 0x5a, 0x63, 0xaf, 0xf7, 0xb0, 0x70, 0xc8, 0xcc, 0x2b, 0x34, 0x7b, 0x5f, 0x7d, 0xc6, 0x96, 0x1d, 0x59,
48 0x1d, 0xdd, 0x8f, 0x7e, 0x55, 0xc4, 0x92, 0x11, 0x8d, 0xd9, 0x11, 0x11, 0x22, 0x20, 0xd3, 0x56, 0x1e, 0x11, 0xae, 0x97, 0xf2, 0x71, 0xea, 0x8c, 0xf5, 0x15, 0x2d, 0xb1, 0x59, 0xdd, 0x3e, 0x43, 0x9c, 0xf1, 0xda, 0x81, 0xd7, 0xc8, 0x6c, 0xf6, 0x08, 0x5d, 0x6f, 0xdf, 0x26, 0xa8, 0xfe, 0x84, 0xa2, 0x08, 0xaf, 0xdb, 0x9b, 0x39, 0xf5, 0x46, 0xfa, 0x5b, 0xfa, 0x97, 0x64, 0x1d, 0xf1, 0xd4, 0xbc, 0xb0, 0xa4, 0x2f, 0x36, 0xf1, 0x90, 0xb5, 0x3b, 0x67, 0x0b, 0x5b, 0xf3, 0x24, 0x50, 0x27, 0x63, 0xdc, 0xeb, 0xb6, 0x55, 0x0f, 0xb7, 0xbe, 0xee, 0x2e, 0xfb, 0xc8, 0x6a, 0x10, 0xab, 0xee, 0x9a, 0x27, 0xe4, 0x13, 0x16, 0xcf, 0xdd, 0x13, 0xa7, 0x0f, 0xde, 0x61, 0x8c, 0xfa, 0xed, 0x2d, 0x00, 0x60, 0xf9, 0xc4, 0x3d, 0xad, 0xd6, 0xa2,
49 0xc0, 0xa3, 0x29, 0x11, 0x61, 0x0b, 0x65, 0xdb, 0x14, 0x79, 0xb1, 0x7d, 0x8a, 0x57, 0x91, 0x59, 0xa4, 0xfc, 0x4c, 0x60, 0x4f, 0x3c, 0xc8, 0x31, 0x9b, 0x69, 0x70, 0xb9, 0xae, 0xed, 0xb1, 0xde, 0x58, 0x8d, 0x62, 0x30, 0xb4, 0x7b, 0x46, 0xf2, 0xda, 0x7b, 0xbb, 0x72, 0xcf, 0xf0, 0x47, 0x8b, 0x84,
50 /* clang-format on */
51 };
52
53 /* This data format is bogus, but sufficient to test the server is able
54 to return correctly what has been configured. Once the client does
55 validation we will need real data here.
56 */
57 static uint8_t sct_list[] = {
58 0xff, 0xff, 0xff, 0xff, 0xff
59 };
60
61 int main(int argc, char **argv)
62 {
63 char *cert_chain = NULL;
64 char *private_key = NULL;
65
66 BEGIN_TEST();
67 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
68
69 EXPECT_NOT_NULL(cert_chain = malloc(S2N_MAX_TEST_PEM_SIZE));
70 EXPECT_NOT_NULL(private_key = malloc(S2N_MAX_TEST_PEM_SIZE));
71 EXPECT_SUCCESS(setenv("S2N_DONT_MLOCK", "1", 0));
72
73 /* Create nonblocking pipes */
74 struct s2n_test_io_pair io_pair;
75 EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
76
77 /* Client doesn't use the server name extension. */
78 {
79 struct s2n_connection *client_conn = NULL;
80 struct s2n_connection *server_conn = NULL;
81 struct s2n_config *server_config = NULL;
82 struct s2n_cert_chain_and_key *chain_and_key = NULL;
83
84 struct s2n_config *client_config = NULL;
85 EXPECT_NOT_NULL(client_config = s2n_config_new());
86 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
87 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
88 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
89 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
90 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
91 client_conn->actual_protocol_version = S2N_TLS12;
92 client_conn->server_protocol_version = S2N_TLS12;
93 client_conn->client_protocol_version = S2N_TLS12;
94
95 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
96 server_conn->actual_protocol_version = S2N_TLS12;
97 server_conn->server_protocol_version = S2N_TLS12;
98 server_conn->client_protocol_version = S2N_TLS12;
99
100 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
101
102 EXPECT_NOT_NULL(server_config = s2n_config_new());
103 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
104 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
105 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
106 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
107 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
108 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
109 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
110
111 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
112
113 /* Verify that the server didn't receive the server name. */
114 EXPECT_NULL(s2n_get_server_name(server_conn));
115
116 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
117
118 EXPECT_SUCCESS(s2n_connection_free(server_conn));
119 EXPECT_SUCCESS(s2n_connection_free(client_conn));
120
121 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
122 EXPECT_SUCCESS(s2n_config_free(server_config));
123 EXPECT_SUCCESS(s2n_config_free(client_config));
124 };
125
126 /* Client uses the server name extension. */
127 {
128 struct s2n_connection *client_conn = NULL;
129 struct s2n_connection *server_conn = NULL;
130 struct s2n_config *server_config = NULL;
131 struct s2n_cert_chain_and_key *chain_and_key = NULL;
132
133 const char *sent_server_name = "www.alligator.com";
134 const char *received_server_name = NULL;
135
136 struct s2n_config *client_config = NULL;
137 EXPECT_NOT_NULL(client_config = s2n_config_new());
138 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
139 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
140 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
141 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
142 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
143 client_conn->actual_protocol_version = S2N_TLS12;
144 client_conn->server_protocol_version = S2N_TLS12;
145 client_conn->client_protocol_version = S2N_TLS12;
146
147 /* Set the server name */
148 EXPECT_SUCCESS(s2n_set_server_name(client_conn, sent_server_name));
149
150 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
151 server_conn->actual_protocol_version = S2N_TLS12;
152 server_conn->server_protocol_version = S2N_TLS12;
153 server_conn->client_protocol_version = S2N_TLS12;
154
155 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
156
157 EXPECT_NOT_NULL(server_config = s2n_config_new());
158 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
159 EXPECT_SUCCESS(s2n_read_test_pem(S2N_ALLIGATOR_SAN_CERT, cert_chain, S2N_MAX_TEST_PEM_SIZE));
160 EXPECT_SUCCESS(s2n_read_test_pem(S2N_ALLIGATOR_SAN_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
161 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
162 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
163 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
164 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
165
166 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
167
168 /* Verify that the server name was received intact. */
169 EXPECT_NOT_NULL(received_server_name = s2n_get_server_name(server_conn));
170 EXPECT_EQUAL(strlen(received_server_name), strlen(sent_server_name));
171 EXPECT_BYTEARRAY_EQUAL(received_server_name, sent_server_name, strlen(received_server_name));
172
173 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
174
175 EXPECT_SUCCESS(s2n_connection_free(server_conn));
176 EXPECT_SUCCESS(s2n_connection_free(client_conn));
177
178 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
179
180 EXPECT_SUCCESS(s2n_config_free(server_config));
181 EXPECT_SUCCESS(s2n_config_free(client_config));
182 };
183
184 /* Client sends multiple server names. */
185 {
186 struct s2n_connection *server_conn = NULL;
187 struct s2n_config *server_config = NULL;
188 s2n_blocked_status server_blocked;
189 const char *sent_server_name = "svr";
190 const char *received_server_name = NULL;
191 struct s2n_cert_chain_and_key *chain_and_key = NULL;
192 uint32_t cert_chain_len = 0;
193 uint32_t private_key_len = 0;
194
195 uint8_t client_extensions[] = {
196 /* Extension type TLS_EXTENSION_SERVER_NAME */
197 0x00,
198 0x00,
199 /* Extension size */
200 0x00,
201 0x0C,
202 /* All server names len */
203 0x00,
204 0x0A,
205 /* First server name type - host name */
206 0x00,
207 /* First server name len */
208 0x00,
209 0x03,
210 /* First server name, matches sent_server_name */
211 's',
212 'v',
213 'r',
214 /* Second server name type - host name */
215 0x00,
216 /* Second server name len */
217 0x00,
218 0x01,
219 /* Second server name */
220 0xFF,
221 };
222 int client_extensions_len = sizeof(client_extensions);
223 uint8_t client_hello_message[] = {
224 /* Protocol version TLS 1.2 */
225 0x03,
226 0x03,
227 /* Client random */
228 ZERO_TO_THIRTY_ONE,
229 /* SessionID len - 32 bytes */
230 0x20,
231 /* Session ID */
232 ZERO_TO_THIRTY_ONE,
233 /* Cipher suites len */
234 0x00,
235 0x02,
236 /* Cipher suite - TLS_RSA_WITH_AES_128_CBC_SHA256 */
237 0x00,
238 0x3C,
239 /* Compression methods len */
240 0x01,
241 /* Compression method - none */
242 0x00,
243 /* Extensions len */
244 (client_extensions_len >> 8) & 0xff,
245 (client_extensions_len & 0xff),
246 };
247 int body_len = sizeof(client_hello_message) + client_extensions_len;
248 uint8_t message_header[] = {
249 /* Handshake message type CLIENT HELLO */
250 0x01,
251 /* Body len */
252 (body_len >> 16) & 0xff,
253 (body_len >> 8) & 0xff,
254 (body_len & 0xff),
255 };
256 int message_len = sizeof(message_header) + body_len;
257 uint8_t record_header[] = {
258 /* Record type HANDSHAKE */
259 0x16,
260 /* Protocol version garbage value. s2n should still accept this. */
261 0x01,
262 0x01,
263 /* Message len */
264 (message_len >> 8) & 0xff,
265 (message_len & 0xff),
266 };
267
268 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
269 server_conn->actual_protocol_version = S2N_TLS12;
270 server_conn->server_protocol_version = S2N_TLS12;
271 server_conn->client_protocol_version = S2N_TLS12;
272 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
273
274 EXPECT_NOT_NULL(server_config = s2n_config_new());
275 /* Security policy must allow cipher suite hard coded into client hello */
276 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "test_all"));
277 EXPECT_SUCCESS(s2n_read_test_pem_and_len(S2N_DEFAULT_TEST_CERT_CHAIN, (uint8_t *) cert_chain, &cert_chain_len, S2N_MAX_TEST_PEM_SIZE));
278 EXPECT_SUCCESS(s2n_read_test_pem_and_len(S2N_DEFAULT_TEST_PRIVATE_KEY, (uint8_t *) private_key, &private_key_len, S2N_MAX_TEST_PEM_SIZE));
279 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
280 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem_bytes(chain_and_key, (uint8_t *) cert_chain, cert_chain_len, (uint8_t *) private_key, private_key_len));
281 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
282 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
283
284 /* Send the client hello */
285 EXPECT_EQUAL(s2n_test_send(io_pair.client, record_header, sizeof(record_header)), sizeof(record_header));
286 EXPECT_EQUAL(s2n_test_send(io_pair.client, message_header, sizeof(message_header)), sizeof(message_header));
287 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_hello_message, sizeof(client_hello_message)), sizeof(client_hello_message));
288 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_extensions, sizeof(client_extensions)), sizeof(client_extensions));
289
290 /* Verify that the CLIENT HELLO is accepted */
291 s2n_negotiate(server_conn, &server_blocked);
292 EXPECT_TRUE(s2n_conn_get_current_message_type(server_conn) > CLIENT_HELLO);
293 EXPECT_EQUAL(server_conn->handshake.handshake_type, NEGOTIATED | FULL_HANDSHAKE);
294
295 /* Verify that the server name was received intact. */
296 EXPECT_NOT_NULL(received_server_name = s2n_get_server_name(server_conn));
297 EXPECT_EQUAL(strlen(received_server_name), strlen(sent_server_name));
298 EXPECT_BYTEARRAY_EQUAL(received_server_name, sent_server_name, strlen(received_server_name));
299
300 EXPECT_SUCCESS(s2n_shutdown(server_conn, &server_blocked));
301 EXPECT_TRUE(server_conn->alert_sent);
302
303 EXPECT_SUCCESS(s2n_connection_free(server_conn));
304
305 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
306
307 EXPECT_SUCCESS(s2n_config_free(server_config));
308 };
309
310 /* Client sends duplicate server name extension */
311 {
312 struct s2n_connection *server_conn = NULL;
313 struct s2n_config *server_config = NULL;
314 s2n_blocked_status server_blocked;
315 struct s2n_cert_chain_and_key *chain_and_key = NULL;
316
317 uint8_t client_extensions[] = {
318 /* Extension type TLS_EXTENSION_SERVER_NAME */
319 0x00,
320 0x00,
321 /* Extension size */
322 0x00,
323 0x0C,
324 /* All server names len */
325 0x00,
326 0x0A,
327 /* First server name type - host name */
328 0x00,
329 /* First server name len */
330 0x00,
331 0x03,
332 /* First server name, matches sent_server_name */
333 's',
334 'v',
335 'r',
336 /* Second server name type - host name */
337 0x00,
338 /* Second server name len */
339 0x00,
340 0x01,
341 /* Second server name */
342 0xFF,
343 /* And all that again... */
344 /* Extension type TLS_EXTENSION_SERVER_NAME */
345 0x00,
346 0x00,
347 /* Extension size */
348 0x00,
349 0x0C,
350 /* All server names len */
351 0x00,
352 0x0A,
353 /* First server name type - host name */
354 0x00,
355 /* First server name len */
356 0x00,
357 0x03,
358 /* First server name, matches sent_server_name */
359 's',
360 'v',
361 'r',
362 /* Second server name type - host name */
363 0x00,
364 /* Second server name len */
365 0x00,
366 0x01,
367 /* Second server name */
368 0xFF,
369 };
370 int client_extensions_len = sizeof(client_extensions);
371 uint8_t client_hello_message[] = {
372 /* Protocol version TLS 1.2 */
373 0x03,
374 0x03,
375 /* Client random */
376 ZERO_TO_THIRTY_ONE,
377 /* SessionID len - 32 bytes */
378 0x20,
379 /* Session ID */
380 ZERO_TO_THIRTY_ONE,
381 /* Cipher suites len */
382 0x00,
383 0x02,
384 /* Cipher suite - TLS_RSA_WITH_AES_128_CBC_SHA256 */
385 0x00,
386 0x3C,
387 /* Compression methods len */
388 0x01,
389 /* Compression method - none */
390 0x00,
391 /* Extensions len */
392 (client_extensions_len >> 8) & 0xff,
393 (client_extensions_len & 0xff),
394 };
395 int body_len = sizeof(client_hello_message) + client_extensions_len;
396 uint8_t message_header[] = {
397 /* Handshake message type CLIENT HELLO */
398 0x01,
399 /* Body len */
400 (body_len >> 16) & 0xff,
401 (body_len >> 8) & 0xff,
402 (body_len & 0xff),
403 };
404 int message_len = sizeof(message_header) + body_len;
405 uint8_t record_header[] = {
406 /* Record type HANDSHAKE */
407 0x16,
408 /* Protocol version TLS 1.2 */
409 0x03,
410 0x03,
411 /* Message len */
412 (message_len >> 8) & 0xff,
413 (message_len & 0xff),
414 };
415
416 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
417 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
418
419 EXPECT_NOT_NULL(server_config = s2n_config_new());
420 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
421 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
422 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
423 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
424 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
425 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
426 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
427
428 /* Send the client hello */
429 EXPECT_EQUAL(s2n_test_send(io_pair.client, record_header, sizeof(record_header)), sizeof(record_header));
430 EXPECT_EQUAL(s2n_test_send(io_pair.client, message_header, sizeof(message_header)), sizeof(message_header));
431 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_hello_message, sizeof(client_hello_message)), sizeof(client_hello_message));
432 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_extensions, sizeof(client_extensions)), sizeof(client_extensions));
433
434 /* Verify that we fail for duplicated extension type Bad Message */
435 EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
436 s2n_negotiate(server_conn, &server_blocked);
437 EXPECT_EQUAL(s2n_errno, S2N_ERR_DUPLICATE_EXTENSION);
438
439 EXPECT_SUCCESS(s2n_connection_free(server_conn));
440
441 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
442
443 EXPECT_SUCCESS(s2n_config_free(server_config));
444 };
445
446 /* Client sends a valid initial renegotiation_info */
447 {
448 struct s2n_connection *server_conn = NULL;
449 struct s2n_config *server_config = NULL;
450 s2n_blocked_status server_blocked;
451 struct s2n_cert_chain_and_key *chain_and_key = NULL;
452
453 uint8_t client_extensions[] = {
454 /* Extension type TLS_EXTENSION_RENEGOTIATION_INFO */
455 0xff,
456 0x01,
457 /* Extension size */
458 0x00,
459 0x01,
460 /* Empty renegotiated_connection */
461 0x00,
462 };
463 int client_extensions_len = sizeof(client_extensions);
464 uint8_t client_hello_message[] = {
465 /* Protocol version TLS 1.2 */
466 0x03,
467 0x03,
468 /* Client random */
469 ZERO_TO_THIRTY_ONE,
470 /* SessionID len - 32 bytes */
471 0x20,
472 /* Session ID */
473 ZERO_TO_THIRTY_ONE,
474 /* Cipher suites len */
475 0x00,
476 0x02,
477 /* Cipher suite - TLS_RSA_WITH_AES_128_CBC_SHA256 */
478 0x00,
479 0x3C,
480 /* Compression methods len */
481 0x01,
482 /* Compression method - none */
483 0x00,
484 /* Extensions len */
485 (client_extensions_len >> 8) & 0xff,
486 (client_extensions_len & 0xff),
487 };
488 int body_len = sizeof(client_hello_message) + client_extensions_len;
489 uint8_t message_header[] = {
490 /* Handshake message type CLIENT HELLO */
491 0x01,
492 /* Body len */
493 (body_len >> 16) & 0xff,
494 (body_len >> 8) & 0xff,
495 (body_len & 0xff),
496 };
497 int message_len = sizeof(message_header) + body_len;
498 uint8_t record_header[] = {
499 /* Record type HANDSHAKE */
500 0x16,
501 /* Protocol version TLS 1.2 */
502 0x03,
503 0x03,
504 /* Message len */
505 (message_len >> 8) & 0xff,
506 (message_len & 0xff),
507 };
508
509 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
510 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
511
512 EXPECT_NOT_NULL(server_config = s2n_config_new());
513 /* Security policy must allow cipher suite hard coded into client hello */
514 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "test_all"));
515 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
516 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
517 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
518 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
519 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
520 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
521
522 /* Send the client hello */
523 EXPECT_EQUAL(s2n_test_send(io_pair.client, record_header, sizeof(record_header)), sizeof(record_header));
524 EXPECT_EQUAL(s2n_test_send(io_pair.client, message_header, sizeof(message_header)), sizeof(message_header));
525 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_hello_message, sizeof(client_hello_message)), sizeof(client_hello_message));
526 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_extensions, sizeof(client_extensions)), sizeof(client_extensions));
527
528 /* Verify that the CLIENT HELLO is accepted */
529 s2n_negotiate(server_conn, &server_blocked);
530 EXPECT_TRUE(s2n_conn_get_current_message_type(server_conn) > CLIENT_HELLO);
531 EXPECT_EQUAL(server_conn->handshake.handshake_type & NEGOTIATED, NEGOTIATED);
532
533 /* Verify that the that we detected secure_renegotiation */
534 EXPECT_EQUAL(server_conn->secure_renegotiation, 1);
535
536 EXPECT_SUCCESS(s2n_shutdown(server_conn, &server_blocked));
537 EXPECT_TRUE(server_conn->alert_sent);
538
539 EXPECT_SUCCESS(s2n_connection_free(server_conn));
540
541 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
542
543 EXPECT_SUCCESS(s2n_config_free(server_config));
544 };
545
546 /* Client sends a non-empty initial renegotiation_info */
547 {
548 struct s2n_connection *server_conn = NULL;
549 struct s2n_config *server_config = NULL;
550 s2n_blocked_status server_blocked;
551 struct s2n_cert_chain_and_key *chain_and_key = NULL;
552 uint8_t buf[5120];
553
554 uint8_t client_extensions[] = {
555 /* Extension type TLS_EXTENSION_RENEGOTIATION_INFO */
556 0xff,
557 0x01,
558 /* Extension size */
559 0x00,
560 0x21,
561 /* renegotiated_connection len */
562 0x20,
563 /* fake renegotiated_connection */
564 ZERO_TO_THIRTY_ONE,
565 };
566 int client_extensions_len = sizeof(client_extensions);
567 uint8_t client_hello_message[] = {
568 /* Protocol version TLS 1.2 */
569 0x03,
570 0x03,
571 /* Client random */
572 ZERO_TO_THIRTY_ONE,
573 /* SessionID len - 32 bytes */
574 0x20,
575 /* Session ID */
576 ZERO_TO_THIRTY_ONE,
577 /* Cipher suites len */
578 0x00,
579 0x02,
580 /* Cipher suite - TLS_RSA_WITH_AES_128_CBC_SHA256 */
581 0x00,
582 0x3C,
583 /* Compression methods len */
584 0x01,
585 /* Compression method - none */
586 0x00,
587 /* Extensions len */
588 (client_extensions_len >> 8) & 0xff,
589 (client_extensions_len & 0xff),
590 };
591 int body_len = sizeof(client_hello_message) + client_extensions_len;
592 uint8_t message_header[] = {
593 /* Handshake message type CLIENT HELLO */
594 0x01,
595 /* Body len */
596 (body_len >> 16) & 0xff,
597 (body_len >> 8) & 0xff,
598 (body_len & 0xff),
599 };
600 int message_len = sizeof(message_header) + body_len;
601 uint8_t record_header[] = {
602 /* Record type HANDSHAKE */
603 0x16,
604 /* Protocol version TLS 1.2 */
605 0x03,
606 0x03,
607 /* Message len */
608 (message_len >> 8) & 0xff,
609 (message_len & 0xff),
610 };
611
612 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
613 EXPECT_SUCCESS(s2n_connection_set_io_pair(server_conn, &io_pair));
614
615 EXPECT_NOT_NULL(server_config = s2n_config_new());
616 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
617 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
618 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
619 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
620 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
621 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
622 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
623
624 /* Send the client hello */
625 EXPECT_EQUAL(s2n_test_send(io_pair.client, record_header, sizeof(record_header)), sizeof(record_header));
626 EXPECT_EQUAL(s2n_test_send(io_pair.client, message_header, sizeof(message_header)), sizeof(message_header));
627 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_hello_message, sizeof(client_hello_message)), sizeof(client_hello_message));
628 EXPECT_EQUAL(s2n_test_send(io_pair.client, client_extensions, sizeof(client_extensions)), sizeof(client_extensions));
629
630 /* Verify that we fail for non-empty renegotiated_connection */
631 EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
632 s2n_negotiate(server_conn, &server_blocked);
633 EXPECT_EQUAL(s2n_errno, S2N_ERR_NON_EMPTY_RENEGOTIATION_INFO);
634
635 EXPECT_SUCCESS(s2n_connection_free(server_conn));
636 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
637 EXPECT_SUCCESS(s2n_config_free(server_config));
638
639 /* Clear pipe since negotiation failed mid-handshake */
640 EXPECT_SUCCESS(s2n_test_recv(io_pair.client, buf, sizeof(buf)));
641 };
642
643 /* Client doesn't use the OCSP extension. */
644 {
645 struct s2n_connection *client_conn = NULL;
646 struct s2n_connection *server_conn = NULL;
647 struct s2n_config *server_config = NULL;
648 uint32_t length = 0;
649
650 struct s2n_config *client_config = NULL;
651 EXPECT_NOT_NULL(client_config = s2n_config_new());
652 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
653 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
654 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
655 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
656 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
657 client_conn->actual_protocol_version = S2N_TLS12;
658 client_conn->server_protocol_version = S2N_TLS12;
659 client_conn->client_protocol_version = S2N_TLS12;
660
661 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
662 server_conn->actual_protocol_version = S2N_TLS12;
663 server_conn->server_protocol_version = S2N_TLS12;
664 server_conn->client_protocol_version = S2N_TLS12;
665
666 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
667
668 EXPECT_NOT_NULL(server_config = s2n_config_new());
669 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
670 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
671 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
672 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key(server_config, cert_chain, private_key));
673 EXPECT_SUCCESS(s2n_config_set_extension_data(server_config, S2N_EXTENSION_OCSP_STAPLING,
674 server_ocsp_status_bytes, sizeof(server_ocsp_status_bytes)));
675 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
676
677 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
678
679 /* Verify that the server didn't send an OCSP response. */
680 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(server_conn), 0);
681
682 /* Verify that the client didn't receive an OCSP response. */
683 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(client_conn), 0);
684 EXPECT_NULL(s2n_connection_get_ocsp_response(client_conn, &length));
685 EXPECT_EQUAL(length, 0);
686
687 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
688
689 EXPECT_SUCCESS(s2n_connection_free(server_conn));
690 EXPECT_SUCCESS(s2n_connection_free(client_conn));
691
692 EXPECT_SUCCESS(s2n_config_free(server_config));
693 EXPECT_SUCCESS(s2n_config_free(client_config));
694 };
695
696 /* Cannot enable OCSP stapling if there's no support for it */
697 if (!s2n_x509_ocsp_stapling_supported()) {
698 struct s2n_config *client_config = NULL;
699 EXPECT_NOT_NULL(client_config = s2n_config_new());
700 EXPECT_FAILURE(s2n_config_set_check_stapled_ocsp_response(client_config, 1));
701 EXPECT_SUCCESS(s2n_config_free(client_config));
702 }
703
704 /* Server doesn't support the OCSP extension. We can't run this test if ocsp isn't supported by the client. */
705 if (s2n_x509_ocsp_stapling_supported()) {
706 struct s2n_connection *client_conn = NULL;
707 struct s2n_connection *server_conn = NULL;
708 struct s2n_config *server_config = NULL;
709 struct s2n_config *client_config = NULL;
710 uint32_t length = 0;
711 struct s2n_cert_chain_and_key *chain_and_key = NULL;
712
713 EXPECT_NOT_NULL(client_config = s2n_config_new());
714 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
715 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
716 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
717 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
718 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
719 client_conn->actual_protocol_version = S2N_TLS12;
720 client_conn->server_protocol_version = S2N_TLS12;
721 client_conn->client_protocol_version = S2N_TLS12;
722
723 EXPECT_SUCCESS(s2n_config_set_status_request_type(client_config, S2N_STATUS_REQUEST_OCSP));
724 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
725
726 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
727 server_conn->actual_protocol_version = S2N_TLS12;
728 server_conn->server_protocol_version = S2N_TLS12;
729 server_conn->client_protocol_version = S2N_TLS12;
730
731 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
732
733 EXPECT_NOT_NULL(server_config = s2n_config_new());
734 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
735 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
736 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
737 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
738 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
739 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
740 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
741
742 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
743
744 /* Verify that the server didn't send an OCSP response. */
745 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(server_conn), 0);
746
747 /* Verify that the client didn't receive an OCSP response. */
748 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(client_conn), 0);
749 EXPECT_NULL(s2n_connection_get_ocsp_response(client_conn, &length));
750 EXPECT_EQUAL(length, 0);
751
752 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
753
754 EXPECT_SUCCESS(s2n_connection_free(server_conn));
755 EXPECT_SUCCESS(s2n_connection_free(client_conn));
756
757 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
758
759 EXPECT_SUCCESS(s2n_config_free(server_config));
760 EXPECT_SUCCESS(s2n_config_free(client_config));
761 }
762
763 /* Test with s2n_config_set_extension_data(). Can be removed once API is deprecated */
764 if (s2n_x509_ocsp_stapling_supported()) {
765 struct s2n_connection *client_conn = NULL;
766 struct s2n_connection *server_conn = NULL;
767 struct s2n_config *server_config = NULL;
768 struct s2n_config *client_config = NULL;
769 const uint8_t *server_ocsp_reply = NULL;
770 uint32_t length = 0;
771
772 EXPECT_NOT_NULL(client_config = s2n_config_new());
773 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
774 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
775 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
776 EXPECT_SUCCESS(s2n_config_set_status_request_type(client_config, S2N_STATUS_REQUEST_OCSP));
777
778 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
779 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
780
781 EXPECT_NOT_NULL(server_config = s2n_config_new());
782 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
783 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
784 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
785 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key(server_config, cert_chain, private_key));
786 EXPECT_SUCCESS(s2n_config_set_extension_data(server_config, S2N_EXTENSION_OCSP_STAPLING,
787 server_ocsp_status_bytes, sizeof(server_ocsp_status_bytes)));
788
789 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
790 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
791
792 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
793
794 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
795
796 /* Verify that the server sent an OCSP response. */
797 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(server_conn), 1);
798
799 /* Verify that the client received an OCSP response. */
800 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(client_conn), 1);
801 EXPECT_NOT_NULL(server_ocsp_reply = s2n_connection_get_ocsp_response(client_conn, &length));
802 EXPECT_EQUAL(length, sizeof(server_ocsp_status_bytes));
803
804 for (size_t i = 0; i < sizeof(server_ocsp_status_bytes); i++) {
805 EXPECT_EQUAL(server_ocsp_reply[i], server_ocsp_status_bytes[i]);
806 }
807
808 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
809
810 EXPECT_SUCCESS(s2n_connection_free(server_conn));
811 EXPECT_SUCCESS(s2n_connection_free(client_conn));
812 EXPECT_SUCCESS(s2n_config_free(server_config));
813 EXPECT_SUCCESS(s2n_config_free(client_config));
814 }
815
816 /* Server and client support the OCSP extension. Test only runs if ocsp stapled responses are supported by the client */
817 if (s2n_x509_ocsp_stapling_supported()) {
818 struct s2n_connection *client_conn = NULL;
819 struct s2n_connection *server_conn = NULL;
820 struct s2n_config *server_config = NULL;
821 struct s2n_config *client_config = NULL;
822 const uint8_t *server_ocsp_reply = NULL;
823 uint32_t length = 0;
824
825 EXPECT_NOT_NULL(client_config = s2n_config_new());
826 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
827 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
828 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
829 EXPECT_SUCCESS(s2n_config_set_status_request_type(client_config, S2N_STATUS_REQUEST_OCSP));
830
831 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
832 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
833 client_conn->actual_protocol_version = S2N_TLS12;
834 client_conn->server_protocol_version = S2N_TLS12;
835 client_conn->client_protocol_version = S2N_TLS12;
836
837 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
838 server_conn->actual_protocol_version = S2N_TLS12;
839 server_conn->server_protocol_version = S2N_TLS12;
840 server_conn->client_protocol_version = S2N_TLS12;
841
842 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
843
844 EXPECT_NOT_NULL(server_config = s2n_config_new());
845 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
846 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
847 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
848 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key(server_config, cert_chain, private_key));
849 EXPECT_SUCCESS(s2n_config_set_extension_data(server_config, S2N_EXTENSION_OCSP_STAPLING,
850 server_ocsp_status_bytes, sizeof(server_ocsp_status_bytes)));
851 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
852
853 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
854
855 /* Verify that the server sent an OCSP response. */
856 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(server_conn), 1);
857
858 /* Verify that the client received an OCSP response. */
859 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(client_conn), 1);
860 EXPECT_NOT_NULL(server_ocsp_reply = s2n_connection_get_ocsp_response(client_conn, &length));
861 EXPECT_EQUAL(length, sizeof(server_ocsp_status_bytes));
862
863 for (size_t i = 0; i < sizeof(server_ocsp_status_bytes); i++) {
864 EXPECT_EQUAL(server_ocsp_reply[i], server_ocsp_status_bytes[i]);
865 }
866
867 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
868
869 EXPECT_SUCCESS(s2n_connection_free(server_conn));
870 EXPECT_SUCCESS(s2n_connection_free(client_conn));
871
872 EXPECT_SUCCESS(s2n_config_free(server_config));
873 EXPECT_SUCCESS(s2n_config_free(client_config));
874 }
875
876 /* Server and client support the OCSP extension. Test Behavior for TLS 1.3 */
877 if (s2n_x509_ocsp_stapling_supported() && s2n_is_tls13_fully_supported()) {
878 struct s2n_connection *client_conn = NULL;
879 struct s2n_connection *server_conn = NULL;
880 struct s2n_config *server_config = NULL;
881 struct s2n_config *client_config = NULL;
882 const uint8_t *server_ocsp_reply = NULL;
883 uint32_t length = 0;
884
885 EXPECT_SUCCESS(s2n_enable_tls13_in_test());
886
887 EXPECT_NOT_NULL(client_config = s2n_config_new());
888 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(client_config, "default_tls13"));
889 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
890 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
891 EXPECT_SUCCESS(s2n_config_set_status_request_type(client_config, S2N_STATUS_REQUEST_OCSP));
892
893 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
894 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
895 client_conn->actual_protocol_version = S2N_TLS13;
896 client_conn->server_protocol_version = S2N_TLS13;
897 client_conn->client_protocol_version = S2N_TLS13;
898
899 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
900 server_conn->actual_protocol_version = S2N_TLS13;
901 server_conn->server_protocol_version = S2N_TLS13;
902 server_conn->client_protocol_version = S2N_TLS13;
903
904 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
905
906 EXPECT_NOT_NULL(server_config = s2n_config_new());
907 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(server_config, "default_tls13"));
908 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_ECDSA_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
909 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_ECDSA_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
910 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key(server_config, cert_chain, private_key));
911 EXPECT_SUCCESS(s2n_config_set_extension_data(server_config, S2N_EXTENSION_OCSP_STAPLING,
912 server_ocsp_status_bytes, sizeof(server_ocsp_status_bytes)));
913 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
914
915 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
916
917 /* Verify that the server sent an OCSP response. */
918 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(server_conn), 1);
919
920 /* Verify that the client received an OCSP response. */
921 EXPECT_EQUAL(s2n_connection_is_ocsp_stapled(client_conn), 1);
922
923 EXPECT_NOT_NULL(server_ocsp_reply = s2n_connection_get_ocsp_response(client_conn, &length));
924 EXPECT_EQUAL(length, sizeof(server_ocsp_status_bytes));
925
926 for (size_t i = 0; i < sizeof(server_ocsp_status_bytes); i++) {
927 EXPECT_EQUAL(server_ocsp_reply[i], server_ocsp_status_bytes[i]);
928 }
929
930 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
931
932 EXPECT_SUCCESS(s2n_connection_free(server_conn));
933 EXPECT_SUCCESS(s2n_connection_free(client_conn));
934
935 EXPECT_SUCCESS(s2n_config_free(server_config));
936 EXPECT_SUCCESS(s2n_config_free(client_config));
937
938 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
939 }
940
941 /* Client does not request SCT, but server is configured to serve them. */
942 {
943 struct s2n_connection *client_conn = NULL;
944 struct s2n_connection *server_conn = NULL;
945 struct s2n_config *server_config = NULL;
946
947 uint32_t length = 0;
948
949 struct s2n_config *client_config = NULL;
950 EXPECT_NOT_NULL(client_config = s2n_config_new());
951 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
952 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
953 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
954 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
955 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
956 client_conn->actual_protocol_version = S2N_TLS12;
957 client_conn->server_protocol_version = S2N_TLS12;
958 client_conn->client_protocol_version = S2N_TLS12;
959
960 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
961 server_conn->actual_protocol_version = S2N_TLS12;
962 server_conn->server_protocol_version = S2N_TLS12;
963 server_conn->client_protocol_version = S2N_TLS12;
964
965 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
966
967 EXPECT_NOT_NULL(server_config = s2n_config_new());
968 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
969 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
970 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
971 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key(server_config, cert_chain, private_key));
972 EXPECT_SUCCESS(s2n_config_set_extension_data(server_config, S2N_EXTENSION_CERTIFICATE_TRANSPARENCY,
973 sct_list, sizeof(sct_list)));
974 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
975
976 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
977
978 /* Verify that the client did *not* receive an SCT list */
979 EXPECT_NULL(s2n_connection_get_sct_list(client_conn, &length));
980 EXPECT_EQUAL(length, 0);
981
982 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
983
984 EXPECT_SUCCESS(s2n_connection_free(server_conn));
985 EXPECT_SUCCESS(s2n_connection_free(client_conn));
986
987 EXPECT_SUCCESS(s2n_config_free(client_config));
988 EXPECT_SUCCESS(s2n_config_free(server_config));
989 };
990
991 /* Client requests SCT and server does have it. */
992 {
993 struct s2n_connection *client_conn = NULL;
994 struct s2n_connection *server_conn = NULL;
995 struct s2n_config *client_config = NULL;
996 struct s2n_config *server_config = NULL;
997
998 uint32_t length = 0;
999
1000 EXPECT_NOT_NULL(client_config = s2n_config_new());
1001 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
1002 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
1003 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
1004 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
1005 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1006 client_conn->actual_protocol_version = S2N_TLS12;
1007 client_conn->server_protocol_version = S2N_TLS12;
1008 client_conn->client_protocol_version = S2N_TLS12;
1009
1010 /* Indicate that the client wants CT if available */
1011 EXPECT_SUCCESS(s2n_config_set_ct_support_level(client_config, S2N_CT_SUPPORT_REQUEST));
1012 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1013
1014 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
1015 server_conn->actual_protocol_version = S2N_TLS12;
1016 server_conn->server_protocol_version = S2N_TLS12;
1017 server_conn->client_protocol_version = S2N_TLS12;
1018
1019 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
1020
1021 EXPECT_NOT_NULL(server_config = s2n_config_new());
1022 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
1023 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
1024 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
1025 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key(server_config, cert_chain, private_key));
1026 EXPECT_SUCCESS(s2n_config_set_extension_data(server_config, S2N_EXTENSION_CERTIFICATE_TRANSPARENCY,
1027 sct_list, sizeof(sct_list)));
1028 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
1029
1030 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
1031
1032 /* Verify that the client did receive an SCT list */
1033 EXPECT_NOT_NULL(s2n_connection_get_sct_list(client_conn, &length));
1034 EXPECT_EQUAL(length, sizeof(sct_list));
1035
1036 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
1037
1038 EXPECT_SUCCESS(s2n_connection_free(server_conn));
1039 EXPECT_SUCCESS(s2n_connection_free(client_conn));
1040
1041 EXPECT_SUCCESS(s2n_config_free(server_config));
1042 EXPECT_SUCCESS(s2n_config_free(client_config));
1043 };
1044
1045 /* Client requests SCT and server does *not* have it. */
1046 {
1047 struct s2n_connection *client_conn = NULL;
1048 struct s2n_connection *server_conn = NULL;
1049 struct s2n_config *client_config = NULL;
1050 struct s2n_config *server_config = NULL;
1051 struct s2n_cert_chain_and_key *chain_and_key = NULL;
1052
1053 uint32_t length = 0;
1054
1055 EXPECT_NOT_NULL(client_config = s2n_config_new());
1056 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
1057 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
1058 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
1059 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
1060 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1061 client_conn->actual_protocol_version = S2N_TLS12;
1062 client_conn->server_protocol_version = S2N_TLS12;
1063 client_conn->client_protocol_version = S2N_TLS12;
1064
1065 /* Indicate that the client wants CT if available */
1066 EXPECT_SUCCESS(s2n_config_set_ct_support_level(client_config, S2N_CT_SUPPORT_REQUEST));
1067 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1068
1069 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
1070 server_conn->actual_protocol_version = S2N_TLS12;
1071 server_conn->server_protocol_version = S2N_TLS12;
1072 server_conn->client_protocol_version = S2N_TLS12;
1073
1074 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
1075
1076 EXPECT_NOT_NULL(server_config = s2n_config_new());
1077 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
1078 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_CERT_CHAIN, cert_chain, S2N_MAX_TEST_PEM_SIZE));
1079 EXPECT_SUCCESS(s2n_read_test_pem(S2N_DEFAULT_TEST_PRIVATE_KEY, private_key, S2N_MAX_TEST_PEM_SIZE));
1080 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
1081 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
1082 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
1083 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
1084
1085 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
1086
1087 /* Verify that the client does not get a list */
1088 EXPECT_NULL(s2n_connection_get_sct_list(client_conn, &length));
1089 EXPECT_EQUAL(length, 0);
1090
1091 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
1092
1093 EXPECT_SUCCESS(s2n_connection_free(server_conn));
1094 EXPECT_SUCCESS(s2n_connection_free(client_conn));
1095
1096 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
1097
1098 EXPECT_SUCCESS(s2n_config_free(server_config));
1099 EXPECT_SUCCESS(s2n_config_free(client_config));
1100 };
1101
1102 /* Client requests 512, 1024, 2048, and 4096 maximum fragment lengths */
1103 for (uint8_t mfl_code = S2N_TLS_MAX_FRAG_LEN_512; mfl_code <= S2N_TLS_MAX_FRAG_LEN_4096; mfl_code++) {
1104 struct s2n_connection *client_conn = NULL;
1105 struct s2n_connection *server_conn = NULL;
1106 struct s2n_config *server_config = NULL;
1107 struct s2n_config *client_config = NULL;
1108 struct s2n_cert_chain_and_key *chain_and_key = NULL;
1109
1110 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
1111 client_conn->actual_protocol_version = S2N_TLS12;
1112 client_conn->server_protocol_version = S2N_TLS12;
1113 client_conn->client_protocol_version = S2N_TLS12;
1114
1115 EXPECT_NOT_NULL(client_config = s2n_config_new());
1116 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
1117 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
1118 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
1119
1120 EXPECT_SUCCESS(s2n_config_send_max_fragment_length(client_config, mfl_code));
1121 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1122
1123 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
1124 server_conn->actual_protocol_version = S2N_TLS12;
1125 server_conn->server_protocol_version = S2N_TLS12;
1126 server_conn->client_protocol_version = S2N_TLS12;
1127
1128 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
1129
1130 EXPECT_NOT_NULL(server_config = s2n_config_new());
1131 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
1132 EXPECT_SUCCESS(s2n_config_accept_max_fragment_length(server_config));
1133 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
1134 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
1135 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
1136 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
1137
1138 /* Preference should be ignored as the TlS Maximum Fragment Length Extension is Set */
1139 EXPECT_SUCCESS(s2n_connection_prefer_throughput(server_conn));
1140
1141 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
1142
1143 EXPECT_EQUAL(server_conn->max_outgoing_fragment_length, mfl_code_to_length[mfl_code]);
1144 EXPECT_EQUAL(server_conn->negotiated_mfl_code, mfl_code);
1145
1146 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
1147
1148 EXPECT_SUCCESS(s2n_connection_free(server_conn));
1149 EXPECT_SUCCESS(s2n_connection_free(client_conn));
1150
1151 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
1152
1153 EXPECT_SUCCESS(s2n_config_free(server_config));
1154 EXPECT_SUCCESS(s2n_config_free(client_config));
1155 }
1156
1157 /* Client requests invalid maximum fragment length */
1158 {
1159 struct s2n_connection *client_conn = NULL;
1160 struct s2n_connection *server_conn = NULL;
1161 struct s2n_config *server_config = NULL;
1162 struct s2n_config *client_config = NULL;
1163 struct s2n_cert_chain_and_key *chain_and_key = NULL;
1164
1165 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
1166 client_conn->actual_protocol_version = S2N_TLS12;
1167 client_conn->server_protocol_version = S2N_TLS12;
1168 client_conn->client_protocol_version = S2N_TLS12;
1169
1170 EXPECT_NOT_NULL(client_config = s2n_config_new());
1171 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
1172 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
1173 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
1174 EXPECT_FAILURE(s2n_config_send_max_fragment_length(client_config, 5));
1175 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1176
1177 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
1178 server_conn->actual_protocol_version = S2N_TLS12;
1179 server_conn->server_protocol_version = S2N_TLS12;
1180 server_conn->client_protocol_version = S2N_TLS12;
1181
1182 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
1183
1184 EXPECT_NOT_NULL(server_config = s2n_config_new());
1185 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
1186 EXPECT_SUCCESS(s2n_config_accept_max_fragment_length(server_config));
1187 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
1188 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
1189 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
1190 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
1191
1192 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
1193
1194 /* check that max_fragment_length did not get set due to invalid mfl_code */
1195 EXPECT_EQUAL(server_conn->max_outgoing_fragment_length, S2N_DEFAULT_FRAGMENT_LENGTH);
1196 EXPECT_EQUAL(server_conn->negotiated_mfl_code, S2N_TLS_MAX_FRAG_LEN_EXT_NONE);
1197
1198 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
1199
1200 EXPECT_SUCCESS(s2n_connection_free(server_conn));
1201 EXPECT_SUCCESS(s2n_connection_free(client_conn));
1202
1203 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
1204
1205 EXPECT_SUCCESS(s2n_config_free(server_config));
1206 EXPECT_SUCCESS(s2n_config_free(client_config));
1207 };
1208
1209 /* Server ignores client's request of S2N_TLS_MAX_FRAG_LEN_2048 maximum fragment length when accept_mfl is not set*/
1210 {
1211 struct s2n_connection *client_conn = NULL;
1212 struct s2n_connection *server_conn = NULL;
1213 struct s2n_config *server_config = NULL;
1214 struct s2n_config *client_config = NULL;
1215 struct s2n_cert_chain_and_key *chain_and_key = NULL;
1216
1217 EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
1218 client_conn->actual_protocol_version = S2N_TLS12;
1219 client_conn->server_protocol_version = S2N_TLS12;
1220 client_conn->client_protocol_version = S2N_TLS12;
1221
1222 EXPECT_NOT_NULL(client_config = s2n_config_new());
1223 EXPECT_OK(s2n_config_set_tls12_security_policy(client_config));
1224 EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(client_config, 0));
1225 EXPECT_SUCCESS(s2n_config_disable_x509_verification(client_config));
1226 EXPECT_SUCCESS(s2n_config_send_max_fragment_length(client_config, S2N_TLS_MAX_FRAG_LEN_2048));
1227 EXPECT_SUCCESS(s2n_connection_set_config(client_conn, client_config));
1228
1229 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
1230 server_conn->actual_protocol_version = S2N_TLS12;
1231 server_conn->server_protocol_version = S2N_TLS12;
1232 server_conn->client_protocol_version = S2N_TLS12;
1233
1234 EXPECT_SUCCESS(s2n_connections_set_io_pair(client_conn, server_conn, &io_pair));
1235
1236 EXPECT_NOT_NULL(server_config = s2n_config_new());
1237 EXPECT_OK(s2n_config_set_tls12_security_policy(server_config));
1238 EXPECT_NOT_NULL(chain_and_key = s2n_cert_chain_and_key_new());
1239 EXPECT_SUCCESS(s2n_cert_chain_and_key_load_pem(chain_and_key, cert_chain, private_key));
1240 EXPECT_SUCCESS(s2n_config_add_cert_chain_and_key_to_store(server_config, chain_and_key));
1241 EXPECT_SUCCESS(s2n_connection_set_config(server_conn, server_config));
1242
1243 EXPECT_SUCCESS(s2n_negotiate_test_server_and_client(server_conn, client_conn));
1244
1245 /* check that max_fragment_length did not get set since accept_mfl is not set */
1246 EXPECT_EQUAL(server_conn->max_outgoing_fragment_length, S2N_DEFAULT_FRAGMENT_LENGTH);
1247 EXPECT_EQUAL(server_conn->negotiated_mfl_code, S2N_TLS_MAX_FRAG_LEN_EXT_NONE);
1248
1249 EXPECT_SUCCESS(s2n_shutdown_test_server_and_client(server_conn, client_conn));
1250
1251 EXPECT_SUCCESS(s2n_connection_free(server_conn));
1252 EXPECT_SUCCESS(s2n_connection_free(client_conn));
1253
1254 EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
1255
1256 EXPECT_SUCCESS(s2n_config_free(server_config));
1257 EXPECT_SUCCESS(s2n_config_free(client_config));
1258 };
1259
1260 EXPECT_SUCCESS(s2n_io_pair_close(&io_pair));
1261 free(cert_chain);
1262 free(private_key);
1263 END_TEST();
1264 }