From: David Howells <dhowells@redhat.com>
To: keyrings@vger.kernel.org
Cc: dhowells@redhat.com, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 7/7] There's a bug in the code determining whether a certificate is self-signed
Date: Mon, 29 Feb 2016 18:22:24 +0000 [thread overview]
Message-ID: <20160229182224.27797.31380.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20160229182136.27797.75917.stgit@warthog.procyon.org.uk>
or not: if they have neither AKID nor SKID then we just assume that the
cert is self-signed, which may not be true.
Fix this by checking that the raw subject name matches the raw issuer name
and that the public key algorithm for the key and signature are both the
same in addition to requiring that the AKID bits match.
Signed-off-by: David Howells <dhowells@redhat.com>
---
crypto/asymmetric_keys/x509_public_key.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c
index 0d5b9add313f..da42acd492b6 100644
--- a/crypto/asymmetric_keys/x509_public_key.c
+++ b/crypto/asymmetric_keys/x509_public_key.c
@@ -230,6 +230,11 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
pr_devel("==>%s()\n", __func__);
+ if (cert->raw_subject_size != cert->raw_issuer_size ||
+ memcmp(cert->raw_subject, cert->raw_issuer,
+ cert->raw_issuer_size) != 0)
+ goto not_self_signed;
+
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.
@@ -246,6 +251,10 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
goto out;
}
+ ret = -EKEYREJECTED;
+ if (cert->pub->pkey_algo != cert->sig->pkey_algo)
+ goto out;
+
ret = public_key_verify_signature(cert->pub, cert->sig);
if (ret < 0) {
if (ret == -ENOPKG) {
next prev parent reply other threads:[~2016-02-29 18:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 18:21 [RFC PATCH 0/7] KEYS: Adjust public key signature handling David Howells
2016-02-29 18:21 ` [RFC PATCH 1/7] X.509: Whitespace cleanup David Howells
2016-02-29 18:21 ` [RFC PATCH 2/7] KEYS: Allow authentication data to be stored in an asymmetric key David Howells
2016-02-29 18:21 ` [RFC PATCH 3/7] KEYS: Add identifier pointers to public_key_signature struct David Howells
2016-02-29 18:22 ` [RFC PATCH 4/7] X.509: Retain the key verification data David Howells
2016-02-29 18:22 ` [RFC PATCH 5/7] PKCS#7: Make the signature a pointer rather than embedding it David Howells
2016-02-29 18:22 ` [RFC PATCH 6/7] X.509: Extract signature digest and make self-signed cert checks earlier David Howells
2016-02-29 18:22 ` David Howells [this message]
2016-03-02 12:10 ` [RFC PATCH 0/7] KEYS: Adjust public key signature handling Mimi Zohar
2016-03-02 12:24 ` David Howells
2016-03-02 15:00 ` Mimi Zohar
2016-03-04 11:22 ` David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160229182224.27797.31380.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®