test: prepare test-crypto-rsa-dsa for newer OpenSSL · nodejs/node@39978f5

Original file line numberDiff line numberDiff line change

@@ -9,7 +9,7 @@ const crypto = require('crypto');

99

const constants = crypto.constants;

1010
1111

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

12-

const { hasOpenSSL3 } = require('../common/crypto');

12+

const { hasOpenSSL, hasOpenSSL3 } = require('../common/crypto');

1313
1414

// Test certificates

1515

const certPem = fixtures.readKey('rsa_cert.crt');

@@ -225,20 +225,38 @@ function test_rsa(padding, encryptOaepHash, decryptOaepHash) {

225225
226226

if (padding === constants.RSA_PKCS1_PADDING) {

227227

if (!process.config.variables.node_shared_openssl) {

228-

assert.throws(() => {

229-

crypto.privateDecrypt({

228+

// TODO(richardlau) remove check and else branch after deps/openssl

229+

// is upgraded.

230+

if (hasOpenSSL(3, 2)) {

231+

let decryptedBuffer = crypto.privateDecrypt({

230232

key: rsaKeyPem,

231233

padding: padding,

232234

oaepHash: decryptOaepHash

233235

}, encryptedBuffer);

234-

}, { code: 'ERR_INVALID_ARG_VALUE' });

235-

assert.throws(() => {

236-

crypto.privateDecrypt({

236+

assert.deepStrictEqual(decryptedBuffer, input);

237+
238+

decryptedBuffer = crypto.privateDecrypt({

237239

key: rsaPkcs8KeyPem,

238240

padding: padding,

239241

oaepHash: decryptOaepHash

240242

}, encryptedBuffer);

241-

}, { code: 'ERR_INVALID_ARG_VALUE' });

243+

assert.deepStrictEqual(decryptedBuffer, input);

244+

} else {

245+

assert.throws(() => {

246+

crypto.privateDecrypt({

247+

key: rsaKeyPem,

248+

padding: padding,

249+

oaepHash: decryptOaepHash

250+

}, encryptedBuffer);

251+

}, { code: 'ERR_INVALID_ARG_VALUE' });

252+

assert.throws(() => {

253+

crypto.privateDecrypt({

254+

key: rsaPkcs8KeyPem,

255+

padding: padding,

256+

oaepHash: decryptOaepHash

257+

}, encryptedBuffer);

258+

}, { code: 'ERR_INVALID_ARG_VALUE' });

259+

}

242260

} else {

243261

// The version of a linked against OpenSSL. May

244262

// or may not support implicit rejection. Figuring