Commit adbb7787 authored by David Howells's avatar David Howells

X.509: Don't treat self-signed keys specially

Trust for a self-signed certificate can normally only be determined by
whether we obtained it from a trusted location (ie. it was built into the
kernel at compile time), so there's not really any point in checking it -
we could verify that the signature is valid, but it doesn't really tell us
anything if the signature checks out.

However, there's a bug in the code determining whether a certificate is
self-signed or not - if they have neither AKID nor SKID then we just assume
that the cert is self-signed, which may not be true.

Given this, remove the code that treats self-signed certs specially when it
comes to evaluating trustability and attempt to evaluate them as ordinary
signed certificates.  We then expect self-signed certificates to fail the
trustability check and be marked as untrustworthy in x509_key_preparse().

Note that there is the possibility of the trustability check on a
self-signed cert then succeeding.  This is most likely to happen when a
duplicate of the certificate is already on the trust keyring - in which
case it shouldn't be a problem.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: David Woodhouse <David.Woodhouse@intel.com>
cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
parent aa9eeca6
...@@ -255,6 +255,9 @@ static int x509_validate_trust(struct x509_certificate *cert, ...@@ -255,6 +255,9 @@ static int x509_validate_trust(struct x509_certificate *cert,
struct key *key; struct key *key;
int ret = 1; int ret = 1;
if (!cert->akid_id && !cert->akid_skid)
return 1;
if (!trust_keyring) if (!trust_keyring)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -312,17 +315,21 @@ static int x509_key_preparse(struct key_preparsed_payload *prep) ...@@ -312,17 +315,21 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
cert->pub->algo = pkey_algo[cert->pub->pkey_algo]; cert->pub->algo = pkey_algo[cert->pub->pkey_algo];
cert->pub->id_type = PKEY_ID_X509; cert->pub->id_type = PKEY_ID_X509;
/* Check the signature on the key if it appears to be self-signed */ /* See if we can derive the trustability of this certificate.
if ((!cert->akid_skid && !cert->akid_id) || *
asymmetric_key_id_same(cert->skid, cert->akid_skid) || * When it comes to self-signed certificates, we cannot evaluate
asymmetric_key_id_same(cert->id, cert->akid_id)) { * trustedness except by the fact that we obtained it from a trusted
ret = x509_check_signature(cert->pub, cert); /* self-signed */ * location. So we just rely on x509_validate_trust() failing in this
if (ret < 0) * case.
goto error_free_cert; *
} else if (!prep->trusted) { * Note that there's a possibility of a self-signed cert matching a
* cert that we have (most likely a duplicate that we already trust) -
* in which case it will be marked trusted.
*/
if (!prep->trusted) {
ret = x509_validate_trust(cert, get_system_trusted_keyring()); ret = x509_validate_trust(cert, get_system_trusted_keyring());
if (!ret) if (!ret)
prep->trusted = 1; prep->trusted = true;
} }
/* Propose a description */ /* Propose a description */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment