1*e0c4386eSCy Schubert#! /usr/bin/env perl 2*e0c4386eSCy Schubert# Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved. 3*e0c4386eSCy Schubert# 4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License"). You may not use 5*e0c4386eSCy Schubert# this file except in compliance with the License. You can obtain a copy 6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at 7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html 8*e0c4386eSCy Schubert 9*e0c4386eSCy Schubert 10*e0c4386eSCy Schubertuse strict; 11*e0c4386eSCy Schubertuse warnings; 12*e0c4386eSCy Schubert 13*e0c4386eSCy Schubertuse POSIX; 14*e0c4386eSCy Schubertuse File::Basename; 15*e0c4386eSCy Schubertuse File::Copy; 16*e0c4386eSCy Schubertuse OpenSSL::Test qw/:DEFAULT with bldtop_file bldtop_dir srctop_file srctop_dir cmdstr data_file/; 17*e0c4386eSCy Schubertuse OpenSSL::Test::Utils; 18*e0c4386eSCy Schubert 19*e0c4386eSCy SchubertBEGIN { 20*e0c4386eSCy Schubertsetup("test_ssl_old"); 21*e0c4386eSCy Schubert} 22*e0c4386eSCy Schubert 23*e0c4386eSCy Schubertuse lib srctop_dir('Configurations'); 24*e0c4386eSCy Schubertuse lib bldtop_dir('.'); 25*e0c4386eSCy Schubert 26*e0c4386eSCy Schubertmy $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); 27*e0c4386eSCy Schubertmy ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_psk, 28*e0c4386eSCy Schubert $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2, $no_tls1_3, 29*e0c4386eSCy Schubert $no_dtls, $no_dtls1, $no_dtls1_2, $no_ct) = 30*e0c4386eSCy Schubert anydisabled qw/rsa dsa dh ec psk 31*e0c4386eSCy Schubert ssl3 tls1 tls1_1 tls1_2 tls1_3 32*e0c4386eSCy Schubert dtls dtls1 dtls1_2 ct/; 33*e0c4386eSCy Schubert#If ec and dh are disabled then don't use TLSv1.3 34*e0c4386eSCy Schubert$no_tls1_3 = 1 if (!$no_tls1_3 && $no_ec && $no_dh); 35*e0c4386eSCy Schubertmy $no_anytls = alldisabled(available_protocols("tls")); 36*e0c4386eSCy Schubertmy $no_anydtls = alldisabled(available_protocols("dtls")); 37*e0c4386eSCy Schubert 38*e0c4386eSCy Schubertplan skip_all => "No SSL/TLS/DTLS protocol is support by this OpenSSL build" 39*e0c4386eSCy Schubert if $no_anytls && $no_anydtls; 40*e0c4386eSCy Schubert 41*e0c4386eSCy Schubertmy $digest = "-sha1"; 42*e0c4386eSCy Schubertmy @reqcmd = ("openssl", "req"); 43*e0c4386eSCy Schubertmy @x509cmd = ("openssl", "x509", $digest); 44*e0c4386eSCy Schubertmy @verifycmd = ("openssl", "verify"); 45*e0c4386eSCy Schubertmy @genpkeycmd = ("openssl", "genpkey"); 46*e0c4386eSCy Schubertmy $dummycnf = srctop_file("apps", "openssl.cnf"); 47*e0c4386eSCy Schubert 48*e0c4386eSCy Schubertmy $cnf = srctop_file("test", "ca-and-certs.cnf"); 49*e0c4386eSCy Schubertmy $CAkey = srctop_file("test", "certs", "ca-key.pem"); # "keyCA.ss" 50*e0c4386eSCy Schubertmy $CAcert="certCA.ss"; 51*e0c4386eSCy Schubertmy $CAserial="certCA.srl"; 52*e0c4386eSCy Schubertmy $CAreq="reqCA.ss"; 53*e0c4386eSCy Schubertmy $CAreq2="req2CA.ss"; # temp 54*e0c4386eSCy Schubertmy $Ukey = srctop_file("test", "certs", "ee-key.pem"); # "keyU.ss"; 55*e0c4386eSCy Schubertmy $Ureq="reqU.ss"; 56*e0c4386eSCy Schubertmy $Ucert="certU.ss"; 57*e0c4386eSCy Schubertmy $Dkey="keyD.ss"; 58*e0c4386eSCy Schubertmy $Dreq="reqD.ss"; 59*e0c4386eSCy Schubertmy $Dcert="certD.ss"; 60*e0c4386eSCy Schubertmy $Ekey="keyE.ss"; 61*e0c4386eSCy Schubertmy $Ereq="reqE.ss"; 62*e0c4386eSCy Schubertmy $Ecert="certE.ss"; 63*e0c4386eSCy Schubert 64*e0c4386eSCy Schubertmy $proxycnf=srctop_file("test", "proxy.cnf"); 65*e0c4386eSCy Schubertmy $P1key= srctop_file("test", "certs", "alt1-key.pem"); # "keyP1.ss"; 66*e0c4386eSCy Schubertmy $P1req="reqP1.ss"; 67*e0c4386eSCy Schubertmy $P1cert="certP1.ss"; 68*e0c4386eSCy Schubertmy $P1intermediate="tmp_intP1.ss"; 69*e0c4386eSCy Schubertmy $P2key= srctop_file("test", "certs", "alt2-key.pem"); # "keyP2.ss"; 70*e0c4386eSCy Schubertmy $P2req="reqP2.ss"; 71*e0c4386eSCy Schubertmy $P2cert="certP2.ss"; 72*e0c4386eSCy Schubertmy $P2intermediate="tmp_intP2.ss"; 73*e0c4386eSCy Schubert 74*e0c4386eSCy Schubertmy $server_sess="server.ss"; 75*e0c4386eSCy Schubertmy $client_sess="client.ss"; 76*e0c4386eSCy Schubert 77*e0c4386eSCy Schubert# ssl_old_test.c is deprecated in favour of the new framework in ssl_test.c 78*e0c4386eSCy Schubert# If you're adding tests here, you probably want to convert them to the 79*e0c4386eSCy Schubert# new format in ssl_test.c and add recipes to 80-test_ssl_new.t instead. 80*e0c4386eSCy Schubertplan tests => 81*e0c4386eSCy Schubert ($no_fips ? 0 : 5) # testssl with fips provider 82*e0c4386eSCy Schubert + 1 # For testss 83*e0c4386eSCy Schubert + 5 # For the testssl with default provider 84*e0c4386eSCy Schubert ; 85*e0c4386eSCy Schubert 86*e0c4386eSCy Schubertsubtest 'test_ss' => sub { 87*e0c4386eSCy Schubert if (testss()) { 88*e0c4386eSCy Schubert open OUT, ">", "intP1.ss"; 89*e0c4386eSCy Schubert copy($CAcert, \*OUT); copy($Ucert, \*OUT); 90*e0c4386eSCy Schubert close OUT; 91*e0c4386eSCy Schubert 92*e0c4386eSCy Schubert open OUT, ">", "intP2.ss"; 93*e0c4386eSCy Schubert copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT); 94*e0c4386eSCy Schubert close OUT; 95*e0c4386eSCy Schubert } 96*e0c4386eSCy Schubert}; 97*e0c4386eSCy Schubert 98*e0c4386eSCy Schubertnote('test_ssl_old -- key U'); 99*e0c4386eSCy Schubertmy $configfile = srctop_file("test","default-and-legacy.cnf"); 100*e0c4386eSCy Schubertif (disabled("legacy")) { 101*e0c4386eSCy Schubert $configfile = srctop_file("test","default.cnf"); 102*e0c4386eSCy Schubert} 103*e0c4386eSCy Schubert 104*e0c4386eSCy Schuberttestssl($Ukey, $Ucert, $CAcert, "default", $configfile); 105*e0c4386eSCy Schubertunless ($no_fips) { 106*e0c4386eSCy Schubert testssl($Ukey, $Ucert, $CAcert, "fips", 107*e0c4386eSCy Schubert srctop_file("test","fips-and-base.cnf")); 108*e0c4386eSCy Schubert} 109*e0c4386eSCy Schubert 110*e0c4386eSCy Schubert# ----------- 111*e0c4386eSCy Schubert# subtest functions 112*e0c4386eSCy Schubertsub testss { 113*e0c4386eSCy Schubert my @req_dsa = ("-newkey", 114*e0c4386eSCy Schubert "dsa:".data_file("dsa2048.pem")); 115*e0c4386eSCy Schubert my $dsaparams = data_file("dsa2048.pem"); 116*e0c4386eSCy Schubert my @req_new; 117*e0c4386eSCy Schubert if ($no_rsa) { 118*e0c4386eSCy Schubert @req_new = @req_dsa; 119*e0c4386eSCy Schubert } else { 120*e0c4386eSCy Schubert @req_new = ("-new"); 121*e0c4386eSCy Schubert } 122*e0c4386eSCy Schubert 123*e0c4386eSCy Schubert plan tests => 17; 124*e0c4386eSCy Schubert 125*e0c4386eSCy Schubert SKIP: { 126*e0c4386eSCy Schubert skip 'failure', 16 unless 127*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $cnf, 128*e0c4386eSCy Schubert "-out", $CAreq, "-key", $CAkey, 129*e0c4386eSCy Schubert @req_new])), 130*e0c4386eSCy Schubert 'make cert request'); 131*e0c4386eSCy Schubert 132*e0c4386eSCy Schubert skip 'failure', 15 unless 133*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30", 134*e0c4386eSCy Schubert "-req", "-out", $CAcert, "-signkey", $CAkey, 135*e0c4386eSCy Schubert "-extfile", $cnf, "-extensions", "v3_ca"], 136*e0c4386eSCy Schubert stdout => "err.ss")), 137*e0c4386eSCy Schubert 'convert request into self-signed cert'); 138*e0c4386eSCy Schubert 139*e0c4386eSCy Schubert skip 'failure', 14 unless 140*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-in", $CAcert, 141*e0c4386eSCy Schubert "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2], 142*e0c4386eSCy Schubert stdout => "err.ss")), 143*e0c4386eSCy Schubert 'convert cert into a cert request'); 144*e0c4386eSCy Schubert 145*e0c4386eSCy Schubert skip 'failure', 13 unless 146*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $dummycnf, 147*e0c4386eSCy Schubert "-verify", "-in", $CAreq, "-noout"])), 148*e0c4386eSCy Schubert 'verify request 1'); 149*e0c4386eSCy Schubert 150*e0c4386eSCy Schubert 151*e0c4386eSCy Schubert skip 'failure', 12 unless 152*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $dummycnf, 153*e0c4386eSCy Schubert "-verify", "-in", $CAreq2, "-noout"])), 154*e0c4386eSCy Schubert 'verify request 2'); 155*e0c4386eSCy Schubert 156*e0c4386eSCy Schubert skip 'failure', 11 unless 157*e0c4386eSCy Schubert ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])), 158*e0c4386eSCy Schubert 'verify signature'); 159*e0c4386eSCy Schubert 160*e0c4386eSCy Schubert skip 'failure', 10 unless 161*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $cnf, "-section", "userreq", 162*e0c4386eSCy Schubert "-out", $Ureq, "-key", $Ukey, @req_new], 163*e0c4386eSCy Schubert stdout => "err.ss")), 164*e0c4386eSCy Schubert 'make a user cert request'); 165*e0c4386eSCy Schubert 166*e0c4386eSCy Schubert skip 'failure', 9 unless 167*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30", 168*e0c4386eSCy Schubert "-req", "-out", $Ucert, 169*e0c4386eSCy Schubert "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial, 170*e0c4386eSCy Schubert "-extfile", $cnf, "-extensions", "v3_ee"], 171*e0c4386eSCy Schubert stdout => "err.ss")) 172*e0c4386eSCy Schubert && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])), 173*e0c4386eSCy Schubert 'sign user cert request'); 174*e0c4386eSCy Schubert 175*e0c4386eSCy Schubert skip 'failure', 8 unless 176*e0c4386eSCy Schubert ok(run(app([@x509cmd, 177*e0c4386eSCy Schubert "-subject", "-issuer", "-startdate", "-enddate", 178*e0c4386eSCy Schubert "-noout", "-in", $Ucert])), 179*e0c4386eSCy Schubert 'Certificate details'); 180*e0c4386eSCy Schubert 181*e0c4386eSCy Schubert skip 'failure', 7 unless 182*e0c4386eSCy Schubert subtest 'DSA certificate creation' => sub { 183*e0c4386eSCy Schubert plan skip_all => "skipping DSA certificate creation" 184*e0c4386eSCy Schubert if $no_dsa; 185*e0c4386eSCy Schubert 186*e0c4386eSCy Schubert plan tests => 5; 187*e0c4386eSCy Schubert 188*e0c4386eSCy Schubert SKIP: { 189*e0c4386eSCy Schubert $ENV{CN2} = "DSA Certificate"; 190*e0c4386eSCy Schubert skip 'failure', 4 unless 191*e0c4386eSCy Schubert ok(run(app([@genpkeycmd, "-out", $Dkey, 192*e0c4386eSCy Schubert "-paramfile", $dsaparams], 193*e0c4386eSCy Schubert stdout => "err.ss")), 194*e0c4386eSCy Schubert "make a DSA key"); 195*e0c4386eSCy Schubert skip 'failure', 3 unless 196*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-new", "-config", $cnf, 197*e0c4386eSCy Schubert "-section", "userreq", 198*e0c4386eSCy Schubert "-out", $Dreq, "-key", $Dkey], 199*e0c4386eSCy Schubert stdout => "err.ss")), 200*e0c4386eSCy Schubert "make a DSA user cert request"); 201*e0c4386eSCy Schubert skip 'failure', 2 unless 202*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-CAcreateserial", 203*e0c4386eSCy Schubert "-in", $Dreq, 204*e0c4386eSCy Schubert "-days", "30", 205*e0c4386eSCy Schubert "-req", 206*e0c4386eSCy Schubert "-out", $Dcert, 207*e0c4386eSCy Schubert "-CA", $CAcert, "-CAkey", $CAkey, 208*e0c4386eSCy Schubert "-CAserial", $CAserial, 209*e0c4386eSCy Schubert "-extfile", $cnf, 210*e0c4386eSCy Schubert "-extensions", "v3_ee_dsa"], 211*e0c4386eSCy Schubert stdout => "err.ss")), 212*e0c4386eSCy Schubert "sign DSA user cert request"); 213*e0c4386eSCy Schubert skip 'failure', 1 unless 214*e0c4386eSCy Schubert ok(run(app([@verifycmd, "-CAfile", $CAcert, $Dcert])), 215*e0c4386eSCy Schubert "verify DSA user cert"); 216*e0c4386eSCy Schubert skip 'failure', 0 unless 217*e0c4386eSCy Schubert ok(run(app([@x509cmd, 218*e0c4386eSCy Schubert "-subject", "-issuer", 219*e0c4386eSCy Schubert "-startdate", "-enddate", "-noout", 220*e0c4386eSCy Schubert "-in", $Dcert])), 221*e0c4386eSCy Schubert "DSA Certificate details"); 222*e0c4386eSCy Schubert } 223*e0c4386eSCy Schubert }; 224*e0c4386eSCy Schubert 225*e0c4386eSCy Schubert skip 'failure', 6 unless 226*e0c4386eSCy Schubert subtest 'ECDSA/ECDH certificate creation' => sub { 227*e0c4386eSCy Schubert plan skip_all => "skipping ECDSA/ECDH certificate creation" 228*e0c4386eSCy Schubert if $no_ec; 229*e0c4386eSCy Schubert 230*e0c4386eSCy Schubert plan tests => 5; 231*e0c4386eSCy Schubert 232*e0c4386eSCy Schubert SKIP: { 233*e0c4386eSCy Schubert $ENV{CN2} = "ECDSA Certificate"; 234*e0c4386eSCy Schubert skip 'failure', 4 unless 235*e0c4386eSCy Schubert ok(run(app(["openssl", "genpkey", "-genparam", 236*e0c4386eSCy Schubert "-algorithm", "EC", 237*e0c4386eSCy Schubert "-pkeyopt", "ec_paramgen_curve:P-256", 238*e0c4386eSCy Schubert "-pkeyopt", "ec_param_enc:named_curve", 239*e0c4386eSCy Schubert "-out", "ecp.ss"])), 240*e0c4386eSCy Schubert "make EC parameters"); 241*e0c4386eSCy Schubert skip 'failure', 3 unless 242*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $cnf, 243*e0c4386eSCy Schubert "-section", "userreq", 244*e0c4386eSCy Schubert "-out", $Ereq, "-keyout", $Ekey, 245*e0c4386eSCy Schubert "-newkey", "ec:ecp.ss"], 246*e0c4386eSCy Schubert stdout => "err.ss")), 247*e0c4386eSCy Schubert "make a ECDSA/ECDH user cert request"); 248*e0c4386eSCy Schubert skip 'failure', 2 unless 249*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-CAcreateserial", 250*e0c4386eSCy Schubert "-in", $Ereq, 251*e0c4386eSCy Schubert "-days", "30", 252*e0c4386eSCy Schubert "-req", 253*e0c4386eSCy Schubert "-out", $Ecert, 254*e0c4386eSCy Schubert "-CA", $CAcert, "-CAkey", $CAkey, 255*e0c4386eSCy Schubert "-CAserial", $CAserial, 256*e0c4386eSCy Schubert "-extfile", $cnf, 257*e0c4386eSCy Schubert "-extensions", "v3_ee_ec"], 258*e0c4386eSCy Schubert stdout => "err.ss")), 259*e0c4386eSCy Schubert "sign ECDSA/ECDH user cert request"); 260*e0c4386eSCy Schubert skip 'failure', 1 unless 261*e0c4386eSCy Schubert ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])), 262*e0c4386eSCy Schubert "verify ECDSA/ECDH user cert"); 263*e0c4386eSCy Schubert skip 'failure', 0 unless 264*e0c4386eSCy Schubert ok(run(app([@x509cmd, 265*e0c4386eSCy Schubert "-subject", "-issuer", 266*e0c4386eSCy Schubert "-startdate", "-enddate", "-noout", 267*e0c4386eSCy Schubert "-in", $Ecert])), 268*e0c4386eSCy Schubert "ECDSA Certificate details"); 269*e0c4386eSCy Schubert } 270*e0c4386eSCy Schubert }; 271*e0c4386eSCy Schubert 272*e0c4386eSCy Schubert skip 'failure', 5 unless 273*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $proxycnf, 274*e0c4386eSCy Schubert "-out", $P1req, "-key", $P1key, @req_new], 275*e0c4386eSCy Schubert stdout => "err.ss")), 276*e0c4386eSCy Schubert 'make a proxy cert request'); 277*e0c4386eSCy Schubert 278*e0c4386eSCy Schubert 279*e0c4386eSCy Schubert skip 'failure', 4 unless 280*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30", 281*e0c4386eSCy Schubert "-req", "-out", $P1cert, 282*e0c4386eSCy Schubert "-CA", $Ucert, "-CAkey", $Ukey, 283*e0c4386eSCy Schubert "-extfile", $proxycnf, "-extensions", "proxy"], 284*e0c4386eSCy Schubert stdout => "err.ss")), 285*e0c4386eSCy Schubert 'sign proxy with user cert'); 286*e0c4386eSCy Schubert 287*e0c4386eSCy Schubert copy($Ucert, $P1intermediate); 288*e0c4386eSCy Schubert run(app([@verifycmd, "-CAfile", $CAcert, 289*e0c4386eSCy Schubert "-untrusted", $P1intermediate, $P1cert])); 290*e0c4386eSCy Schubert ok(run(app([@x509cmd, 291*e0c4386eSCy Schubert "-subject", "-issuer", "-startdate", "-enddate", 292*e0c4386eSCy Schubert "-noout", "-in", $P1cert])), 293*e0c4386eSCy Schubert 'Certificate details'); 294*e0c4386eSCy Schubert 295*e0c4386eSCy Schubert skip 'failure', 2 unless 296*e0c4386eSCy Schubert ok(run(app([@reqcmd, "-config", $proxycnf, "-section", "proxy2_req", 297*e0c4386eSCy Schubert "-out", $P2req, "-key", $P2key, 298*e0c4386eSCy Schubert @req_new], 299*e0c4386eSCy Schubert stdout => "err.ss")), 300*e0c4386eSCy Schubert 'make another proxy cert request'); 301*e0c4386eSCy Schubert 302*e0c4386eSCy Schubert 303*e0c4386eSCy Schubert skip 'failure', 1 unless 304*e0c4386eSCy Schubert ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30", 305*e0c4386eSCy Schubert "-req", "-out", $P2cert, 306*e0c4386eSCy Schubert "-CA", $P1cert, "-CAkey", $P1key, 307*e0c4386eSCy Schubert "-extfile", $proxycnf, "-extensions", "proxy_2"], 308*e0c4386eSCy Schubert stdout => "err.ss")), 309*e0c4386eSCy Schubert 'sign second proxy cert request with the first proxy cert'); 310*e0c4386eSCy Schubert 311*e0c4386eSCy Schubert 312*e0c4386eSCy Schubert open OUT, ">", $P2intermediate; 313*e0c4386eSCy Schubert copy($Ucert, \*OUT); copy($P1cert, \*OUT); 314*e0c4386eSCy Schubert close OUT; 315*e0c4386eSCy Schubert run(app([@verifycmd, "-CAfile", $CAcert, 316*e0c4386eSCy Schubert "-untrusted", $P2intermediate, $P2cert])); 317*e0c4386eSCy Schubert ok(run(app([@x509cmd, 318*e0c4386eSCy Schubert "-subject", "-issuer", "-startdate", "-enddate", 319*e0c4386eSCy Schubert "-noout", "-in", $P2cert])), 320*e0c4386eSCy Schubert 'Certificate details'); 321*e0c4386eSCy Schubert } 322*e0c4386eSCy Schubert} 323*e0c4386eSCy Schubert 324*e0c4386eSCy Schubertsub testssl { 325*e0c4386eSCy Schubert my ($key, $cert, $CAtmp, $provider, $configfile) = @_; 326*e0c4386eSCy Schubert my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs")); 327*e0c4386eSCy Schubert my @providerflags = ("-provider", $provider); 328*e0c4386eSCy Schubert 329*e0c4386eSCy Schubert if ($provider eq "default" && !disabled("legacy")) { 330*e0c4386eSCy Schubert push @providerflags, "-provider", "legacy"; 331*e0c4386eSCy Schubert } 332*e0c4386eSCy Schubert 333*e0c4386eSCy Schubert my @ssltest = ("ssl_old_test", 334*e0c4386eSCy Schubert "-s_key", $key, "-s_cert", $cert, 335*e0c4386eSCy Schubert "-c_key", $key, "-c_cert", $cert, 336*e0c4386eSCy Schubert "-config", $configfile, 337*e0c4386eSCy Schubert @providerflags); 338*e0c4386eSCy Schubert 339*e0c4386eSCy Schubert 340*e0c4386eSCy Schubert my $serverinfo = srctop_file("test","serverinfo.pem"); 341*e0c4386eSCy Schubert 342*e0c4386eSCy Schubert my $dsa_cert = 0; 343*e0c4386eSCy Schubert if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert, 344*e0c4386eSCy Schubert "-text", "-noout"]), capture => 1)) { 345*e0c4386eSCy Schubert $dsa_cert = 1; 346*e0c4386eSCy Schubert } 347*e0c4386eSCy Schubert 348*e0c4386eSCy Schubert 349*e0c4386eSCy Schubert subtest 'standard SSL tests' => sub { 350*e0c4386eSCy Schubert ###################################################################### 351*e0c4386eSCy Schubert plan tests => 19; 352*e0c4386eSCy Schubert 353*e0c4386eSCy Schubert SKIP: { 354*e0c4386eSCy Schubert skip "SSLv3 is not supported by this OpenSSL build", 4 355*e0c4386eSCy Schubert if disabled("ssl3"); 356*e0c4386eSCy Schubert 357*e0c4386eSCy Schubert skip "SSLv3 is not supported by the FIPS provider", 4 358*e0c4386eSCy Schubert if $provider eq "fips"; 359*e0c4386eSCy Schubert 360*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-ssl3"])), 361*e0c4386eSCy Schubert 'test sslv3 via BIO pair'); 362*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA])), 363*e0c4386eSCy Schubert 'test sslv3 with server authentication via BIO pair'); 364*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA])), 365*e0c4386eSCy Schubert 'test sslv3 with client authentication via BIO pair'); 366*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA])), 367*e0c4386eSCy Schubert 'test sslv3 with both server and client authentication via BIO pair'); 368*e0c4386eSCy Schubert } 369*e0c4386eSCy Schubert 370*e0c4386eSCy Schubert SKIP: { 371*e0c4386eSCy Schubert skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1 372*e0c4386eSCy Schubert if $no_anytls; 373*e0c4386eSCy Schubert 374*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair"])), 375*e0c4386eSCy Schubert 'test sslv2/sslv3 via BIO pair'); 376*e0c4386eSCy Schubert } 377*e0c4386eSCy Schubert 378*e0c4386eSCy Schubert SKIP: { 379*e0c4386eSCy Schubert skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 14 380*e0c4386eSCy Schubert if $no_anytls; 381*e0c4386eSCy Schubert 382*e0c4386eSCy Schubert SKIP: { 383*e0c4386eSCy Schubert skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert; 384*e0c4386eSCy Schubert 385*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe"])), 386*e0c4386eSCy Schubert 'test sslv2/sslv3 w/o (EC)DHE via BIO pair'); 387*e0c4386eSCy Schubert } 388*e0c4386eSCy Schubert 389*e0c4386eSCy Schubert SKIP: { 390*e0c4386eSCy Schubert skip "skipping dhe1024dsa test", 1 391*e0c4386eSCy Schubert if ($no_dh); 392*e0c4386eSCy Schubert 393*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v"])), 394*e0c4386eSCy Schubert 'test sslv2/sslv3 with 1024bit DHE via BIO pair'); 395*e0c4386eSCy Schubert } 396*e0c4386eSCy Schubert 397*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA])), 398*e0c4386eSCy Schubert 'test sslv2/sslv3 with server authentication'); 399*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA])), 400*e0c4386eSCy Schubert 'test sslv2/sslv3 with client authentication via BIO pair'); 401*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA])), 402*e0c4386eSCy Schubert 'test sslv2/sslv3 with both client and server authentication via BIO pair'); 403*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA])), 404*e0c4386eSCy Schubert 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify'); 405*e0c4386eSCy Schubert 406*e0c4386eSCy Schubert SKIP: { 407*e0c4386eSCy Schubert skip "No IPv4 available on this machine", 4 408*e0c4386eSCy Schubert unless !disabled("sock") && have_IPv4(); 409*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv4"])), 410*e0c4386eSCy Schubert 'test TLS via IPv4'); 411*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv4", "-client_ktls"])), 412*e0c4386eSCy Schubert 'test TLS via IPv4 + ktls(client)'); 413*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv4", "-server_ktls"])), 414*e0c4386eSCy Schubert 'test TLS via IPv4 + ktls(server)'); 415*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv4", "-client_ktls", "-server_ktls"])), 416*e0c4386eSCy Schubert 'test TLS via IPv4 + ktls'); 417*e0c4386eSCy Schubert } 418*e0c4386eSCy Schubert 419*e0c4386eSCy Schubert SKIP: { 420*e0c4386eSCy Schubert skip "No IPv6 available on this machine", 4 421*e0c4386eSCy Schubert unless !disabled("sock") && have_IPv6(); 422*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv6"])), 423*e0c4386eSCy Schubert 'test TLS via IPv6'); 424*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv6", "-client_ktls"])), 425*e0c4386eSCy Schubert 'test TLS via IPv6 + ktls(client)'); 426*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv6", "-server_ktls"])), 427*e0c4386eSCy Schubert 'test TLS via IPv6 + ktls(client)'); 428*e0c4386eSCy Schubert ok(run(test([@ssltest, "-ipv6", "-client_ktls", "-server_ktls"])), 429*e0c4386eSCy Schubert 'test TLS via IPv6 + ktls'); 430*e0c4386eSCy Schubert } 431*e0c4386eSCy Schubert } 432*e0c4386eSCy Schubert }; 433*e0c4386eSCy Schubert 434*e0c4386eSCy Schubert subtest "Testing ciphersuites" => sub { 435*e0c4386eSCy Schubert 436*e0c4386eSCy Schubert my @exkeys = (); 437*e0c4386eSCy Schubert my $ciphers = '-PSK:-SRP:@SECLEVEL=0'; 438*e0c4386eSCy Schubert 439*e0c4386eSCy Schubert if (!$no_dsa) { 440*e0c4386eSCy Schubert push @exkeys, "-s_cert", "certD.ss", "-s_key", $Dkey; 441*e0c4386eSCy Schubert } 442*e0c4386eSCy Schubert 443*e0c4386eSCy Schubert if (!$no_ec) { 444*e0c4386eSCy Schubert push @exkeys, "-s_cert", "certE.ss", "-s_key", $Ekey; 445*e0c4386eSCy Schubert } 446*e0c4386eSCy Schubert 447*e0c4386eSCy Schubert my @protocols = (); 448*e0c4386eSCy Schubert # We only use the flags that ssl_old_test understands 449*e0c4386eSCy Schubert push @protocols, "-tls1_3" unless $no_tls1_3; 450*e0c4386eSCy Schubert push @protocols, "-tls1_2" unless $no_tls1_2; 451*e0c4386eSCy Schubert push @protocols, "-tls1" unless $no_tls1 || $provider eq "fips"; 452*e0c4386eSCy Schubert push @protocols, "-ssl3" unless $no_ssl3 || $provider eq "fips"; 453*e0c4386eSCy Schubert my $protocolciphersuitecount = 0; 454*e0c4386eSCy Schubert my %ciphersuites = (); 455*e0c4386eSCy Schubert my %ciphersstatus = (); 456*e0c4386eSCy Schubert #There's no "-config" option to the ciphers command so we set the 457*e0c4386eSCy Schubert #environment variable instead 458*e0c4386eSCy Schubert my $opensslconf = $ENV{OPENSSL_CONF}; 459*e0c4386eSCy Schubert $ENV{OPENSSL_CONF} = $configfile; 460*e0c4386eSCy Schubert foreach my $protocol (@protocols) { 461*e0c4386eSCy Schubert my $ciphersstatus = undef; 462*e0c4386eSCy Schubert my @ciphers = run(app(["openssl", "ciphers", "-s", $protocol, 463*e0c4386eSCy Schubert @providerflags, 464*e0c4386eSCy Schubert "ALL:$ciphers"]), 465*e0c4386eSCy Schubert capture => 1, statusvar => \$ciphersstatus); 466*e0c4386eSCy Schubert $ciphersstatus{$protocol} = $ciphersstatus; 467*e0c4386eSCy Schubert if ($ciphersstatus) { 468*e0c4386eSCy Schubert $ciphersuites{$protocol} = [ map { s|\R||; split(/:/, $_) } 469*e0c4386eSCy Schubert @ciphers ]; 470*e0c4386eSCy Schubert $protocolciphersuitecount += scalar @{$ciphersuites{$protocol}}; 471*e0c4386eSCy Schubert } 472*e0c4386eSCy Schubert } 473*e0c4386eSCy Schubert $ENV{OPENSSL_CONF} = $opensslconf; 474*e0c4386eSCy Schubert 475*e0c4386eSCy Schubert plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build" 476*e0c4386eSCy Schubert if $protocolciphersuitecount + scalar(keys %ciphersuites) == 0; 477*e0c4386eSCy Schubert 478*e0c4386eSCy Schubert # The count of protocols is because in addition to the ciphersuites 479*e0c4386eSCy Schubert # we got above, we're running a weak DH test for each protocol (except 480*e0c4386eSCy Schubert # TLSv1.3) 481*e0c4386eSCy Schubert my $testcount = scalar(@protocols) + $protocolciphersuitecount 482*e0c4386eSCy Schubert + scalar(keys %ciphersuites); 483*e0c4386eSCy Schubert $testcount-- unless $no_tls1_3; 484*e0c4386eSCy Schubert plan tests => $testcount; 485*e0c4386eSCy Schubert 486*e0c4386eSCy Schubert foreach my $protocol (@protocols) { 487*e0c4386eSCy Schubert ok($ciphersstatus{$protocol}, "Getting ciphers for $protocol"); 488*e0c4386eSCy Schubert } 489*e0c4386eSCy Schubert 490*e0c4386eSCy Schubert foreach my $protocol (sort keys %ciphersuites) { 491*e0c4386eSCy Schubert note "Testing ciphersuites for $protocol"; 492*e0c4386eSCy Schubert # ssl_old_test doesn't know -tls1_3, but that's fine, since that's 493*e0c4386eSCy Schubert # the default choice if TLSv1.3 enabled 494*e0c4386eSCy Schubert my $flag = $protocol eq "-tls1_3" ? "" : $protocol; 495*e0c4386eSCy Schubert my $ciphersuites = ""; 496*e0c4386eSCy Schubert foreach my $cipher (@{$ciphersuites{$protocol}}) { 497*e0c4386eSCy Schubert if ($protocol eq "-ssl3" && $cipher =~ /ECDH/ ) { 498*e0c4386eSCy Schubert note "*****SKIPPING $protocol $cipher"; 499*e0c4386eSCy Schubert ok(1); 500*e0c4386eSCy Schubert } else { 501*e0c4386eSCy Schubert if ($protocol eq "-tls1_3") { 502*e0c4386eSCy Schubert $ciphersuites = $cipher; 503*e0c4386eSCy Schubert $cipher = ""; 504*e0c4386eSCy Schubert } else { 505*e0c4386eSCy Schubert $cipher = $cipher.':@SECLEVEL=0'; 506*e0c4386eSCy Schubert } 507*e0c4386eSCy Schubert ok(run(test([@ssltest, @exkeys, "-cipher", 508*e0c4386eSCy Schubert $cipher, 509*e0c4386eSCy Schubert "-ciphersuites", $ciphersuites, 510*e0c4386eSCy Schubert $flag || ()])), 511*e0c4386eSCy Schubert "Testing $cipher"); 512*e0c4386eSCy Schubert } 513*e0c4386eSCy Schubert } 514*e0c4386eSCy Schubert next if $protocol eq "-tls1_3"; 515*e0c4386eSCy Schubert 516*e0c4386eSCy Schubert SKIP: { 517*e0c4386eSCy Schubert skip "skipping dhe512 test", 1 518*e0c4386eSCy Schubert if ($no_dh); 519*e0c4386eSCy Schubert 520*e0c4386eSCy Schubert is(run(test([@ssltest, 521*e0c4386eSCy Schubert "-s_cipher", "EDH", 522*e0c4386eSCy Schubert "-c_cipher", 'EDH:@SECLEVEL=1', 523*e0c4386eSCy Schubert "-dhe512", 524*e0c4386eSCy Schubert $protocol])), 0, 525*e0c4386eSCy Schubert "testing connection with weak DH, expecting failure"); 526*e0c4386eSCy Schubert } 527*e0c4386eSCy Schubert } 528*e0c4386eSCy Schubert }; 529*e0c4386eSCy Schubert 530*e0c4386eSCy Schubert subtest 'RSA/(EC)DHE/PSK tests' => sub { 531*e0c4386eSCy Schubert ###################################################################### 532*e0c4386eSCy Schubert 533*e0c4386eSCy Schubert plan tests => 10; 534*e0c4386eSCy Schubert 535*e0c4386eSCy Schubert SKIP: { 536*e0c4386eSCy Schubert skip "TLSv1.0 is not supported by this OpenSSL build", 6 537*e0c4386eSCy Schubert if $no_tls1 || $provider eq "fips"; 538*e0c4386eSCy Schubert 539*e0c4386eSCy Schubert SKIP: { 540*e0c4386eSCy Schubert skip "skipping anonymous DH tests", 1 541*e0c4386eSCy Schubert if ($no_dh); 542*e0c4386eSCy Schubert 543*e0c4386eSCy Schubert ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time"])), 544*e0c4386eSCy Schubert 'test tlsv1 with 1024bit anonymous DH, multiple handshakes'); 545*e0c4386eSCy Schubert } 546*e0c4386eSCy Schubert 547*e0c4386eSCy Schubert SKIP: { 548*e0c4386eSCy Schubert skip "skipping RSA tests", 2 549*e0c4386eSCy Schubert if $no_rsa; 550*e0c4386eSCy Schubert 551*e0c4386eSCy Schubert ok(run(test(["ssl_old_test", "-provider", "default", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time"])), 552*e0c4386eSCy Schubert 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes'); 553*e0c4386eSCy Schubert 554*e0c4386eSCy Schubert skip "skipping RSA+DHE tests", 1 555*e0c4386eSCy Schubert if $no_dh; 556*e0c4386eSCy Schubert 557*e0c4386eSCy Schubert ok(run(test(["ssl_old_test", "-provider", "default", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time"])), 558*e0c4386eSCy Schubert 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes'); 559*e0c4386eSCy Schubert } 560*e0c4386eSCy Schubert 561*e0c4386eSCy Schubert SKIP: { 562*e0c4386eSCy Schubert skip "skipping PSK tests", 2 563*e0c4386eSCy Schubert if ($no_psk); 564*e0c4386eSCy Schubert 565*e0c4386eSCy Schubert ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123"])), 566*e0c4386eSCy Schubert 'test tls1 with PSK'); 567*e0c4386eSCy Schubert 568*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123"])), 569*e0c4386eSCy Schubert 'test tls1 with PSK via BIO pair'); 570*e0c4386eSCy Schubert } 571*e0c4386eSCy Schubert 572*e0c4386eSCy Schubert SKIP: { 573*e0c4386eSCy Schubert skip "skipping auto DH PSK tests", 1 574*e0c4386eSCy Schubert if ($no_dh || $no_psk); 575*e0c4386eSCy Schubert 576*e0c4386eSCy Schubert ok(run(test(['ssl_old_test', '-psk', '0102030405', '-cipher', '@SECLEVEL=2:DHE-PSK-AES128-CCM'])), 577*e0c4386eSCy Schubert 'test auto DH meets security strength'); 578*e0c4386eSCy Schubert } 579*e0c4386eSCy Schubert } 580*e0c4386eSCy Schubert 581*e0c4386eSCy Schubert SKIP: { 582*e0c4386eSCy Schubert skip "TLSv1.1 is not supported by this OpenSSL build", 4 583*e0c4386eSCy Schubert if $no_tls1_1; 584*e0c4386eSCy Schubert 585*e0c4386eSCy Schubert SKIP: { 586*e0c4386eSCy Schubert skip "skipping auto DHE PSK test at SECLEVEL 3", 1 587*e0c4386eSCy Schubert if ($no_dh || $no_psk); 588*e0c4386eSCy Schubert 589*e0c4386eSCy Schubert ok(run(test(['ssl_old_test', '-tls1_1', '-dhe4096', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:DHE-PSK-AES256-CBC-SHA384'])), 590*e0c4386eSCy Schubert 'test auto DHE PSK meets security strength'); 591*e0c4386eSCy Schubert } 592*e0c4386eSCy Schubert 593*e0c4386eSCy Schubert SKIP: { 594*e0c4386eSCy Schubert skip "skipping auto ECDHE PSK test at SECLEVEL 3", 1 595*e0c4386eSCy Schubert if ($no_ec || $no_psk); 596*e0c4386eSCy Schubert 597*e0c4386eSCy Schubert ok(run(test(['ssl_old_test', '-tls1_1', '-no_dhe', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:ECDHE-PSK-AES256-CBC-SHA384'])), 598*e0c4386eSCy Schubert 'test auto ECDHE PSK meets security strength'); 599*e0c4386eSCy Schubert } 600*e0c4386eSCy Schubert 601*e0c4386eSCy Schubert SKIP: { 602*e0c4386eSCy Schubert skip "skipping no RSA PSK at SECLEVEL 3 test", 1 603*e0c4386eSCy Schubert if ($no_rsa || $no_psk); 604*e0c4386eSCy Schubert 605*e0c4386eSCy Schubert ok(!run(test(['ssl_old_test', '-tls1_1', '-no_dhe', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:RSA-PSK-AES256-CBC-SHA384'])), 606*e0c4386eSCy Schubert 'test auto RSA PSK does not meet security level 3 requirements (PFS)'); 607*e0c4386eSCy Schubert } 608*e0c4386eSCy Schubert 609*e0c4386eSCy Schubert SKIP: { 610*e0c4386eSCy Schubert skip "skipping no PSK at SECLEVEL 3 test", 1 611*e0c4386eSCy Schubert if ($no_psk); 612*e0c4386eSCy Schubert 613*e0c4386eSCy Schubert ok(!run(test(['ssl_old_test', '-tls1_1', '-no_dhe', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:PSK-AES256-CBC-SHA384'])), 614*e0c4386eSCy Schubert 'test auto PSK does not meet security level 3 requirements (PFS)'); 615*e0c4386eSCy Schubert } 616*e0c4386eSCy Schubert } 617*e0c4386eSCy Schubert 618*e0c4386eSCy Schubert }; 619*e0c4386eSCy Schubert 620*e0c4386eSCy Schubert subtest 'Custom Extension tests' => sub { 621*e0c4386eSCy Schubert ###################################################################### 622*e0c4386eSCy Schubert 623*e0c4386eSCy Schubert plan tests => 1; 624*e0c4386eSCy Schubert 625*e0c4386eSCy Schubert SKIP: { 626*e0c4386eSCy Schubert skip "TLSv1.0 is not supported by this OpenSSL build", 1 627*e0c4386eSCy Schubert if $no_tls1 || $provider eq "fips"; 628*e0c4386eSCy Schubert 629*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])), 630*e0c4386eSCy Schubert 'test tls1 with custom extensions'); 631*e0c4386eSCy Schubert } 632*e0c4386eSCy Schubert }; 633*e0c4386eSCy Schubert 634*e0c4386eSCy Schubert subtest 'Serverinfo tests' => sub { 635*e0c4386eSCy Schubert ###################################################################### 636*e0c4386eSCy Schubert 637*e0c4386eSCy Schubert plan tests => 5; 638*e0c4386eSCy Schubert 639*e0c4386eSCy Schubert SKIP: { 640*e0c4386eSCy Schubert skip "TLSv1.0 is not supported by this OpenSSL build", 5 641*e0c4386eSCy Schubert if $no_tls1 || $provider eq "fips"; 642*e0c4386eSCy Schubert 643*e0c4386eSCy Schubert note('echo test tls1 with serverinfo'); 644*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo]))); 645*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"]))); 646*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"]))); 647*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"]))); 648*e0c4386eSCy Schubert ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"]))); 649*e0c4386eSCy Schubert } 650*e0c4386eSCy Schubert }; 651*e0c4386eSCy Schubert} 652