return (0, $rtsppid, $pid2, $port);
}
+#***************************************************************************
+# Return key algorithm string
+#
+sub sshkeyalgostr {
+ my ($algo) = @_;
+ my %algomap = (
+ ecdsa => 'ecdsa-sha2-nistp256',
+ );
+ return exists $algomap{$algo} ? $algomap{$algo} : 'ssh-' . $algo;
+}
+
#######################################################################
# Start the ssh (scp/sftp) server
#
$flags .= "--id $idnum " if($idnum > 1);
$flags .= "--ipv$ipvnum --addr \"$ip\" ";
$flags .= "--user \"$USER\"";
+ if(defined $feature{"sshkeyalgo"}) {
+ $flags .= ' --keyalgo ' . $feature{"sshkeyalgo"};
+ }
my @tports;
my $port = getfreeport($ipvnum);
$$thing =~ s/${prefix}SSHSRVMD5/$SSHSRVMD5/g;
$$thing =~ s/${prefix}SSHSRVSHA256/$SSHSRVSHA256/g;
+ my $keyalgostr = sshkeyalgostr(defined $feature{"sshkeyalgo"} ? $feature{"sshkeyalgo"} : "");
+ $$thing =~ s/${prefix}SSHKEYALGO/$keyalgostr/g;
# The purpose of FTPTIME2 is to provide times that can be
# used for time-out tests and that would work on most hosts as these
our $sftplog = undef; # sftp client log file
our $sftpcmds = 'curl_sftp_cmds'; # sftp client commands batch file
our $knownhosts = 'curl_client_knownhosts'; # ssh knownhosts file
-our $hstprvkeyf = 'curl_host_rsa_key'; # host private key file
-our $hstpubkeyf = 'curl_host_rsa_key.pub'; # host public key file
-our $hstpubmd5f = 'curl_host_rsa_key.pub_md5'; # md5 hash of host public key
-our $hstpubsha256f = 'curl_host_rsa_key.pub_sha256'; # sha256 hash of host public key
+our $hstprvkeyf = 'curl_host_key'; # host private key file
+our $hstpubkeyf = 'curl_host_key.pub'; # host public key file
+our $hstpubmd5f = 'curl_host_key.pub_md5'; # md5 hash of host public key
+our $hstpubsha256f = 'curl_host_key.pub_sha256'; # sha256 hash of host public key
our $cliprvkeyf = 'curl_client_key'; # client private key file
our $clipubkeyf = 'curl_client_key.pub'; # client public key file
my $ipvnum = 4; # default IP version of listener address
my $idnum = 1; # default ssh daemon instance number
my $proto = 'ssh'; # protocol the ssh daemon speaks
+my $keyalgo = 'rsa'; # key algorithm
my $path = getcwd(); # current working directory
my $logdir = $path .'/log'; # directory for log files
my $piddir; # directory for server config files
}
}
}
+ elsif($ARGV[0] eq '--keyalgo') {
+ if($ARGV[1]) {
+ $keyalgo = $ARGV[1];
+ shift @ARGV;
+ }
+ }
else {
print STDERR "\nWarning: sshserver.pl unknown parameter: '$ARGV[0]'\n";
}
# -N: new passphrase : OpenSSH 1.2.1 and later
# -q: quiet keygen : OpenSSH 1.2.1 and later
# -t: key type : OpenSSH 2.5.0 and later
+# -m: key format : OpenSSH 5.6.0 and later
#
# -C: identity comment : SunSSH 1.0.0 and later
# -f: key filename : SunSSH 1.0.0 and later
# format, e.g. WinCNG.
# Accepted values: RFC4716, PKCS8, PEM (see also 'man ssh-keygen')
push @sshkeygenopt, '-m';
- # Default to the most compatible RSA format for tests.
+ # Default to the most compatible format for tests.
push @sshkeygenopt, $ENV{'CURL_TEST_SSH_KEY_FORMAT'} ? $ENV{'CURL_TEST_SSH_KEY_FORMAT'} : 'PEM';
}
logmsg "generating host keys...\n" if($verbose);
- if(system($sshkeygen, ('-q', '-t', 'rsa', '-f', pp($hstprvkeyf), '-C', 'curl test server', '-N', '', @sshkeygenopt))) {
+ if(system($sshkeygen, ('-q', '-t', $keyalgo, '-f', pp($hstprvkeyf), '-C', 'curl test server', '-N', '', @sshkeygenopt))) {
logmsg "Could not generate host key\n";
exit 1;
}
display_file_top(pp($hstprvkeyf)) if($verbose);
logmsg "generating client keys...\n" if($verbose);
- if(system($sshkeygen, ('-q', '-t', 'rsa', '-f', pp($cliprvkeyf), '-C', 'curl test client', '-N', '', @sshkeygenopt))) {
+ if(system($sshkeygen, ('-q', '-t', $keyalgo, '-f', pp($cliprvkeyf), '-C', 'curl test client', '-N', '', @sshkeygenopt))) {
logmsg "Could not generate client key\n";
exit 1;
}
push @cfgarr, "PidFile $pidfile_config";
push @cfgarr, '#';
}
-if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 880)) {
+if(($sshdid =~ /OpenSSH/) && ($sshdvernum >= 880) && ($keyalgo eq 'rsa')) {
push @cfgarr, 'HostKeyAlgorithms +ssh-rsa';
push @cfgarr, 'PubkeyAcceptedKeyTypes +ssh-rsa';
}
if((! -e pp($knownhosts)) || (! -s pp($knownhosts))) {
logmsg "generating ssh client known hosts file...\n" if($verbose);
unlink(pp($knownhosts));
- if(open(my $rsakeyfile, "<", pp($hstpubkeyf))) {
- my @rsahostkey = do { local $/ = ' '; <$rsakeyfile> };
- if(close($rsakeyfile)) {
+ if(open(my $keyfile, "<", pp($hstpubkeyf))) {
+ chomp(my $line = <$keyfile>);
+ if(close($keyfile)) {
if(open(my $knownhostsh, ">", pp($knownhosts))) {
- print $knownhostsh "$listenaddr ssh-rsa $rsahostkey[1]\n";
+ my @hostkey = split /\s+/, $line;
+ print $knownhostsh "$listenaddr $hostkey[0] $hostkey[1]\n";
if(!close($knownhostsh)) {
$error = "Error: cannot close file $knownhosts";
}