Artifactspublic-v0

curl

master
ply4 git calls223 ms294 KiB2 cachedprotocol v2
629 lines31 KiBRaw
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
21# SPDX-License-Identifier: curl
23###########################################################################
25import json
26import logging
27import os
28import re
29from dataclasses import dataclass
30from typing import ClassVar, Dict, List
32import pytest
33from testenv import CurlClient, Env, LocalClient
35log = logging.getLogger(__name__)
38@dataclass(frozen=True)
39class TLSDefs:
40 TLS_VERSIONS: ClassVar[List[str]] = ['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']
41 TLS_VERSION_IDS: ClassVar[Dict[str, int]] = {
42 'TLSv1': 0x301,
43 'TLSv1.1': 0x302,
44 'TLSv1.2': 0x303,
45 'TLSv1.3': 0x304
46 }
47 CURL_ARG_MIN_VERSION_ID: ClassVar[Dict[str, int]] = {
48 'none': 0x0,
49 'tlsv1': 0x301,
50 'tlsv1.0': 0x301,
51 'tlsv1.1': 0x302,
52 'tlsv1.2': 0x303,
53 'tlsv1.3': 0x304,
54 }
55 CURL_ARG_MAX_VERSION_ID: ClassVar[Dict[str, int]] = {
56 'none': 0x0,
57 '1.0': 0x301,
58 '1.1': 0x302,
59 '1.2': 0x303,
60 '1.3': 0x304,
61 }
64class TestSSLUse:
66 @pytest.fixture(autouse=True, scope='class')
67 @classmethod
68 def _class_scope(cls, env, httpd, nghttpx):
69 env.make_data_file(indir=httpd.docs_dir, fname="data-10k", fsize=10 * 1024)
71 def test_17_01_sslinfo_plain(self, env: Env, httpd):
72 if env.curl_uses_lib('libressl') and env.curl_lib_version('libressl') == '4.4.0':
73 pytest.skip('LibreSSL 4.4.0 skipped due to incompatibility with OpenSSL 4.1.0+-based servers')
74 proto = 'http/1.1'
75 curl = CurlClient(env=env)
76 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
77 r = curl.http_get(url=url, alpn_proto=proto)
78 assert r.json['HTTPS'] == 'on', f'{r.json}'
79 assert 'SSL_SESSION_ID' in r.json, f'{r.json}'
80 assert 'SSL_SESSION_RESUMED' in r.json, f'{r.json}'
81 assert r.json['SSL_SESSION_RESUMED'] == 'Initial', f'{r.json}'
83 @pytest.mark.parametrize("tls_max", ['1.2', '1.3'])
84 def test_17_02_sslinfo_reconnect(self, env: Env, tls_max, httpd):
85 proto = 'http/1.1'
86 count = 3
87 exp_resumed = 'Resumed'
88 xargs = ['--sessionid', '--tls-max', tls_max, f'--tlsv{tls_max}']
89 if env.curl_uses_lib('libressl') and tls_max == '1.3':
90 exp_resumed = 'Initial' # 1.2 works in LibreSSL, but 1.3 does not, TODO
91 if env.curl_uses_lib('rustls-ffi'):
92 exp_resumed = 'Initial' # Rustls does not support sessions, TODO
93 if env.curl_uses_lib('mbedtls') and tls_max == '1.3' and \
94 not env.curl_lib_version_at_least('mbedtls', '3.6.0'):
95 pytest.skip('mbedtls TLSv1.3 session resume not working in 3.6.0')
97 run_env = os.environ.copy()
98 run_env['CURL_DEBUG'] = 'ssl'
99 curl = CurlClient(env=env, run_env=run_env)
100 # tell the server to close the connection after each request
101 urln = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo?'\
102 f'id=[0-{count-1}]&close'
103 r = curl.http_download(urls=[urln], alpn_proto=proto, with_stats=True,
104 extra_args=xargs)
105 r.check_response(count=count, http_status=200)
106 # should have used one connection for each request, sessions after
107 # first should have been resumed
108 assert r.total_connects == count, r.dump_logs()
109 for i in range(count):
110 dfile = curl.download_file(i)
111 assert os.path.exists(dfile)
112 with open(dfile) as f:
113 djson = json.load(f)
114 assert djson['HTTPS'] == 'on', f'{i}: {djson}'
115 if i == 0:
116 assert djson['SSL_SESSION_RESUMED'] == 'Initial', f'{i}: {djson}\n{r.dump_logs()}'
117 else:
118 assert djson['SSL_SESSION_RESUMED'] == exp_resumed, f'{i}: {djson}\n{r.dump_logs()}'
120 # use hostname with trailing dot, verify handshake
121 @pytest.mark.parametrize("proto", Env.http_protos())
122 def test_17_03_trailing_dot(self, env: Env, proto, httpd, nghttpx):
123 curl = CurlClient(env=env)
124 domain = f'{env.domain1}.'
125 url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
126 r = curl.http_get(url=url, alpn_proto=proto)
127 assert r.exit_code == 0, f'{r}'
128 assert r.json, f'{r}'
129 if proto != 'h3': # we proxy h3
130 # the SNI the server received is without trailing dot
131 assert r.json['SSL_TLS_SNI'] == env.domain1, f'{r.json}'
133 # use hostname with double trailing dot
134 @pytest.mark.parametrize("proto", Env.http_protos())
135 def test_17_04_double_dot(self, env: Env, proto, httpd, nghttpx):
136 curl = CurlClient(env=env)
137 domain = f'{env.domain1}..'
138 url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
139 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
140 '-H', f'Host: {env.domain1}',
141 ])
142 if r.exit_code == 0:
143 assert r.json, f'{r.stdout}'
144 # the SNI the server received is without trailing dot
145 if proto != 'h3': # we proxy h3
146 assert r.json['SSL_TLS_SNI'] == env.domain1, f'{r.json}'
147 assert False, f'should not have succeeded: {r.json}'
148 # 3 - not allowed in the URL
149 assert r.exit_code == 3, f'{r}'
151 # use ip address for connect
152 @pytest.mark.parametrize("proto", Env.http_protos())
153 def test_17_05_good_ip_addr(self, env: Env, proto, httpd, nghttpx):
154 if env.curl_uses_lib('mbedtls'):
155 pytest.skip("mbedTLS does use IP addresses in SNI")
156 curl = CurlClient(env=env)
157 domain = '127.0.0.1'
158 url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
159 r = curl.http_get(url=url, alpn_proto=proto)
160 assert r.exit_code == 0, f'{r}'
161 assert r.json, f'{r}'
162 if proto != 'h3': # we proxy h3
163 # the SNI should not have been used
164 assert 'SSL_TLS_SNI' not in r.json, f'{r.json}'
166 # use IP address that is not in cert
167 @pytest.mark.parametrize("proto", Env.http_protos())
168 def test_17_05_bad_ip_addr(self, env: Env, proto,
169 httpd, configures_httpd,
170 nghttpx, configures_nghttpx):
171 httpd.set_domain1_cred_name('domain1-no-ip')
172 httpd.reload_if_config_changed()
173 if proto == 'h3':
174 nghttpx.set_cred_name('domain1-no-ip')
175 nghttpx.reload_if_config_changed()
176 curl = CurlClient(env=env)
177 url = f'https://127.0.0.1:{env.port_for(proto)}/curltest/sslinfo'
178 r = curl.http_get(url=url, alpn_proto=proto)
179 assert r.exit_code == 60, f'{r}'
181 # use IP address that is in cert as DNS name (not really legal)
182 @pytest.mark.parametrize("proto", Env.http_protos())
183 def test_17_05_very_bad_ip_addr(self, env: Env, proto,
184 httpd, configures_httpd,
185 nghttpx, configures_nghttpx):
186 if env.curl_uses_lib('mbedtls'):
187 pytest.skip("mbedtls falsely verifies a DNS: altname as IP address")
188 if env.curl_uses_lib('wolfssl') and \
189 env.curl_lib_version_before('wolfssl', '5.8.4'):
190 pytest.skip("wolfSSL falsely verifies a DNS: altname as IP address in 5.8.2 and before")
191 httpd.set_domain1_cred_name('domain1-very-bad')
192 httpd.reload_if_config_changed()
193 if proto == 'h3':
194 nghttpx.set_cred_name('domain1-very-bad')
195 nghttpx.reload_if_config_changed()
196 curl = CurlClient(env=env)
197 url = f'https://127.0.0.1:{env.port_for(proto)}/curltest/sslinfo'
198 r = curl.http_get(url=url, alpn_proto=proto)
199 assert r.exit_code == 60, f'{r}'
201 # use localhost for connect
202 @pytest.mark.parametrize("proto", Env.http_protos())
203 def test_17_06_localhost(self, env: Env, proto, httpd, nghttpx):
204 curl = CurlClient(env=env)
205 domain = 'localhost'
206 url = f'https://{env.authority_for(domain, proto)}/curltest/sslinfo'
207 r = curl.http_get(url=url, alpn_proto=proto)
208 assert r.exit_code == 0, f'{r}'
209 assert r.json, f'{r}'
210 if proto != 'h3': # we proxy h3
211 assert r.json['SSL_TLS_SNI'] == domain, f'{r.json}'
213 @staticmethod
214 def gen_test_17_07_list():
215 tls13_tests = [
216 ['def', None, True],
217 ['AES128SHA256', ['TLS_AES_128_GCM_SHA256'], True],
218 ['AES128SHA384', ['TLS_AES_256_GCM_SHA384'], False],
219 ['CHACHA20SHA256', ['TLS_CHACHA20_POLY1305_SHA256'], True],
220 ['AES128SHA384+CHACHA20SHA256', ['TLS_AES_256_GCM_SHA384', 'TLS_CHACHA20_POLY1305_SHA256'], True],
221 ]
222 tls12_tests = [
223 ['def', None, True],
224 ['AES128ish', ['ECDHE-ECDSA-AES128-GCM-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256'], True],
225 ['AES256ish', ['ECDHE-ECDSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES256-GCM-SHA384'], False],
226 ['CHACHA20ish', ['ECDHE-ECDSA-CHACHA20-POLY1305', 'ECDHE-RSA-CHACHA20-POLY1305'], True],
227 ['AES256ish+CHACHA20ish', ['ECDHE-ECDSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES256-GCM-SHA384',
228 'ECDHE-ECDSA-CHACHA20-POLY1305', 'ECDHE-RSA-CHACHA20-POLY1305'], True],
229 ]
230 ret = []
231 for tls_id, tls_proto in {
232 'TLSv1.2+3': 'TLSv1.3 +TLSv1.2',
233 'TLSv1.3': 'TLSv1.3',
234 'TLSv1.2': 'TLSv1.2'}.items():
235 for [cid13, ciphers13, succeed13] in tls13_tests:
236 for [cid12, ciphers12, succeed12] in tls12_tests:
237 testid = f'{tls_id}-{cid13}-{cid12}'
238 ret.append(pytest.param(tls_proto, ciphers13, ciphers12, succeed13, succeed12, id=testid))
239 return ret
241 @pytest.mark.parametrize(
242 "tls_proto, ciphers13, ciphers12, succeed13, succeed12",
243 gen_test_17_07_list())
244 def test_17_07_ssl_ciphers(self, env: Env, httpd, configures_httpd,
245 tls_proto, ciphers13, ciphers12,
246 succeed13, succeed12):
247 # to test setting cipher suites, the AES 256 ciphers are disabled in the test server
248 httpd.set_extra_config('base', [
249 'SSLCipherSuite SSL' +
250 ' ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256' +
251 ':ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305',
252 'SSLCipherSuite TLSv1.3' +
253 ' TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256',
254 f'SSLProtocol {tls_proto}'
255 ])
256 httpd.reload_if_config_changed()
257 proto = 'http/1.1'
258 curl = CurlClient(env=env)
259 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
260 # SSL backend specifics
261 # see wolfSSL/wolfssl#9462
262 if env.curl_uses_lib('wolfssl') and env.curl_lib_version('wolfssl') == '5.8.4' \
263 and ciphers13 and 'TLS_CHACHA20_POLY1305_SHA256' in ciphers13:
264 pytest.skip('wolfSSL 5.8.4 is borked on ARM with CHACHA20')
265 if env.curl_uses_lib('gnutls'):
266 pytest.skip('GnuTLS does not support setting ciphers')
267 elif env.curl_uses_lib('boringssl'):
268 if ciphers13 is not None:
269 pytest.skip('BoringSSL does not support setting TLSv1.3 ciphers')
270 elif env.curl_uses_lib('schannel'): # not in CI, so untested
271 if ciphers12 is not None:
272 pytest.skip('Schannel does not support setting TLSv1.2 ciphers by name')
273 elif (env.curl_uses_lib('mbedtls') and not env.curl_lib_version_at_least('mbedtls', '3.6.0')
274 and tls_proto == 'TLSv1.3'):
275 pytest.skip('mbedTLS < 3.6.0 does not support TLSv1.3')
276 # test
277 extra_args = ['--tls13-ciphers', ':'.join(ciphers13)] if ciphers13 else []
278 extra_args += ['--ciphers', ':'.join(ciphers12)] if ciphers12 else []
279 r = curl.http_get(url=url, alpn_proto=proto, extra_args=extra_args)
280 if tls_proto != 'TLSv1.2' and succeed13:
281 assert r.exit_code == 0, r.dump_logs()
282 assert r.json['HTTPS'] == 'on', r.dump_logs()
283 assert r.json['SSL_PROTOCOL'] == 'TLSv1.3', r.dump_logs()
284 assert ciphers13 is None or r.json['SSL_CIPHER'] in ciphers13, r.dump_logs()
285 elif tls_proto == 'TLSv1.2' and succeed12:
286 assert r.exit_code == 0, r.dump_logs()
287 assert r.json['HTTPS'] == 'on', r.dump_logs()
288 assert r.json['SSL_PROTOCOL'] == 'TLSv1.2', r.dump_logs()
289 assert ciphers12 is None or r.json['SSL_CIPHER'] in ciphers12, r.dump_logs()
290 else:
291 assert r.exit_code != 0, r.dump_logs()
293 @pytest.mark.parametrize("proto", Env.http_protos())
294 def test_17_08_cert_status(self, env: Env, proto, httpd, nghttpx):
295 if not env.curl_can_cert_status():
296 pytest.skip("TLS library does not support --cert-status")
297 curl = CurlClient(env=env)
298 domain = 'localhost'
299 url = f'https://{env.authority_for(domain, proto)}/'
300 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
301 '--cert-status'
302 ])
303 # CURLE_SSL_INVALIDCERTSTATUS, our certs have no OCSP info
304 assert r.exit_code == 91, f'{r}'
306 @staticmethod
307 def gen_test_17_09_list():
308 return [
309 [server_tls, min_arg, max_arg]
310 for server_tls in TLSDefs.TLS_VERSIONS
311 for min_arg in TLSDefs.CURL_ARG_MIN_VERSION_ID
312 for max_arg in TLSDefs.CURL_ARG_MAX_VERSION_ID
313 ]
315 @pytest.mark.parametrize("server_tls, min_arg, max_arg", gen_test_17_09_list())
316 def test_17_09_ssl_min_max(self, env: Env, httpd, configures_httpd, server_tls, min_arg, max_arg):
317 # We test if curl using min/max versions arguments (and defaults) can connect
318 # to a server using 'server_tls' version only
319 httpd.set_extra_config('base', [
320 f'SSLProtocol {server_tls}',
321 'SSLCipherSuite ALL:@SECLEVEL=0',
322 ])
323 httpd.reload_if_config_changed()
324 # curl's TLS backend supported version
325 if (env.curl_uses_lib('gnutls') or
326 env.curl_uses_lib('quiche') or
327 env.curl_uses_lib('aws-lc') or
328 env.curl_uses_lib('boringssl') or
329 (env.curl_uses_lib('openssl') and
330 env.curl_lib_version_before('openssl', '3.0.0'))):
331 curl_supported = [0x301, 0x302, 0x303, 0x304]
332 else: # most SSL backends dropped support for TLSv1.0, TLSv1.1
333 curl_supported = [0x303, 0x304]
335 extra_args = ['--trace-config', 'ssl']
337 # determine effective min/max version used by curl with these args
338 if max_arg != 'none':
339 extra_args.extend(['--tls-max', max_arg])
340 curl_max_ver = TLSDefs.CURL_ARG_MAX_VERSION_ID[max_arg]
341 else:
342 curl_max_ver = max(TLSDefs.TLS_VERSION_IDS.values())
343 if min_arg != 'none':
344 extra_args.append(f'--{min_arg}')
345 curl_min_ver = TLSDefs.CURL_ARG_MIN_VERSION_ID[min_arg]
346 else:
347 curl_min_ver = min(0x303, curl_max_ver) # TLSv1.2 is the default now
349 # collect all versions that curl is allowed with this command lines and supports
350 curl_allowed = [tid for tid in sorted(TLSDefs.TLS_VERSION_IDS.values())
351 if curl_min_ver <= tid <= curl_max_ver and
352 tid in curl_supported]
353 # we expect a successful transfer, when the server TLS version is allowed
354 server_ver = TLSDefs.TLS_VERSION_IDS[server_tls]
355 # do the transfer
356 proto = 'http/1.1'
357 run_env = os.environ.copy()
358 if env.curl_uses_lib('gnutls'):
359 # we need to override any default system configuration since
360 # we want to test all protocol versions. Ubuntu (or the GH image)
361 # disable TSL1.0 and TLS1.1 system wide. We do not want.
362 our_config = os.path.join(env.gen_dir, 'gnutls_config')
363 if not os.path.exists(our_config):
364 with open(our_config, 'w') as fd:
365 fd.write('# empty\n')
366 run_env['GNUTLS_SYSTEM_PRIORITY_FILE'] = our_config
367 curl = CurlClient(env=env, run_env=run_env)
368 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
369 r = curl.http_get(url=url, alpn_proto=proto, extra_args=extra_args)
371 if server_ver in curl_allowed:
372 assert r.exit_code == 0, f'should succeed, server={server_ver:04x}, curl=[{curl_min_ver:04x}, {curl_max_ver:04x}], allowed={curl_allowed}\n{r.dump_logs()}'
373 assert r.json['HTTPS'] == 'on', r.dump_logs()
374 assert r.json['SSL_PROTOCOL'] == server_tls, r.dump_logs()
375 else:
376 assert r.exit_code != 0, f'should fail, server={server_ver:04x}, curl=[{curl_min_ver:04x}, {curl_max_ver:04x}]\n{r.dump_logs()}'
378 @pytest.mark.skipif(condition=not Env.curl_is_debug(), reason="needs curl debug")
379 @pytest.mark.skipif(condition=not Env.curl_is_verbose(), reason="needs curl verbose strings")
380 def test_17_10_h3_session_reuse(self, env: Env, httpd, nghttpx):
381 if not env.have_h3():
382 pytest.skip("h3 not supported")
383 if not env.curl_uses_lib('quictls') and \
384 not env.curl_uses_lib('openssl') and \
385 not env.curl_uses_lib('gnutls') and \
386 not env.curl_uses_lib('wolfssl'):
387 pytest.skip("QUIC session reuse not implemented")
388 count = 2
389 docname = 'data-10k'
390 url = f'https://localhost:{env.https_port}/{docname}'
391 client = LocalClient(name='cli_hx_download', env=env)
392 if not client.exists():
393 pytest.skip(f'example client not built: {client.name}')
394 r = client.run(args=[
395 '-n', f'{count}',
396 '-f', # forbid reuse of connections
397 '-C', env.ca.cert_file,
398 '-r', f'{env.domain1}:{env.port_for("h3")}:127.0.0.1',
399 '-V', 'h3', url
400 ])
401 r.check_exit_code(0)
402 # check that TLS session was reused as expected
403 reused_session = False
404 for line in r.trace_lines:
405 if re.match(r'.*\[1-1] (\* )?SSL reusing session.*', line):
406 reused_session = True
407 assert reused_session, f'{r}\n{r.dump_logs()}'
409 # use hostname server has no certificate for
410 @pytest.mark.parametrize("proto", Env.http_protos())
411 def test_17_11_wrong_host(self, env: Env, proto, httpd, nghttpx):
412 curl = CurlClient(env=env)
413 domain = f'insecure.{env.tld}'
414 url = f'https://{domain}:{env.port_for(proto)}/curltest/sslinfo'
415 r = curl.http_get(url=url, alpn_proto=proto)
416 assert r.exit_code == 60, f'{r}'
418 # use hostname server has no cert for with --insecure
419 @pytest.mark.parametrize("proto", Env.http_protos())
420 def test_17_12_insecure(self, env: Env, proto, httpd, nghttpx):
421 curl = CurlClient(env=env)
422 domain = f'insecure.{env.tld}'
423 url = f'https://{domain}:{env.port_for(proto)}/curltest/sslinfo'
424 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
425 '--insecure'
426 ])
427 assert r.exit_code == 0, f'{r}'
428 assert r.json, f'{r}'
430 # connect to an expired certificate
431 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
432 def test_17_14_expired_cert(self, env: Env, proto, httpd):
433 curl = CurlClient(env=env)
434 url = f'https://{env.expired_domain}:{env.port_for(proto)}/'
435 r = curl.http_get(url=url, alpn_proto=proto)
436 assert r.exit_code == 60, f'{r}' # peer failed verification
437 exp_trace = None
438 match_trace = None
439 if env.curl_uses_lib('openssl') or env.curl_uses_lib('quictls'):
440 exp_trace = r'.*SSL certificate OpenSSL verify result: certificate has expired.*$'
441 elif env.curl_uses_lib('gnutls'):
442 exp_trace = r'.*SSL certificate verification failed: certificate has expired\..*'
443 elif env.curl_uses_lib('wolfssl'):
444 exp_trace = r'.*server verification failed: certificate has expired\.$'
445 if exp_trace is not None:
446 for line in r.trace_lines:
447 if re.match(exp_trace, line):
448 match_trace = line
449 break
450 assert match_trace, f'Did not find "{exp_trace}" in trace\n{r.dump_logs()}'
452 @pytest.mark.skipif(condition=not Env.curl_has_feature('SSLS-EXPORT'),
453 reason='curl lacks SSL session export support')
454 def test_17_15_session_export(self, env: Env, httpd):
455 proto = 'http/1.1'
456 if env.curl_uses_lib('libressl'):
457 pytest.skip('Libressl resumption does not work inTLSv1.3')
458 if env.curl_uses_lib('rustls-ffi'):
459 pytest.skip('rustsls does not expose sessions')
460 if env.curl_uses_lib('mbedtls') and \
461 not env.curl_lib_version_at_least('mbedtls', '3.6.0'):
462 pytest.skip('mbedtls TLSv1.3 session resume not working before 3.6.0')
463 run_env = os.environ.copy()
464 run_env['CURL_DEBUG'] = 'ssl,ssls'
465 # clean session file first, then reuse
466 session_file = os.path.join(env.gen_dir, 'test_17_15.sessions')
467 if os.path.exists(session_file):
468 os.remove(session_file)
469 xargs = ['--tls-max', '1.3', '--tlsv1.3', '--ssl-sessions', session_file]
470 curl = CurlClient(env=env, run_env=run_env)
471 # tell the server to close the connection after each request
472 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
473 r = curl.http_get(url=url, alpn_proto=proto, extra_args=xargs)
474 assert r.exit_code == 0, f'{r}'
475 assert r.json['HTTPS'] == 'on', f'{r.json}'
476 assert r.json['SSL_SESSION_RESUMED'] == 'Initial', f'{r.json}\n{r.dump_logs()}'
477 # ok, run again, sessions should be imported
478 run_dir2 = os.path.join(env.gen_dir, 'curl2')
479 curl = CurlClient(env=env, run_env=run_env, run_dir=run_dir2)
480 r = curl.http_get(url=url, alpn_proto=proto, extra_args=xargs)
481 assert r.exit_code == 0, f'{r}'
482 assert r.json['SSL_SESSION_RESUMED'] == 'Resumed', f'{r.json}\n{r.dump_logs()}'
484 # verify the ciphers are ignored when talking TLSv1.3 only
485 # see issue #16232
486 def test_17_16_h3_ignore_ciphers12(self, env: Env, httpd, nghttpx):
487 proto = 'h3'
488 if proto == 'h3' and not env.have_h3():
489 pytest.skip("h3 not supported")
490 if env.curl_uses_lib('gnutls'):
491 pytest.skip("gnutls does not ignore --ciphers on TLSv1.3")
492 curl = CurlClient(env=env)
493 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
494 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
495 '--ciphers', 'NONSENSE'
496 ])
497 assert r.exit_code == 0, f'{r}'
499 def test_17_17_h1_ignore_ciphers13(self, env: Env, httpd):
500 proto = 'http/1.1'
501 curl = CurlClient(env=env)
502 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
503 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
504 '--tls13-ciphers', 'NONSENSE', '--tls-max', '1.2'
505 ])
506 assert r.exit_code == 0, f'{r}'
508 @pytest.mark.parametrize("priority, tls_proto, ciphers, success", [
509 pytest.param("", "", [], False, id='prio-empty'),
510 pytest.param("NONSENSE", "", [], False, id='nonsense'),
511 pytest.param("+NONSENSE", "", [], False, id='+nonsense'),
512 pytest.param("NORMAL:-VERS-ALL:+VERS-TLS1.2", "TLSv1.2", ['ECDHE-RSA-CHACHA20-POLY1305'], True, id='TLSv1.2-normal-only'),
513 pytest.param("-VERS-ALL:+VERS-TLS1.2", "TLSv1.2", ['ECDHE-RSA-CHACHA20-POLY1305'], True, id='TLSv1.2-only'),
514 pytest.param("NORMAL", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-normal'),
515 pytest.param("NORMAL:-VERS-ALL:+VERS-TLS1.3", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-normal-only'),
516 pytest.param("-VERS-ALL:+VERS-TLS1.3", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-only'),
517 pytest.param("!CHACHA20-POLY1305", "TLSv1.3", ['TLS_AES_128_GCM_SHA256'], True, id='TLSv1.3-no-chacha'),
518 pytest.param("-CIPHER-ALL:+CHACHA20-POLY1305", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-only-chacha'),
519 pytest.param("-CIPHER-ALL:+AES-256-GCM", "", [], False, id='only-AES256'),
520 pytest.param("-CIPHER-ALL:+AES-128-GCM", "TLSv1.3", ['TLS_AES_128_GCM_SHA256'], True, id='TLSv1.3-only-AES128'),
521 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'),
522 pytest.param("-MAC-ALL:+SHA256", "", [], False, id='MAC-only-SHA256'),
523 pytest.param("-MAC-ALL:+AEAD", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-MAC-only-AEAD'),
524 pytest.param("-GROUP-ALL:+GROUP-X25519", "TLSv1.3", ['TLS_CHACHA20_POLY1305_SHA256'], True, id='TLSv1.3-group-only-X25519'),
525 pytest.param("-GROUP-ALL:+GROUP-SECP192R1", "", [], False, id='group-only-SECP192R1'),
526 ])
527 def test_17_18_gnutls_priority(self, env: Env, httpd, configures_httpd, priority, tls_proto, ciphers, success):
528 # to test setting cipher suites, the AES 256 ciphers are disabled in the test server
529 httpd.set_extra_config('base', [
530 'SSLCipherSuite SSL' +
531 ' ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256' +
532 ':ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305',
533 'SSLCipherSuite TLSv1.3' +
534 ' TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256',
535 ])
536 httpd.reload_if_config_changed()
537 proto = 'http/1.1'
538 curl = CurlClient(env=env)
539 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
540 # SSL backend specifics
541 if not env.curl_uses_lib('gnutls'):
542 pytest.skip('curl not build with GnuTLS')
543 # test
544 extra_args = ['--ciphers', f'{priority}']
545 r = curl.http_get(url=url, alpn_proto=proto, extra_args=extra_args)
546 if success:
547 assert r.exit_code == 0, r.dump_logs()
548 assert r.json['HTTPS'] == 'on', r.dump_logs()
549 if tls_proto:
550 assert r.json['SSL_PROTOCOL'] == tls_proto, r.dump_logs()
551 assert r.json['SSL_CIPHER'] in ciphers, r.dump_logs()
552 else:
553 assert r.exit_code != 0, r.dump_logs()
555 @pytest.mark.parametrize("proto", Env.http_protos())
556 def test_17_19_wrong_pin(self, env: Env, proto, httpd, nghttpx):
557 if env.curl_uses_lib('rustls-ffi'):
558 pytest.skip('TLS backend ignores --pinnedpubkey')
559 curl = CurlClient(env=env)
560 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
561 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
562 '--pinnedpubkey', 'sha256//ffff'
563 ])
564 # expect NOT_IMPLEMENTED or CURLE_SSL_PINNEDPUBKEYNOTMATCH
565 assert r.exit_code in [2, 90], f'{r.dump_logs()}'
567 @pytest.mark.parametrize("proto", Env.http_protos())
568 def test_17_20_correct_pin(self, env: Env, proto, httpd, nghttpx):
569 curl = CurlClient(env=env)
570 creds = env.get_credentials(env.domain1)
571 assert creds
572 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
573 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
574 '--pinnedpubkey', f'sha256//{creds.pub_sha256_b64()}'
575 ])
576 # expect NOT_IMPLEMENTED or OK
577 assert r.exit_code in [0, 2], f'{r.dump_logs()}'
579 @pytest.mark.skipif(condition=not Env.have_openssl(), reason="needs openssl command")
580 def test_17_21_capath_valid(self, env: Env, httpd):
581 if env.curl_uses_lib('rustls-ffi'):
582 pytest.skip('rustls does not support CURLOPT_CAPATH')
583 proto = 'http/1.1'
584 curl = CurlClient(env=env)
585 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
586 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
587 '--capath', env.ca.hashdir
588 ])
589 assert r.exit_code == 0, f'{r.dump_logs()}'
590 assert r.json['HTTPS'] == 'on', f'{r.json}'
592 @pytest.mark.skipif(condition=not Env.have_openssl(), reason="needs openssl command")
593 def test_17_22_capath_invalid(self, env: Env, httpd):
594 # we can test all TLS backends here. the ones not supporting CAPATH
595 # need to fail as well as the ones which do, but get an invalid path.
596 proto = 'http/1.1'
597 curl = CurlClient(env=env)
598 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
599 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
600 '--capath', os.path.join(env.gen_dir, 'ca/invalid')
601 ])
602 # CURLE_PEER_FAILED_VERIFICATION or CURLE_SSL_CACERT_BADFILE
603 assert r.exit_code in [60, 77], f'{r.dump_logs()}'
605 @pytest.mark.parametrize("proto", Env.http_protos())
606 def test_17_23_embedded_zero(self, env: Env, proto, httpd, nghttpx):
607 httpd.set_domain1_cred_name('embedded-zero')
608 httpd.reload_if_config_changed()
609 if proto == 'h3':
610 nghttpx.set_cred_name('embedded-zero')
611 nghttpx.reload_if_config_changed()
612 curl = CurlClient(env=env)
613 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
614 r = curl.http_get(url=url, alpn_proto=proto)
615 # CURLE_SSL_CONNECT_ERROR or CURLE_PEER_FAILED_VERIFICATION
616 assert r.exit_code in [35, 60], f'{r.dump_logs()}'
618 @pytest.mark.parametrize("proto", Env.http_protos())
619 def test_17_24_embedded_zero_wildcard(self, env: Env, proto, httpd, nghttpx):
620 httpd.set_domain1_cred_name('embedded-zero-wildcard')
621 httpd.reload_if_config_changed()
622 if proto == 'h3':
623 nghttpx.set_cred_name('embedded-zero-wildcard')
624 nghttpx.reload_if_config_changed()
625 curl = CurlClient(env=env)
626 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/sslinfo'
627 r = curl.http_get(url=url, alpn_proto=proto)
628 # CURLE_SSL_CONNECT_ERROR or CURLE_PEER_FAILED_VERIFICATION
629 assert r.exit_code in [35, 60], f'{r.dump_logs()}'
Diagnostics4 git calls · 223 ms
CallStatusSizeTime0223 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=219
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2007.2 KiB219 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=7378
git.response.cache=MISS
git.response.duration_ms=219
git.fetch.wants=ca03282d4466b8528a29a06ac7e4c9ff45f18788
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=7378
git.pkt.payload.max=7357
git.sideband.band1.bytes=7356
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e2dff9ae6e2308
Request
a32bd1be…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format