25-test_req.t 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 OpenSSL::Test::Utils;
  11. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  12. setup("test_req");
  13. plan tests => 92;
  14. require_ok(srctop_file('test', 'recipes', 'tconversion.pl'));
  15. my @certs = qw(test certs);
  16. # What type of key to generate?
  17. my @req_new;
  18. if (disabled("rsa")) {
  19. @req_new = ("-newkey", "dsa:".srctop_file("apps", "dsa512.pem"));
  20. } else {
  21. @req_new = ("-new");
  22. note("There should be a 2 sequences of .'s and some +'s.");
  23. note("There should not be more that at most 80 per line");
  24. }
  25. # Prevent MSys2 filename munging for arguments that look like file paths but
  26. # aren't
  27. $ENV{MSYS2_ARG_CONV_EXCL} = "/CN=";
  28. # Check for duplicate -addext parameters, and one "working" case.
  29. my @addext_args = ( "openssl", "req", "-new", "-out", "testreq.pem",
  30. "-key", srctop_file(@certs, "ee-key.pem"),
  31. "-config", srctop_file("test", "test.cnf"), @req_new );
  32. my $val = "subjectAltName=DNS:example.com";
  33. my $val2 = " " . $val;
  34. my $val3 = $val;
  35. $val3 =~ s/=/ =/;
  36. ok( run(app([@addext_args, "-addext", $val])));
  37. ok(!run(app([@addext_args, "-addext", $val, "-addext", $val])));
  38. ok(!run(app([@addext_args, "-addext", $val, "-addext", $val2])));
  39. ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3])));
  40. ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3])));
  41. # If a CSR is provided with neither of -key or -CA/-CAkey, this should fail.
  42. ok(!run(app(["openssl", "req", "-x509",
  43. "-in", srctop_file(@certs, "x509-check.csr"),
  44. "-out", "testreq.pem"])));
  45. subtest "generating alt certificate requests with RSA" => sub {
  46. plan tests => 3;
  47. SKIP: {
  48. skip "RSA is not supported by this OpenSSL build", 2
  49. if disabled("rsa");
  50. ok(run(app(["openssl", "req",
  51. "-config", srctop_file("test", "test.cnf"),
  52. "-section", "altreq",
  53. "-new", "-out", "testreq-rsa.pem", "-utf8",
  54. "-key", srctop_file("test", "testrsa.pem")])),
  55. "Generating request");
  56. ok(run(app(["openssl", "req",
  57. "-config", srctop_file("test", "test.cnf"),
  58. "-verify", "-in", "testreq-rsa.pem", "-noout"])),
  59. "Verifying signature on request");
  60. ok(run(app(["openssl", "req",
  61. "-config", srctop_file("test", "test.cnf"),
  62. "-section", "altreq",
  63. "-verify", "-in", "testreq-rsa.pem", "-noout"])),
  64. "Verifying signature on request");
  65. }
  66. };
  67. subtest "generating certificate requests with RSA" => sub {
  68. plan tests => 8;
  69. SKIP: {
  70. skip "RSA is not supported by this OpenSSL build", 2
  71. if disabled("rsa");
  72. ok(!run(app(["openssl", "req",
  73. "-config", srctop_file("test", "test.cnf"),
  74. "-new", "-out", "testreq-rsa.pem", "-utf8",
  75. "-key", srctop_file("test", "testrsa.pem"),
  76. "-keyform", "DER"])),
  77. "Checking that mismatching keyform fails");
  78. ok(run(app(["openssl", "req",
  79. "-config", srctop_file("test", "test.cnf"),
  80. "-new", "-out", "testreq-rsa.pem", "-utf8",
  81. "-key", srctop_file("test", "testrsa.pem"),
  82. "-keyform", "PEM"])),
  83. "Generating request");
  84. ok(run(app(["openssl", "req",
  85. "-config", srctop_file("test", "test.cnf"),
  86. "-verify", "-in", "testreq-rsa.pem", "-noout"])),
  87. "Verifying signature on request");
  88. ok(run(app(["openssl", "req",
  89. "-config", srctop_file("test", "test.cnf"),
  90. "-modulus", "-in", "testreq-rsa.pem", "-noout"])),
  91. "Printing a modulus of the request key");
  92. ok(run(app(["openssl", "req",
  93. "-config", srctop_file("test", "test.cnf"),
  94. "-new", "-out", "testreq_withattrs_pem.pem", "-utf8",
  95. "-key", srctop_file("test", "testrsa_withattrs.pem")])),
  96. "Generating request from a key with extra attributes - PEM");
  97. ok(run(app(["openssl", "req",
  98. "-config", srctop_file("test", "test.cnf"),
  99. "-verify", "-in", "testreq_withattrs_pem.pem", "-noout"])),
  100. "Verifying signature on request from a key with extra attributes - PEM");
  101. ok(run(app(["openssl", "req",
  102. "-config", srctop_file("test", "test.cnf"),
  103. "-new", "-out", "testreq_withattrs_der.pem", "-utf8",
  104. "-key", srctop_file("test", "testrsa_withattrs.der"),
  105. "-keyform", "DER"])),
  106. "Generating request from a key with extra attributes - PEM");
  107. ok(run(app(["openssl", "req",
  108. "-config", srctop_file("test", "test.cnf"),
  109. "-verify", "-in", "testreq_withattrs_der.pem", "-noout"])),
  110. "Verifying signature on request from a key with extra attributes - PEM");
  111. }
  112. };
  113. subtest "generating certificate requests with RSA-PSS" => sub {
  114. plan tests => 12;
  115. SKIP: {
  116. skip "RSA is not supported by this OpenSSL build", 2
  117. if disabled("rsa");
  118. ok(run(app(["openssl", "req",
  119. "-config", srctop_file("test", "test.cnf"),
  120. "-new", "-out", "testreq-rsapss.pem", "-utf8",
  121. "-key", srctop_file("test", "testrsapss.pem")])),
  122. "Generating request");
  123. ok(run(app(["openssl", "req",
  124. "-config", srctop_file("test", "test.cnf"),
  125. "-verify", "-in", "testreq-rsapss.pem", "-noout"])),
  126. "Verifying signature on request");
  127. ok(run(app(["openssl", "req",
  128. "-config", srctop_file("test", "test.cnf"),
  129. "-new", "-out", "testreq-rsapss2.pem", "-utf8",
  130. "-sigopt", "rsa_padding_mode:pss",
  131. "-sigopt", "rsa_pss_saltlen:-1",
  132. "-key", srctop_file("test", "testrsapss.pem")])),
  133. "Generating request");
  134. ok(run(app(["openssl", "req",
  135. "-config", srctop_file("test", "test.cnf"),
  136. "-verify", "-in", "testreq-rsapss2.pem", "-noout"])),
  137. "Verifying signature on request");
  138. ok(run(app(["openssl", "req",
  139. "-config", srctop_file("test", "test.cnf"),
  140. "-new", "-out", "testreq-rsapssmand.pem", "-utf8",
  141. "-sigopt", "rsa_padding_mode:pss",
  142. "-key", srctop_file("test", "testrsapssmandatory.pem")])),
  143. "Generating request");
  144. ok(run(app(["openssl", "req",
  145. "-config", srctop_file("test", "test.cnf"),
  146. "-verify", "-in", "testreq-rsapssmand.pem", "-noout"])),
  147. "Verifying signature on request");
  148. ok(run(app(["openssl", "req",
  149. "-config", srctop_file("test", "test.cnf"),
  150. "-new", "-out", "testreq-rsapssmand2.pem", "-utf8",
  151. "-sigopt", "rsa_pss_saltlen:100",
  152. "-key", srctop_file("test", "testrsapssmandatory.pem")])),
  153. "Generating request");
  154. ok(run(app(["openssl", "req",
  155. "-config", srctop_file("test", "test.cnf"),
  156. "-verify", "-in", "testreq-rsapssmand2.pem", "-noout"])),
  157. "Verifying signature on request");
  158. ok(!run(app(["openssl", "req",
  159. "-config", srctop_file("test", "test.cnf"),
  160. "-new", "-out", "testreq-rsapss3.pem", "-utf8",
  161. "-sigopt", "rsa_padding_mode:pkcs1",
  162. "-key", srctop_file("test", "testrsapss.pem")])),
  163. "Generating request with expected failure");
  164. ok(!run(app(["openssl", "req",
  165. "-config", srctop_file("test", "test.cnf"),
  166. "-new", "-out", "testreq-rsapss3.pem", "-utf8",
  167. "-sigopt", "rsa_pss_saltlen:-4",
  168. "-key", srctop_file("test", "testrsapss.pem")])),
  169. "Generating request with expected failure");
  170. ok(!run(app(["openssl", "req",
  171. "-config", srctop_file("test", "test.cnf"),
  172. "-new", "-out", "testreq-rsapssmand3.pem", "-utf8",
  173. "-sigopt", "rsa_pss_saltlen:10",
  174. "-key", srctop_file("test", "testrsapssmandatory.pem")])),
  175. "Generating request with expected failure");
  176. ok(!run(app(["openssl", "req",
  177. "-config", srctop_file("test", "test.cnf"),
  178. "-new", "-out", "testreq-rsapssmand3.pem", "-utf8",
  179. "-sha256",
  180. "-key", srctop_file("test", "testrsapssmandatory.pem")])),
  181. "Generating request with expected failure");
  182. }
  183. };
  184. subtest "generating certificate requests with DSA" => sub {
  185. plan tests => 2;
  186. SKIP: {
  187. skip "DSA is not supported by this OpenSSL build", 2
  188. if disabled("dsa");
  189. ok(run(app(["openssl", "req",
  190. "-config", srctop_file("test", "test.cnf"),
  191. "-new", "-out", "testreq-dsa.pem", "-utf8",
  192. "-key", srctop_file("test", "testdsa.pem")])),
  193. "Generating request");
  194. ok(run(app(["openssl", "req",
  195. "-config", srctop_file("test", "test.cnf"),
  196. "-verify", "-in", "testreq-dsa.pem", "-noout"])),
  197. "Verifying signature on request");
  198. }
  199. };
  200. subtest "generating certificate requests with ECDSA" => sub {
  201. plan tests => 2;
  202. SKIP: {
  203. skip "ECDSA is not supported by this OpenSSL build", 2
  204. if disabled("ec");
  205. ok(run(app(["openssl", "req",
  206. "-config", srctop_file("test", "test.cnf"),
  207. "-new", "-out", "testreq-ec.pem", "-utf8",
  208. "-key", srctop_file("test", "testec-p256.pem")])),
  209. "Generating request");
  210. ok(run(app(["openssl", "req",
  211. "-config", srctop_file("test", "test.cnf"),
  212. "-verify", "-in", "testreq-ec.pem", "-noout"])),
  213. "Verifying signature on request");
  214. }
  215. };
  216. subtest "generating certificate requests with Ed25519" => sub {
  217. plan tests => 2;
  218. SKIP: {
  219. skip "Ed25519 is not supported by this OpenSSL build", 2
  220. if disabled("ec");
  221. ok(run(app(["openssl", "req",
  222. "-config", srctop_file("test", "test.cnf"),
  223. "-new", "-out", "testreq-ed25519.pem", "-utf8",
  224. "-key", srctop_file("test", "tested25519.pem")])),
  225. "Generating request");
  226. ok(run(app(["openssl", "req",
  227. "-config", srctop_file("test", "test.cnf"),
  228. "-verify", "-in", "testreq-ed25519.pem", "-noout"])),
  229. "Verifying signature on request");
  230. }
  231. };
  232. subtest "generating certificate requests with Ed448" => sub {
  233. plan tests => 2;
  234. SKIP: {
  235. skip "Ed448 is not supported by this OpenSSL build", 2
  236. if disabled("ec");
  237. ok(run(app(["openssl", "req",
  238. "-config", srctop_file("test", "test.cnf"),
  239. "-new", "-out", "testreq-ed448.pem", "-utf8",
  240. "-key", srctop_file("test", "tested448.pem")])),
  241. "Generating request");
  242. ok(run(app(["openssl", "req",
  243. "-config", srctop_file("test", "test.cnf"),
  244. "-verify", "-in", "testreq-ed448.pem", "-noout"])),
  245. "Verifying signature on request");
  246. }
  247. };
  248. subtest "generating certificate requests" => sub {
  249. plan tests => 2;
  250. ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
  251. "-key", srctop_file(@certs, "ee-key.pem"),
  252. @req_new, "-out", "testreq.pem"])),
  253. "Generating request");
  254. ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
  255. "-verify", "-in", "testreq.pem", "-noout"])),
  256. "Verifying signature on request");
  257. };
  258. subtest "generating SM2 certificate requests" => sub {
  259. plan tests => 4;
  260. SKIP: {
  261. skip "SM2 is not supported by this OpenSSL build", 4
  262. if disabled("sm2");
  263. ok(run(app(["openssl", "req",
  264. "-config", srctop_file("test", "test.cnf"),
  265. "-new", "-key", srctop_file(@certs, "sm2.key"),
  266. "-sigopt", "distid:1234567812345678",
  267. "-out", "testreq-sm2.pem", "-sm3"])),
  268. "Generating SM2 certificate request");
  269. ok(run(app(["openssl", "req",
  270. "-config", srctop_file("test", "test.cnf"),
  271. "-verify", "-in", "testreq-sm2.pem", "-noout",
  272. "-vfyopt", "distid:1234567812345678", "-sm3"])),
  273. "Verifying signature on SM2 certificate request");
  274. ok(run(app(["openssl", "req",
  275. "-config", srctop_file("test", "test.cnf"),
  276. "-new", "-key", srctop_file(@certs, "sm2.key"),
  277. "-sigopt", "hexdistid:DEADBEEF",
  278. "-out", "testreq-sm2.pem", "-sm3"])),
  279. "Generating SM2 certificate request with hex id");
  280. ok(run(app(["openssl", "req",
  281. "-config", srctop_file("test", "test.cnf"),
  282. "-verify", "-in", "testreq-sm2.pem", "-noout",
  283. "-vfyopt", "hexdistid:DEADBEEF", "-sm3"])),
  284. "Verifying signature on SM2 certificate request");
  285. }
  286. };
  287. my @openssl_args = ("req", "-config", srctop_file("apps", "openssl.cnf"));
  288. run_conversion('req conversions',
  289. "testreq.pem");
  290. run_conversion('req conversions -- testreq2',
  291. srctop_file("test", "testreq2.pem"));
  292. sub run_conversion {
  293. my $title = shift;
  294. my $reqfile = shift;
  295. subtest $title => sub {
  296. run(app(["openssl", @openssl_args,
  297. "-in", $reqfile, "-inform", "p",
  298. "-noout", "-text"],
  299. stderr => "req-check.err", stdout => undef));
  300. open DATA, "req-check.err";
  301. SKIP: {
  302. plan skip_all => "skipping req conversion test for $reqfile"
  303. if grep /Unknown Public Key/, map { s/\R//; } <DATA>;
  304. tconversion( -type => 'req', -in => $reqfile,
  305. -args => [ @openssl_args ] );
  306. }
  307. close DATA;
  308. unlink "req-check.err";
  309. done_testing();
  310. };
  311. }
  312. # Test both generation and verification of certs w.r.t. RFC 5280 requirements
  313. my $ca_cert; # will be set below
  314. sub generate_cert {
  315. my $cert = shift @_;
  316. my $ss = $cert =~ m/self-signed/;
  317. my $is_ca = $cert =~ m/CA/;
  318. my $cn = $is_ca ? "CA" : "EE";
  319. my $ca_key = srctop_file(@certs, "ca-key.pem");
  320. my $key = $is_ca ? $ca_key : srctop_file(@certs, "ee-key.pem");
  321. my @cmd = ("openssl", "req", "-config", "", "-x509",
  322. "-subj", "/CN=$cn", @_, "-out", $cert);
  323. push(@cmd, ("-key", $key)) if $ss;
  324. push(@cmd, ("-CA", $ca_cert, "-CAkey", $ca_key)) unless $ss;
  325. ok(run(app([@cmd])), "generate $cert");
  326. }
  327. sub has_SKID {
  328. my $cert = shift @_;
  329. my $expect = shift @_;
  330. cert_contains($cert, "Subject Key Identifier", $expect);
  331. }
  332. sub has_AKID {
  333. my $cert = shift @_;
  334. my $expect = shift @_;
  335. cert_contains($cert, "Authority Key Identifier", $expect);
  336. }
  337. sub has_keyUsage {
  338. my $cert = shift @_;
  339. my $expect = shift @_;
  340. cert_contains($cert, "Key Usage", $expect);
  341. }
  342. sub strict_verify {
  343. my $cert = shift @_;
  344. my $expect = shift @_;
  345. my $trusted = shift @_;
  346. $trusted = $cert unless $trusted;
  347. ok(run(app(["openssl", "verify", "-x509_strict", "-trusted", $trusted,
  348. "-partial_chain", $cert])) == $expect,
  349. "strict verify allow $cert");
  350. }
  351. my @v3_ca = ("-addext", "basicConstraints = critical,CA:true",
  352. "-addext", "keyUsage = keyCertSign");
  353. my $SKID_AKID = "subjectKeyIdentifier,authorityKeyIdentifier";
  354. # # SKID
  355. my $cert = "self-signed_v3_CA_hash_SKID.pem";
  356. generate_cert($cert, @v3_ca, "-addext", "subjectKeyIdentifier = hash");
  357. has_SKID($cert, 1); # explicit hash SKID
  358. $cert = "self-signed_v3_CA_no_SKID.pem";
  359. generate_cert($cert, @v3_ca, "-addext", "subjectKeyIdentifier = none");
  360. cert_ext_has_n_different_lines($cert, 0, $SKID_AKID); # no SKID and no AKID
  361. #TODO strict_verify($cert, 0);
  362. $cert = "self-signed_v3_CA_given_SKID.pem";
  363. generate_cert($cert, @v3_ca, "-addext", "subjectKeyIdentifier = 45");
  364. cert_contains($cert, "Subject Key Identifier: 45 ", 1); # given SKID
  365. strict_verify($cert, 1);
  366. # AKID of self-signed certs
  367. $cert = "self-signed_v1_CA_no_KIDs.pem";
  368. generate_cert($cert);
  369. cert_ext_has_n_different_lines($cert, 0, $SKID_AKID); # no SKID and no AKID
  370. #TODO strict_verify($cert, 1); # self-signed v1 root cert should be accepted as CA
  371. $ca_cert = "self-signed_v3_CA_default_SKID.pem"; # will also be used below
  372. generate_cert($ca_cert, @v3_ca);
  373. has_SKID($ca_cert, 1); # default SKID
  374. has_AKID($ca_cert, 0); # no default AKID
  375. strict_verify($ca_cert, 1);
  376. $cert = "self-signed_v3_CA_no_AKID.pem";
  377. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = none");
  378. has_AKID($cert, 0); # forced no AKID
  379. $cert = "self-signed_v3_CA_explicit_AKID.pem";
  380. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid");
  381. has_AKID($cert, 0); # for self-signed cert, AKID suppressed and not forced
  382. $cert = "self-signed_v3_CA_forced_AKID.pem";
  383. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always");
  384. cert_ext_has_n_different_lines($cert, 3, $SKID_AKID); # forced AKID, AKID == SKID
  385. strict_verify($cert, 1);
  386. $cert = "self-signed_v3_CA_issuer_AKID.pem";
  387. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer");
  388. has_AKID($cert, 0); # suppressed AKID since not forced
  389. $cert = "self-signed_v3_CA_forced_issuer_AKID.pem";
  390. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer:always");
  391. cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # forced issuer AKID
  392. $cert = "self-signed_v3_CA_nonforced_keyid_issuer_AKID.pem";
  393. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid, issuer");
  394. has_AKID($cert, 0); # AKID not present because not forced and cert self-signed
  395. $cert = "self-signed_v3_CA_keyid_forced_issuer_AKID.pem";
  396. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid, issuer:always");
  397. cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # issuer AKID forced, with keyid not forced
  398. $cert = "self-signed_v3_CA_forced_keyid_issuer_AKID.pem";
  399. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always, issuer");
  400. has_AKID($cert, 1); # AKID with keyid forced
  401. cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 0); # no issuer AKID
  402. $cert = "self-signed_v3_CA_forced_keyid_forced_issuer_AKID.pem";
  403. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always, issuer:always");
  404. cert_contains($cert, "Authority Key Identifier: keyid(:[0-9A-Fa-f]{2})+ DirName:/CN=CA serial:", 1); # AKID with keyid and issuer forced
  405. $cert = "self-signed_v3_EE_wrong_keyUsage.pem";
  406. generate_cert($cert, "-addext", "keyUsage = keyCertSign");
  407. #TODO strict_verify($cert, 1); # should be accepted because RFC 5280 does not apply
  408. # AKID of self-issued but not self-signed certs
  409. $cert = "self-issued_x509_v3_CA_default_KIDs.pem";
  410. ok(run(app([("openssl", "x509", "-copy_extensions", "copy",
  411. "-req", "-in", srctop_file(@certs, "ext-check.csr"),
  412. "-key", srctop_file(@certs, "ca-key.pem"),
  413. "-force_pubkey", srctop_file("test", "testrsapub.pem"),
  414. "-out", $cert)])), "generate using x509: $cert");
  415. cert_contains($cert, "Issuer: CN=test .*? Subject: CN=test", 1);
  416. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
  417. strict_verify($cert, 1);
  418. $cert = "self-issued_v3_CA_default_KIDs.pem";
  419. generate_cert($cert, "-addext", "keyUsage = dataEncipherment",
  420. "-in", srctop_file(@certs, "x509-check.csr"));
  421. cert_contains($cert, "Issuer: CN=CA .*? Subject: CN=CA", 1);
  422. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
  423. strict_verify($cert, 1);
  424. $cert = "self-issued_v3_CA_no_AKID.pem";
  425. generate_cert($cert, "-addext", "authorityKeyIdentifier = none",
  426. "-in", srctop_file(@certs, "x509-check.csr"));
  427. has_AKID($cert, 0);
  428. strict_verify($cert, 1);
  429. $cert = "self-issued_v3_CA_explicit_AKID.pem";
  430. generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid",
  431. "-in", srctop_file(@certs, "x509-check.csr"));
  432. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
  433. strict_verify($cert, 1);
  434. $cert = "self-issued_v3_CA_forced_AKID.pem";
  435. generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid:always",
  436. "-in", srctop_file(@certs, "x509-check.csr"));
  437. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
  438. $cert = "self-issued_v3_CA_issuer_AKID.pem";
  439. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer",
  440. "-in", srctop_file(@certs, "x509-check.csr"));
  441. cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # just issuer AKID
  442. $cert = "self-issued_v3_CA_forced_issuer_AKID.pem";
  443. generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer:always",
  444. "-in", srctop_file(@certs, "x509-check.csr"));
  445. cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # just issuer AKID
  446. $cert = "self-issued_v3_CA_keyid_issuer_AKID.pem";
  447. generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid, issuer",
  448. "-in", srctop_file(@certs, "x509-check.csr"));
  449. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID, not forced
  450. $cert = "self-issued_v3_CA_keyid_forced_issuer_AKID.pem";
  451. generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid, issuer:always",
  452. "-in", srctop_file(@certs, "x509-check.csr"));
  453. cert_ext_has_n_different_lines($cert, 6, $SKID_AKID); # SKID != AKID, with forced issuer
  454. $cert = "self-issued_v3_CA_forced_keyid_and_issuer_AKID.pem";
  455. generate_cert($cert, "-addext", "authorityKeyIdentifier = keyid:always, issuer:always",
  456. "-in", srctop_file(@certs, "x509-check.csr"));
  457. cert_ext_has_n_different_lines($cert, 6, $SKID_AKID); # SKID != AKID, both forced
  458. # AKID of not self-issued certs
  459. $cert = "regular_v3_EE_default_KIDs.pem";
  460. generate_cert($cert, "-addext", "keyUsage = dataEncipherment",
  461. "-key", srctop_file(@certs, "ee-key.pem"));
  462. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
  463. strict_verify($cert, 1, $ca_cert);
  464. $cert = "regular_v3_EE_copied_exts_default_KIDs.pem";
  465. generate_cert($cert, "-copy_extensions", "copy",
  466. "-in", srctop_file(@certs, "ext-check.csr"));
  467. cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
  468. strict_verify($cert, 1);
  469. $cert = "v3_EE_no_AKID.pem";
  470. generate_cert($cert, "-addext", "authorityKeyIdentifier = none",
  471. "-key", srctop_file(@certs, "ee-key.pem"));
  472. has_SKID($cert, 1);
  473. has_AKID($cert, 0);
  474. strict_verify($cert, 0, $ca_cert);
  475. # Key Usage
  476. $cert = "self-signed_CA_no_keyUsage.pem";
  477. generate_cert($cert, "-in", srctop_file(@certs, "ext-check.csr"));
  478. has_keyUsage($cert, 0);
  479. $cert = "self-signed_CA_with_keyUsages.pem";
  480. generate_cert($cert, "-in", srctop_file(@certs, "ext-check.csr"),
  481. "-copy_extensions", "copy");
  482. has_keyUsage($cert, 1);