| 1 |
#!/usr/bin/env perl |
| 2 |
#*************************************************************************** |
| 3 |
# _ _ ____ _ |
| 4 |
# Project ___| | | | _ \| | |
| 5 |
# / __| | | | |_) | | |
| 6 |
# | (__| |_| | _ <| |___ |
| 7 |
# \___|\___/|_| \_\_____| |
| 8 |
# |
| 9 |
# Copyright (C) 1998 - 2019, Daniel Stenberg, <[email protected]>, 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.haxx.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 |
#*************************************************************************** |
| 23 |
|
| 24 |
# Starts sshd for use in the SCP and SFTP curl test harness tests. |
| 25 |
# Also creates the ssh configuration files needed for these tests. |
| 26 |
|
| 27 |
use strict; |
| 28 |
use warnings; |
| 29 |
use Cwd; |
| 30 |
use Cwd 'abs_path'; |
| 31 |
|
| 32 |
#*************************************************************************** |
| 33 |
# Variables and subs imported from sshhelp module |
| 34 |
# |
| 35 |
use sshhelp qw( |
| 36 |
$sshdexe |
| 37 |
$sshexe |
| 38 |
$sftpsrvexe |
| 39 |
$sftpexe |
| 40 |
$sshkeygenexe |
| 41 |
$sshdconfig |
| 42 |
$sshconfig |
| 43 |
$sftpconfig |
| 44 |
$knownhosts |
| 45 |
$sshdlog |
| 46 |
$sshlog |
| 47 |
$sftplog |
| 48 |
$sftpcmds |
| 49 |
$hstprvkeyf |
| 50 |
$hstpubkeyf |
| 51 |
$cliprvkeyf |
| 52 |
$clipubkeyf |
| 53 |
display_sshdconfig |
| 54 |
display_sshconfig |
| 55 |
display_sftpconfig |
| 56 |
display_sshdlog |
| 57 |
display_sshlog |
| 58 |
display_sftplog |
| 59 |
dump_array |
| 60 |
find_sshd |
| 61 |
find_ssh |
| 62 |
find_sftpsrv |
| 63 |
find_sftp |
| 64 |
find_sshkeygen |
| 65 |
logmsg |
| 66 |
sshversioninfo |
| 67 |
); |
| 68 |
|
| 69 |
#*************************************************************************** |
| 70 |
# Subs imported from serverhelp module |
| 71 |
# |
| 72 |
use serverhelp qw( |
| 73 |
server_pidfilename |
| 74 |
server_logfilename |
| 75 |
); |
| 76 |
|
| 77 |
use pathhelp; |
| 78 |
|
| 79 |
#*************************************************************************** |
| 80 |
|
| 81 |
my $verbose = 0; # set to 1 for debugging |
| 82 |
my $debugprotocol = 0; # set to 1 for protocol debugging |
| 83 |
my $port = 8999; # our default SCP/SFTP server port |
| 84 |
my $listenaddr = '127.0.0.1'; # default address on which to listen |
| 85 |
my $ipvnum = 4; # default IP version of listener address |
| 86 |
my $idnum = 1; # default ssh daemon instance number |
| 87 |
my $proto = 'ssh'; # protocol the ssh daemon speaks |
| 88 |
my $path = getcwd(); # current working directory |
| 89 |
my $logdir = $path .'/log'; # directory for log files |
| 90 |
my $username = $ENV{USER}; # default user |
| 91 |
my $pidfile; # ssh daemon pid file |
| 92 |
my $identity = 'curl_client_key'; # default identity file |
| 93 |
|
| 94 |
my $error; |
| 95 |
my @cfgarr; |
| 96 |
|
| 97 |
|
| 98 |
#*************************************************************************** |
| 99 |
# Parse command line options |
| 100 |
# |
| 101 |
while(@ARGV) { |
| 102 |
if($ARGV[0] eq '--verbose') { |
| 103 |
$verbose = 1; |
| 104 |
} |
| 105 |
elsif($ARGV[0] eq '--debugprotocol') { |
| 106 |
$verbose = 1; |
| 107 |
$debugprotocol = 1; |
| 108 |
} |
| 109 |
elsif($ARGV[0] eq '--user') { |
| 110 |
if($ARGV[1]) { |
| 111 |
$username = $ARGV[1]; |
| 112 |
shift @ARGV; |
| 113 |
} |
| 114 |
} |
| 115 |
elsif($ARGV[0] eq '--id') { |
| 116 |
if($ARGV[1]) { |
| 117 |
if($ARGV[1] =~ /^(\d+)$/) { |
| 118 |
$idnum = $1 if($1 > 0); |
| 119 |
shift @ARGV; |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
elsif($ARGV[0] eq '--ipv4') { |
| 124 |
$ipvnum = 4; |
| 125 |
$listenaddr = '127.0.0.1' if($listenaddr eq '::1'); |
| 126 |
} |
| 127 |
elsif($ARGV[0] eq '--ipv6') { |
| 128 |
$ipvnum = 6; |
| 129 |
$listenaddr = '::1' if($listenaddr eq '127.0.0.1'); |
| 130 |
} |
| 131 |
elsif($ARGV[0] eq '--addr') { |
| 132 |
if($ARGV[1]) { |
| 133 |
my $tmpstr = $ARGV[1]; |
| 134 |
if($tmpstr =~ /^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)$/) { |
| 135 |
$listenaddr = "$1.$2.$3.$4" if($ipvnum == 4); |
| 136 |
shift @ARGV; |
| 137 |
} |
| 138 |
elsif($ipvnum == 6) { |
| 139 |
$listenaddr = $tmpstr; |
| 140 |
$listenaddr =~ s/^\[(.*)\]$/$1/; |
| 141 |
shift @ARGV; |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
elsif($ARGV[0] eq '--pidfile') { |
| 146 |
if($ARGV[1]) { |
| 147 |
$pidfile = "$path/". $ARGV[1]; |
| 148 |
shift @ARGV; |
| 149 |
} |
| 150 |
} |
| 151 |
elsif($ARGV[0] eq '--sshport') { |
| 152 |
if($ARGV[1]) { |
| 153 |
if($ARGV[1] =~ /^(\d+)$/) { |
| 154 |
$port = $1; |
| 155 |
shift @ARGV; |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
else { |
| 160 |
print STDERR "\nWarning: sshserver.pl unknown parameter: $ARGV[0]\n"; |
| 161 |
} |
| 162 |
shift @ARGV; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
#*************************************************************************** |
| 167 |
# Default ssh daemon pid file name |
| 168 |
# |
| 169 |
if(!$pidfile) { |
| 170 |
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
#*************************************************************************** |
| 175 |
# ssh and sftp server log file names |
| 176 |
# |
| 177 |
$sshdlog = server_logfilename($logdir, 'ssh', $ipvnum, $idnum); |
| 178 |
$sftplog = server_logfilename($logdir, 'sftp', $ipvnum, $idnum); |
| 179 |
|
| 180 |
|
| 181 |
#*************************************************************************** |
| 182 |
# Logging level for ssh server and client |
| 183 |
# |
| 184 |
my $loglevel = $debugprotocol?'DEBUG3':'DEBUG2'; |
| 185 |
|
| 186 |
|
| 187 |
#*************************************************************************** |
| 188 |
# Validate username |
| 189 |
# |
| 190 |
if(!$username) { |
| 191 |
$error = 'Will not run ssh server without a user name'; |
| 192 |
} |
| 193 |
elsif($username eq 'root') { |
| 194 |
$error = 'Will not run ssh server as root to mitigate security risks'; |
| 195 |
} |
| 196 |
if($error) { |
| 197 |
logmsg $error; |
| 198 |
exit 1; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
#*************************************************************************** |
| 203 |
# Find out ssh daemon canonical file name |
| 204 |
# |
| 205 |
my $sshd = find_sshd(); |
| 206 |
if(!$sshd) { |
| 207 |
logmsg "cannot find $sshdexe"; |
| 208 |
exit 1; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
#*************************************************************************** |
| 213 |
# Find out ssh daemon version info |
| 214 |
# |
| 215 |
my ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd); |
| 216 |
if(!$sshdid) { |
| 217 |
# Not an OpenSSH or SunSSH ssh daemon |
| 218 |
logmsg $sshderror if($verbose); |
| 219 |
logmsg 'SCP and SFTP tests require OpenSSH 2.9.9 or later'; |
| 220 |
exit 1; |
| 221 |
} |
| 222 |
logmsg "ssh server found $sshd is $sshdverstr" if($verbose); |
| 223 |
|
| 224 |
|
| 225 |
#*************************************************************************** |
| 226 |
# ssh daemon command line options we might use and version support |
| 227 |
# |
| 228 |
# -e: log stderr : OpenSSH 2.9.0 and later |
| 229 |
# -f: sshd config file : OpenSSH 1.2.1 and later |
| 230 |
# -D: no daemon forking : OpenSSH 2.5.0 and later |
| 231 |
# -o: command-line option : OpenSSH 3.1.0 and later |
| 232 |
# -t: test config file : OpenSSH 2.9.9 and later |
| 233 |
# -?: sshd version info : OpenSSH 1.2.1 and later |
| 234 |
# |
| 235 |
# -e: log stderr : SunSSH 1.0.0 and later |
| 236 |
# -f: sshd config file : SunSSH 1.0.0 and later |
| 237 |
# -D: no daemon forking : SunSSH 1.0.0 and later |
| 238 |
# -o: command-line option : SunSSH 1.0.0 and later |
| 239 |
# -t: test config file : SunSSH 1.0.0 and later |
| 240 |
# -?: sshd version info : SunSSH 1.0.0 and later |
| 241 |
|
| 242 |
|
| 243 |
#*************************************************************************** |
| 244 |
# Verify minimum ssh daemon version |
| 245 |
# |
| 246 |
if((($sshdid =~ /OpenSSH/) && ($sshdvernum < 299)) || |
| 247 |
(($sshdid =~ /SunSSH/) && ($sshdvernum < 100))) { |
| 248 |
logmsg 'SCP and SFTP tests require OpenSSH 2.9.9 or later'; |
| 249 |
exit 1; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
#*************************************************************************** |
| 254 |
# Find out sftp server plugin canonical file name |
| 255 |
# |
| 256 |
my $sftpsrv = find_sftpsrv(); |
| 257 |
if(!$sftpsrv) { |
| 258 |
logmsg "cannot find $sftpsrvexe"; |
| 259 |
exit 1; |
| 260 |
} |
| 261 |
logmsg "sftp server plugin found $sftpsrv" if($verbose); |
| 262 |
|
| 263 |
|
| 264 |
#*************************************************************************** |
| 265 |
# Find out sftp client canonical file name |
| 266 |
# |
| 267 |
my $sftp = find_sftp(); |
| 268 |
if(!$sftp) { |
| 269 |
logmsg "cannot find $sftpexe"; |
| 270 |
exit 1; |
| 271 |
} |
| 272 |
logmsg "sftp client found $sftp" if($verbose); |
| 273 |
|
| 274 |
|
| 275 |
#*************************************************************************** |
| 276 |
# Find out ssh keygen canonical file name |
| 277 |
# |
| 278 |
my $sshkeygen = find_sshkeygen(); |
| 279 |
if(!$sshkeygen) { |
| 280 |
logmsg "cannot find $sshkeygenexe"; |
| 281 |
exit 1; |
| 282 |
} |
| 283 |
logmsg "ssh keygen found $sshkeygen" if($verbose); |
| 284 |
|
| 285 |
|
| 286 |
#*************************************************************************** |
| 287 |
# Find out ssh client canonical file name |
| 288 |
# |
| 289 |
my $ssh = find_ssh(); |
| 290 |
if(!$ssh) { |
| 291 |
logmsg "cannot find $sshexe"; |
| 292 |
exit 1; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
#*************************************************************************** |
| 297 |
# Find out ssh client version info |
| 298 |
# |
| 299 |
my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh); |
| 300 |
if(!$sshid) { |
| 301 |
# Not an OpenSSH or SunSSH ssh client |
| 302 |
logmsg $ssherror if($verbose); |
| 303 |
logmsg 'SCP and SFTP tests require OpenSSH 2.9.9 or later'; |
| 304 |
exit 1; |
| 305 |
} |
| 306 |
logmsg "ssh client found $ssh is $sshverstr" if($verbose); |
| 307 |
|
| 308 |
|
| 309 |
#*************************************************************************** |
| 310 |
# ssh client command line options we might use and version support |
| 311 |
# |
| 312 |
# -D: dynamic app port forwarding : OpenSSH 2.9.9 and later |
| 313 |
# -F: ssh config file : OpenSSH 2.9.9 and later |
| 314 |
# -N: no shell/command : OpenSSH 2.1.0 and later |
| 315 |
# -p: connection port : OpenSSH 1.2.1 and later |
| 316 |
# -v: verbose messages : OpenSSH 1.2.1 and later |
| 317 |
# -vv: increase verbosity : OpenSSH 2.3.0 and later |
| 318 |
# -V: ssh version info : OpenSSH 1.2.1 and later |
| 319 |
# |
| 320 |
# -D: dynamic app port forwarding : SunSSH 1.0.0 and later |
| 321 |
# -F: ssh config file : SunSSH 1.0.0 and later |
| 322 |
# -N: no shell/command : SunSSH 1.0.0 and later |
| 323 |
# -p: connection port : SunSSH 1.0.0 and later |
| 324 |
# -v: verbose messages : SunSSH 1.0.0 and later |
| 325 |
# -vv: increase verbosity : SunSSH 1.0.0 and later |
| 326 |
# -V: ssh version info : SunSSH 1.0.0 and later |
| 327 |
|
| 328 |
|
| 329 |
#*************************************************************************** |
| 330 |
# Verify minimum ssh client version |
| 331 |
# |
| 332 |
if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) || |
| 333 |
(($sshid =~ /SunSSH/) && ($sshvernum < 100))) { |
| 334 |
logmsg 'SCP and SFTP tests require OpenSSH 2.9.9 or later'; |
| 335 |
exit 1; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
#*************************************************************************** |
| 340 |
# ssh keygen command line options we actually use and version support |
| 341 |
# |
| 342 |
# -C: identity comment : OpenSSH 1.2.1 and later |
| 343 |
# -f: key filename : OpenSSH 1.2.1 and later |
| 344 |
# -N: new passphrase : OpenSSH 1.2.1 and later |
| 345 |
# -q: quiet keygen : OpenSSH 1.2.1 and later |
| 346 |
# -t: key type : OpenSSH 2.5.0 and later |
| 347 |
# |
| 348 |
# -C: identity comment : SunSSH 1.0.0 and later |
| 349 |
# -f: key filename : SunSSH 1.0.0 and later |
| 350 |
# -N: new passphrase : SunSSH 1.0.0 and later |
| 351 |
# -q: quiet keygen : SunSSH 1.0.0 and later |
| 352 |
# -t: key type : SunSSH 1.0.0 and later |
| 353 |
|
| 354 |
|
| 355 |
#*************************************************************************** |
| 356 |
# Generate host and client key files for curl's tests |
| 357 |
# |
| 358 |
if((! -e $hstprvkeyf) || (! -s $hstprvkeyf) || |
| 359 |
(! -e $hstpubkeyf) || (! -s $hstpubkeyf) || |
| 360 |
(! -e $cliprvkeyf) || (! -s $cliprvkeyf) || |
| 361 |
(! -e $clipubkeyf) || (! -s $clipubkeyf)) { |
| 362 |
# Make sure all files are gone so ssh-keygen doesn't complain |
| 363 |
unlink($hstprvkeyf, $hstpubkeyf, $cliprvkeyf, $clipubkeyf); |
| 364 |
logmsg 'generating host keys...' if($verbose); |
| 365 |
if(system "\"$sshkeygen\" -q -t rsa -f $hstprvkeyf -C 'curl test server' -N ''") { |
| 366 |
logmsg 'Could not generate host key'; |
| 367 |
exit 1; |
| 368 |
} |
| 369 |
logmsg 'generating client keys...' if($verbose); |
| 370 |
if(system "\"$sshkeygen\" -q -t rsa -f $cliprvkeyf -C 'curl test client' -N ''") { |
| 371 |
logmsg 'Could not generate client key'; |
| 372 |
exit 1; |
| 373 |
} |
| 374 |
# Make sure that permissions are restricted so openssh doesn't complain |
| 375 |
system "chmod 600 $hstprvkeyf"; |
| 376 |
system "chmod 600 $cliprvkeyf"; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
#*************************************************************************** |
| 381 |
# Convert paths for curl's tests running on Windows with Cygwin/Msys OpenSSH |
| 382 |
# |
| 383 |
my $clipubkeyf_config = abs_path("$path/$clipubkeyf"); |
| 384 |
my $hstprvkeyf_config = abs_path("$path/$hstprvkeyf"); |
| 385 |
my $pidfile_config = $pidfile; |
| 386 |
my $sftpsrv_config = $sftpsrv; |
| 387 |
|
| 388 |
if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') { |
| 389 |
# Ensure to use MinGW/Cygwin paths |
| 390 |
$clipubkeyf_config = pathhelp::build_sys_abs_path($clipubkeyf_config); |
| 391 |
$hstprvkeyf_config = pathhelp::build_sys_abs_path($hstprvkeyf_config); |
| 392 |
$pidfile_config = pathhelp::build_sys_abs_path($pidfile_config); |
| 393 |
$sftpsrv_config = "internal-sftp"; |
| 394 |
} |
| 395 |
if ($sshdid =~ /OpenSSH-Windows/) { |
| 396 |
# Ensure to use native Windows paths with OpenSSH for Windows |
| 397 |
$clipubkeyf_config = pathhelp::sys_native_abs_path($clipubkeyf); |
| 398 |
$hstprvkeyf_config = pathhelp::sys_native_abs_path($hstprvkeyf); |
| 399 |
$pidfile_config = pathhelp::sys_native_abs_path($pidfile); |
| 400 |
$sftpsrv_config = pathhelp::sys_native_abs_path($sftpsrv); |
| 401 |
|
| 402 |
$sshdconfig = pathhelp::sys_native_abs_path($sshdconfig); |
| 403 |
$sshconfig = pathhelp::sys_native_abs_path($sshconfig); |
| 404 |
$sftpconfig = pathhelp::sys_native_abs_path($sftpconfig); |
| 405 |
} |
| 406 |
|
| 407 |
#*************************************************************************** |
| 408 |
# ssh daemon configuration file options we might use and version support |
| 409 |
# |
| 410 |
# AFSTokenPassing : OpenSSH 1.2.1 and later [1] |
| 411 |
# AcceptEnv : OpenSSH 3.9.0 and later |
| 412 |
# AddressFamily : OpenSSH 4.0.0 and later |
| 413 |
# AllowGroups : OpenSSH 1.2.1 and later |
| 414 |
# AllowTcpForwarding : OpenSSH 2.3.0 and later |
| 415 |
# AllowUsers : OpenSSH 1.2.1 and later |
| 416 |
# AuthorizedKeysFile : OpenSSH 2.9.9 and later |
| 417 |
# AuthorizedKeysFile2 : OpenSSH 2.9.9 and later |
| 418 |
# Banner : OpenSSH 2.5.0 and later |
| 419 |
# ChallengeResponseAuthentication : OpenSSH 2.5.0 and later |
| 420 |
# Ciphers : OpenSSH 2.1.0 and later [3] |
| 421 |
# ClientAliveCountMax : OpenSSH 2.9.0 and later |
| 422 |
# ClientAliveInterval : OpenSSH 2.9.0 and later |
| 423 |
# Compression : OpenSSH 3.3.0 and later |
| 424 |
# DenyGroups : OpenSSH 1.2.1 and later |
| 425 |
# DenyUsers : OpenSSH 1.2.1 and later |
| 426 |
# ForceCommand : OpenSSH 4.4.0 and later [3] |
| 427 |
# GatewayPorts : OpenSSH 2.1.0 and later |
| 428 |
# GSSAPIAuthentication : OpenSSH 3.7.0 and later [1] |
| 429 |
# GSSAPICleanupCredentials : OpenSSH 3.8.0 and later [1] |
| 430 |
# GSSAPIKeyExchange : SunSSH 1.0.0 and later [1] |
| 431 |
# GSSAPIStoreDelegatedCredentials : SunSSH 1.0.0 and later [1] |
| 432 |
# GSSCleanupCreds : SunSSH 1.0.0 and later [1] |
| 433 |
# GSSUseSessionCredCache : SunSSH 1.0.0 and later [1] |
| 434 |
# HostbasedAuthentication : OpenSSH 2.9.0 and later |
| 435 |
# HostbasedUsesNameFromPacketOnly : OpenSSH 2.9.0 and later |
| 436 |
# HostKey : OpenSSH 1.2.1 and later |
| 437 |
# IgnoreRhosts : OpenSSH 1.2.1 and later |
| 438 |
# IgnoreUserKnownHosts : OpenSSH 1.2.1 and later |
| 439 |
# KbdInteractiveAuthentication : OpenSSH 2.3.0 and later |
| 440 |
# KeepAlive : OpenSSH 1.2.1 and later |
| 441 |
# KerberosAuthentication : OpenSSH 1.2.1 and later [1] |
| 442 |
# KerberosGetAFSToken : OpenSSH 3.8.0 and later [1] |
| 443 |
# KerberosOrLocalPasswd : OpenSSH 1.2.1 and later [1] |
| 444 |
# KerberosTgtPassing : OpenSSH 1.2.1 and later [1] |
| 445 |
# KerberosTicketCleanup : OpenSSH 1.2.1 and later [1] |
| 446 |
# KeyRegenerationInterval : OpenSSH 1.2.1 and later |
| 447 |
# ListenAddress : OpenSSH 1.2.1 and later |
| 448 |
# LoginGraceTime : OpenSSH 1.2.1 and later |
| 449 |
# LogLevel : OpenSSH 1.2.1 and later |
| 450 |
# LookupClientHostnames : SunSSH 1.0.0 and later |
| 451 |
# MACs : OpenSSH 2.5.0 and later [3] |
| 452 |
# Match : OpenSSH 4.4.0 and later [3] |
| 453 |
# MaxAuthTries : OpenSSH 3.9.0 and later |
| 454 |
# MaxStartups : OpenSSH 2.2.0 and later |
| 455 |
# PAMAuthenticationViaKbdInt : OpenSSH 2.9.0 and later [2] |
| 456 |
# PasswordAuthentication : OpenSSH 1.2.1 and later |
| 457 |
# PermitEmptyPasswords : OpenSSH 1.2.1 and later |
| 458 |
# PermitOpen : OpenSSH 4.4.0 and later [3] |
| 459 |
# PermitRootLogin : OpenSSH 1.2.1 and later |
| 460 |
# PermitTunnel : OpenSSH 4.3.0 and later |
| 461 |
# PermitUserEnvironment : OpenSSH 3.5.0 and later |
| 462 |
# PidFile : OpenSSH 2.1.0 and later |
| 463 |
# Port : OpenSSH 1.2.1 and later |
| 464 |
# PrintLastLog : OpenSSH 2.9.0 and later |
| 465 |
# PrintMotd : OpenSSH 1.2.1 and later |
| 466 |
# Protocol : OpenSSH 2.1.0 and later |
| 467 |
# PubkeyAuthentication : OpenSSH 2.5.0 and later |
| 468 |
# RhostsAuthentication : OpenSSH 1.2.1 and later |
| 469 |
# RhostsRSAAuthentication : OpenSSH 1.2.1 and later |
| 470 |
# RSAAuthentication : OpenSSH 1.2.1 and later |
| 471 |
# ServerKeyBits : OpenSSH 1.2.1 and later |
| 472 |
# SkeyAuthentication : OpenSSH 1.2.1 and later [1] |
| 473 |
# StrictModes : OpenSSH 1.2.1 and later |
| 474 |
# Subsystem : OpenSSH 2.2.0 and later |
| 475 |
# SyslogFacility : OpenSSH 1.2.1 and later |
| 476 |
# TCPKeepAlive : OpenSSH 3.8.0 and later |
| 477 |
# UseDNS : OpenSSH 3.7.0 and later |
| 478 |
# UseLogin : OpenSSH 1.2.1 and later |
| 479 |
# UsePAM : OpenSSH 3.7.0 and later [1][2] |
| 480 |
# UsePrivilegeSeparation : OpenSSH 3.2.2 and later |
| 481 |
# VerifyReverseMapping : OpenSSH 3.1.0 and later |
| 482 |
# X11DisplayOffset : OpenSSH 1.2.1 and later [3] |
| 483 |
# X11Forwarding : OpenSSH 1.2.1 and later |
| 484 |
# X11UseLocalhost : OpenSSH 3.1.0 and later |
| 485 |
# XAuthLocation : OpenSSH 2.1.1 and later [3] |
| 486 |
# |
| 487 |
# [1] Option only available if activated at compile time |
| 488 |
# [2] Option specific for portable versions |
| 489 |
# [3] Option not used in our ssh server config file |
| 490 |
|
| 491 |
|
| 492 |
#*************************************************************************** |
| 493 |
# Initialize sshd config with options actually supported in OpenSSH 2.9.9 |
| 494 |
# |
| 495 |
logmsg 'generating ssh server config file...' if($verbose); |
| 496 |
@cfgarr = (); |
| 497 |
push @cfgarr, '# This is a generated file. Do not edit.'; |
| 498 |
push @cfgarr, "# $sshdverstr sshd configuration file for curl testing"; |
| 499 |
push @cfgarr, '#'; |
| 500 |
|
| 501 |
# AllowUsers and DenyUsers options should use lowercase on Windows |
| 502 |
# and do not support quotes around values for some unknown reason. |
| 503 |
if ($sshdid =~ /OpenSSH-Windows/) { |
| 504 |
my $username_lc = lc $username; |
| 505 |
push @cfgarr, "DenyUsers !$username_lc"; |
| 506 |
push @cfgarr, "AllowUsers $username_lc"; |
| 507 |
} else { |
| 508 |
push @cfgarr, "DenyUsers !$username"; |
| 509 |
push @cfgarr, "AllowUsers $username"; |
| 510 |
} |
| 511 |
|
| 512 |
push @cfgarr, 'DenyGroups'; |
| 513 |
push @cfgarr, 'AllowGroups'; |
| 514 |
push @cfgarr, '#'; |
| 515 |
push @cfgarr, "AuthorizedKeysFile $clipubkeyf_config"; |
| 516 |
push @cfgarr, "AuthorizedKeysFile2 $clipubkeyf_config"; |
| 517 |
push @cfgarr, "HostKey $hstprvkeyf_config"; |
| 518 |
push @cfgarr, "PidFile $pidfile_config"; |
| 519 |
push @cfgarr, '#'; |
| 520 |
push @cfgarr, "Port $port"; |
| 521 |
push @cfgarr, "ListenAddress $listenaddr"; |
| 522 |
push @cfgarr, 'Protocol 2'; |
| 523 |
push @cfgarr, '#'; |
| 524 |
push @cfgarr, 'AllowTcpForwarding yes'; |
| 525 |
push @cfgarr, 'Banner none'; |
| 526 |
push @cfgarr, 'ChallengeResponseAuthentication no'; |
| 527 |
push @cfgarr, 'ClientAliveCountMax 3'; |
| 528 |
push @cfgarr, 'ClientAliveInterval 0'; |
| 529 |
push @cfgarr, 'GatewayPorts no'; |
| 530 |
push @cfgarr, 'HostbasedAuthentication no'; |
| 531 |
push @cfgarr, 'HostbasedUsesNameFromPacketOnly no'; |
| 532 |
push @cfgarr, 'IgnoreRhosts yes'; |
| 533 |
push @cfgarr, 'IgnoreUserKnownHosts yes'; |
| 534 |
push @cfgarr, 'KeyRegenerationInterval 0'; |
| 535 |
push @cfgarr, 'LoginGraceTime 30'; |
| 536 |
push @cfgarr, "LogLevel $loglevel"; |
| 537 |
push @cfgarr, 'MaxStartups 5'; |
| 538 |
push @cfgarr, 'PasswordAuthentication no'; |
| 539 |
push @cfgarr, 'PermitEmptyPasswords no'; |
| 540 |
push @cfgarr, 'PermitRootLogin no'; |
| 541 |
push @cfgarr, 'PrintLastLog no'; |
| 542 |
push @cfgarr, 'PrintMotd no'; |
| 543 |
push @cfgarr, 'PubkeyAuthentication yes'; |
| 544 |
push @cfgarr, 'RhostsRSAAuthentication no'; |
| 545 |
push @cfgarr, 'RSAAuthentication no'; |
| 546 |
push @cfgarr, 'ServerKeyBits 768'; |
| 547 |
push @cfgarr, 'StrictModes no'; |
| 548 |
push @cfgarr, "Subsystem sftp \"$sftpsrv_config\""; |
| 549 |
push @cfgarr, 'SyslogFacility AUTH'; |
| 550 |
push @cfgarr, 'UseLogin no'; |
| 551 |
push @cfgarr, 'X11Forwarding no'; |
| 552 |
push @cfgarr, '#'; |
| 553 |
|
| 554 |
|
| 555 |
#*************************************************************************** |
| 556 |
# Write out initial sshd configuration file for curl's tests |
| 557 |
# |
| 558 |
$error = dump_array($sshdconfig, @cfgarr); |
| 559 |
if($error) { |
| 560 |
logmsg $error; |
| 561 |
exit 1; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
#*************************************************************************** |
| 566 |
# Verifies at run time if sshd supports a given configuration file option |
| 567 |
# |
| 568 |
sub sshd_supports_opt { |
| 569 |
my ($option, $value) = @_; |
| 570 |
my $err; |
| 571 |
# |
| 572 |
if((($sshdid =~ /OpenSSH/) && ($sshdvernum >= 310)) || |
| 573 |
($sshdid =~ /SunSSH/)) { |
| 574 |
# ssh daemon supports command line options -t -f and -o |
| 575 |
$err = grep /((Unsupported)|(Bad configuration)|(Deprecated)) option.*$option/, |
| 576 |
qx("$sshd" -t -f $sshdconfig -o "$option=$value" 2>&1); |
| 577 |
return !$err; |
| 578 |
} |
| 579 |
if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 299)) { |
| 580 |
# ssh daemon supports command line options -t and -f |
| 581 |
$err = dump_array($sshdconfig, (@cfgarr, "$option $value")); |
| 582 |
if($err) { |
| 583 |
logmsg $err; |
| 584 |
return 0; |
| 585 |
} |
| 586 |
$err = grep /((Unsupported)|(Bad configuration)|(Deprecated)) option.*$option/, |
| 587 |
qx("$sshd" -t -f $sshdconfig 2>&1); |
| 588 |
unlink $sshdconfig; |
| 589 |
return !$err; |
| 590 |
} |
| 591 |
return 0; |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
#*************************************************************************** |
| 596 |
# Kerberos Authentication support may have not been built into sshd |
| 597 |
# |
| 598 |
if(sshd_supports_opt('KerberosAuthentication','no')) { |
| 599 |
push @cfgarr, 'KerberosAuthentication no'; |
| 600 |
} |
| 601 |
if(sshd_supports_opt('KerberosGetAFSToken','no')) { |
| 602 |
push @cfgarr, 'KerberosGetAFSToken no'; |
| 603 |
} |
| 604 |
if(sshd_supports_opt('KerberosOrLocalPasswd','no')) { |
| 605 |
push @cfgarr, 'KerberosOrLocalPasswd no'; |
| 606 |
} |
| 607 |
if(sshd_supports_opt('KerberosTgtPassing','no')) { |
| 608 |
push @cfgarr, 'KerberosTgtPassing no'; |
| 609 |
} |
| 610 |
if(sshd_supports_opt('KerberosTicketCleanup','yes')) { |
| 611 |
push @cfgarr, 'KerberosTicketCleanup yes'; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
#*************************************************************************** |
| 616 |
# Andrew File System support may have not been built into sshd |
| 617 |
# |
| 618 |
if(sshd_supports_opt('AFSTokenPassing','no')) { |
| 619 |
push @cfgarr, 'AFSTokenPassing no'; |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
#*************************************************************************** |
| 624 |
# S/Key authentication support may have not been built into sshd |
| 625 |
# |
| 626 |
if(sshd_supports_opt('SkeyAuthentication','no')) { |
| 627 |
push @cfgarr, 'SkeyAuthentication no'; |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
#*************************************************************************** |
| 632 |
# GSSAPI Authentication support may have not been built into sshd |
| 633 |
# |
| 634 |
my $sshd_builtwith_GSSAPI; |
| 635 |
if(sshd_supports_opt('GSSAPIAuthentication','no')) { |
| 636 |
push @cfgarr, 'GSSAPIAuthentication no'; |
| 637 |
$sshd_builtwith_GSSAPI = 1; |
| 638 |
} |
| 639 |
if(sshd_supports_opt('GSSAPICleanupCredentials','yes')) { |
| 640 |
push @cfgarr, 'GSSAPICleanupCredentials yes'; |
| 641 |
} |
| 642 |
if(sshd_supports_opt('GSSAPIKeyExchange','no')) { |
| 643 |
push @cfgarr, 'GSSAPIKeyExchange no'; |
| 644 |
} |
| 645 |
if(sshd_supports_opt('GSSAPIStoreDelegatedCredentials','no')) { |
| 646 |
push @cfgarr, 'GSSAPIStoreDelegatedCredentials no'; |
| 647 |
} |
| 648 |
if(sshd_supports_opt('GSSCleanupCreds','yes')) { |
| 649 |
push @cfgarr, 'GSSCleanupCreds yes'; |
| 650 |
} |
| 651 |
if(sshd_supports_opt('GSSUseSessionCredCache','no')) { |
| 652 |
push @cfgarr, 'GSSUseSessionCredCache no'; |
| 653 |
} |
| 654 |
push @cfgarr, '#'; |
| 655 |
|
| 656 |
|
| 657 |
#*************************************************************************** |
| 658 |
# Options that might be supported or not in sshd OpenSSH 2.9.9 and later |
| 659 |
# |
| 660 |
if(sshd_supports_opt('AcceptEnv','')) { |
| 661 |
push @cfgarr, 'AcceptEnv'; |
| 662 |
} |
| 663 |
if(sshd_supports_opt('AddressFamily','any')) { |
| 664 |
# Address family must be specified before ListenAddress |
| 665 |
splice @cfgarr, 14, 0, 'AddressFamily any'; |
| 666 |
} |
| 667 |
if(sshd_supports_opt('Compression','no')) { |
| 668 |
push @cfgarr, 'Compression no'; |
| 669 |
} |
| 670 |
if(sshd_supports_opt('KbdInteractiveAuthentication','no')) { |
| 671 |
push @cfgarr, 'KbdInteractiveAuthentication no'; |
| 672 |
} |
| 673 |
if(sshd_supports_opt('KeepAlive','no')) { |
| 674 |
push @cfgarr, 'KeepAlive no'; |
| 675 |
} |
| 676 |
if(sshd_supports_opt('LookupClientHostnames','no')) { |
| 677 |
push @cfgarr, 'LookupClientHostnames no'; |
| 678 |
} |
| 679 |
if(sshd_supports_opt('MaxAuthTries','10')) { |
| 680 |
push @cfgarr, 'MaxAuthTries 10'; |
| 681 |
} |
| 682 |
if(sshd_supports_opt('PAMAuthenticationViaKbdInt','no')) { |
| 683 |
push @cfgarr, 'PAMAuthenticationViaKbdInt no'; |
| 684 |
} |
| 685 |
if(sshd_supports_opt('PermitTunnel','no')) { |
| 686 |
push @cfgarr, 'PermitTunnel no'; |
| 687 |
} |
| 688 |
if(sshd_supports_opt('PermitUserEnvironment','no')) { |
| 689 |
push @cfgarr, 'PermitUserEnvironment no'; |
| 690 |
} |
| 691 |
if(sshd_supports_opt('RhostsAuthentication','no')) { |
| 692 |
push @cfgarr, 'RhostsAuthentication no'; |
| 693 |
} |
| 694 |
if(sshd_supports_opt('TCPKeepAlive','no')) { |
| 695 |
push @cfgarr, 'TCPKeepAlive no'; |
| 696 |
} |
| 697 |
if(sshd_supports_opt('UseDNS','no')) { |
| 698 |
push @cfgarr, 'UseDNS no'; |
| 699 |
} |
| 700 |
if(sshd_supports_opt('UsePAM','no')) { |
| 701 |
push @cfgarr, 'UsePAM no'; |
| 702 |
} |
| 703 |
|
| 704 |
if($sshdid =~ /OpenSSH/) { |
| 705 |
# http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6492415 |
| 706 |
if(sshd_supports_opt('UsePrivilegeSeparation','no')) { |
| 707 |
push @cfgarr, 'UsePrivilegeSeparation no'; |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
if(sshd_supports_opt('VerifyReverseMapping','no')) { |
| 712 |
push @cfgarr, 'VerifyReverseMapping no'; |
| 713 |
} |
| 714 |
if(sshd_supports_opt('X11UseLocalhost','yes')) { |
| 715 |
push @cfgarr, 'X11UseLocalhost yes'; |
| 716 |
} |
| 717 |
push @cfgarr, '#'; |
| 718 |
|
| 719 |
|
| 720 |
#*************************************************************************** |
| 721 |
# Write out resulting sshd configuration file for curl's tests |
| 722 |
# |
| 723 |
$error = dump_array($sshdconfig, @cfgarr); |
| 724 |
if($error) { |
| 725 |
logmsg $error; |
| 726 |
exit 1; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
#*************************************************************************** |
| 731 |
# Verify that sshd actually supports our generated configuration file |
| 732 |
# |
| 733 |
if(system "\"$sshd\" -t -f $sshdconfig > $sshdlog 2>&1") { |
| 734 |
logmsg "sshd configuration file $sshdconfig failed verification"; |
| 735 |
display_sshdlog(); |
| 736 |
display_sshdconfig(); |
| 737 |
exit 1; |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
#*************************************************************************** |
| 742 |
# Generate ssh client host key database file for curl's tests |
| 743 |
# |
| 744 |
if((! -e $knownhosts) || (! -s $knownhosts)) { |
| 745 |
logmsg 'generating ssh client known hosts file...' if($verbose); |
| 746 |
unlink($knownhosts); |
| 747 |
if(open(RSAKEYFILE, "<$hstpubkeyf")) { |
| 748 |
my @rsahostkey = do { local $/ = ' '; <RSAKEYFILE> }; |
| 749 |
if(close(RSAKEYFILE)) { |
| 750 |
if(open(KNOWNHOSTS, ">$knownhosts")) { |
| 751 |
print KNOWNHOSTS "$listenaddr ssh-rsa $rsahostkey[1]\n"; |
| 752 |
if(!close(KNOWNHOSTS)) { |
| 753 |
$error = "Error: cannot close file $knownhosts"; |
| 754 |
} |
| 755 |
} |
| 756 |
else { |
| 757 |
$error = "Error: cannot write file $knownhosts"; |
| 758 |
} |
| 759 |
} |
| 760 |
else { |
| 761 |
$error = "Error: cannot close file $hstpubkeyf"; |
| 762 |
} |
| 763 |
} |
| 764 |
else { |
| 765 |
$error = "Error: cannot read file $hstpubkeyf"; |
| 766 |
} |
| 767 |
if($error) { |
| 768 |
logmsg $error; |
| 769 |
exit 1; |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
#*************************************************************************** |
| 775 |
# Convert paths for curl's tests running on Windows using Cygwin OpenSSH |
| 776 |
# |
| 777 |
my $identity_config = abs_path("$path/$identity"); |
| 778 |
my $knownhosts_config = abs_path("$path/$knownhosts"); |
| 779 |
|
| 780 |
if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') { |
| 781 |
# Ensure to use MinGW/Cygwin paths |
| 782 |
$identity_config = pathhelp::build_sys_abs_path($identity_config); |
| 783 |
$knownhosts_config = pathhelp::build_sys_abs_path($knownhosts_config); |
| 784 |
} |
| 785 |
if ($sshdid =~ /OpenSSH-Windows/) { |
| 786 |
# Ensure to use native Windows paths with OpenSSH for Windows |
| 787 |
$identity_config = pathhelp::sys_native_abs_path($identity); |
| 788 |
$knownhosts_config = pathhelp::sys_native_abs_path($knownhosts); |
| 789 |
} |
| 790 |
|
| 791 |
#*************************************************************************** |
| 792 |
# ssh client configuration file options we might use and version support |
| 793 |
# |
| 794 |
# AddressFamily : OpenSSH 3.7.0 and later |
| 795 |
# BatchMode : OpenSSH 1.2.1 and later |
| 796 |
# BindAddress : OpenSSH 2.9.9 and later |
| 797 |
# ChallengeResponseAuthentication : OpenSSH 2.5.0 and later |
| 798 |
# CheckHostIP : OpenSSH 1.2.1 and later |
| 799 |
# Cipher : OpenSSH 1.2.1 and later [3] |
| 800 |
# Ciphers : OpenSSH 2.1.0 and later [3] |
| 801 |
# ClearAllForwardings : OpenSSH 2.9.9 and later |
| 802 |
# Compression : OpenSSH 1.2.1 and later |
| 803 |
# CompressionLevel : OpenSSH 1.2.1 and later [3] |
| 804 |
# ConnectionAttempts : OpenSSH 1.2.1 and later |
| 805 |
# ConnectTimeout : OpenSSH 3.7.0 and later |
| 806 |
# ControlMaster : OpenSSH 3.9.0 and later |
| 807 |
# ControlPath : OpenSSH 3.9.0 and later |
| 808 |
# DisableBanner : SunSSH 1.2.0 and later |
| 809 |
# DynamicForward : OpenSSH 2.9.0 and later |
| 810 |
# EnableSSHKeysign : OpenSSH 3.6.0 and later |
| 811 |
# EscapeChar : OpenSSH 1.2.1 and later [3] |
| 812 |
# ExitOnForwardFailure : OpenSSH 4.4.0 and later |
| 813 |
# ForwardAgent : OpenSSH 1.2.1 and later |
| 814 |
# ForwardX11 : OpenSSH 1.2.1 and later |
| 815 |
# ForwardX11Trusted : OpenSSH 3.8.0 and later |
| 816 |
# GatewayPorts : OpenSSH 1.2.1 and later |
| 817 |
# GlobalKnownHostsFile : OpenSSH 1.2.1 and later |
| 818 |
# GSSAPIAuthentication : OpenSSH 3.7.0 and later [1] |
| 819 |
# GSSAPIDelegateCredentials : OpenSSH 3.7.0 and later [1] |
| 820 |
# HashKnownHosts : OpenSSH 4.0.0 and later |
| 821 |
# Host : OpenSSH 1.2.1 and later |
| 822 |
# HostbasedAuthentication : OpenSSH 2.9.0 and later |
| 823 |
# HostKeyAlgorithms : OpenSSH 2.9.0 and later [3] |
| 824 |
# HostKeyAlias : OpenSSH 2.5.0 and later [3] |
| 825 |
# HostName : OpenSSH 1.2.1 and later |
| 826 |
# IdentitiesOnly : OpenSSH 3.9.0 and later |
| 827 |
# IdentityFile : OpenSSH 1.2.1 and later |
| 828 |
# IgnoreIfUnknown : SunSSH 1.2.0 and later |
| 829 |
# KeepAlive : OpenSSH 1.2.1 and later |
| 830 |
# KbdInteractiveAuthentication : OpenSSH 2.3.0 and later |
| 831 |
# KbdInteractiveDevices : OpenSSH 2.3.0 and later [3] |
| 832 |
# LocalCommand : OpenSSH 4.3.0 and later [3] |
| 833 |
# LocalForward : OpenSSH 1.2.1 and later [3] |
| 834 |
# LogLevel : OpenSSH 1.2.1 and later |
| 835 |
# MACs : OpenSSH 2.5.0 and later [3] |
| 836 |
# NoHostAuthenticationForLocalhost : OpenSSH 3.0.0 and later |
| 837 |
# NumberOfPasswordPrompts : OpenSSH 1.2.1 and later |
| 838 |
# PasswordAuthentication : OpenSSH 1.2.1 and later |
| 839 |
# PermitLocalCommand : OpenSSH 4.3.0 and later |
| 840 |
# Port : OpenSSH 1.2.1 and later |
| 841 |
# PreferredAuthentications : OpenSSH 2.5.2 and later |
| 842 |
# Protocol : OpenSSH 2.1.0 and later |
| 843 |
# ProxyCommand : OpenSSH 1.2.1 and later [3] |
| 844 |
# PubkeyAuthentication : OpenSSH 2.5.0 and later |
| 845 |
# RekeyLimit : OpenSSH 3.7.0 and later |
| 846 |
# RemoteForward : OpenSSH 1.2.1 and later [3] |
| 847 |
# RhostsRSAAuthentication : OpenSSH 1.2.1 and later |
| 848 |
# RSAAuthentication : OpenSSH 1.2.1 and later |
| 849 |
# SendEnv : OpenSSH 3.9.0 and later |
| 850 |
# ServerAliveCountMax : OpenSSH 3.8.0 and later |
| 851 |
# ServerAliveInterval : OpenSSH 3.8.0 and later |
| 852 |
# SmartcardDevice : OpenSSH 2.9.9 and later [1][3] |
| 853 |
# StrictHostKeyChecking : OpenSSH 1.2.1 and later |
| 854 |
# TCPKeepAlive : OpenSSH 3.8.0 and later |
| 855 |
# Tunnel : OpenSSH 4.3.0 and later |
| 856 |
# TunnelDevice : OpenSSH 4.3.0 and later [3] |
| 857 |
# UsePAM : OpenSSH 3.7.0 and later [1][2][3] |
| 858 |
# UsePrivilegedPort : OpenSSH 1.2.1 and later |
| 859 |
# User : OpenSSH 1.2.1 and later |
| 860 |
# UserKnownHostsFile : OpenSSH 1.2.1 and later |
| 861 |
# VerifyHostKeyDNS : OpenSSH 3.8.0 and later |
| 862 |
# XAuthLocation : OpenSSH 2.1.1 and later [3] |
| 863 |
# |
| 864 |
# [1] Option only available if activated at compile time |
| 865 |
# [2] Option specific for portable versions |
| 866 |
# [3] Option not used in our ssh client config file |
| 867 |
|
| 868 |
|
| 869 |
#*************************************************************************** |
| 870 |
# Initialize ssh config with options actually supported in OpenSSH 2.9.9 |
| 871 |
# |
| 872 |
logmsg 'generating ssh client config file...' if($verbose); |
| 873 |
@cfgarr = (); |
| 874 |
push @cfgarr, '# This is a generated file. Do not edit.'; |
| 875 |
push @cfgarr, "# $sshverstr ssh client configuration file for curl testing"; |
| 876 |
push @cfgarr, '#'; |
| 877 |
push @cfgarr, 'Host *'; |
| 878 |
push @cfgarr, '#'; |
| 879 |
push @cfgarr, "Port $port"; |
| 880 |
push @cfgarr, "HostName $listenaddr"; |
| 881 |
push @cfgarr, "User $username"; |
| 882 |
push @cfgarr, 'Protocol 2'; |
| 883 |
push @cfgarr, '#'; |
| 884 |
|
| 885 |
# BindAddress option is not supported by OpenSSH for Windows |
| 886 |
if (!($sshdid =~ /OpenSSH-Windows/)) { |
| 887 |
push @cfgarr, "BindAddress $listenaddr"; |
| 888 |
} |
| 889 |
|
| 890 |
push @cfgarr, '#'; |
| 891 |
push @cfgarr, "IdentityFile $identity_config"; |
| 892 |
push @cfgarr, "UserKnownHostsFile $knownhosts_config"; |
| 893 |
push @cfgarr, '#'; |
| 894 |
push @cfgarr, 'BatchMode yes'; |
| 895 |
push @cfgarr, 'ChallengeResponseAuthentication no'; |
| 896 |
push @cfgarr, 'CheckHostIP no'; |
| 897 |
push @cfgarr, 'ClearAllForwardings no'; |
| 898 |
push @cfgarr, 'Compression no'; |
| 899 |
push @cfgarr, 'ConnectionAttempts 3'; |
| 900 |
push @cfgarr, 'ForwardAgent no'; |
| 901 |
push @cfgarr, 'ForwardX11 no'; |
| 902 |
push @cfgarr, 'GatewayPorts no'; |
| 903 |
push @cfgarr, 'GlobalKnownHostsFile /dev/null'; |
| 904 |
push @cfgarr, 'HostbasedAuthentication no'; |
| 905 |
push @cfgarr, 'KbdInteractiveAuthentication no'; |
| 906 |
push @cfgarr, "LogLevel $loglevel"; |
| 907 |
push @cfgarr, 'NumberOfPasswordPrompts 0'; |
| 908 |
push @cfgarr, 'PasswordAuthentication no'; |
| 909 |
push @cfgarr, 'PreferredAuthentications publickey'; |
| 910 |
push @cfgarr, 'PubkeyAuthentication yes'; |
| 911 |
|
| 912 |
# RSA authentication options are not supported by OpenSSH for Windows |
| 913 |
if (!($sshdid =~ /OpenSSH-Windows/)) { |
| 914 |
push @cfgarr, 'RhostsRSAAuthentication no'; |
| 915 |
push @cfgarr, 'RSAAuthentication no'; |
| 916 |
} |
| 917 |
|
| 918 |
# Disabled StrictHostKeyChecking since it makes the tests fail on my |
| 919 |
# OpenSSH_6.0p1 on Debian Linux / Daniel |
| 920 |
push @cfgarr, 'StrictHostKeyChecking no'; |
| 921 |
push @cfgarr, 'UsePrivilegedPort no'; |
| 922 |
push @cfgarr, '#'; |
| 923 |
|
| 924 |
|
| 925 |
#*************************************************************************** |
| 926 |
# Options supported in ssh client newer than OpenSSH 2.9.9 |
| 927 |
# |
| 928 |
|
| 929 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 370)) { |
| 930 |
push @cfgarr, 'AddressFamily any'; |
| 931 |
} |
| 932 |
|
| 933 |
if((($sshid =~ /OpenSSH/) && ($sshvernum >= 370)) || |
| 934 |
(($sshid =~ /SunSSH/) && ($sshvernum >= 120))) { |
| 935 |
push @cfgarr, 'ConnectTimeout 30'; |
| 936 |
} |
| 937 |
|
| 938 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 390)) { |
| 939 |
push @cfgarr, 'ControlMaster no'; |
| 940 |
} |
| 941 |
|
| 942 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 420)) { |
| 943 |
push @cfgarr, 'ControlPath none'; |
| 944 |
} |
| 945 |
|
| 946 |
if(($sshid =~ /SunSSH/) && ($sshvernum >= 120)) { |
| 947 |
push @cfgarr, 'DisableBanner yes'; |
| 948 |
} |
| 949 |
|
| 950 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 360)) { |
| 951 |
push @cfgarr, 'EnableSSHKeysign no'; |
| 952 |
} |
| 953 |
|
| 954 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 440)) { |
| 955 |
push @cfgarr, 'ExitOnForwardFailure yes'; |
| 956 |
} |
| 957 |
|
| 958 |
if((($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) || |
| 959 |
(($sshid =~ /SunSSH/) && ($sshvernum >= 120))) { |
| 960 |
push @cfgarr, 'ForwardX11Trusted no'; |
| 961 |
} |
| 962 |
|
| 963 |
if(($sshd_builtwith_GSSAPI) && ($sshdid eq $sshid) && |
| 964 |
($sshdvernum == $sshvernum)) { |
| 965 |
push @cfgarr, 'GSSAPIAuthentication no'; |
| 966 |
push @cfgarr, 'GSSAPIDelegateCredentials no'; |
| 967 |
if($sshid =~ /SunSSH/) { |
| 968 |
push @cfgarr, 'GSSAPIKeyExchange no'; |
| 969 |
} |
| 970 |
} |
| 971 |
|
| 972 |
if((($sshid =~ /OpenSSH/) && ($sshvernum >= 400)) || |
| 973 |
(($sshid =~ /SunSSH/) && ($sshvernum >= 120))) { |
| 974 |
push @cfgarr, 'HashKnownHosts no'; |
| 975 |
} |
| 976 |
|
| 977 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 390)) { |
| 978 |
push @cfgarr, 'IdentitiesOnly yes'; |
| 979 |
} |
| 980 |
|
| 981 |
if(($sshid =~ /SunSSH/) && ($sshvernum >= 120)) { |
| 982 |
push @cfgarr, 'IgnoreIfUnknown no'; |
| 983 |
} |
| 984 |
|
| 985 |
if((($sshid =~ /OpenSSH/) && ($sshvernum < 380)) || |
| 986 |
($sshid =~ /SunSSH/)) { |
| 987 |
push @cfgarr, 'KeepAlive no'; |
| 988 |
} |
| 989 |
|
| 990 |
if((($sshid =~ /OpenSSH/) && ($sshvernum >= 300)) || |
| 991 |
($sshid =~ /SunSSH/)) { |
| 992 |
push @cfgarr, 'NoHostAuthenticationForLocalhost no'; |
| 993 |
} |
| 994 |
|
| 995 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 430)) { |
| 996 |
push @cfgarr, 'PermitLocalCommand no'; |
| 997 |
} |
| 998 |
|
| 999 |
if((($sshid =~ /OpenSSH/) && ($sshvernum >= 370)) || |
| 1000 |
(($sshid =~ /SunSSH/) && ($sshvernum >= 120))) { |
| 1001 |
push @cfgarr, 'RekeyLimit 1G'; |
| 1002 |
} |
| 1003 |
|
| 1004 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 390)) { |
| 1005 |
push @cfgarr, 'SendEnv'; |
| 1006 |
} |
| 1007 |
|
| 1008 |
if((($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) || |
| 1009 |
(($sshid =~ /SunSSH/) && ($sshvernum >= 120))) { |
| 1010 |
push @cfgarr, 'ServerAliveCountMax 3'; |
| 1011 |
push @cfgarr, 'ServerAliveInterval 0'; |
| 1012 |
} |
| 1013 |
|
| 1014 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) { |
| 1015 |
push @cfgarr, 'TCPKeepAlive no'; |
| 1016 |
} |
| 1017 |
|
| 1018 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 430)) { |
| 1019 |
push @cfgarr, 'Tunnel no'; |
| 1020 |
} |
| 1021 |
|
| 1022 |
if(($sshid =~ /OpenSSH/) && ($sshvernum >= 380)) { |
| 1023 |
push @cfgarr, 'VerifyHostKeyDNS no'; |
| 1024 |
} |
| 1025 |
|
| 1026 |
push @cfgarr, '#'; |
| 1027 |
|
| 1028 |
|
| 1029 |
#*************************************************************************** |
| 1030 |
# Write out resulting ssh client configuration file for curl's tests |
| 1031 |
# |
| 1032 |
$error = dump_array($sshconfig, @cfgarr); |
| 1033 |
if($error) { |
| 1034 |
logmsg $error; |
| 1035 |
exit 1; |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
#*************************************************************************** |
| 1040 |
# Initialize client sftp config with options actually supported. |
| 1041 |
# |
| 1042 |
logmsg 'generating sftp client config file...' if($verbose); |
| 1043 |
splice @cfgarr, 1, 1, "# $sshverstr sftp client configuration file for curl testing"; |
| 1044 |
# |
| 1045 |
for(my $i = scalar(@cfgarr) - 1; $i > 0; $i--) { |
| 1046 |
if($cfgarr[$i] =~ /^DynamicForward/) { |
| 1047 |
splice @cfgarr, $i, 1; |
| 1048 |
next; |
| 1049 |
} |
| 1050 |
if($cfgarr[$i] =~ /^ClearAllForwardings/) { |
| 1051 |
splice @cfgarr, $i, 1, "ClearAllForwardings yes"; |
| 1052 |
next; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
#*************************************************************************** |
| 1058 |
# Write out resulting sftp client configuration file for curl's tests |
| 1059 |
# |
| 1060 |
$error = dump_array($sftpconfig, @cfgarr); |
| 1061 |
if($error) { |
| 1062 |
logmsg $error; |
| 1063 |
exit 1; |
| 1064 |
} |
| 1065 |
@cfgarr = (); |
| 1066 |
|
| 1067 |
|
| 1068 |
#*************************************************************************** |
| 1069 |
# Generate client sftp commands batch file for sftp server verification |
| 1070 |
# |
| 1071 |
logmsg 'generating sftp client commands file...' if($verbose); |
| 1072 |
push @cfgarr, 'pwd'; |
| 1073 |
push @cfgarr, 'quit'; |
| 1074 |
$error = dump_array($sftpcmds, @cfgarr); |
| 1075 |
if($error) { |
| 1076 |
logmsg $error; |
| 1077 |
exit 1; |
| 1078 |
} |
| 1079 |
@cfgarr = (); |
| 1080 |
|
| 1081 |
|
| 1082 |
#*************************************************************************** |
| 1083 |
# Start the ssh server daemon without forking it |
| 1084 |
# |
| 1085 |
logmsg "SCP/SFTP server listening on port $port" if($verbose); |
| 1086 |
my $rc = system "\"$sshd\" -e -D -f $sshdconfig > $sshdlog 2>&1"; |
| 1087 |
if($rc == -1) { |
| 1088 |
logmsg "\"$sshd\" failed with: $!"; |
| 1089 |
} |
| 1090 |
elsif($rc & 127) { |
| 1091 |
logmsg sprintf("\"$sshd\" died with signal %d, and %s coredump", |
| 1092 |
($rc & 127), ($rc & 128)?'a':'no'); |
| 1093 |
} |
| 1094 |
elsif($verbose && ($rc >> 8)) { |
| 1095 |
logmsg sprintf("\"$sshd\" exited with %d", $rc >> 8); |
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
#*************************************************************************** |
| 1100 |
# Clean up once the server has stopped |
| 1101 |
# |
| 1102 |
unlink($hstprvkeyf, $hstpubkeyf, $cliprvkeyf, $clipubkeyf, $knownhosts); |
| 1103 |
unlink($sshdconfig, $sshconfig, $sftpconfig); |
| 1104 |
|
| 1105 |
|
| 1106 |
exit 0; |