Artifactspublic-v0

curl

master
ply4 git calls391 ms297 KiB2 cachedprotocol v2
1225 lines45 KiBexecutableRaw
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
22# SPDX-License-Identifier: curl
24#***************************************************************************
26# Starts sshd for use in the SCP and SFTP curl test harness tests.
27# Also creates the ssh configuration files needed for these tests.
29use strict;
30use warnings;
31use Cwd;
32use Cwd 'abs_path';
33use Digest::MD5;
34use Digest::MD5 'md5_hex';
35use Digest::SHA;
36use Digest::SHA 'sha256_base64';
37use MIME::Base64;
38use File::Basename;
40#***************************************************************************
41# Variables and subs imported from sshhelp module
43use sshhelp qw(
44 $sshdexe
45 $sshexe
46 $sftpsrvexe
47 $sftpexe
48 $sshkeygenexe
49 $sshdconfig
50 $sshconfig
51 $sftpconfig
52 $knownhosts
53 $sshdlog
54 $sshlog
55 $sftplog
56 $sftpcmds
57 $hstprvkeyf
58 $hstpubkeyf
59 $hstpubmd5f
60 $hstpubsha256f
61 $cliprvkeyf
62 $clipubkeyf
63 display_file_top
64 display_sshdconfig
65 display_sshconfig
66 display_sftpconfig
67 display_sshdlog
68 display_sshlog
69 display_sftplog
70 dump_array
71 find_sshd
72 find_ssh
73 find_sftpsrv
74 find_sftp
75 find_sshkeygen
76 sshversioninfo
77 );
79#***************************************************************************
80# Subs imported from serverhelp module
82use serverhelp qw(
83 $logfile
84 server_pidfilename
85 server_logfilename
86 );
88use pathhelp;
90#***************************************************************************
92my $verbose = 0; # set to 1 for debugging
93my $debugprotocol = 0; # set to 1 for protocol debugging
94my $port = 8999; # our default SCP/SFTP server port
95my $listenaddr = '127.0.0.1'; # default address on which to listen
96my $ipvnum = 4; # default IP version of listener address
97my $idnum = 1; # default ssh daemon instance number
98my $proto = 'ssh'; # protocol the ssh daemon speaks
99my $keyalgo = 'rsa'; # key algorithm
100my $path = getcwd(); # current working directory
101my $logdir = $path . '/log'; # directory for log files
102my $piddir; # directory for server config files
103my $username = $ENV{USER}; # default user
104my $pidfile; # ssh daemon pid file
105my $identity = 'curl_client_key'; # default identity file
107my $error;
108my @cfgarr;
110#***************************************************************************
111# Returns a path of the given filename in the log directory (PiddirPath)
113sub pp {
114 my $file = $_[0];
115 return "$piddir/$file";
116 # TODO: do Windows path conversion here
119#***************************************************************************
120# Save the message to the log and print it
121sub logmsg {
122 my $msg = $_[0];
123 serverhelp::logmsg $msg;
124 print $msg;
127#***************************************************************************
128# Parse command line options
130while(@ARGV) {
131 if($ARGV[0] eq '--verbose') {
132 $verbose = 1;
133 }
134 elsif($ARGV[0] eq '--debugprotocol') {
135 $verbose = 1;
136 $debugprotocol = 1;
137 }
138 elsif($ARGV[0] eq '--user') {
139 if($ARGV[1]) {
140 $username = $ARGV[1];
141 shift @ARGV;
142 }
143 }
144 elsif($ARGV[0] eq '--id') {
145 if($ARGV[1]) {
146 if($ARGV[1] =~ /^(\d+)$/) {
147 $idnum = $1 if($1 > 0);
148 shift @ARGV;
149 }
150 }
151 }
152 elsif($ARGV[0] eq '--ipv4') {
153 $ipvnum = 4;
154 $listenaddr = '127.0.0.1' if($listenaddr eq '::1');
155 }
156 elsif($ARGV[0] eq '--ipv6') {
157 $ipvnum = 6;
158 $listenaddr = '::1' if($listenaddr eq '127.0.0.1');
159 }
160 elsif($ARGV[0] eq '--addr') {
161 if($ARGV[1]) {
162 my $tmpstr = $ARGV[1];
163 if($tmpstr =~ /^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)$/) {
164 $listenaddr = "$1.$2.$3.$4" if($ipvnum == 4);
165 shift @ARGV;
166 }
167 elsif($ipvnum == 6) {
168 $listenaddr = $tmpstr;
169 $listenaddr =~ s/^\[(.*)\]$/$1/;
170 shift @ARGV;
171 }
172 }
173 }
174 elsif($ARGV[0] eq '--pidfile') {
175 if($ARGV[1]) {
176 $pidfile = "$path/" . $ARGV[1];
177 shift @ARGV;
178 }
179 }
180 elsif($ARGV[0] eq '--logdir') {
181 if($ARGV[1]) {
182 $logdir = "$path/" . $ARGV[1];
183 shift @ARGV;
184 }
185 }
186 elsif($ARGV[0] eq '--sshport') {
187 if($ARGV[1]) {
188 if($ARGV[1] =~ /^(\d+)$/) {
189 $port = $1;
190 shift @ARGV;
191 }
192 }
193 }
194 elsif($ARGV[0] eq '--keyalgo') {
195 if($ARGV[1]) {
196 $keyalgo = $ARGV[1];
197 shift @ARGV;
198 }
199 }
200 else {
201 print STDERR "\nWarning: sshserver.pl unknown parameter: '$ARGV[0]'\n";
202 }
203 shift @ARGV;
206#***************************************************************************
207# Initialize command line option dependent variables
210#***************************************************************************
211# Default ssh daemon pid filename & directory
213if($pidfile) {
214 # Use our pidfile directory to store server config files
215 $piddir = dirname($pidfile);
217else {
218 # Use the current directory to store server config files
219 $piddir = $path;
220 $pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
223#***************************************************************************
224# ssh and sftp server log filenames
226$sshdlog = server_logfilename($logdir, 'ssh', $ipvnum, $idnum);
227$sftplog = server_logfilename($logdir, 'sftp', $ipvnum, $idnum);
228$logfile = "$logdir/sshserver.log"; # used by logmsg
230#***************************************************************************
231# Logging level for ssh server and client
233my $loglevel = $debugprotocol ? 'DEBUG3' : 'DEBUG2';
235#***************************************************************************
236# Validate username
238if(!$username) {
239 $error = 'Will not run ssh server without a username';
241elsif($username eq 'root') {
242 $error = 'Will not run ssh server as root to mitigate security risks';
244if($error) {
245 logmsg "$error\n";
246 exit 1;
249#***************************************************************************
250# Find out ssh daemon canonical filename
252my $sshd = find_sshd();
253if(!$sshd) {
254 logmsg "cannot find $sshdexe\n";
255 exit 1;
258#***************************************************************************
259# Find out ssh daemon version info
261my ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
262if(!$sshdid) {
263 # Not an OpenSSH or SunSSH ssh daemon
264 logmsg "$sshderror\n" if($verbose);
265 logmsg "SCP and SFTP tests require OpenSSH 2.9.9 or later\n";
266 exit 1;
268logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);
270#***************************************************************************
271# ssh daemon command line options we might use and version support
273# -e: log stderr : OpenSSH 2.9.0 and later
274# -f: sshd config file : OpenSSH 1.2.1 and later
275# -D: no daemon forking : OpenSSH 2.5.0 and later
276# -o: command-line option : OpenSSH 3.1.0 and later
277# -t: test config file : OpenSSH 2.9.9 and later
278# -?: sshd version info : OpenSSH 1.2.1 and later
280# -e: log stderr : SunSSH 1.0.0 and later
281# -f: sshd config file : SunSSH 1.0.0 and later
282# -D: no daemon forking : SunSSH 1.0.0 and later
283# -o: command-line option : SunSSH 1.0.0 and later
284# -t: test config file : SunSSH 1.0.0 and later
285# -?: sshd version info : SunSSH 1.0.0 and later
287#***************************************************************************
288# Verify minimum ssh daemon version
290if((($sshdid =~ /OpenSSH/) && ($sshdvernum < 299)) ||
291 (($sshdid =~ /SunSSH/) && ($sshdvernum < 100))) {
292 logmsg "SCP and SFTP tests require OpenSSH 2.9.9 or later\n";
293 exit 1;
296#***************************************************************************
297# Find out sftp server plugin canonical filename
299my $sftpsrv = find_sftpsrv();
300if(!$sftpsrv) {
301 logmsg "cannot find $sftpsrvexe\n";
302 exit 1;
304logmsg "sftp server plugin found $sftpsrv\n" if($verbose);
306#***************************************************************************
307# Find out sftp client canonical filename
309my $sftp = find_sftp();
310if(!$sftp) {
311 logmsg "cannot find $sftpexe\n";
312 exit 1;
314logmsg "sftp client found $sftp\n" if($verbose);
316#***************************************************************************
317# Find out ssh keygen canonical filename
319my $sshkeygen = find_sshkeygen();
320if(!$sshkeygen) {
321 logmsg "cannot find $sshkeygenexe\n";
322 exit 1;
324logmsg "ssh keygen found $sshkeygen\n" if($verbose);
326#***************************************************************************
327# Find out ssh client canonical filename
329my $ssh = find_ssh();
330if(!$ssh) {
331 logmsg "cannot find $sshexe\n";
332 exit 1;
335#***************************************************************************
336# Find out ssh client version info
338my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
339if(!$sshid) {
340 # Not an OpenSSH or SunSSH ssh client
341 logmsg "$ssherror\n" if($verbose);
342 logmsg "SCP and SFTP tests require OpenSSH 2.9.9 or later\n";
343 exit 1;
345logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);
347#***************************************************************************
348# ssh client command line options we might use and version support
350# -D: dynamic app port forwarding : OpenSSH 2.9.9 and later
351# -F: ssh config file : OpenSSH 2.9.9 and later
352# -N: no shell/command : OpenSSH 2.1.0 and later
353# -p: connection port : OpenSSH 1.2.1 and later
354# -v: verbose messages : OpenSSH 1.2.1 and later
355# -vv: increase verbosity : OpenSSH 2.3.0 and later
356# -V: ssh version info : OpenSSH 1.2.1 and later
358# -D: dynamic app port forwarding : SunSSH 1.0.0 and later
359# -F: ssh config file : SunSSH 1.0.0 and later
360# -N: no shell/command : SunSSH 1.0.0 and later
361# -p: connection port : SunSSH 1.0.0 and later
362# -v: verbose messages : SunSSH 1.0.0 and later
363# -vv: increase verbosity : SunSSH 1.0.0 and later
364# -V: ssh version info : SunSSH 1.0.0 and later
366#***************************************************************************
367# Verify minimum ssh client version
369if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
370 (($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
371 logmsg "SCP and SFTP tests require OpenSSH 2.9.9 or later\n";
372 exit 1;
375#***************************************************************************
376# ssh keygen command line options we actually use and version support
378# -C: identity comment : OpenSSH 1.2.1 and later
379# -f: key filename : OpenSSH 1.2.1 and later
380# -N: new passphrase : OpenSSH 1.2.1 and later
381# -q: quiet keygen : OpenSSH 1.2.1 and later
382# -t: key type : OpenSSH 2.5.0 and later
383# -m: key format : OpenSSH 5.6.0 and later
385# -C: identity comment : SunSSH 1.0.0 and later
386# -f: key filename : SunSSH 1.0.0 and later
387# -N: new passphrase : SunSSH 1.0.0 and later
388# -q: quiet keygen : SunSSH 1.0.0 and later
389# -t: key type : SunSSH 1.0.0 and later
391$sshdconfig = pp($sshdconfig);
392$sshconfig = pp($sshconfig);
393$sftpconfig = pp($sftpconfig);
395#***************************************************************************
396# Generate host and client key files for curl's tests
398if((! -e pp($hstprvkeyf)) || (! -s pp($hstprvkeyf)) ||
399 (! -e pp($hstpubkeyf)) || (! -s pp($hstpubkeyf)) ||
400 (! -e pp($hstpubmd5f)) || (! -s pp($hstpubmd5f)) ||
401 (! -e pp($hstpubsha256f)) || (! -s pp($hstpubsha256f)) ||
402 (! -e pp($cliprvkeyf)) || (! -s pp($cliprvkeyf)) ||
403 (! -e pp($clipubkeyf)) || (! -s pp($clipubkeyf))) {
404 # Make sure all files are gone so ssh-keygen does not complain
405 unlink(pp($hstprvkeyf), pp($hstpubkeyf), pp($hstpubmd5f),
406 pp($hstpubsha256f), pp($cliprvkeyf), pp($clipubkeyf));
408 my @sshkeygenopt;
409 if(($sshid =~ /OpenSSH/) && ($sshvernum >= 560) && ($keyalgo ne 'ed25519')) {
410 # Override the default key format. Necessary to force legacy PEM format
411 # for libssh2 crypto backends that do not understand the OpenSSH (RFC4716)
412 # format, e.g. WinCNG.
413 # Accepted values: RFC4716, PKCS8, PEM (see also 'man ssh-keygen')
414 # Default to the most compatible format for tests.
415 push @sshkeygenopt, '-m', $ENV{'CURL_TEST_SSH_KEY_FORMAT'} ? $ENV{'CURL_TEST_SSH_KEY_FORMAT'} : 'PEM';
416 }
417 logmsg "generating host keys...\n" if($verbose);
418 if(system($sshkeygen, ('-q', '-t', $keyalgo, '-f', pp($hstprvkeyf), '-C', 'curl test server', '-N', '', @sshkeygenopt))) {
419 logmsg "Could not generate host key\n";
420 exit 1;
421 }
422 display_file_top(pp($hstprvkeyf)) if($verbose);
423 logmsg "generating client keys...\n" if($verbose);
424 if(system($sshkeygen, ('-q', '-t', $keyalgo, '-f', pp($cliprvkeyf), '-C', 'curl test client', '-N', '', @sshkeygenopt))) {
425 logmsg "Could not generate client key\n";
426 exit 1;
427 }
428 display_file_top(pp($cliprvkeyf)) if($verbose);
429 # Make sure that permissions are restricted so openssh does not complain
430 chmod 0600, pp($hstprvkeyf);
431 chmod 0600, pp($cliprvkeyf);
432 if(($^O eq 'cygwin' || $^O eq 'msys') && -e "/bin/setfacl") {
433 # https://cygwin.com/cygwin-ug-net/setfacl.html
434 system('/bin/setfacl', ('--remove-all', pp($hstprvkeyf)));
435 }
436 elsif(pathhelp::os_is_win()) {
437 # https://ss64.com/nt/icacls.html
438 $ENV{'MSYS2_ARG_CONV_EXCL'} = '/reset';
439 system('icacls', (pathhelp::sys_native_abs_path(pp($hstprvkeyf)), '/reset'));
440 system('icacls', (pathhelp::sys_native_abs_path(pp($hstprvkeyf)), '/grant:r', "$username:(R)"));
441 system('icacls', (pathhelp::sys_native_abs_path(pp($hstprvkeyf)), '/inheritance:r'));
442 }
443 # Save md5 and sha256 hashes of public host key
444 open(my $rsakeyfile, "<", pp($hstpubkeyf));
445 my @rsahostkey = do { local $/ = ' '; <$rsakeyfile> };
446 close($rsakeyfile);
447 if(!$rsahostkey[1]) {
448 logmsg "Failed parsing base64 encoded SSH host key\n";
449 exit 1;
450 }
451 open(my $pubmd5file, ">", pp($hstpubmd5f));
452 print $pubmd5file md5_hex(decode_base64($rsahostkey[1]));
453 close($pubmd5file);
454 if((! -e pp($hstpubmd5f)) || (! -s pp($hstpubmd5f))) {
455 logmsg "Failed writing MD5 hash of SSH host key\n";
456 exit 1;
457 }
458 open(my $pubsha256file, ">", pp($hstpubsha256f));
459 print $pubsha256file sha256_base64(decode_base64($rsahostkey[1]));
460 close($pubsha256file);
461 if((! -e pp($hstpubsha256f)) || (! -s pp($hstpubsha256f))) {
462 logmsg "Failed writing SHA256 hash of SSH host key\n";
463 exit 1;
464 }
467#***************************************************************************
468# Convert paths for curl's tests running on Windows with Cygwin/MSYS OpenSSH
470my $clipubkeyf_config;
471my $hstprvkeyf_config;
472my $pidfile_config;
473my $sftpsrv_config;
474my $sshdconfig_abs;
475if($sshdid =~ /OpenSSH-Windows/) {
476 # Ensure to use native Windows paths with OpenSSH for Windows
477 $clipubkeyf_config = pathhelp::sys_native_abs_path(pp($clipubkeyf));
478 $hstprvkeyf_config = pathhelp::sys_native_abs_path(pp($hstprvkeyf));
479 $pidfile_config = pathhelp::sys_native_abs_path($pidfile);
480 $sftpsrv_config = pathhelp::sys_native_abs_path($sftpsrv);
481 $sshdconfig_abs = pathhelp::sys_native_abs_path($sshdconfig);
483elsif(pathhelp::os_is_win()) {
484 # Ensure to use MinGW/Cygwin paths
485 $clipubkeyf_config = pathhelp::build_sys_abs_path(pp($clipubkeyf));
486 $hstprvkeyf_config = pathhelp::build_sys_abs_path(pp($hstprvkeyf));
487 $pidfile_config = pathhelp::build_sys_abs_path($pidfile);
488 $sftpsrv_config = "internal-sftp";
489 $sshdconfig_abs = pathhelp::build_sys_abs_path($sshdconfig);
491else {
492 $clipubkeyf_config = abs_path(pp($clipubkeyf));
493 $hstprvkeyf_config = abs_path(pp($hstprvkeyf));
494 $pidfile_config = $pidfile;
495 $sftpsrv_config = $sftpsrv;
496 $sshdconfig_abs = abs_path($sshdconfig);
499#***************************************************************************
500# ssh daemon configuration file options we might use and version support
502# AFSTokenPassing : OpenSSH 1.2.1 and later [1]
503# AddressFamily : OpenSSH 4.0.0 and later
504# AllowTcpForwarding : OpenSSH 2.3.0 and later
505# AllowUsers : OpenSSH 1.2.1 and later
506# AuthorizedKeysFile : OpenSSH 2.9.9 and later
507# AuthorizedKeysFile2 : OpenSSH 2.9.9 till 5.9
508# Banner : OpenSSH 2.5.0 and later
509# ChallengeResponseAuthentication : OpenSSH 2.5.0 and later
510# Ciphers : OpenSSH 2.1.0 and later [3]
511# ClientAliveCountMax : OpenSSH 2.9.0 and later
512# ClientAliveInterval : OpenSSH 2.9.0 and later
513# Compression : OpenSSH 3.3.0 and later
514# DenyUsers : OpenSSH 1.2.1 and later
515# ForceCommand : OpenSSH 4.4.0 and later [3]
516# GatewayPorts : OpenSSH 2.1.0 and later
517# GSSAPIAuthentication : OpenSSH 3.7.0 and later [1]
518# GSSAPICleanupCredentials : OpenSSH 3.8.0 and later [1]
519# GSSAPIKeyExchange : SunSSH 1.0.0 and later [1]
520# GSSAPIStoreDelegatedCredentials : SunSSH 1.0.0 and later [1]
521# GSSCleanupCreds : SunSSH 1.0.0 and later [1]
522# GSSUseSessionCredCache : SunSSH 1.0.0 and later [1]
523# HostbasedAuthentication : OpenSSH 2.9.0 and later
524# HostbasedUsesNameFromPacketOnly : OpenSSH 2.9.0 and later
525# HostKey : OpenSSH 1.2.1 and later
526# IgnoreRhosts : OpenSSH 1.2.1 and later
527# IgnoreUserKnownHosts : OpenSSH 1.2.1 and later
528# KbdInteractiveAuthentication : OpenSSH 2.3.0 and later
529# KeepAlive : OpenSSH 1.2.1 and later
530# KerberosAuthentication : OpenSSH 1.2.1 and later [1]
531# KerberosGetAFSToken : OpenSSH 3.8.0 and later [1]
532# KerberosOrLocalPasswd : OpenSSH 1.2.1 and later [1]
533# KerberosTgtPassing : OpenSSH 1.2.1 and later [1]
534# KerberosTicketCleanup : OpenSSH 1.2.1 and later [1]
535# KexAlgorithms : OpenSSH 5.7.0 and later (7.0.0 for '+' support, 7.5.0 for '-' support)
536# KeyRegenerationInterval : OpenSSH 1.2.1 till 7.3
537# ListenAddress : OpenSSH 1.2.1 and later
538# LoginGraceTime : OpenSSH 1.2.1 and later
539# LogLevel : OpenSSH 1.2.1 and later
540# LookupClientHostnames : SunSSH 1.0.0 and later
541# MACs : OpenSSH 2.5.0 and later [3]
542# Match : OpenSSH 4.4.0 and later [3]
543# MaxAuthTries : OpenSSH 3.9.0 and later
544# MaxStartups : OpenSSH 2.2.0 and later
545# PAMAuthenticationViaKbdInt : OpenSSH 2.9.0 and later [2]
546# PasswordAuthentication : OpenSSH 1.2.1 and later
547# PermitEmptyPasswords : OpenSSH 1.2.1 and later
548# PermitOpen : OpenSSH 4.4.0 and later [3]
549# PermitRootLogin : OpenSSH 1.2.1 and later
550# PermitTunnel : OpenSSH 4.3.0 and later
551# PermitUserEnvironment : OpenSSH 3.5.0 and later
552# PerSourcePenalties : OpenSSH 9.8.0 and later
553# PidFile : OpenSSH 2.1.0 and later
554# Port : OpenSSH 1.2.1 and later
555# PrintLastLog : OpenSSH 2.9.0 and later
556# PrintMotd : OpenSSH 1.2.1 and later
557# Protocol : OpenSSH 2.1.0 and later
558# PubkeyAuthentication : OpenSSH 2.5.0 and later
559# RhostsAuthentication : OpenSSH 1.2.1 and later
560# RhostsRSAAuthentication : OpenSSH 1.2.1 till 7.3
561# RSAAuthentication : OpenSSH 1.2.1 till 7.3
562# ServerKeyBits : OpenSSH 1.2.1 till 7.3
563# SkeyAuthentication : OpenSSH 1.2.1 and later [1]
564# StrictModes : OpenSSH 1.2.1 and later
565# Subsystem : OpenSSH 2.2.0 and later
566# SyslogFacility : OpenSSH 1.2.1 and later
567# TCPKeepAlive : OpenSSH 3.8.0 and later
568# UseDNS : OpenSSH 3.7.0 and later
569# UseLogin : OpenSSH 1.2.1 till 7.3
570# UsePAM : OpenSSH 3.7.0 and later [1][2]
571# UsePrivilegeSeparation : OpenSSH 3.2.2 and later
572# VerifyReverseMapping : OpenSSH 3.1.0 and later
573# X11DisplayOffset : OpenSSH 1.2.1 and later [3]
574# X11Forwarding : OpenSSH 1.2.1 and later
575# X11UseLocalhost : OpenSSH 3.1.0 and later
576# XAuthLocation : OpenSSH 2.1.1 and later [3]
578# [1] Option only available if activated at compile time
579# [2] Option specific for portable versions
580# [3] Option not used in our ssh server config file
582#***************************************************************************
583# Initialize sshd config with options actually supported in OpenSSH 2.9.9
585logmsg "generating ssh server config file...\n" if($verbose);
586@cfgarr = ();
587push @cfgarr, '# This is a generated file. Do not edit.';
588push @cfgarr, "# $sshdverstr sshd configuration file for curl testing";
589push @cfgarr, '#';
591# AllowUsers and DenyUsers options should use lowercase on Windows
592# and do not support quotes around values for an unknown reason.
593if($sshdid =~ /OpenSSH-Windows/) {
594 my $username_lc = lc $username;
595 push @cfgarr, "AllowUsers " . ($username_lc =~ s/ /\?/gr); # replace space with '?'
596 if(exists $ENV{USERDOMAIN}) {
597 my $userdomain_lc = lc $ENV{USERDOMAIN};
598 $username_lc = "$userdomain_lc\\$username_lc";
599 push @cfgarr, "AllowUsers " . ($username_lc =~ s/ /\?/gr); # replace space with '?'
600 }
602else {
603 push @cfgarr, "AllowUsers $username";
606push @cfgarr, "AuthorizedKeysFile $clipubkeyf_config";
607if(!($sshdid =~ /OpenSSH/) || ($sshdvernum <= 590)) {
608 push @cfgarr, "AuthorizedKeysFile2 $clipubkeyf_config";
610push @cfgarr, "HostKey $hstprvkeyf_config";
611if($sshdid !~ /OpenSSH-Windows/) {
612 push @cfgarr, "PidFile $pidfile_config";
613 push @cfgarr, '#';
615if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 880) && ($keyalgo eq 'rsa')) {
616 push @cfgarr, 'HostKeyAlgorithms +ssh-rsa';
617 push @cfgarr, 'PubkeyAcceptedAlgorithms +ssh-rsa'; # named PubkeyAcceptedKeyTypes in OpenSSH <8.5
619push @cfgarr, '#';
620push @cfgarr, "Port $port";
621push @cfgarr, "ListenAddress $listenaddr";
622push @cfgarr, 'Protocol 2';
623push @cfgarr, '#';
624push @cfgarr, 'AllowTcpForwarding yes';
625push @cfgarr, 'Banner none';
626push @cfgarr, 'ChallengeResponseAuthentication no';
627push @cfgarr, 'ClientAliveCountMax 3';
628push @cfgarr, 'ClientAliveInterval 0';
629push @cfgarr, 'GatewayPorts no';
630push @cfgarr, 'HostbasedAuthentication no';
631push @cfgarr, 'HostbasedUsesNameFromPacketOnly no';
632push @cfgarr, 'IgnoreRhosts yes';
633push @cfgarr, 'IgnoreUserKnownHosts yes';
634if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 700) && $ENV{'CURL_TEST_SSH_ENABLE_KEX'}) {
635 push @cfgarr, 'KexAlgorithms +' . $ENV{'CURL_TEST_SSH_ENABLE_KEX'};
637if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 750) && $ENV{'CURL_TEST_SSH_DISABLE_KEX'}) {
638 push @cfgarr, 'KexAlgorithms -' . $ENV{'CURL_TEST_SSH_DISABLE_KEX'};
640push @cfgarr, 'LoginGraceTime 30';
641push @cfgarr, "LogLevel $loglevel";
642push @cfgarr, 'MaxStartups 5';
643push @cfgarr, 'PasswordAuthentication no';
644push @cfgarr, 'PermitEmptyPasswords no';
645push @cfgarr, 'PermitRootLogin no';
646if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 980)) {
647 push @cfgarr, 'PerSourcePenalties no';
649push @cfgarr, 'PrintLastLog no';
650push @cfgarr, 'PrintMotd no';
651push @cfgarr, 'PubkeyAuthentication yes';
652push @cfgarr, 'StrictModes no';
653push @cfgarr, "Subsystem sftp \"$sftpsrv_config\"";
654push @cfgarr, 'SyslogFacility AUTH';
655if(!($sshdid =~ /OpenSSH/) || ($sshdvernum <= 730)) {
656 push @cfgarr, 'KeyRegenerationInterval 0';
657 push @cfgarr, 'RhostsRSAAuthentication no';
658 push @cfgarr, 'RSAAuthentication no';
659 push @cfgarr, 'ServerKeyBits 768';
660 push @cfgarr, 'UseLogin no';
662push @cfgarr, 'X11Forwarding no';
663push @cfgarr, '#';
665#***************************************************************************
666# Write out initial sshd configuration file for curl's tests
668$error = dump_array($sshdconfig, @cfgarr);
669if($error) {
670 logmsg "$error\n";
671 exit 1;
674#***************************************************************************
675# Verifies at run time if sshd supports a given configuration file option
677sub sshd_supports_opt {
678 my ($option, $value) = @_;
679 my $err;
680 #
681 if((($sshdid =~ /OpenSSH/) && ($sshdvernum >= 310)) ||
682 ($sshdid =~ /SunSSH/)) {
683 # ssh daemon supports command line options -t -f and -o
684 $err = grep /((Unsupported)|(Bad configuration)|(Deprecated)) option.*$option/,
685 qx(\"$sshd\" -t -f $sshdconfig_abs -o \"$option=$value\" 2>&1);
686 return !$err;
687 }
688 if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 299)) {
689 # ssh daemon supports command line options -t and -f
690 $err = dump_array($sshdconfig, (@cfgarr, "$option $value"));
691 if($err) {
692 logmsg "$err\n";
693 return 0;
694 }
695 $err = grep /((Unsupported)|(Bad configuration)|(Deprecated)) option.*$option/,
696 qx(\"$sshd\" -t -f $sshdconfig_abs 2>&1);
697 unlink $sshdconfig;
698 return !$err;
699 }
700 return 0;
703#***************************************************************************
704# Kerberos Authentication support may have not been built into sshd
706if(sshd_supports_opt('KerberosAuthentication', 'no')) {
707 push @cfgarr, 'KerberosAuthentication no';
709if(sshd_supports_opt('KerberosGetAFSToken', 'no')) {
710 push @cfgarr, 'KerberosGetAFSToken no';
712if(sshd_supports_opt('KerberosOrLocalPasswd', 'no')) {
713 push @cfgarr, 'KerberosOrLocalPasswd no';
715if(sshd_supports_opt('KerberosTgtPassing', 'no')) {
716 push @cfgarr, 'KerberosTgtPassing no';
718if(sshd_supports_opt('KerberosTicketCleanup', 'yes')) {
719 push @cfgarr, 'KerberosTicketCleanup yes';
722#***************************************************************************
723# Andrew File System support may have not been built into sshd
725if(sshd_supports_opt('AFSTokenPassing', 'no')) {
726 push @cfgarr, 'AFSTokenPassing no';
729#***************************************************************************
730# S/Key authentication support may have not been built into sshd
732if(sshd_supports_opt('SkeyAuthentication', 'no')) {
733 push @cfgarr, 'SkeyAuthentication no';
736#***************************************************************************
737# GSSAPI Authentication support may have not been built into sshd
739my $sshd_builtwith_GSSAPI;
740if(sshd_supports_opt('GSSAPIAuthentication', 'no')) {
741 push @cfgarr, 'GSSAPIAuthentication no';
742 $sshd_builtwith_GSSAPI = 1;
744if(sshd_supports_opt('GSSAPICleanupCredentials', 'yes')) {
745 push @cfgarr, 'GSSAPICleanupCredentials yes';
747if(sshd_supports_opt('GSSAPIKeyExchange', 'no')) {
748 push @cfgarr, 'GSSAPIKeyExchange no';
750if(sshd_supports_opt('GSSAPIStoreDelegatedCredentials', 'no')) {
751 push @cfgarr, 'GSSAPIStoreDelegatedCredentials no';
753if(sshd_supports_opt('GSSCleanupCreds', 'yes')) {
754 push @cfgarr, 'GSSCleanupCreds yes';
756if(sshd_supports_opt('GSSUseSessionCredCache', 'no')) {
757 push @cfgarr, 'GSSUseSessionCredCache no';
759push @cfgarr, '#';
761#***************************************************************************
762# Options that might be supported or not in sshd OpenSSH 2.9.9 and later
764if(sshd_supports_opt('AddressFamily','any')) {
765 # Address family must be specified before ListenAddress
766 splice @cfgarr, 11, 0, 'AddressFamily any';
768if(sshd_supports_opt('Compression', 'no')) {
769 push @cfgarr, 'Compression no';
771if(sshd_supports_opt('KbdInteractiveAuthentication', 'no')) {
772 push @cfgarr, 'KbdInteractiveAuthentication no';
774if(sshd_supports_opt('KeepAlive', 'no')) {
775 push @cfgarr, 'KeepAlive no';
777if(sshd_supports_opt('LookupClientHostnames', 'no')) {
778 push @cfgarr, 'LookupClientHostnames no';
780if(sshd_supports_opt('MaxAuthTries','10')) {
781 push @cfgarr, 'MaxAuthTries 10';
783if(sshd_supports_opt('PAMAuthenticationViaKbdInt', 'no')) {
784 push @cfgarr, 'PAMAuthenticationViaKbdInt no';
786if(sshd_supports_opt('PermitTunnel', 'no')) {
787 push @cfgarr, 'PermitTunnel no';
789if(sshd_supports_opt('PermitUserEnvironment', 'no')) {
790 push @cfgarr, 'PermitUserEnvironment no';
792if(sshd_supports_opt('RhostsAuthentication', 'no')) {
793 push @cfgarr, 'RhostsAuthentication no';
795if(sshd_supports_opt('TCPKeepAlive', 'no')) {
796 push @cfgarr, 'TCPKeepAlive no';
798if(sshd_supports_opt('UseDNS', 'no')) {
799 push @cfgarr, 'UseDNS no';
801if(sshd_supports_opt('UsePAM', 'no')) {
802 push @cfgarr, 'UsePAM no';
805if($sshdid =~ /OpenSSH/) {
806 # http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6492415
807 if(sshd_supports_opt('UsePrivilegeSeparation', 'no')) {
808 push @cfgarr, 'UsePrivilegeSeparation no';
809 }
812if(sshd_supports_opt('VerifyReverseMapping', 'no')) {
813 push @cfgarr, 'VerifyReverseMapping no';
815if(sshd_supports_opt('X11UseLocalhost', 'yes')) {
816 push @cfgarr, 'X11UseLocalhost yes';
818push @cfgarr, '#';
820#***************************************************************************
821# Write out resulting sshd configuration file for curl's tests
823$error = dump_array($sshdconfig, @cfgarr);
824if($error) {
825 logmsg "$error\n";
826 exit 1;
829#***************************************************************************
830# Verify that sshd actually supports our generated configuration file
832if(system("\"$sshd\" -t -f $sshdconfig_abs > $sshdlog 2>&1")) {
833 logmsg "sshd configuration file $sshdconfig failed verification\n";
834 display_sshdlog();
835 display_sshdconfig();
836 exit 1;
839#***************************************************************************
840# Generate ssh client host key database file for curl's tests
842if((! -e pp($knownhosts)) || (! -s pp($knownhosts))) {
843 logmsg "generating ssh client known hosts file...\n" if($verbose);
844 unlink(pp($knownhosts));
845 if(open(my $keyfile, "<", pp($hstpubkeyf))) {
846 chomp(my $line = <$keyfile>);
847 if(close($keyfile)) {
848 if(open(my $knownhostsh, ">", pp($knownhosts))) {
849 my @hostkey = split /\s+/, $line;
850 print $knownhostsh "$listenaddr $hostkey[0] $hostkey[1]\n";
851 if(!close($knownhostsh)) {
852 $error = "Error: cannot close file $knownhosts";
853 }
854 }
855 else {
856 $error = "Error: cannot write file $knownhosts";
857 }
858 }
859 else {
860 $error = "Error: cannot close file $hstpubkeyf";
861 }
862 }
863 else {
864 $error = "Error: cannot read file $hstpubkeyf";
865 }
866 if($error) {
867 logmsg "$error\n";
868 exit 1;
869 }
872#***************************************************************************
873# Convert paths for curl's tests running on Windows using Cygwin OpenSSH
875my $identity_config;
876my $knownhosts_config;
877if($sshdid =~ /OpenSSH-Windows/) {
878 # Ensure to use native Windows paths with OpenSSH for Windows
879 $identity_config = pathhelp::sys_native_abs_path(pp($identity));
880 $knownhosts_config = pathhelp::sys_native_abs_path(pp($knownhosts));
882elsif(pathhelp::os_is_win()) {
883 # Ensure to use MinGW/Cygwin paths
884 $identity_config = pathhelp::build_sys_abs_path(pp($identity));
885 $knownhosts_config = pathhelp::build_sys_abs_path(pp($knownhosts));
887else {
888 $identity_config = abs_path(pp($identity));
889 $knownhosts_config = abs_path(pp($knownhosts));
892#***************************************************************************
893# ssh client configuration file options we might use and version support
895# AddressFamily : OpenSSH 3.7.0 and later
896# BatchMode : OpenSSH 1.2.1 and later
897# BindAddress : OpenSSH 2.9.9 and later
898# ChallengeResponseAuthentication : OpenSSH 2.5.0 and later
899# CheckHostIP : OpenSSH 1.2.1 and later
900# Cipher : OpenSSH 1.2.1 and later [3]
901# Ciphers : OpenSSH 2.1.0 and later [3]
902# ClearAllForwardings : OpenSSH 2.9.9 and later
903# Compression : OpenSSH 1.2.1 and later
904# CompressionLevel : OpenSSH 1.2.1 and later [3]
905# ConnectionAttempts : OpenSSH 1.2.1 and later
906# ConnectTimeout : OpenSSH 3.7.0 and later
907# ControlMaster : OpenSSH 3.9.0 and later
908# ControlPath : OpenSSH 3.9.0 and later
909# DisableBanner : SunSSH 1.2.0 and later
910# DynamicForward : OpenSSH 2.9.0 and later
911# EnableSSHKeysign : OpenSSH 3.6.0 and later
912# EscapeChar : OpenSSH 1.2.1 and later [3]
913# ExitOnForwardFailure : OpenSSH 4.4.0 and later
914# ForwardAgent : OpenSSH 1.2.1 and later
915# ForwardX11 : OpenSSH 1.2.1 and later
916# ForwardX11Trusted : OpenSSH 3.8.0 and later
917# GatewayPorts : OpenSSH 1.2.1 and later
918# GlobalKnownHostsFile : OpenSSH 1.2.1 and later
919# GSSAPIAuthentication : OpenSSH 3.7.0 and later [1]
920# GSSAPIDelegateCredentials : OpenSSH 3.7.0 and later [1]
921# HashKnownHosts : OpenSSH 4.0.0 and later
922# Host : OpenSSH 1.2.1 and later
923# HostbasedAuthentication : OpenSSH 2.9.0 and later
924# HostKeyAlgorithms : OpenSSH 2.9.0 and later [3]
925# HostKeyAlias : OpenSSH 2.5.0 and later [3]
926# HostName : OpenSSH 1.2.1 and later
927# IdentitiesOnly : OpenSSH 3.9.0 and later
928# IdentityFile : OpenSSH 1.2.1 and later
929# IgnoreIfUnknown : SunSSH 1.2.0 and later
930# KeepAlive : OpenSSH 1.2.1 and later
931# KbdInteractiveAuthentication : OpenSSH 2.3.0 and later
932# KbdInteractiveDevices : OpenSSH 2.3.0 and later [3]
933# LocalCommand : OpenSSH 4.3.0 and later [3]
934# LocalForward : OpenSSH 1.2.1 and later [3]
935# LogLevel : OpenSSH 1.2.1 and later
936# MACs : OpenSSH 2.5.0 and later [3]
937# NoHostAuthenticationForLocalhost : OpenSSH 3.0.0 and later
938# NumberOfPasswordPrompts : OpenSSH 1.2.1 and later
939# PasswordAuthentication : OpenSSH 1.2.1 and later
940# PermitLocalCommand : OpenSSH 4.3.0 and later
941# Port : OpenSSH 1.2.1 and later
942# PreferredAuthentications : OpenSSH 2.5.2 and later
943# Protocol : OpenSSH 2.1.0 and later
944# ProxyCommand : OpenSSH 1.2.1 and later [3]
945# PubkeyAuthentication : OpenSSH 2.5.0 and later
946# RekeyLimit : OpenSSH 3.7.0 and later
947# RemoteForward : OpenSSH 1.2.1 and later [3]
948# RhostsRSAAuthentication : OpenSSH 1.2.1 and later
949# RSAAuthentication : OpenSSH 1.2.1 and later
950# ServerAliveCountMax : OpenSSH 3.8.0 and later
951# ServerAliveInterval : OpenSSH 3.8.0 and later
952# SmartcardDevice : OpenSSH 2.9.9 and later [1][3]
953# StrictHostKeyChecking : OpenSSH 1.2.1 and later
954# TCPKeepAlive : OpenSSH 3.8.0 and later
955# Tunnel : OpenSSH 4.3.0 and later
956# TunnelDevice : OpenSSH 4.3.0 and later [3]
957# UsePAM : OpenSSH 3.7.0 and later [1][2][3]
958# UsePrivilegedPort : OpenSSH 1.2.1 and later
959# User : OpenSSH 1.2.1 and later
960# UserKnownHostsFile : OpenSSH 1.2.1 and later
961# VerifyHostKeyDNS : OpenSSH 3.8.0 and later
962# XAuthLocation : OpenSSH 2.1.1 and later [3]
964# [1] Option only available if activated at compile time
965# [2] Option specific for portable versions
966# [3] Option not used in our ssh client config file
968#***************************************************************************
969# Initialize ssh config with options actually supported in OpenSSH 2.9.9
971logmsg "generating ssh client config file...\n" if($verbose);
972@cfgarr = ();
973push @cfgarr, '# This is a generated file. Do not edit.';
974push @cfgarr, "# $sshverstr ssh client configuration file for curl testing";
975push @cfgarr, '#';
976push @cfgarr, 'Host *';
977push @cfgarr, '#';
978push @cfgarr, "Port $port";
979push @cfgarr, "HostName $listenaddr";
980push @cfgarr, "User $username";
981push @cfgarr, 'Protocol 2';
982push @cfgarr, '#';
984# BindAddress option is not supported by OpenSSH for Windows
985if(!($sshdid =~ /OpenSSH-Windows/)) {
986 push @cfgarr, "BindAddress $listenaddr";
989push @cfgarr, '#';
990push @cfgarr, "IdentityFile $identity_config";
991push @cfgarr, "UserKnownHostsFile $knownhosts_config";
992push @cfgarr, '#';
993push @cfgarr, 'BatchMode yes';
994push @cfgarr, 'ChallengeResponseAuthentication no';
995push @cfgarr, 'CheckHostIP no';
996push @cfgarr, 'ClearAllForwardings no';
997push @cfgarr, 'Compression no';
998push @cfgarr, 'ConnectionAttempts 3';
999push @cfgarr, 'ForwardAgent no';
1000push @cfgarr, 'ForwardX11 no';
1001push @cfgarr, 'GatewayPorts no';
1002push @cfgarr, 'GlobalKnownHostsFile /dev/null';
1003push @cfgarr, 'HostbasedAuthentication no';
1004push @cfgarr, 'KbdInteractiveAuthentication no';
1005push @cfgarr, "LogLevel $loglevel";
1006push @cfgarr, 'NumberOfPasswordPrompts 0';
1007push @cfgarr, 'PasswordAuthentication no';
1008push @cfgarr, 'PreferredAuthentications publickey';
1009push @cfgarr, 'PubkeyAuthentication yes';
1011# RSA authentication options are deprecated by newer OpenSSH
1012if(!($sshid =~ /OpenSSH/) || ($sshvernum <= 730)) {
1013 push @cfgarr, 'RhostsRSAAuthentication no';
1014 push @cfgarr, 'RSAAuthentication no';
1017# Disabled StrictHostKeyChecking since it makes the tests fail on my
1018# OpenSSH_6.0p1 on Debian Linux / Daniel
1019push @cfgarr, 'StrictHostKeyChecking no';
1020push @cfgarr, 'UsePrivilegedPort no';
1021push @cfgarr, '#';
1023#***************************************************************************
1024# Options supported in ssh client newer than OpenSSH 2.9.9
1027if(($sshid =~ /OpenSSH/) && ($sshvernum >= 370)) {
1028 push @cfgarr, 'AddressFamily any';
1031if((($sshid =~ /OpenSSH/) && ($sshvernum >= 370)) ||
1032 (($sshid =~ /SunSSH/) && ($sshvernum >= 120))) {
1033 push @cfgarr, 'ConnectTimeout 30';
1036if(($sshid =~ /OpenSSH/) && ($sshvernum >= 390)) {
1037 push @cfgarr, 'ControlMaster no';
1040if(($sshid =~ /OpenSSH/) && ($sshvernum >= 420)) {
1041 push @cfgarr, 'ControlPath none';
1044if(($sshid =~ /SunSSH/) && ($sshvernum >= 120)) {
1045 push @cfgarr, 'DisableBanner yes';
1048if(($sshid =~ /OpenSSH/) && ($sshvernum >= 360)) {
1049 push @cfgarr, 'EnableSSHKeysign no';
1052if(($sshid =~ /OpenSSH/) && ($sshvernum >= 440)) {
1053 push @cfgarr, 'ExitOnForwardFailure yes';
1056if((($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) ||
1057 (($sshid =~ /SunSSH/) && ($sshvernum >= 120))) {
1058 push @cfgarr, 'ForwardX11Trusted no';
1061if(($sshd_builtwith_GSSAPI) && ($sshdid eq $sshid) &&
1062 ($sshdvernum == $sshvernum)) {
1063 push @cfgarr, 'GSSAPIAuthentication no';
1064 push @cfgarr, 'GSSAPIDelegateCredentials no';
1065 if($sshid =~ /SunSSH/) {
1066 push @cfgarr, 'GSSAPIKeyExchange no';
1070if((($sshid =~ /OpenSSH/) && ($sshvernum >= 400)) ||
1071 (($sshid =~ /SunSSH/) && ($sshvernum >= 120))) {
1072 push @cfgarr, 'HashKnownHosts no';
1075if(($sshid =~ /OpenSSH/) && ($sshvernum >= 390)) {
1076 push @cfgarr, 'IdentitiesOnly yes';
1079if(($sshid =~ /SunSSH/) && ($sshvernum >= 120)) {
1080 push @cfgarr, 'IgnoreIfUnknown no';
1083if((($sshid =~ /OpenSSH/) && ($sshvernum < 380)) ||
1084 ($sshid =~ /SunSSH/)) {
1085 push @cfgarr, 'KeepAlive no';
1088if((($sshid =~ /OpenSSH/) && ($sshvernum >= 300)) ||
1089 ($sshid =~ /SunSSH/)) {
1090 push @cfgarr, 'NoHostAuthenticationForLocalhost no';
1093if(($sshid =~ /OpenSSH/) && ($sshvernum >= 430)) {
1094 push @cfgarr, 'PermitLocalCommand no';
1097if((($sshid =~ /OpenSSH/) && ($sshvernum >= 370)) ||
1098 (($sshid =~ /SunSSH/) && ($sshvernum >= 120))) {
1099 push @cfgarr, 'RekeyLimit 1G';
1102if((($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) ||
1103 (($sshid =~ /SunSSH/) && ($sshvernum >= 120))) {
1104 push @cfgarr, 'ServerAliveCountMax 3';
1105 push @cfgarr, 'ServerAliveInterval 0';
1108if(($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) {
1109 push @cfgarr, 'TCPKeepAlive no';
1112if(($sshid =~ /OpenSSH/) && ($sshvernum >= 430)) {
1113 push @cfgarr, 'Tunnel no';
1116if(($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) {
1117 push @cfgarr, 'VerifyHostKeyDNS no';
1120push @cfgarr, '#';
1122#***************************************************************************
1123# Write out resulting ssh client configuration file for curl's tests
1125$error = dump_array($sshconfig, @cfgarr);
1126if($error) {
1127 logmsg "$error\n";
1128 exit 1;
1131#***************************************************************************
1132# Initialize client sftp config with options actually supported.
1134logmsg "generating sftp client config file...\n" if($verbose);
1135splice @cfgarr, 1, 1, "# $sshverstr sftp client configuration file for curl testing";
1137for(my $i = scalar(@cfgarr) - 1; $i > 0; $i--) {
1138 if($cfgarr[$i] =~ /^DynamicForward/) {
1139 splice @cfgarr, $i, 1;
1140 next;
1142 if($cfgarr[$i] =~ /^ClearAllForwardings/) {
1143 splice @cfgarr, $i, 1, "ClearAllForwardings yes";
1144 next;
1148#***************************************************************************
1149# Write out resulting sftp client configuration file for curl's tests
1151$error = dump_array($sftpconfig, @cfgarr);
1152if($error) {
1153 logmsg "$error\n";
1154 exit 1;
1156@cfgarr = ();
1158#***************************************************************************
1159# Generate client sftp commands batch file for sftp server verification
1161logmsg "generating sftp client commands file...\n" if($verbose);
1162push @cfgarr, 'pwd';
1163push @cfgarr, 'quit';
1164$error = dump_array(pp($sftpcmds), @cfgarr);
1165if($error) {
1166 logmsg "$error\n";
1167 exit 1;
1169@cfgarr = ();
1171#***************************************************************************
1172# Prepare command line of ssh server daemon
1174my $cmd = "\"$sshd\" -e -D -f $sshdconfig_abs > $sshdlog 2>&1";
1175logmsg "SCP/SFTP server listening on port $port\n" if($verbose);
1176logmsg "RUN: $cmd\n" if($verbose);
1178#***************************************************************************
1179# Start the ssh server daemon on Windows without forking it
1181if($sshdid =~ /OpenSSH-Windows/) {
1182 # Fake pidfile for ssh server on Windows.
1183 if(open(my $out, ">", $pidfile)) {
1184 print $out $$ . "\n";
1185 close($out);
1188 # Flush output.
1189 $| = 1;
1191 # Put an "exec" in front of the command so that the child process
1192 # keeps this child's process ID by being tied to the spawned shell.
1193 exec("exec $cmd") or die "Cannot exec() $cmd: $!";
1194 # exec() creates a new process, but ties the existence of the
1195 # new process to the parent waiting perl.exe and sh.exe processes.
1197 # exec() should never return back here to this process. We protect
1198 # ourselves by calling die() in case something goes really bad.
1199 die "error: exec() has returned";
1202#***************************************************************************
1203# Start the ssh server daemon without forking it
1205# "exec" avoids the shell process sticking around
1206my $rc = system("exec " . $cmd);
1207if($rc == -1) {
1208 logmsg "\"$sshd\" failed with: $!\n";
1210elsif($rc & 127) {
1211 logmsg sprintf("\"$sshd\" died with signal %d, and %s coredump\n",
1212 ($rc & 127), ($rc & 128) ? 'a' : 'no');
1214elsif($verbose && ($rc >> 8)) {
1215 logmsg sprintf("\"$sshd\" exited with %d\n", $rc >> 8);
1218#***************************************************************************
1219# Clean up once the server has stopped
1221unlink(pp($hstprvkeyf), pp($hstpubkeyf), pp($hstpubmd5f), pp($hstpubsha256f),
1222 pp($cliprvkeyf), pp($clipubkeyf), pp($knownhosts),
1223 $sshdconfig, $sshconfig, $sftpconfig);
1225exit 0;
Diagnostics4 git calls · 391 ms
CallStatusSizeTime0391 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 · hit7 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=4
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=2
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=86
Open pack map
fetch20010 KiB381 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=380
git.response.bytes=10394
git.response.cache=MISS
git.response.duration_ms=381
git.fetch.wants=facd7573dbfa559cee0983189f0b55fa838cecf5
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=10394
git.pkt.payload.max=10373
git.sideband.band1.bytes=10372
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
a5ea3eca8d10fc85
Request
bcd3f403…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format