80-test_cmp_http.t: fix handling of IPv6 server host (localhost '::1')

Fixes 22467

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25010)
This commit is contained in:
David von Oheimb 2024-07-26 15:34:05 +02:00 committed by Tomas Mraz
parent ac91bd88d9
commit 1ef3032eac
3 changed files with 18 additions and 12 deletions

View File

@ -144,7 +144,7 @@ sub test_cmp_http {
my $title = shift;
my $params = shift;
my $expected_result = shift;
$params = [ '-server', "127.0.0.1:$server_port", @$params ]
$params = [ '-server', "$server_host:$server_port", @$params ]
if ($server_name eq "Mock" && !(grep { $_ eq '-server' } @$params));
my $cmd = app([@app, @$params]);
@ -252,14 +252,15 @@ sub load_tests {
next LOOP if $server_tls == 0 && $line =~ m/,\s*-tls_used\s*,/;
my $noproxy = $no_proxy;
my $server_plain = $server_host =~ m/^\[(.*)\]$/ ? $1 : $server_host;
if ($line =~ m/,\s*-no_proxy\s*,(.*?)(,|$)/) {
$noproxy = $1;
} elsif ($server_host eq "127.0.0.1") {
} elsif ($server_plain eq "127.0.0.1" || $server_plain eq "::1") {
# do connections to localhost (e.g., mock server) without proxy
$line =~ s{-section,,}{-section,,-no_proxy,127.0.0.1,} ;
$line =~ s{-section,,}{-section,,-no_proxy,$server_plain,} ;
}
if ($line =~ m/,\s*-proxy\s*,/) {
next LOOP if $no_proxy && ($noproxy =~ $server_host);
next LOOP if $no_proxy && ($noproxy =~ $server_plain);
} else {
$line =~ s{-section,,}{-section,,-proxy,$proxy,};
}
@ -301,27 +302,32 @@ sub start_server {
if ($server_host eq '*' || $server_port == 0) {
# Find out the actual server host and port and possibly different PID
my ($host, $port);
$pid = 0;
while (<$server_fh>) {
print "$server_name server output: $_";
next if m/using section/;
s/\R$//; # Better chomp
($server_host, $server_port, $pid) = ($1, $2, $3)
($host, $port, $pid) = ($1, $2, $3)
if /^ACCEPT\s(.*?):(\d+) PID=(\d+)$/;
last; # Do not loop further to prevent hangs on server misbehavior
}
$server_host = "[::1]" if $server_host eq "[::]";
$server_host = "127.0.0.1" if $server_host eq "0.0.0.0";
if ($server_host eq '*' && defined $host) {
$server_host = "[::1]" if $host eq "[::]";
$server_host = "127.0.0.1" if $host eq "0.0.0.0";
}
$server_port = $port if $server_port == 0 && defined $port;
}
unless ($server_port > 0) {
if ($server_host eq '*' || $server_port == 0) {
stop_server($server_name, $pid) if $pid;
print "Cannot get expected output from the $server_name server";
print "Cannot get expected output from the $server_name server\n";
return 0;
}
$kur_port = $server_port if $kur_port eq "\$server_port";
$pbm_port = $server_port if $pbm_port eq "\$server_port";
$server_tls = $server_port if $server_tls;
return $pid;
}
sub stop_server {

View File

@ -17,11 +17,11 @@ policies = certificatePolicies
[Mock] # the built-in OpenSSL CMP mock server
# no_check_time = 1
server_host = 127.0.0.1 # localhost
server_host = * # to be determined by server: 127.0.0.1 or ::1 (localhost)
server_port = 0 # 0 means that the port is determined by the server
server_tls = $server_port
server_cert = server.crt
server = $server_host:$server_port
# server = $server_host:$server_port
server_path = pkix/
path = $server_path
ca_dn = /CN=Root CA

View File

@ -2,7 +2,7 @@ expected,description, -section,val, -server,val, -proxy,val, -no_proxy,val, -tls
,Message transfer options:,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,
1,default config, -section,,,,,,,,BLANK,,,,BLANK,,BLANK,,BLANK,
disabled as not supported by some host IP configurations,server domain name, -section,, -server,localhost:_SERVER_PORT,,,,,,,,,,,,,,
disabled as not supported by some host IP configurations,server domain name, -section,, -server,_SERVER_HOST:_SERVER_PORT,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,
0,wrong server, -section,, -server,xn--rksmrgs-5wao1o.example.com:_SERVER_PORT,,,,,BLANK,,,, -msg_timeout,1,BLANK,,BLANK,
0,wrong server port, -section,, -server,_SERVER_HOST:99,,,,,BLANK,,,, -msg_timeout,1,BLANK,,BLANK,

1 expected description -section val -server val -proxy val -no_proxy val -tls_used noarg -path val -msg_timeout int -total_timeout int -keep_alive val
2 Message transfer options:
3
4 1 default config -section BLANK BLANK BLANK BLANK
5 disabled as not supported by some host IP configurations server domain name -section -server localhost:_SERVER_PORT _SERVER_HOST:_SERVER_PORT
6
7 0 wrong server -section -server xn--rksmrgs-5wao1o.example.com:_SERVER_PORT BLANK -msg_timeout 1 BLANK BLANK
8 0 wrong server port -section -server _SERVER_HOST:99 BLANK -msg_timeout 1 BLANK BLANK