master
1#ifndef HEADER_CURL_VTLS_SCACHE_H
2#define HEADER_CURL_VTLS_SCACHE_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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#include "curl_setup.h"
28#ifdef USE_SSL
30#include "cfilters.h"
31#include "urldata.h"
33struct Curl_cfilter;
34struct Curl_easy;
35struct Curl_ssl_scache;
36struct Curl_ssl_session;
37struct ssl_peer;
39/* RFC 8446 (TLSv1.3) restrict lifetime to one week max, for
40 * other, less secure versions, we restrict it to a day */
41#define CURL_SCACHE_MAX_13_LIFETIME_SEC (60 * 60 * 24 * 7)
42#define CURL_SCACHE_MAX_12_LIFETIME_SEC (60 * 60 * 24)
44/* Create a session cache for up to max_peers endpoints with a total
45 * of up to max_sessions SSL sessions per peer */
46CURLcode Curl_ssl_scache_create(size_t max_peers,
47 size_t max_sessions_per_peer,
48 struct Curl_ssl_scache **pscache);
50void Curl_ssl_scache_destroy(struct Curl_ssl_scache *scache);
52/* Create a key from peer and TLS configuration information that is
53 * unique for how the connection filter wants to establish a TLS
54 * connection to the peer.
55 * If the filter is a TLS proxy filter, it uses the proxy relevant
56 * information.
57 * @param peer the peer the filter wants to talk to
58 * @param sslc the relevant ssl configuration
59 * @param tls_id identifier of TLS implementation for sessions. Should
60 * include full version if session data from other versions
61 * is to be avoided.
62 * @param ppeer_key on successful return, the key generated
63 */
64CURLcode Curl_ssl_peer_key_make(const struct ssl_peer *peer,
65 struct ssl_filter_config *sslc,
66 const char *tls_id,
67 char **ppeer_key);
69/* Return if there is a session cache shall be used.
70 * An SSL session might not be configured or not available for
71 * "connect-only" transfers.
72 */
73bool Curl_ssl_scache_use(struct Curl_cfilter *cf, struct Curl_easy *data);
75/* Lock session cache mutex.
76 * Call this before calling other Curl_ssl_*session* functions
77 * Caller should unlock this mutex as soon as possible, as it may block
78 * other SSL connection from making progress.
79 * The purpose of explicitly locking SSL session cache data is to allow
80 * individual SSL engines to manage session lifetime in their specific way.
81 */
82void Curl_ssl_scache_lock(struct Curl_easy *data);
84/* Unlock session cache mutex */
85void Curl_ssl_scache_unlock(struct Curl_easy *data);
87/* Get TLS session object from the cache for the ssl_peer_key.
88 * scache mutex must be locked (see Curl_ssl_scache_lock).
89 * Caller must make sure that the ownership of returned session object
90 * is properly taken (e.g. its refcount is incremented
91 * under scache mutex).
92 * @param cf the connection filter wanting to use it
93 * @param data the transfer involved
94 * @param ssl_peer_key the key for lookup
95 * @retval sobj the object for the peer key or NULL
96 */
97void *Curl_ssl_scache_get_obj(struct Curl_cfilter *cf,
98 struct Curl_easy *data,
99 const char *ssl_peer_key);
101typedef void Curl_ssl_scache_obj_dtor(void *sobj);
103/* Add a TLS session related object to the cache.
104 * Replaces an existing object with the same peer_key.
105 * scache mutex must be locked (see Curl_ssl_scache_lock).
106 * Call takes ownership of `sobj`, using `sobj_dtor_cb`
107 * to deallocate it. Is called in all outcomes, either right away or
108 * later when the session cache is cleaned up.
109 * Caller must ensure that it has properly shared ownership of `sobj`
110 * with cache (e.g. incrementing refcount on success)
111 * @param cf the connection filter wanting to use it
112 * @param data the transfer involved
113 * @param ssl_peer_key the key for lookup
114 * @param sobj the TLS session object
115 * @param sobj_free_cb callback to free the session object
116 */
117CURLcode Curl_ssl_scache_add_obj(struct Curl_cfilter *cf,
118 struct Curl_easy *data,
119 const char *ssl_peer_key,
120 void *sobj,
121 Curl_ssl_scache_obj_dtor *sobj_dtor_cb);
123/* All about an SSL session ticket */
124struct Curl_ssl_session {
125 uint8_t *sdata; /* session ticket data, plain bytes */
126 size_t sdata_len; /* number of bytes in sdata */
127 curl_off_t valid_until; /* seconds since EPOCH until ticket expires */
128 int ietf_tls_id; /* TLS protocol identifier negotiated */
129 char *alpn; /* APLN TLS negotiated protocol string */
130 size_t earlydata_max; /* max 0-RTT data supported by peer */
131 uint8_t *quic_tp; /* Optional QUIC transport param bytes */
132 size_t quic_tp_len; /* number of bytes in quic_tp */
133 struct Curl_llist_node list; /* internal storage handling */
134 BIT(sectrust_verified); /* session comes from sectrust verified TLS */
135};
137/* Create a `session` instance. Does NOT need locking.
138 * Takes ownership of `sdata` and `sobj` regardless of return code.
139 * @param sdata bytes of SSL session data or NULL (sobj then required)
140 * @param sdata_len amount of session data bytes
141 * @param ietf_tls_id IETF protocol version, e.g. 0x304 for TLSv1.3
142 * @param alpn ALPN protocol selected or NULL
143 * @param valid_until seconds since EPOCH when session expires, pass 0
144 * in case this is not known.
145 * @param psession on return the scached session instance created
146 */
147CURLcode Curl_ssl_session_create(void *sdata, size_t sdata_len,
148 int ietf_tls_id, const char *alpn,
149 curl_off_t valid_until, size_t earlydata_max,
150 struct Curl_ssl_session **psession);
152/* Variation of session creation with quic transport parameter bytes,
153 * Takes ownership of `quic_tp` regardless of return code. */
154CURLcode Curl_ssl_session_create2(void *sdata, size_t sdata_len,
155 int ietf_tls_id, const char *alpn,
156 curl_off_t valid_until, size_t earlydata_max,
157 unsigned char *quic_tp, size_t quic_tp_len,
158 struct Curl_ssl_session **psession);
160/* Duplicate an ssl session */
161CURLcode Curl_ssl_session_dup(struct Curl_ssl_session *src,
162 struct Curl_ssl_session **pdest);
164/* Destroy a `session` instance. Can be called with NULL.
165 * Does NOT need locking. */
166void Curl_ssl_session_destroy(struct Curl_ssl_session *s);
168/* Put the scache session into the cache. Does NOT need locking.
169 * Call takes ownership of `s` in all outcomes.
170 * @param cf the connection filter wanting to use it
171 * @param data the transfer involved
172 * @param ssl_peer_key the key for lookup
173 * @param s the scache session object
174 */
175CURLcode Curl_ssl_scache_put(struct Curl_cfilter *cf,
176 struct Curl_easy *data,
177 const char *ssl_peer_key,
178 struct Curl_ssl_session *s);
180/* Take a matching scache session from the cache. Does NOT need locking.
181 * @param cf the connection filter wanting to use it
182 * @param data the transfer involved
183 * @param ssl_peer_key the key for lookup
184 * @param s on return, the scache session object or NULL
185 */
186CURLcode Curl_ssl_scache_take(struct Curl_cfilter *cf,
187 struct Curl_easy *data,
188 const char *ssl_peer_key,
189 struct Curl_ssl_session **ps);
191/* Return a taken scache session to the cache. Does NOT need locking.
192 * Depending on TLS version and other criteria, it may cache it again
193 * or destroy it. Maybe called with a NULL session.
194 */
195void Curl_ssl_scache_return(struct Curl_cfilter *cf,
196 struct Curl_easy *data,
197 const char *ssl_peer_key,
198 struct Curl_ssl_session *s);
200/* Remove all sessions and obj for the peer_key. Does NOT need locking. */
201void Curl_ssl_scache_remove_all(struct Curl_cfilter *cf,
202 struct Curl_easy *data,
203 const char *ssl_peer_key);
205bool Curl_ssl_scache_is_locked_by_current_thread(struct Curl_easy *data);
207#ifdef USE_SSLS_EXPORT
209CURLcode Curl_ssl_session_import(struct Curl_easy *data,
210 const char *ssl_peer_key,
211 const unsigned char *shmac, size_t shmac_len,
212 const void *sdata, size_t sdata_len);
214CURLcode Curl_ssl_session_export(struct Curl_easy *data,
215 curl_ssls_export_cb *export_fn,
216 void *userptr);
218#endif /* USE_SSLS_EXPORT */
219#endif /* USE_SSL */
221#endif /* HEADER_CURL_VTLS_SCACHE_H */
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 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 · 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 · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=23 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 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
fetch2003.0 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3112 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=9a393c72f6fdd4d559dc7f6c8a9e60942e2e61e1 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=3112 git.pkt.payload.max=3091 git.sideband.band1.bytes=3090 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
- a5e3887d7e95a691
- Request
- a777cbaa…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format