Skip to content

Commit 2c62068

Browse files
committed
x509: Separately calculate sha256 for blacklist
Calculate the SHA256 hash for blacklisting purposes independently of the signature hash (which may be something other than SHA256). This is necessary because when ML-DSA is used, no digest is calculated. Note that this represents a change of behaviour in that the hash used for the blacklist check would previously have been whatever digest was used for, say, RSA-based signatures. It may be that this is inadvisable. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org
1 parent d3b6dd9 commit 2c62068

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

crypto/asymmetric_keys/x509_parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
#include <linux/time.h>
1010
#include <crypto/public_key.h>
1111
#include <keys/asymmetric-type.h>
12+
#include <crypto/sha2.h>
1213

1314
struct x509_certificate {
1415
struct x509_certificate *next;
1516
struct x509_certificate *signer; /* Certificate that signed this one */
1617
struct public_key *pub; /* Public key details */
1718
struct public_key_signature *sig; /* Signature parameters */
19+
u8 sha256[SHA256_DIGEST_SIZE]; /* Hash for blacklist purposes */
1820
char *issuer; /* Name of certificate issuer */
1921
char *subject; /* Name of certificate subject */
2022
struct asymmetric_key_id *id; /* Issuer + Serial number */

crypto/asymmetric_keys/x509_public_key.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ int x509_get_sig_params(struct x509_certificate *cert)
3131

3232
pr_devel("==>%s()\n", __func__);
3333

34+
/* Calculate a SHA256 hash of the TBS and check it against the
35+
* blacklist.
36+
*/
37+
sha256(cert->tbs, cert->tbs_size, cert->sha256);
38+
ret = is_hash_blacklisted(cert->sha256, sizeof(cert->sha256),
39+
BLACKLIST_HASH_X509_TBS);
40+
if (ret == -EKEYREJECTED) {
41+
pr_err("Cert %*phN is blacklisted\n",
42+
(int)sizeof(cert->sha256), cert->sha256);
43+
cert->blacklisted = true;
44+
ret = 0;
45+
}
46+
3447
sig->s = kmemdup(cert->raw_sig, cert->raw_sig_size, GFP_KERNEL);
3548
if (!sig->s)
3649
return -ENOMEM;
@@ -69,15 +82,6 @@ int x509_get_sig_params(struct x509_certificate *cert)
6982
if (ret < 0)
7083
goto error_2;
7184

72-
ret = is_hash_blacklisted(sig->digest, sig->digest_size,
73-
BLACKLIST_HASH_X509_TBS);
74-
if (ret == -EKEYREJECTED) {
75-
pr_err("Cert %*phN is blacklisted\n",
76-
sig->digest_size, sig->digest);
77-
cert->blacklisted = true;
78-
ret = 0;
79-
}
80-
8185
error_2:
8286
kfree(desc);
8387
error:

0 commit comments

Comments
 (0)