|
4 | 4 | if defined?(OpenSSL)
|
5 | 5 |
|
6 | 6 | class OpenSSL::TestX509Store < OpenSSL::TestCase
|
7 |
| - def setup |
8 |
| - super |
9 |
| - @rsa1024 = Fixtures.pkey("rsa1024") |
10 |
| - @rsa2048 = Fixtures.pkey("rsa2048") |
11 |
| - @dsa256 = Fixtures.pkey("dsa256") |
12 |
| - @dsa512 = Fixtures.pkey("dsa512") |
13 |
| - @ca1 = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=CA1") |
14 |
| - @ca2 = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=CA2") |
15 |
| - @ee1 = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=EE1") |
16 |
| - @ee2 = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=EE2") |
17 |
| - end |
18 |
| - |
19 | 7 | def test_store_new
|
20 | 8 | # v2.3.0 emits explicit warning
|
21 | 9 | assert_warning(/new does not take any arguments/) {
|
@@ -339,22 +327,26 @@ def test_verify_with_crl
|
339 | 327 | assert_equal(false, store.verify(ee2_cert))
|
340 | 328 | end
|
341 | 329 |
|
342 |
| - def test_set_errors |
| 330 | + def test_add_cert_duplicate |
| 331 | + # Up until OpenSSL 1.1.0, X509_STORE_add_{cert,crl}() returned an error |
| 332 | + # if the given certificate is already in the X509_STORE |
343 | 333 | return if openssl?(1, 1, 0) || libressl?
|
344 |
| - now = Time.now |
345 |
| - ca1_cert = issue_cert(@ca1, @rsa2048, 1, [], nil, nil) |
| 334 | + ca1 = OpenSSL::X509::Name.parse_rfc2253("CN=Root CA") |
| 335 | + ca1_key = Fixtures.pkey("rsa-1") |
| 336 | + ca1_cert = issue_cert(ca1, ca1_key, 1, [], nil, nil) |
346 | 337 | store = OpenSSL::X509::Store.new
|
347 | 338 | store.add_cert(ca1_cert)
|
348 | 339 | assert_raise(OpenSSL::X509::StoreError){
|
349 | 340 | store.add_cert(ca1_cert) # add same certificate twice
|
350 | 341 | }
|
351 | 342 |
|
| 343 | + now = Time.now |
352 | 344 | revoke_info = []
|
353 | 345 | crl1 = issue_crl(revoke_info, 1, now, now+1800, [],
|
354 |
| - ca1_cert, @rsa2048, OpenSSL::Digest.new('SHA1')) |
| 346 | + ca1_cert, ca1_key, "sha256") |
355 | 347 | revoke_info = [ [2, now, 1], ]
|
356 | 348 | crl2 = issue_crl(revoke_info, 2, now+1800, now+3600, [],
|
357 |
| - ca1_cert, @rsa2048, OpenSSL::Digest.new('SHA1')) |
| 349 | + ca1_cert, ca1_key, "sha256") |
358 | 350 | store.add_crl(crl1)
|
359 | 351 | assert_raise(OpenSSL::X509::StoreError){
|
360 | 352 | store.add_crl(crl2) # add CRL issued by same CA twice.
|
|
0 commit comments