Skip to content

Commit 4365295

Browse files
committed
X.509: Allow X.509 certs to be blacklisted
Allow X.509 certs to be blacklisted based on their TBSCertificate hash. This is convenient since we have to determine this anyway to be able to check the signature on an X.509 certificate. This is also what UEFI uses in its blacklist. If a certificate built into the kernel is blacklisted, something like the following might then be seen during boot: X.509: Cert 123412341234c55c1dcc601ab8e172917706aa32fb5eaf826813547fdf02dd46 is blacklisted Problem loading in-kernel X.509 certificate (-129) where the hex string shown is the blacklisted hash. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 734114f commit 4365295

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

crypto/asymmetric_keys/x509_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct x509_certificate {
4242
bool self_signed; /* T if self-signed (check unsupported_sig too) */
4343
bool unsupported_key; /* T if key uses unsupported crypto */
4444
bool unsupported_sig; /* T if signature uses unsupported crypto */
45+
bool blacklisted;
4546
};
4647

4748
/*

crypto/asymmetric_keys/x509_public_key.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ int x509_get_sig_params(struct x509_certificate *cert)
8484
goto error_2;
8585
might_sleep();
8686
ret = crypto_shash_finup(desc, cert->tbs, cert->tbs_size, sig->digest);
87+
if (ret < 0)
88+
goto error_2;
89+
90+
ret = is_hash_blacklisted(sig->digest, sig->digest_size, "tbs");
91+
if (ret == -EKEYREJECTED) {
92+
pr_err("Cert %*phN is blacklisted\n",
93+
sig->digest_size, sig->digest);
94+
cert->blacklisted = true;
95+
ret = 0;
96+
}
8797

8898
error_2:
8999
kfree(desc);
@@ -186,6 +196,11 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
186196
cert->sig->pkey_algo, cert->sig->hash_algo);
187197
}
188198

199+
/* Don't permit addition of blacklisted keys */
200+
ret = -EKEYREJECTED;
201+
if (cert->blacklisted)
202+
goto error_free_cert;
203+
189204
/* Propose a description */
190205
sulen = strlen(cert->subject);
191206
if (cert->raw_skid) {

0 commit comments

Comments
 (0)