master
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.
13 *
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.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
25/* Unit tests for TLS session cache peer key discrimination on mTLS fields.
26 * Verifies that Curl_ssl_peer_key_build() produces distinct keys when two
27 * handles differ only on key, key_type or cert_type. key_passwd is NOT
28 * embedded in the peer key; it is compared separately at session lookup via
29 * cf_ssl_scache_match_auth().
30 */
32#include "unitcheck.h"
33#include "urldata.h"
34#include "peer.h"
36#ifdef USE_SSL
37#include "vtls/vtls.h"
38#include "vtls/vtls_scache.h"
39#endif
41static CURLcode test_unit3304(const char *arg)
42{
43 UNITTEST_BEGIN_SIMPLE
45#ifdef USE_SSL
46 struct Curl_peer origin;
47 struct ssl_peer peer;
48 struct ssl_filter_config ssl;
49 struct Curl_scheme scheme;
50 char *key1 = NULL;
51 char *key2 = NULL;
52 static char base_hostname[] = "example.com";
53 static char base_cert[] = "client.pem";
54 static char base_key[] = "client.key";
55 static char base_passwd[] = "secret";
56 static char base_ctype[] = "PEM";
57 static char base_ktype[] = "PEM";
58 static char alt_key[] = "other.key";
59 static char alt_ktype[] = "DER";
60 static char alt_ctype[] = "P12";
61 static char lc_ctype[] = "pem";
62 static char lc_ktype[] = "pem";
63 static char cafile_fields[] = "/root:CApath-/certs";
64 static char cafile[] = "/root";
65 static char capath[] = "/certs";
66 static char cipher_fields[] = "DEFAULT:CIPHER13-TLS_AES_128_GCM_SHA256";
67 static char cipher_list[] = "DEFAULT";
68 static char cipher_list13[] = "TLS_AES_128_GCM_SHA256";
70 memset(&scheme, 0, sizeof(scheme));
71 scheme.name = "https";
73 memset(&origin, 0, sizeof(origin));
74 origin.hostname = base_hostname;
75 origin.port = 443;
76 origin.scheme = &scheme;
78 memset(&peer, 0, sizeof(peer));
79 peer.origin = &origin;
80 peer.transport = TRNSPRT_TCP;
82 memset(&ssl, 0, sizeof(ssl));
83 ssl.verifypeer = TRUE;
84 ssl.verifyhost = TRUE;
85 ssl.clientcert = base_cert;
86 ssl.key = base_key;
87 ssl.key_passwd = base_passwd;
88 ssl.cert_type = base_ctype;
89 ssl.key_type = base_ktype;
91 /* Baseline: same config produces same key. */
92 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
93 "peer key build failed");
94 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
95 "peer key build failed");
96 fail_unless(key1 && key2 && !strcmp(key1, key2),
97 "identical config should produce identical peer key");
98 /* Keep legacy serialized keys separate from this key format. */
99 fail_unless(key1 && !strncmp(key1, "https:example.com:443:KEY-V3:",
100 sizeof("https:example.com:443:KEY-V3:") - 1),
101 "peer key must carry the V3 format marker after the port");
102 curlx_safefree(key1);
103 curlx_safefree(key2);
105 /* The effective native CA-store policy is not necessarily represented in
106 * ssl_options: a build can enable it by default. It must still separate
107 * sessions authenticated with native roots from file-only sessions. */
108 ssl.native_ca_store = TRUE;
109 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
110 "peer key build failed");
111 ssl.native_ca_store = FALSE;
112 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
113 "peer key build failed");
114 fail_unless(key1 && key2 && strcmp(key1, key2),
115 "native CA-store policy must affect the peer key");
116 curlx_safefree(key1);
117 curlx_safefree(key2);
119 /* A delimiter in a CA path must not create a second trust field. */
120 ssl.CAfile = cafile_fields;
121 ssl.CApath = NULL;
122 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
123 "peer key build failed");
124 ssl.CAfile = cafile;
125 ssl.CApath = capath;
126 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
127 "peer key build failed");
128 fail_unless(key1 && key2 && strcmp(key1, key2),
129 "CA file and path must not alias another CA file");
130 curlx_safefree(key1);
131 curlx_safefree(key2);
132 ssl.CAfile = NULL;
133 ssl.CApath = NULL;
135 /* Non-path fields must not inject a following field either. */
136 ssl.cipher_list = cipher_fields;
137 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
138 "peer key build failed");
139 ssl.cipher_list = cipher_list;
140 ssl.cipher_list13 = cipher_list13;
141 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
142 "peer key build failed");
143 fail_unless(key1 && key2 && strcmp(key1, key2),
144 "cipher fields must have unambiguous boundaries");
145 curlx_safefree(key1);
146 curlx_safefree(key2);
147 ssl.cipher_list = NULL;
148 ssl.cipher_list13 = NULL;
150 /* key_passwd is NOT in the peer key: lookup uses timing-safe comparison
151 * via cf_ssl_scache_match_auth(). */
152 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
153 "peer key build failed");
154 ssl.key_passwd = NULL;
155 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
156 "peer key build failed");
157 fail_unless(key1 && key2 && !strcmp(key1, key2),
158 "key_passwd must not affect the peer key");
159 curlx_safefree(key1);
160 curlx_safefree(key2);
161 ssl.key_passwd = base_passwd;
163 /* Different key path must produce a different peer key. */
164 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
165 "peer key build failed");
166 ssl.key = alt_key;
167 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
168 "peer key build failed");
169 fail_unless(key1 && key2 && strcmp(key1, key2),
170 "different key must produce different peer key");
171 curlx_safefree(key1);
172 curlx_safefree(key2);
173 ssl.key = base_key;
175 /* Different key_type must produce a different peer key. */
176 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
177 "peer key build failed");
178 ssl.key_type = alt_ktype;
179 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
180 "peer key build failed");
181 fail_unless(key1 && key2 && strcmp(key1, key2),
182 "different key_type must produce different peer key");
183 curlx_safefree(key1);
184 curlx_safefree(key2);
185 ssl.key_type = base_ktype;
187 /* Different cert_type must produce a different peer key. */
188 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
189 "peer key build failed");
190 ssl.cert_type = alt_ctype;
191 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
192 "peer key build failed");
193 fail_unless(key1 && key2 && strcmp(key1, key2),
194 "different cert_type must produce different peer key");
195 curlx_safefree(key1);
196 curlx_safefree(key2);
197 ssl.cert_type = base_ctype;
199 /* cert_type is case-insensitive: "PEM" and "pem" must produce the
200 * same peer key, consistent with the conn-reuse comparison. */
201 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
202 "peer key build failed");
203 ssl.cert_type = lc_ctype;
204 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
205 "peer key build failed");
206 fail_unless(key1 && key2 && !strcmp(key1, key2),
207 "cert_type case must not affect peer key");
208 curlx_safefree(key1);
209 curlx_safefree(key2);
210 ssl.cert_type = base_ctype;
212 /* key_type is case-insensitive: "PEM" and "pem" must produce the
213 * same peer key. */
214 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1),
215 "peer key build failed");
216 ssl.key_type = lc_ktype;
217 fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key2),
218 "peer key build failed");
219 fail_unless(key1 && key2 && !strcmp(key1, key2),
220 "key_type case must not affect peer key");
221 curlx_safefree(key1);
222 curlx_safefree(key2);
223#endif /* USE_SSL */
225 UNITTEST_END_SIMPLE
226}
Diagnostics4 git calls · 37 ms
CallStatusSizeTime037 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 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=2 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=86Open pack map
fetch2002.3 KiB · hit32 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=32 git.response.bytes=2315 git.response.cache=HIT git.response.duration_ms=32 git.fetch.wants=29ea23a35802f2e20f5ada42a385109c2c342bee 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=2315 git.pkt.payload.max=2294 git.sideband.band1.bytes=2293 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
- a5e1fe393eaba9c0
- Request
- ffe71e1e…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format