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

test: crypto-rsa-dsa testing for dynamic openssl #52781

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
51 changes: 49 additions & 2 deletions test/parallel/test-crypto-rsa-dsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ function test_rsa(padding, encryptOaepHash, decryptOaepHash) {


if (padding === constants.RSA_PKCS1_PADDING) {
// TODO(richardlau): see if it's possible to determine implicit rejection
// support when dynamically linked against OpenSSL.
if (!process.config.variables.node_shared_openssl) {
assert.throws(() => {
crypto.privateDecrypt({
Expand All @@ -240,6 +238,55 @@ function test_rsa(padding, encryptOaepHash, decryptOaepHash) {
oaepHash: decryptOaepHash
}, encryptedBuffer);
}, { code: 'ERR_INVALID_ARG_VALUE' });
} else {
// The version of a linked against OpenSSL. May
// or may not support implicit rejection. Figuring
// this out in the test is not feasible but we
// require that it pass based on one of the two
// cases of supporting it or not.
try {
// The expected exceptions should be thrown if implicit rejection
// is not supported
assert.throws(() => {
crypto.privateDecrypt({
key: rsaKeyPem,
padding: padding,
oaepHash: decryptOaepHash
}, encryptedBuffer);
}, { code: 'ERR_INVALID_ARG_VALUE' });
assert.throws(() => {
crypto.privateDecrypt({
key: rsaPkcs8KeyPem,
padding: padding,
oaepHash: decryptOaepHash
}, encryptedBuffer);
}, { code: 'ERR_INVALID_ARG_VALUE' });
} catch (e) {
if (e.toString() ===
'AssertionError [ERR_ASSERTION]: Missing expected exception.') {
// Implicit rejection must be supported since
// we did not get the exceptions that are thrown
// when it is not, we should be able to decrypt
let decryptedBuffer = crypto.privateDecrypt({
key: rsaKeyPem,
padding: padding,
oaepHash: decryptOaepHash
}, encryptedBuffer);
assert.deepStrictEqual(decryptedBuffer, input);

decryptedBuffer = crypto.privateDecrypt({
key: rsaPkcs8KeyPem,
padding: padding,
oaepHash: decryptOaepHash
}, encryptedBuffer);
assert.deepStrictEqual(decryptedBuffer, input);
} else {
// There was an exception but it not the one we expect if implicit
mhdawson marked this conversation as resolved.
Show resolved Hide resolved
// rejection is not supported so there was some other failure,
// re-throw it so the test fails
throw e;
}
}
}
} else {
let decryptedBuffer = crypto.privateDecrypt({
Expand Down
Loading