jruby-openssl 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +45 -0
  2. data/Manifest.txt +19 -11
  3. data/README.txt +1 -12
  4. data/Rakefile +12 -5
  5. data/lib/bcmail-jdk15-144.jar +0 -0
  6. data/lib/bcprov-jdk15-144.jar +0 -0
  7. data/lib/jopenssl/version.rb +1 -1
  8. data/lib/jopenssl.jar +0 -0
  9. data/lib/openssl/bn.rb +5 -3
  10. data/lib/openssl/buffering.rb +2 -2
  11. data/lib/openssl/cipher.rb +27 -18
  12. data/lib/openssl/digest.rb +19 -4
  13. data/lib/openssl/dummy.rb +11 -11
  14. data/lib/openssl/dummyssl.rb +2 -1
  15. data/lib/openssl/pkcs7.rb +25 -0
  16. data/lib/openssl/ssl.rb +70 -26
  17. data/lib/openssl/x509.rb +2 -2
  18. data/lib/openssl.rb +47 -2
  19. data/test/fixture/ca-bundle.crt +2794 -0
  20. data/test/fixture/keypair.pem +27 -0
  21. data/test/fixture/selfcert.pem +23 -0
  22. data/test/{pkcs7_mime_enveloped.message → java/pkcs7_mime_enveloped.message} +0 -0
  23. data/test/{pkcs7_mime_signed.message → java/pkcs7_mime_signed.message} +0 -0
  24. data/test/{pkcs7_multipart_signed.message → java/pkcs7_multipart_signed.message} +0 -0
  25. data/test/{test_java_attribute.rb → java/test_java_attribute.rb} +2 -2
  26. data/test/{test_java_bio.rb → java/test_java_bio.rb} +0 -0
  27. data/test/{test_java_mime.rb → java/test_java_mime.rb} +0 -0
  28. data/test/{test_java_pkcs7.rb → java/test_java_pkcs7.rb} +35 -32
  29. data/test/{test_java_smime.rb → java/test_java_smime.rb} +0 -0
  30. data/test/openssl/test_asn1.rb +1 -3
  31. data/test/openssl/test_cipher.rb +7 -10
  32. data/test/openssl/test_ec.rb +113 -0
  33. data/test/openssl/test_pair.rb +3 -8
  34. data/test/openssl/test_pkcs7.rb +339 -11
  35. data/test/openssl/test_ssl.rb +728 -100
  36. data/test/openssl/test_x509cert.rb +5 -5
  37. data/test/openssl/test_x509crl.rb +1 -2
  38. data/test/openssl/test_x509ext.rb +3 -3
  39. data/test/openssl/test_x509name.rb +1 -0
  40. data/test/openssl/test_x509req.rb +5 -7
  41. data/test/openssl/test_x509store.rb +3 -2
  42. data/test/test_all.rb +1 -0
  43. data/test/{test_openssl_x509.rb → test_certificate.rb} +33 -3
  44. data/test/test_cipher.rb +85 -7
  45. data/test/test_integration.rb +7 -8
  46. data/test/test_java.rb +9 -9
  47. data/test/test_openssl.rb +3 -33
  48. data/test/test_parse_certificate.rb +8 -1
  49. data/test/test_pkcs7.rb +40 -0
  50. data/test/test_pkey.rb +165 -7
  51. data/test/test_x509store.rb +8 -7
  52. metadata +31 -30
  53. data/lib/bcmail-jdk14-139.jar +0 -0
  54. data/lib/bcprov-jdk14-139.jar +0 -0
@@ -1,8 +1,3 @@
1
- if defined?(JRUBY_VERSION)
2
- require "java"
3
- $CLASSPATH << 'pkg/classes'
4
- $CLASSPATH << 'lib/bcprov-jdk14-139.jar'
5
- end
6
1
  begin
7
2
  require "openssl"
8
3
  require File.join(File.dirname(__FILE__), "utils.rb")
@@ -52,7 +47,7 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
52
47
 
53
48
  data = "aaaaa\r\nbbbbb\r\nccccc\r\n"
54
49
  tmp = OpenSSL::PKCS7.sign(@ee1_cert, @rsa1024, data, ca_certs)
55
- p7 = OpenSSL::PKCS7::PKCS7.new(tmp.to_der)
50
+ p7 = OpenSSL::PKCS7.new(tmp.to_der)
56
51
  certs = p7.certificates
57
52
  signers = p7.signers
58
53
  assert(p7.verify([], store))
@@ -71,7 +66,7 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
71
66
  data = "aaaaa\nbbbbb\nccccc\n"
72
67
  flag = OpenSSL::PKCS7::BINARY
73
68
  tmp = OpenSSL::PKCS7.sign(@ee1_cert, @rsa1024, data, ca_certs, flag)
74
- p7 = OpenSSL::PKCS7::PKCS7.new(tmp.to_der)
69
+ p7 = OpenSSL::PKCS7.new(tmp.to_der)
75
70
  certs = p7.certificates
76
71
  signers = p7.signers
77
72
  assert(p7.verify([], store))
@@ -93,7 +88,7 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
93
88
  tmp1.add_signer(tmp2.signers[0])
94
89
  tmp1.add_certificate(@ee2_cert)
95
90
 
96
- p7 = OpenSSL::PKCS7::PKCS7.new(tmp1.to_der)
91
+ p7 = OpenSSL::PKCS7.new(tmp1.to_der)
97
92
  certs = p7.certificates
98
93
  signers = p7.signers
99
94
  assert(p7.verify([], store))
@@ -114,7 +109,7 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
114
109
  data = "aaaaa\nbbbbb\nccccc\n"
115
110
  flag = OpenSSL::PKCS7::BINARY|OpenSSL::PKCS7::DETACHED
116
111
  tmp = OpenSSL::PKCS7.sign(@ee1_cert, @rsa1024, data, ca_certs, flag)
117
- p7 = OpenSSL::PKCS7::PKCS7.new(tmp.to_der)
112
+ p7 = OpenSSL::PKCS7.new(tmp.to_der)
118
113
  a1 = OpenSSL::ASN1.decode(p7)
119
114
 
120
115
  certs = p7.certificates
@@ -140,9 +135,8 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
140
135
  certs = [@ee1_cert, @ee2_cert]
141
136
  cipher = OpenSSL::Cipher::AES.new("128-CBC")
142
137
  data = "aaaaa\nbbbbb\nccccc\n"
143
-
144
138
  tmp = OpenSSL::PKCS7.encrypt(certs, data, cipher, OpenSSL::PKCS7::BINARY)
145
- p7 = OpenSSL::PKCS7::PKCS7.new(tmp.to_der)
139
+ p7 = OpenSSL::PKCS7.new(tmp.to_der)
146
140
  recip = p7.recipients
147
141
  assert_equal(:enveloped, p7.type)
148
142
  assert_equal(2, recip.size)
@@ -155,6 +149,340 @@ class OpenSSL::TestPKCS7 < Test::Unit::TestCase
155
149
  assert_equal(3, recip[1].serial)
156
150
  assert_equal(data, p7.decrypt(@rsa1024, @ee2_cert))
157
151
  end
152
+
153
+ def test_envelope_des3
154
+ certs = [@ee1_cert]
155
+ cipher = OpenSSL::Cipher.new("des-ede3-cbc")
156
+ data = "aaaaa\nbbbbb\nccccc\n"
157
+ tmp = OpenSSL::PKCS7.encrypt(certs, data, cipher, OpenSSL::PKCS7::BINARY)
158
+ p7 = OpenSSL::PKCS7.new(tmp.to_der)
159
+ assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))
160
+ end
161
+
162
+ def test_envelope_nil # RC2-40-CBC by default
163
+ certs = [@ee1_cert]
164
+ data = "aaaaa\nbbbbb\nccccc\n"
165
+ tmp = OpenSSL::PKCS7.encrypt(certs, data, nil, OpenSSL::PKCS7::BINARY)
166
+ p7 = OpenSSL::PKCS7.new(tmp.to_der)
167
+ assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))
168
+ end
169
+
170
+ def test_envelope_des3_compat
171
+ data = "aaaaa\nbbbbb\nccccc\n"
172
+ cruby_envelope = <<EOP
173
+ -----BEGIN PKCS7-----
174
+ MIIBMgYJKoZIhvcNAQcDoIIBIzCCAR8CAQAxgdwwgdkCAQAwQjA9MRMwEQYKCZIm
175
+ iZPyLGQBGRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQD
176
+ DAJDQQIBAjANBgkqhkiG9w0BAQEFAASBgECDOPwRb0Vimo3bXAypvnhB/JvHZ0hV
177
+ 5CWFdAmovioiu1fnMEqawJWudznUZ1rsCKKX4qzqfvSXk+8w7IZ5rqEFoGmLRQQ+
178
+ GR8yPJnDwNyQJwRjvcX2WzJnFDFIfROb+ySu8UCmxkTd/5jB3jsREXVqSIxezTif
179
+ IT8Q8X7CCx8+MDsGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIaH1JJe6+hX+AGD8E
180
+ j3/kwFY3IOUxly+lPJNEQLpWBoSHZA==
181
+ -----END PKCS7-----
182
+ EOP
183
+ p7 = OpenSSL::PKCS7.new(cruby_envelope)
184
+ assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))
185
+ #
186
+ jruby_envelope = <<EOP
187
+ -----BEGIN PKCS7-----
188
+ MIIBMAYJKoZIhvcNAQcDoIIBITCCAR0CAQAxgdowgdcCAQAwQjA9MRMwEQYKCZIm
189
+ iZPyLGQBGRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQD
190
+ DAJDQQIBAjALBgkqhkiG9w0BAQEEgYBqCQY/oP0Gv1XbAJ5HjZ9HNZN9gBFlmMDx
191
+ fb9YWDQZH24KrTUEssr6jyJuyMsONTdaYWIfG/RWHxw970AkXUXcXDeO8Ze+vSVh
192
+ 8tohLGLTsBKdvizuC/5jFHLAoNaa5qJZEFanmqMXlO5HiImUZB2BHwJddRuRTg0y
193
+ UuAnFtLd+DA7BgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECP1rHLNHCtyWgBgFQDex
194
+ XDgcukPOkDwRcUQJAKu3x5HtQpw=
195
+ -----END PKCS7-----
196
+ EOP
197
+ p7 = OpenSSL::PKCS7.new(jruby_envelope)
198
+ assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))
199
+ end
200
+
201
+ def test_envelope_aes_compat
202
+ data = "aaaaa\nbbbbb\nccccc\n"
203
+ cruby_envelope = <<EOP
204
+ -----BEGIN PKCS7-----
205
+ MIICIAYJKoZIhvcNAQcDoIICETCCAg0CAQAxggG4MIHZAgEAMEIwPTETMBEGCgmS
206
+ JomT8ixkARkWA29yZzEZMBcGCgmSJomT8ixkARkWCXJ1YnktbGFuZzELMAkGA1UE
207
+ AwwCQ0ECAQIwDQYJKoZIhvcNAQEBBQAEgYCHIMVl+WKzjnTuslePlItMq4A+klIZ
208
+ rU+5U0UvaOPPpr2UgjD3J1OL09W19De7pKNSSZUd0QWQBB3IG4IzefWzYxt2ejZY
209
+ rJDO/wdHa6Mdq1ZsdbLP1sIRxTyWskc3O8VJvo5boFG/bZxLHA6CPnhifnfqEkkq
210
+ wVbjAbBGI61HxTCB2QIBADBCMD0xEzARBgoJkiaJk/IsZAEZFgNvcmcxGTAXBgoJ
211
+ kiaJk/IsZAEZFglydWJ5LWxhbmcxCzAJBgNVBAMMAkNBAgEDMA0GCSqGSIb3DQEB
212
+ AQUABIGASvO7jsPCAB/TcRgmIKEHRDqPThQrSAJRE+uDVeiPlIHsCaUDspGX8niH
213
+ 4+UPsLhdd6H68Ecay93Hi78SYR/w0NbrwwMBGRlU3/AFhq/OseosuBb303mAqnoz
214
+ kU6qlNwJuy/4NIReldsaVJJuZ4nkEBfZAw+99Mxh7IQYx069fwIwTAYJKoZIhvcN
215
+ AQcBMB0GCWCGSAFlAwQBAgQQf1IrOpN2OmqMHz1t7biX/oAgubIiBzarCuTKPMby
216
+ eg4/+hy0xJsT0IkF1O0G1XTOWcE=
217
+ -----END PKCS7-----
218
+ EOP
219
+ p7 = OpenSSL::PKCS7.new(cruby_envelope)
220
+ assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))
221
+ #
222
+ jruby_envelope = <<EOP
223
+ -----BEGIN PKCS7-----
224
+ MIICHAYJKoZIhvcNAQcDoIICDTCCAgkCAQAxggG0MIHXAgEAMEIwPTETMBEGCgmS
225
+ JomT8ixkARkWA29yZzEZMBcGCgmSJomT8ixkARkWCXJ1YnktbGFuZzELMAkGA1UE
226
+ AwwCQ0ECAQIwCwYJKoZIhvcNAQEBBIGAg0Yz54LwCKM9l128jjh0FlA5Wvzfsjd2
227
+ S3dYESzxnxqdhKkSDya16lkYyZZ+aVWmC8XOgkGGwGJTudq3gGn2p3wsgx63J4Ar
228
+ PfslsDslIaddp8op4i+ifDi15qCjWXIyQaYMSN/DsFN8DlB8jMjPAlQO3MFtifb2
229
+ D7vFjLjSrogwgdcCAQAwQjA9MRMwEQYKCZImiZPyLGQBGRYDb3JnMRkwFwYKCZIm
230
+ iZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQDDAJDQQIBAzALBgkqhkiG9w0BAQEE
231
+ gYCfAEL80vCsFo9kalePlb73lL2iDPbbDfjpWs0nnlXX8BhS/H781kvUkDpwl/qT
232
+ 9KcFCaPGJ2IYgEjys6VPK9ho/hIIIz+BX8MIuWbweQTn1Y0TTlTL91Zr66xyZP1p
233
+ zyStG6Zc1u26hiX31hk1P6ihhhXu+I5bserKNYUnYsxJSjBMBgkqhkiG9w0BBwEw
234
+ HQYJYIZIAWUDBAECBBD42Hndr47SEdUoc6SWOKsbgCCylxb34kE14eBc9nN9MnC+
235
+ SaVrDPgso584FIimP6o+Fw==
236
+ -----END PKCS7-----
237
+ EOP
238
+ p7 = OpenSSL::PKCS7.new(jruby_envelope)
239
+ assert_equal(data, p7.decrypt(@rsa1024, @ee1_cert))
240
+ end
241
+
242
+ def test_signed_compat
243
+ =begin
244
+ # how to generate signature
245
+ ca_certs = [@ca_cert]
246
+ data = "aaaaa\r\nbbbbb\r\nccccc\r\n"
247
+ tmp = OpenSSL::PKCS7.sign(@ee1_cert, @rsa1024, data, ca_certs)
248
+ puts tmp
249
+ =end
250
+ cruby_sign = <<EOP
251
+ -----BEGIN PKCS7-----
252
+ MIIILgYJKoZIhvcNAQcCoIIIHzCCCBsCAQExCzAJBgUrDgMCGgUAMCQGCSqGSIb3
253
+ DQEHAaAXBBVhYWFhYQ0KYmJiYmINCmNjY2NjDQqgggZBMIIC4TCCAcmgAwIBAgIB
254
+ AjANBgkqhkiG9w0BAQUFADA9MRMwEQYKCZImiZPyLGQBGRYDb3JnMRkwFwYKCZIm
255
+ iZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQDDAJDQTAeFw0wOTEyMTYxNTQ1MzRa
256
+ Fw0wOTEyMTYxNjE1MzRaMD4xEzARBgoJkiaJk/IsZAEZFgNvcmcxGTAXBgoJkiaJ
257
+ k/IsZAEZFglydWJ5LWxhbmcxDDAKBgNVBAMMA0VFMTCBnzANBgkqhkiG9w0BAQEF
258
+ AAOBjQAwgYkCgYEAy8LEsNRApz7U/j5DoB4XBgO9Z8Atv5y/OVQRp0ag8Tqo1Yew
259
+ sWijxEWB7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qhkiG
339
+ 9w0BCQ8xRTBDMAoGCCqGSIb3DQMHMA4GCCqGSIb3DQMCAgIAgDANBggqhkiG9w0D
340
+ AgIBQDANBggqhkiG9w0DAgIBKDAHBgUrDgMCBzALBgkqhkiG9w0BAQEEgYBygH60
341
+ /1zLRnXaPKh8fTaQtQCTobefRqGLxbWJaTmO83UeDEmS8HXyr6t5KkZ4qZL6BA50
342
+ bQSlVx3I9SiqevP0vEiXGzmb4m1blFzdH5HHZk4ZUWqWYyTqOdXTSfwFp53VAUhi
343
+ 9d8f3IBfFoxCvORtzYZKCzW/ZRvEqBO3xJlVuQ==
344
+ -----END PKCS7-----
345
+ EOP
346
+ store = OpenSSL::X509::Store.new
347
+ store.add_cert(@ca_cert)
348
+ # just checks pubkey's n to avoid certificate expiration.
349
+ # this test is for PKCS#7, not for certificate verification.
350
+ store.verify_callback = proc { |ok, ctx|
351
+ # !! CAUTION: NEVER DO THIS KIND OF NEGLIGENCE !!
352
+ [@ca_cert.public_key.n, @ee1_cert.public_key.n].include?(ctx.current_cert.public_key.n)
353
+ # should return 'ok' here
354
+ }
355
+
356
+ p7 = OpenSSL::PKCS7.new(cruby_sign)
357
+ assert(p7.verify([], store))
358
+
359
+ p7 = OpenSSL::PKCS7.new(jruby_sign)
360
+ assert(p7.verify([], store))
361
+ end
362
+
363
+ def test_detached_sign_compat
364
+ =begin
365
+ # how to generate signature
366
+ ca_certs = [@ca_cert]
367
+ flag = OpenSSL::PKCS7::BINARY|OpenSSL::PKCS7::DETACHED
368
+ tmp = OpenSSL::PKCS7.sign(@ee1_cert, @rsa1024, data, ca_certs, flag)
369
+ puts tmp
370
+ =end
371
+ cruby_sign = <<EOP
372
+ -----BEGIN PKCS7-----
373
+ MIIIFQYJKoZIhvcNAQcCoIIIBjCCCAICAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3
374
+ DQEHAaCCBkEwggLhMIIByaADAgECAgECMA0GCSqGSIb3DQEBBQUAMD0xEzARBgoJ
375
+ kiaJk/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gsRVhIkvSsTNaTe0ylA3Lqa5COd89PrCjm66IdAjyND3puWP4etFP6
407
+ ycc7rtc0302ndadSEJRgul9pFJ4xtuAN5jGCAZwwggGYAgEBMEIwPTETMBEGCgmS
408
+ JomT8ixkARkWA29yZzEZMBcGCgmSJomT8ixkARkWCXJ1YnktbGFuZzELMAkGA1UE
409
+ AwwCQ0ECAQIwCQYFKw4DAhoFAKCBsTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcB
410
+ MBwGCSqGSIb3DQEJBTEPFw0wOTEyMTYxNTQ5MjdaMCMGCSqGSIb3DQEJBDEWBBT2
411
+ oG8gOR1i/LHuubBgBOVTjSF6lzBSBgkqhkiG9w0BCQ8xRTBDMAoGCCqGSIb3DQMH
412
+ MA4GCCqGSIb3DQMCAgIAgDANBggqhkiG9w0DAgIBQDAHBgUrDgMCBzANBggqhkiG
413
+ 9w0DAgIBKDANBgkqhkiG9w0BAQEFAASBgCPxDWHnvO3pMg0XUDGtisZgbjFG+sJy
414
+ brFi2QG0IR+iQ6kOrBWkBW15SDgj0te1ze6ddLx3VT0aaOHMzGS103oWQT6l+xqV
415
+ C+A/FA5O+hefjqusgl289gFvApuGVSaMisHBcMAN059E1rsSTnG3LoHqkKjOgKkJ
416
+ zyAlR+YeT270
417
+ -----END PKCS7-----
418
+ EOP
419
+ jruby_sign = <<EOP
420
+ -----BEGIN PKCS7-----
421
+ MIIIEwYJKoZIhvcNAQcCoIIIBDCCCAACAQExCTAHBgUrDgMCGjAPBgkqhkiG9w0B
422
+ BwGgAgQAoIIGQTCCAuEwggHJoAMCAQICAQIwDQYJKoZIhvcNAQEFBQAwPTETMBEG
423
+ CgmSJomT8ixkARkWA29yZzEZMBcGCgmSJomT8ixkARkWCXJ1YnktbGFuZzELMAkG
424
+ A1UEAwwCQ0EwHhcNMDkxMjE2MTU0OTU3WhcNMDkxMjE2MTYxOTU3WjA+MRMwEQYK
425
+ CZImiZPyLGQBGRYDb3JnMRkwFwYKCZImiZPyL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PyLGQBGRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMQswCQYD
457
+ VQQDDAJDQQIBAjAHBgUrDgMCGqCBsTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcB
458
+ MBwGCSqGSIb3DQEJBTEPFw0wOTEyMTYxNTQ5NTdaMCMGCSqGSIb3DQEJBDEWBBT2
459
+ oG8gOR1i/LHuubBgBOVTjSF6lzBSBgkqhkiG9w0BCQ8xRTBDMAoGCCqGSIb3DQMH
460
+ MA4GCCqGSIb3DQMCAgIAgDANBggqhkiG9w0DAgIBQDANBggqhkiG9w0DAgIBKDAH
461
+ BgUrDgMCBzALBgkqhkiG9w0BAQEEgYBPjfO6ZkzbNhlRI9Y58QpOxdqdF/NmWBJE
462
+ rYoqlDUeMcH5RHb+MLUBEeo666u0xIXYzG9CWrlVjJa42FDNEl5sGRB1Oic6LNIB
463
+ YBFvB2CAX9R3+d34WMLXKwl6ikeN6VVud+TeB5SpLR/hltWIb1FJMeJ4wM8fNI/t
464
+ RfHXsdxTuA==
465
+ -----END PKCS7-----
466
+ EOP
467
+ data = "aaaaa\nbbbbb\nccccc\n"
468
+ store = OpenSSL::X509::Store.new
469
+ store.add_cert(@ca_cert)
470
+ # just checks pubkey's n to avoid certificate expiration.
471
+ # this test is for PKCS#7, not for certificate verification.
472
+ store.verify_callback = proc { |ok, ctx|
473
+ # !! CAUTION: NEVER DO THIS KIND OF NEGLIGENCE !!
474
+ [@ca_cert.public_key.n, @ee1_cert.public_key.n].include?(ctx.current_cert.public_key.n)
475
+ # should return 'ok' here
476
+ }
477
+
478
+ p7 = OpenSSL::PKCS7.new(cruby_sign)
479
+ assert(!p7.verify([], store))
480
+ assert(p7.verify([], store, data))
481
+
482
+ p7 = OpenSSL::PKCS7.new(jruby_sign)
483
+ assert(!p7.verify([], store))
484
+ assert(p7.verify([], store, data))
485
+ end
158
486
  end
159
487
 
160
488
  end