Skip to content

Commit 07e2d11

Browse files
committed
Relax PK and DB key usage constraints and try to follow what OEMs do
* Since OEMs, including Microsoft, don't set key usage, and since we had trouble with that in #19, remove it altogether. * On the other hand, since all the OEMs we see seem to use them, add subject_key_identifier and authority_key_identifier. * Also make sure we set up a proper context in AddExtension().
1 parent 3ed74b8 commit 07e2d11

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/pki.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ STATIC EFI_STATUS AddExtension(
121121
{
122122
EFI_STATUS Status = EFI_SUCCESS;
123123
X509_EXTENSION *ex = NULL;
124+
X509V3_CTX ctx;
124125

125-
ex = X509V3_EXT_nconf_nid(NULL, NULL, ExtNid, (char *)ExtStr);
126+
X509V3_set_ctx(&ctx, Cert, Cert, NULL, NULL, 0);
127+
ex = X509V3_EXT_nconf_nid(NULL, &ctx, ExtNid, (char *)ExtStr);
126128
if (ex == NULL)
127129
ReportOpenSSLErrorAndExit(EFI_UNSUPPORTED);
128130

@@ -173,9 +175,12 @@ EFI_STATUS GenerateCredentials(
173175
// Set version
174176
X509_set_version(Cert, 2);
175177

176-
// Set usage for code signing as a Certification Authority
177-
AddExtension(Cert, NID_basic_constraints, "critical,CA:TRUE");
178-
AddExtension(Cert, NID_key_usage, "critical,digitalSignature,keyCertSign");
178+
// Set usage to what OEMs typically use for PK. Should also work fine for DB.
179+
// Avoid restricting key usage and avoid critical, as some UEFI firmwares do
180+
// take objection to a signed cert with an improperly declared key usage.
181+
AddExtension(Cert, NID_basic_constraints, "CA:TRUE");
182+
AddExtension(Cert, NID_subject_key_identifier, "hash");
183+
AddExtension(Cert, NID_authority_key_identifier, "keyid:always,issuer");
179184

180185
// Set subject key identifier
181186
ASN1_OCTET_STRING *Skid = ASN1_OCTET_STRING_new();

0 commit comments

Comments
 (0)