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

Commit db8a916

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. PR-URL: #65649 Backport-PR-URL: #66128 Assisted-by: Codex Signed-off-by: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 022ac83 commit db8a916

7 files changed

Lines changed: 353 additions & 6 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
@@ -723,6 +723,23 @@ class Rsa final {
723723
const BIGNUM* dq;
724724
const BIGNUM* qi;
725725
};
726+
struct OtherPrimeInfo {
727+
const BIGNUM* r;
728+
const BIGNUM* d;
729+
const BIGNUM* t;
730+
};
731+
struct OtherPrimeInfoPointer {
732+
OtherPrimeInfoPointer() = default;
733+
OtherPrimeInfoPointer(BignumPointer&& r,
734+
BignumPointer&& d,
735+
BignumPointer&& t);
736+
737+
DeleteFnPtr<BIGNUM, BN_clear_free> r;
738+
DeleteFnPtr<BIGNUM, BN_clear_free> d;
739+
DeleteFnPtr<BIGNUM, BN_clear_free> t;
740+
};
741+
using OtherPrimeInfos = std::vector<OtherPrimeInfo>;
742+
using OtherPrimeInfoPointers = std::vector<OtherPrimeInfoPointer>;
726743
struct PssParams {
727744
std::string_view digest = "sha1";
728745
std::optional<std::string_view> mgf1_digest = "sha1";
@@ -731,6 +748,7 @@ class Rsa final {
731748

732749
const PublicKey getPublicKey() const;
733750
const PrivateKey getPrivateKey() const;
751+
const OtherPrimeInfos getOtherPrimeInfos() const;
734752
const std::optional<PssParams> getPssParams() const;
735753

736754
bool setPublicKey(BignumPointer&& n, BignumPointer&& e);
@@ -739,7 +757,8 @@ class Rsa final {
739757
BignumPointer&& p,
740758
BignumPointer&& dp,
741759
BignumPointer&& dq,
742-
BignumPointer&& qi);
760+
BignumPointer&& qi,
761+
OtherPrimeInfoPointers&& other_prime_infos = {});
743762

744763
using CipherParams = Cipher::CipherParams;
745764

@@ -764,6 +783,7 @@ class Rsa final {
764783
DeleteFnPtr<BIGNUM, BN_clear_free> dp_;
765784
DeleteFnPtr<BIGNUM, BN_clear_free> dq_;
766785
DeleteFnPtr<BIGNUM, BN_clear_free> qi_;
786+
OtherPrimeInfoPointers other_prime_infos_;
767787
std::optional<PssParams> pss_params_;
768788
#else
769789
OSSL3_CONST RSA* rsa_;

‎src/crypto/crypto_rsa.cc‎

Lines changed: 108 additions & 4 deletions

0 commit comments

Comments
 (0)