From: Jarkko Sakkinen <jarkko@kernel.org>
To: Stefan Berger <stefanb@linux.vnet.ibm.com>
Cc: keyrings@vger.kernel.org, linux-crypto@vger.kernel.org,
davem@davemloft.net, herbert@gondor.apana.org.au,
dhowells@redhat.com, zohar@linux.ibm.com,
linux-kernel@vger.kernel.org, patrick@puiterwijk.org,
linux-integrity@vger.kernel.org,
Stefan Berger <stefanb@linux.ibm.com>
Subject: Re: [PATCH v10 6/9] x509: Add support for parsing x509 certs with ECDSA keys
Date: Fri, 5 Mar 2021 19:07:13 +0200 [thread overview]
Message-ID: <YEJlQUC5pfIemTaI@kernel.org> (raw)
In-Reply-To: <20210305005203.3547587-7-stefanb@linux.vnet.ibm.com>
On Thu, Mar 04, 2021 at 07:52:00PM -0500, Stefan Berger wrote:
> From: Stefan Berger <stefanb@linux.ibm.com>
>
> This patch adds support for parsing of x509 certificates that contain
"Add support..." instead of "This patch adds"
> ECDSA keys, such as NIST P256, that have been signed by a CA using any
> of the current SHA hash algorithms.
>
> Cc: David Howells <dhowells@redhat.com>
> Cc: keyrings@vger.kernel.org
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
/Jarkko
>
> ---
>
> v7->v8:
> - do not detect key algo using parse_OID() in public_key.c but set
> pkey_algo to the key type 'ecdsa-nist-p192/256' when parsing cert
> ---
> crypto/asymmetric_keys/public_key.c | 4 ++-
> crypto/asymmetric_keys/x509_cert_parser.c | 34 ++++++++++++++++++++++-
> crypto/asymmetric_keys/x509_public_key.c | 4 ++-
> include/linux/oid_registry.h | 2 ++
> 4 files changed, 41 insertions(+), 3 deletions(-)
>
> diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> index 788a4ba1e2e7..4fefb219bfdc 100644
> --- a/crypto/asymmetric_keys/public_key.c
> +++ b/crypto/asymmetric_keys/public_key.c
> @@ -14,6 +14,7 @@
> #include <linux/slab.h>
> #include <linux/seq_file.h>
> #include <linux/scatterlist.h>
> +#include <linux/asn1.h>
> #include <keys/asymmetric-subtype.h>
> #include <crypto/public_key.h>
> #include <crypto/akcipher.h>
> @@ -85,7 +86,8 @@ int software_key_determine_akcipher(const char *encoding,
> return n >= CRYPTO_MAX_ALG_NAME ? -EINVAL : 0;
> }
>
> - if (strcmp(encoding, "raw") == 0) {
> + if (strcmp(encoding, "raw") == 0 ||
> + strcmp(encoding, "x962") == 0) {
> strcpy(alg_name, pkey->pkey_algo);
> return 0;
> }
> diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
> index 1621ceaf5c95..f5d547c6dfb5 100644
> --- a/crypto/asymmetric_keys/x509_cert_parser.c
> +++ b/crypto/asymmetric_keys/x509_cert_parser.c
> @@ -227,6 +227,26 @@ int x509_note_pkey_algo(void *context, size_t hdrlen,
> ctx->cert->sig->hash_algo = "sha224";
> goto rsa_pkcs1;
>
> + case OID_id_ecdsa_with_sha1:
> + ctx->cert->sig->hash_algo = "sha1";
> + goto ecdsa;
> +
> + case OID_id_ecdsa_with_sha224:
> + ctx->cert->sig->hash_algo = "sha224";
> + goto ecdsa;
> +
> + case OID_id_ecdsa_with_sha256:
> + ctx->cert->sig->hash_algo = "sha256";
> + goto ecdsa;
> +
> + case OID_id_ecdsa_with_sha384:
> + ctx->cert->sig->hash_algo = "sha384";
> + goto ecdsa;
> +
> + case OID_id_ecdsa_with_sha512:
> + ctx->cert->sig->hash_algo = "sha512";
> + goto ecdsa;
> +
> case OID_gost2012Signature256:
> ctx->cert->sig->hash_algo = "streebog256";
> goto ecrdsa;
> @@ -255,6 +275,11 @@ int x509_note_pkey_algo(void *context, size_t hdrlen,
> ctx->cert->sig->encoding = "raw";
> ctx->algo_oid = ctx->last_oid;
> return 0;
> +ecdsa:
> + ctx->cert->sig->pkey_algo = "ecdsa";
> + ctx->cert->sig->encoding = "x962";
> + ctx->algo_oid = ctx->last_oid;
> + return 0;
> }
>
> /*
> @@ -276,7 +301,8 @@ int x509_note_signature(void *context, size_t hdrlen,
>
> if (strcmp(ctx->cert->sig->pkey_algo, "rsa") == 0 ||
> strcmp(ctx->cert->sig->pkey_algo, "ecrdsa") == 0 ||
> - strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0) {
> + strcmp(ctx->cert->sig->pkey_algo, "sm2") == 0 ||
> + strcmp(ctx->cert->sig->pkey_algo, "ecdsa") == 0) {
> /* Discard the BIT STRING metadata */
> if (vlen < 1 || *(const u8 *)value != 0)
> return -EBADMSG;
> @@ -478,6 +504,12 @@ int x509_extract_key_data(void *context, size_t hdrlen,
> case OID_sm2:
> ctx->cert->pub->pkey_algo = "sm2";
> break;
> + case OID_id_prime192v1:
> + ctx->cert->pub->pkey_algo = "ecdsa-nist-p192";
> + break;
> + case OID_id_prime256v1:
> + ctx->cert->pub->pkey_algo = "ecdsa-nist-p256";
> + break;
> default:
> return -ENOPKG;
> }
> diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c
> index ae450eb8be14..3d45161b271a 100644
> --- a/crypto/asymmetric_keys/x509_public_key.c
> +++ b/crypto/asymmetric_keys/x509_public_key.c
> @@ -129,7 +129,9 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
> }
>
> ret = -EKEYREJECTED;
> - if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0)
> + if (strcmp(cert->pub->pkey_algo, cert->sig->pkey_algo) != 0 &&
> + (strncmp(cert->pub->pkey_algo, "ecdsa-", 6) != 0 ||
> + strcmp(cert->sig->pkey_algo, "ecdsa") != 0))
> goto out;
>
> ret = public_key_verify_signature(cert->pub, cert->sig);
> diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h
> index f32d91895e4d..3583908cf1ca 100644
> --- a/include/linux/oid_registry.h
> +++ b/include/linux/oid_registry.h
> @@ -20,6 +20,8 @@ enum OID {
> OID_id_dsa_with_sha1, /* 1.2.840.10030.4.3 */
> OID_id_dsa, /* 1.2.840.10040.4.1 */
> OID_id_ecPublicKey, /* 1.2.840.10045.2.1 */
> + OID_id_prime192v1, /* 1.2.840.10045.3.1.1 */
> + OID_id_prime256v1, /* 1.2.840.10045.3.1.7 */
> OID_id_ecdsa_with_sha1, /* 1.2.840.10045.4.1 */
> OID_id_ecdsa_with_sha224, /* 1.2.840.10045.4.3.1 */
> OID_id_ecdsa_with_sha256, /* 1.2.840.10045.4.3.2 */
> --
> 2.29.2
>
>
next prev parent reply other threads:[~2021-03-05 17:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-05 0:51 [PATCH v10 0/9] Add support for x509 certs with NIST P384/256/192 keys Stefan Berger
2021-03-05 0:51 ` [PATCH v10 1/9] crypto: Add support for ECDSA signature verification Stefan Berger
2021-03-05 17:05 ` Jarkko Sakkinen
2021-03-05 17:58 ` Vitaly Chikunov
2021-03-05 19:46 ` Vitaly Chikunov
2021-03-05 22:15 ` Stefan Berger
2021-03-05 0:51 ` [PATCH v10 2/9] crypto: Add NIST P384 curve parameters Stefan Berger
2021-03-05 17:08 ` Jarkko Sakkinen
2021-03-05 0:51 ` [PATCH v10 3/9] crypto: Add math to support fast NIST P384 Stefan Berger
2021-03-05 17:09 ` Jarkko Sakkinen
2021-03-06 19:25 ` Vitaly Chikunov
2021-03-06 23:29 ` Stefan Berger
2021-03-07 0:03 ` Vitaly Chikunov
2021-03-07 1:21 ` Stefan Berger
2021-03-05 0:51 ` [PATCH v10 4/9] ecdsa: Register NIST P384 and extend test suite Stefan Berger
2021-03-05 17:10 ` Jarkko Sakkinen
2021-03-05 18:27 ` Stefan Berger
2021-03-05 0:51 ` [PATCH v10 5/9] x509: Detect sm2 keys by their parameters OID Stefan Berger
2021-03-05 7:39 ` Tianjia Zhang
2021-03-05 17:16 ` Jarkko Sakkinen
2021-03-05 18:02 ` Stefan Berger
2021-03-05 0:52 ` [PATCH v10 6/9] x509: Add support for parsing x509 certs with ECDSA keys Stefan Berger
2021-03-05 17:07 ` Jarkko Sakkinen [this message]
2021-03-05 0:52 ` [PATCH v10 7/9] ima: Support EC keys for signature verification Stefan Berger
2021-03-05 0:52 ` [PATCH v10 8/9] x509: Add OID for NIST P384 and extend parser for it Stefan Berger
2021-03-05 17:10 ` Jarkko Sakkinen
2021-03-05 0:52 ` [PATCH v10 9/9] certs: Add support for using elliptic curve keys for signing modules Stefan Berger
2021-03-05 17:07 ` Jarkko Sakkinen
2021-03-05 0:53 ` [PATCH v10 0/9] Add support for x509 certs with NIST P384/256/192 keys Stefan Berger
2021-03-05 17:10 ` Jarkko Sakkinen
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=YEJlQUC5pfIemTaI@kernel.org \
--to=jarkko@kernel.org \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patrick@puiterwijk.org \
--cc=stefanb@linux.ibm.com \
--cc=stefanb@linux.vnet.ibm.com \
--cc=zohar@linux.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).