From d7b995cd38bfe4b0f607f8803f87e2ac4c5de812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 18 Feb 2023 01:27:24 +0100 Subject: [PATCH] test: cover publicExponent validation in OpenSSL Add a test case for public exponents that are invalid according to some internal OpenSSL validation logic, but which are accepted by node's own validation logic. PR-URL: https://github.com/nodejs/node/pull/46632 Reviewed-By: Filip Skokan Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anto Aravinth --- test/parallel/test-crypto-keygen.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 9d08e2d9fab3dd..1a77266b057041 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -1200,6 +1200,17 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); code: 'ERR_OUT_OF_RANGE', }); } + + // Test invalid exponents. (caught by OpenSSL) + for (const publicExponent of [1, 1 + 0x10001]) { + generateKeyPair('rsa', { + modulusLength: 4096, + publicExponent + }, common.mustCall((err) => { + assert.strictEqual(err.name, 'Error'); + assert.match(err.message, common.hasOpenSSL3 ? /exponent/ : /bad e value/); + })); + } } // Test DSA parameters.