Skip to content

Commit bb206e1

Browse files
committed
fixup! crypto: coerce -0 to +0 before native calls
1 parent ace7877 commit bb206e1

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

test/parallel/test-crypto-negative-zero.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (!common.hasCrypto)
66

77
const assert = require('assert');
88
const crypto = require('crypto');
9+
const { hasOpenSSL } = require('../common/crypto');
910

1011
function getOutcome(fn) {
1112
try {
@@ -68,30 +69,38 @@ function assertSameErrorOrSuccess(actual, expected) {
6869
});
6970
}
7071

72+
const isOpenSSL111Fips = !hasOpenSSL(3) && crypto.getFips();
7173
{
72-
for (const [type, getOptions] of [
73-
['rsa', (zero) => ({ modulusLength: zero })],
74-
['rsa', (zero) => ({ modulusLength: 512, publicExponent: zero })],
75-
['rsa-pss', (zero) => ({
76-
modulusLength: 512,
77-
publicExponent: 65537,
78-
saltLength: zero,
79-
})],
80-
['dsa', (zero) => ({ modulusLength: zero })],
81-
['dsa', (zero) => ({ modulusLength: 512, divisorLength: zero })],
82-
['dh', (zero) => ({ primeLength: zero })],
83-
['dh', (zero) => ({ primeLength: 2, generator: zero })],
84-
]) {
85-
assertSameErrorOrSuccess(
86-
getOutcome(() => crypto.generateKeyPairSync(type, getOptions(-0))),
87-
getOutcome(() => crypto.generateKeyPairSync(type, getOptions(0))),
88-
);
89-
}
74+
if (isOpenSSL111Fips) {
75+
// OpenSSL 1.1.1 FIPS can hang on invalid key generation parameters.
76+
// These cases only verify that -0 reaches the same path as +0.
77+
common.printSkipMessage(
78+
'Skipping invalid key generation parity checks with OpenSSL 1.1.1 FIPS');
79+
} else {
80+
for (const [type, getOptions] of [
81+
['rsa', (zero) => ({ modulusLength: zero })],
82+
['rsa', (zero) => ({ modulusLength: 512, publicExponent: zero })],
83+
['rsa-pss', (zero) => ({
84+
modulusLength: 512,
85+
publicExponent: 65537,
86+
saltLength: zero,
87+
})],
88+
['dsa', (zero) => ({ modulusLength: zero })],
89+
['dsa', (zero) => ({ modulusLength: 512, divisorLength: zero })],
90+
['dh', (zero) => ({ primeLength: zero })],
91+
['dh', (zero) => ({ primeLength: 2, generator: zero })],
92+
]) {
93+
assertSameErrorOrSuccess(
94+
getOutcome(() => crypto.generateKeyPairSync(type, getOptions(-0))),
95+
getOutcome(() => crypto.generateKeyPairSync(type, getOptions(0))),
96+
);
97+
}
9098

91-
crypto.generateKeyPair('rsa', { modulusLength: -0 },
92-
common.mustCall((err) => {
93-
assert(err instanceof Error);
94-
}));
99+
crypto.generateKeyPair('rsa', { modulusLength: -0 },
100+
common.mustCall((err) => {
101+
assert(err instanceof Error);
102+
}));
103+
}
95104
}
96105

97106
if (!process.features.openssl_is_boringssl) {

0 commit comments

Comments
 (0)