// SPDX-License-Identifier: GPL-2.0-or-later /* Instantiate a public key crypto key from an X.509 Certificate * * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com)
*/
/* * Set up the signature parameters in an X.509 certificate. This involves * digesting the signed data and extracting the signature.
*/ int x509_get_sig_params(struct x509_certificate *cert)
{ struct public_key_signature *sig = cert->sig; struct crypto_shash *tfm; struct shash_desc *desc;
size_t desc_size; int ret;
pr_devel("==>%s()\n", __func__);
sig->s = kmemdup(cert->raw_sig, cert->raw_sig_size, GFP_KERNEL); if (!sig->s) return -ENOMEM;
sig->s_size = cert->raw_sig_size;
/* Allocate the hashing algorithm we're going to need and find out how * big the hash operational data will be.
*/
tfm = crypto_alloc_shash(sig->hash_algo, 0, 0); if (IS_ERR(tfm)) { if (PTR_ERR(tfm) == -ENOENT) {
cert->unsupported_sig = true; return 0;
} return PTR_ERR(tfm);
}
/* * Check for self-signedness in an X.509 cert and if found, check the signature * immediately if we can.
*/ int x509_check_for_self_signed(struct x509_certificate *cert)
{ int ret = 0;
if (cert->sig->auth_ids[0] || cert->sig->auth_ids[1]) { /* If the AKID is present it may have one or two parts. If * both are supplied, both must match.
*/ bool a = asymmetric_key_id_same(cert->skid, cert->sig->auth_ids[1]); bool b = asymmetric_key_id_same(cert->id, cert->sig->auth_ids[0]);
if (!a && !b) goto not_self_signed;
ret = -EKEYREJECTED; if (((a && !b) || (b && !a)) &&
cert->sig->auth_ids[0] && cert->sig->auth_ids[1]) goto out;
}
if (cert->unsupported_sig) {
ret = 0; goto out;
}
ret = public_key_verify_signature(cert->pub, cert->sig); if (ret < 0) { if (ret == -ENOPKG) {
cert->unsupported_sig = true;
ret = 0;
} goto out;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.