^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Instantiate a public key crypto key from an X.509 Certificate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2012, 2016 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) "ASYM: "fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <crypto/public_key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "asymmetric_keys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static bool use_builtin_keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static struct asymmetric_key_id *ca_keyid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct asymmetric_key_id id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) unsigned char data[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) } cakey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int __init ca_keys_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) if (!str) /* default system keyring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (strncmp(str, "id:", 3) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct asymmetric_key_id *p = &cakey.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) size_t hexlen = (strlen(str) - 3) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (hexlen == 0 || hexlen > sizeof(cakey.data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) pr_err("Missing or invalid ca_keys id\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ret = __asymmetric_key_hex_to_key_id(str + 3, p, hexlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) pr_err("Unparsable ca_keys id hex string\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ca_keyid = p; /* owner key 'id:xxxxxx' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } else if (strcmp(str, "builtin") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) use_builtin_keys = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __setup("ca_keys=", ca_keys_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * restrict_link_by_signature - Restrict additions to a ring of public keys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @dest_keyring: Keyring being linked to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @type: The type of key being added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @payload: The payload of the new key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @trust_keyring: A ring of keys that can be used to vouch for the new cert.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Check the new certificate against the ones in the trust keyring. If one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * those is the signing key and validates the new certificate, then mark the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * new certificate as being trusted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Returns 0 if the new certificate was accepted, -ENOKEY if we couldn't find a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * matching parent certificate in the trusted list, -EKEYREJECTED if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * signature check fails or the key is blacklisted, -ENOPKG if the signature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * uses unsupported crypto, or some other error if there is a matching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * certificate but the signature check cannot be performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int restrict_link_by_signature(struct key *dest_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct key *trust_keyring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct public_key_signature *sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) pr_devel("==>%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!trust_keyring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (type != &key_type_asymmetric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sig = payload->data[asym_auth];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (!sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return -ENOPKG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!sig->auth_ids[0] && !sig->auth_ids[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ca_keyid && !asymmetric_key_id_partial(sig->auth_ids[1], ca_keyid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* See if we have a key that signed this one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) key = find_asymmetric_key(trust_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) sig->auth_ids[0], sig->auth_ids[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (IS_ERR(key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (use_builtin_keys && !test_bit(KEY_FLAG_BUILTIN, &key->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ret = -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ret = verify_signature(key, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) key_put(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static bool match_either_id(const struct asymmetric_key_ids *pair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) const struct asymmetric_key_id *single)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return (asymmetric_key_id_same(pair->id[0], single) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) asymmetric_key_id_same(pair->id[1], single));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int key_or_keyring_common(struct key *dest_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct key *trusted, bool check_dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) const struct public_key_signature *sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct key *key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) pr_devel("==>%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (!dest_keyring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) else if (dest_keyring->type != &key_type_keyring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (!trusted && !check_dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (type != &key_type_asymmetric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) sig = payload->data[asym_auth];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return -ENOPKG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!sig->auth_ids[0] && !sig->auth_ids[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (trusted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (trusted->type == &key_type_keyring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* See if we have a key that signed this one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) key = find_asymmetric_key(trusted, sig->auth_ids[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) sig->auth_ids[1], false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (IS_ERR(key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) } else if (trusted->type == &key_type_asymmetric) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) const struct asymmetric_key_ids *signer_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) signer_ids = asymmetric_key_ids(trusted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * The auth_ids come from the candidate key (the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * one that is being considered for addition to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * dest_keyring) and identify the key that was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * used to sign.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * The signer_ids are identifiers for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * signing key specified for dest_keyring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * The first auth_id is the preferred id, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * the second is the fallback. If only one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * auth_id is present, it may match against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * either signer_id. If two auth_ids are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * present, the first auth_id must match one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * signer_id and the second auth_id must match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * the second signer_id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (!sig->auth_ids[0] || !sig->auth_ids[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) const struct asymmetric_key_id *auth_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) auth_id = sig->auth_ids[0] ?: sig->auth_ids[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (match_either_id(signer_ids, auth_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) key = __key_get(trusted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) } else if (asymmetric_key_id_same(signer_ids->id[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) sig->auth_ids[1]) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) match_either_id(signer_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) sig->auth_ids[0])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) key = __key_get(trusted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (check_dest && !key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* See if the destination has a key that signed this one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) key = find_asymmetric_key(dest_keyring, sig->auth_ids[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) sig->auth_ids[1], false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (IS_ERR(key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ret = key_validate(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ret = verify_signature(key, sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) key_put(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * restrict_link_by_key_or_keyring - Restrict additions to a ring of public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * keys using the restrict_key information stored in the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * @dest_keyring: Keyring being linked to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * @type: The type of key being added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * @payload: The payload of the new key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * @trusted: A key or ring of keys that can be used to vouch for the new cert.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Check the new certificate only against the key or keys passed in the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * parameter. If one of those is the signing key and validates the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * certificate, then mark the new certificate as being ok to link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Returns 0 if the new certificate was accepted, -ENOKEY if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * couldn't find a matching parent certificate in the trusted list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * -EKEYREJECTED if the signature check fails, -ENOPKG if the signature uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * unsupported crypto, or some other error if there is a matching certificate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * but the signature check cannot be performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int restrict_link_by_key_or_keyring(struct key *dest_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct key *trusted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return key_or_keyring_common(dest_keyring, type, payload, trusted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * restrict_link_by_key_or_keyring_chain - Restrict additions to a ring of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * public keys using the restrict_key information stored in the ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * @dest_keyring: Keyring being linked to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * @type: The type of key being added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * @payload: The payload of the new key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * @trusted: A key or ring of keys that can be used to vouch for the new cert.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * Check the new certificate only against the key or keys passed in the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * parameter. If one of those is the signing key and validates the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * certificate, then mark the new certificate as being ok to link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Returns 0 if the new certificate was accepted, -ENOKEY if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * couldn't find a matching parent certificate in the trusted list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * -EKEYREJECTED if the signature check fails, -ENOPKG if the signature uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * unsupported crypto, or some other error if there is a matching certificate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * but the signature check cannot be performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int restrict_link_by_key_or_keyring_chain(struct key *dest_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct key *trusted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return key_or_keyring_common(dest_keyring, type, payload, trusted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }