Skip to content

Commit 90d6af6

Browse files
committed
pkey: update keys used in tests
Use generic keys whenever possible.
1 parent cc4d405 commit 90d6af6

File tree

4 files changed

+133
-212
lines changed

4 files changed

+133
-212
lines changed

test/openssl/test_pkey.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ def test_raw_initialize_errors
293293
end
294294

295295
def test_compare?
296-
key1 = Fixtures.pkey("rsa1024")
297-
key2 = Fixtures.pkey("rsa1024")
298-
key3 = Fixtures.pkey("rsa2048")
299-
key4 = Fixtures.pkey("dh-1")
296+
key1 = Fixtures.pkey("rsa-1")
297+
key2 = Fixtures.pkey("rsa-1")
298+
key3 = Fixtures.pkey("rsa-2")
299+
key4 = Fixtures.pkey("p256")
300300

301301
assert_equal(true, key1.compare?(key2))
302302
assert_equal(true, key1.public_key.compare?(key2))
@@ -311,7 +311,7 @@ def test_compare?
311311
end
312312

313313
def test_to_text
314-
rsa = Fixtures.pkey("rsa1024")
314+
rsa = Fixtures.pkey("rsa-1")
315315
assert_include rsa.to_text, "publicExponent"
316316
end
317317
end

test/openssl/test_pkey_dsa.rb

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup
1010
end
1111

1212
def test_private
13-
key = Fixtures.pkey("dsa1024")
13+
key = Fixtures.pkey("dsa2048")
1414
assert_equal true, key.private?
1515
key2 = OpenSSL::PKey::DSA.new(key.to_der)
1616
assert_equal true, key2.private?
@@ -114,105 +114,76 @@ def test_sign_verify_raw
114114

115115
def test_DSAPrivateKey
116116
# OpenSSL DSAPrivateKey format; similar to RSAPrivateKey
117-
dsa512 = Fixtures.pkey("dsa512")
117+
orig = Fixtures.pkey("dsa2048")
118118
asn1 = OpenSSL::ASN1::Sequence([
119119
OpenSSL::ASN1::Integer(0),
120-
OpenSSL::ASN1::Integer(dsa512.p),
121-
OpenSSL::ASN1::Integer(dsa512.q),
122-
OpenSSL::ASN1::Integer(dsa512.g),
123-
OpenSSL::ASN1::Integer(dsa512.pub_key),
124-
OpenSSL::ASN1::Integer(dsa512.priv_key)
120+
OpenSSL::ASN1::Integer(orig.p),
121+
OpenSSL::ASN1::Integer(orig.q),
122+
OpenSSL::ASN1::Integer(orig.g),
123+
OpenSSL::ASN1::Integer(orig.pub_key),
124+
OpenSSL::ASN1::Integer(orig.priv_key)
125125
])
126126
key = OpenSSL::PKey::DSA.new(asn1.to_der)
127127
assert_predicate key, :private?
128-
assert_same_dsa dsa512, key
129-
130-
pem = <<~EOF
131-
-----BEGIN DSA PRIVATE KEY-----
132-
MIH4AgEAAkEA5lB4GvEwjrsMlGDqGsxrbqeFRh6o9OWt6FgTYiEEHaOYhkIxv0Ok
133-
RZPDNwOG997mDjBnvDJ1i56OmS3MbTnovwIVAJgub/aDrSDB4DZGH7UyarcaGy6D
134-
AkB9HdFw/3td8K4l1FZHv7TCZeJ3ZLb7dF3TWoGUP003RCqoji3/lHdKoVdTQNuR
135-
S/m6DlCwhjRjiQ/lBRgCLCcaAkEAjN891JBjzpMj4bWgsACmMggFf57DS0Ti+5++
136-
Q1VB8qkJN7rA7/2HrCR3gTsWNb1YhAsnFsoeRscC+LxXoXi9OAIUBG98h4tilg6S
137-
55jreJD3Se3slps=
138-
-----END DSA PRIVATE KEY-----
139-
EOF
128+
assert_same_dsa orig, key
129+
130+
pem = der_to_pem(asn1.to_der, "DSA PRIVATE KEY")
140131
key = OpenSSL::PKey::DSA.new(pem)
141-
assert_same_dsa dsa512, key
132+
assert_same_dsa orig, key
142133

143-
assert_equal asn1.to_der, dsa512.to_der
144-
assert_equal pem, dsa512.export
134+
assert_equal asn1.to_der, orig.to_der
135+
assert_equal pem, orig.export
145136
end
146137

147138
def test_DSAPrivateKey_encrypted
148-
# key = abcdef
149-
dsa512 = Fixtures.pkey("dsa512")
150-
pem = <<~EOF
151-
-----BEGIN DSA PRIVATE KEY-----
152-
Proc-Type: 4,ENCRYPTED
153-
DEK-Info: AES-128-CBC,F8BB7BFC7EAB9118AC2E3DA16C8DB1D9
154-
155-
D2sIzsM9MLXBtlF4RW42u2GB9gX3HQ3prtVIjWPLaKBYoToRUiv8WKsjptfZuLSB
156-
74ZPdMS7VITM+W1HIxo/tjS80348Cwc9ou8H/E6WGat8ZUk/igLOUEII+coQS6qw
157-
QpuLMcCIavevX0gjdjEIkojBB81TYDofA1Bp1z1zDI/2Zhw822xapI79ZF7Rmywt
158-
OSyWzFaGipgDpdFsGzvT6//z0jMr0AuJVcZ0VJ5lyPGQZAeVBlbYEI4T72cC5Cz7
159-
XvLiaUtum6/sASD2PQqdDNpgx/WA6Vs1Po2kIUQIM5TIwyJI0GdykZcYm6xIK/ta
160-
Wgx6c8K+qBAIVrilw3EWxw==
161-
-----END DSA PRIVATE KEY-----
162-
EOF
139+
# OpenSSL DSAPrivateKey with OpenSSL encryption
140+
orig = Fixtures.pkey("dsa2048")
141+
142+
pem = der_to_encrypted_pem(orig.to_der, "DSA PRIVATE KEY", "abcdef")
163143
key = OpenSSL::PKey::DSA.new(pem, "abcdef")
164-
assert_same_dsa dsa512, key
144+
assert_same_dsa orig, key
165145
key = OpenSSL::PKey::DSA.new(pem) { "abcdef" }
166-
assert_same_dsa dsa512, key
146+
assert_same_dsa orig, key
167147

168148
cipher = OpenSSL::Cipher.new("aes-128-cbc")
169-
exported = dsa512.to_pem(cipher, "abcdef\0\1")
170-
assert_same_dsa dsa512, OpenSSL::PKey::DSA.new(exported, "abcdef\0\1")
149+
exported = orig.to_pem(cipher, "abcdef\0\1")
150+
assert_same_dsa orig, OpenSSL::PKey::DSA.new(exported, "abcdef\0\1")
171151
assert_raise(OpenSSL::PKey::DSAError) {
172152
OpenSSL::PKey::DSA.new(exported, "abcdef")
173153
}
174154
end
175155

176156
def test_PUBKEY
177-
dsa512 = Fixtures.pkey("dsa512")
178-
dsa512pub = OpenSSL::PKey::DSA.new(dsa512.public_to_der)
157+
orig = Fixtures.pkey("dsa2048")
158+
pub = OpenSSL::PKey::DSA.new(orig.public_to_der)
179159

180160
asn1 = OpenSSL::ASN1::Sequence([
181161
OpenSSL::ASN1::Sequence([
182162
OpenSSL::ASN1::ObjectId("DSA"),
183163
OpenSSL::ASN1::Sequence([
184-
OpenSSL::ASN1::Integer(dsa512.p),
185-
OpenSSL::ASN1::Integer(dsa512.q),
186-
OpenSSL::ASN1::Integer(dsa512.g)
164+
OpenSSL::ASN1::Integer(orig.p),
165+
OpenSSL::ASN1::Integer(orig.q),
166+
OpenSSL::ASN1::Integer(orig.g)
187167
])
188168
]),
189169
OpenSSL::ASN1::BitString(
190-
OpenSSL::ASN1::Integer(dsa512.pub_key).to_der
170+
OpenSSL::ASN1::Integer(orig.pub_key).to_der
191171
)
192172
])
193173
key = OpenSSL::PKey::DSA.new(asn1.to_der)
194174
assert_not_predicate key, :private?
195-
assert_same_dsa dsa512pub, key
196-
197-
pem = <<~EOF
198-
-----BEGIN PUBLIC KEY-----
199-
MIHxMIGoBgcqhkjOOAQBMIGcAkEA5lB4GvEwjrsMlGDqGsxrbqeFRh6o9OWt6FgT
200-
YiEEHaOYhkIxv0OkRZPDNwOG997mDjBnvDJ1i56OmS3MbTnovwIVAJgub/aDrSDB
201-
4DZGH7UyarcaGy6DAkB9HdFw/3td8K4l1FZHv7TCZeJ3ZLb7dF3TWoGUP003RCqo
202-
ji3/lHdKoVdTQNuRS/m6DlCwhjRjiQ/lBRgCLCcaA0QAAkEAjN891JBjzpMj4bWg
203-
sACmMggFf57DS0Ti+5++Q1VB8qkJN7rA7/2HrCR3gTsWNb1YhAsnFsoeRscC+LxX
204-
oXi9OA==
205-
-----END PUBLIC KEY-----
206-
EOF
175+
assert_same_dsa pub, key
176+
177+
pem = der_to_pem(asn1.to_der, "PUBLIC KEY")
207178
key = OpenSSL::PKey::DSA.new(pem)
208-
assert_same_dsa dsa512pub, key
179+
assert_same_dsa pub, key
209180

210181
assert_equal asn1.to_der, key.to_der
211182
assert_equal pem, key.export
212183

213-
assert_equal asn1.to_der, dsa512.public_to_der
184+
assert_equal asn1.to_der, orig.public_to_der
214185
assert_equal asn1.to_der, key.public_to_der
215-
assert_equal pem, dsa512.public_to_pem
186+
assert_equal pem, orig.public_to_pem
216187
assert_equal pem, key.public_to_pem
217188
end
218189

@@ -263,7 +234,7 @@ def test_params
263234
end
264235

265236
def test_dup
266-
key = Fixtures.pkey("dsa1024")
237+
key = Fixtures.pkey("dsa2048")
267238
key2 = key.dup
268239
assert_equal key.params, key2.params
269240

@@ -275,7 +246,7 @@ def test_dup
275246
end
276247

277248
def test_marshal
278-
key = Fixtures.pkey("dsa1024")
249+
key = Fixtures.pkey("dsa2048")
279250
deserialized = Marshal.load(Marshal.dump(key))
280251

281252
assert_equal key.to_der, deserialized.to_der

0 commit comments

Comments
 (0)