pftg-jruby-openssl 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +48 -0
- data/License.txt +30 -0
- data/README.txt +24 -0
- data/lib/bcmail-jdk14-139.jar +0 -0
- data/lib/bcprov-jdk14-139.jar +0 -0
- data/lib/jopenssl.jar +0 -0
- data/lib/jopenssl/version.rb +5 -0
- data/lib/openssl.rb +24 -0
- data/lib/openssl/bn.rb +33 -0
- data/lib/openssl/buffering.rb +239 -0
- data/lib/openssl/cipher.rb +56 -0
- data/lib/openssl/digest.rb +46 -0
- data/lib/openssl/dummy.rb +34 -0
- data/lib/openssl/dummyssl.rb +13 -0
- data/lib/openssl/ssl.rb +135 -0
- data/lib/openssl/x509.rb +154 -0
- data/test/fixture/cacert.pem +23 -0
- data/test/fixture/cert_localhost.pem +19 -0
- data/test/fixture/common.pem +48 -0
- data/test/fixture/localhost_keypair.pem +18 -0
- data/test/fixture/max.pem +29 -0
- data/test/openssl/ssl_server.rb +99 -0
- data/test/openssl/test_asn1.rb +199 -0
- data/test/openssl/test_cipher.rb +196 -0
- data/test/openssl/test_digest.rb +88 -0
- data/test/openssl/test_hmac.rb +44 -0
- data/test/openssl/test_ns_spki.rb +69 -0
- data/test/openssl/test_pair.rb +149 -0
- data/test/openssl/test_pkcs7.rb +159 -0
- data/test/openssl/test_pkey_rsa.rb +49 -0
- data/test/openssl/test_ssl.rb +413 -0
- data/test/openssl/test_x509cert.rb +236 -0
- data/test/openssl/test_x509crl.rb +234 -0
- data/test/openssl/test_x509ext.rb +95 -0
- data/test/openssl/test_x509name.rb +265 -0
- data/test/openssl/test_x509req.rb +178 -0
- data/test/openssl/test_x509store.rb +245 -0
- data/test/openssl/utils.rb +135 -0
- data/test/pkcs7_mime_enveloped.message +19 -0
- data/test/pkcs7_mime_signed.message +30 -0
- data/test/pkcs7_multipart_signed.message +45 -0
- data/test/ref/a.out +0 -0
- data/test/ref/compile.rb +8 -0
- data/test/ref/pkcs1 +0 -0
- data/test/ref/pkcs1.c +21 -0
- data/test/test_cipher.rb +90 -0
- data/test/test_integration.rb +100 -0
- data/test/test_java.rb +98 -0
- data/test/test_java_attribute.rb +25 -0
- data/test/test_java_bio.rb +42 -0
- data/test/test_java_mime.rb +173 -0
- data/test/test_java_pkcs7.rb +769 -0
- data/test/test_java_smime.rb +177 -0
- data/test/test_openssl.rb +34 -0
- data/test/test_openssl_x509.rb +34 -0
- data/test/test_pkey.rb +46 -0
- data/test/ut_eof.rb +128 -0
- metadata +124 -0
data/test/ref/a.out
ADDED
|
File without changes
|
data/test/ref/compile.rb
ADDED
data/test/ref/pkcs1
ADDED
|
Binary file
|
data/test/ref/pkcs1.c
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
#include <openssl/pkcs7.h>
|
|
3
|
+
|
|
4
|
+
void print_pkcs7(PKCS7* p7) {
|
|
5
|
+
printf(" | asn1 : %s\n", p7->asn1);
|
|
6
|
+
printf(" | len : %d\n", p7->length);
|
|
7
|
+
printf(" | state : %d\n", p7->state);
|
|
8
|
+
printf(" | detached : %d\n", p7->detached);
|
|
9
|
+
printf(" | type : %d\n", OBJ_nid2obj(p7->type));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
int main(int argc, char** argv) {
|
|
13
|
+
PKCS7* p7;
|
|
14
|
+
p7 = PKCS7_new();
|
|
15
|
+
|
|
16
|
+
printf("--before:\n");
|
|
17
|
+
print_pkcs7(p7);
|
|
18
|
+
|
|
19
|
+
PKCS7_free(p7);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
data/test/test_cipher.rb
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
if defined?(JRUBY_VERSION)
|
|
2
|
+
require "java"
|
|
3
|
+
base = File.dirname(__FILE__)
|
|
4
|
+
$CLASSPATH << File.join(base, '..', 'pkg', 'classes')
|
|
5
|
+
$CLASSPATH << File.join(base, '..', 'lib', 'bcprov-jdk14-139.jar')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
begin
|
|
9
|
+
require "openssl"
|
|
10
|
+
rescue LoadError
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require "test/unit"
|
|
14
|
+
|
|
15
|
+
class TestCipher < Test::Unit::TestCase
|
|
16
|
+
def test_encrypt_takes_parameter
|
|
17
|
+
enc = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC')
|
|
18
|
+
enc.encrypt("123")
|
|
19
|
+
data = enc.update("password")
|
|
20
|
+
data << enc.final
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
IV_TEMPLATE = "aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjj"
|
|
24
|
+
KEY_TEMPLATE = "aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjj"
|
|
25
|
+
|
|
26
|
+
# JRUBY-1692
|
|
27
|
+
def test_repeated_des
|
|
28
|
+
do_repeated_test(
|
|
29
|
+
"des-ede3-cbc",
|
|
30
|
+
"foobarbazboofarf",
|
|
31
|
+
":\022Q\211ex\370\332\374\274\214\356\301\260V\025",
|
|
32
|
+
"B\242\3531\003\362\3759\363s\203\374\240\030|\230"
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# JRUBY-1692
|
|
37
|
+
def test_repeated_aes
|
|
38
|
+
do_repeated_test(
|
|
39
|
+
"aes-128-cbc",
|
|
40
|
+
"foobarbazboofarf",
|
|
41
|
+
"\342\260Y\344\306\227\004^\272|/\323<\016,\226",
|
|
42
|
+
"jqO\305/\211\216\b\373\300\274\bw\213]\310"
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_rc2
|
|
47
|
+
do_repeated_test(
|
|
48
|
+
"RC2",
|
|
49
|
+
"foobarbazboofarf",
|
|
50
|
+
"\x18imZ\x9Ed\x15\xF3\xD6\xE6M\xCDf\xAA\xD3\xFE",
|
|
51
|
+
"\xEF\xF7\x16\x06\x93)-##\xB2~\xAD,\xAD\x82\xF5"
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
def do_repeated_test(algo, string, enc1, enc2)
|
|
57
|
+
do_repeated_encrypt_test(algo, string, enc1, enc2)
|
|
58
|
+
do_repeated_decrypt_test(algo, string, enc1, enc2)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def do_repeated_encrypt_test(algo, string, result1, result2)
|
|
62
|
+
cipher = OpenSSL::Cipher::Cipher.new(algo)
|
|
63
|
+
cipher.encrypt
|
|
64
|
+
|
|
65
|
+
cipher.padding = 0
|
|
66
|
+
cipher.iv = IV_TEMPLATE[0, cipher.iv_len]
|
|
67
|
+
cipher.key = KEY_TEMPLATE[0, cipher.key_len]
|
|
68
|
+
|
|
69
|
+
assert_equal result1, cipher.update(string)
|
|
70
|
+
cipher.final
|
|
71
|
+
|
|
72
|
+
assert_equal result2, cipher.update(string)
|
|
73
|
+
cipher.final
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def do_repeated_decrypt_test(algo, result, string1, string2)
|
|
77
|
+
cipher = OpenSSL::Cipher::Cipher.new(algo)
|
|
78
|
+
cipher.decrypt
|
|
79
|
+
|
|
80
|
+
cipher.padding = 0
|
|
81
|
+
cipher.iv = IV_TEMPLATE[0, cipher.iv_len]
|
|
82
|
+
cipher.key = KEY_TEMPLATE[0, cipher.key_len]
|
|
83
|
+
|
|
84
|
+
assert_equal result, cipher.update(string1)
|
|
85
|
+
cipher.final
|
|
86
|
+
|
|
87
|
+
assert_equal result, cipher.update(string2)
|
|
88
|
+
cipher.final
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
if defined?(JRUBY_VERSION)
|
|
2
|
+
require "java"
|
|
3
|
+
base = File.join(File.dirname(__FILE__), '..')
|
|
4
|
+
$CLASSPATH << File.join(base, 'pkg', 'classes')
|
|
5
|
+
$CLASSPATH << File.join(base, 'lib', 'bcprov-jdk14-139.jar')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
begin
|
|
9
|
+
require "openssl"
|
|
10
|
+
rescue LoadError
|
|
11
|
+
end
|
|
12
|
+
require "test/unit"
|
|
13
|
+
require 'net/https'
|
|
14
|
+
|
|
15
|
+
class TestIntegration < Test::Unit::TestCase
|
|
16
|
+
# JRUBY-2471
|
|
17
|
+
def _test_drb
|
|
18
|
+
config = {
|
|
19
|
+
:SSLVerifyMode => OpenSSL::SSL::VERIFY_PEER,
|
|
20
|
+
:SSLCACertificateFile => File.join(File.dirname(__FILE__), "fixture", "cacert.pem"),
|
|
21
|
+
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(File.join(File.dirname(__FILE__), "fixture", "localhost_keypair.pem"))),
|
|
22
|
+
:SSLCertificate => OpenSSL::X509::Certificate.new(File.read(File.join(File.dirname(__FILE__), "fixture", "cert_localhost.pem"))),
|
|
23
|
+
}
|
|
24
|
+
p config
|
|
25
|
+
DRb.start_service(nil, nil, config)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# JRUBY-2913
|
|
29
|
+
# Warning - this test actually uses the internet connection.
|
|
30
|
+
# If there is no connection, it will fail.
|
|
31
|
+
def test_ca_path_name
|
|
32
|
+
uri = URI.parse('https://www.paypal.com')
|
|
33
|
+
|
|
34
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
35
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
36
|
+
http.ca_path = "./"
|
|
37
|
+
http.use_ssl = true
|
|
38
|
+
|
|
39
|
+
response = http.start do |s|
|
|
40
|
+
assert s.get(uri.request_uri).length > 0
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# JRUBY-2178 and JRUBY-1307
|
|
45
|
+
# Warning - this test actually uses the internet connection.
|
|
46
|
+
# If there is no connection, it will fail.
|
|
47
|
+
# This test generally throws an exception
|
|
48
|
+
# about illegal_parameter when
|
|
49
|
+
# it can't use the cipher string correctly
|
|
50
|
+
def test_cipher_strings
|
|
51
|
+
socket = TCPSocket.new('rubyforge.org', 443)
|
|
52
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
|
53
|
+
ctx.cert_store = OpenSSL::X509::Store.new
|
|
54
|
+
ctx.verify_mode = 0
|
|
55
|
+
ctx.cert = nil
|
|
56
|
+
ctx.key = nil
|
|
57
|
+
ctx.client_ca = nil
|
|
58
|
+
ctx.ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"
|
|
59
|
+
|
|
60
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
|
61
|
+
ssl_socket.connect
|
|
62
|
+
ssl_socket.close
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# JRUBY-1194
|
|
66
|
+
def test_des_encryption
|
|
67
|
+
iv = "IVIVIVIV"
|
|
68
|
+
key = "KEYKEYKE"
|
|
69
|
+
alg = "des"
|
|
70
|
+
str = "string abc foo bar baxz"
|
|
71
|
+
|
|
72
|
+
cipher = OpenSSL::Cipher::Cipher.new(alg)
|
|
73
|
+
cipher.encrypt(key, iv)
|
|
74
|
+
cipher.padding = 32
|
|
75
|
+
cipher.key = key
|
|
76
|
+
cipher.iv = iv
|
|
77
|
+
|
|
78
|
+
encrypted = cipher.update(str)
|
|
79
|
+
encrypted << cipher.final
|
|
80
|
+
|
|
81
|
+
assert_equal "\253\305\306\372;\374\235\302\357/\006\360\355XO\232\312S\356* #\227\217", encrypted
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def _test_perf_of_nil
|
|
85
|
+
# require 'net/https'
|
|
86
|
+
# require 'benchmark'
|
|
87
|
+
|
|
88
|
+
# def request(data)
|
|
89
|
+
# connection = Net::HTTP.new("www.google.com", 443)
|
|
90
|
+
# connection.use_ssl = true
|
|
91
|
+
# connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
92
|
+
# connection.start do |connection|
|
|
93
|
+
# connection.request_post("/tbproxy/spell?lang=en", data, { 'User-Agent' => "Test", 'Accept' => 'text/xml' })
|
|
94
|
+
# end
|
|
95
|
+
# end
|
|
96
|
+
|
|
97
|
+
# puts "is not: #{Benchmark.measure { request("") }.to_s.chomp}"
|
|
98
|
+
# puts "is nil: #{Benchmark.measure { request(nil) }.to_s.chomp}"
|
|
99
|
+
end
|
|
100
|
+
end
|
data/test/test_java.rb
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'mocha', 'lib')
|
|
2
|
+
|
|
3
|
+
require "test/unit"
|
|
4
|
+
require 'mocha'
|
|
5
|
+
|
|
6
|
+
if defined?(JRUBY_VERSION)
|
|
7
|
+
require "java"
|
|
8
|
+
$CLASSPATH << 'pkg/classes'
|
|
9
|
+
$CLASSPATH << 'lib/bcprov-jdk14-139.jar'
|
|
10
|
+
|
|
11
|
+
module PKCS7Test
|
|
12
|
+
module ASN1
|
|
13
|
+
OctetString = org.bouncycastle.asn1.DEROctetString
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
PKCS7 = org.jruby.ext.openssl.impl.PKCS7 unless defined?(PKCS7)
|
|
17
|
+
Attribute = org.jruby.ext.openssl.impl.Attribute unless defined?(Attribute)
|
|
18
|
+
Digest = org.jruby.ext.openssl.impl.Digest unless defined?(Digest)
|
|
19
|
+
EncContent = org.jruby.ext.openssl.impl.EncContent unless defined?(EncContent)
|
|
20
|
+
Encrypt = org.jruby.ext.openssl.impl.Encrypt unless defined?(Encrypt)
|
|
21
|
+
Envelope = org.jruby.ext.openssl.impl.Envelope unless defined?(Envelope)
|
|
22
|
+
IssuerAndSerial = org.jruby.ext.openssl.impl.IssuerAndSerial unless defined?(IssuerAndSerial)
|
|
23
|
+
RecipInfo = org.jruby.ext.openssl.impl.RecipInfo unless defined?(RecipInfo)
|
|
24
|
+
SignEnvelope = org.jruby.ext.openssl.impl.SignEnvelope unless defined?(SignEnvelope)
|
|
25
|
+
Signed = org.jruby.ext.openssl.impl.Signed unless defined?(Signed)
|
|
26
|
+
SMIME = org.jruby.ext.openssl.impl.SMIME unless defined?(SMIME)
|
|
27
|
+
Mime = org.jruby.ext.openssl.impl.Mime unless defined?(Mime)
|
|
28
|
+
MimeHeader = org.jruby.ext.openssl.impl.MimeHeader unless defined?(MimeHeader)
|
|
29
|
+
MimeParam = org.jruby.ext.openssl.impl.MimeParam unless defined?(MimeParam)
|
|
30
|
+
BIO = org.jruby.ext.openssl.impl.BIO unless defined?(BIO)
|
|
31
|
+
PKCS7Exception = org.jruby.ext.openssl.impl.PKCS7Exception unless defined?(PKCS7Exception)
|
|
32
|
+
ASN1Registry = org.jruby.ext.openssl.impl.ASN1Registry unless defined?(ASN1Registry)
|
|
33
|
+
AlgorithmIdentifier = org.bouncycastle.asn1.x509.AlgorithmIdentifier unless defined?(AlgorithmIdentifier)
|
|
34
|
+
SignerInfoWithPkey = org.jruby.ext.openssl.impl.SignerInfoWithPkey unless defined?(SignerInfoWithPkey)
|
|
35
|
+
IssuerAndSerialNumber = org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber unless defined?(IssuerAndSerialNumber)
|
|
36
|
+
ASN1InputStream = org.bouncycastle.asn1.ASN1InputStream unless defined?(ASN1InputStream)
|
|
37
|
+
X509AuxCertificate = org.jruby.ext.openssl.x509store.X509AuxCertificate unless defined?(X509AuxCertificate)
|
|
38
|
+
|
|
39
|
+
ArrayList = java.util.ArrayList unless defined?(ArrayList)
|
|
40
|
+
CertificateFactory = java.security.cert.CertificateFactory unless defined?(CertificateFactory)
|
|
41
|
+
BCP = org.bouncycastle.jce.provider.BouncyCastleProvider unless defined?(BCP)
|
|
42
|
+
ByteArrayInputStream = java.io.ByteArrayInputStream unless defined?(ByteArrayInputStream)
|
|
43
|
+
BigInteger = java.math.BigInteger unless defined?(BigInteger)
|
|
44
|
+
Cipher = javax.crypto.Cipher unless defined?(Cipher)
|
|
45
|
+
|
|
46
|
+
DERInteger = org.bouncycastle.asn1.DERInteger
|
|
47
|
+
DERSet = org.bouncycastle.asn1.DERSet
|
|
48
|
+
DEROctetString = org.bouncycastle.asn1.DEROctetString
|
|
49
|
+
X509Name = org.bouncycastle.asn1.x509.X509Name
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
MimeEnvelopedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_mime_enveloped.message'))
|
|
53
|
+
MimeSignedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_mime_signed.message'))
|
|
54
|
+
MultipartSignedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7_multipart_signed.message'))
|
|
55
|
+
|
|
56
|
+
X509CertString = <<CERT
|
|
57
|
+
-----BEGIN CERTIFICATE-----
|
|
58
|
+
MIICijCCAXKgAwIBAgIBAjANBgkqhkiG9w0BAQUFADA9MRMwEQYKCZImiZPyLGQB
|
|
59
|
+
GRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQDDAJDQTAe
|
|
60
|
+
Fw0wODA3MDgxOTE1NDZaFw0wODA3MDgxOTQ1NDZaMEQxEzARBgoJkiaJk/IsZAEZ
|
|
61
|
+
FgNvcmcxGTAXBgoJkiaJk/IsZAEZFglydWJ5LWxhbmcxEjAQBgNVBAMMCWxvY2Fs
|
|
62
|
+
aG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAy8LEsNRApz7U/j5DoB4X
|
|
63
|
+
BgO9Z8Atv5y/OVQRp0ag8Tqo1YewsWijxEWB7JOATwpBN267U4T1nPZIxxEEO7n/
|
|
64
|
+
WNa2ws9JWsjah8ssEBFSxZqdXKSLf0N4Hi7/GQ/aYoaMCiQ8jA4jegK2FJmXM71u
|
|
65
|
+
Pe+jFN/peeBOpRfyXxRFOYcCAwEAAaMSMBAwDgYDVR0PAQH/BAQDAgWgMA0GCSqG
|
|
66
|
+
SIb3DQEBBQUAA4IBAQCU879BALJIM9avHiuZ3WTjDy0UYP3ZG5wtuSqBSnD1k8pr
|
|
67
|
+
hXfRaga7mDj6EQaGUovImb+KrRi6mZc+zsx4rTxwBNJT9U8yiW2eYxmgcT9/qKrD
|
|
68
|
+
/1nz+e8NeUCCDY5UTUHGszZw5zLEDgDX2n3E/CDIZsoRSyq5vXq1jpfih/tSWanj
|
|
69
|
+
Y9uP/o8Dc7ZcRJOAX7NPu1bbZcbxEbZ8sMe5wZ5HNiAR6gnOrjz2Yyazb//PSskE
|
|
70
|
+
4flt/2h4pzGA0/ZHcnDjcoLdiLtInsqPOlVDLgqd/XqRYWtj84N4gw1iS9cHyrIZ
|
|
71
|
+
dqbS54IKvzElD+R0QVS2z6TIGJSpuSBnZ4yfuNuq
|
|
72
|
+
-----END CERTIFICATE-----
|
|
73
|
+
CERT
|
|
74
|
+
|
|
75
|
+
X509CRLString = <<CRL
|
|
76
|
+
----BEGIN X509 CRL-----
|
|
77
|
+
MIIBlTB/AgEBMA0GCSqGSIb3DQEBBQUAMD0xEzARBgoJkiaJk/IsZAEZFgNvcmcx
|
|
78
|
+
GTAXBgoJkiaJk/IsZAEZFglydWJ5LWxhbmcxCzAJBgNVBAMMAkNBFw0wODA3MTgx
|
|
79
|
+
NzQxMjhaFw0wODA3MTgxODA4MDhaoA4wDDAKBgNVHRQEAwIBATANBgkqhkiG9w0B
|
|
80
|
+
AQUFAAOCAQEASJaj1keN+tMmsF3QmjH2RhbW/9rZAl4gjv+uQQqrcS2ByfkXLU1d
|
|
81
|
+
l/8rCHeT/XMoeU6xhQNHPP3uZBwfuuETcp65BMBcZFOUhUR0U5AaGhvSDS/+6EsP
|
|
82
|
+
zFdQgAagmThFdN5ei9guTLqWwN0ZyqiaHyevFJuk+L9qbKavaSeKqfJbU7Sj/Z3J
|
|
83
|
+
WLKoixvyj3N6W7evygH80lTvjZugmxJ1/AjICVSYr1hpHHd6EWq0b0YFrGFmg27R
|
|
84
|
+
WmsAXd0QV5UChfAJ2+Cz5U1bPszvIJGrzfAIoLxHv5rI5rseQzqZdPaFSe4Oehln
|
|
85
|
+
9qEYmsK3PS6bYoQol0cgj97Ep4olS8CulA==
|
|
86
|
+
-----END X509 CRL-----
|
|
87
|
+
CRL
|
|
88
|
+
|
|
89
|
+
X509Cert = X509AuxCertificate.new(CertificateFactory.getInstance("X.509",BCP.new).generateCertificate(ByteArrayInputStream.new(X509CertString.to_java_bytes)))
|
|
90
|
+
X509CRL = CertificateFactory.getInstance("X.509",BCP.new).generateCRL(ByteArrayInputStream.new(X509CRLString.to_java_bytes))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
require File.join(File.dirname(__FILE__), 'test_java_attribute')
|
|
94
|
+
require File.join(File.dirname(__FILE__), 'test_java_bio')
|
|
95
|
+
require File.join(File.dirname(__FILE__), 'test_java_mime')
|
|
96
|
+
require File.join(File.dirname(__FILE__), 'test_java_pkcs7')
|
|
97
|
+
require File.join(File.dirname(__FILE__), 'test_java_smime')
|
|
98
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module PKCS7Test
|
|
2
|
+
class TestJavaAttribute < Test::Unit::TestCase
|
|
3
|
+
def test_attributes
|
|
4
|
+
val = ASN1::OctetString.new("foo".to_java_bytes)
|
|
5
|
+
val2 = ASN1::OctetString.new("bar".to_java_bytes)
|
|
6
|
+
attr = Attribute.create(123, 444, val)
|
|
7
|
+
assert_raises NoMethodError do
|
|
8
|
+
attr.type = 12
|
|
9
|
+
end
|
|
10
|
+
assert_raises NoMethodError do
|
|
11
|
+
attr.value = val2
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
assert_equal 123, attr.type
|
|
15
|
+
assert_equal val, attr.set.get(0)
|
|
16
|
+
|
|
17
|
+
attr2 = Attribute.create(123, 444, val)
|
|
18
|
+
|
|
19
|
+
assert_equal attr, attr2
|
|
20
|
+
|
|
21
|
+
assert_not_equal Attribute.create(124, 444, val), attr
|
|
22
|
+
assert_not_equal Attribute.create(123, 444, val2), attr
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module PKCS7Test
|
|
2
|
+
class TestJavaBIO < Test::Unit::TestCase
|
|
3
|
+
def test_string_bio_simple
|
|
4
|
+
bio = BIO::from_string("abc")
|
|
5
|
+
arr = Java::byte[20].new
|
|
6
|
+
read = bio.gets(arr, 10)
|
|
7
|
+
assert_equal 3, read
|
|
8
|
+
assert_equal "abc".to_java_bytes.to_a, arr.to_a[0...read]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_string_bio_simple_with_newline
|
|
12
|
+
bio = BIO::from_string("abc\n")
|
|
13
|
+
arr = Java::byte[20].new
|
|
14
|
+
read = bio.gets(arr, 10)
|
|
15
|
+
assert_equal 4, read
|
|
16
|
+
assert_equal "abc\n".to_java_bytes.to_a, arr.to_a[0...read]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_string_bio_simple_with_newline_and_more_data
|
|
20
|
+
bio = BIO::from_string("abc\nfoo\n\nbar")
|
|
21
|
+
arr = Java::byte[20].new
|
|
22
|
+
read = bio.gets(arr, 10)
|
|
23
|
+
assert_equal 4, read
|
|
24
|
+
assert_equal "abc\n".to_java_bytes.to_a, arr.to_a[0...read]
|
|
25
|
+
|
|
26
|
+
read = bio.gets(arr, 10)
|
|
27
|
+
assert_equal 4, read
|
|
28
|
+
assert_equal "foo\n".to_java_bytes.to_a, arr.to_a[0...read]
|
|
29
|
+
|
|
30
|
+
read = bio.gets(arr, 10)
|
|
31
|
+
assert_equal 1, read
|
|
32
|
+
assert_equal "\n".to_java_bytes.to_a, arr.to_a[0...read]
|
|
33
|
+
|
|
34
|
+
read = bio.gets(arr, 10)
|
|
35
|
+
assert_equal 3, read
|
|
36
|
+
assert_equal "bar".to_java_bytes.to_a, arr.to_a[0...read]
|
|
37
|
+
|
|
38
|
+
read = bio.gets(arr, 10)
|
|
39
|
+
assert_equal 0, read
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
module PKCS7Test
|
|
2
|
+
class TestJavaMime < Test::Unit::TestCase
|
|
3
|
+
def test_find_header_returns_null_on_nonexisting_header
|
|
4
|
+
headers = []
|
|
5
|
+
assert_nil Mime::DEFAULT.find_header(headers, "foo")
|
|
6
|
+
|
|
7
|
+
headers = [MimeHeader.new("blarg", "bluff")]
|
|
8
|
+
assert_nil Mime::DEFAULT.find_header(headers, "foo")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_find_header_returns_the_header_with_the_same_name
|
|
12
|
+
hdr = MimeHeader.new("one", "two")
|
|
13
|
+
assert_equal hdr, Mime::DEFAULT.find_header([hdr], "one")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_find_param_returns_null_on_nonexisting_param
|
|
17
|
+
assert_nil Mime::DEFAULT.find_param(MimeHeader.new("one", "two", []), "foo")
|
|
18
|
+
assert_nil Mime::DEFAULT.find_param(MimeHeader.new("one", "two", [MimeParam.new("hi", "ho")]), "foo")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_find_param_returns_the_param_with_the_same_name
|
|
22
|
+
par = MimeParam.new("hox", "box")
|
|
23
|
+
hdr = MimeHeader.new("one", "two", [par])
|
|
24
|
+
assert_equal par, Mime::DEFAULT.find_param(hdr, "hox")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_simple_parse_headers
|
|
28
|
+
bio = BIO::from_string("Foo: bar")
|
|
29
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
30
|
+
assert_equal 1, result.size
|
|
31
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
32
|
+
assert_equal "foo", result[0].name
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_simple_parse_headers2
|
|
36
|
+
bio = BIO::from_string("Foo:bar")
|
|
37
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
38
|
+
assert_equal 1, result.size
|
|
39
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
40
|
+
assert_equal "foo", result[0].name
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_simple_parse_headers3
|
|
44
|
+
bio = BIO::from_string("Foo: bar")
|
|
45
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
46
|
+
assert_equal 1, result.size
|
|
47
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
48
|
+
assert_equal "foo", result[0].name
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_simple_parse_headers4
|
|
52
|
+
bio = BIO::from_string("Foo: bar\n")
|
|
53
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
54
|
+
assert_equal 1, result.size
|
|
55
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
56
|
+
assert_equal "foo", result[0].name
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_simple_parse_headers5
|
|
60
|
+
bio = BIO::from_string(" Foo : bar \n")
|
|
61
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
62
|
+
assert_equal 1, result.size
|
|
63
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
64
|
+
assert_equal "foo", result[0].name
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_simple_parse_headers6
|
|
69
|
+
bio = BIO::from_string("Foo: bar;\n")
|
|
70
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
71
|
+
assert_equal 1, result.size
|
|
72
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
73
|
+
assert_equal "foo", result[0].name
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_simple_parse_headers7
|
|
77
|
+
bio = BIO::from_string("Foo: bar;\nFlurg: blarg")
|
|
78
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
79
|
+
assert_equal 2, result.size
|
|
80
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
81
|
+
assert_equal MimeHeader.new("Flurg", "blarg"), result[1]
|
|
82
|
+
assert_equal "foo", result[0].name
|
|
83
|
+
assert_equal "flurg", result[1].name
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_simple_parse_headers_quotes
|
|
87
|
+
bio = BIO::from_string("Foo: \"bar\"")
|
|
88
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
89
|
+
assert_equal 1, result.size
|
|
90
|
+
assert_equal MimeHeader.new("Foo", "bar"), result[0]
|
|
91
|
+
assert_equal "foo", result[0].name
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_simple_parse_headers_comment
|
|
95
|
+
bio = BIO::from_string("Foo: (this is the right thing)ba(and this is the wrong one)r")
|
|
96
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
97
|
+
assert_equal 1, result.size
|
|
98
|
+
assert_equal MimeHeader.new("Foo", "(this is the right thing)ba(and this is the wrong one)r"), result[0]
|
|
99
|
+
assert_equal "foo", result[0].name
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_parse_headers_with_param
|
|
103
|
+
bio = BIO::from_string("Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml")
|
|
104
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
105
|
+
assert_equal 1, result.size
|
|
106
|
+
header = result[0]
|
|
107
|
+
assert_equal "content-type", header.name
|
|
108
|
+
assert_equal "multipart/related", header.value
|
|
109
|
+
assert_equal [MimeParam.new("boundary","MIME_boundary"),
|
|
110
|
+
MimeParam.new("type","text/xml")], header.params.to_a
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_parse_headers_with_param_newline
|
|
114
|
+
bio = BIO::from_string("Content-Type: Multipart/Related\n boundary=MIME_boundary; type=text/xml")
|
|
115
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
116
|
+
assert_equal 1, result.size
|
|
117
|
+
header = result[0]
|
|
118
|
+
assert_equal "content-type", header.name
|
|
119
|
+
assert_equal "multipart/related", header.value
|
|
120
|
+
assert_equal [MimeParam.new("boundary","MIME_boundary"),
|
|
121
|
+
MimeParam.new("type","text/xml")], header.params.to_a
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_parse_headers_with_param_newline_and_semicolon
|
|
125
|
+
bio = BIO::from_string("Content-Type: Multipart/Related;\n boundary=MIME_boundary;\n Type=text/xml")
|
|
126
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
127
|
+
assert_equal 1, result.size
|
|
128
|
+
header = result[0]
|
|
129
|
+
assert_equal "content-type", header.name
|
|
130
|
+
assert_equal "multipart/related", header.value
|
|
131
|
+
assert_equal [MimeParam.new("boundary","MIME_boundary"),
|
|
132
|
+
MimeParam.new("type","text/xml")], header.params.to_a
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def test_advanced_mime_message
|
|
136
|
+
bio = BIO::from_string(MultipartSignedString)
|
|
137
|
+
result = Mime::DEFAULT.parse_headers(bio)
|
|
138
|
+
|
|
139
|
+
assert_equal "mime-version", result[0].name
|
|
140
|
+
assert_equal "1.0", result[0].value
|
|
141
|
+
|
|
142
|
+
assert_equal "to", result[1].name
|
|
143
|
+
assert_equal "user2@examples.com", result[1].value
|
|
144
|
+
|
|
145
|
+
assert_equal "from", result[2].name
|
|
146
|
+
assert_equal "alicedss@examples.com", result[2].value
|
|
147
|
+
|
|
148
|
+
assert_equal "subject", result[3].name
|
|
149
|
+
assert_equal "example 4.8", result[3].value
|
|
150
|
+
|
|
151
|
+
assert_equal "message-id", result[4].name
|
|
152
|
+
assert_equal "<020906002550300.249@examples.com>", result[4].value
|
|
153
|
+
|
|
154
|
+
assert_equal "date", result[5].name
|
|
155
|
+
assert_equal "fri, 06 sep 2002 00:25:21 -0300", result[5].value
|
|
156
|
+
|
|
157
|
+
assert_equal "content-type", result[6].name
|
|
158
|
+
assert_equal "multipart/signed", result[6].value
|
|
159
|
+
|
|
160
|
+
assert_equal "micalg", result[6].params[0].param_name
|
|
161
|
+
assert_equal "SHA1", result[6].params[0].param_value
|
|
162
|
+
|
|
163
|
+
assert_equal "boundary", result[6].params[1].param_name
|
|
164
|
+
assert_equal "----=_NextBoundry____Fri,_06_Sep_2002_00:25:21", result[6].params[1].param_value
|
|
165
|
+
|
|
166
|
+
assert_equal "protocol", result[6].params[2].param_name
|
|
167
|
+
assert_equal "application/pkcs7-signature", result[6].params[2].param_value
|
|
168
|
+
|
|
169
|
+
assert_equal 3, result[6].params.length
|
|
170
|
+
assert_equal 7, result.length
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|