master
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10#
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
14#
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
18#
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
21#
22# SPDX-License-Identifier: curl
23#
24#***************************************************************************
26# This is the HTTPS, FTPS, POP3S, IMAPS, SMTPS, server used for curl test
27# harness. Actually a layer that runs stunnel properly using the
28# non-secure test harness servers.
30use strict;
31use warnings;
33BEGIN {
34 push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
35 push(@INC, ".");
36}
38use Cwd;
39use Cwd 'abs_path';
40use File::Basename;
42use serverhelp qw(
43 server_pidfilename
44 server_logfilename
45 );
47use pathhelp;
49my $stunnel = "stunnel";
51my $verbose = 0; # set to 1 for debugging
53my $accept_port = 8991; # our default, weird enough
54my $target_port = 8999; # default test http-server port
56my $stuncert;
58my $ver_major;
59my $ver_minor;
60my $fips_support;
61my $stunnel_version;
62my $tstunnel_windows;
63my $socketopt;
64my $cmd;
66my $pidfile; # stunnel pid file
67my $logfile; # stunnel log file
68my $loglevel = 5; # stunnel log level
69my $ipvnum = 4; # default IP version of stunneled server
70my $idnum = 1; # default stunneled server instance number
71my $proto = 'https'; # default secure server protocol
72my $conffile; # stunnel configuration file
73my $cafile; # certificate CA PEM file
74my $certfile; # certificate chain PEM file
75my $mtls = 0; # Whether to verify client certificates
77#***************************************************************************
78# stunnel requires full path specification for several files.
79#
80my $path = getcwd();
81my $srcdir = $path;
82my $logdir = $path . '/log';
83my $piddir;
85#***************************************************************************
86# Signal handler to remove our stunnel 4.00 and newer configuration file.
87#
88sub exit_signal_handler {
89 my $signame = shift;
90 local $!; # preserve errno
91 local $?; # preserve exit status
92 unlink($conffile) if($conffile && (-f $conffile));
93 exit;
94}
96#***************************************************************************
97# Process command line options
98#
99while(@ARGV) {
100 if($ARGV[0] eq '--verbose') {
101 $verbose = 1;
102 }
103 elsif($ARGV[0] eq '--proto') {
104 if($ARGV[1]) {
105 $proto = $ARGV[1];
106 shift @ARGV;
107 }
108 }
109 elsif($ARGV[0] eq '--accept') {
110 if($ARGV[1]) {
111 if($ARGV[1] =~ /^(\d+)$/) {
112 $accept_port = $1;
113 shift @ARGV;
114 }
115 }
116 }
117 elsif($ARGV[0] eq '--connect') {
118 if($ARGV[1]) {
119 if($ARGV[1] =~ /^(\d+)$/) {
120 $target_port = $1;
121 shift @ARGV;
122 }
123 }
124 }
125 elsif($ARGV[0] eq '--stunnel') {
126 if($ARGV[1]) {
127 $stunnel = $ARGV[1];
128 shift @ARGV;
129 }
130 }
131 elsif($ARGV[0] eq '--srcdir') {
132 if($ARGV[1]) {
133 $srcdir = $ARGV[1];
134 shift @ARGV;
135 }
136 }
137 elsif($ARGV[0] eq '--certfile') {
138 if($ARGV[1]) {
139 $stuncert = $ARGV[1];
140 shift @ARGV;
141 }
142 }
143 elsif($ARGV[0] eq '--id') {
144 if($ARGV[1]) {
145 if($ARGV[1] =~ /^(\d+)$/) {
146 $idnum = $1 if($1 > 0);
147 shift @ARGV;
148 }
149 }
150 }
151 elsif($ARGV[0] eq '--ipv4') {
152 $ipvnum = 4;
153 }
154 elsif($ARGV[0] eq '--ipv6') {
155 $ipvnum = 6;
156 }
157 elsif($ARGV[0] eq '--pidfile') {
158 if($ARGV[1]) {
159 $pidfile = "$path/" . $ARGV[1];
160 shift @ARGV;
161 }
162 }
163 elsif($ARGV[0] eq '--logfile') {
164 if($ARGV[1]) {
165 $logfile = "$path/" . $ARGV[1];
166 shift @ARGV;
167 }
168 }
169 elsif($ARGV[0] eq '--logdir') {
170 if($ARGV[1]) {
171 $logdir = "$path/" . $ARGV[1];
172 shift @ARGV;
173 }
174 }
175 elsif($ARGV[0] eq '--mtls') {
176 $mtls = 1;
177 }
178 else {
179 print STDERR "\nWarning: secureserver.pl unknown parameter: '$ARGV[0]'\n";
180 }
181 shift @ARGV;
182}
184#***************************************************************************
185# Initialize command line option dependent variables
186#
187if($pidfile) {
188 # Use our pidfile directory to store the conf files
189 $piddir = dirname($pidfile);
190}
191else {
192 # Use the current directory to store the conf files
193 $piddir = $path;
194 $pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
195}
196if(!$logfile) {
197 $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
198}
200$conffile = "$piddir/${proto}_stunnel.conf";
202$cafile = abs_path("$path/certs/test-ca.cacert");
203$certfile = $stuncert ? "certs/$stuncert" : "certs/test-localhost.pem";
204$certfile = abs_path($certfile);
206my $ssltext = uc($proto) . " SSL/TLS:";
208my $host_ip = ($ipvnum == 6) ? '::1' : '127.0.0.1';
210#***************************************************************************
211# Find out version info for the given stunnel binary
212#
213foreach my $veropt (('-version', '-V')) {
214 foreach my $verstr (qx($stunnel $veropt 2>&1)) {
215 if($verstr =~ /^stunnel (\d+)\.(\d+) on /) {
216 $ver_major = $1;
217 $ver_minor = $2;
218 }
219 elsif($verstr =~ /^sslVersion.*fips *= *yes/) {
220 # the fips option causes an error if stunnel does not support it
221 $fips_support = 1;
222 last
223 }
224 }
225 last if($ver_major);
226}
227if((!$ver_major) || !defined($ver_minor)) {
228 if(-x $stunnel && ! -d $stunnel) {
229 print "$ssltext Unknown stunnel version\n";
230 }
231 else {
232 print "$ssltext No stunnel\n";
233 }
234 exit 1;
235}
236$stunnel_version = (100 * $ver_major) + $ver_minor;
238#***************************************************************************
239# Verify minimum stunnel required version
240#
241if($stunnel_version < 310) {
242 print "$ssltext Unsupported stunnel version $ver_major.$ver_minor\n";
243 exit 1;
244}
246#***************************************************************************
247# Find out if we are running on Windows using the tstunnel binary
248#
249if($stunnel =~ /tstunnel(\.exe)?$/) {
250 $tstunnel_windows = 1;
252 # convert Cygwin/MinGW paths to Windows format
253 $cafile = pathhelp::sys_native_abs_path($cafile);
254 $certfile = pathhelp::sys_native_abs_path($certfile);
255}
257#***************************************************************************
258# Build command to execute for stunnel 3.X versions
259#
260if($stunnel_version < 400) {
261 if($stunnel_version >= 319) {
262 $socketopt = "-O a:SO_REUSEADDR=1";
263 }
264 # TODO: we do not use $host_ip in this old version. I find
265 # no documentation how to. But maybe IPv6 is not available anyway?
266 $cmd = "\"$stunnel\" -p $certfile -P $pidfile ";
267 $cmd .= "-d $accept_port -r $target_port -f -D $loglevel ";
268 $cmd .= ($socketopt) ? "$socketopt " : "";
269 $cmd .= ">$logfile 2>&1";
270 if($verbose) {
271 print uc($proto) . " server (stunnel $ver_major.$ver_minor)\n";
272 print "cmd: $cmd\n";
273 print "pem cert file: $certfile\n";
274 print "pid file: $pidfile\n";
275 print "log file: $logfile\n";
276 print "log level: $loglevel\n";
277 print "listen on port: $accept_port\n";
278 print "connect to port: $target_port\n";
279 }
280}
282#***************************************************************************
283# Build command to execute for stunnel 4.00 and newer
284#
285if($stunnel_version >= 400) {
286 $socketopt = "a:SO_REUSEADDR=1";
287 my $conffile_cmdline;
288 if($tstunnel_windows) {
289 if($stunnel_version >= 534) {
290 # SO_EXCLUSIVEADDRUSE is on by default on Vista or newer,
291 # but does not work together with SO_REUSEADDR being on.
292 $socketopt .= "\nsocket = a:SO_EXCLUSIVEADDRUSE=0";
293 }
294 $conffile_cmdline = pathhelp::sys_native_abs_path($conffile);
295 }
296 else {
297 $conffile_cmdline = $conffile;
298 }
299 $cmd = "\"$stunnel\" $conffile_cmdline ";
300 $cmd .= ">$logfile 2>&1";
301 # setup signal handler
302 $SIG{INT} = \&exit_signal_handler;
303 $SIG{TERM} = \&exit_signal_handler;
304 # stunnel configuration file
305 if(open(my $stunconf, ">", $conffile)) {
306 print $stunconf "cert = $certfile\n";
307 print $stunconf "debug = $loglevel\n";
308 print $stunconf "socket = $socketopt\n";
309 if($mtls) {
310 print $stunconf "CAfile = $cafile\n";
311 print $stunconf "verifyChain = yes\n";
312 }
313 if($fips_support) {
314 # disable fips in case OpenSSL does not support it
315 print $stunconf "fips = no\n";
316 }
317 if(!$tstunnel_windows) {
318 # do not use Linux-specific options on Windows
319 print $stunconf "output = $logfile\n";
320 print $stunconf "pid = $pidfile\n";
321 print $stunconf "foreground = yes\n";
322 }
323 print $stunconf "\n";
324 print $stunconf "[curltest]\n";
325 print $stunconf "accept = $host_ip:$accept_port\n";
326 print $stunconf "connect = $host_ip:$target_port\n";
327 if(!close($stunconf)) {
328 print "$ssltext Error closing file $conffile\n";
329 exit 1;
330 }
331 }
332 else {
333 print "$ssltext Error writing file $conffile\n";
334 exit 1;
335 }
336 if($verbose) {
337 print uc($proto) . " server (stunnel $ver_major.$ver_minor)\n";
338 print "cmd: $cmd\n";
339 print "stunnel config at $conffile:\n";
340 open(my $writtenconf, '<', $conffile) or die "$ssltext could not open the config file after writing\n";
341 print <$writtenconf>;
342 print "\n";
343 close ($writtenconf);
344 }
345}
347#***************************************************************************
348# Set file permissions on certificate pem file.
349#
350chmod(0600, $certfile) if(-f $certfile);
351print STDERR "RUN: $cmd\n" if($verbose);
353#***************************************************************************
354# Run tstunnel on Windows.
355#
356if($tstunnel_windows) {
357 # Fake pidfile for tstunnel on Windows.
358 if(open(my $out, ">", $pidfile)) {
359 print $out $$ . "\n";
360 close($out);
361 }
363 # Flush output.
364 $| = 1;
366 # Put an "exec" in front of the command so that the child process
367 # keeps this child's process ID by being tied to the spawned shell.
368 exec("exec $cmd") or die "Cannot exec() $cmd: $!";
369 # exec() creates a new process, but ties the existence of the
370 # new process to the parent waiting perl.exe and sh.exe processes.
372 # exec() should never return back here to this process. We protect
373 # ourselves by calling die() in case something goes really bad.
374 die "error: exec() has returned";
375}
377#***************************************************************************
378# Run stunnel.
379#
380my $rc = system($cmd);
382$rc >>= 8;
384unlink($conffile) if($conffile && -f $conffile);
386exit $rc;
Diagnostics4 git calls · 448 ms
CallStatusSizeTime0448 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=442 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 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.7 KiB442 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3765 git.response.cache=MISS git.response.duration_ms=442 git.fetch.wants=17fc1487cdd875ec1ea77254c53501b678b896c2 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=3765 git.pkt.payload.max=3744 git.sideband.band1.bytes=3743 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
- a5e2c84bfcc94b67
- Request
- 9e7ec761…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format