Skip to content

Commit 402179d

Browse files
akyidrianAydin Arik
andauthored
🔑 Using RSA_padding_add_PKCS1_PSS and RSA_verify_PKCS1_PSS functions (#159)
When both Hash and mgs1Hash parameters match in the _mgf1 equivalent calls, or mgf1Hash is NULL, we can opt to use the non _mgf1 calls mentioned. This change will allow wolfssl to be compiled with jwt-cpp. Co-authored-by: Aydin Arik <aarik@teradici.com>
1 parent 67eadcf commit 402179d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

include/jwt-cpp/jwt.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace jwt {
259259
case signature_generation_error::digestfinal_failed:
260260
return "failed to create signature: DigestFinal failed";
261261
case signature_generation_error::rsa_padding_failed:
262-
return "failed to create signature: RSA_padding_add_PKCS1_PSS_mgf1 failed";
262+
return "failed to create signature: RSA_padding_add_PKCS1_PSS failed";
263263
case signature_generation_error::rsa_private_encrypt_failed:
264264
return "failed to create signature: RSA_private_encrypt failed";
265265
case signature_generation_error::get_key_failed:
@@ -1235,9 +1235,9 @@ namespace jwt {
12351235
const int size = RSA_size(key.get());
12361236

12371237
std::string padded(size, 0x00);
1238-
if (RSA_padding_add_PKCS1_PSS_mgf1(
1239-
key.get(), (unsigned char*)padded.data(), reinterpret_cast<const unsigned char*>(hash.data()),
1240-
md(), md(), -1) == 0) { // NOLINT(google-readability-casting) requires `const_cast`
1238+
if (RSA_padding_add_PKCS1_PSS(key.get(), (unsigned char*)padded.data(),
1239+
reinterpret_cast<const unsigned char*>(hash.data()), md(),
1240+
-1) == 0) { // NOLINT(google-readability-casting) requires `const_cast`
12411241
ec = error::signature_generation_error::rsa_padding_failed;
12421242
return {};
12431243
}
@@ -1279,8 +1279,8 @@ namespace jwt {
12791279
return;
12801280
}
12811281

1282-
if (RSA_verify_PKCS1_PSS_mgf1(key.get(), reinterpret_cast<const unsigned char*>(hash.data()), md(),
1283-
md(), reinterpret_cast<const unsigned char*>(sig.data()), -1) == 0) {
1282+
if (RSA_verify_PKCS1_PSS(key.get(), reinterpret_cast<const unsigned char*>(hash.data()), md(),
1283+
reinterpret_cast<const unsigned char*>(sig.data()), -1) == 0) {
12841284
ec = error::signature_verification_error::invalid_signature;
12851285
return;
12861286
}

tests/OpenSSLErrorTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ TEST(OpenSSLErrorTest, PS256SignErrorCode) {
703703
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed},
704704
{&fail_EVP_DigestFinal, 1, jwt::error::signature_generation_error::digestfinal_failed},
705705
{&fail_EVP_PKEY_get1_RSA, 1, jwt::error::signature_generation_error::get_key_failed}
706-
//TODO: RSA_padding_add_PKCS1_PSS_mgf1, RSA_private_encrypt
706+
//TODO: RSA_padding_add_PKCS1_PSS, RSA_private_encrypt
707707
};
708708

709709
run_multitest(mapping, [&alg](std::error_code& ec) {

0 commit comments

Comments
 (0)