1#! /usr/bin/env perl 2# Copyright 2015-2023 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 9 10use strict; 11use warnings; 12 13use File::Spec::Functions qw/canonpath/; 14use File::Copy; 15use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir ok_nofips with/; 16use OpenSSL::Test::Utils; 17 18setup("test_verify"); 19 20sub verify { 21 my ($cert, $purpose, $trusted, $untrusted, @opts) = @_; 22 my @path = qw(test certs); 23 my @args = qw(openssl verify -auth_level 1); 24 push(@args, "-purpose", $purpose) if $purpose ne ""; 25 push(@args, @opts); 26 for (@$trusted) { push(@args, "-trusted", srctop_file(@path, "$_.pem")) } 27 for (@$untrusted) { push(@args, "-untrusted", srctop_file(@path, "$_.pem")) } 28 push(@args, srctop_file(@path, "$cert.pem")); 29 run(app([@args])); 30} 31 32plan tests => 166; 33 34# Canonical success 35ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]), 36 "accept compat trust"); 37 38# Root CA variants 39ok(!verify("ee-cert", "sslserver", [qw(root-nonca)], [qw(ca-cert)]), 40 "fail trusted non-ca root"); 41ok(!verify("ee-cert", "sslserver", [qw(nroot+serverAuth)], [qw(ca-cert)]), 42 "fail server trust non-ca root"); 43ok(!verify("ee-cert", "sslserver", [qw(nroot+anyEKU)], [qw(ca-cert)]), 44 "fail wildcard trust non-ca root"); 45ok(!verify("ee-cert", "sslserver", [qw(root-cert2)], [qw(ca-cert)]), 46 "fail wrong root key"); 47ok(!verify("ee-cert", "sslserver", [qw(root-name2)], [qw(ca-cert)]), 48 "fail wrong root DN"); 49 50# Critical extensions 51 52ok(verify("ee-cert-noncrit-unknown-ext", "", ["root-cert"], ["ca-cert"]), 53 "accept non-critical unknown extension"); 54ok(!verify("ee-cert-crit-unknown-ext", "", ["root-cert"], ["ca-cert"]), 55 "reject critical unknown extension"); 56ok(verify("ee-cert-ocsp-nocheck", "", ["root-cert"], ["ca-cert"]), 57 "accept critical OCSP No Check"); 58 59# Explicit trust/purpose combinations 60# 61ok(verify("ee-cert", "sslserver", [qw(sroot-cert)], [qw(ca-cert)]), 62 "accept server purpose"); 63ok(!verify("ee-cert", "sslserver", [qw(croot-cert)], [qw(ca-cert)]), 64 "fail client purpose"); 65ok(verify("ee-cert", "sslserver", [qw(root+serverAuth)], [qw(ca-cert)]), 66 "accept server trust"); 67ok(verify("ee-cert", "sslserver", [qw(sroot+serverAuth)], [qw(ca-cert)]), 68 "accept server trust with server purpose"); 69ok(verify("ee-cert", "sslserver", [qw(croot+serverAuth)], [qw(ca-cert)]), 70 "accept server trust with client purpose"); 71# Wildcard trust 72ok(verify("ee-cert", "sslserver", [qw(root+anyEKU)], [qw(ca-cert)]), 73 "accept wildcard trust"); 74ok(verify("ee-cert", "sslserver", [qw(sroot+anyEKU)], [qw(ca-cert)]), 75 "accept wildcard trust with server purpose"); 76ok(verify("ee-cert", "sslserver", [qw(croot+anyEKU)], [qw(ca-cert)]), 77 "accept wildcard trust with client purpose"); 78# Inapplicable mistrust 79ok(verify("ee-cert", "sslserver", [qw(root-clientAuth)], [qw(ca-cert)]), 80 "accept client mistrust"); 81ok(verify("ee-cert", "sslserver", [qw(sroot-clientAuth)], [qw(ca-cert)]), 82 "accept client mistrust with server purpose"); 83ok(!verify("ee-cert", "sslserver", [qw(croot-clientAuth)], [qw(ca-cert)]), 84 "fail client mistrust with client purpose"); 85# Inapplicable trust 86ok(!verify("ee-cert", "sslserver", [qw(root+clientAuth)], [qw(ca-cert)]), 87 "fail client trust"); 88ok(!verify("ee-cert", "sslserver", [qw(sroot+clientAuth)], [qw(ca-cert)]), 89 "fail client trust with server purpose"); 90ok(!verify("ee-cert", "sslserver", [qw(croot+clientAuth)], [qw(ca-cert)]), 91 "fail client trust with client purpose"); 92# Server mistrust 93ok(!verify("ee-cert", "sslserver", [qw(root-serverAuth)], [qw(ca-cert)]), 94 "fail rejected EKU"); 95ok(!verify("ee-cert", "sslserver", [qw(sroot-serverAuth)], [qw(ca-cert)]), 96 "fail server mistrust with server purpose"); 97ok(!verify("ee-cert", "sslserver", [qw(croot-serverAuth)], [qw(ca-cert)]), 98 "fail server mistrust with client purpose"); 99# Wildcard mistrust 100ok(!verify("ee-cert", "sslserver", [qw(root-anyEKU)], [qw(ca-cert)]), 101 "fail wildcard mistrust"); 102ok(!verify("ee-cert", "sslserver", [qw(sroot-anyEKU)], [qw(ca-cert)]), 103 "fail wildcard mistrust with server purpose"); 104ok(!verify("ee-cert", "sslserver", [qw(croot-anyEKU)], [qw(ca-cert)]), 105 "fail wildcard mistrust with client purpose"); 106 107# Check that trusted-first is on by setting up paths to different roots 108# depending on whether the intermediate is the trusted or untrusted one. 109# 110ok(verify("ee-cert", "sslserver", [qw(root-serverAuth root-cert2 ca-root2)], 111 [qw(ca-cert)]), 112 "accept trusted-first path"); 113ok(verify("ee-cert", "sslserver", [qw(root-cert root2+serverAuth ca-root2)], 114 [qw(ca-cert)]), 115 "accept trusted-first path with server trust"); 116ok(!verify("ee-cert", "sslserver", [qw(root-cert root2-serverAuth ca-root2)], 117 [qw(ca-cert)]), 118 "fail trusted-first path with server mistrust"); 119ok(!verify("ee-cert", "sslserver", [qw(root-cert root2+clientAuth ca-root2)], 120 [qw(ca-cert)]), 121 "fail trusted-first path with client trust"); 122 123# CA variants 124ok(!verify("ee-cert", "sslserver", [qw(root-cert)], [qw(ca-nonca)]), 125 "fail non-CA untrusted intermediate"); 126ok(!verify("ee-cert", "sslserver", [qw(root-cert)], [qw(ca-nonbc)]), 127 "fail non-CA untrusted intermediate"); 128ok(!verify("ee-cert", "sslserver", [qw(root-cert ca-nonca)], []), 129 "fail non-CA trust-store intermediate"); 130ok(!verify("ee-cert", "sslserver", [qw(root-cert ca-nonbc)], []), 131 "fail non-CA trust-store intermediate"); 132ok(!verify("ee-cert", "sslserver", [qw(root-cert nca+serverAuth)], []), 133 "fail non-CA server trust intermediate"); 134ok(!verify("ee-cert", "sslserver", [qw(root-cert nca+anyEKU)], []), 135 "fail non-CA wildcard trust intermediate"); 136ok(!verify("ee-cert", "sslserver", [qw(root-cert)], [qw(ca-cert2)]), 137 "fail wrong intermediate CA key"); 138ok(!verify("ee-cert", "sslserver", [qw(root-cert)], [qw(ca-name2)]), 139 "fail wrong intermediate CA DN"); 140ok(!verify("ee-cert", "sslserver", [qw(root-cert)], [qw(ca-root2)]), 141 "fail wrong intermediate CA issuer"); 142ok(!verify("ee-cert", "sslserver", [], [qw(ca-cert)], "-partial_chain"), 143 "fail untrusted partial chain"); 144ok(verify("ee-cert", "sslserver", [qw(ca-cert)], [], "-partial_chain"), 145 "accept trusted partial chain"); 146ok(!verify("ee-cert", "sslserver", [qw(ca-expired)], [], "-partial_chain"), 147 "reject expired trusted partial chain"); # this check is beyond RFC 5280 148ok(!verify("ee-cert", "sslserver", [qw(root-expired)], [qw(ca-cert)]), 149 "reject expired trusted root"); # this check is beyond RFC 5280 150ok(verify("ee-cert", "sslserver", [qw(sca-cert)], [], "-partial_chain"), 151 "accept partial chain with server purpose"); 152ok(!verify("ee-cert", "sslserver", [qw(cca-cert)], [], "-partial_chain"), 153 "fail partial chain with client purpose"); 154ok(verify("ee-cert", "sslserver", [qw(ca+serverAuth)], [], "-partial_chain"), 155 "accept server trust partial chain"); 156ok(verify("ee-cert", "sslserver", [qw(cca+serverAuth)], [], "-partial_chain"), 157 "accept server trust client purpose partial chain"); 158ok(verify("ee-cert", "sslserver", [qw(ca-clientAuth)], [], "-partial_chain"), 159 "accept client mistrust partial chain"); 160ok(verify("ee-cert", "sslserver", [qw(ca+anyEKU)], [], "-partial_chain"), 161 "accept wildcard trust partial chain"); 162ok(!verify("ee-cert", "sslserver", [], [qw(ca+serverAuth)], "-partial_chain"), 163 "fail untrusted partial issuer with ignored server trust"); 164ok(!verify("ee-cert", "sslserver", [qw(ca-serverAuth)], [], "-partial_chain"), 165 "fail server mistrust partial chain"); 166ok(!verify("ee-cert", "sslserver", [qw(ca+clientAuth)], [], "-partial_chain"), 167 "fail client trust partial chain"); 168ok(!verify("ee-cert", "sslserver", [qw(ca-anyEKU)], [], "-partial_chain"), 169 "fail wildcard mistrust partial chain"); 170 171# We now test auxiliary trust even for intermediate trusted certs without 172# -partial_chain. Note that "-trusted_first" is now always on and cannot 173# be disabled. 174ok(verify("ee-cert", "sslserver", [qw(root-cert ca+serverAuth)], [qw(ca-cert)]), 175 "accept server trust"); 176ok(verify("ee-cert", "sslserver", [qw(root-cert ca+anyEKU)], [qw(ca-cert)]), 177 "accept wildcard trust"); 178ok(verify("ee-cert", "sslserver", [qw(root-cert sca-cert)], [qw(ca-cert)]), 179 "accept server purpose"); 180ok(verify("ee-cert", "sslserver", [qw(root-cert sca+serverAuth)], [qw(ca-cert)]), 181 "accept server trust and purpose"); 182ok(verify("ee-cert", "sslserver", [qw(root-cert sca+anyEKU)], [qw(ca-cert)]), 183 "accept wildcard trust and server purpose"); 184ok(verify("ee-cert", "sslserver", [qw(root-cert sca-clientAuth)], [qw(ca-cert)]), 185 "accept client mistrust and server purpose"); 186ok(verify("ee-cert", "sslserver", [qw(root-cert cca+serverAuth)], [qw(ca-cert)]), 187 "accept server trust and client purpose"); 188ok(verify("ee-cert", "sslserver", [qw(root-cert cca+anyEKU)], [qw(ca-cert)]), 189 "accept wildcard trust and client purpose"); 190ok(!verify("ee-cert", "sslserver", [qw(root-cert cca-cert)], [qw(ca-cert)]), 191 "fail client purpose"); 192ok(!verify("ee-cert", "sslserver", [qw(root-cert ca-anyEKU)], [qw(ca-cert)]), 193 "fail wildcard mistrust"); 194ok(!verify("ee-cert", "sslserver", [qw(root-cert ca-serverAuth)], [qw(ca-cert)]), 195 "fail server mistrust"); 196ok(!verify("ee-cert", "sslserver", [qw(root-cert ca+clientAuth)], [qw(ca-cert)]), 197 "fail client trust"); 198ok(!verify("ee-cert", "sslserver", [qw(root-cert sca+clientAuth)], [qw(ca-cert)]), 199 "fail client trust and server purpose"); 200ok(!verify("ee-cert", "sslserver", [qw(root-cert cca+clientAuth)], [qw(ca-cert)]), 201 "fail client trust and client purpose"); 202ok(!verify("ee-cert", "sslserver", [qw(root-cert cca-serverAuth)], [qw(ca-cert)]), 203 "fail server mistrust and client purpose"); 204ok(!verify("ee-cert", "sslserver", [qw(root-cert cca-clientAuth)], [qw(ca-cert)]), 205 "fail client mistrust and client purpose"); 206ok(!verify("ee-cert", "sslserver", [qw(root-cert sca-serverAuth)], [qw(ca-cert)]), 207 "fail server mistrust and server purpose"); 208ok(!verify("ee-cert", "sslserver", [qw(root-cert sca-anyEKU)], [qw(ca-cert)]), 209 "fail wildcard mistrust and server purpose"); 210ok(!verify("ee-cert", "sslserver", [qw(root-cert cca-anyEKU)], [qw(ca-cert)]), 211 "fail wildcard mistrust and client purpose"); 212 213# EE variants 214ok(verify("ee-client", "sslclient", [qw(root-cert)], [qw(ca-cert)]), 215 "accept client chain"); 216ok(!verify("ee-client", "sslserver", [qw(root-cert)], [qw(ca-cert)]), 217 "fail server leaf purpose"); 218ok(!verify("ee-cert", "sslclient", [qw(root-cert)], [qw(ca-cert)]), 219 "fail client leaf purpose"); 220ok(!verify("ee-cert2", "sslserver", [qw(root-cert)], [qw(ca-cert)]), 221 "fail wrong intermediate CA key"); 222ok(!verify("ee-name2", "sslserver", [qw(root-cert)], [qw(ca-cert)]), 223 "fail wrong intermediate CA DN"); 224ok(!verify("ee-expired", "sslserver", [qw(root-cert)], [qw(ca-cert)]), 225 "fail expired leaf"); 226ok(verify("ee-cert", "sslserver", [qw(ee-cert)], [], "-partial_chain"), 227 "accept last-resort direct leaf match"); 228ok(verify("ee-client", "sslclient", [qw(ee-client)], [], "-partial_chain"), 229 "accept last-resort direct leaf match"); 230ok(!verify("ee-cert", "sslserver", [qw(ee-client)], [], "-partial_chain"), 231 "fail last-resort direct leaf non-match"); 232ok(verify("ee-cert", "sslserver", [qw(ee+serverAuth)], [], "-partial_chain"), 233 "accept direct match with server trust"); 234ok(!verify("ee-cert", "sslserver", [qw(ee-serverAuth)], [], "-partial_chain"), 235 "fail direct match with server mistrust"); 236ok(verify("ee-client", "sslclient", [qw(ee+clientAuth)], [], "-partial_chain"), 237 "accept direct match with client trust"); 238ok(!verify("ee-client", "sslclient", [qw(ee-clientAuth)], [], "-partial_chain"), 239 "reject direct match with client mistrust"); 240ok(verify("ee-pathlen", "sslserver", [qw(root-cert)], [qw(ca-cert)]), 241 "accept non-ca with pathlen:0 by default"); 242ok(!verify("ee-pathlen", "sslserver", [qw(root-cert)], [qw(ca-cert)], "-x509_strict"), 243 "reject non-ca with pathlen:0 with strict flag"); 244 245# Proxy certificates 246ok(!verify("pc1-cert", "sslclient", [qw(root-cert)], [qw(ee-client ca-cert)]), 247 "fail to accept proxy cert without -allow_proxy_certs"); 248ok(verify("pc1-cert", "sslclient", [qw(root-cert)], [qw(ee-client ca-cert)], 249 "-allow_proxy_certs"), 250 "accept proxy cert 1"); 251ok(verify("pc2-cert", "sslclient", [qw(root-cert)], [qw(pc1-cert ee-client ca-cert)], 252 "-allow_proxy_certs"), 253 "accept proxy cert 2"); 254ok(!verify("bad-pc3-cert", "sslclient", [qw(root-cert)], [qw(pc1-cert ee-client ca-cert)], 255 "-allow_proxy_certs"), 256 "fail proxy cert with incorrect subject"); 257ok(!verify("bad-pc4-cert", "sslclient", [qw(root-cert)], [qw(pc1-cert ee-client ca-cert)], 258 "-allow_proxy_certs"), 259 "fail proxy cert with incorrect pathlen"); 260ok(verify("pc5-cert", "sslclient", [qw(root-cert)], [qw(pc1-cert ee-client ca-cert)], 261 "-allow_proxy_certs"), 262 "accept proxy cert missing proxy policy"); 263ok(!verify("pc6-cert", "sslclient", [qw(root-cert)], [qw(pc1-cert ee-client ca-cert)], 264 "-allow_proxy_certs"), 265 "failed proxy cert where last CN was added as a multivalue RDN component"); 266 267# Security level tests 268ok(verify("ee-cert", "", ["root-cert"], ["ca-cert"], "-auth_level", "2"), 269 "accept RSA 2048 chain at auth level 2"); 270ok(!verify("ee-cert", "", ["root-cert"], ["ca-cert"], "-auth_level", "3"), 271 "reject RSA 2048 root at auth level 3"); 272ok(verify("ee-cert", "", ["root-cert-768"], ["ca-cert-768i"], "-auth_level", "0"), 273 "accept RSA 768 root at auth level 0"); 274ok(!verify("ee-cert", "", ["root-cert-768"], ["ca-cert-768i"]), 275 "reject RSA 768 root at auth level 1"); 276ok(verify("ee-cert-768i", "", ["root-cert"], ["ca-cert-768"], "-auth_level", "0"), 277 "accept RSA 768 intermediate at auth level 0"); 278ok(!verify("ee-cert-768i", "", ["root-cert"], ["ca-cert-768"]), 279 "reject RSA 768 intermediate at auth level 1"); 280ok(verify("ee-cert-768", "", ["root-cert"], ["ca-cert"], "-auth_level", "0"), 281 "accept RSA 768 leaf at auth level 0"); 282ok(!verify("ee-cert-768", "", ["root-cert"], ["ca-cert"]), 283 "reject RSA 768 leaf at auth level 1"); 284# 285ok(verify("ee-cert", "", ["root-cert-md5"], ["ca-cert"], "-auth_level", "2"), 286 "accept md5 self-signed TA at auth level 2"); 287ok(verify("ee-cert", "", ["ca-cert-md5-any"], [], "-auth_level", "2"), 288 "accept md5 intermediate TA at auth level 2"); 289ok(verify("ee-cert", "", ["root-cert"], ["ca-cert-md5"], "-auth_level", "0"), 290 "accept md5 intermediate at auth level 0"); 291ok(!verify("ee-cert", "", ["root-cert"], ["ca-cert-md5"]), 292 "reject md5 intermediate at auth level 1"); 293ok(verify("ee-cert-md5", "", ["root-cert"], ["ca-cert"], "-auth_level", "0"), 294 "accept md5 leaf at auth level 0"); 295ok(!verify("ee-cert-md5", "", ["root-cert"], ["ca-cert"]), 296 "reject md5 leaf at auth level 1"); 297 298# Explicit vs named curve tests 299SKIP: { 300 skip "EC is not supported by this OpenSSL build", 3 301 if disabled("ec"); 302 ok(!verify("ee-cert-ec-explicit", "", ["root-cert"], 303 ["ca-cert-ec-named"]), 304 "reject explicit curve leaf with named curve intermediate"); 305 ok(!verify("ee-cert-ec-named-explicit", "", ["root-cert"], 306 ["ca-cert-ec-explicit"]), 307 "reject named curve leaf with explicit curve intermediate"); 308 ok(verify("ee-cert-ec-named-named", "", ["root-cert"], 309 ["ca-cert-ec-named"]), 310 "accept named curve leaf with named curve intermediate"); 311} 312# Same as above but with base provider used for decoding 313SKIP: { 314 my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); 315 my $provconf = srctop_file("test", "fips-and-base.cnf"); 316 my $provpath = bldtop_dir("providers"); 317 my @prov = ("-provider-path", $provpath); 318 319 skip "EC is not supported or FIPS is disabled", 3 320 if disabled("ec") || $no_fips; 321 322 run(test(["fips_version_test", "-config", $provconf, ">3.0.0"]), 323 capture => 1, statusvar => \my $exit); 324 skip "FIPS provider version is too old", 3 325 if !$exit; 326 327 $ENV{OPENSSL_CONF} = $provconf; 328 329 ok(!verify("ee-cert-ec-explicit", "", ["root-cert"], 330 ["ca-cert-ec-named"], @prov), 331 "reject explicit curve leaf with named curve intermediate w/fips"); 332 ok(!verify("ee-cert-ec-named-explicit", "", ["root-cert"], 333 ["ca-cert-ec-explicit"], @prov), 334 "reject named curve leaf with explicit curve intermediate w/fips"); 335 ok(verify("ee-cert-ec-named-named", "", ["root-cert"], 336 ["ca-cert-ec-named"], @prov), 337 "accept named curve leaf with named curve intermediate w/fips"); 338 339 delete $ENV{OPENSSL_CONF}; 340} 341 342# Depth tests, note the depth limit bounds the number of CA certificates 343# between the trust-anchor and the leaf, so, for example, with a root->ca->leaf 344# chain, depth = 1 is sufficient, but depth == 0 is not. 345# 346ok(verify("ee-cert", "", ["root-cert"], ["ca-cert"], "-verify_depth", "2"), 347 "accept chain with verify_depth 2"); 348ok(verify("ee-cert", "", ["root-cert"], ["ca-cert"], "-verify_depth", "1"), 349 "accept chain with verify_depth 1"); 350ok(!verify("ee-cert", "", ["root-cert"], ["ca-cert"], "-verify_depth", "0"), 351 "reject chain with verify_depth 0"); 352ok(verify("ee-cert", "", ["ca-cert-md5-any"], [], "-verify_depth", "0"), 353 "accept md5 intermediate TA with verify_depth 0"); 354 355# Name Constraints tests. 356 357ok(verify("alt1-cert", "", ["root-cert"], ["ncca1-cert"], ), 358 "Name Constraints everything permitted"); 359 360ok(verify("alt2-cert", "", ["root-cert"], ["ncca2-cert"], ), 361 "Name Constraints nothing excluded"); 362 363ok(verify("alt3-cert", "", ["root-cert"], ["ncca1-cert", "ncca3-cert"], ), 364 "Name Constraints nested test all permitted"); 365 366ok(verify("goodcn1-cert", "", ["root-cert"], ["ncca1-cert"], ), 367 "Name Constraints CNs permitted"); 368 369ok(verify("goodcn2-cert", "", ["root-cert"], ["ncca1-cert"], ), 370 "Name Constraints CNs permitted - no SAN extension"); 371 372ok(!verify("badcn1-cert", "", ["root-cert"], ["ncca1-cert"], ), 373 "Name Constraints CNs not permitted"); 374 375ok(!verify("badalt1-cert", "", ["root-cert"], ["ncca1-cert"], ), 376 "Name Constraints hostname not permitted"); 377 378ok(!verify("badalt2-cert", "", ["root-cert"], ["ncca2-cert"], ), 379 "Name Constraints hostname excluded"); 380 381ok(!verify("badalt3-cert", "", ["root-cert"], ["ncca1-cert"], ), 382 "Name Constraints email address not permitted"); 383 384ok(!verify("badalt4-cert", "", ["root-cert"], ["ncca1-cert"], ), 385 "Name Constraints subject email address not permitted"); 386 387ok(!verify("badalt5-cert", "", ["root-cert"], ["ncca1-cert"], ), 388 "Name Constraints IP address not permitted"); 389 390ok(!verify("badalt6-cert", "", ["root-cert"], ["ncca1-cert"], ), 391 "Name Constraints CN hostname not permitted"); 392 393ok(!verify("badalt7-cert", "", ["root-cert"], ["ncca1-cert"], ), 394 "Name Constraints CN BMPSTRING hostname not permitted"); 395 396ok(!verify("badalt8-cert", "", ["root-cert"], ["ncca1-cert", "ncca3-cert"], ), 397 "Name constraints nested DNS name not permitted 1"); 398 399ok(!verify("badalt9-cert", "", ["root-cert"], ["ncca1-cert", "ncca3-cert"], ), 400 "Name constraints nested DNS name not permitted 2"); 401 402ok(!verify("badalt10-cert", "", ["root-cert"], ["ncca1-cert", "ncca3-cert"], ), 403 "Name constraints nested DNS name excluded"); 404 405ok(!verify("bad-othername-cert", "", ["root-cert"], ["nccaothername-cert"], ), 406 "CVE-2022-4203 type confusion test"); 407 408#Check that we get the expected failure return code 409with({ exit_checker => sub { return shift == 2; } }, 410 sub { 411 ok(verify("bad-othername-namec", "", ["bad-othername-namec-inter"], [], 412 "-partial_chain", "-attime", "1623060000"), 413 "Name constraints bad othername name constraint"); 414 }); 415 416ok(verify("ee-pss-sha1-cert", "", ["root-cert"], ["ca-cert"], "-auth_level", "0"), 417 "Accept PSS signature using SHA1 at auth level 0"); 418 419ok(verify("ee-pss-sha256-cert", "", ["root-cert"], ["ca-cert"], ), 420 "CA with PSS signature using SHA256"); 421 422ok(!verify("ee-pss-sha1-cert", "", ["root-cert"], ["ca-cert"], "-auth_level", "1"), 423 "Reject PSS signature using SHA1 and auth level 1"); 424 425ok(verify("ee-pss-sha256-cert", "", ["root-cert"], ["ca-cert"], "-auth_level", "2"), 426 "PSS signature using SHA256 and auth level 2"); 427 428ok(verify("ee-pss-cert", "", ["root-cert"], ["ca-pss-cert"], ), 429 "CA PSS signature"); 430ok(!verify("ee-pss-wrong1.5-cert", "", ["root-cert"], ["ca-pss-cert"], ), 431 "CA producing regular PKCS#1 v1.5 signature with PSA-PSS key"); 432 433ok(!verify("many-names1", "", ["many-constraints"], ["many-constraints"], ), 434 "Too many names and constraints to check (1)"); 435ok(!verify("many-names2", "", ["many-constraints"], ["many-constraints"], ), 436 "Too many names and constraints to check (2)"); 437ok(!verify("many-names3", "", ["many-constraints"], ["many-constraints"], ), 438 "Too many names and constraints to check (3)"); 439 440ok(verify("some-names1", "", ["many-constraints"], ["many-constraints"], ), 441 "Not too many names and constraints to check (1)"); 442ok(verify("some-names2", "", ["many-constraints"], ["many-constraints"], ), 443 "Not too many names and constraints to check (2)"); 444ok(verify("some-names2", "", ["many-constraints"], ["many-constraints"], ), 445 "Not too many names and constraints to check (3)"); 446ok(verify("root-cert-rsa2", "", ["root-cert-rsa2"], [], "-check_ss_sig"), 447 "Public Key Algorithm rsa instead of rsaEncryption"); 448 449ok(verify("ee-self-signed", "", ["ee-self-signed"], [], "-attime", "1593565200"), 450 "accept trusted self-signed EE cert excluding key usage keyCertSign"); 451ok(verify("ee-ss-with-keyCertSign", "", ["ee-ss-with-keyCertSign"], []), 452 "accept trusted self-signed EE cert with key usage keyCertSign also when strict"); 453 454SKIP: { 455 skip "Ed25519 is not supported by this OpenSSL build", 6 456 if disabled("ec"); 457 458 # ED25519 certificate from draft-ietf-curdle-pkix-04 459 ok(verify("ee-ed25519", "", ["root-ed25519"], []), 460 "accept X25519 EE cert issued by trusted Ed25519 self-signed CA cert"); 461 462 ok(!verify("ee-ed25519", "", ["root-ed25519"], [], "-x509_strict"), 463 "reject X25519 EE cert in strict mode since AKID is missing"); 464 465 ok(!verify("root-ed25519", "", ["ee-ed25519"], []), 466 "fail Ed25519 CA and EE certs swapped"); 467 468 ok(verify("root-ed25519", "", ["root-ed25519"], []), 469 "accept trusted Ed25519 self-signed CA cert"); 470 471 ok(!verify("ee-ed25519", "", ["ee-ed25519"], []), 472 "fail trusted Ed25519-signed self-issued X25519 cert"); 473 474 ok(verify("ee-ed25519", "", ["ee-ed25519"], [], "-partial_chain"), 475 "accept last-resort direct leaf match Ed25519-signed self-issued cert"); 476 477} 478 479SKIP: { 480 skip "SM2 is not supported by this OpenSSL build", 2 if disabled("sm2"); 481 482 ok_nofips(verify("sm2", "", ["sm2-ca-cert"], [], "-vfyopt", "distid:1234567812345678"), 483 "SM2 ID test"); 484 ok_nofips(verify("sm2", "", ["sm2-ca-cert"], [], "-vfyopt", "hexdistid:31323334353637383132333435363738"), 485 "SM2 hex ID test"); 486} 487 488# Mixed content tests 489my $cert_file = srctop_file('test', 'certs', 'root-cert.pem'); 490my $rsa_file = srctop_file('test', 'certs', 'key-pass-12345.pem'); 491 492SKIP: { 493 my $certplusrsa_file = 'certplusrsa.pem'; 494 my $certplusrsa; 495 496 skip "Couldn't create certplusrsa.pem", 1 497 unless ( open $certplusrsa, '>', $certplusrsa_file 498 and copy($cert_file, $certplusrsa) 499 and copy($rsa_file, $certplusrsa) 500 and close $certplusrsa ); 501 502 ok(run(app([ qw(openssl verify -trusted), $certplusrsa_file, $cert_file ])), 503 'Mixed cert + key file test'); 504} 505 506SKIP: { 507 my $rsapluscert_file = 'rsapluscert.pem'; 508 my $rsapluscert; 509 510 skip "Couldn't create rsapluscert.pem", 1 511 unless ( open $rsapluscert, '>', $rsapluscert_file 512 and copy($rsa_file, $rsapluscert) 513 and copy($cert_file, $rsapluscert) 514 and close $rsapluscert ); 515 516 ok(run(app([ qw(openssl verify -trusted), $rsapluscert_file, $cert_file ])), 517 'Mixed key + cert file test'); 518} 519 520# Certificate Policies 521ok(verify("ee-cert-policies", "", ["root-cert"], ["ca-pol-cert"], 522 "-policy_check", "-policy", "1.3.6.1.4.1.16604.998855.1", 523 "-explicit_policy"), 524 "Certificate policy"); 525 526ok(!verify("ee-cert-policies-bad", "", ["root-cert"], ["ca-pol-cert"], 527 "-policy_check", "-policy", "1.3.6.1.4.1.16604.998855.1", 528 "-explicit_policy"), 529 "Bad certificate policy"); 530