From 841e8f444e0916a3e63c12e1f19508a53413a2dd Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Fri, 20 Nov 2020 21:26:47 +0100 Subject: [PATCH] crypto: fix "Invalid JWK" error messages PR-URL: https://github.com/nodejs/node/pull/36200 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Franziska Hinkelmann --- src/crypto/crypto_dsa.cc | 6 +++--- src/crypto/crypto_ecdh.cc | 8 ++++---- src/crypto/crypto_rsa.cc | 13 ++++++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/crypto/crypto_dsa.cc b/src/crypto/crypto_dsa.cc index ad921ac92012e6..8a80904d9c1afb 100644 --- a/src/crypto/crypto_dsa.cc +++ b/src/crypto/crypto_dsa.cc @@ -192,7 +192,7 @@ std::shared_ptr ImportJWKDsaKey( !q_value->IsString() || !q_value->IsString() || (!x_value->IsUndefined() && !x_value->IsString())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK DSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK DSA key"); return std::shared_ptr(); } @@ -210,14 +210,14 @@ std::shared_ptr ImportJWKDsaKey( p.ToBN().release(), q.ToBN().release(), g.ToBN().release())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK DSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK DSA key"); return std::shared_ptr(); } if (type == kKeyTypePrivate) { ByteSource x = ByteSource::FromEncodedString(env, x_value.As()); if (!DSA_set0_key(dsa.get(), nullptr, x.ToBN().release())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK DSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK DSA key"); return std::shared_ptr(); } } diff --git a/src/crypto/crypto_ecdh.cc b/src/crypto/crypto_ecdh.cc index e2fdc3234b0ae8..277a5a731d37ae 100644 --- a/src/crypto/crypto_ecdh.cc +++ b/src/crypto/crypto_ecdh.cc @@ -680,7 +680,7 @@ std::shared_ptr ImportJWKEcKey( if (!x_value->IsString() || !y_value->IsString() || (!d_value->IsUndefined() && !d_value->IsString())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK EC key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK EC key"); return std::shared_ptr(); } @@ -688,7 +688,7 @@ std::shared_ptr ImportJWKEcKey( ECKeyPointer ec(EC_KEY_new_by_curve_name(nid)); if (!ec) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK EC key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK EC key"); return std::shared_ptr(); } @@ -699,14 +699,14 @@ std::shared_ptr ImportJWKEcKey( ec.get(), x.ToBN().get(), y.ToBN().get())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK EC key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK EC key"); return std::shared_ptr(); } if (type == kKeyTypePrivate) { ByteSource d = ByteSource::FromEncodedString(env, d_value.As()); if (!EC_KEY_set_private_key(ec.get(), d.ToBN().get())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK EC key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK EC key"); return std::shared_ptr(); } } diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index ac5dbd5106e678..d859551392a382 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -422,12 +422,12 @@ std::shared_ptr ImportJWKRsaKey( !jwk->Get(env->context(), env->jwk_d_string()).ToLocal(&d_value) || !n_value->IsString() || !e_value->IsString()) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK RSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK RSA key"); return std::shared_ptr(); } if (!d_value->IsUndefined() && !d_value->IsString()) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK RSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK RSA key"); return std::shared_ptr(); } @@ -443,7 +443,7 @@ std::shared_ptr ImportJWKRsaKey( n.ToBN().release(), e.ToBN().release(), nullptr)) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK RSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK RSA key"); return std::shared_ptr(); } @@ -459,7 +459,7 @@ std::shared_ptr ImportJWKRsaKey( !jwk->Get(env->context(), env->jwk_dp_string()).ToLocal(&dp_value) || !jwk->Get(env->context(), env->jwk_dq_string()).ToLocal(&dq_value) || !jwk->Get(env->context(), env->jwk_qi_string()).ToLocal(&qi_value)) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK RSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK RSA key"); return std::shared_ptr(); } @@ -468,7 +468,7 @@ std::shared_ptr ImportJWKRsaKey( !dp_value->IsString() || !dq_value->IsString() || !qi_value->IsString()) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK RSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK RSA key"); return std::shared_ptr(); } @@ -486,7 +486,7 @@ std::shared_ptr ImportJWKRsaKey( dp.ToBN().release(), dq.ToBN().release(), qi.ToBN().release())) { - THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JSK RSA key"); + THROW_ERR_CRYPTO_INVALID_JWK(env, "Invalid JWK RSA key"); return std::shared_ptr(); } } @@ -547,4 +547,3 @@ void Initialize(Environment* env, Local target) { } // namespace RSAAlg } // namespace crypto } // namespace node -