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 ***************************************************************************/
24#include "curl_setup.h"
26#ifdef USE_SSL
28#include "urldata.h"
29#include "cfilters.h"
31#include "vtls/vtls.h" /* generic SSL protos etc */
32#include "vtls/vtls_int.h"
33#include "vtls/vtls_scache.h"
34#include "vtls/vtls_spack.h"
36#include "strcase.h"
37#include "url.h"
38#include "llist.h"
39#include "curl_share.h"
40#include "curl_threads.h"
41#include "curl_trc.h"
42#include "curl_sha256.h"
43#include "rand.h"
44#include "curlx/strdup.h"
46/* a peer+tls-config we cache sessions for */
47struct Curl_ssl_scache_peer {
48 char *ssl_peer_key; /* id for peer + relevant TLS configuration */
49 char *clientcert;
50 char *key_passwd;
51 struct Curl_llist sessions;
52 void *sobj; /* object instance or NULL */
53 Curl_ssl_scache_obj_dtor *sobj_free; /* free `sobj` callback */
54 unsigned char key_salt[CURL_SHA256_DIGEST_LENGTH]; /* for entry export */
55 unsigned char key_hmac[CURL_SHA256_DIGEST_LENGTH]; /* for entry export */
56 size_t max_sessions;
57 long age; /* a number, the higher the more recent */
58 BIT(hmac_set); /* if key_salt and key_hmac are present */
59 BIT(exportable); /* sessions for this peer can be exported */
60};
62#define CURL_SCACHE_MAGIC 0x000e1551
64#define GOOD_SCACHE(x) ((x) && (x)->magic == CURL_SCACHE_MAGIC)
66/* Prefix the length to keep field boundaries unambiguous. */
67static CURLcode cf_ssl_peer_key_add_string(struct dynbuf *buf,
68 const char *name,
69 const char *value)
70{
71 return curlx_dyn_addf(buf, ":%s-%zu:%s", name, strlen(value), value);
72}
74static CURLcode cf_ssl_peer_key_add_path(struct dynbuf *buf,
75 const char *name,
76 const char *path,
77 bool *is_local)
78{
79 if(path && path[0]) {
80 /* We try to add absolute paths, so that the session key can stay valid
81 * when used in another process with different CWD. When a path does not
82 * exist, this does not work. Then, we add the path as is. */
83#ifdef _WIN32
84 char *abspath = _fullpath(NULL, path, 0);
85 if(abspath) {
86 CURLcode result = cf_ssl_peer_key_add_string(buf, name, abspath);
87 /* !checksrc! disable BANNEDFUNC 1 */
88 free(abspath); /* allocated by CRT, use system free() */
89 return result;
90 }
91 *is_local = TRUE;
92#elif defined(HAVE_REALPATH)
93 if(path[0] != '/') {
94 char *abspath = realpath(path, NULL);
95 if(abspath) {
96 CURLcode result = cf_ssl_peer_key_add_string(buf, name, abspath);
97 /* !checksrc! disable BANNEDFUNC 1 */
98 free(abspath); /* allocated by libc, free without memdebug */
99 return result;
100 }
101 *is_local = TRUE;
102 }
103#endif
104 return cf_ssl_peer_key_add_string(buf, name, path);
105 }
106 return CURLE_OK;
107}
109static CURLcode cf_ssl_peer_key_add_hash(struct dynbuf *buf,
110 const char *name,
111 struct curl_blob *blob)
112{
113 CURLcode result = CURLE_OK;
114 if(blob && blob->len) {
115 unsigned char hash[CURL_SHA256_DIGEST_LENGTH];
116 size_t i;
118 result = curlx_dyn_addf(buf, ":%s-", name);
119 if(result)
120 goto out;
121 result = Curl_sha256it(hash, blob->data, blob->len);
122 if(result)
123 goto out;
124 for(i = 0; i < CURL_SHA256_DIGEST_LENGTH; ++i) {
125 result = curlx_dyn_addf(buf, "%02x", hash[i]);
126 if(result)
127 goto out;
128 }
129 }
130out:
131 return result;
132}
134static CURLcode cf_ssl_peer_key_add_mtls(struct dynbuf *buf,
135 struct ssl_filter_config *ssl,
136 bool *is_local)
137{
138 CURLcode result = CURLE_OK;
139 if(ssl->clientcert && ssl->clientcert[0]) {
140 result = cf_ssl_peer_key_add_path(buf, "CCERT", ssl->clientcert, is_local);
141 if(result)
142 goto out;
143 }
144 if(ssl->key && ssl->key[0]) {
145 result = cf_ssl_peer_key_add_path(buf, "KEY", ssl->key, is_local);
146 if(result)
147 goto out;
148 }
149 if(ssl->key_blob) {
150 result = cf_ssl_peer_key_add_hash(buf, "KEYBlob", ssl->key_blob);
151 if(result)
152 goto out;
153 }
154 if(ssl->cert_type && ssl->cert_type[0]) {
155 size_t i;
156 result = curlx_dyn_addf(buf, ":CT-%zu:", strlen(ssl->cert_type));
157 for(i = 0; !result && ssl->cert_type[i]; i++) {
158 char c = Curl_raw_toupper(ssl->cert_type[i]);
159 result = curlx_dyn_addn(buf, &c, 1);
160 }
161 if(result)
162 goto out;
163 }
164 if(ssl->key_type && ssl->key_type[0]) {
165 size_t i;
166 result = curlx_dyn_addf(buf, ":KT-%zu:", strlen(ssl->key_type));
167 for(i = 0; !result && ssl->key_type[i]; i++) {
168 char c = Curl_raw_toupper(ssl->key_type[i]);
169 result = curlx_dyn_addn(buf, &c, 1);
170 }
171 }
172out:
173 return result;
174}
176#define CURL_SSLS_LOCAL_SUFFIX ":L"
177#define CURL_SSLS_GLOBAL_SUFFIX ":G"
179static bool cf_ssl_peer_key_is_global(const char *peer_key)
180{
181 size_t len = peer_key ? strlen(peer_key) : 0;
182 return (len > 2) &&
183 (peer_key[len - 1] == 'G') &&
184 (peer_key[len - 2] == ':');
185}
187static CURLcode ssl_peer_key_add_transport(struct dynbuf *buf,
188 uint8_t transport)
189{
190 switch(transport) {
191 case TRNSPRT_TCP:
192 return CURLE_OK;
193 case TRNSPRT_UDP:
194 return curlx_dyn_add(buf, ":UDP");
195 case TRNSPRT_QUIC:
196 return curlx_dyn_add(buf, ":QUIC");
197 case TRNSPRT_UNIX:
198 return curlx_dyn_add(buf, ":UNIX");
199 default:
200 return curlx_dyn_addf(buf, ":TRNSPRT-%d", transport);
201 }
202}
204static CURLcode ssl_peer_key_add_vrfy(struct dynbuf *buf,
205 struct ssl_filter_config *ssl,
206 const struct ssl_peer *peer)
207{
208 CURLcode result;
210 if(!ssl->verifypeer) {
211 result = curlx_dyn_add(buf, ":NO-VRFY-PEER");
212 if(result)
213 return result;
214 }
215 if(!ssl->verifyhost) {
216 result = curlx_dyn_add(buf, ":NO-VRFY-HOST");
217 if(result)
218 return result;
219 }
220 if(ssl->verifystatus) {
221 result = curlx_dyn_add(buf, ":VRFY-STATUS");
222 if(result)
223 return result;
224 }
225 if((!ssl->verifypeer || !ssl->verifyhost) &&
226 peer->peer && !Curl_peer_equal(peer->origin, peer->peer)) {
227 result = cf_ssl_peer_key_add_string(buf, "CHOST", peer->peer->hostname);
228 if(!result)
229 result = curlx_dyn_addf(buf, ":CPORT-%u", peer->peer->port);
230 if(result)
231 return result;
232 }
233 return CURLE_OK;
234}
236static CURLcode ssl_peer_key_build(struct ssl_filter_config *ssl,
237 const struct ssl_peer *peer,
238 const char *tls_id,
239 char **ppeer_key)
240{
241 struct dynbuf buf;
242 size_t key_len;
243 bool is_local = FALSE;
244 CURLcode result;
246 *ppeer_key = NULL;
247 curlx_dyn_init(&buf, 10 * 1024);
249 result = curlx_dyn_addf(&buf, "%s:%s:%d:KEY-V3",
250 peer->origin->scheme->name,
251 peer->origin->hostname, peer->origin->port);
252 if(result)
253 goto out;
254 result = ssl_peer_key_add_transport(&buf, peer->transport);
255 if(result)
256 goto out;
257 result = ssl_peer_key_add_vrfy(&buf, ssl, peer);
258 if(result)
259 goto out;
260 if(ssl->version || ssl->version_max) {
261 result = curlx_dyn_addf(&buf, ":TLSVER-%d-%u", ssl->version,
262 (ssl->version_max >> 16));
263 if(result)
264 goto out;
265 }
266 if(ssl->ssl_options) {
267 result = curlx_dyn_addf(&buf, ":TLSOPT-%x", ssl->ssl_options);
268 if(result)
269 goto out;
270 }
271 if(ssl->cipher_list) {
272 result = cf_ssl_peer_key_add_string(&buf, "CIPHER", ssl->cipher_list);
273 if(result)
274 goto out;
275 }
276 if(ssl->cipher_list13) {
277 result = cf_ssl_peer_key_add_string(&buf, "CIPHER13", ssl->cipher_list13);
278 if(result)
279 goto out;
280 }
281 if(ssl->curves) {
282 result = cf_ssl_peer_key_add_string(&buf, "CURVES", ssl->curves);
283 if(result)
284 goto out;
285 }
286 if(ssl->signature_algorithms) {
287 result = cf_ssl_peer_key_add_string(&buf, "SIGALGS",
288 ssl->signature_algorithms);
289 if(result)
290 goto out;
291 }
292 if(ssl->verifypeer) {
293 result = cf_ssl_peer_key_add_path(&buf, "CA", ssl->CAfile, &is_local);
294 if(!result)
295 result = cf_ssl_peer_key_add_path(&buf, "CApath",
296 ssl->CApath, &is_local);
297 if(!result && ssl->native_ca_store)
298 result = curlx_dyn_add(&buf, ":NATIVE-CA");
299 if(!result)
300 result = cf_ssl_peer_key_add_path(&buf, "CRL", ssl->CRLfile, &is_local);
301 if(result)
302 goto out;
303 result = cf_ssl_peer_key_add_path(&buf, "Issuer", ssl->issuercert,
304 &is_local);
305 if(result)
306 goto out;
307 if(ssl->ca_info_blob) {
308 result = cf_ssl_peer_key_add_hash(&buf, "CAInfoBlob", ssl->ca_info_blob);
309 if(result)
310 goto out;
311 }
312 if(ssl->issuercert_blob) {
313 result = cf_ssl_peer_key_add_hash(&buf, "IssuerBlob",
314 ssl->issuercert_blob);
315 if(result)
316 goto out;
317 }
318 }
319 if(ssl->cert_blob) {
320 result = cf_ssl_peer_key_add_hash(&buf, "CertBlob", ssl->cert_blob);
321 if(result)
322 goto out;
323 }
324 if(ssl->pinned_key && ssl->pinned_key[0]) {
325 result = cf_ssl_peer_key_add_string(&buf, "Pinned", ssl->pinned_key);
326 if(result)
327 goto out;
328 }
329 if(ssl->auto_client_cert) {
330 result = curlx_dyn_add(&buf, ":AUTOC");
331 if(result)
332 goto out;
333 }
335 result = cf_ssl_peer_key_add_mtls(&buf, ssl, &is_local);
336 if(result)
337 goto out;
339 if(!tls_id || !tls_id[0]) {
340 result = CURLE_FAILED_INIT;
341 goto out;
342 }
343 result = cf_ssl_peer_key_add_string(&buf, "IMPL", tls_id);
344 if(result)
345 goto out;
347 result = curlx_dyn_addf(&buf, is_local ?
348 CURL_SSLS_LOCAL_SUFFIX : CURL_SSLS_GLOBAL_SUFFIX);
349 if(result)
350 goto out;
352 *ppeer_key = curlx_dyn_take(&buf, &key_len);
353 /* we added printable char, and dynbuf always null-terminates, no need
354 * to track length */
356out:
357 curlx_dyn_free(&buf);
358 return result;
359}
361CURLcode Curl_ssl_peer_key_make(const struct ssl_peer *peer,
362 struct ssl_filter_config *sslc,
363 const char *tls_id,
364 char **ppeer_key)
365{
366 return ssl_peer_key_build(sslc, peer, tls_id, ppeer_key);
367}
369struct Curl_ssl_scache {
370 unsigned int magic;
371 struct Curl_ssl_scache_peer *peers;
372 size_t peer_count;
373 int default_lifetime_secs;
374 long age;
375#ifdef USE_MUTEX
376 curl_mutex_t mutex;
377 curl_thread_id_t locking_thread;
378#endif
379 BIT(is_locked);
380};
382static struct Curl_ssl_scache *cf_ssl_scache_get(struct Curl_easy *data)
383{
384 struct Curl_ssl_scache *scache = NULL;
385 /* If a share is present, its ssl_scache has preference over the multi */
386 if(data->share && data->share->ssl_scache)
387 scache = data->share->ssl_scache;
388 else if(data->multi && data->multi->ssl_scache)
389 scache = data->multi->ssl_scache;
390 if(scache && !GOOD_SCACHE(scache)) {
391 failf(data, "transfer would use an invalid scache at %p, denied",
392 (void *)scache);
393 DEBUGASSERT(0);
394 return NULL;
395 }
396 return scache;
397}
399static void cf_ssl_scache_session_ldestroy(void *udata, void *obj)
400{
401 struct Curl_ssl_session *s = obj;
402 (void)udata;
403 curlx_free(s->sdata);
404 curlx_free(s->quic_tp);
405 curlx_free(s->alpn);
406 curlx_free(s);
407}
409CURLcode Curl_ssl_session_create(void *sdata, size_t sdata_len,
410 int ietf_tls_id, const char *alpn,
411 curl_off_t valid_until, size_t earlydata_max,
412 struct Curl_ssl_session **psession)
413{
414 return Curl_ssl_session_create2(sdata, sdata_len, ietf_tls_id, alpn,
415 valid_until, earlydata_max,
416 NULL, 0, psession);
417}
419CURLcode Curl_ssl_session_create2(void *sdata, size_t sdata_len,
420 int ietf_tls_id, const char *alpn,
421 curl_off_t valid_until, size_t earlydata_max,
422 unsigned char *quic_tp, size_t quic_tp_len,
423 struct Curl_ssl_session **psession)
424{
425 struct Curl_ssl_session *s;
427 if(!sdata || !sdata_len) {
428 curlx_free(sdata);
429 return CURLE_BAD_FUNCTION_ARGUMENT;
430 }
432 *psession = NULL;
433 s = curlx_calloc(1, sizeof(*s));
434 if(!s) {
435 curlx_free(sdata);
436 curlx_free(quic_tp);
437 return CURLE_OUT_OF_MEMORY;
438 }
440 s->ietf_tls_id = ietf_tls_id;
441 s->valid_until = valid_until;
442 s->earlydata_max = earlydata_max;
443 s->sdata = sdata;
444 s->sdata_len = sdata_len;
445 s->quic_tp = quic_tp;
446 s->quic_tp_len = quic_tp_len;
447 if(alpn) {
448 s->alpn = curlx_strdup(alpn);
449 if(!s->alpn) {
450 cf_ssl_scache_session_ldestroy(NULL, s);
451 return CURLE_OUT_OF_MEMORY;
452 }
453 }
454 *psession = s;
455 return CURLE_OK;
456}
458void Curl_ssl_session_destroy(struct Curl_ssl_session *s)
459{
460 if(s) {
461 /* if in the list, the list destructor takes care of it */
462 if(Curl_node_llist(&s->list))
463 Curl_node_remove(&s->list);
464 else {
465 cf_ssl_scache_session_ldestroy(NULL, s);
466 }
467 }
468}
470CURLcode Curl_ssl_session_dup(struct Curl_ssl_session *src,
471 struct Curl_ssl_session **pdest)
472{
473 struct Curl_ssl_session *dest = NULL;
474 CURLcode result = CURLE_OUT_OF_MEMORY;
476 if(!src || !pdest)
477 return CURLE_BAD_FUNCTION_ARGUMENT;
478 *pdest = NULL;
480 dest = curlx_calloc(1, sizeof(*dest));
481 if(!dest)
482 goto out;
484 dest->ietf_tls_id = src->ietf_tls_id;
485 dest->valid_until = src->valid_until;
486 dest->earlydata_max = src->earlydata_max;
487 dest->sectrust_verified = src->sectrust_verified;
488 if(src->sdata_len) {
489 dest->sdata = curlx_memdup(src->sdata, src->sdata_len);
490 if(!dest->sdata)
491 goto out;
492 dest->sdata_len = src->sdata_len;
493 }
494 if(src->quic_tp_len) {
495 dest->quic_tp = curlx_memdup(src->quic_tp, src->quic_tp_len);
496 if(!dest->quic_tp)
497 goto out;
498 dest->quic_tp_len = src->quic_tp_len;
499 }
500 if(src->alpn) {
501 dest->alpn = curlx_strdup(src->alpn);
502 if(!dest->alpn)
503 goto out;
504 }
505 result = CURLE_OK;
507out:
508 if(!result)
509 *pdest = dest;
510 else {
511 *pdest = NULL;
512 if(dest)
513 Curl_ssl_session_destroy(dest);
514 }
515 return result;
516}
518static void cf_ssl_scache_clear_peer(struct Curl_ssl_scache_peer *peer)
519{
520 Curl_llist_destroy(&peer->sessions, NULL);
521 if(peer->sobj) {
522 DEBUGASSERT(peer->sobj_free);
523 if(peer->sobj_free)
524 peer->sobj_free(peer->sobj);
525 peer->sobj = NULL;
526 }
527 peer->sobj_free = NULL;
528 curlx_safefree(peer->clientcert);
529 curlx_safefree(peer->key_passwd);
530 curlx_safefree(peer->ssl_peer_key);
531 peer->age = 0;
532 peer->hmac_set = FALSE;
533}
535static void cf_ssl_scache_peer_set_obj(struct Curl_ssl_scache_peer *peer,
536 void *sobj,
537 Curl_ssl_scache_obj_dtor *sobj_free)
538{
539 DEBUGASSERT(peer);
540 if(peer->sobj_free) {
541 peer->sobj_free(peer->sobj);
542 }
543 peer->sobj = sobj;
544 peer->sobj_free = sobj_free;
545}
547static void cf_ssl_cache_peer_update(struct Curl_ssl_scache_peer *peer)
548{
549 /* The sessions of this peer are exportable if
550 * - it has no confidential information
551 * - its peer key is not yet known, because sessions were
552 * imported using only the salt+hmac
553 * - the peer key is global, e.g. carrying no relative paths */
554 peer->exportable = (!peer->clientcert && !peer->key_passwd &&
555 (!peer->ssl_peer_key ||
556 cf_ssl_peer_key_is_global(peer->ssl_peer_key)));
557}
559static CURLcode cf_ssl_scache_peer_init(struct Curl_ssl_scache_peer *peer,
560 const char *ssl_peer_key,
561 const char *clientcert,
562 const char *key_passwd,
563 const unsigned char *salt,
564 const unsigned char *hmac)
565{
566 CURLcode result = CURLE_OUT_OF_MEMORY;
568 DEBUGASSERT(!peer->ssl_peer_key);
569 if(ssl_peer_key) {
570 peer->ssl_peer_key = curlx_strdup(ssl_peer_key);
571 if(!peer->ssl_peer_key)
572 goto out;
573 peer->hmac_set = FALSE;
574 }
575 else if(salt && hmac) {
576 memcpy(peer->key_salt, salt, sizeof(peer->key_salt));
577 memcpy(peer->key_hmac, hmac, sizeof(peer->key_hmac));
578 peer->hmac_set = TRUE;
579 }
580 else {
581 result = CURLE_BAD_FUNCTION_ARGUMENT;
582 goto out;
583 }
584 if(clientcert) {
585 peer->clientcert = curlx_strdup(clientcert);
586 if(!peer->clientcert)
587 goto out;
588 }
589 if(key_passwd) {
590 peer->key_passwd = curlx_strdup(key_passwd);
591 if(!peer->key_passwd)
592 goto out;
593 }
594 cf_ssl_cache_peer_update(peer);
595 result = CURLE_OK;
596out:
597 if(result)
598 cf_ssl_scache_clear_peer(peer);
599 return result;
600}
602static void cf_scache_session_remove(struct Curl_ssl_scache_peer *peer,
603 struct Curl_ssl_session *s)
604{
605 (void)peer;
606 DEBUGASSERT(Curl_node_llist(&s->list) == &peer->sessions);
607 Curl_ssl_session_destroy(s);
608}
610static bool cf_scache_session_expired(struct Curl_ssl_session *s,
611 curl_off_t now)
612{
613 return (s->valid_until > 0) && (s->valid_until < now);
614}
616static void cf_scache_peer_remove_expired(struct Curl_ssl_scache_peer *peer,
617 curl_off_t now)
618{
619 struct Curl_llist_node *n = Curl_llist_head(&peer->sessions);
620 while(n) {
621 struct Curl_ssl_session *s = Curl_node_elem(n);
622 n = Curl_node_next(n);
623 if(cf_scache_session_expired(s, now))
624 cf_scache_session_remove(peer, s);
625 }
626}
628static void cf_scache_peer_remove_non13(struct Curl_ssl_scache_peer *peer)
629{
630 struct Curl_llist_node *n = Curl_llist_head(&peer->sessions);
631 while(n) {
632 struct Curl_ssl_session *s = Curl_node_elem(n);
633 n = Curl_node_next(n);
634 if(s->ietf_tls_id != CURL_IETF_PROTO_TLS1_3)
635 cf_scache_session_remove(peer, s);
636 }
637}
639CURLcode Curl_ssl_scache_create(size_t max_peers,
640 size_t max_sessions_per_peer,
641 struct Curl_ssl_scache **pscache)
642{
643 struct Curl_ssl_scache *scache;
644 struct Curl_ssl_scache_peer *peers;
645 size_t i;
647 *pscache = NULL;
648 peers = curlx_calloc(max_peers, sizeof(*peers));
649 if(!peers)
650 return CURLE_OUT_OF_MEMORY;
652 scache = curlx_calloc(1, sizeof(*scache));
653 if(!scache) {
654 curlx_free(peers);
655 return CURLE_OUT_OF_MEMORY;
656 }
658 scache->magic = CURL_SCACHE_MAGIC;
659 scache->default_lifetime_secs = (24 * 60 * 60); /* 1 day */
660 scache->peer_count = max_peers;
661 scache->peers = peers;
662 scache->age = 1;
663 for(i = 0; i < scache->peer_count; ++i) {
664 scache->peers[i].max_sessions = max_sessions_per_peer;
665 Curl_llist_init(&scache->peers[i].sessions,
666 cf_ssl_scache_session_ldestroy);
667 }
668#ifdef USE_MUTEX
669 Curl_mutex_init(&scache->mutex);
670#endif
671 *pscache = scache;
672 return CURLE_OK;
673}
675void Curl_ssl_scache_destroy(struct Curl_ssl_scache *scache)
676{
677 if(GOOD_SCACHE(scache)) {
678 size_t i;
679 scache->magic = 0;
680 for(i = 0; i < scache->peer_count; ++i) {
681 cf_ssl_scache_clear_peer(&scache->peers[i]);
682 }
683 curlx_free(scache->peers);
684#ifdef USE_MUTEX
685 Curl_mutex_destroy(&scache->mutex);
686#endif
687 curlx_free(scache);
688 }
689}
691bool Curl_ssl_scache_use(struct Curl_cfilter *cf, struct Curl_easy *data)
692{
693 if(cf_ssl_scache_get(data)) {
694 struct ssl_filter_config *conn_config =
695 Curl_ssl_cf_get_filter_config(cf);
696 return conn_config ? conn_config->cache_session : FALSE;
697 }
698 return FALSE;
699}
701/* Lock shared SSL session data */
702void Curl_ssl_scache_lock(struct Curl_easy *data)
703{
704 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
705 if(scache) {
706 if(CURL_SHARE_ssl_scache(data))
707 Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION,
708 CURL_LOCK_ACCESS_SINGLE);
709#ifdef USE_MUTEX
710 Curl_mutex_acquire(&scache->mutex);
711 scache->locking_thread = Curl_thread_get_current_id();
712 DEBUGASSERT(!scache->is_locked);
713 scache->is_locked = TRUE;
714 Curl_mutex_release(&scache->mutex);
715#else
716 DEBUGASSERT(!scache->is_locked);
717 scache->is_locked = TRUE;
718#endif
719 }
720}
722/* Unlock shared SSL session data */
723void Curl_ssl_scache_unlock(struct Curl_easy *data)
724{
725 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
726 if(scache) {
727#ifdef USE_MUTEX
728 Curl_mutex_acquire(&scache->mutex);
729 scache->locking_thread = 0;
730 DEBUGASSERT(scache->is_locked);
731 scache->is_locked = FALSE;
732 Curl_mutex_release(&scache->mutex);
733#else
734 DEBUGASSERT(scache->is_locked);
735 scache->is_locked = FALSE;
736#endif
737 if(CURL_SHARE_ssl_scache(data))
738 Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
739 }
740}
742bool Curl_ssl_scache_is_locked_by_current_thread(struct Curl_easy *data)
743{
744 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
745 bool locked = FALSE;
746 if(!scache)
747 return FALSE;
748#ifdef USE_MUTEX
749 Curl_mutex_acquire(&scache->mutex);
750 locked = scache->is_locked && Curl_thread_is_current(scache->locking_thread);
751 Curl_mutex_release(&scache->mutex);
752#else
753 locked = (bool)scache->is_locked;
754#endif
755 return locked;
756}
758static bool cf_ssl_scache_match_auth(struct Curl_ssl_scache_peer *peer,
759 struct ssl_filter_config *conn_config)
760{
761 if(!conn_config) {
762 if(peer->clientcert || peer->key_passwd)
763 return FALSE;
764 return TRUE;
765 }
766 else if(!Curl_safecmp(peer->clientcert, conn_config->clientcert))
767 return FALSE;
768 if(Curl_timestrcmp(peer->key_passwd, conn_config->key_passwd))
769 return FALSE;
770 return TRUE;
771}
773static CURLcode cf_ssl_find_peer_by_key(struct Curl_easy *data,
774 struct Curl_ssl_scache *scache,
775 const char *ssl_peer_key,
776 struct ssl_filter_config *conn_config,
777 struct Curl_ssl_scache_peer **ppeer)
778{
779 size_t i, peer_key_len = 0;
780 CURLcode result = CURLE_OK;
782 *ppeer = NULL;
783 if(!GOOD_SCACHE(scache)) {
784 return CURLE_BAD_FUNCTION_ARGUMENT;
785 }
787 CURL_TRC_SSLS(data, "find peer slot for %s among %zu slots",
788 ssl_peer_key, scache->peer_count);
790 /* check for entries with known peer_key */
791 for(i = 0; scache && i < scache->peer_count; i++) {
792 if(scache->peers[i].ssl_peer_key &&
793 !strcmp(ssl_peer_key, scache->peers[i].ssl_peer_key) &&
794 cf_ssl_scache_match_auth(&scache->peers[i], conn_config)) {
795 /* yes, we have a cached session for this! */
796 *ppeer = &scache->peers[i];
797 goto out;
798 }
799 }
800 /* check for entries with HMAC set but no known peer_key */
801 for(i = 0; scache && i < scache->peer_count; i++) {
802 if(!scache->peers[i].ssl_peer_key &&
803 scache->peers[i].hmac_set &&
804 cf_ssl_scache_match_auth(&scache->peers[i], conn_config)) {
805 /* possible entry with unknown peer_key, check hmac */
806 unsigned char my_hmac[CURL_SHA256_DIGEST_LENGTH];
807 if(!peer_key_len) /* we are lazy */
808 peer_key_len = strlen(ssl_peer_key);
809 result = Curl_hmacit(&Curl_HMAC_SHA256,
810 scache->peers[i].key_salt,
811 sizeof(scache->peers[i].key_salt),
812 (const unsigned char *)ssl_peer_key,
813 peer_key_len,
814 my_hmac);
815 if(result)
816 goto out;
817 if(!memcmp(scache->peers[i].key_hmac, my_hmac, sizeof(my_hmac))) {
818 /* remember peer_key for future lookups */
819 CURL_TRC_SSLS(data, "peer entry %zu key recovered: %s",
820 i, ssl_peer_key);
821 scache->peers[i].ssl_peer_key = curlx_strdup(ssl_peer_key);
822 if(!scache->peers[i].ssl_peer_key) {
823 result = CURLE_OUT_OF_MEMORY;
824 goto out;
825 }
826 cf_ssl_cache_peer_update(&scache->peers[i]);
827 *ppeer = &scache->peers[i];
828 goto out;
829 }
830 }
831 }
832 CURL_TRC_SSLS(data, "peer not found for %s", ssl_peer_key);
833out:
834 return result;
835}
837static struct Curl_ssl_scache_peer *cf_ssl_get_free_peer(
838 struct Curl_ssl_scache *scache)
839{
840 struct Curl_ssl_scache_peer *peer = NULL;
841 size_t i;
843 /* find empty or oldest peer */
844 for(i = 0; i < scache->peer_count; ++i) {
845 /* free peer entry? */
846 if(!scache->peers[i].ssl_peer_key && !scache->peers[i].hmac_set) {
847 peer = &scache->peers[i];
848 break;
849 }
850 /* peer without sessions and obj */
851 if(!scache->peers[i].sobj &&
852 !Curl_llist_count(&scache->peers[i].sessions)) {
853 peer = &scache->peers[i];
854 break;
855 }
856 /* remember "oldest" peer */
857 if(!peer || (scache->peers[i].age < peer->age)) {
858 peer = &scache->peers[i];
859 }
860 }
861 DEBUGASSERT(peer);
862 if(peer)
863 cf_ssl_scache_clear_peer(peer);
864 return peer;
865}
867static CURLcode cf_ssl_add_peer(struct Curl_easy *data,
868 struct Curl_ssl_scache *scache,
869 const char *ssl_peer_key,
870 struct ssl_filter_config *conn_config,
871 struct Curl_ssl_scache_peer **ppeer)
872{
873 struct Curl_ssl_scache_peer *peer = NULL;
874 CURLcode result = CURLE_OK;
876 *ppeer = NULL;
877 if(ssl_peer_key) {
878 result = cf_ssl_find_peer_by_key(data, scache, ssl_peer_key, conn_config,
879 &peer);
880 if(result || !scache->peer_count)
881 return result;
882 }
884 if(peer) {
885 *ppeer = peer;
886 return CURLE_OK;
887 }
889 peer = cf_ssl_get_free_peer(scache);
890 if(peer) {
891 char buffer[64];
892 const char *ccert = conn_config ? conn_config->clientcert : NULL;
893 const char *kpasswd = conn_config ? conn_config->key_passwd : NULL;
894 if(!ccert && conn_config && conn_config->cert_blob) {
895 /* when using a client cert blob, create a name for it */
896 curl_msnprintf(buffer, sizeof(buffer),
897 "cert-%p", conn_config->cert_blob->data);
898 ccert = buffer; /* data is strduped by cf_ssl_scache_peer_init */
899 }
900 result = cf_ssl_scache_peer_init(peer, ssl_peer_key, ccert, kpasswd,
901 NULL, NULL);
902 if(result)
903 goto out;
904 /* all ready */
905 *ppeer = peer;
906 result = CURLE_OK;
907 }
909out:
910 if(result) {
911 cf_ssl_scache_clear_peer(peer);
912 }
913 return result;
914}
916static void cf_scache_peer_add_session(struct Curl_ssl_scache_peer *peer,
917 struct Curl_ssl_session *s,
918 curl_off_t now)
919{
920 /* A session not from TLSv1.3 replaces all other. */
921 if(s->ietf_tls_id != CURL_IETF_PROTO_TLS1_3) {
922 Curl_llist_destroy(&peer->sessions, NULL);
923 Curl_llist_append(&peer->sessions, s, &s->list);
924 }
925 else {
926 /* Expire existing, append, trim from head to obey max_sessions */
927 cf_scache_peer_remove_expired(peer, now);
928 cf_scache_peer_remove_non13(peer);
929 Curl_llist_append(&peer->sessions, s, &s->list);
930 while(Curl_llist_count(&peer->sessions) > peer->max_sessions) {
931 Curl_node_remove(Curl_llist_head(&peer->sessions));
932 }
933 }
934}
936static CURLcode cf_scache_add_session(struct Curl_cfilter *cf,
937 struct Curl_easy *data,
938 struct Curl_ssl_scache *scache,
939 const char *ssl_peer_key,
940 struct Curl_ssl_session *s)
941{
942 struct Curl_ssl_scache_peer *peer = NULL;
943 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
944 CURLcode result = CURLE_OUT_OF_MEMORY;
945 curl_off_t now = (curl_off_t)time(NULL);
946 curl_off_t max_lifetime;
948 if(!scache || !scache->peer_count) {
949 Curl_ssl_session_destroy(s);
950 return CURLE_OK;
951 }
953 if(s->valid_until <= 0)
954 s->valid_until = now + scache->default_lifetime_secs;
956 max_lifetime = (s->ietf_tls_id == CURL_IETF_PROTO_TLS1_3) ?
957 CURL_SCACHE_MAX_13_LIFETIME_SEC :
958 CURL_SCACHE_MAX_12_LIFETIME_SEC;
959 if(s->valid_until > (now + max_lifetime))
960 s->valid_until = now + max_lifetime;
962 if(cf_scache_session_expired(s, now)) {
963 CURL_TRC_SSLS(data, "add, session already expired");
964 Curl_ssl_session_destroy(s);
965 return CURLE_OK;
966 }
968 result = cf_ssl_add_peer(data, scache, ssl_peer_key, conn_config, &peer);
969 if(result || !peer) {
970 CURL_TRC_SSLS(data, "unable to add scache peer: %d", (int)result);
971 Curl_ssl_session_destroy(s);
972 goto out;
973 }
975 cf_scache_peer_add_session(peer, s, now);
977out:
978 if(result) {
979 failf(data, "[SCACHE] failed to add session for %s, error=%d",
980 ssl_peer_key, (int)result);
981 }
982 else
983 CURL_TRC_SSLS(data, "added session for %s [proto=0x%x, "
984 "valid_secs=%" FMT_OFF_T ", alpn=%s, earlydata=%zu, "
985 "quic_tp=%s], peer has %zu sessions now", ssl_peer_key,
986 (unsigned int)s->ietf_tls_id, s->valid_until - now,
987 s->alpn, s->earlydata_max, s->quic_tp ? "yes" : "no",
988 peer ? Curl_llist_count(&peer->sessions) : 0);
989 return result;
990}
992CURLcode Curl_ssl_scache_put(struct Curl_cfilter *cf,
993 struct Curl_easy *data,
994 const char *ssl_peer_key,
995 struct Curl_ssl_session *s)
996{
997 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
998 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
999 CURLcode result;
1000 DEBUGASSERT(conn_config);
1002 if(!scache || !conn_config->cache_session) {
1003 Curl_ssl_session_destroy(s);
1004 return CURLE_OK;
1005 }
1007 Curl_ssl_scache_lock(data);
1008 result = cf_scache_add_session(cf, data, scache, ssl_peer_key, s);
1009 Curl_ssl_scache_unlock(data);
1010 return result;
1011}
1013void Curl_ssl_scache_return(struct Curl_cfilter *cf,
1014 struct Curl_easy *data,
1015 const char *ssl_peer_key,
1016 struct Curl_ssl_session *s)
1017{
1018 /* See RFC 8446 C.4:
1019 * "Clients SHOULD NOT reuse a ticket for multiple connections." */
1020 if(s && s->ietf_tls_id < 0x304)
1021 (void)Curl_ssl_scache_put(cf, data, ssl_peer_key, s);
1022 else
1023 Curl_ssl_session_destroy(s);
1024}
1026CURLcode Curl_ssl_scache_take(struct Curl_cfilter *cf,
1027 struct Curl_easy *data,
1028 const char *ssl_peer_key,
1029 struct Curl_ssl_session **ps)
1030{
1031 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
1032 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
1033 struct Curl_ssl_scache_peer *peer = NULL;
1034 struct Curl_llist_node *n;
1035 struct Curl_ssl_session *s = NULL;
1036 CURLcode result;
1038 *ps = NULL;
1039 if(!scache)
1040 return CURLE_OK;
1042 Curl_ssl_scache_lock(data);
1043 result = cf_ssl_find_peer_by_key(data, scache, ssl_peer_key, conn_config,
1044 &peer);
1045 if(!result && peer) {
1046 cf_scache_peer_remove_expired(peer, (curl_off_t)time(NULL));
1047 n = Curl_llist_head(&peer->sessions);
1048 if(n) {
1049 s = Curl_node_take_elem(n);
1050 scache->age++; /* increase general age */
1051 peer->age = scache->age; /* set this as used in this age */
1052 }
1053 }
1054 if(s) {
1055 *ps = s;
1056 CURL_TRC_SSLS(data, "took session for %s [proto=0x%x, "
1057 "alpn=%s, earlydata=%zu, quic_tp=%s], %zu sessions remain",
1058 ssl_peer_key, (unsigned int)s->ietf_tls_id, s->alpn,
1059 s->earlydata_max, s->quic_tp ? "yes" : "no",
1060 Curl_llist_count(&peer->sessions));
1061 }
1062 else {
1063 CURL_TRC_SSLS(data, "no cached session for %s", ssl_peer_key);
1064 }
1065 Curl_ssl_scache_unlock(data);
1066 return result;
1067}
1069CURLcode Curl_ssl_scache_add_obj(struct Curl_cfilter *cf,
1070 struct Curl_easy *data,
1071 const char *ssl_peer_key,
1072 void *sobj,
1073 Curl_ssl_scache_obj_dtor *sobj_dtor_cb)
1074{
1075 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
1076 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
1077 struct Curl_ssl_scache_peer *peer = NULL;
1078 CURLcode result;
1080 DEBUGASSERT(sobj);
1081 DEBUGASSERT(sobj_dtor_cb);
1083 if(!scache) {
1084 result = CURLE_BAD_FUNCTION_ARGUMENT;
1085 goto out;
1086 }
1088 result = cf_ssl_add_peer(data, scache, ssl_peer_key, conn_config, &peer);
1089 if(result || !peer) {
1090 CURL_TRC_SSLS(data, "unable to add scache peer: %d", (int)result);
1091 goto out;
1092 }
1094 cf_ssl_scache_peer_set_obj(peer, sobj, sobj_dtor_cb);
1095 sobj = NULL; /* peer took ownership */
1097out:
1098 if(sobj && sobj_dtor_cb)
1099 sobj_dtor_cb(sobj);
1100 return result;
1101}
1103void *Curl_ssl_scache_get_obj(struct Curl_cfilter *cf,
1104 struct Curl_easy *data,
1105 const char *ssl_peer_key)
1106{
1107 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
1108 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
1109 struct Curl_ssl_scache_peer *peer = NULL;
1110 CURLcode result;
1111 void *sobj;
1113 if(!scache)
1114 return NULL;
1116 result = cf_ssl_find_peer_by_key(data, scache, ssl_peer_key, conn_config,
1117 &peer);
1118 if(result)
1119 return NULL;
1121 sobj = peer ? peer->sobj : NULL;
1123 CURL_TRC_SSLS(data, "%s cached session for '%s'",
1124 sobj ? "Found" : "No", ssl_peer_key);
1125 return sobj;
1126}
1128void Curl_ssl_scache_remove_all(struct Curl_cfilter *cf,
1129 struct Curl_easy *data,
1130 const char *ssl_peer_key)
1131{
1132 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
1133 struct ssl_filter_config *conn_config = Curl_ssl_cf_get_filter_config(cf);
1134 struct Curl_ssl_scache_peer *peer = NULL;
1135 CURLcode result;
1137 (void)cf;
1138 if(!scache)
1139 return;
1141 Curl_ssl_scache_lock(data);
1142 result = cf_ssl_find_peer_by_key(data, scache, ssl_peer_key, conn_config,
1143 &peer);
1144 if(!result && peer)
1145 cf_ssl_scache_clear_peer(peer);
1146 Curl_ssl_scache_unlock(data);
1147}
1149#ifdef USE_SSLS_EXPORT
1151#define CURL_SSL_TICKET_MAX (16 * 1024)
1153static CURLcode cf_ssl_scache_peer_set_hmac(struct Curl_ssl_scache_peer *peer)
1154{
1155 CURLcode result;
1157 DEBUGASSERT(peer);
1158 if(!peer->ssl_peer_key)
1159 return CURLE_BAD_FUNCTION_ARGUMENT;
1161 result = Curl_rand(NULL, peer->key_salt, sizeof(peer->key_salt));
1162 if(result)
1163 return result;
1165 result = Curl_hmacit(&Curl_HMAC_SHA256,
1166 peer->key_salt, sizeof(peer->key_salt),
1167 (const unsigned char *)peer->ssl_peer_key,
1168 strlen(peer->ssl_peer_key),
1169 peer->key_hmac);
1170 if(!result)
1171 peer->hmac_set = TRUE;
1172 return result;
1173}
1175static CURLcode cf_ssl_find_peer_by_hmac(struct Curl_ssl_scache *scache,
1176 const unsigned char *salt,
1177 const unsigned char *hmac,
1178 struct Curl_ssl_scache_peer **ppeer)
1179{
1180 size_t i;
1181 CURLcode result = CURLE_OK;
1183 *ppeer = NULL;
1184 if(!GOOD_SCACHE(scache))
1185 return CURLE_BAD_FUNCTION_ARGUMENT;
1187 /* look for an entry that matches salt+hmac exactly or has a known
1188 * ssl_peer_key which salt+hmac's to the same. */
1189 for(i = 0; scache && i < scache->peer_count; i++) {
1190 struct Curl_ssl_scache_peer *peer = &scache->peers[i];
1191 if(!cf_ssl_scache_match_auth(peer, NULL))
1192 continue;
1193 if(scache->peers[i].hmac_set &&
1194 !memcmp(peer->key_salt, salt, sizeof(peer->key_salt)) &&
1195 !memcmp(peer->key_hmac, hmac, sizeof(peer->key_hmac))) {
1196 /* found exact match, return */
1197 *ppeer = peer;
1198 goto out;
1199 }
1200 else if(peer->ssl_peer_key) {
1201 unsigned char my_hmac[CURL_SHA256_DIGEST_LENGTH];
1202 /* compute hmac for the passed salt */
1203 result = Curl_hmacit(&Curl_HMAC_SHA256,
1204 salt, sizeof(peer->key_salt),
1205 (const unsigned char *)peer->ssl_peer_key,
1206 strlen(peer->ssl_peer_key),
1207 my_hmac);
1208 if(result)
1209 goto out;
1210 if(!memcmp(my_hmac, hmac, sizeof(my_hmac))) {
1211 /* cryptohash match, take over salt+hmac if no set and return */
1212 if(!peer->hmac_set) {
1213 memcpy(peer->key_salt, salt, sizeof(peer->key_salt));
1214 memcpy(peer->key_hmac, hmac, sizeof(peer->key_hmac));
1215 peer->hmac_set = TRUE;
1216 }
1217 *ppeer = peer;
1218 goto out;
1219 }
1220 }
1221 }
1222out:
1223 return result;
1224}
1226CURLcode Curl_ssl_session_import(struct Curl_easy *data,
1227 const char *ssl_peer_key,
1228 const unsigned char *shmac, size_t shmac_len,
1229 const void *sdata, size_t sdata_len)
1230{
1231 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
1232 struct Curl_ssl_scache_peer *peer = NULL;
1233 struct Curl_ssl_session *s = NULL;
1234 bool have_lock = FALSE;
1235 CURLcode result;
1237 if(!scache || !sdata || !sdata_len) {
1238 result = CURLE_BAD_FUNCTION_ARGUMENT;
1239 goto out;
1240 }
1241 if(!ssl_peer_key && (!shmac || !shmac_len)) {
1242 result = CURLE_BAD_FUNCTION_ARGUMENT;
1243 goto out;
1244 }
1246 result = Curl_ssl_session_unpack(data, sdata, sdata_len, &s);
1247 if(result)
1248 goto out;
1250 Curl_ssl_scache_lock(data);
1251 have_lock = TRUE;
1253 if(ssl_peer_key) {
1254 result = cf_ssl_add_peer(data, scache, ssl_peer_key, NULL, &peer);
1255 if(result)
1256 goto out;
1257 }
1258 else if(shmac_len != (sizeof(peer->key_salt) + sizeof(peer->key_hmac))) {
1259 /* Either salt+hmac was garbled by caller or is from a curl version
1260 * that does things differently */
1261 result = CURLE_BAD_FUNCTION_ARGUMENT;
1262 goto out;
1263 }
1264 else {
1265 const unsigned char *salt = shmac;
1266 const unsigned char *hmac = shmac + sizeof(peer->key_salt);
1268 result = cf_ssl_find_peer_by_hmac(scache, salt, hmac, &peer);
1269 if(result)
1270 goto out;
1271 if(!peer) {
1272 peer = cf_ssl_get_free_peer(scache);
1273 if(peer) {
1274 result = cf_ssl_scache_peer_init(peer, ssl_peer_key, NULL, NULL,
1275 salt, hmac);
1276 if(result)
1277 goto out;
1278 }
1279 }
1280 }
1282 if(peer) {
1283 cf_scache_peer_add_session(peer, s, time(NULL));
1284 s = NULL; /* peer is now owner */
1285 CURL_TRC_SSLS(data, "successfully imported ticket for peer %s, now "
1286 "with %zu tickets",
1287 peer->ssl_peer_key ? peer->ssl_peer_key : "without key",
1288 Curl_llist_count(&peer->sessions));
1289 }
1291out:
1292 if(scache && have_lock)
1293 Curl_ssl_scache_unlock(data);
1294 Curl_ssl_session_destroy(s);
1295 return result;
1296}
1298CURLcode Curl_ssl_session_export(struct Curl_easy *data,
1299 curl_ssls_export_cb *export_fn,
1300 void *userptr)
1301{
1302 struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
1303 struct Curl_ssl_scache_peer *peer;
1304 struct dynbuf sbuf, hbuf;
1305 struct Curl_llist_node *n;
1306 size_t i;
1307 curl_off_t now = time(NULL);
1308 CURLcode result = CURLE_OK;
1309#ifdef CURLVERBOSE
1310 size_t npeers = 0, ntickets = 0;
1311#endif
1313 if(!export_fn)
1314 return CURLE_BAD_FUNCTION_ARGUMENT;
1316 Curl_ssl_scache_lock(data);
1318 curlx_dyn_init(&hbuf, (CURL_SHA256_DIGEST_LENGTH * 2) + 1);
1319 curlx_dyn_init(&sbuf, CURL_SSL_TICKET_MAX);
1321 for(i = 0; scache && i < scache->peer_count; i++) {
1322 peer = &scache->peers[i];
1323 if(!peer->ssl_peer_key && !peer->hmac_set)
1324 continue; /* skip free entry */
1325 if(!peer->exportable)
1326 continue;
1328 curlx_dyn_reset(&hbuf);
1329 cf_scache_peer_remove_expired(peer, now);
1330 n = Curl_llist_head(&peer->sessions);
1331 if(n)
1332 VERBOSE(++npeers);
1333 while(n) {
1334 struct Curl_ssl_session *s = Curl_node_elem(n);
1335 if(!peer->hmac_set) {
1336 result = cf_ssl_scache_peer_set_hmac(peer);
1337 if(result)
1338 goto out;
1339 }
1340 if(!curlx_dyn_len(&hbuf)) {
1341 result = curlx_dyn_addn(&hbuf, peer->key_salt, sizeof(peer->key_salt));
1342 if(result)
1343 goto out;
1344 result = curlx_dyn_addn(&hbuf, peer->key_hmac, sizeof(peer->key_hmac));
1345 if(result)
1346 goto out;
1347 }
1348 curlx_dyn_reset(&sbuf);
1349 result = Curl_ssl_session_pack(data, s, &sbuf);
1350 if(result)
1351 goto out;
1353 result = export_fn(data, userptr, peer->ssl_peer_key,
1354 curlx_dyn_uptr(&hbuf), curlx_dyn_len(&hbuf),
1355 curlx_dyn_uptr(&sbuf), curlx_dyn_len(&sbuf),
1356 s->valid_until, s->ietf_tls_id,
1357 s->alpn, s->earlydata_max);
1358 if(result)
1359 goto out;
1360 VERBOSE(++ntickets);
1361 n = Curl_node_next(n);
1362 }
1363 }
1364 result = CURLE_OK;
1365 CURL_TRC_SSLS(data, "exported %zu session tickets for %zu peers",
1366 ntickets, npeers);
1368out:
1369 Curl_ssl_scache_unlock(data);
1370 curlx_dyn_free(&hbuf);
1371 curlx_dyn_free(&sbuf);
1372 return result;
1373}
1375#endif /* USE_SSLS_EXPORT */
1377#endif /* USE_SSL */
Diagnostics4 git calls · 648 ms
CallStatusSizeTime0648 ms
discover200152 B3 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 · 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=643 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
fetch2009.9 KiB643 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=10180 git.response.cache=MISS git.response.duration_ms=643 git.fetch.wants=f52f5933844b581dccf567b9607fc067e25884c3 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=10180 git.pkt.payload.max=10159 git.sideband.band1.bytes=10158 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
- a5e37b2758913a24
- Request
- 73a633c1…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format