Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: fix WebCrypto import of RSA-PSS keys #36877

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/crypto/crypto_rsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,14 @@ Maybe<bool> ExportJWKRsaKey(
int type = EVP_PKEY_id(pkey.get());
CHECK(type == EVP_PKEY_RSA || type == EVP_PKEY_RSA_PSS);

RSA* rsa = EVP_PKEY_get0_RSA(pkey.get());
// TODO(tniessen): Remove the "else" branch once we drop support for OpenSSL
// versions older than 1.1.1e via FIPS / dynamic linking.
RSA* rsa;
if (OpenSSL_version_num() >= 0x1010105fL) {
rsa = EVP_PKEY_get0_RSA(pkey.get());
} else {
rsa = static_cast<RSA*>(EVP_PKEY_get0(pkey.get()));
}
CHECK_NOT_NULL(rsa);

const BIGNUM* n;
Expand Down Expand Up @@ -508,7 +515,14 @@ Maybe<bool> GetRsaKeyDetail(
int type = EVP_PKEY_id(pkey.get());
CHECK(type == EVP_PKEY_RSA || type == EVP_PKEY_RSA_PSS);

RSA* rsa = EVP_PKEY_get0_RSA(pkey.get());
// TODO(tniessen): Remove the "else" branch once we drop support for OpenSSL
// versions older than 1.1.1e via FIPS / dynamic linking.
RSA* rsa;
if (OpenSSL_version_num() >= 0x1010105fL) {
rsa = EVP_PKEY_get0_RSA(pkey.get());
} else {
rsa = static_cast<RSA*>(EVP_PKEY_get0(pkey.get()));
}
CHECK_NOT_NULL(rsa);

RSA_get0_key(rsa, &n, &e, nullptr);
Expand Down
40 changes: 40 additions & 0 deletions test/parallel/test-webcrypto-rsa-pss-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const common = require('../common');

if (!common.hasCrypto)
common.skip('missing crypto');

const {
createPrivateKey,
createPublicKey,
webcrypto: {
subtle
}
} = require('crypto');

const fixtures = require('../common/fixtures');

{
const rsaPssKeyWithoutParams = fixtures.readKey('rsa_pss_private_2048.pem');

const pkcs8 = createPrivateKey(rsaPssKeyWithoutParams).export({
type: 'pkcs8',
format: 'der'
});
const spki = createPublicKey(rsaPssKeyWithoutParams).export({
type: 'spki',
format: 'der'
});

const hashes = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'];

const tasks = [];
for (const hash of hashes) {
const algorithm = { name: 'RSA-PSS', hash };
tasks.push(subtle.importKey('pkcs8', pkcs8, algorithm, true, ['sign']));
tasks.push(subtle.importKey('spki', spki, algorithm, true, ['verify']));
}

Promise.all(tasks).then(common.mustCall());
}