Skip to content

Commit 6715dde

Browse files
Use the private key from X509V3_set_issuer_pkey only as an override
when authorityKeyIdentifier=keyid is used, the private key if available, is simply used as an unconditional override to the SKID in the issuer certificate, when the issuer certificate is the same as the subject certificate. This restores the semantics of authorityKeyIdentifier=keyid in config files to the previous versions, where it was a best effort, while still keeping the default when that extension is not defined by the config file.
1 parent 0b7fa64 commit 6715dde

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

crypto/x509/v3_akid.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
107107
ASN1_INTEGER *serial = NULL;
108108
X509_EXTENSION *ext;
109109
X509 *issuer_cert;
110-
int self_signed = 0;
111110
AUTHORITY_KEYID *akeyid = AUTHORITY_KEYID_new();
112111

113112
if (akeyid == NULL)
@@ -157,15 +156,8 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
157156
goto err;
158157
}
159158

160-
if (ctx->subject_cert != NULL && ctx->issuer_pkey != NULL) {
161-
ERR_set_mark();
162-
self_signed = X509_check_private_key(ctx->subject_cert,
163-
ctx->issuer_pkey);
164-
ERR_pop_to_mark();
165-
}
166-
167-
/* unless forced with "always", AKID is suppressed for self-signed certs */
168-
if (keyid == 2 || (keyid == 1 && !self_signed)) {
159+
/* unless forced with "always", AKID is optional */
160+
if (keyid != 0) {
169161
/*
170162
* prefer any pre-existing subject key identifier of the issuer cert
171163
* except issuer cert is same as subject cert and private key is given
@@ -193,7 +185,7 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
193185
}
194186
}
195187

196-
if (issuer == 2 || (issuer == 1 && ikeyid == NULL && !self_signed)) {
188+
if (issuer == 2 || (issuer == 1 && ikeyid == NULL)) {
197189
isname = X509_NAME_dup(X509_get_issuer_name(issuer_cert));
198190
serial = ASN1_INTEGER_dup(X509_get0_serialNumber(issuer_cert));
199191
if (isname == NULL || serial == NULL) {

test/recipes/25-test_req.t

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
1515

1616
setup("test_req");
1717

18-
plan tests => 116;
18+
plan tests => 117;
1919

2020
require_ok(srctop_file('test', 'recipes', 'tconversion.pl'));
2121

@@ -612,7 +612,7 @@ has_AKID($cert, 0); # forced no AKID
612612

613613
$cert = "self-signed_v3_CA_explicit_AKID.pem";
614614
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid");
615-
has_AKID($cert, 0); # for self-signed cert, AKID suppressed and not forced
615+
has_AKID($cert, 1); # for self-signed cert, AKID present but not forced
616616

617617
$cert = "self-signed_v3_CA_forced_AKID.pem";
618618
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always");
@@ -621,19 +621,20 @@ strict_verify($cert, 1);
621621

622622
$cert = "self-signed_v3_CA_issuer_AKID.pem";
623623
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer");
624-
has_AKID($cert, 0); # suppressed AKID since not forced
624+
cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # for self-signed cert, AKID=issuer present as requested and possible
625625

626626
$cert = "self-signed_v3_CA_forced_issuer_AKID.pem";
627627
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = issuer:always");
628628
cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # forced issuer AKID
629629

630630
$cert = "self-signed_v3_CA_nonforced_keyid_issuer_AKID.pem";
631631
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid, issuer");
632-
has_AKID($cert, 0); # AKID not present because not forced and cert self-signed
632+
has_AKID($cert, 1); # for self-signed cert, AKID=keyid present as requested and possible
633+
cert_contains($cert, "Authority Key Identifier: .*DirName:/CN=CA serial:", 0); # but no issuer AKID (as not forced)
633634

634635
$cert = "self-signed_v3_CA_keyid_forced_issuer_AKID.pem";
635636
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid, issuer:always");
636-
cert_contains($cert, "Authority Key Identifier: DirName:/CN=CA serial:", 1); # issuer AKID forced, with keyid not forced
637+
cert_contains($cert, "Authority Key Identifier: keyid:.* DirName:/CN=CA serial:", 1); # issuer AKID forced, with keyid not forced
637638

638639
$cert = "self-signed_v3_CA_forced_keyid_issuer_AKID.pem";
639640
generate_cert($cert, @v3_ca, "-addext", "authorityKeyIdentifier = keyid:always, issuer");

0 commit comments

Comments
 (0)