@@ -10,90 +10,49 @@ const tls = require('tls');
1010const key = fixtures . readKey ( 'agent2-key.pem' ) ;
1111const cert = fixtures . readKey ( 'agent2-cert.pem' ) ;
1212
13- let ntests = 0 ;
14- let nsuccess = 0 ;
15-
1613function loadDHParam ( n ) {
1714 return fixtures . readKey ( `dh${ n } .pem` ) ;
1815}
1916
20- const cipherlist = {
21- 'NOT_PFS' : 'AES128-SHA256' ,
22- 'DH' : 'DHE-RSA-AES128-GCM-SHA256' ,
23- 'ECDH' : 'ECDHE-RSA-AES128-GCM-SHA256'
24- } ;
25-
26- function test ( size , type , name , next ) {
27- const cipher = type ? cipherlist [ type ] : cipherlist . NOT_PFS ;
28-
29- if ( name ) tls . DEFAULT_ECDH_CURVE = name ;
17+ function test ( size , type , name , cipher ) {
18+ assert ( cipher ) ;
3019
3120 const options = {
3221 key : key ,
3322 cert : cert ,
3423 ciphers : cipher
3524 } ;
3625
26+ if ( name ) options . ecdhCurve = name ;
27+
3728 if ( type === 'DH' ) options . dhparam = loadDHParam ( size ) ;
3829
39- const server = tls . createServer ( options , function ( conn ) {
30+ const server = tls . createServer ( options , common . mustCall ( ( conn ) => {
4031 assert . strictEqual ( conn . getEphemeralKeyInfo ( ) , null ) ;
4132 conn . end ( ) ;
42- } ) ;
33+ } ) ) ;
4334
44- server . on ( 'close' , common . mustCall ( function ( err ) {
35+ server . on ( 'close' , common . mustCall ( ( err ) => {
4536 assert . ifError ( err ) ;
46- if ( next ) next ( ) ;
4737 } ) ) ;
4838
49- server . listen ( 0 , '127.0.0.1' , common . mustCall ( function ( ) {
39+ server . listen ( 0 , '127.0.0.1' , common . mustCall ( ( ) => {
5040 const client = tls . connect ( {
51- port : this . address ( ) . port ,
41+ port : server . address ( ) . port ,
5242 rejectUnauthorized : false
5343 } , function ( ) {
5444 const ekeyinfo = client . getEphemeralKeyInfo ( ) ;
5545 assert . strictEqual ( ekeyinfo . type , type ) ;
5646 assert . strictEqual ( ekeyinfo . size , size ) ;
5747 assert . strictEqual ( ekeyinfo . name , name ) ;
58- nsuccess ++ ;
5948 server . close ( ) ;
6049 } ) ;
6150 } ) ) ;
6251}
6352
64- function testNOT_PFS ( ) {
65- test ( undefined , undefined , undefined , testDHE1024 ) ;
66- ntests ++ ;
67- }
68-
69- function testDHE1024 ( ) {
70- test ( 1024 , 'DH' , undefined , testDHE2048 ) ;
71- ntests ++ ;
72- }
73-
74- function testDHE2048 ( ) {
75- test ( 2048 , 'DH' , undefined , testECDHE256 ) ;
76- ntests ++ ;
77- }
78-
79- function testECDHE256 ( ) {
80- test ( 256 , 'ECDH' , 'prime256v1' , testECDHE512 ) ;
81- ntests ++ ;
82- }
83-
84- function testECDHE512 ( ) {
85- test ( 521 , 'ECDH' , 'secp521r1' , testX25519 ) ;
86- ntests ++ ;
87- }
88-
89- function testX25519 ( ) {
90- test ( 253 , 'ECDH' , 'X25519' , null ) ;
91- ntests ++ ;
92- }
93-
94- testNOT_PFS ( ) ;
95-
96- process . on ( 'exit' , function ( ) {
97- assert . strictEqual ( ntests , nsuccess ) ;
98- assert . strictEqual ( ntests , 6 ) ;
99- } ) ;
53+ test ( undefined , undefined , undefined , 'AES128-SHA256' ) ;
54+ test ( 1024 , 'DH' , undefined , 'DHE-RSA-AES128-GCM-SHA256' ) ;
55+ test ( 2048 , 'DH' , undefined , 'DHE-RSA-AES128-GCM-SHA256' ) ;
56+ test ( 256 , 'ECDH' , 'prime256v1' , 'ECDHE-RSA-AES128-GCM-SHA256' ) ;
57+ test ( 521 , 'ECDH' , 'secp521r1' , 'ECDHE-RSA-AES128-GCM-SHA256' ) ;
58+ test ( 253 , 'ECDH' , 'X25519' , 'ECDHE-RSA-AES128-GCM-SHA256' ) ;
0 commit comments