2
0

80-test_ssl_old.t 26 KB

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