Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/test_17_ssl_use.py
2066 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#***************************************************************************
4
# _ _ ____ _
5
# Project ___| | | | _ \| |
6
# / __| | | | |_) | |
7
# | (__| |_| | _ <| |___
8
# \___|\___/|_| \_\_____|
9
#
10
# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
#
12
# This software is licensed as described in the file COPYING, which
13
# you should have received as part of this distribution. The terms
14
# are also available at https://curl.se/docs/copyright.html.
15
#
16
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
# copies of the Software, and permit persons to whom the Software is
18
# furnished to do so, under the terms of the COPYING file.
19
#
20
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
# KIND, either express or implied.
22
#
23
# SPDX-License-Identifier: curl
24
#
25
###########################################################################
26
#
27
import json
28
import logging
29
import os
30
import re
31
import pytest
32
33
from testenv import Env, CurlClient, LocalClient
34
35
36
log = logging.getLogger(__name__)
37
38
39
class TestSSLUse:
40
41
@pytest.fixture(autouse=True, scope='class')
42
def _class_scope(self, env, httpd, nghttpx):
43
env.make_data_file(indir=httpd.docs_dir, fname="data-10k", fsize=10*1024)
44
45
def test_17_01_sslinfo_plain(self, env: Env, httpd):
46
proto = 'http/1.1'
47
curl = CurlClient(env=env)
48
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
49
r = curl.http_get(url=url, alpn_proto=proto)
50
assert r.json['HTTPS'] == 'on', f'{r.json}'
51
assert 'SSL_SESSION_ID' in r.json, f'{r.json}'
52
assert 'SSL_SESSION_RESUMED' in r.json, f'{r.json}'
53
assert r.json['SSL_SESSION_RESUMED'] == 'Initial', f'{r.json}'
54
55
@pytest.mark.parametrize("tls_max", ['1.2', '1.3'])
56
def test_17_02_sslinfo_reconnect(self, env: Env, tls_max, httpd):
57
proto = 'http/1.1'
58
count = 3
59
exp_resumed = 'Resumed'
60
xargs = ['--sessionid', '--tls-max', tls_max, f'--tlsv{tls_max}']
61
if env.curl_uses_lib('libressl'):
62
if tls_max == '1.3':
63
exp_resumed = 'Initial' # 1.2 works in LibreSSL, but 1.3 does not, TODO
64
if env.curl_uses_lib('rustls-ffi'):
65
exp_resumed = 'Initial' # Rustls does not support sessions, TODO
66
if env.curl_uses_lib('bearssl') and tls_max == '1.3':
67
pytest.skip('BearSSL does not support TLSv1.3')
68
if env.curl_uses_lib('mbedtls') and tls_max == '1.3' and \
69
not env.curl_lib_version_at_least('mbedtls', '3.6.0'):
70
pytest.skip('mbedtls TLSv1.3 session resume not working in 3.6.0')
71
72
run_env = os.environ.copy()
73
run_env['CURL_DEBUG'] = 'ssl'
74
curl = CurlClient(env=env, run_env=run_env)
75
# tell the server to close the connection after each request
76
urln = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo?'\
77
f'id=[0-{count-1}]&close'
78
r = curl.http_download(urls=[urln], alpn_proto=proto, with_stats=True,
79
extra_args=xargs)
80
r.check_response(count=count, http_status=200)
81
# should have used one connection for each request, sessions after
82
# first should have been resumed
83
assert r.total_connects == count, r.dump_logs()
84
for i in range(count):
85
dfile = curl.download_file(i)
86
assert os.path.exists(dfile)
87
with open(dfile) as f:
88
djson = json.load(f)
89
assert djson['HTTPS'] == 'on', f'{i}: {djson}'
90
if i == 0:
91
assert djson['SSL_SESSION_RESUMED'] == 'Initial', f'{i}: {djson}\n{r.dump_logs()}'
92
else:
93
assert djson['SSL_SESSION_RESUMED'] == exp_resumed, f'{i}: {djson}\n{r.dump_logs()}'
94
95
# use host name with trailing dot, verify handshake
96
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
97
def test_17_03_trailing_dot(self, env: Env, proto, httpd, nghttpx):
98
if proto == 'h3' and not env.have_h3():
99
pytest.skip("h3 not supported")
100
curl = CurlClient(env=env)
101
domain = f'{env.domain1}.'
102
url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
103
r = curl.http_get(url=url, alpn_proto=proto)
104
assert r.exit_code == 0, f'{r}'
105
assert r.json, f'{r}'
106
if proto != 'h3': # we proxy h3
107
# the SNI the server received is without trailing dot
108
assert r.json['SSL_TLS_SNI'] == env.domain1, f'{r.json}'
109
110
# use host name with double trailing dot, verify handshake
111
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
112
def test_17_04_double_dot(self, env: Env, proto, httpd, nghttpx):
113
if proto == 'h3' and not env.have_h3():
114
pytest.skip("h3 not supported")
115
curl = CurlClient(env=env)
116
domain = f'{env.domain1}..'
117
url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
118
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
119
'-H', f'Host: {env.domain1}',
120
])
121
if r.exit_code == 0:
122
assert r.json, f'{r.stdout}'
123
# the SNI the server received is without trailing dot
124
if proto != 'h3': # we proxy h3
125
assert r.json['SSL_TLS_SNI'] == env.domain1, f'{r.json}'
126
assert False, f'should not have succeeded: {r.json}'
127
# 7 - Rustls rejects a servername with .. during setup
128
# 35 - LibreSSL rejects setting an SNI name with trailing dot
129
# 60 - peer name matching failed against certificate
130
assert r.exit_code in [7, 35, 60], f'{r}'
131
132
# use ip address for connect
133
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
134
def test_17_05_good_ip_addr(self, env: Env, proto, httpd, nghttpx):
135
if env.curl_uses_lib('bearssl'):
136
pytest.skip("BearSSL does not support cert verification with IP addresses")
137
if env.curl_uses_lib('mbedtls'):
138
pytest.skip("mbedTLS does use IP addresses in SNI")
139
if proto == 'h3' and not env.have_h3():
140
pytest.skip("h3 not supported")
141
curl = CurlClient(env=env)
142
domain = '127.0.0.1'
143
url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
144
r = curl.http_get(url=url, alpn_proto=proto)
145
assert r.exit_code == 0, f'{r}'
146
assert r.json, f'{r}'
147
if proto != 'h3': # we proxy h3
148
# the SNI should not have been used
149
assert 'SSL_TLS_SNI' not in r.json, f'{r.json}'
150
151
# use IP address that is not in cert
152
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
153
def test_17_05_bad_ip_addr(self, env: Env, proto,
154
httpd, configures_httpd,
155
nghttpx, configures_nghttpx):
156
if proto == 'h3' and not env.have_h3():
157
pytest.skip("h3 not supported")
158
httpd.set_domain1_cred_name('domain1-no-ip')
159
httpd.reload_if_config_changed()
160
if proto == 'h3':
161
nghttpx.set_cred_name('domain1-no-ip')
162
nghttpx.reload_if_config_changed()
163
curl = CurlClient(env=env)
164
url = f'https://127.0.0.1:{env.port_for(proto)}/curltest/sslinfo'
165
r = curl.http_get(url=url, alpn_proto=proto)
166
assert r.exit_code == 60, f'{r}'
167
168
# use localhost for connect
169
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
170
def test_17_06_localhost(self, env: Env, proto, httpd, nghttpx):
171
if proto == 'h3' and not env.have_h3():
172
pytest.skip("h3 not supported")
173
curl = CurlClient(env=env)
174
domain = 'localhost'
175
url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
176
r = curl.http_get(url=url, alpn_proto=proto)
177
assert r.exit_code == 0, f'{r}'
178
assert r.json, f'{r}'
179
if proto != 'h3': # we proxy h3
180
assert r.json['SSL_TLS_SNI'] == domain, f'{r.json}'
181
182
@staticmethod
183
def gen_test_17_07_list():
184
tls13_tests = [
185
['def', None, True],
186
['AES128SHA256', ['TLS_AES_128_GCM_SHA256'], True],
187
['AES128SHA384', ['TLS_AES_256_GCM_SHA384'], False],
188
['CHACHA20SHA256', ['TLS_CHACHA20_POLY1305_SHA256'], True],
189
['AES128SHA384+CHACHA20SHA256', ['TLS_AES_256_GCM_SHA384', 'TLS_CHACHA20_POLY1305_SHA256'], True],
190
]
191
tls12_tests = [
192
['def', None, True],
193
['AES128ish', ['ECDHE-ECDSA-AES128-GCM-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256'], True],
194
['AES256ish', ['ECDHE-ECDSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES256-GCM-SHA384'], False],
195
['CHACHA20ish', ['ECDHE-ECDSA-CHACHA20-POLY1305', 'ECDHE-RSA-CHACHA20-POLY1305'], True],
196
['AES256ish+CHACHA20ish', ['ECDHE-ECDSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES256-GCM-SHA384',
197
'ECDHE-ECDSA-CHACHA20-POLY1305', 'ECDHE-RSA-CHACHA20-POLY1305'], True],
198
]
199
ret = []
200
for tls_id, tls_proto in {
201
'TLSv1.2+3': 'TLSv1.3 +TLSv1.2',
202
'TLSv1.3': 'TLSv1.3',
203
'TLSv1.2': 'TLSv1.2'}.items():
204
for [cid13, ciphers13, succeed13] in tls13_tests:
205
for [cid12, ciphers12, succeed12] in tls12_tests:
206
id = f'{tls_id}-{cid13}-{cid12}'
207
ret.append(pytest.param(tls_proto, ciphers13, ciphers12, succeed13, succeed12, id=id))
208
return ret
209
210
@pytest.mark.parametrize(
211
"tls_proto, ciphers13, ciphers12, succeed13, succeed12",
212
gen_test_17_07_list())
213
def test_17_07_ssl_ciphers(self, env: Env, httpd, configures_httpd,
214
tls_proto, ciphers13, ciphers12,
215
succeed13, succeed12):
216
# to test setting cipher suites, the AES 256 ciphers are disabled in the test server
217
httpd.set_extra_config('base', [
218
'SSLCipherSuite SSL'
219
' ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256'
220
':ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305',
221
'SSLCipherSuite TLSv1.3'
222
' TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256',
223
f'SSLProtocol {tls_proto}'
224
])
225
httpd.reload_if_config_changed()
226
proto = 'http/1.1'
227
curl = CurlClient(env=env)
228
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
229
# SSL backend specifics
230
if env.curl_uses_lib('gnutls'):
231
pytest.skip('GnuTLS does not support setting ciphers')
232
elif env.curl_uses_lib('boringssl'):
233
if ciphers13 is not None:
234
pytest.skip('BoringSSL does not support setting TLSv1.3 ciphers')
235
elif env.curl_uses_lib('schannel'): # not in CI, so untested
236
if ciphers12 is not None:
237
pytest.skip('Schannel does not support setting TLSv1.2 ciphers by name')
238
elif env.curl_uses_lib('bearssl'):
239
if tls_proto == 'TLSv1.3':
240
pytest.skip('BearSSL does not support TLSv1.3')
241
tls_proto = 'TLSv1.2'
242
elif env.curl_uses_lib('mbedtls') and not env.curl_lib_version_at_least('mbedtls', '3.6.0'):
243
if tls_proto == 'TLSv1.3':
244
pytest.skip('mbedTLS < 3.6.0 does not support TLSv1.3')
245
elif env.curl_uses_lib('sectransp'): # not in CI, so untested
246
if tls_proto == 'TLSv1.3':
247
pytest.skip('Secure Transport does not support TLSv1.3')
248
tls_proto = 'TLSv1.2'
249
# test
250
extra_args = ['--tls13-ciphers', ':'.join(ciphers13)] if ciphers13 else []
251
extra_args += ['--ciphers', ':'.join(ciphers12)] if ciphers12 else []
252
r = curl.http_get(url=url, alpn_proto=proto, extra_args=extra_args)
253
if tls_proto != 'TLSv1.2' and succeed13:
254
assert r.exit_code == 0, r.dump_logs()
255
assert r.json['HTTPS'] == 'on', r.dump_logs()
256
assert r.json['SSL_PROTOCOL'] == 'TLSv1.3', r.dump_logs()
257
assert ciphers13 is None or r.json['SSL_CIPHER'] in ciphers13, r.dump_logs()
258
elif tls_proto == 'TLSv1.2' and succeed12:
259
assert r.exit_code == 0, r.dump_logs()
260
assert r.json['HTTPS'] == 'on', r.dump_logs()
261
assert r.json['SSL_PROTOCOL'] == 'TLSv1.2', r.dump_logs()
262
assert ciphers12 is None or r.json['SSL_CIPHER'] in ciphers12, r.dump_logs()
263
else:
264
assert r.exit_code != 0, r.dump_logs()
265
266
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
267
def test_17_08_cert_status(self, env: Env, proto, httpd, nghttpx):
268
if proto == 'h3' and not env.have_h3():
269
pytest.skip("h3 not supported")
270
if not env.curl_uses_lib('openssl') and \
271
not env.curl_uses_lib('gnutls') and \
272
not env.curl_uses_lib('quictls'):
273
pytest.skip("TLS library does not support --cert-status")
274
curl = CurlClient(env=env)
275
domain = 'localhost'
276
url = f'https://{env.authority_for(domain, proto)}/'
277
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
278
'--cert-status'
279
])
280
# CURLE_SSL_INVALIDCERTSTATUS, our certs have no OCSP info
281
assert r.exit_code == 91, f'{r}'
282
283
@staticmethod
284
def gen_test_17_09_list():
285
return [[tls_proto, max_ver, min_ver]
286
for tls_proto in ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']
287
for max_ver in range(5)
288
for min_ver in range(-2, 4)]
289
290
@pytest.mark.parametrize("tls_proto, max_ver, min_ver", gen_test_17_09_list())
291
def test_17_09_ssl_min_max(self, env: Env, httpd, configures_httpd, tls_proto, max_ver, min_ver):
292
httpd.set_extra_config('base', [
293
f'SSLProtocol {tls_proto}',
294
'SSLCipherSuite ALL:@SECLEVEL=0',
295
])
296
httpd.reload_if_config_changed()
297
proto = 'http/1.1'
298
run_env = os.environ.copy()
299
if env.curl_uses_lib('gnutls'):
300
# we need to override any default system configuration since
301
# we want to test all protocol versions. Ubuntu (or the GH image)
302
# disable TSL1.0 and TLS1.1 system wide. We do not want.
303
our_config = os.path.join(env.gen_dir, 'gnutls_config')
304
if not os.path.exists(our_config):
305
with open(our_config, 'w') as fd:
306
fd.write('# empty\n')
307
run_env['GNUTLS_SYSTEM_PRIORITY_FILE'] = our_config
308
curl = CurlClient(env=env, run_env=run_env)
309
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
310
# SSL backend specifics
311
if env.curl_uses_lib('bearssl'):
312
supported = ['TLSv1', 'TLSv1.1', 'TLSv1.2', None]
313
elif env.curl_uses_lib('sectransp'): # not in CI, so untested
314
supported = ['TLSv1', 'TLSv1.1', 'TLSv1.2', None]
315
elif env.curl_uses_lib('gnutls'):
316
supported = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']
317
elif env.curl_uses_lib('quiche'):
318
supported = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']
319
elif env.curl_uses_lib('aws-lc'):
320
supported = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']
321
else: # most SSL backends dropped support for TLSv1.0, TLSv1.1
322
supported = [None, None, 'TLSv1.2', 'TLSv1.3']
323
# test
324
extra_args = [[], ['--tlsv1'], ['--tlsv1.0'], ['--tlsv1.1'], ['--tlsv1.2'], ['--tlsv1.3']][min_ver+2] + \
325
[['--tls-max', '1.0'], ['--tls-max', '1.1'], ['--tls-max', '1.2'], ['--tls-max', '1.3'], []][max_ver]
326
extra_args.extend(['--trace-config', 'ssl'])
327
r = curl.http_get(url=url, alpn_proto=proto, extra_args=extra_args)
328
if max_ver >= min_ver and tls_proto in supported[max(0, min_ver):min(max_ver, 3)+1]:
329
assert r.exit_code == 0, f'extra_args={extra_args}\n{r.dump_logs()}'
330
assert r.json['HTTPS'] == 'on', r.dump_logs()
331
assert r.json['SSL_PROTOCOL'] == tls_proto, r.dump_logs()
332
else:
333
assert r.exit_code != 0, f'extra_args={extra_args}\n{r.dump_logs()}'
334
335
def test_17_10_h3_session_reuse(self, env: Env, httpd, nghttpx):
336
if not env.have_h3():
337
pytest.skip("h3 not supported")
338
if not env.curl_uses_lib('quictls') and \
339
not (env.curl_uses_lib('openssl') and env.curl_uses_lib('ngtcp2')) and \
340
not env.curl_uses_lib('gnutls') and \
341
not env.curl_uses_lib('wolfssl'):
342
pytest.skip("QUIC session reuse not implemented")
343
count = 2
344
docname = 'data-10k'
345
url = f'https://localhost:{env.https_port}/{docname}'
346
client = LocalClient(name='hx-download', env=env)
347
if not client.exists():
348
pytest.skip(f'example client not built: {client.name}')
349
r = client.run(args=[
350
'-n', f'{count}',
351
'-f', # forbid reuse of connections
352
'-r', f'{env.domain1}:{env.port_for("h3")}:127.0.0.1',
353
'-V', 'h3', url
354
])
355
r.check_exit_code(0)
356
# check that TLS session was reused as expected
357
reused_session = False
358
for line in r.trace_lines:
359
if re.match(r'.*\[1-1] (\* )?SSL reusing session.*', line):
360
reused_session = True
361
assert reused_session, f'{r}\n{r.dump_logs()}'
362
363
# use host name server has no certificate for
364
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
365
def test_17_11_wrong_host(self, env: Env, proto, httpd, nghttpx):
366
if proto == 'h3' and not env.have_h3():
367
pytest.skip("h3 not supported")
368
curl = CurlClient(env=env)
369
domain = f'insecure.{env.tld}'
370
url = f'https://{domain}:{env.port_for(proto)}/curltest/sslinfo'
371
r = curl.http_get(url=url, alpn_proto=proto)
372
assert r.exit_code == 60, f'{r}'
373
374
# use host name server has no cert for with --insecure
375
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
376
def test_17_12_insecure(self, env: Env, proto, httpd, nghttpx):
377
if proto == 'h3' and not env.have_h3():
378
pytest.skip("h3 not supported")
379
curl = CurlClient(env=env)
380
domain = f'insecure.{env.tld}'
381
url = f'https://{domain}:{env.port_for(proto)}/curltest/sslinfo'
382
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
383
'--insecure'
384
])
385
assert r.exit_code == 0, f'{r}'
386
assert r.json, f'{r}'
387
388
# connect to an expired certificate
389
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
390
def test_17_14_expired_cert(self, env: Env, proto, httpd):
391
if proto == 'h3' and not env.have_h3():
392
pytest.skip("h3 not supported")
393
curl = CurlClient(env=env)
394
url = f'https://{env.expired_domain}:{env.port_for(proto)}/'
395
r = curl.http_get(url=url, alpn_proto=proto)
396
assert r.exit_code == 60, f'{r}' # peer failed verification
397
exp_trace = None
398
match_trace = None
399
if env.curl_uses_lib('openssl') or env.curl_uses_lib('quictls'):
400
exp_trace = r'.*SSL certificate problem: certificate has expired$'
401
elif env.curl_uses_lib('gnutls'):
402
exp_trace = r'.*server verification failed: certificate has expired\..*'
403
elif env.curl_uses_lib('wolfssl'):
404
exp_trace = r'.*server verification failed: certificate has expired\.$'
405
if exp_trace is not None:
406
for line in r.trace_lines:
407
if re.match(exp_trace, line):
408
match_trace = line
409
break
410
assert match_trace, f'Did not find "{exp_trace}" in trace\n{r.dump_logs()}'
411
412
@pytest.mark.skipif(condition=not Env.curl_has_feature('SSLS-EXPORT'),
413
reason='curl lacks SSL session export support')
414
def test_17_15_session_export(self, env: Env, httpd):
415
proto = 'http/1.1'
416
if env.curl_uses_lib('libressl'):
417
pytest.skip('Libressl resumption does not work inTLSv1.3')
418
if env.curl_uses_lib('rustls-ffi'):
419
pytest.skip('rustsls does not expose sessions')
420
if env.curl_uses_lib('bearssl'):
421
pytest.skip('BearSSL does not support TLSv1.3')
422
if env.curl_uses_lib('mbedtls') and \
423
not env.curl_lib_version_at_least('mbedtls', '3.6.0'):
424
pytest.skip('mbedtls TLSv1.3 session resume not working before 3.6.0')
425
run_env = os.environ.copy()
426
run_env['CURL_DEBUG'] = 'ssl,ssls'
427
# clean session file first, then reuse
428
session_file = os.path.join(env.gen_dir, 'test_17_15.sessions')
429
if os.path.exists(session_file):
430
return os.remove(session_file)
431
xargs = ['--tls-max', '1.3', '--tlsv1.3', '--ssl-sessions', session_file]
432
curl = CurlClient(env=env, run_env=run_env)
433
# tell the server to close the connection after each request
434
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
435
r = curl.http_get(url=url, alpn_proto=proto, extra_args=xargs)
436
assert r.exit_code == 0, f'{r}'
437
assert r.json['HTTPS'] == 'on', f'{r.json}'
438
assert r.json['SSL_SESSION_RESUMED'] == 'Initial', f'{r.json}\n{r.dump_logs()}'
439
# ok, run again, sessions should be imported
440
run_dir2 = os.path.join(env.gen_dir, 'curl2')
441
curl = CurlClient(env=env, run_env=run_env, run_dir=run_dir2)
442
r = curl.http_get(url=url, alpn_proto=proto, extra_args=xargs)
443
assert r.exit_code == 0, f'{r}'
444
assert r.json['SSL_SESSION_RESUMED'] == 'Resumed', f'{r.json}\n{r.dump_logs()}'
445
446
# verify the ciphers are ignored when talking TLSv1.3 only
447
# see issue #16232
448
def test_17_16_h3_ignore_ciphers12(self, env: Env, httpd, nghttpx):
449
proto = 'h3'
450
if proto == 'h3' and not env.have_h3():
451
pytest.skip("h3 not supported")
452
if env.curl_uses_lib('gnutls'):
453
pytest.skip("gnutls does not ignore --ciphers on TLSv1.3")
454
curl = CurlClient(env=env)
455
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
456
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
457
'--ciphers', 'NONSENSE'
458
])
459
assert r.exit_code == 0, f'{r}'
460
461
def test_17_17_h1_ignore_ciphers13(self, env: Env, httpd):
462
proto = 'http/1.1'
463
curl = CurlClient(env=env)
464
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
465
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
466
'--tls13-ciphers', 'NONSENSE', '--tls-max', '1.2'
467
])
468
assert r.exit_code == 0, f'{r}'
469
470
@pytest.mark.parametrize("priority, tls_proto, ciphers, success", [
471
pytest.param("", "", [], False, id='prio-empty'),
472
pytest.param("NONSENSE", "", [], False, id='nonsense'),
473
pytest.param("+NONSENSE", "", [], False, id='+nonsense'),
474
pytest.param("NORMAL:-VERS-ALL:+VERS-TLS1.2", "TLSv1.2", ['ECDHE-RSA-CHACHA20-POLY1305'], True, id='TLSv1.2-normal-only'),
475
pytest.param("-VERS-ALL:+VERS-TLS1.2", "TLSv1.2", ['ECDHE-RSA-CHACHA20-POLY1305'], True, id='TLSv1.2-only'),
476
pytest.param("NORMAL", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-normal'),
477
pytest.param("NORMAL:-VERS-ALL:+VERS-TLS1.3", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-normal-only'),
478
pytest.param("-VERS-ALL:+VERS-TLS1.3", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-only'),
479
pytest.param("!CHACHA20-POLY1305", "TLSv1.3", ['TLS_AES_128_GCM_SHA256'], True, id='TLSv1.3-no-chacha'),
480
pytest.param("-CIPHER-ALL:+CHACHA20-POLY1305", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-only-chacha'),
481
pytest.param("-CIPHER-ALL:+AES-256-GCM", "", [], False, id='only-AES256'),
482
pytest.param("-CIPHER-ALL:+AES-128-GCM", "TLSv1.3", ['TLS_AES_128_GCM_SHA256'], True, id='TLSv1.3-only-AES128'),
483
pytest.param("SECURE:-CIPHER-ALL:+AES-128-GCM:-VERS-ALL:+VERS-TLS1.2", "TLSv1.2", ['ECDHE-RSA-AES128-GCM-SHA256'], True, id='TLSv1.2-secure'),
484
pytest.param("-MAC-ALL:+SHA256", "", [], False, id='MAC-only-SHA256'),
485
pytest.param("-MAC-ALL:+AEAD", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-MAC-only-AEAD'),
486
pytest.param("-GROUP-ALL:+GROUP-X25519", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-group-only-X25519'),
487
pytest.param("-GROUP-ALL:+GROUP-SECP192R1", "", [], False, id='group-only-SECP192R1'),
488
])
489
def test_17_18_gnutls_priority(self, env: Env, httpd, configures_httpd, priority, tls_proto, ciphers, success):
490
# to test setting cipher suites, the AES 256 ciphers are disabled in the test server
491
httpd.set_extra_config('base', [
492
'SSLCipherSuite SSL'
493
' ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256'
494
':ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305',
495
'SSLCipherSuite TLSv1.3'
496
' TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256',
497
])
498
httpd.reload_if_config_changed()
499
proto = 'http/1.1'
500
curl = CurlClient(env=env)
501
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
502
# SSL backend specifics
503
if not env.curl_uses_lib('gnutls'):
504
pytest.skip('curl not build with GnuTLS')
505
# test
506
extra_args = ['--ciphers', f'{priority}']
507
r = curl.http_get(url=url, alpn_proto=proto, extra_args=extra_args)
508
if success:
509
assert r.exit_code == 0, r.dump_logs()
510
assert r.json['HTTPS'] == 'on', r.dump_logs()
511
if tls_proto:
512
assert r.json['SSL_PROTOCOL'] == tls_proto, r.dump_logs()
513
assert r.json['SSL_CIPHER'] in ciphers, r.dump_logs()
514
else:
515
assert r.exit_code != 0, r.dump_logs()
516
517
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
518
def test_17_19_wrong_pin(self, env: Env, proto, httpd):
519
if proto == 'h3' and not env.have_h3():
520
pytest.skip("h3 not supported")
521
if env.curl_uses_any_libs(['bearssl', 'rustls-ffi']):
522
pytest.skip('TLS backend ignores --pinnedpubkey')
523
curl = CurlClient(env=env)
524
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
525
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
526
'--pinnedpubkey', 'sha256//ffff'
527
])
528
# expect NOT_IMPLEMENTED or CURLE_SSL_PINNEDPUBKEYNOTMATCH
529
assert r.exit_code in [2, 90], f'{r.dump_logs()}'
530
531
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
532
def test_17_20_correct_pin(self, env: Env, proto, httpd):
533
if proto == 'h3' and not env.have_h3():
534
pytest.skip("h3 not supported")
535
curl = CurlClient(env=env)
536
creds = env.get_credentials(env.domain1)
537
assert creds
538
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
539
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
540
'--pinnedpubkey', f'sha256//{creds.pub_sha256_b64()}'
541
])
542
# expect NOT_IMPLEMENTED or OK
543
assert r.exit_code in [0, 2], f'{r.dump_logs()}'
544
545