| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b72c0b9 commit a5d4ac8
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5703,12 +5703,14 @@ Rsa::Rsa(const EVP_PKEY* pkey) : Rsa() { | |||
| 5703 | 5703 | !GetPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_E, &e_)) { | |
| 5704 | 5704 | return; | |
| 5705 | 5705 | } | |
| 5706 | - GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_D, &d_); | ||
| 5707 | - GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_FACTOR1, &p_); | ||
| 5708 | - GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_FACTOR2, &q_); | ||
| 5709 | - GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT1, &dp_); | ||
| 5710 | - GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT2, &dq_); | ||
| 5711 | - GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_COEFFICIENT1, &qi_); | ||
| 5706 | + if (!GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_D, &d_) || | ||
| 5707 | + !GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_FACTOR1, &p_) || | ||
| 5708 | + !GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_FACTOR2, &q_) || | ||
| 5709 | + !GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT1, &dp_) || | ||
| 5710 | + !GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT2, &dq_) || | ||
| 5711 | + !GetOptionalPKeyBnParam(pkey, OSSL_PKEY_PARAM_RSA_COEFFICIENT1, &qi_)) { | ||
| 5712 | + return; | ||
| 5713 | + } | ||
| 5712 | 5714 | ||
| 5713 | 5715 | if (type == EVP_PKEY_RSA_PSS) { | |
| 5714 | 5716 | MarkPopErrorOnReturn pop_errors; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -357,6 +357,13 @@ bool ExportJWKRsaKey(Environment* env, | |||
| 357 | 357 | ||
| 358 | 358 | if (key.GetKeyType() == kKeyTypePrivate) { | |
| 359 | 359 | auto pvt_key = rsa.getPrivateKey(); | |
| 360 | + if (pub_key.d == nullptr || pvt_key.p == nullptr || pvt_key.q == nullptr || | ||
| 361 | + pvt_key.dp == nullptr || pvt_key.dq == nullptr || | ||
| 362 | + pvt_key.qi == nullptr) { | ||
| 363 | + THROW_ERR_CRYPTO_OPERATION_FAILED(env, | ||
| 364 | + "Failed to export RSA private key"); | ||
| 365 | + return false; | ||
| 366 | + } | ||
| 360 | 367 | if (SetEncodedValue(env, target, env->jwk_d_string(), pub_key.d) | |
| 361 | 368 | .IsNothing() || | |
| 362 | 369 | SetEncodedValue(env, target, env->jwk_p_string(), pvt_key.p) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,14 @@ | |||
| 1 | 1 | #include <ncrypto.h> | |
| 2 | 2 | #include "crypto/crypto_bio.h" | |
| 3 | + #include "crypto/crypto_keys.h" | ||
| 4 | + #include "crypto/crypto_rsa.h" | ||
| 3 | 5 | #include "gtest/gtest.h" | |
| 4 | 6 | #include "node_options.h" | |
| 5 | 7 | #include "node_test_fixture.h" | |
| 6 | 8 | #include "openssl/err.h" | |
| 7 | 9 | ||
| 8 | 10 | using v8::Local; | |
| 11 | + using v8::Object; | ||
| 9 | 12 | using v8::String; | |
| 10 | 13 | ||
| 11 | 14 | /* | |
@@ -31,3 +34,27 @@ TEST_F(NodeCryptoEnv, LoadBIO) { | |||
| 31 | 34 | ASSERT_EQ(ERR_peek_error(), 0UL) << "There should not have left " | |
| 32 | 35 | "any errors on the OpenSSL error stack\n"; | |
| 33 | 36 | } | |
| 37 | + | ||
| 38 | + #if NCRYPTO_USE_OPENSSL3_PROVIDER | ||
| 39 | + TEST_F(NodeCryptoEnv, ExportIncompleteRsaPrivateKeyAsJwk) { | ||
| 40 | + v8::HandleScope handle_scope(isolate_); | ||
| 41 | + Argv argv; | ||
| 42 | + Env env{handle_scope, argv}; | ||
| 43 | + | ||
| 44 | + ncrypto::Rsa rsa; | ||
| 45 | + auto n = ncrypto::BignumPointer::New(); | ||
| 46 | + auto e = ncrypto::BignumPointer::New(); | ||
| 47 | + ASSERT_TRUE(n.setWord(3233)); | ||
| 48 | + ASSERT_TRUE(e.setWord(17)); | ||
| 49 | + ASSERT_TRUE(rsa.setPublicKey(std::move(n), std::move(e))); | ||
| 50 | + | ||
| 51 | + auto pkey = ncrypto::EVPKeyPointer::NewRSA(rsa); | ||
| 52 | + ASSERT_TRUE(pkey); | ||
| 53 | + auto key = node::crypto::KeyObjectData::CreateAsymmetric( | ||
| 54 | + node::crypto::kKeyTypePrivate, std::move(pkey)); | ||
| 55 | + | ||
| 56 | + v8::TryCatch try_catch(isolate_); | ||
| 57 | + EXPECT_FALSE(node::crypto::ExportJWKRsaKey(*env, key, Object::New(isolate_))); | ||
| 58 | + EXPECT_TRUE(try_catch.HasCaught()); | ||
| 59 | + } | ||
| 60 | + #endif | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments