@@ -10,90 +10,49 @@ const tls = require('tls');
10
10
const key = fixtures . readKey ( 'agent2-key.pem' ) ;
11
11
const cert = fixtures . readKey ( 'agent2-cert.pem' ) ;
12
12
13
- let ntests = 0 ;
14
- let nsuccess = 0 ;
15
-
16
13
function loadDHParam ( n ) {
17
14
return fixtures . readKey ( `dh${ n } .pem` ) ;
18
15
}
19
16
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 ) ;
30
19
31
20
const options = {
32
21
key : key ,
33
22
cert : cert ,
34
23
ciphers : cipher
35
24
} ;
36
25
26
+ if ( name ) options . ecdhCurve = name ;
27
+
37
28
if ( type === 'DH' ) options . dhparam = loadDHParam ( size ) ;
38
29
39
- const server = tls . createServer ( options , function ( conn ) {
30
+ const server = tls . createServer ( options , common . mustCall ( ( conn ) => {
40
31
assert . strictEqual ( conn . getEphemeralKeyInfo ( ) , null ) ;
41
32
conn . end ( ) ;
42
- } ) ;
33
+ } ) ) ;
43
34
44
- server . on ( 'close' , common . mustCall ( function ( err ) {
35
+ server . on ( 'close' , common . mustCall ( ( err ) => {
45
36
assert . ifError ( err ) ;
46
- if ( next ) next ( ) ;
47
37
} ) ) ;
48
38
49
- server . listen ( 0 , '127.0.0.1' , common . mustCall ( function ( ) {
39
+ server . listen ( 0 , '127.0.0.1' , common . mustCall ( ( ) => {
50
40
const client = tls . connect ( {
51
- port : this . address ( ) . port ,
41
+ port : server . address ( ) . port ,
52
42
rejectUnauthorized : false
53
43
} , function ( ) {
54
44
const ekeyinfo = client . getEphemeralKeyInfo ( ) ;
55
45
assert . strictEqual ( ekeyinfo . type , type ) ;
56
46
assert . strictEqual ( ekeyinfo . size , size ) ;
57
47
assert . strictEqual ( ekeyinfo . name , name ) ;
58
- nsuccess ++ ;
59
48
server . close ( ) ;
60
49
} ) ;
61
50
} ) ) ;
62
51
}
63
52
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