Skip to content

Commit 13d8549

Browse files
sam-githubBethGriggs
authored andcommitted
test: well-defined DH groups now verify clean
OpenSSL 1.1.1d no longer generates warnings for some DH groups that used to be considered unsafe. See below for discussion. This is considered a bug fix. See: - openssl/openssl#9363 - openssl/openssl#9363 (comment) PR-URL: #29550 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 7202792 commit 13d8549

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

test/parallel/test-crypto-binary-default.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const crypto = require('crypto');
3636
const fs = require('fs');
3737
const tls = require('tls');
3838
const fixtures = require('../common/fixtures');
39-
const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR;
4039

4140
require('internal/crypto/util').setDefaultEncoding('latin1');
4241

@@ -615,8 +614,7 @@ common.expectsError(
615614
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' +
616615
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' +
617616
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
618-
const d = crypto.createDiffieHellman(p, 'hex');
619-
assert.strictEqual(d.verifyError, DH_NOT_SUITABLE_GENERATOR);
617+
crypto.createDiffieHellman(p, 'hex');
620618

621619
// Test RSA key signing/verification
622620
const rsaSign = crypto.createSign('SHA1');

test/parallel/test-crypto-dh.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const crypto = require('crypto');
88

9-
const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR;
10-
119
// Test Diffie-Hellman with two parties sharing a secret,
1210
// using various encodings as we go along
1311
const dh1 = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256);
@@ -121,8 +119,6 @@ bob.generateKeys();
121119
const aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex');
122120
const bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex');
123121
assert.strictEqual(aSecret, bSecret);
124-
assert.strictEqual(alice.verifyError, DH_NOT_SUITABLE_GENERATOR);
125-
assert.strictEqual(bob.verifyError, DH_NOT_SUITABLE_GENERATOR);
126122

127123
/* Ensure specific generator (buffer) works as expected.
128124
* The values below (modp2/modp2buf) are for a 1024 bits long prime from
@@ -153,8 +149,6 @@ const modp2buf = Buffer.from([
153149
const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
154150
.toString('hex');
155151
assert.strictEqual(modp2Secret, exmodp2Secret);
156-
assert.strictEqual(modp2.verifyError, DH_NOT_SUITABLE_GENERATOR);
157-
assert.strictEqual(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR);
158152
}
159153

160154
for (const buf of [modp2buf, ...common.getArrayBufferViews(modp2buf)]) {
@@ -167,7 +161,6 @@ for (const buf of [modp2buf, ...common.getArrayBufferViews(modp2buf)]) {
167161
const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
168162
.toString('hex');
169163
assert.strictEqual(modp2Secret, exmodp2Secret);
170-
assert.strictEqual(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR);
171164
}
172165

173166
{
@@ -179,7 +172,6 @@ for (const buf of [modp2buf, ...common.getArrayBufferViews(modp2buf)]) {
179172
const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
180173
.toString('hex');
181174
assert.strictEqual(modp2Secret, exmodp2Secret);
182-
assert.strictEqual(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR);
183175
}
184176

185177
{
@@ -191,17 +183,20 @@ for (const buf of [modp2buf, ...common.getArrayBufferViews(modp2buf)]) {
191183
const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
192184
.toString('hex');
193185
assert.strictEqual(modp2Secret, exmodp2Secret);
194-
assert.strictEqual(exmodp2.verifyError, DH_NOT_SUITABLE_GENERATOR);
195186
}
196187

197-
188+
// Second OAKLEY group, see
189+
// https://github.com/nodejs/node-v0.x-archive/issues/2338 and
190+
// https://xml2rfc.tools.ietf.org/public/rfc/html/rfc2412.html#anchor49
198191
const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
199192
'020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' +
200193
'4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' +
201194
'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF';
202-
const bad_dh = crypto.createDiffieHellman(p, 'hex');
203-
assert.strictEqual(bad_dh.verifyError, DH_NOT_SUITABLE_GENERATOR);
195+
crypto.createDiffieHellman(p, 'hex');
204196

197+
// Confirm DH_check() results are exposed for optional examination.
198+
const bad_dh = crypto.createDiffieHellman('02', 'hex');
199+
assert.notStrictEqual(bad_dh.verifyError, 0);
205200

206201
const availableCurves = new Set(crypto.getCurves());
207202
const availableHashes = new Set(crypto.getHashes());

0 commit comments

Comments
 (0)