From a69184fb9d6fb2ad91903631fd1086220ed1e584 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Mon, 17 Jul 2023 11:43:47 +0200 Subject: [PATCH] wolfssl: Reject EC keys with explicitly encoded parameters These are not allowed in X.509 certificates according to RFC 5480 and some newer validations apparently explicitly check for this. Note that WolfSSL rejects such keys, by default. Only when compiled with WOLFSSL_NO_ASN_STRICT are they accepted. --- src/libstrongswan/plugins/wolfssl/wolfssl_ec_private_key.c | 3 ++- src/libstrongswan/plugins/wolfssl/wolfssl_ec_public_key.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/plugins/wolfssl/wolfssl_ec_private_key.c b/src/libstrongswan/plugins/wolfssl/wolfssl_ec_private_key.c index a08cc17e3..addd3bda2 100644 --- a/src/libstrongswan/plugins/wolfssl/wolfssl_ec_private_key.c +++ b/src/libstrongswan/plugins/wolfssl/wolfssl_ec_private_key.c @@ -449,7 +449,8 @@ wolfssl_ec_private_key_t *wolfssl_ec_private_key_load(key_type_t type, } idx = 0; - if (wc_EccPrivateKeyDecode(key.ptr, &idx, &this->ec, key.len) < 0) + if (wc_EccPrivateKeyDecode(key.ptr, &idx, &this->ec, key.len) < 0 || + this->ec.idx == -1) { destroy(this); return NULL; diff --git a/src/libstrongswan/plugins/wolfssl/wolfssl_ec_public_key.c b/src/libstrongswan/plugins/wolfssl/wolfssl_ec_public_key.c index 97abe950b..58fd6eded 100644 --- a/src/libstrongswan/plugins/wolfssl/wolfssl_ec_public_key.c +++ b/src/libstrongswan/plugins/wolfssl/wolfssl_ec_public_key.c @@ -378,7 +378,7 @@ wolfssl_ec_public_key_t *wolfssl_ec_public_key_load(key_type_t type, idx = 0; ret = wc_EccPublicKeyDecode(blob.ptr, &idx, &this->ec, blob.len); - if (ret < 0) + if (ret < 0 || this->ec.idx == -1) { destroy(this); return NULL;