Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1294349 > unrolled thread

[PATCH] X.509: Fix determination of self-signedness

Started byDavid Howells <dhowells@redhat.com>
First post2015-12-18 01:10 +0100
Last post2015-12-18 15:50 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] X.509: Fix determination of self-signedness David Howells <dhowells@redhat.com> - 2015-12-18 01:10 +0100
    Re: [PATCH] X.509: Fix determination of self-signedness Josh Boyer <jwboyer@fedoraproject.org> - 2015-12-18 15:50 +0100
      Re: [PATCH] X.509: Fix determination of self-signedness David Howells <dhowells@redhat.com> - 2015-12-18 15:50 +0100

#1294349 — [PATCH] X.509: Fix determination of self-signedness

FromDavid Howells <dhowells@redhat.com>
Date2015-12-18 01:10 +0100
Subject[PATCH] X.509: Fix determination of self-signedness
Message-ID<qGQMp-6FZ-15@gated-at.bofh.it>
Fix determination of whether an X.509 certificate is self-signed or not.

It is currently assumed that a cert is self-signed if has no
authorityKeyIdentifier or the authorityKeyIdentifier matches the
subjectKeyIdentifier.  However, it is possible to encounter a certificate
that has neither AKID not SKID but is not self-signed.

This symptoms of this show up as an attempt to load a certificate failing
with -ERANGE or -EBADMSG, produced from the RSA module when the result of
calculating "m = s^e mod n" is checked.

To fix this, don't check to see if a certificate is self-signed if the
Issuer and Subject names differ.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: David Woodhouse <David.Woodhouse@intel.com>
---

 crypto/asymmetric_keys/x509_public_key.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c
index 2a44b3752471..6236e7996f19 100644
--- a/crypto/asymmetric_keys/x509_public_key.c
+++ b/crypto/asymmetric_keys/x509_public_key.c
@@ -313,9 +313,14 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
 	cert->pub->id_type = PKEY_ID_X509;
 
 	/* Check the signature on the key if it appears to be self-signed */
-	if ((!cert->akid_skid && !cert->akid_id) ||
-	    asymmetric_key_id_same(cert->skid, cert->akid_skid) ||
-	    asymmetric_key_id_same(cert->id, cert->akid_id)) {
+	if ((!cert->akid_skid && !cert->akid_id)) {
+		if (cert->raw_issuer_size == cert->raw_subject_size &&
+		    memcmp(cert->raw_issuer, cert->raw_subject,
+			   cert->raw_subject_size) == 0)
+			goto self_signed;
+	} else if (asymmetric_key_id_same(cert->skid, cert->akid_skid) ||
+		   asymmetric_key_id_same(cert->id, cert->akid_id)) {
+self_signed:
 		ret = x509_check_signature(cert->pub, cert); /* self-signed */
 		if (ret < 0)
 			goto error_free_cert;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1294921

FromJosh Boyer <jwboyer@fedoraproject.org>
Date2015-12-18 15:50 +0100
Message-ID<qH4w2-6U7-5@gated-at.bofh.it>
In reply to#1294349
On Thu, Dec 17, 2015 at 7:03 PM, David Howells <dhowells@redhat.com> wrote:
> Fix determination of whether an X.509 certificate is self-signed or not.
>
> It is currently assumed that a cert is self-signed if has no
> authorityKeyIdentifier or the authorityKeyIdentifier matches the
> subjectKeyIdentifier.  However, it is possible to encounter a certificate
> that has neither AKID not SKID but is not self-signed.
>
> This symptoms of this show up as an attempt to load a certificate failing
> with -ERANGE or -EBADMSG, produced from the RSA module when the result of
> calculating "m = s^e mod n" is checked.
>
> To fix this, don't check to see if a certificate is self-signed if the
> Issuer and Subject names differ.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: David Woodhouse <David.Woodhouse@intel.com>

Should this also be Cc'd to stable?

josh

> ---
>
>  crypto/asymmetric_keys/x509_public_key.c |   11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c
> index 2a44b3752471..6236e7996f19 100644
> --- a/crypto/asymmetric_keys/x509_public_key.c
> +++ b/crypto/asymmetric_keys/x509_public_key.c
> @@ -313,9 +313,14 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
>         cert->pub->id_type = PKEY_ID_X509;
>
>         /* Check the signature on the key if it appears to be self-signed */
> -       if ((!cert->akid_skid && !cert->akid_id) ||
> -           asymmetric_key_id_same(cert->skid, cert->akid_skid) ||
> -           asymmetric_key_id_same(cert->id, cert->akid_id)) {
> +       if ((!cert->akid_skid && !cert->akid_id)) {
> +               if (cert->raw_issuer_size == cert->raw_subject_size &&
> +                   memcmp(cert->raw_issuer, cert->raw_subject,
> +                          cert->raw_subject_size) == 0)
> +                       goto self_signed;
> +       } else if (asymmetric_key_id_same(cert->skid, cert->akid_skid) ||
> +                  asymmetric_key_id_same(cert->id, cert->akid_id)) {
> +self_signed:
>                 ret = x509_check_signature(cert->pub, cert); /* self-signed */
>                 if (ret < 0)
>                         goto error_free_cert;
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1294927

FromDavid Howells <dhowells@redhat.com>
Date2015-12-18 15:50 +0100
Message-ID<qH4w2-6U7-15@gated-at.bofh.it>
In reply to#1294921
Josh Boyer <jwboyer@fedoraproject.org> wrote:

> Should this also be Cc'd to stable?

Argh.  Probably.

David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web