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 "tool_setup.h"
26#include "tool_cfgable.h"
27#include "tool_cb_dbg.h"
28#include "tool_msgs.h"
29#include "tool_setopt.h"
30#include "tool_ssls.h"
31#include "tool_parsecfg.h"
33/* The maximum line length for an encoded session ticket */
34#define MAX_SSLS_LINE (64 * 1024)
36static CURLcode tool_ssls_easy(struct OperationConfig *config,
37 CURLSH *share, CURL **peasy)
38{
39 CURLcode result = CURLE_OK;
41 *peasy = curl_easy_init();
42 if(!*peasy)
43 return CURLE_OUT_OF_MEMORY;
45 result = curl_easy_setopt(*peasy, CURLOPT_SHARE, share);
46 if(!result && (global->tracetype != TRACE_NONE)) {
47 result = my_setopt_ptr(*peasy, CURLOPT_DEBUGFUNCTION, tool_debug_cb);
48 if(!result)
49 result = my_setopt_ptr(*peasy, CURLOPT_DEBUGDATA, config);
50 my_setopt_long(*peasy, CURLOPT_VERBOSE, 1L);
51 }
52 return result;
53}
55CURLcode tool_ssls_load(struct OperationConfig *config,
56 CURLSH *share, const char *filename)
57{
58 FILE *fp;
59 CURL *easy = NULL;
60 struct dynbuf buf;
61 unsigned char *shmac = NULL, *sdata = NULL;
62 char *c, *line, *end;
63 size_t shmac_len, sdata_len;
64 CURLcode result = CURLE_OK;
65 int i, imported;
66 bool error = FALSE;
68 curlx_dyn_init(&buf, MAX_SSLS_LINE);
69 fp = curlx_fopen(filename, FOPEN_READTEXT);
70 if(!fp) { /* ok if it does not exist */
71 notef("SSL session file does not exist (yet?): %s", filename);
72 goto out;
73 }
75 result = tool_ssls_easy(config, share, &easy);
76 if(result)
77 goto out;
79 i = imported = 0;
80 while(my_get_line(fp, &buf, &error, NULL)) {
81 ++i;
82 curlx_safefree(shmac);
83 curlx_safefree(sdata);
84 line = curlx_dyn_ptr(&buf);
86 c = memchr(line, ':', strlen(line));
87 if(!c) {
88 warnf("unrecognized line %d in SSL session file %s", i, filename);
89 continue;
90 }
91 *c = '\0';
92 result = curlx_base64_decode(line, &shmac, &shmac_len);
93 if(result) {
94 warnf("invalid shmax base64 encoding in line %d", i);
95 continue;
96 }
97 line = c + 1;
98 end = line + strlen(line) - 1;
99 while((end > line) && (*end == '\n' || *end == '\r' || ISBLANK(*line))) {
100 *end = '\0';
101 --end;
102 }
103 result = curlx_base64_decode(line, &sdata, &sdata_len);
104 if(result) {
105 warnf("invalid sdata base64 encoding in line %d: %s", i, line);
106 continue;
107 }
109 result = curl_easy_ssls_import(easy, NULL, shmac, shmac_len, sdata,
110 sdata_len);
111 if(result) {
112 warnf("import of session from line %d rejected(%d)", i, (int)result);
113 continue;
114 }
115 ++imported;
116 }
117 if(error)
118 result = CURLE_FAILED_INIT;
119 else
120 result = CURLE_OK;
122out:
123 if(easy)
124 curl_easy_cleanup(easy);
125 if(fp)
126 curlx_fclose(fp);
127 curlx_dyn_free(&buf);
128 curlx_free(shmac);
129 curlx_free(sdata);
130 return result;
131}
133struct tool_ssls_ctx {
134 FILE *fp;
135 int exported;
136};
138static CURLcode tool_ssls_exp(CURL *easy, void *userptr,
139 const char *session_key,
140 const unsigned char *shmac, size_t shmac_len,
141 const unsigned char *sdata, size_t sdata_len,
142 curl_off_t valid_until, int ietf_tls_id,
143 const char *alpn, size_t earlydata_max)
144{
145 struct tool_ssls_ctx *ctx = userptr;
146 char *enc = NULL;
147 size_t enc_len;
148 CURLcode result;
150 (void)easy;
151 (void)valid_until;
152 (void)ietf_tls_id;
153 (void)alpn;
154 (void)earlydata_max;
155 if(!ctx->exported)
156 fputs("# Your SSL session cache. https://curl.se/docs/ssl-sessions.html\n"
157 "# This file was generated by libcurl! Edit at your own risk.\n",
158 ctx->fp);
160 result = curlx_base64_encode(shmac, shmac_len, &enc, &enc_len);
161 if(result)
162 goto out;
163 result = CURLE_WRITE_ERROR;
164 if(fwrite(enc, 1, enc_len, ctx->fp) != enc_len)
165 goto out;
166 if(fputc(':', ctx->fp) == EOF)
167 goto out;
168 curlx_safefree(enc);
169 result = curlx_base64_encode(sdata, sdata_len, &enc, &enc_len);
170 if(result)
171 goto out;
172 result = CURLE_WRITE_ERROR;
173 if(fwrite(enc, 1, enc_len, ctx->fp) != enc_len)
174 goto out;
175 if(fputc('\n', ctx->fp) == EOF)
176 goto out;
177 result = CURLE_OK;
178 ctx->exported++;
179out:
180 if(result)
181 warnf("Warning: error saving SSL session for '%s': %d", session_key,
182 (int)result);
183 curlx_free(enc);
184 return result;
185}
187CURLcode tool_ssls_save(struct OperationConfig *config,
188 CURLSH *share, const char *filename)
189{
190 struct tool_ssls_ctx ctx;
191 CURL *easy = NULL;
192 CURLcode result = CURLE_OK;
194 ctx.exported = 0;
195 ctx.fp = curlx_fopen(filename, FOPEN_WRITETEXT);
196 if(!ctx.fp) {
197 warnf("Warning: Failed to create SSL session file %s", filename);
198 goto out;
199 }
201 result = tool_ssls_easy(config, share, &easy);
202 if(result)
203 goto out;
205 result = curl_easy_ssls_export(easy, tool_ssls_exp, &ctx);
207out:
208 if(easy)
209 curl_easy_cleanup(easy);
210 if(ctx.fp)
211 curlx_fclose(ctx.fp);
212 return result;
213}
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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=1 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 · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=1 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.2 KiB · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2211 git.response.cache=HIT git.response.duration_ms=24 git.fetch.wants=8e575f15252698f0870493a214c54bd248664f26 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=2211 git.pkt.payload.max=2190 git.sideband.band1.bytes=2189 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
- a5e14767ab86a140
- Request
- 64219c9f…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format