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 <panva.ip@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
This commit is contained in:
Tobias Nießen 2023-02-18 01:27:24 +01:00 committed by GitHub
parent c566a04c86
commit f1a30b9bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.