David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 1 | /* Instantiate a public key crypto key from an X.509 Certificate |
| 2 | * |
| 3 | * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #define pr_fmt(fmt) "X.509: "fmt |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/mpi.h> |
| 18 | #include <linux/asn1_decoder.h> |
| 19 | #include <keys/asymmetric-subtype.h> |
| 20 | #include <keys/asymmetric-parser.h> |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 21 | #include <keys/system_keyring.h> |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 22 | #include <crypto/hash.h> |
| 23 | #include "asymmetric_keys.h" |
| 24 | #include "public_key.h" |
| 25 | #include "x509_parser.h" |
| 26 | |
Dmitry Kasatkin | 32c4741 | 2014-06-17 11:56:59 +0300 | [diff] [blame] | 27 | static bool use_builtin_keys; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 28 | static struct asymmetric_key_id *ca_keyid; |
Dmitry Kasatkin | ffb70f6 | 2014-06-17 11:56:58 +0300 | [diff] [blame] | 29 | |
| 30 | #ifndef MODULE |
| 31 | static int __init ca_keys_setup(char *str) |
| 32 | { |
| 33 | if (!str) /* default system keyring */ |
| 34 | return 1; |
| 35 | |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 36 | if (strncmp(str, "id:", 3) == 0) { |
| 37 | struct asymmetric_key_id *p; |
| 38 | p = asymmetric_key_hex_to_key_id(str); |
| 39 | if (p == ERR_PTR(-EINVAL)) |
| 40 | pr_err("Unparsable hex string in ca_keys\n"); |
| 41 | else if (!IS_ERR(p)) |
| 42 | ca_keyid = p; /* owner key 'id:xxxxxx' */ |
| 43 | } else if (strcmp(str, "builtin") == 0) { |
Dmitry Kasatkin | 32c4741 | 2014-06-17 11:56:59 +0300 | [diff] [blame] | 44 | use_builtin_keys = true; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 45 | } |
Dmitry Kasatkin | ffb70f6 | 2014-06-17 11:56:58 +0300 | [diff] [blame] | 46 | |
| 47 | return 1; |
| 48 | } |
| 49 | __setup("ca_keys=", ca_keys_setup); |
| 50 | #endif |
| 51 | |
David Howells | 5ce43ad | 2014-07-28 14:11:32 +0100 | [diff] [blame] | 52 | /** |
| 53 | * x509_request_asymmetric_key - Request a key by X.509 certificate params. |
| 54 | * @keyring: The keys to search. |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 55 | * @kid: The key ID. |
David Howells | 5ce43ad | 2014-07-28 14:11:32 +0100 | [diff] [blame] | 56 | * |
| 57 | * Find a key in the given keyring by subject name and key ID. These might, |
| 58 | * for instance, be the issuer name and the authority key ID of an X.509 |
| 59 | * certificate that needs to be verified. |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 60 | */ |
David Howells | 5ce43ad | 2014-07-28 14:11:32 +0100 | [diff] [blame] | 61 | struct key *x509_request_asymmetric_key(struct key *keyring, |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 62 | const struct asymmetric_key_id *kid) |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 63 | { |
| 64 | key_ref_t key; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 65 | char *id, *p; |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 66 | |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 67 | /* Construct an identifier "id:<keyid>". */ |
| 68 | p = id = kmalloc(2 + 1 + kid->len * 2 + 1, GFP_KERNEL); |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 69 | if (!id) |
| 70 | return ERR_PTR(-ENOMEM); |
| 71 | |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 72 | *p++ = 'i'; |
| 73 | *p++ = 'd'; |
| 74 | *p++ = ':'; |
| 75 | p = bin2hex(p, kid->data, kid->len); |
| 76 | *p = 0; |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 77 | |
| 78 | pr_debug("Look up: \"%s\"\n", id); |
| 79 | |
| 80 | key = keyring_search(make_key_ref(keyring, 1), |
| 81 | &key_type_asymmetric, id); |
| 82 | if (IS_ERR(key)) |
David Howells | 5ce43ad | 2014-07-28 14:11:32 +0100 | [diff] [blame] | 83 | pr_debug("Request for key '%s' err %ld\n", id, PTR_ERR(key)); |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 84 | kfree(id); |
| 85 | |
| 86 | if (IS_ERR(key)) { |
| 87 | switch (PTR_ERR(key)) { |
| 88 | /* Hide some search errors */ |
| 89 | case -EACCES: |
| 90 | case -ENOTDIR: |
| 91 | case -EAGAIN: |
| 92 | return ERR_PTR(-ENOKEY); |
| 93 | default: |
| 94 | return ERR_CAST(key); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | pr_devel("<==%s() = 0 [%x]\n", __func__, |
| 99 | key_serial(key_ref_to_ptr(key))); |
| 100 | return key_ref_to_ptr(key); |
| 101 | } |
David Howells | cf5b50f | 2014-08-03 12:54:48 +0100 | [diff] [blame] | 102 | EXPORT_SYMBOL_GPL(x509_request_asymmetric_key); |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 103 | |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 104 | /* |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 105 | * Set up the signature parameters in an X.509 certificate. This involves |
| 106 | * digesting the signed data and extracting the signature. |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 107 | */ |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 108 | int x509_get_sig_params(struct x509_certificate *cert) |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 109 | { |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 110 | struct crypto_shash *tfm; |
| 111 | struct shash_desc *desc; |
| 112 | size_t digest_size, desc_size; |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 113 | void *digest; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 114 | int ret; |
| 115 | |
| 116 | pr_devel("==>%s()\n", __func__); |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 117 | |
David Howells | 4155942 | 2014-09-16 17:36:15 +0100 | [diff] [blame] | 118 | if (cert->unsupported_crypto) |
| 119 | return -ENOPKG; |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 120 | if (cert->sig.rsa.s) |
| 121 | return 0; |
| 122 | |
| 123 | cert->sig.rsa.s = mpi_read_raw_data(cert->raw_sig, cert->raw_sig_size); |
| 124 | if (!cert->sig.rsa.s) |
| 125 | return -ENOMEM; |
| 126 | cert->sig.nr_mpi = 1; |
| 127 | |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 128 | /* Allocate the hashing algorithm we're going to need and find out how |
| 129 | * big the hash operational data will be. |
| 130 | */ |
Dmitry Kasatkin | 3fe78ca | 2013-05-06 15:58:15 +0300 | [diff] [blame] | 131 | tfm = crypto_alloc_shash(hash_algo_name[cert->sig.pkey_hash_algo], 0, 0); |
David Howells | 4155942 | 2014-09-16 17:36:15 +0100 | [diff] [blame] | 132 | if (IS_ERR(tfm)) { |
| 133 | if (PTR_ERR(tfm) == -ENOENT) { |
| 134 | cert->unsupported_crypto = true; |
| 135 | return -ENOPKG; |
| 136 | } |
| 137 | return PTR_ERR(tfm); |
| 138 | } |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 139 | |
| 140 | desc_size = crypto_shash_descsize(tfm) + sizeof(*desc); |
| 141 | digest_size = crypto_shash_digestsize(tfm); |
| 142 | |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 143 | /* We allocate the hash operational data storage on the end of the |
| 144 | * digest storage space. |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 145 | */ |
| 146 | ret = -ENOMEM; |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 147 | digest = kzalloc(digest_size + desc_size, GFP_KERNEL); |
| 148 | if (!digest) |
| 149 | goto error; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 150 | |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 151 | cert->sig.digest = digest; |
| 152 | cert->sig.digest_size = digest_size; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 153 | |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 154 | desc = digest + digest_size; |
| 155 | desc->tfm = tfm; |
| 156 | desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 157 | |
| 158 | ret = crypto_shash_init(desc); |
| 159 | if (ret < 0) |
| 160 | goto error; |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 161 | might_sleep(); |
| 162 | ret = crypto_shash_finup(desc, cert->tbs, cert->tbs_size, digest); |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 163 | error: |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 164 | crypto_free_shash(tfm); |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 165 | pr_devel("<==%s() = %d\n", __func__, ret); |
| 166 | return ret; |
| 167 | } |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 168 | EXPORT_SYMBOL_GPL(x509_get_sig_params); |
| 169 | |
| 170 | /* |
| 171 | * Check the signature on a certificate using the provided public key |
| 172 | */ |
| 173 | int x509_check_signature(const struct public_key *pub, |
| 174 | struct x509_certificate *cert) |
| 175 | { |
| 176 | int ret; |
| 177 | |
| 178 | pr_devel("==>%s()\n", __func__); |
| 179 | |
| 180 | ret = x509_get_sig_params(cert); |
| 181 | if (ret < 0) |
| 182 | return ret; |
| 183 | |
| 184 | ret = public_key_verify_signature(pub, &cert->sig); |
David Howells | 4155942 | 2014-09-16 17:36:15 +0100 | [diff] [blame] | 185 | if (ret == -ENOPKG) |
| 186 | cert->unsupported_crypto = true; |
David Howells | b426beb | 2013-08-30 16:18:02 +0100 | [diff] [blame] | 187 | pr_debug("Cert Verification: %d\n", ret); |
| 188 | return ret; |
| 189 | } |
| 190 | EXPORT_SYMBOL_GPL(x509_check_signature); |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 191 | |
| 192 | /* |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 193 | * Check the new certificate against the ones in the trust keyring. If one of |
| 194 | * those is the signing key and validates the new certificate, then mark the |
| 195 | * new certificate as being trusted. |
| 196 | * |
| 197 | * Return 0 if the new certificate was successfully validated, 1 if we couldn't |
| 198 | * find a matching parent certificate in the trusted list and an error if there |
| 199 | * is a matching certificate but the signature check fails. |
| 200 | */ |
| 201 | static int x509_validate_trust(struct x509_certificate *cert, |
| 202 | struct key *trust_keyring) |
| 203 | { |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 204 | struct key *key; |
| 205 | int ret = 1; |
| 206 | |
| 207 | if (!trust_keyring) |
| 208 | return -EOPNOTSUPP; |
| 209 | |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 210 | if (ca_keyid && !asymmetric_key_id_same(cert->authority, ca_keyid)) |
Dmitry Kasatkin | ffb70f6 | 2014-06-17 11:56:58 +0300 | [diff] [blame] | 211 | return -EPERM; |
| 212 | |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 213 | key = x509_request_asymmetric_key(trust_keyring, cert->authority); |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 214 | if (!IS_ERR(key)) { |
Dmitry Kasatkin | 32c4741 | 2014-06-17 11:56:59 +0300 | [diff] [blame] | 215 | if (!use_builtin_keys |
| 216 | || test_bit(KEY_FLAG_BUILTIN, &key->flags)) |
| 217 | ret = x509_check_signature(key->payload.data, cert); |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 218 | key_put(key); |
| 219 | } |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | /* |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 224 | * Attempt to parse a data blob for a key as an X509 certificate. |
| 225 | */ |
| 226 | static int x509_key_preparse(struct key_preparsed_payload *prep) |
| 227 | { |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 228 | struct asymmetric_key_ids *kids; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 229 | struct x509_certificate *cert; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 230 | const char *q; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 231 | size_t srlen, sulen; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 232 | char *desc = NULL, *p; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 233 | int ret; |
| 234 | |
| 235 | cert = x509_cert_parse(prep->data, prep->datalen); |
| 236 | if (IS_ERR(cert)) |
| 237 | return PTR_ERR(cert); |
| 238 | |
| 239 | pr_devel("Cert Issuer: %s\n", cert->issuer); |
| 240 | pr_devel("Cert Subject: %s\n", cert->subject); |
David Howells | 2ecdb23 | 2013-08-30 16:18:15 +0100 | [diff] [blame] | 241 | |
| 242 | if (cert->pub->pkey_algo >= PKEY_ALGO__LAST || |
| 243 | cert->sig.pkey_algo >= PKEY_ALGO__LAST || |
| 244 | cert->sig.pkey_hash_algo >= PKEY_HASH__LAST || |
| 245 | !pkey_algo[cert->pub->pkey_algo] || |
| 246 | !pkey_algo[cert->sig.pkey_algo] || |
Dmitry Kasatkin | 3fe78ca | 2013-05-06 15:58:15 +0300 | [diff] [blame] | 247 | !hash_algo_name[cert->sig.pkey_hash_algo]) { |
David Howells | 2ecdb23 | 2013-08-30 16:18:15 +0100 | [diff] [blame] | 248 | ret = -ENOPKG; |
| 249 | goto error_free_cert; |
| 250 | } |
| 251 | |
David Howells | 67f7d60b | 2013-08-30 16:15:24 +0100 | [diff] [blame] | 252 | pr_devel("Cert Key Algo: %s\n", pkey_algo_name[cert->pub->pkey_algo]); |
David Howells | 2f1c4fe | 2012-10-04 14:21:23 +0100 | [diff] [blame] | 253 | pr_devel("Cert Valid From: %04ld-%02d-%02d %02d:%02d:%02d\n", |
David Howells | a5752d1 | 2012-10-02 14:36:16 +0100 | [diff] [blame] | 254 | cert->valid_from.tm_year + 1900, cert->valid_from.tm_mon + 1, |
| 255 | cert->valid_from.tm_mday, cert->valid_from.tm_hour, |
| 256 | cert->valid_from.tm_min, cert->valid_from.tm_sec); |
David Howells | 2f1c4fe | 2012-10-04 14:21:23 +0100 | [diff] [blame] | 257 | pr_devel("Cert Valid To: %04ld-%02d-%02d %02d:%02d:%02d\n", |
David Howells | a5752d1 | 2012-10-02 14:36:16 +0100 | [diff] [blame] | 258 | cert->valid_to.tm_year + 1900, cert->valid_to.tm_mon + 1, |
| 259 | cert->valid_to.tm_mday, cert->valid_to.tm_hour, |
| 260 | cert->valid_to.tm_min, cert->valid_to.tm_sec); |
Dmitry Kasatkin | c7c8bb2 | 2013-04-25 10:43:56 +0300 | [diff] [blame] | 261 | pr_devel("Cert Signature: %s + %s\n", |
| 262 | pkey_algo_name[cert->sig.pkey_algo], |
Dmitry Kasatkin | 3fe78ca | 2013-05-06 15:58:15 +0300 | [diff] [blame] | 263 | hash_algo_name[cert->sig.pkey_hash_algo]); |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 264 | |
David Howells | 67f7d60b | 2013-08-30 16:15:24 +0100 | [diff] [blame] | 265 | cert->pub->algo = pkey_algo[cert->pub->pkey_algo]; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 266 | cert->pub->id_type = PKEY_ID_X509; |
| 267 | |
David Howells | 17334ca | 2013-08-30 16:18:31 +0100 | [diff] [blame] | 268 | /* Check the signature on the key if it appears to be self-signed */ |
| 269 | if (!cert->authority || |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 270 | asymmetric_key_id_same(cert->skid, cert->authority)) { |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 271 | ret = x509_check_signature(cert->pub, cert); /* self-signed */ |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 272 | if (ret < 0) |
| 273 | goto error_free_cert; |
Mimi Zohar | 3be4bea | 2013-08-20 14:36:27 -0400 | [diff] [blame] | 274 | } else if (!prep->trusted) { |
| 275 | ret = x509_validate_trust(cert, get_system_trusted_keyring()); |
| 276 | if (!ret) |
| 277 | prep->trusted = 1; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* Propose a description */ |
| 281 | sulen = strlen(cert->subject); |
David Howells | dd2f6c4 | 2014-10-03 16:17:02 +0100 | [diff] [blame^] | 282 | if (cert->raw_skid) { |
| 283 | srlen = cert->raw_skid_size; |
| 284 | q = cert->raw_skid; |
| 285 | } else { |
| 286 | srlen = cert->raw_serial_size; |
| 287 | q = cert->raw_serial; |
| 288 | } |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 289 | if (srlen > 1 && *q == 0) { |
| 290 | srlen--; |
| 291 | q++; |
| 292 | } |
| 293 | |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 294 | ret = -ENOMEM; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 295 | desc = kmalloc(sulen + 2 + srlen * 2 + 1, GFP_KERNEL); |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 296 | if (!desc) |
| 297 | goto error_free_cert; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 298 | p = memcpy(desc, cert->subject, sulen); |
| 299 | p += sulen; |
| 300 | *p++ = ':'; |
| 301 | *p++ = ' '; |
| 302 | p = bin2hex(p, q, srlen); |
| 303 | *p = 0; |
| 304 | |
| 305 | kids = kmalloc(sizeof(struct asymmetric_key_ids), GFP_KERNEL); |
| 306 | if (!kids) |
| 307 | goto error_free_desc; |
| 308 | kids->id[0] = cert->id; |
| 309 | kids->id[1] = cert->skid; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 310 | |
| 311 | /* We're pinning the module by being linked against it */ |
| 312 | __module_get(public_key_subtype.owner); |
| 313 | prep->type_data[0] = &public_key_subtype; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 314 | prep->type_data[1] = kids; |
David Howells | fc7c70e | 2014-07-18 18:56:34 +0100 | [diff] [blame] | 315 | prep->payload[0] = cert->pub; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 316 | prep->description = desc; |
| 317 | prep->quotalen = 100; |
| 318 | |
| 319 | /* We've finished with the certificate */ |
| 320 | cert->pub = NULL; |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 321 | cert->id = NULL; |
| 322 | cert->skid = NULL; |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 323 | desc = NULL; |
| 324 | ret = 0; |
| 325 | |
David Howells | 46963b7 | 2014-09-16 17:36:13 +0100 | [diff] [blame] | 326 | error_free_desc: |
| 327 | kfree(desc); |
David Howells | c26fd69 | 2012-09-24 17:11:48 +0100 | [diff] [blame] | 328 | error_free_cert: |
| 329 | x509_free_certificate(cert); |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | static struct asymmetric_key_parser x509_key_parser = { |
| 334 | .owner = THIS_MODULE, |
| 335 | .name = "x509", |
| 336 | .parse = x509_key_preparse, |
| 337 | }; |
| 338 | |
| 339 | /* |
| 340 | * Module stuff |
| 341 | */ |
| 342 | static int __init x509_key_init(void) |
| 343 | { |
| 344 | return register_asymmetric_key_parser(&x509_key_parser); |
| 345 | } |
| 346 | |
| 347 | static void __exit x509_key_exit(void) |
| 348 | { |
| 349 | unregister_asymmetric_key_parser(&x509_key_parser); |
| 350 | } |
| 351 | |
| 352 | module_init(x509_key_init); |
| 353 | module_exit(x509_key_exit); |
Konstantin Khlebnikov | e19aaa7 | 2013-09-17 15:14:55 +0400 | [diff] [blame] | 354 | |
| 355 | MODULE_DESCRIPTION("X.509 certificate parser"); |
| 356 | MODULE_LICENSE("GPL"); |