crypto: fix multi-prime RSA JWKs · nodejs/node@2f494cb · GitHub
Skip to content

Commit 2f494cb

Browse files
panvaaduh95
authored andcommitted
crypto: fix multi-prime RSA JWKs
Preserve additional RSA prime information when exporting and importing private JWKs across supported OpenSSL versions. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65649 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 00ad283 commit 2f494cb

7 files changed

Lines changed: 344 additions & 10 deletions

File tree

‎deps/ncrypto/ncrypto.cc‎

Lines changed: 122 additions & 1 deletion

‎deps/ncrypto/ncrypto.h‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,23 @@ class Rsa final {
724724
const BIGNUM* dq;
725725
const BIGNUM* qi;
726726
};
727+
struct OtherPrimeInfo {
728+
const BIGNUM* r;
729+
const BIGNUM* d;
730+
const BIGNUM* t;
731+
};
732+
struct OtherPrimeInfoPointer {
733+
OtherPrimeInfoPointer() = default;
734+
OtherPrimeInfoPointer(BignumPointer&& r,
735+
BignumPointer&& d,
736+
BignumPointer&& t);
737+
738+
DeleteFnPtr<BIGNUM, BN_clear_free> r;
739+
DeleteFnPtr<BIGNUM, BN_clear_free> d;
740+
DeleteFnPtr<BIGNUM, BN_clear_free> t;
741+
};
742+
using OtherPrimeInfos = std::vector<OtherPrimeInfo>;
743+
using OtherPrimeInfoPointers = std::vector<OtherPrimeInfoPointer>;
727744
struct PssParams {
728745
std::string_view digest = "sha1";
729746
std::optional<std::string_view> mgf1_digest = "sha1";
@@ -732,6 +749,7 @@ class Rsa final {
732749

733750
const PublicKey getPublicKey() const;
734751
const PrivateKey getPrivateKey() const;
752+
const OtherPrimeInfos getOtherPrimeInfos() const;
735753
const std::optional<PssParams> getPssParams() const;
736754

737755
bool setPublicKey(BignumPointer&& n, BignumPointer&& e);
@@ -740,7 +758,8 @@ class Rsa final {
740758
BignumPointer&& p,
741759
BignumPointer&& dp,
742760
BignumPointer&& dq,
743-
BignumPointer&& qi);
761+
BignumPointer&& qi,
762+
OtherPrimeInfoPointers&& other_prime_infos = {});
744763

745764
using CipherParams = Cipher::CipherParams;
746765

@@ -765,6 +784,7 @@ class Rsa final {
765784
DeleteFnPtr<BIGNUM, BN_clear_free> dp_;
766785
DeleteFnPtr<BIGNUM, BN_clear_free> dq_;
767786
DeleteFnPtr<BIGNUM, BN_clear_free> qi_;
787+
OtherPrimeInfoPointers other_prime_infos_;
768788
std::optional<PssParams> pss_params_;
769789
#else
770790
OSSL3_CONST RSA* rsa_;

‎src/crypto/crypto_rsa.cc‎

Lines changed: 99 additions & 8 deletions

0 commit comments

Comments
 (0)