12 #define pr_fmt(fmt) "X.509: "fmt
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
29 #if defined(CONFIG_PUBLIC_KEY_ALGO_RSA) || \
30 defined(CONFIG_PUBLIC_KEY_ALGO_RSA_MODULE)
38 static int x509_check_signature(
const struct public_key *pub,
44 size_t digest_size, desc_size;
54 return (PTR_ERR(tfm) == -
ENOENT) ? -
ENOPKG : PTR_ERR(tfm);
56 desc_size = crypto_shash_descsize(tfm) +
sizeof(*desc);
57 digest_size = crypto_shash_digestsize(tfm);
63 sig = kzalloc(
sizeof(*sig) + desc_size + digest_size,
GFP_KERNEL);
67 sig->pkey_hash_algo = cert->sig_hash_algo;
68 sig->
digest = (
u8 *)sig +
sizeof(*sig) + desc_size;
71 desc = (
void *)sig +
sizeof(*sig);
75 ret = crypto_shash_init(desc);
88 ret = pub->
algo->verify_signature(pub, sig);
90 pr_debug(
"Cert Verification: %d\n", ret);
97 crypto_free_shash(tfm);
99 pr_devel(
"<==%s() = %d\n", __func__, ret);
106 static int x509_key_preparse(
struct key_preparsed_payload *prep)
116 return PTR_ERR(cert);
121 pr_devel(
"Cert Valid From: %04ld-%02d-%02d %02d:%02d:%02d\n",
125 pr_devel(
"Cert Valid To: %04ld-%02d-%02d %02d:%02d:%02d\n",
129 pr_devel(
"Cert Signature: %s + %s\n",
134 pr_warn(
"Cert for '%s' must have SubjKeyId and AuthKeyId extensions\n",
137 goto error_free_cert;
141 pr_devel(
"Now: %04ld-%02d-%02d %02d:%02d:%02d\n",
142 now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
143 now.tm_hour, now.tm_min, now.tm_sec);
158 goto error_free_cert;
160 if (now.tm_year > cert->
valid_to.tm_year ||
161 (now.tm_year == cert->
valid_to.tm_year &&
162 (now.tm_mon > cert->
valid_to.tm_mon ||
163 (now.tm_mon == cert->
valid_to.tm_mon &&
164 (now.tm_mday > cert->
valid_to.tm_mday ||
165 (now.tm_mday == cert->
valid_to.tm_mday &&
166 (now.tm_hour > cert->
valid_to.tm_hour ||
167 (now.tm_hour == cert->
valid_to.tm_hour &&
168 (now.tm_min > cert->
valid_to.tm_min ||
169 (now.tm_min == cert->
valid_to.tm_min &&
174 goto error_free_cert;
177 cert->
pub->algo = x509_public_key_algorithms[cert->pkey_algo];
182 ret = x509_check_signature(cert->
pub, cert);
184 goto error_free_cert;
193 goto error_free_cert;
196 desc[sulen + 1] =
' ';
198 desc[sulen + 2 + srlen] = 0;
204 prep->payload = cert->
pub;
205 prep->description = desc;
206 prep->quotalen = 100;
222 .parse = x509_key_preparse,
228 static int __init x509_key_init(
void)
233 static void __exit x509_key_exit(
void)