@@ -26,14 +26,19 @@ def test_new_break
26
26
end
27
27
28
28
def test_derive_key
29
- dh1 = Fixtures . pkey ( "dh1024" ) . generate_key!
30
- dh2 = Fixtures . pkey ( "dh1024" ) . generate_key!
29
+ params = Fixtures . pkey ( "dh1024" )
30
+ dh1 = OpenSSL ::PKey . generate_key ( params )
31
+ dh2 = OpenSSL ::PKey . generate_key ( params )
31
32
dh1_pub = OpenSSL ::PKey . read ( dh1 . public_to_der )
32
33
dh2_pub = OpenSSL ::PKey . read ( dh2 . public_to_der )
34
+
33
35
z = dh1 . g . mod_exp ( dh1 . priv_key , dh1 . p ) . mod_exp ( dh2 . priv_key , dh1 . p ) . to_s ( 2 )
34
36
assert_equal z , dh1 . derive ( dh2_pub )
35
37
assert_equal z , dh2 . derive ( dh1_pub )
36
38
39
+ assert_raise ( OpenSSL ::PKey ::PKeyError ) { params . derive ( dh1_pub ) }
40
+ assert_raise ( OpenSSL ::PKey ::PKeyError ) { dh1_pub . derive ( params ) }
41
+
37
42
assert_equal z , dh1 . compute_key ( dh2 . pub_key )
38
43
assert_equal z , dh2 . compute_key ( dh1 . pub_key )
39
44
end
@@ -74,19 +79,17 @@ def test_public_key
74
79
end
75
80
76
81
def test_generate_key
77
- dh = Fixtures . pkey ( "dh1024" ) . public_key # creates a copy
78
- assert_no_key ( dh )
79
- dh . generate_key!
80
- assert_key ( dh )
81
- end
82
-
83
- def test_key_exchange
84
- dh = Fixtures . pkey ( "dh1024" )
85
- dh2 = dh . public_key
86
- dh . generate_key!
87
- dh2 . generate_key!
88
- assert_equal ( dh . compute_key ( dh2 . pub_key ) , dh2 . compute_key ( dh . pub_key ) )
89
- end
82
+ EnvUtil . suppress_warning { # Deprecated in v3.0.0; incompatible with OpenSSL 3.0
83
+ dh = Fixtures . pkey ( "dh1024" ) . public_key # creates a copy with params only
84
+ assert_no_key ( dh )
85
+ dh . generate_key!
86
+ assert_key ( dh )
87
+
88
+ dh2 = dh . public_key
89
+ dh2 . generate_key!
90
+ assert_equal ( dh . compute_key ( dh2 . pub_key ) , dh2 . compute_key ( dh . pub_key ) )
91
+ }
92
+ end if !openssl? ( 3 , 0 , 0 )
90
93
91
94
def test_params_ok?
92
95
dh0 = Fixtures . pkey ( "dh1024" )
0 commit comments