Debian Codegraph @

crt/s2n/tests/integrationv2/test_early_data.py

raw symbols SCIP
1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 # SPDX-License-Identifier: Apache-2.0
3 import copy
4 import os
5 import pytest
6
7 from configuration import (
8 available_ports,
9 ALL_TEST_CURVES,
10 MINIMAL_TEST_CERTS,
11 TLS13_CIPHERS,
12 )
13 from common import ProviderOptions, Protocols, Curves, data_bytes
14 from fixtures import managed_process # noqa: F401
15 from providers import Provider, S2N as S2NBase, OpenSSL as OpenSSLBase
16 from utils import invalid_test_parameters, get_parameter_name, to_bytes
17
18 from test_hello_retry_requests import S2N_HRR_MARKER
19
20 TICKET_FILE = "ticket"
21 EARLY_DATA_FILE = "early_data"
22
23 MAX_EARLY_DATA = 500 # Arbitrary largish number
24 DATA_TO_SEND = data_bytes(500) # Arbitrary large number
25
26 NUM_RESUMES = 5 # Hardcoded for s2nc --reconnect
27 NUM_CONNECTIONS = NUM_RESUMES + 1 # resumes + initial
28
29 S2N_DEFAULT_CURVE = Curves.X25519
30 # We have no plans to support this curve any time soon
31 S2N_UNSUPPORTED_CURVE = "X448"
32 S2N_HRR_CURVES = list(curve for curve in ALL_TEST_CURVES if curve != S2N_DEFAULT_CURVE)
33
34 S2N_EARLY_DATA_MARKER = to_bytes("WITH_EARLY_DATA")
35 S2N_EARLY_DATA_RECV_MARKER = "Early Data received: "
36 S2N_EARLY_DATA_STATUS_MARKER = "Early Data status: {status}"
37 S2N_EARLY_DATA_ACCEPTED_MARKER = S2N_EARLY_DATA_STATUS_MARKER.format(status="ACCEPTED")
38 S2N_EARLY_DATA_REJECTED_MARKER = S2N_EARLY_DATA_STATUS_MARKER.format(status="REJECTED")
39 S2N_EARLY_DATA_NOT_REQUESTED_MARKER = S2N_EARLY_DATA_STATUS_MARKER.format(
40 status="NOT REQUESTED"
41 )
42
43
44 class S2N(S2NBase):
45 def __init__(self, options: ProviderOptions):
46 S2NBase.__init__(self, options)
47
48 def setup_client(self):
49 cmd_line = S2NBase.setup_client(self)
50 early_data_file = self.options.early_data_file
51 if early_data_file and os.path.exists(early_data_file):
52 cmd_line.extend(["--early-data", early_data_file])
53 return cmd_line
54
55 def setup_server(self):
56 cmd_line = S2NBase.setup_server(self)
57 cmd_line.extend(["--max-early-data", self.options.max_early_data])
58 return cmd_line
59
60
61 class OpenSSL(OpenSSLBase):
62 def __init__(self, options: ProviderOptions):
63 OpenSSLBase.__init__(self, options)
64
65 def setup_client(self):
66 cmd_line = OpenSSLBase.setup_client(self)
67 early_data_file = self.options.early_data_file
68 if early_data_file and os.path.exists(early_data_file):
69 cmd_line.extend(["-early_data", early_data_file])
70 ticket_file = self.options.ticket_file
71 if ticket_file:
72 if os.path.exists(ticket_file):
73 cmd_line.extend(["-sess_in", ticket_file])
74 else:
75 cmd_line.extend(["-sess_out", self.options.ticket_file])
76 return cmd_line
77
78 def setup_server(self):
79 cmd_line = OpenSSLBase.setup_server(self)
80 if self.options.max_early_data > 0:
81 cmd_line.extend(["-early_data"])
82 return cmd_line
83
84
85 # The `-reconnect` option is broken for TLS1.3 in OpenSSL s_client: https://github.com/openssl/openssl/issues/8517
86 # The `-sess_in`/`-sess_out` options can be used instead, but don't have an s2nc equivalent.
87 # As we add more providers, we may need both a `-reconnect`-like and a `-sess_in/out`-like S2N server test,
88 # but for now we can just use `-sess_in/out` and cover the S2N->S2N case in the S2N client tests.
89 CLIENT_PROVIDERS = [OpenSSL]
90 SERVER_PROVIDERS = [OpenSSL, S2N]
91
92
93 def get_early_data_bytes(file_path, early_data_size):
94 early_data = data_bytes(early_data_size)
95 with open(file_path, "wb") as fout:
96 fout.write(early_data)
97 return early_data
98
99
100 def get_ticket_from_s2n_server(options, managed_process, provider, certificate): # noqa: F811
101 port = next(available_ports)
102
103 """
104 Generally clients start checking for stdin EoF to exit as soon as they finish the handshake.
105 To make sure the client reliably receives the post-handshake NST,
106 do NOT indicate stdin EoF until after some data has been received from the server.
107 """
108 close_marker_bytes = data_bytes(10)
109
110 client_options = copy.copy(options)
111 client_options.mode = Provider.ClientMode
112 client_options.port = port
113
114 server_options = copy.copy(options)
115 server_options.mode = Provider.ServerMode
116 server_options.port = port
117 server_options.key = certificate.key
118 server_options.cert = certificate.cert
119 server_options.data_to_send = close_marker_bytes
120
121 assert not os.path.exists(options.ticket_file)
122
123 s2n_server = managed_process(
124 S2N, server_options, send_marker=S2N.get_send_marker(), timeout=10
125 )
126 client = managed_process(
127 provider, client_options, close_marker=str(close_marker_bytes), timeout=10
128 )
129
130 for results in s2n_server.get_results():
131 results.assert_success()
132
133 for results in client.get_results():
134 results.assert_success()
135
136 assert os.path.exists(options.ticket_file)
137
138
139 def test_nothing():
140 """
141 Sometimes the early data test parameters in combination with the s2n libcrypto
142 results in no test cases existing. In this case, pass a nothing test to avoid
143 marking the entire codebuild run as failed.
144 """
145 assert True
146
147
148 """
149 Basic S2N server happy case.
150
151 We make one full connection to get a session ticket with early data enabled,
152 then another resumption connection with early data.
153 """
154
155
156 @pytest.mark.uncollect_if(func=invalid_test_parameters)
157 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
158 @pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name)
159 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
160 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
161 @pytest.mark.parametrize("provider", CLIENT_PROVIDERS, ids=get_parameter_name)
162 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
163 @pytest.mark.parametrize(
164 "early_data_size",
165 [int(MAX_EARLY_DATA / 2), int(MAX_EARLY_DATA - 1), MAX_EARLY_DATA, 1],
166 )
167 def test_s2n_server_with_early_data(
168 managed_process, # noqa: F811
169 tmp_path,
170 cipher,
171 curve,
172 certificate,
173 protocol,
174 provider,
175 other_provider,
176 early_data_size,
177 ):
178 ticket_file = str(tmp_path / TICKET_FILE)
179 early_data_file = str(tmp_path / EARLY_DATA_FILE)
180 early_data = get_early_data_bytes(early_data_file, early_data_size)
181
182 options = ProviderOptions(
183 port=next(available_ports),
184 cipher=cipher,
185 curve=curve,
186 protocol=protocol,
187 insecure=True,
188 use_session_ticket=True,
189 data_to_send=DATA_TO_SEND,
190 )
191 options.ticket_file = ticket_file
192 options.early_data_file = early_data_file
193 options.max_early_data = MAX_EARLY_DATA
194
195 get_ticket_from_s2n_server(options, managed_process, provider, certificate)
196
197 client_options = copy.copy(options)
198 client_options.mode = Provider.ClientMode
199
200 server_options = copy.copy(options)
201 server_options.mode = Provider.ServerMode
202
203 s2n_server = managed_process(S2N, server_options, timeout=10)
204 client = managed_process(provider, client_options, timeout=10)
205
206 for results in client.get_results():
207 results.assert_success()
208
209 for results in s2n_server.get_results():
210 results.assert_success()
211 assert S2N_EARLY_DATA_MARKER in results.stdout
212 assert (to_bytes(S2N_EARLY_DATA_RECV_MARKER) + early_data) in results.stdout
213 assert to_bytes(S2N_EARLY_DATA_ACCEPTED_MARKER) in results.stdout
214 assert DATA_TO_SEND in results.stdout
215
216
217 """
218 Basic S2N client happy case.
219
220 The S2N client tests session resumption by repeatedly reconnecting.
221 That means we don't need to manually perform the initial full connection, and there is no external ticket file.
222 """
223
224
225 @pytest.mark.uncollect_if(func=invalid_test_parameters)
226 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
227 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
228 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
229 @pytest.mark.parametrize("provider", SERVER_PROVIDERS, ids=get_parameter_name)
230 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
231 @pytest.mark.parametrize(
232 "early_data_size",
233 [int(MAX_EARLY_DATA / 2), int(MAX_EARLY_DATA - 1), MAX_EARLY_DATA, 1],
234 )
235 def test_s2n_client_with_early_data(
236 managed_process, # noqa: F811
237 tmp_path,
238 cipher,
239 certificate,
240 protocol,
241 provider,
242 other_provider,
243 early_data_size,
244 ):
245 early_data_file = str(tmp_path / EARLY_DATA_FILE)
246 early_data = get_early_data_bytes(early_data_file, early_data_size)
247
248 options = ProviderOptions(
249 port=next(available_ports),
250 cipher=cipher,
251 protocol=protocol,
252 insecure=True,
253 use_session_ticket=True,
254 reconnect=True,
255 )
256 options.ticket_file = None
257 options.early_data_file = early_data_file
258 options.max_early_data = MAX_EARLY_DATA
259
260 client_options = copy.copy(options)
261 client_options.mode = Provider.ClientMode
262
263 server_options = copy.copy(options)
264 server_options.mode = Provider.ServerMode
265 server_options.key = certificate.key # Required for the initial connection
266 server_options.cert = certificate.cert # Required for the initial connection
267 server_options.reconnects_before_exit = NUM_CONNECTIONS
268
269 server = managed_process(provider, server_options, timeout=10)
270 s2n_client = managed_process(S2N, client_options, timeout=10)
271
272 for results in s2n_client.get_results():
273 results.assert_success()
274 assert S2N_EARLY_DATA_MARKER in results.stdout
275 assert (
276 results.stdout.count(to_bytes(S2N_EARLY_DATA_ACCEPTED_MARKER))
277 == NUM_RESUMES
278 )
279
280 for results in server.get_results():
281 results.assert_success()
282 assert results.stdout.count(early_data) == NUM_RESUMES
283
284
285 """
286 Verify that the S2N client doesn't request early data when a server doesn't support early data.
287
288 We repeatedly reconnect with max_early_data set to 0. This is basically a test from
289 test_session_resumption but with validation that no early data is sent.
290 """
291
292
293 @pytest.mark.uncollect_if(func=invalid_test_parameters)
294 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
295 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
296 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
297 @pytest.mark.parametrize("provider", SERVER_PROVIDERS, ids=get_parameter_name)
298 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
299 def test_s2n_client_without_early_data(
300 managed_process, # noqa: F811
301 tmp_path,
302 cipher,
303 certificate,
304 protocol,
305 provider,
306 other_provider,
307 ):
308 early_data_file = str(tmp_path / EARLY_DATA_FILE)
309 early_data = get_early_data_bytes(early_data_file, MAX_EARLY_DATA)
310
311 options = ProviderOptions(
312 port=next(available_ports),
313 cipher=cipher,
314 protocol=protocol,
315 insecure=True,
316 use_session_ticket=True,
317 reconnect=True,
318 )
319 options.ticket_file = None
320 options.early_data_file = early_data_file
321 options.max_early_data = 0
322
323 client_options = copy.copy(options)
324 client_options.mode = Provider.ClientMode
325
326 server_options = copy.copy(options)
327 server_options.mode = Provider.ServerMode
328 server_options.key = certificate.key # Required for the initial connection
329 server_options.cert = certificate.cert # Required for the initial connection
330 server_options.reconnects_before_exit = NUM_CONNECTIONS
331
332 server = managed_process(provider, server_options, timeout=10)
333 s2n_client = managed_process(S2N, client_options, timeout=10)
334
335 for results in server.get_results():
336 results.assert_success()
337 assert early_data not in results.stdout
338
339 for results in s2n_client.get_results():
340 results.assert_success()
341 assert S2N_EARLY_DATA_MARKER not in results.stdout
342 assert (
343 results.stdout.count(to_bytes(S2N_EARLY_DATA_NOT_REQUESTED_MARKER))
344 == NUM_CONNECTIONS
345 )
346
347
348 """
349 Test the S2N server rejecting early data.
350
351 We do this by disabling early data on the server after the ticket is issued.
352 When the client attempts to use the ticket to send early data, the server rejects the attempt.
353
354 We can't perform an S2N client version of this test because the S2N client performs its hardcoded
355 reconnects automatically, without any mechanism to modify the connection in between.
356 """
357
358
359 @pytest.mark.flaky(reruns=5)
360 @pytest.mark.uncollect_if(func=invalid_test_parameters)
361 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
362 @pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name)
363 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
364 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
365 @pytest.mark.parametrize("provider", CLIENT_PROVIDERS, ids=get_parameter_name)
366 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
367 @pytest.mark.parametrize(
368 "early_data_size",
369 [int(MAX_EARLY_DATA / 2), int(MAX_EARLY_DATA - 1), MAX_EARLY_DATA, 1],
370 )
371 def test_s2n_server_with_early_data_rejected(
372 managed_process, # noqa: F811
373 tmp_path,
374 cipher,
375 curve,
376 certificate,
377 protocol,
378 provider,
379 other_provider,
380 early_data_size,
381 ):
382 ticket_file = str(tmp_path / TICKET_FILE)
383 early_data_file = str(tmp_path / EARLY_DATA_FILE)
384 get_early_data_bytes(early_data_file, early_data_size)
385
386 options = ProviderOptions(
387 port=next(available_ports),
388 cipher=cipher,
389 curve=curve,
390 protocol=protocol,
391 insecure=True,
392 use_session_ticket=True,
393 data_to_send=DATA_TO_SEND,
394 )
395 options.ticket_file = ticket_file
396 options.early_data_file = early_data_file
397 options.max_early_data = MAX_EARLY_DATA
398
399 get_ticket_from_s2n_server(options, managed_process, provider, certificate)
400 options.max_early_data = 0
401
402 client_options = copy.copy(options)
403 client_options.mode = Provider.ClientMode
404
405 server_options = copy.copy(options)
406 server_options.mode = Provider.ServerMode
407
408 s2n_server = managed_process(S2N, server_options, timeout=10)
409 client = managed_process(provider, client_options, timeout=10)
410
411 for results in client.get_results():
412 results.assert_success()
413
414 for results in s2n_server.get_results():
415 results.assert_success()
416 assert S2N_EARLY_DATA_MARKER not in results.stdout
417 assert S2N_HRR_MARKER not in results.stdout
418 assert to_bytes(S2N_EARLY_DATA_RECV_MARKER) not in results.stdout
419 assert to_bytes(S2N_EARLY_DATA_REJECTED_MARKER) in results.stdout
420 assert DATA_TO_SEND in results.stdout
421
422
423 """
424 Test the S2N client attempting to send early data, but the server triggering a hello retry.
425
426 We trigger the HRR by configuring the server to only accept curves that the S2N client
427 does not send key shares for.
428 """
429
430
431 @pytest.mark.uncollect_if(func=invalid_test_parameters)
432 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
433 @pytest.mark.parametrize("curve", S2N_HRR_CURVES, ids=get_parameter_name)
434 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
435 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
436 @pytest.mark.parametrize("provider", SERVER_PROVIDERS, ids=get_parameter_name)
437 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
438 @pytest.mark.parametrize(
439 "early_data_size",
440 [int(MAX_EARLY_DATA / 2), int(MAX_EARLY_DATA - 1), MAX_EARLY_DATA, 1],
441 )
442 def test_s2n_client_with_early_data_rejected_via_hrr(
443 managed_process, # noqa: F811
444 tmp_path,
445 cipher,
446 curve,
447 certificate,
448 protocol,
449 provider,
450 other_provider,
451 early_data_size,
452 ):
453 if provider == S2N:
454 pytest.skip(
455 "S2N does not respect ProviderOptions.curve, so does not trigger a retry"
456 )
457
458 early_data_file = str(tmp_path / EARLY_DATA_FILE)
459 early_data = get_early_data_bytes(early_data_file, early_data_size)
460
461 options = ProviderOptions(
462 port=next(available_ports),
463 cipher=cipher,
464 curve=curve,
465 protocol=protocol,
466 insecure=True,
467 use_session_ticket=True,
468 reconnect=True,
469 )
470 options.ticket_file = None
471 options.early_data_file = early_data_file
472 options.max_early_data = MAX_EARLY_DATA
473
474 client_options = copy.copy(options)
475 client_options.mode = Provider.ClientMode
476
477 server_options = copy.copy(options)
478 server_options.mode = Provider.ServerMode
479 server_options.key = certificate.key # Required for the initial connection
480 server_options.cert = certificate.cert # Required for the initial connection
481 server_options.reconnects_before_exit = NUM_CONNECTIONS
482
483 server = managed_process(provider, server_options, timeout=10)
484 s2n_client = managed_process(S2N, client_options, timeout=10)
485
486 for results in s2n_client.get_results():
487 results.assert_success()
488 assert S2N_EARLY_DATA_MARKER not in results.stdout
489 assert S2N_HRR_MARKER in results.stdout
490 assert (
491 results.stdout.count(to_bytes(S2N_EARLY_DATA_REJECTED_MARKER))
492 == NUM_RESUMES
493 )
494
495 for results in server.get_results():
496 results.assert_success()
497 assert early_data not in results.stdout
498
499
500 """
501 Test the S2N server rejecting early data because of a hello retry request.
502
503 In order to trigger a successful retry, we need to force the peer to offer us a key share that
504 S2N doesn't support while still supporting at least one curve S2N does support.
505 """
506
507
508 @pytest.mark.uncollect_if(func=invalid_test_parameters)
509 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
510 @pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name)
511 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
512 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
513 @pytest.mark.parametrize("provider", CLIENT_PROVIDERS, ids=get_parameter_name)
514 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
515 @pytest.mark.parametrize(
516 "early_data_size",
517 [int(MAX_EARLY_DATA / 2), int(MAX_EARLY_DATA - 1), MAX_EARLY_DATA, 1],
518 )
519 def test_s2n_server_with_early_data_rejected_via_hrr(
520 managed_process, # noqa: F811
521 tmp_path,
522 cipher,
523 curve,
524 certificate,
525 protocol,
526 provider,
527 other_provider,
528 early_data_size,
529 ):
530 ticket_file = str(tmp_path / TICKET_FILE)
531 early_data_file = str(tmp_path / EARLY_DATA_FILE)
532 early_data = get_early_data_bytes(early_data_file, early_data_size)
533
534 options = ProviderOptions(
535 port=next(available_ports),
536 cipher=cipher,
537 curve=(S2N_UNSUPPORTED_CURVE + ":" + str(curve)),
538 protocol=protocol,
539 insecure=True,
540 use_session_ticket=True,
541 data_to_send=DATA_TO_SEND,
542 )
543 options.ticket_file = ticket_file
544 options.early_data_file = early_data_file
545 options.max_early_data = MAX_EARLY_DATA
546
547 get_ticket_from_s2n_server(options, managed_process, provider, certificate)
548
549 client_options = copy.copy(options)
550 client_options.mode = Provider.ClientMode
551
552 server_options = copy.copy(options)
553 server_options.mode = Provider.ServerMode
554
555 s2n_server = managed_process(S2N, server_options, timeout=10)
556 client = managed_process(provider, client_options, timeout=10)
557
558 for results in client.get_results():
559 results.assert_success()
560 assert early_data not in results.stdout
561
562 for results in s2n_server.get_results():
563 results.assert_success()
564 assert S2N_EARLY_DATA_MARKER not in results.stdout
565 assert S2N_HRR_MARKER in results.stdout
566 assert to_bytes(S2N_EARLY_DATA_RECV_MARKER) not in results.stdout
567 assert to_bytes(S2N_EARLY_DATA_REJECTED_MARKER) in results.stdout
568 assert DATA_TO_SEND in results.stdout
569
570
571 """
572 Test the S2N server fails if it receives too much early data.
573 """
574
575
576 @pytest.mark.uncollect_if(func=invalid_test_parameters)
577 @pytest.mark.parametrize("cipher", TLS13_CIPHERS, ids=get_parameter_name)
578 @pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name)
579 @pytest.mark.parametrize("certificate", MINIMAL_TEST_CERTS, ids=get_parameter_name)
580 @pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
581 @pytest.mark.parametrize("provider", CLIENT_PROVIDERS, ids=get_parameter_name)
582 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
583 @pytest.mark.parametrize("excess_early_data", [1, 10, MAX_EARLY_DATA])
584 def test_s2n_server_with_early_data_max_exceeded(
585 managed_process, # noqa: F811
586 tmp_path,
587 cipher,
588 curve,
589 certificate,
590 protocol,
591 provider,
592 other_provider,
593 excess_early_data,
594 ):
595 ticket_file = str(tmp_path / TICKET_FILE)
596 early_data_file = str(tmp_path / EARLY_DATA_FILE)
597 early_data = get_early_data_bytes(
598 early_data_file, MAX_EARLY_DATA + excess_early_data
599 )
600
601 options = ProviderOptions(
602 port=next(available_ports),
603 cipher=cipher,
604 curve=curve,
605 protocol=protocol,
606 insecure=True,
607 use_session_ticket=True,
608 data_to_send=DATA_TO_SEND,
609 )
610 options.ticket_file = ticket_file
611 options.early_data_file = early_data_file
612 options.max_early_data = MAX_EARLY_DATA + excess_early_data
613
614 get_ticket_from_s2n_server(options, managed_process, provider, certificate)
615 options.max_early_data = MAX_EARLY_DATA
616
617 client_options = copy.copy(options)
618 client_options.mode = Provider.ClientMode
619
620 server_options = copy.copy(options)
621 server_options.mode = Provider.ServerMode
622
623 s2n_server = managed_process(S2N, server_options, timeout=10)
624 client = managed_process(provider, client_options, timeout=10)
625
626 for results in client.get_results():
627 """
628 We can't make any assertions about the client exit_code.
629 To avoid blinding delays, s2nd doesn't call s2n_shutdown for a failed negotiation.
630 That means that instead of sending close_notify, we just close the socket.
631 Whether the peer interprets this as a failure or EoF depends on its state.
632 """
633 assert results.exception is None
634 assert DATA_TO_SEND not in results.stdout
635
636 for results in s2n_server.get_results():
637 assert results.exception is None
638 assert results.exit_code != 0
639 # Full early data should not be reported
640 assert early_data not in results.stdout
641 # Partial early data should be reported
642 assert (
643 to_bytes(S2N_EARLY_DATA_RECV_MARKER) + early_data[:MAX_EARLY_DATA]
644 ) in results.stdout
645 assert to_bytes("Bad message encountered") in results.stderr