@@ -6,8 +6,6 @@ if (!common.hasCrypto)
66const assert = require ( 'assert' ) ;
77const 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
1311const dh1 = crypto . createDiffieHellman ( common . hasFipsCrypto ? 1024 : 256 ) ;
@@ -121,8 +119,6 @@ bob.generateKeys();
121119const aSecret = alice . computeSecret ( bob . getPublicKey ( ) ) . toString ( 'hex' ) ;
122120const bSecret = bob . computeSecret ( alice . getPublicKey ( ) ) . toString ( 'hex' ) ;
123121assert . 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
160154for ( 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
198191const 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
206201const availableCurves = new Set ( crypto . getCurves ( ) ) ;
207202const availableHashes = new Set ( crypto . getHashes ( ) ) ;
0 commit comments