Skip to content

Commit 1f9f343

Browse files
authored
Migrate PQ Python code to TLS 1.3 (#4999)
1 parent 4746f70 commit 1f9f343

File tree

2 files changed

+23
-150
lines changed

2 files changed

+23
-150
lines changed

tests/integrationv2/common.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,6 @@ class Ciphers(object):
318318

319319
KMS_TLS_1_0_2018_10 = Cipher(
320320
"KMS-TLS-1-0-2018-10", Protocols.TLS10, False, False, s2n=True)
321-
KMS_PQ_TLS_1_0_2019_06 = Cipher(
322-
"KMS-PQ-TLS-1-0-2019-06", Protocols.TLS10, False, False, s2n=True, pq=True)
323-
KMS_PQ_TLS_1_0_2020_02 = Cipher(
324-
"KMS-PQ-TLS-1-0-2020-02", Protocols.TLS10, False, False, s2n=True, pq=True)
325-
KMS_PQ_TLS_1_0_2020_07 = Cipher(
326-
"KMS-PQ-TLS-1-0-2020-07", Protocols.TLS10, False, False, s2n=True, pq=True)
327-
PQ_SIKE_TEST_TLS_1_0_2019_11 = Cipher(
328-
"PQ-SIKE-TEST-TLS-1-0-2019-11", Protocols.TLS10, False, False, s2n=True, pq=True)
329-
PQ_SIKE_TEST_TLS_1_0_2020_02 = Cipher(
330-
"PQ-SIKE-TEST-TLS-1-0-2020-02", Protocols.TLS10, False, False, s2n=True, pq=True)
331-
PQ_TLS_1_0_2020_12 = Cipher(
332-
"PQ-TLS-1-0-2020-12", Protocols.TLS10, False, False, s2n=True, pq=True)
333321
PQ_TLS_1_0_2023_01 = Cipher(
334322
"PQ-TLS-1-0-2023-01-24", Protocols.TLS10, False, False, s2n=True, pq=True)
335323
PQ_TLS_1_3_2023_06_01 = Cipher(

tests/integrationv2/test_pq_handshake.py

Lines changed: 23 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414

1515
CIPHERS = [
1616
None, # `None` will default to the appropriate `test_all` cipher preference in the S2N client provider
17-
Ciphers.KMS_PQ_TLS_1_0_2019_06,
18-
Ciphers.KMS_PQ_TLS_1_0_2020_02,
19-
Ciphers.KMS_PQ_TLS_1_0_2020_07,
20-
Ciphers.PQ_SIKE_TEST_TLS_1_0_2019_11,
21-
Ciphers.PQ_SIKE_TEST_TLS_1_0_2020_02,
2217
Ciphers.KMS_TLS_1_0_2018_10,
23-
Ciphers.PQ_TLS_1_0_2020_12,
2418
Ciphers.PQ_TLS_1_3_2023_06_01,
2519
]
2620

@@ -32,124 +26,35 @@
3226
]
3327

3428
EXPECTED_RESULTS = {
35-
# The tuple keys have the form (client_{cipher, kem_group}, server_{cipher, kem_group})
36-
(Ciphers.KMS_PQ_TLS_1_0_2019_06, Ciphers.KMS_PQ_TLS_1_0_2019_06):
37-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
38-
"kem": None, "kem_group": None},
39-
(Ciphers.KMS_PQ_TLS_1_0_2019_06, Ciphers.KMS_PQ_TLS_1_0_2020_02):
40-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
41-
"kem": None, "kem_group": None},
42-
(Ciphers.KMS_PQ_TLS_1_0_2019_06, Ciphers.KMS_PQ_TLS_1_0_2020_07):
43-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
44-
"kem": None, "kem_group": None},
45-
46-
(Ciphers.KMS_PQ_TLS_1_0_2020_02, Ciphers.KMS_PQ_TLS_1_0_2019_06):
47-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
48-
"kem": None, "kem_group": None},
49-
(Ciphers.KMS_PQ_TLS_1_0_2020_02, Ciphers.KMS_PQ_TLS_1_0_2020_02):
50-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
51-
"kem": None, "kem_group": None},
52-
(Ciphers.KMS_PQ_TLS_1_0_2020_02, Ciphers.KMS_PQ_TLS_1_0_2020_07):
53-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
54-
"kem": None, "kem_group": None},
55-
56-
(Ciphers.KMS_PQ_TLS_1_0_2020_07, Ciphers.KMS_PQ_TLS_1_0_2019_06):
57-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
58-
"kem": None, "kem_group": None},
59-
(Ciphers.KMS_PQ_TLS_1_0_2020_07, Ciphers.KMS_PQ_TLS_1_0_2020_02):
60-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
61-
"kem": None, "kem_group": None},
62-
(Ciphers.KMS_PQ_TLS_1_0_2020_07, Ciphers.KMS_PQ_TLS_1_0_2020_07):
63-
{"cipher": "ECDHE-KYBER-RSA-AES256-GCM-SHA384",
64-
"kem": "kyber512r3", "kem_group": None},
65-
66-
(Ciphers.PQ_SIKE_TEST_TLS_1_0_2019_11, Ciphers.KMS_PQ_TLS_1_0_2019_06):
67-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
68-
"kem": None, "kem_group": None},
69-
(Ciphers.PQ_SIKE_TEST_TLS_1_0_2019_11, Ciphers.KMS_PQ_TLS_1_0_2020_02):
70-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
71-
"kem": None, "kem_group": None},
72-
(Ciphers.PQ_SIKE_TEST_TLS_1_0_2019_11, Ciphers.KMS_PQ_TLS_1_0_2020_07):
73-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
74-
"kem": None, "kem_group": None},
75-
76-
(Ciphers.PQ_SIKE_TEST_TLS_1_0_2020_02, Ciphers.KMS_PQ_TLS_1_0_2019_06):
77-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
78-
"kem": None, "kem_group": None},
79-
(Ciphers.PQ_SIKE_TEST_TLS_1_0_2020_02, Ciphers.KMS_PQ_TLS_1_0_2020_02):
80-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
81-
"kem": None, "kem_group": None},
82-
(Ciphers.PQ_SIKE_TEST_TLS_1_0_2020_02, Ciphers.KMS_PQ_TLS_1_0_2020_07):
83-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
84-
"kem": None, "kem_group": None},
85-
86-
(Ciphers.KMS_PQ_TLS_1_0_2019_06, Ciphers.KMS_TLS_1_0_2018_10):
87-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
88-
"kem": None, "kem_group": None},
89-
(Ciphers.KMS_PQ_TLS_1_0_2020_02, Ciphers.KMS_TLS_1_0_2018_10):
90-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
91-
"kem": None, "kem_group": None},
92-
(Ciphers.KMS_PQ_TLS_1_0_2020_07, Ciphers.KMS_TLS_1_0_2018_10):
93-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
94-
"kem": None, "kem_group": None},
95-
96-
(Ciphers.KMS_TLS_1_0_2018_10, Ciphers.KMS_PQ_TLS_1_0_2019_06):
97-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
98-
"kem": None, "kem_group": None},
99-
(Ciphers.KMS_TLS_1_0_2018_10, Ciphers.KMS_PQ_TLS_1_0_2020_02):
100-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
101-
"kem": None, "kem_group": None},
102-
(Ciphers.KMS_TLS_1_0_2018_10, Ciphers.KMS_PQ_TLS_1_0_2020_07):
103-
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
104-
"kem": None, "kem_group": None},
105-
106-
# The expected kem_group string for this case purposefully excludes a curve;
107-
# depending on how s2n was compiled, the curve may be either x25519 or one
108-
# of the NIST curves.
109-
(Ciphers.PQ_TLS_1_0_2020_12, Ciphers.PQ_TLS_1_0_2020_12):
110-
{"cipher": "TLS_AES_256_GCM_SHA384",
111-
"kem": None, "kem_group": "_kyber-512-r3"},
112-
(Ciphers.PQ_TLS_1_0_2020_12, Ciphers.PQ_TLS_1_0_2023_01):
113-
{"cipher": "TLS_AES_256_GCM_SHA384",
114-
"kem": None, "kem_group": "_kyber-512-r3"},
29+
# The tuple keys have the form:
30+
# (client_{cipher, kem_group}, server_{cipher, kem_group}): {"cipher": {expected_cipher}, "kem_group": {expected_kem_group}}
11531
(Ciphers.PQ_TLS_1_0_2023_01, Ciphers.PQ_TLS_1_0_2023_01):
11632
{"cipher": "TLS_AES_256_GCM_SHA384",
117-
"kem": None, "kem_group": "_kyber-512-r3"},
118-
(Ciphers.PQ_TLS_1_0_2023_01, Ciphers.PQ_TLS_1_0_2020_12):
119-
{"cipher": "TLS_AES_256_GCM_SHA384",
120-
"kem": None, "kem_group": "_kyber-512-r3"},
121-
(Ciphers.PQ_TLS_1_0_2020_12, Ciphers.KMS_PQ_TLS_1_0_2020_07):
122-
{"cipher": "ECDHE-KYBER-RSA-AES256-GCM-SHA384",
123-
"kem": "kyber512r3", "kem_group": None},
124-
(Ciphers.KMS_PQ_TLS_1_0_2020_07, Ciphers.PQ_TLS_1_0_2020_12):
125-
{"cipher": "ECDHE-KYBER-RSA-AES256-GCM-SHA384",
126-
"kem": "kyber512r3", "kem_group": None},
127-
(Ciphers.PQ_TLS_1_0_2020_12, KemGroups.P256_KYBER512R3):
128-
{"cipher": "AES256_GCM_SHA384", "kem": None,
129-
"kem_group": "secp256r1_kyber-512-r3"},
130-
(KemGroups.P256_KYBER512R3, Ciphers.PQ_TLS_1_0_2020_12):
131-
{"cipher": "AES256_GCM_SHA384", "kem": None,
132-
"kem_group": "secp256r1_kyber-512-r3"},
133-
(KemGroups.P256_KYBER512R3, Ciphers.PQ_TLS_1_0_2023_01):
134-
{"cipher": "AES256_GCM_SHA384", "kem": None,
135-
"kem_group": "secp256r1_kyber-512-r3"},
136-
(KemGroups.P256_KYBER512R3, Ciphers.PQ_TLS_1_3_2023_06_01):
137-
{"cipher": "AES256_GCM_SHA384", "kem": None,
138-
"kem_group": "secp256r1_kyber-512-r3"},
33+
"kem_group": "_kyber-512-r3"},
13934
(KemGroups.P384_KYBER768R3, Ciphers.PQ_TLS_1_3_2023_06_01):
140-
{"cipher": "AES256_GCM_SHA384", "kem": None,
141-
"kem_group": "secp384r1_kyber-768-r3"},
35+
{"cipher": "AES256_GCM_SHA384",
36+
"kem_group": "secp384r1_kyber-768-r3"},
14237
(KemGroups.P521_KYBER1024R3, Ciphers.PQ_TLS_1_3_2023_06_01):
143-
{"cipher": "AES256_GCM_SHA384", "kem": None,
144-
"kem_group": "secp521r1_kyber-1024-r3"},
38+
{"cipher": "AES256_GCM_SHA384",
39+
"kem_group": "secp521r1_kyber-1024-r3"},
14540
(Ciphers.PQ_TLS_1_3_2023_06_01, KemGroups.X25519Kyber768Draft00):
14641
{"cipher": "TLS_AES_256_GCM_SHA384",
147-
"kem": None,
14842
"kem_group": "X25519Kyber768Draft00"},
14943
(Ciphers.PQ_TLS_1_3_2023_06_01, KemGroups.SecP256r1Kyber768Draft00):
15044
{"cipher": "TLS_AES_256_GCM_SHA384",
151-
"kem": None,
15245
"kem_group": "SecP256r1Kyber768Draft00"},
46+
(Ciphers.PQ_TLS_1_3_2023_06_01, Ciphers.PQ_TLS_1_3_2023_06_01):
47+
{"cipher": "TLS_AES_256_GCM_SHA384",
48+
"kem_group": "SecP256r1Kyber768Draft00"},
49+
(Ciphers.PQ_TLS_1_3_2023_06_01, Ciphers.KMS_TLS_1_0_2018_10):
50+
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
51+
"kem_group": None},
52+
(Ciphers.KMS_TLS_1_0_2018_10, Ciphers.PQ_TLS_1_3_2023_06_01):
53+
{"cipher": "ECDHE-RSA-AES128-GCM-SHA256",
54+
"kem_group": None},
55+
(Ciphers.KMS_TLS_1_0_2018_10, Ciphers.KMS_TLS_1_0_2018_10):
56+
{"cipher": "ECDHE-RSA-AES256-GCM-SHA384",
57+
"kem_group": None},
15358
}
15459

15560
"""
@@ -185,16 +90,12 @@ def assert_s2n_negotiation_parameters(s2n_results, expected_result):
18590
if expected_result is not None:
18691
assert to_bytes(
18792
("Cipher negotiated: " + expected_result['cipher'])) in s2n_results.stdout
188-
if expected_result['kem']:
189-
assert to_bytes(
190-
("KEM: " + expected_result['kem'])) in s2n_results.stdout
191-
assert to_bytes(PQ_ENABLED_FLAG) in s2n_results.stdout
19293
if expected_result['kem_group']:
19394
# Purposefully leave off the "KEM Group: " prefix in order to perform partial matches
19495
# without specifying the curve.
19596
assert to_bytes(expected_result['kem_group']) in s2n_results.stdout
19697
assert to_bytes(PQ_ENABLED_FLAG) in s2n_results.stdout
197-
if not expected_result['kem'] and not expected_result['kem_group']:
98+
if not expected_result['kem_group']:
19899
assert to_bytes(PQ_ENABLED_FLAG) not in s2n_results.stdout
199100
assert to_bytes("Curve:") in s2n_results.stdout
200101

@@ -224,22 +125,6 @@ def test_nothing():
224125
@pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
225126
def test_s2nc_to_s2nd_pq_handshake(managed_process, protocol, certificate, client_cipher, server_cipher, provider,
226127
other_provider):
227-
# Incorrect cipher is negotiated when both ciphers are PQ_TLS_1_0_2020_12 with
228-
# openssl 1.0.2, boringssl, and libressl libcryptos
229-
if all([
230-
client_cipher == Ciphers.PQ_TLS_1_0_2020_12,
231-
server_cipher == Ciphers.PQ_TLS_1_0_2020_12,
232-
any([
233-
libcrypto in get_flag(S2N_PROVIDER_VERSION)
234-
for libcrypto in [
235-
"boringssl",
236-
"libressl",
237-
"openssl-1.0.2"
238-
]
239-
])
240-
]):
241-
pytest.skip()
242-
243128
port = next(available_ports)
244129

245130
client_options = ProviderOptions(
@@ -267,7 +152,7 @@ def test_s2nc_to_s2nd_pq_handshake(managed_process, protocol, certificate, clien
267152
# If PQ is not enabled in s2n, we expect classic handshakes to be negotiated.
268153
# Leave the expected cipher blank, as there are multiple possibilities - the
269154
# important thing is that kem and kem_group are NONE.
270-
expected_result = {"cipher": "", "kem": None, "kem_group": None}
155+
expected_result = {"cipher": "", "kem_group": None}
271156

272157
# Client and server are both s2n; can make meaningful assertions about negotiation for both
273158
for results in client.get_results():
@@ -359,7 +244,7 @@ def test_s2nd_to_awslc_pq_handshake(managed_process, s2n_server_policy, awslc_cl
359244

360245
@pytest.mark.uncollect_if(func=invalid_test_parameters)
361246
@pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
362-
@pytest.mark.parametrize("cipher", [Ciphers.PQ_TLS_1_0_2020_12], ids=get_parameter_name)
247+
@pytest.mark.parametrize("cipher", [Ciphers.PQ_TLS_1_3_2023_06_01], ids=get_parameter_name)
363248
@pytest.mark.parametrize("kem_group", KEM_GROUPS, ids=get_parameter_name)
364249
def test_s2nc_to_oqs_openssl_pq_handshake(managed_process, protocol, cipher, kem_group):
365250
# If PQ is not enabled in s2n, there is no reason to test against oqs_openssl
@@ -401,7 +286,7 @@ def test_s2nc_to_oqs_openssl_pq_handshake(managed_process, protocol, cipher, kem
401286

402287
@pytest.mark.uncollect_if(func=invalid_test_parameters)
403288
@pytest.mark.parametrize("protocol", [Protocols.TLS13], ids=get_parameter_name)
404-
@pytest.mark.parametrize("cipher", [Ciphers.PQ_TLS_1_0_2020_12], ids=get_parameter_name)
289+
@pytest.mark.parametrize("cipher", [Ciphers.PQ_TLS_1_3_2023_06_01], ids=get_parameter_name)
405290
@pytest.mark.parametrize("kem_group", KEM_GROUPS, ids=get_parameter_name)
406291
def test_oqs_openssl_to_s2nd_pq_handshake(managed_process, protocol, cipher, kem_group):
407292
# If PQ is not enabled in s2n, there is no reason to test against oqs_openssl

0 commit comments

Comments
 (0)