@@ -18,15 +18,26 @@ def test_new_generate
18
18
assert_key ( dh )
19
19
end if ENV [ "OSSL_TEST_ALL" ]
20
20
21
- def test_new_break
21
+ def test_new_break_on_non_fips
22
+ omit_on_fips
23
+
22
24
assert_nil ( OpenSSL ::PKey ::DH . new ( NEW_KEYLEN ) { break } )
23
25
assert_raise ( RuntimeError ) do
24
26
OpenSSL ::PKey ::DH . new ( NEW_KEYLEN ) { raise }
25
27
end
26
28
end
27
29
30
+ def test_new_break_on_fips
31
+ omit_on_non_fips
32
+
33
+ # The block argument is not executed in FIPS case.
34
+ # See https://github.com/ruby/openssl/issues/692 for details.
35
+ assert ( OpenSSL ::PKey ::DH . new ( NEW_KEYLEN ) { break } )
36
+ assert ( OpenSSL ::PKey ::DH . new ( NEW_KEYLEN ) { raise } )
37
+ end
38
+
28
39
def test_derive_key
29
- params = Fixtures . pkey ( "dh1024 " )
40
+ params = Fixtures . pkey ( "dh2048_ffdhe2048 " )
30
41
dh1 = OpenSSL ::PKey . generate_key ( params )
31
42
dh2 = OpenSSL ::PKey . generate_key ( params )
32
43
dh1_pub = OpenSSL ::PKey . read ( dh1 . public_to_der )
@@ -44,34 +55,38 @@ def test_derive_key
44
55
end
45
56
46
57
def test_DHparams
47
- dh1024 = Fixtures . pkey ( "dh1024 " )
48
- dh1024params = dh1024 . public_key
58
+ dh = Fixtures . pkey ( "dh2048_ffdhe2048 " )
59
+ dh_params = dh . public_key
49
60
50
61
asn1 = OpenSSL ::ASN1 ::Sequence ( [
51
- OpenSSL ::ASN1 ::Integer ( dh1024 . p ) ,
52
- OpenSSL ::ASN1 ::Integer ( dh1024 . g )
62
+ OpenSSL ::ASN1 ::Integer ( dh . p ) ,
63
+ OpenSSL ::ASN1 ::Integer ( dh . g )
53
64
] )
54
65
key = OpenSSL ::PKey ::DH . new ( asn1 . to_der )
55
- assert_same_dh dh1024params , key
66
+ assert_same_dh dh_params , key
56
67
57
68
pem = <<~EOF
58
69
-----BEGIN DH PARAMETERS-----
59
- MIGHAoGBAKnKQ8MNK6nYZzLrrcuTsLxuiJGXoOO5gT+tljOTbHBuiktdMTITzIY0
60
- pFxIvjG05D7HoBZQfrR0c92NGWPkAiCkhQKB8JCbPVzwNLDy6DZ0pmofDKrEsYHG
61
- AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
70
+ MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
71
+ +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
72
+ 87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
73
+ YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
74
+ 7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
75
+ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
62
76
-----END DH PARAMETERS-----
63
77
EOF
78
+
64
79
key = OpenSSL ::PKey ::DH . new ( pem )
65
- assert_same_dh dh1024params , key
80
+ assert_same_dh dh_params , key
66
81
key = OpenSSL ::PKey . read ( pem )
67
- assert_same_dh dh1024params , key
82
+ assert_same_dh dh_params , key
68
83
69
- assert_equal asn1 . to_der , dh1024 . to_der
70
- assert_equal pem , dh1024 . export
84
+ assert_equal asn1 . to_der , dh . to_der
85
+ assert_equal pem , dh . export
71
86
end
72
87
73
88
def test_public_key
74
- dh = Fixtures . pkey ( "dh1024 " )
89
+ dh = Fixtures . pkey ( "dh2048_ffdhe2048 " )
75
90
public_key = dh . public_key
76
91
assert_no_key ( public_key ) #implies public_key.public? is false!
77
92
assert_equal ( dh . to_der , public_key . to_der )
@@ -80,7 +95,8 @@ def test_public_key
80
95
81
96
def test_generate_key
82
97
# Deprecated in v3.0.0; incompatible with OpenSSL 3.0
83
- dh = Fixtures . pkey ( "dh1024" ) . public_key # creates a copy with params only
98
+ # Creates a copy with params only
99
+ dh = Fixtures . pkey ( "dh2048_ffdhe2048" ) . public_key
84
100
assert_no_key ( dh )
85
101
dh . generate_key!
86
102
assert_key ( dh )
@@ -91,7 +107,15 @@ def test_generate_key
91
107
end if !openssl? ( 3 , 0 , 0 )
92
108
93
109
def test_params_ok?
94
- dh0 = Fixtures . pkey ( "dh1024" )
110
+ # Skip the tests in old OpenSSL version 1.1.1c or early versions before
111
+ # applying the following commits in OpenSSL 1.1.1d to make `DH_check`
112
+ # function pass the RFC 7919 FFDHE group texts.
113
+ # https://github.com/openssl/openssl/pull/9435
114
+ unless openssl? ( 1 , 1 , 1 , 4 )
115
+ pend 'DH check for RFC 7919 FFDHE group texts is not implemented'
116
+ end
117
+
118
+ dh0 = Fixtures . pkey ( "dh2048_ffdhe2048" )
95
119
96
120
dh1 = OpenSSL ::PKey ::DH . new ( OpenSSL ::ASN1 ::Sequence ( [
97
121
OpenSSL ::ASN1 ::Integer ( dh0 . p ) ,
@@ -108,7 +132,7 @@ def test_params_ok?
108
132
109
133
def test_dup
110
134
# Parameters only
111
- dh1 = Fixtures . pkey ( "dh1024 " )
135
+ dh1 = Fixtures . pkey ( "dh2048_ffdhe2048 " )
112
136
dh2 = dh1 . dup
113
137
assert_equal dh1 . to_der , dh2 . to_der
114
138
assert_not_equal nil , dh1 . p
@@ -125,7 +149,7 @@ def test_dup
125
149
end
126
150
127
151
# With a key pair
128
- dh3 = OpenSSL ::PKey . generate_key ( Fixtures . pkey ( "dh1024 " ) )
152
+ dh3 = OpenSSL ::PKey . generate_key ( Fixtures . pkey ( "dh2048_ffdhe2048 " ) )
129
153
dh4 = dh3 . dup
130
154
assert_equal dh3 . to_der , dh4 . to_der
131
155
assert_equal dh1 . to_der , dh4 . to_der # encodes parameters only
@@ -136,7 +160,7 @@ def test_dup
136
160
end
137
161
138
162
def test_marshal
139
- dh = Fixtures . pkey ( "dh1024 " )
163
+ dh = Fixtures . pkey ( "dh2048_ffdhe2048 " )
140
164
deserialized = Marshal . load ( Marshal . dump ( dh ) )
141
165
142
166
assert_equal dh . to_der , deserialized . to_der
0 commit comments