Debian Codegraph @

crt/s2n/tests/unit/s2n_tls13_handshake_early_data_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 "s2n_test.h"
17 #include "testlib/s2n_testlib.h"
18 #include "tls/s2n_handshake.h"
19 #include "tls/s2n_record.h"
20 #include "tls/s2n_tls13_handshake.h"
21 #include "utils/s2n_array.h"
22 #include "utils/s2n_mem.h"
23
24 /* Just to get access to the static functions / variables we need to test */
25 #include "tls/s2n_handshake_io.c"
26 #include "tls/s2n_handshake_transcript.c"
27 #include "tls/s2n_tls13_handshake.c"
28
29 #define S2N_SECRET_TYPE_COUNT 5
30
31 const uint8_t empty_secret[S2N_TLS13_SECRET_MAX_LEN] = { 0 };
32 message_type_t empty_handshake[S2N_MAX_HANDSHAKE_LENGTH] = { 0 };
33
34 int main()
35 {
36 BEGIN_TEST();
37
38 /* Test early data encryption */
39 {
40 /**
41 *= https://www.rfc-editor.org/rfc/rfc8448#section-3
42 *= type=test
43 *# {server} generate resumption secret "tls13 resumption":
44 *#
45 *# PRK (32 octets): 7d f2 35 f2 03 1d 2a 05 12 87 d0 2b 02 41 b0 bf
46 *# da f8 6c c8 56 23 1f 2d 5a ba 46 c4 34 ec 19 6c
47 *#
48 *# hash (2 octets): 00 00
49 *#
50 *# info (22 octets): 00 20 10 74 6c 73 31 33 20 72 65 73 75 6d 70 74
51 *# 69 6f 6e 02 00 00
52 *#
53 *# expanded (32 octets): 4e cd 0e b6 ec 3b 4d 87 f5 d6 02 8f 92 2c
54 *# a4 c5 85 1a 27 7f d4 13 11 c9 e6 2d 2c 94 92 e1 c4 f3
55 */
56 S2N_BLOB_FROM_HEX(psk_secret, "4e cd 0e b6 ec 3b 4d 87 f5 d6 02 8f 92 2c \
57 a4 c5 85 1a 27 7f d4 13 11 c9 e6 2d 2c 94 92 e1 c4 f3");
58
59 /**
60 *= https://www.rfc-editor.org/rfc/rfc8448#section-3
61 *= type=test
62 *# {server} construct a NewSessionTicket handshake message:
63 *#
64 *# NewSessionTicket (205 octets): 04 00 00 c9 00 00 00 1e fa d6 aa
65 *# c5 02 00 00 00 b2 2c 03 5d 82 93 59 ee 5f f7 af 4e c9 00 00 00
66 *# 00 26 2a 64 94 dc 48 6d 2c 8a 34 cb 33 fa 90 bf 1b 00 70 ad 3c
67 *# 49 88 83 c9 36 7c 09 a2 be 78 5a bc 55 cd 22 60 97 a3 a9 82 11
68 *# 72 83 f8 2a 03 a1 43 ef d3 ff 5d d3 6d 64 e8 61 be 7f d6 1d 28
69 *# 27 db 27 9c ce 14 50 77 d4 54 a3 66 4d 4e 6d a4 d2 9e e0 37 25
70 *# a6 a4 da fc d0 fc 67 d2 ae a7 05 29 51 3e 3d a2 67 7f a5 90 6c
71 *# 5b 3f 7d 8f 92 f2 28 bd a4 0d da 72 14 70 f9 fb f2 97 b5 ae a6
72 *# 17 64 6f ac 5c 03 27 2e 97 07 27 c6 21 a7 91 41 ef 5f 7d e6 50
73 *# 5e 5b fb c3 88 e9 33 43 69 40 93 93 4a e4 d3 57 00 08 00 2a 00
74 *# 04 00 00 04 00
75 */
76 /* Skip past the message type, message size, ticket lifetime,
77 * ticket age add, nonce, and ticket size:
78 * 04 00 00 c9 00 00 00 1e fa d6 aa
79 * c5 02 00 00 00 b2
80 */
81 S2N_BLOB_FROM_HEX(psk_identity,
82 "2c 03 5d 82 93 59 ee 5f f7 af 4e c9 00 00 00 \
83 00 26 2a 64 94 dc 48 6d 2c 8a 34 cb 33 fa 90 bf 1b 00 70 ad 3c \
84 49 88 83 c9 36 7c 09 a2 be 78 5a bc 55 cd 22 60 97 a3 a9 82 11 \
85 72 83 f8 2a 03 a1 43 ef d3 ff 5d d3 6d 64 e8 61 be 7f d6 1d 28 \
86 27 db 27 9c ce 14 50 77 d4 54 a3 66 4d 4e 6d a4 d2 9e e0 37 25 \
87 a6 a4 da fc d0 fc 67 d2 ae a7 05 29 51 3e 3d a2 67 7f a5 90 6c \
88 5b 3f 7d 8f 92 f2 28 bd a4 0d da 72 14 70 f9 fb f2 97 b5 ae a6 \
89 17 64 6f ac 5c 03 27 2e 97 07 27 c6 21 a7 91 41 ef 5f 7d e6 50 \
90 5e 5b fb c3 88 e9 33 43 69 40 93 93 4a e4 d3 57");
91 /* Skip past the total extensions size, early data extension type,
92 * and early data extension size: 00 08 00 2a 00
93 * 04
94 */
95 const uint32_t max_early_data = 0x00000400;
96
97 /**
98 *= https://www.rfc-editor.org/rfc/rfc8448#section-4
99 *= type=test
100 *# {client} send handshake record:
101 *#
102 *# payload (512 octets): 01 00 01 fc 03 03 1b c3 ce b6 bb e3 9c ff
103 *# 93 83 55 b5 a5 0a db 6d b2 1b 7a 6a f6 49 d7 b4 bc 41 9d 78 76
104 *# 48 7d 95 00 00 06 13 01 13 03 13 02 01 00 01 cd 00 00 00 0b 00
105 *# 09 00 00 06 73 65 72 76 65 72 ff 01 00 01 00 00 0a 00 14 00 12
106 *# 00 1d 00 17 00 18 00 19 01 00 01 01 01 02 01 03 01 04 00 33 00
107 *# 26 00 24 00 1d 00 20 e4 ff b6 8a c0 5f 8d 96 c9 9d a2 66 98 34
108 *# 6c 6b e1 64 82 ba dd da fe 05 1a 66 b4 f1 8d 66 8f 0b 00 2a 00
109 *# 00 00 2b 00 03 02 03 04 00 0d 00 20 00 1e 04 03 05 03 06 03 02
110 *# 03 08 04 08 05 08 06 04 01 05 01 06 01 02 01 04 02 05 02 06 02
111 *# 02 02 00 2d 00 02 01 01 00 1c 00 02 40 01 00 15 00 57 00 00 00
112 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
113 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
114 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
115 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
116 *# 00 29 00 dd 00 b8 00 b2 2c 03 5d 82 93 59 ee 5f f7 af 4e c9 00
117 *# 00 00 00 26 2a 64 94 dc 48 6d 2c 8a 34 cb 33 fa 90 bf 1b 00 70
118 *# ad 3c 49 88 83 c9 36 7c 09 a2 be 78 5a bc 55 cd 22 60 97 a3 a9
119 *# 82 11 72 83 f8 2a 03 a1 43 ef d3 ff 5d d3 6d 64 e8 61 be 7f d6
120 *# 1d 28 27 db 27 9c ce 14 50 77 d4 54 a3 66 4d 4e 6d a4 d2 9e e0
121 *# 37 25 a6 a4 da fc d0 fc 67 d2 ae a7 05 29 51 3e 3d a2 67 7f a5
122 *# 90 6c 5b 3f 7d 8f 92 f2 28 bd a4 0d da 72 14 70 f9 fb f2 97 b5
123 *# ae a6 17 64 6f ac 5c 03 27 2e 97 07 27 c6 21 a7 91 41 ef 5f 7d
124 *# e6 50 5e 5b fb c3 88 e9 33 43 69 40 93 93 4a e4 d3 57 fa d6 aa
125 *# cb 00 21 20 3a dd 4f b2 d8 fd f8 22 a0 ca 3c f7 67 8e f5 e8 8d
126 *# ae 99 01 41 c5 92 4d 57 bb 6f a3 1b 9e 5f 9d
127 */
128 S2N_BLOB_FROM_HEX(client_hello_msg,
129 "01 00 01 fc 03 03 1b c3 ce b6 bb e3 9c ff \
130 93 83 55 b5 a5 0a db 6d b2 1b 7a 6a f6 49 d7 b4 bc 41 9d 78 76 \
131 48 7d 95 00 00 06 13 01 13 03 13 02 01 00 01 cd 00 00 00 0b 00 \
132 09 00 00 06 73 65 72 76 65 72 ff 01 00 01 00 00 0a 00 14 00 12 \
133 00 1d 00 17 00 18 00 19 01 00 01 01 01 02 01 03 01 04 00 33 00 \
134 26 00 24 00 1d 00 20 e4 ff b6 8a c0 5f 8d 96 c9 9d a2 66 98 34 \
135 6c 6b e1 64 82 ba dd da fe 05 1a 66 b4 f1 8d 66 8f 0b 00 2a 00 \
136 00 00 2b 00 03 02 03 04 00 0d 00 20 00 1e 04 03 05 03 06 03 02 \
137 03 08 04 08 05 08 06 04 01 05 01 06 01 02 01 04 02 05 02 06 02 \
138 02 02 00 2d 00 02 01 01 00 1c 00 02 40 01 00 15 00 57 00 00 00 \
139 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
141 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
142 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
143 00 29 00 dd 00 b8 00 b2 2c 03 5d 82 93 59 ee 5f f7 af 4e c9 00 \
144 00 00 00 26 2a 64 94 dc 48 6d 2c 8a 34 cb 33 fa 90 bf 1b 00 70 \
145 ad 3c 49 88 83 c9 36 7c 09 a2 be 78 5a bc 55 cd 22 60 97 a3 a9 \
146 82 11 72 83 f8 2a 03 a1 43 ef d3 ff 5d d3 6d 64 e8 61 be 7f d6 \
147 1d 28 27 db 27 9c ce 14 50 77 d4 54 a3 66 4d 4e 6d a4 d2 9e e0 \
148 37 25 a6 a4 da fc d0 fc 67 d2 ae a7 05 29 51 3e 3d a2 67 7f a5 \
149 90 6c 5b 3f 7d 8f 92 f2 28 bd a4 0d da 72 14 70 f9 fb f2 97 b5 \
150 ae a6 17 64 6f ac 5c 03 27 2e 97 07 27 c6 21 a7 91 41 ef 5f 7d \
151 e6 50 5e 5b fb c3 88 e9 33 43 69 40 93 93 4a e4 d3 57 fa d6 aa \
152 cb 00 21 20 3a dd 4f b2 d8 fd f8 22 a0 ca 3c f7 67 8e f5 e8 8d \
153 ae 99 01 41 c5 92 4d 57 bb 6f a3 1b 9e 5f 9d")
154 /**
155 *= https://www.rfc-editor.org/rfc/rfc8448#section-4
156 *= type=test
157 *#
158 *# complete record (517 octets): 16 03 01 02 00 01 00 01 fc 03 03 1b
159 *# c3 ce b6 bb e3 9c ff 93 83 55 b5 a5 0a db 6d b2 1b 7a 6a f6 49
160 *# d7 b4 bc 41 9d 78 76 48 7d 95 00 00 06 13 01 13 03 13 02 01 00
161 *# 01 cd 00 00 00 0b 00 09 00 00 06 73 65 72 76 65 72 ff 01 00 01
162 *# 00 00 0a 00 14 00 12 00 1d 00 17 00 18 00 19 01 00 01 01 01 02
163 *# 01 03 01 04 00 33 00 26 00 24 00 1d 00 20 e4 ff b6 8a c0 5f 8d
164 *# 96 c9 9d a2 66 98 34 6c 6b e1 64 82 ba dd da fe 05 1a 66 b4 f1
165 *# 8d 66 8f 0b 00 2a 00 00 00 2b 00 03 02 03 04 00 0d 00 20 00 1e
166 *# 04 03 05 03 06 03 02 03 08 04 08 05 08 06 04 01 05 01 06 01 02
167 *# 01 04 02 05 02 06 02 02 02 00 2d 00 02 01 01 00 1c 00 02 40 01
168 *# 00 15 00 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
169 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
170 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
171 *# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
172 *# 00 00 00 00 00 00 00 00 29 00 dd 00 b8 00 b2 2c 03 5d 82 93 59
173 *# ee 5f f7 af 4e c9 00 00 00 00 26 2a 64 94 dc 48 6d 2c 8a 34 cb
174 *# 33 fa 90 bf 1b 00 70 ad 3c 49 88 83 c9 36 7c 09 a2 be 78 5a bc
175 *# 55 cd 22 60 97 a3 a9 82 11 72 83 f8 2a 03 a1 43 ef d3 ff 5d d3
176 *# 6d 64 e8 61 be 7f d6 1d 28 27 db 27 9c ce 14 50 77 d4 54 a3 66
177 *# 4d 4e 6d a4 d2 9e e0 37 25 a6 a4 da fc d0 fc 67 d2 ae a7 05 29
178 *# 51 3e 3d a2 67 7f a5 90 6c 5b 3f 7d 8f 92 f2 28 bd a4 0d da 72
179 *# 14 70 f9 fb f2 97 b5 ae a6 17 64 6f ac 5c 03 27 2e 97 07 27 c6
180 *# 21 a7 91 41 ef 5f 7d e6 50 5e 5b fb c3 88 e9 33 43 69 40 93 93
181 *# 4a e4 d3 57 fa d6 aa cb 00 21 20 3a dd 4f b2 d8 fd f8 22 a0 ca
182 *# 3c f7 67 8e f5 e8 8d ae 99 01 41 c5 92 4d 57 bb 6f a3 1b 9e 5f
183 *# 9d
184 */
185 S2N_BLOB_FROM_HEX(ch_record, "16 03 01 02 00 01 00 01 fc 03 03 1b \
186 c3 ce b6 bb e3 9c ff 93 83 55 b5 a5 0a db 6d b2 1b 7a 6a f6 49 \
187 d7 b4 bc 41 9d 78 76 48 7d 95 00 00 06 13 01 13 03 13 02 01 00 \
188 01 cd 00 00 00 0b 00 09 00 00 06 73 65 72 76 65 72 ff 01 00 01 \
189 00 00 0a 00 14 00 12 00 1d 00 17 00 18 00 19 01 00 01 01 01 02 \
190 01 03 01 04 00 33 00 26 00 24 00 1d 00 20 e4 ff b6 8a c0 5f 8d \
191 96 c9 9d a2 66 98 34 6c 6b e1 64 82 ba dd da fe 05 1a 66 b4 f1 \
192 8d 66 8f 0b 00 2a 00 00 00 2b 00 03 02 03 04 00 0d 00 20 00 1e \
193 04 03 05 03 06 03 02 03 08 04 08 05 08 06 04 01 05 01 06 01 02 \
194 01 04 02 05 02 06 02 02 02 00 2d 00 02 01 01 00 1c 00 02 40 01 \
195 00 15 00 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
196 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
197 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
198 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
199 00 00 00 00 00 00 00 00 29 00 dd 00 b8 00 b2 2c 03 5d 82 93 59 \
200 ee 5f f7 af 4e c9 00 00 00 00 26 2a 64 94 dc 48 6d 2c 8a 34 cb \
201 33 fa 90 bf 1b 00 70 ad 3c 49 88 83 c9 36 7c 09 a2 be 78 5a bc \
202 55 cd 22 60 97 a3 a9 82 11 72 83 f8 2a 03 a1 43 ef d3 ff 5d d3 \
203 6d 64 e8 61 be 7f d6 1d 28 27 db 27 9c ce 14 50 77 d4 54 a3 66 \
204 4d 4e 6d a4 d2 9e e0 37 25 a6 a4 da fc d0 fc 67 d2 ae a7 05 29 \
205 51 3e 3d a2 67 7f a5 90 6c 5b 3f 7d 8f 92 f2 28 bd a4 0d da 72 \
206 14 70 f9 fb f2 97 b5 ae a6 17 64 6f ac 5c 03 27 2e 97 07 27 c6 \
207 21 a7 91 41 ef 5f 7d e6 50 5e 5b fb c3 88 e9 33 43 69 40 93 93 \
208 4a e4 d3 57 fa d6 aa cb 00 21 20 3a dd 4f b2 d8 fd f8 22 a0 ca \
209 3c f7 67 8e f5 e8 8d ae 99 01 41 c5 92 4d 57 bb 6f a3 1b 9e 5f \
210 9d");
211
212 /**
213 *= https://www.rfc-editor.org/rfc/rfc8448#section-4
214 *= type=test
215 *# {client} extract secret "early":
216 *#
217 *# salt: 0 (all zero octets)
218 *#
219 *# IKM (32 octets): 4e cd 0e b6 ec 3b 4d 87 f5 d6 02 8f 92 2c a4 c5
220 *# 85 1a 27 7f d4 13 11 c9 e6 2d 2c 94 92 e1 c4 f3
221 *#
222 *# secret (32 octets): 9b 21 88 e9 b2 fc 6d 64 d7 1d c3 29 90 0e 20
223 *# bb 41 91 50 00 f6 78 aa 83 9c bb 79 7c b7 d8 33 2c
224 */
225 S2N_BLOB_FROM_HEX(early_secret,
226 "9b 21 88 e9 b2 fc 6d 64 d7 1d c3 29 90 0e 20 \
227 bb 41 91 50 00 f6 78 aa 83 9c bb 79 7c b7 d8 33 2c");
228
229 /**
230 *= https://www.rfc-editor.org/rfc/rfc8448#section-4
231 *= type=test
232 *# {client} derive write traffic keys for early application data:
233 *#
234 *# PRK (32 octets): 3f bb e6 a6 0d eb 66 c3 0a 32 79 5a ba 0e ff 7e
235 *# aa 10 10 55 86 e7 be 5c 09 67 8d 63 b6 ca ab 62
236 *#
237 *# key info (13 octets): 00 10 09 74 6c 73 31 33 20 6b 65 79 00
238 *#
239 *# key expanded (16 octets): 92 02 05 a5 b7 bf 21 15 e6 fc 5c 29 42
240 *# 83 4f 54
241 *#
242 *# iv info (12 octets): 00 0c 08 74 6c 73 31 33 20 69 76 00
243 *#
244 *# iv expanded (12 octets): 6d 47 5f 09 93 c8 e5 64 61 0d b2 b9
245 */
246 S2N_BLOB_FROM_HEX(iv, "6d 47 5f 09 93 c8 e5 64 61 0d b2 b9");
247
248 /**
249 *= https://www.rfc-editor.org/rfc/rfc8448#section-4
250 *= type=test
251 *# {client} send application_data record:
252 *#
253 *# payload (6 octets): 41 42 43 44 45 46
254 */
255 S2N_BLOB_FROM_HEX(payload, "41 42 43 44 45 46");
256 /**
257 *= https://www.rfc-editor.org/rfc/rfc8448#section-4
258 *= type=test
259 *#
260 *# complete record (28 octets): 17 03 03 00 17 ab 1d f4 20 e7 5c 45
261 *# 7a 7c c5 d2 84 4f 76 d5 ae e4 b4 ed bf 04 9b e0
262 */
263 S2N_BLOB_FROM_HEX(complete_record, "17 03 03 00 17 ab 1d f4 20 e7 5c 45 \
264 7a 7c c5 d2 84 4f 76 d5 ae e4 b4 ed bf 04 9b e0");
265
266 /* Test client early data encryption against known client outputs */
267 {
268 struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT);
269 EXPECT_NOT_NULL(client_conn);
270 client_conn->actual_protocol_version = S2N_TLS13;
271 client_conn->server_protocol_version = S2N_TLS13;
272 client_conn->early_data_state = S2N_EARLY_DATA_REQUESTED;
273
274 struct s2n_psk *psk = NULL;
275 EXPECT_OK(s2n_array_pushback(&client_conn->psk_params.psk_list, (void **) &psk));
276 psk->hmac_alg = S2N_HMAC_SHA256;
277 EXPECT_SUCCESS(s2n_psk_configure_early_data(psk, max_early_data, 0x13, 0x01));
278 client_conn->secure->cipher_suite = psk->early_data_config.cipher_suite;
279
280 /* Rewrite early secret with known early secret. */
281 EXPECT_SUCCESS(s2n_dup(&early_secret, &psk->early_secret));
282
283 /* Rewrite hashes with known ClientHello */
284 EXPECT_SUCCESS(s2n_conn_update_handshake_hashes(client_conn, &client_hello_msg));
285
286 EXPECT_OK(s2n_tls13_secrets_update(client_conn));
287 EXPECT_OK(s2n_tls13_key_schedule_update(client_conn));
288
289 /* Check early secret secret set correctly */
290 EXPECT_EQUAL(client_conn->secrets.extract_secret_type, S2N_EARLY_SECRET);
291 EXPECT_BYTEARRAY_EQUAL(client_conn->secrets.version.tls13.extract_secret, early_secret.data, early_secret.size);
292
293 /* Check IV calculated correctly */
294 EXPECT_BYTEARRAY_EQUAL(client_conn->secure->client_implicit_iv, iv.data, iv.size);
295
296 /* Check payload encrypted correctly */
297 EXPECT_OK(s2n_record_write(client_conn, TLS_APPLICATION_DATA, &payload));
298 EXPECT_EQUAL(s2n_stuffer_data_available(&client_conn->out), complete_record.size);
299 EXPECT_BYTEARRAY_EQUAL(client_conn->out.blob.data, complete_record.data, complete_record.size);
300
301 EXPECT_SUCCESS(s2n_connection_free(client_conn));
302 };
303
304 /* The known ClientHello uses the x25519 curve,
305 * which the S2N server won't accept if the EVP APIs are not supported */
306 #if EVP_APIS_SUPPORTED
307 /* Test server early data encryption with known client inputs */
308 {
309 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
310 EXPECT_NOT_NULL(server_conn);
311 EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING));
312 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(server_conn, "default_tls13"));
313 EXPECT_SUCCESS(s2n_connection_set_early_data_expected(server_conn));
314 EXPECT_SUCCESS(s2n_connection_set_server_max_early_data_size(server_conn, max_early_data));
315
316 DEFER_CLEANUP(struct s2n_psk *psk = s2n_external_psk_new(), s2n_psk_free);
317 psk->type = S2N_PSK_TYPE_RESUMPTION;
318 EXPECT_SUCCESS(s2n_psk_set_identity(psk, psk_identity.data, psk_identity.size));
319 EXPECT_SUCCESS(s2n_psk_set_secret(psk, psk_secret.data, psk_secret.size));
320 EXPECT_SUCCESS(s2n_psk_configure_early_data(psk, max_early_data, 0x13, 0x01));
321 EXPECT_SUCCESS(s2n_connection_append_psk(server_conn, psk));
322 /* We need to explicitly set the psk_params type to skip our stateless session resumption recv
323 * code because the handshake traces we're using are meant for stateful session resumption.
324 * TODO: https://github.com/aws/s2n-tls/issues/2742 */
325 server_conn->psk_params.type = S2N_PSK_TYPE_EXTERNAL;
326
327 DEFER_CLEANUP(struct s2n_stuffer input = { 0 }, s2n_stuffer_free);
328 DEFER_CLEANUP(struct s2n_stuffer output = { 0 }, s2n_stuffer_free);
329 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, S2N_DEFAULT_RECORD_LENGTH));
330 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&output, S2N_DEFAULT_RECORD_LENGTH));
331 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, &output, server_conn));
332
333 EXPECT_SUCCESS(s2n_stuffer_write(&input, &ch_record));
334
335 s2n_blocked_status blocked = 0;
336 EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate(server_conn, &blocked), S2N_ERR_IO_BLOCKED);
337 EXPECT_EQUAL(blocked, S2N_BLOCKED_ON_READ);
338 EXPECT_EQUAL(s2n_conn_get_current_message_type(server_conn), END_OF_EARLY_DATA);
339 EXPECT_EQUAL(s2n_stuffer_data_available(&input), 0);
340
341 EXPECT_SUCCESS(s2n_stuffer_write(&input, &complete_record));
342
343 DEFER_CLEANUP(struct s2n_blob actual_payload = { 0 }, s2n_free);
344 EXPECT_SUCCESS(s2n_alloc(&actual_payload, payload.size));
345 int r = s2n_recv(server_conn, actual_payload.data, actual_payload.size, &blocked);
346 EXPECT_EQUAL(r, payload.size);
347 EXPECT_BYTEARRAY_EQUAL(actual_payload.data, payload.data, payload.size);
348 EXPECT_EQUAL(s2n_stuffer_data_available(&input), 0);
349
350 EXPECT_SUCCESS(s2n_connection_free(server_conn));
351 };
352 #endif
353 };
354
355 END_TEST();
356 }