jruby-openssl-maven 0.7.4.1
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 +171 -0
- data/License.txt +30 -0
- data/Manifest.txt +115 -0
- data/README.txt +13 -0
- data/Rakefile +79 -0
- data/lib/jopenssl.jar +0 -0
- data/lib/jopenssl/version.rb +5 -0
- data/lib/openssl.rb +76 -0
- data/lib/openssl/bn.rb +35 -0
- data/lib/openssl/buffering.rb +239 -0
- data/lib/openssl/cipher.rb +65 -0
- data/lib/openssl/config.rb +316 -0
- data/lib/openssl/digest.rb +61 -0
- data/lib/openssl/dummy.rb +33 -0
- data/lib/openssl/dummyssl.rb +14 -0
- data/lib/openssl/pkcs7.rb +25 -0
- data/lib/openssl/ssl.rb +179 -0
- data/lib/openssl/x509.rb +154 -0
- data/test/cert_with_ec_pk.cer +27 -0
- data/test/fixture/ca-bundle.crt +2794 -0
- data/test/fixture/ca_path/72fa7371.0 +19 -0
- data/test/fixture/ca_path/verisign.pem +19 -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/imaps/cacert.pem +60 -0
- data/test/fixture/imaps/server.crt +61 -0
- data/test/fixture/imaps/server.key +15 -0
- data/test/fixture/key_then_cert.pem +34 -0
- data/test/fixture/keypair.pem +27 -0
- data/test/fixture/localhost_keypair.pem +18 -0
- data/test/fixture/max.pem +29 -0
- data/test/fixture/purpose/b70a5bc1.0 +24 -0
- data/test/fixture/purpose/ca/PASSWD_OF_CA_KEY_IS_1234 +0 -0
- data/test/fixture/purpose/ca/ca_config.rb +37 -0
- data/test/fixture/purpose/ca/cacert.pem +24 -0
- data/test/fixture/purpose/ca/newcerts/2_cert.pem +19 -0
- data/test/fixture/purpose/ca/newcerts/3_cert.pem +19 -0
- data/test/fixture/purpose/ca/private/cakeypair.pem +30 -0
- data/test/fixture/purpose/ca/serial +1 -0
- data/test/fixture/purpose/cacert.pem +24 -0
- data/test/fixture/purpose/scripts/gen_cert.rb +127 -0
- data/test/fixture/purpose/scripts/gen_csr.rb +50 -0
- data/test/fixture/purpose/scripts/init_ca.rb +66 -0
- data/test/fixture/purpose/sslclient.pem +19 -0
- data/test/fixture/purpose/sslclient/csr.pem +10 -0
- data/test/fixture/purpose/sslclient/keypair.pem +15 -0
- data/test/fixture/purpose/sslclient/sslclient.pem +19 -0
- data/test/fixture/purpose/sslserver.pem +19 -0
- data/test/fixture/purpose/sslserver/csr.pem +10 -0
- data/test/fixture/purpose/sslserver/keypair.pem +15 -0
- data/test/fixture/purpose/sslserver/sslserver.pem +19 -0
- data/test/fixture/selfcert.pem +23 -0
- data/test/fixture/verisign.pem +19 -0
- data/test/fixture/verisign_c3.pem +14 -0
- data/test/java/pkcs7_mime_enveloped.message +19 -0
- data/test/java/pkcs7_mime_signed.message +30 -0
- data/test/java/pkcs7_multipart_signed.message +45 -0
- data/test/java/test_java_attribute.rb +25 -0
- data/test/java/test_java_bio.rb +42 -0
- data/test/java/test_java_mime.rb +173 -0
- data/test/java/test_java_pkcs7.rb +772 -0
- data/test/java/test_java_smime.rb +177 -0
- data/test/openssl/ssl_server.rb +99 -0
- data/test/openssl/test_asn1.rb +197 -0
- data/test/openssl/test_cipher.rb +193 -0
- data/test/openssl/test_config.rb +290 -0
- data/test/openssl/test_digest.rb +88 -0
- data/test/openssl/test_ec.rb +128 -0
- data/test/openssl/test_hmac.rb +46 -0
- data/test/openssl/test_ns_spki.rb +59 -0
- data/test/openssl/test_pair.rb +141 -0
- data/test/openssl/test_pkcs7.rb +489 -0
- data/test/openssl/test_pkey_rsa.rb +49 -0
- data/test/openssl/test_ssl.rb +1035 -0
- data/test/openssl/test_x509cert.rb +277 -0
- data/test/openssl/test_x509crl.rb +253 -0
- data/test/openssl/test_x509ext.rb +99 -0
- data/test/openssl/test_x509name.rb +290 -0
- data/test/openssl/test_x509req.rb +195 -0
- data/test/openssl/test_x509store.rb +246 -0
- data/test/openssl/utils.rb +144 -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_all.rb +1 -0
- data/test/test_certificate.rb +123 -0
- data/test/test_cipher.rb +197 -0
- data/test/test_imaps.rb +107 -0
- data/test/test_integration.rb +144 -0
- data/test/test_java.rb +98 -0
- data/test/test_openssl.rb +4 -0
- data/test/test_parse_certificate.rb +27 -0
- data/test/test_pkcs7.rb +40 -0
- data/test/test_pkey.rb +204 -0
- data/test/test_ssl.rb +97 -0
- data/test/test_x509store.rb +160 -0
- data/test/ut_eof.rb +128 -0
- metadata +161 -0
data/test/test_cipher.rb
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require "openssl"
|
|
3
|
+
rescue LoadError
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
require "test/unit"
|
|
7
|
+
|
|
8
|
+
class TestCipher < Test::Unit::TestCase
|
|
9
|
+
def test_keylen
|
|
10
|
+
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC')
|
|
11
|
+
# must be 24 but it returns 16 on JRE6 without unlimited jurisdiction
|
|
12
|
+
# policy. it returns 24 on JRE6 with the unlimited policy.
|
|
13
|
+
assert_equal(24, cipher.key_len)
|
|
14
|
+
end
|
|
15
|
+
|
|
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
|
+
def test_rc4
|
|
56
|
+
do_repeated_test(
|
|
57
|
+
"RC4",
|
|
58
|
+
"foobarbazboofarf",
|
|
59
|
+
"/i|\257\336U\354\331\212\304E\021\246\351\235\303",
|
|
60
|
+
"\020\367\370\316\212\262\266e\242\333\263\305z\340\204\200"
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_cast
|
|
65
|
+
do_repeated_test(
|
|
66
|
+
"cast-cbc",
|
|
67
|
+
"foobarbazboofarf",
|
|
68
|
+
"`m^\225\277\307\247m`{\f\020fl\ry",
|
|
69
|
+
"(\354\265\251,D\016\037\251\250V\207\367\214\276B"
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# JRUBY-4326 (1)
|
|
74
|
+
def test_cipher_unsupported_algorithm
|
|
75
|
+
assert_raise(OpenSSL::Cipher::CipherError) do
|
|
76
|
+
cipher = OpenSSL::Cipher::Cipher.new('aes-xxxxxxx')
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# JRUBY-4326 (2)
|
|
81
|
+
def test_cipher_unsupported_keylen
|
|
82
|
+
bits_128 = java.lang.String.new("0123456789ABCDEF").getBytes()
|
|
83
|
+
bits_256 = java.lang.String.new("0123456789ABCDEF0123456789ABCDEF").getBytes()
|
|
84
|
+
|
|
85
|
+
# AES128 is allowed
|
|
86
|
+
cipher = OpenSSL::Cipher::Cipher.new('aes-128-cbc')
|
|
87
|
+
cipher = OpenSSL::Cipher::Cipher.new('AES-128-CBC')
|
|
88
|
+
cipher = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding")
|
|
89
|
+
key_spec = javax.crypto.spec.SecretKeySpec.new(bits_128, "AES")
|
|
90
|
+
iv_spec = javax.crypto.spec.IvParameterSpec.new(bits_128)
|
|
91
|
+
assert_nothing_raised do
|
|
92
|
+
cipher.init(javax.crypto.Cipher::ENCRYPT_MODE, key_spec, iv_spec)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# check if AES256 is allowed or not in env policy
|
|
96
|
+
cipher = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding")
|
|
97
|
+
key_spec = javax.crypto.spec.SecretKeySpec.new(bits_256, "AES")
|
|
98
|
+
allowed = false
|
|
99
|
+
begin
|
|
100
|
+
cipher.init(javax.crypto.Cipher::ENCRYPT_MODE, key_spec, iv_spec)
|
|
101
|
+
allowed = true
|
|
102
|
+
rescue
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# jruby-openssl should raise as well?
|
|
106
|
+
# CRuby's openssl raises exception at initialization time.
|
|
107
|
+
# At this time, jruby-openssl raises later. TODO
|
|
108
|
+
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
|
109
|
+
cipher.encrypt
|
|
110
|
+
cipher.padding = 0
|
|
111
|
+
if allowed
|
|
112
|
+
assert_nothing_raised(OpenSSL::Cipher::CipherError) do
|
|
113
|
+
cipher.pkcs5_keyivgen("password")
|
|
114
|
+
end
|
|
115
|
+
else
|
|
116
|
+
assert_raise(OpenSSL::Cipher::CipherError) do
|
|
117
|
+
cipher.pkcs5_keyivgen("password")
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def test_iv_length_auto_trim_JRUBY_4012
|
|
123
|
+
e1 = e2 = nil
|
|
124
|
+
plain = 'data'
|
|
125
|
+
des = OpenSSL::Cipher::Cipher.new("des-ede3-cbc")
|
|
126
|
+
des.encrypt
|
|
127
|
+
des.key = '0123456789abcdef01234567890'
|
|
128
|
+
des.iv = "0" * (128/8) # too long for DES which is a 64 bit block
|
|
129
|
+
assert_nothing_raised do
|
|
130
|
+
e1 = des.update(plain) + des.final
|
|
131
|
+
end
|
|
132
|
+
des = OpenSSL::Cipher::Cipher.new("des-ede3-cbc")
|
|
133
|
+
des.encrypt
|
|
134
|
+
des.key = '0123456789abcdef01234567890'
|
|
135
|
+
des.iv = "0" * (64/8) # DES is a 64 bit block
|
|
136
|
+
e2 = des.update(plain) + des.final
|
|
137
|
+
assert_equal(e2, e1, "JRUBY-4012")
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# JRUBY-5125
|
|
141
|
+
def test_rc4_cipher_name
|
|
142
|
+
assert_equal("RC4", OpenSSL::Cipher::Cipher.new("rc4").name)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# JRUBY-5126
|
|
146
|
+
def test_stream_cipher_reset_should_be_ignored
|
|
147
|
+
c1 = "%E\x96\xDAZ\xEF\xB2$/\x9F\x02"
|
|
148
|
+
c2 = ">aV\xB0\xE1l\xF3oyL\x9B"
|
|
149
|
+
#
|
|
150
|
+
cipher = OpenSSL::Cipher::Cipher.new("RC4")
|
|
151
|
+
cipher.encrypt
|
|
152
|
+
cipher.key = "\0\1\2\3" * (128/8/4)
|
|
153
|
+
str = cipher.update('hello,world')
|
|
154
|
+
str += cipher.final
|
|
155
|
+
assert_equal(c1, str)
|
|
156
|
+
#
|
|
157
|
+
cipher.reset
|
|
158
|
+
cipher.iv = "\0" * 16
|
|
159
|
+
str = cipher.update('hello,world')
|
|
160
|
+
str += cipher.final
|
|
161
|
+
assert_equal(c2, str) # was equal to c1 before the fix
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
private
|
|
165
|
+
def do_repeated_test(algo, string, enc1, enc2)
|
|
166
|
+
do_repeated_encrypt_test(algo, string, enc1, enc2)
|
|
167
|
+
do_repeated_decrypt_test(algo, string, enc1, enc2)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def do_repeated_encrypt_test(algo, string, result1, result2)
|
|
171
|
+
cipher = OpenSSL::Cipher::Cipher.new(algo)
|
|
172
|
+
cipher.encrypt
|
|
173
|
+
|
|
174
|
+
cipher.padding = 0
|
|
175
|
+
cipher.iv = IV_TEMPLATE[0, cipher.iv_len]
|
|
176
|
+
cipher.key = KEY_TEMPLATE[0, cipher.key_len]
|
|
177
|
+
|
|
178
|
+
assert_equal result1, cipher.update(string)
|
|
179
|
+
assert_equal "", cipher.final
|
|
180
|
+
|
|
181
|
+
assert_equal result2, cipher.update(string) + cipher.final
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def do_repeated_decrypt_test(algo, result, string1, string2)
|
|
185
|
+
cipher = OpenSSL::Cipher::Cipher.new(algo)
|
|
186
|
+
cipher.decrypt
|
|
187
|
+
|
|
188
|
+
cipher.padding = 0
|
|
189
|
+
cipher.iv = IV_TEMPLATE[0, cipher.iv_len]
|
|
190
|
+
cipher.key = KEY_TEMPLATE[0, cipher.key_len]
|
|
191
|
+
|
|
192
|
+
assert_equal result, cipher.update(string1)
|
|
193
|
+
assert_equal "", cipher.final
|
|
194
|
+
|
|
195
|
+
assert_equal result, cipher.update(string2) + cipher.final
|
|
196
|
+
end
|
|
197
|
+
end
|
data/test/test_imaps.rb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require "net/imap"
|
|
2
|
+
require "test/unit"
|
|
3
|
+
|
|
4
|
+
# This testcase is made for 1.8 based on test_imap.rb in CRuby 1.9
|
|
5
|
+
class IMAPTest < Test::Unit::TestCase
|
|
6
|
+
CA_FILE = File.expand_path("fixture/imaps/cacert.pem", File.dirname(__FILE__))
|
|
7
|
+
SERVER_KEY = File.expand_path("fixture/imaps/server.key", File.dirname(__FILE__))
|
|
8
|
+
SERVER_CERT = File.expand_path("fixture/imaps/server.crt", File.dirname(__FILE__))
|
|
9
|
+
|
|
10
|
+
SERVER_ADDR = "127.0.0.1"
|
|
11
|
+
|
|
12
|
+
def setup
|
|
13
|
+
@do_not_reverse_lookup = Socket.do_not_reverse_lookup
|
|
14
|
+
Socket.do_not_reverse_lookup = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def teardown
|
|
18
|
+
Socket.do_not_reverse_lookup = @do_not_reverse_lookup
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_imaps_unknown_ca
|
|
22
|
+
assert_raise(OpenSSL::SSL::SSLError) do
|
|
23
|
+
imaps_test do |port|
|
|
24
|
+
Net::IMAP.new("localhost", port, true, nil, true)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_imaps_with_ca_file
|
|
30
|
+
assert_nothing_raised do
|
|
31
|
+
imaps_test do |port|
|
|
32
|
+
Net::IMAP.new("localhost", port, true, CA_FILE, true)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_imaps_login
|
|
38
|
+
assert_raises(Net::IMAP::ByeResponseError) do
|
|
39
|
+
imaps_test do |port|
|
|
40
|
+
imaps = Net::IMAP.new("localhost", port, true, CA_FILE, true)
|
|
41
|
+
imaps.login('foo@bar.com', 'wrong password')
|
|
42
|
+
imaps
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_imaps_verify_none
|
|
48
|
+
assert_nothing_raised do
|
|
49
|
+
imaps_test do |port|
|
|
50
|
+
Net::IMAP.new(SERVER_ADDR, port, true, nil, false)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_imaps_post_connection_check
|
|
56
|
+
assert_raise(OpenSSL::SSL::SSLError) do
|
|
57
|
+
imaps_test do |port|
|
|
58
|
+
# SERVER_ADDR is different from the hostname in the certificate,
|
|
59
|
+
# so the following code should raise a SSLError.
|
|
60
|
+
Net::IMAP.new(SERVER_ADDR, port, true, CA_FILE, true)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def imaps_test
|
|
68
|
+
server = create_tcp_server
|
|
69
|
+
port = server.addr[1]
|
|
70
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
|
71
|
+
ctx.ca_file = CA_FILE
|
|
72
|
+
ctx.key = OpenSSL::PKey::RSA.new(File.read(SERVER_KEY))
|
|
73
|
+
ctx.cert = OpenSSL::X509::Certificate.new(File.read(SERVER_CERT))
|
|
74
|
+
ssl_server = OpenSSL::SSL::SSLServer.new(server, ctx)
|
|
75
|
+
Thread.start do
|
|
76
|
+
begin
|
|
77
|
+
sock = ssl_server.accept
|
|
78
|
+
begin
|
|
79
|
+
sock.print("* OK test server\r\n")
|
|
80
|
+
sock.read(10) # emulates half-read for JRUBY-5200
|
|
81
|
+
sock.print("* BYE terminating connection\r\n")
|
|
82
|
+
sock.print("RUBY0001 OK LOGOUT completed\r\n")
|
|
83
|
+
sock.gets
|
|
84
|
+
ensure
|
|
85
|
+
sock.close
|
|
86
|
+
end
|
|
87
|
+
rescue
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
begin
|
|
91
|
+
begin
|
|
92
|
+
imap = yield(port)
|
|
93
|
+
imap.logout if !imap.disconnected?
|
|
94
|
+
ensure
|
|
95
|
+
imap.disconnect if imap && !imap.disconnected?
|
|
96
|
+
end
|
|
97
|
+
rescue IOError
|
|
98
|
+
# ignore
|
|
99
|
+
ensure
|
|
100
|
+
ssl_server.close
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def create_tcp_server
|
|
105
|
+
return TCPServer.new(SERVER_ADDR, 0)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require "openssl"
|
|
3
|
+
rescue LoadError
|
|
4
|
+
end
|
|
5
|
+
require "test/unit"
|
|
6
|
+
require 'net/https'
|
|
7
|
+
|
|
8
|
+
class TestIntegration < Test::Unit::TestCase
|
|
9
|
+
def path(file)
|
|
10
|
+
File.expand_path(file, File.dirname(__FILE__))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# JRUBY-2471
|
|
14
|
+
def _test_drb
|
|
15
|
+
config = {
|
|
16
|
+
:SSLVerifyMode => OpenSSL::SSL::VERIFY_PEER,
|
|
17
|
+
:SSLCACertificateFile => File.join(File.dirname(__FILE__), "fixture", "cacert.pem"),
|
|
18
|
+
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(File.join(File.dirname(__FILE__), "fixture", "localhost_keypair.pem"))),
|
|
19
|
+
:SSLCertificate => OpenSSL::X509::Certificate.new(File.read(File.join(File.dirname(__FILE__), "fixture", "cert_localhost.pem"))),
|
|
20
|
+
}
|
|
21
|
+
p config
|
|
22
|
+
DRb.start_service(nil, nil, config)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# JRUBY-2913
|
|
26
|
+
# Warning - this test actually uses the internet connection.
|
|
27
|
+
# If there is no connection, it will fail.
|
|
28
|
+
def test_ca_path_name
|
|
29
|
+
uri = URI.parse('https://www.amazon.com')
|
|
30
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
32
|
+
http.ca_path = path("fixture/ca_path/")
|
|
33
|
+
http.use_ssl = true
|
|
34
|
+
response = http.start do |s|
|
|
35
|
+
assert s.get(uri.request_uri).length > 0
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Warning - this test actually uses the internet connection.
|
|
40
|
+
# If there is no connection, it will fail.
|
|
41
|
+
def test_ssl_verify
|
|
42
|
+
uri = URI.parse('https://www.amazon.com/')
|
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
44
|
+
http.use_ssl = true
|
|
45
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
46
|
+
# right trust anchor for www.amazon.com
|
|
47
|
+
http.ca_file = path('fixture/verisign.pem')
|
|
48
|
+
response = http.start do |s|
|
|
49
|
+
assert s.get(uri.request_uri).length > 0
|
|
50
|
+
end
|
|
51
|
+
# wrong trust anchor for www.amazon.com
|
|
52
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
53
|
+
http.use_ssl = true
|
|
54
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
55
|
+
http.ca_file = path('fixture/verisign_c3.pem')
|
|
56
|
+
assert_raise(OpenSSL::SSL::SSLError) do
|
|
57
|
+
# it must cause SSLError for verification failure.
|
|
58
|
+
response = http.start do |s|
|
|
59
|
+
s.get(uri.request_uri)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
# round trip
|
|
63
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
64
|
+
http.use_ssl = true
|
|
65
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
66
|
+
http.ca_file = path('fixture/verisign.pem')
|
|
67
|
+
response = http.start do |s|
|
|
68
|
+
assert s.get(uri.request_uri).length > 0
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Warning - this test actually uses the internet connection.
|
|
73
|
+
# If there is no connection, it will fail.
|
|
74
|
+
def test_pathlen_does_not_appear
|
|
75
|
+
uri = URI.parse('https://www.paypal.com/')
|
|
76
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
77
|
+
http.use_ssl = true
|
|
78
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
79
|
+
# right trust anchor for www.amazon.com
|
|
80
|
+
http.ca_file = path('fixture/verisign_c3.pem')
|
|
81
|
+
response = http.start do |s|
|
|
82
|
+
assert s.get(uri.request_uri).length > 0
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# JRUBY-2178 and JRUBY-1307
|
|
87
|
+
# Warning - this test actually uses the internet connection.
|
|
88
|
+
# If there is no connection, it will fail.
|
|
89
|
+
# This test generally throws an exception
|
|
90
|
+
# about illegal_parameter when
|
|
91
|
+
# it can't use the cipher string correctly
|
|
92
|
+
def test_cipher_strings
|
|
93
|
+
socket = TCPSocket.new('rubyforge.org', 443)
|
|
94
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
|
95
|
+
ctx.cert_store = OpenSSL::X509::Store.new
|
|
96
|
+
ctx.verify_mode = 0
|
|
97
|
+
ctx.cert = nil
|
|
98
|
+
ctx.key = nil
|
|
99
|
+
ctx.client_ca = nil
|
|
100
|
+
ctx.ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"
|
|
101
|
+
|
|
102
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
|
103
|
+
ssl_socket.connect
|
|
104
|
+
ssl_socket.close
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# JRUBY-1194
|
|
108
|
+
def test_des_encryption
|
|
109
|
+
iv = "IVIVIVIV"
|
|
110
|
+
key = "KEYKEYKE"
|
|
111
|
+
alg = "des"
|
|
112
|
+
str = "string abc foo bar baxz"
|
|
113
|
+
|
|
114
|
+
cipher = OpenSSL::Cipher::Cipher.new(alg)
|
|
115
|
+
cipher.encrypt
|
|
116
|
+
cipher.key = key
|
|
117
|
+
cipher.iv = iv
|
|
118
|
+
cipher.padding = 32
|
|
119
|
+
cipher.key = key
|
|
120
|
+
cipher.iv = iv
|
|
121
|
+
|
|
122
|
+
encrypted = cipher.update(str)
|
|
123
|
+
encrypted << cipher.final
|
|
124
|
+
|
|
125
|
+
assert_equal "\253\305\306\372;\374\235\302\357/\006\360\355XO\232\312S\356* #\227\217", encrypted
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def _test_perf_of_nil
|
|
129
|
+
# require 'net/https'
|
|
130
|
+
# require 'benchmark'
|
|
131
|
+
|
|
132
|
+
# def request(data)
|
|
133
|
+
# connection = Net::HTTP.new("www.google.com", 443)
|
|
134
|
+
# connection.use_ssl = true
|
|
135
|
+
# connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
136
|
+
# connection.start do |connection|
|
|
137
|
+
# connection.request_post("/tbproxy/spell?lang=en", data, { 'User-Agent' => "Test", 'Accept' => 'text/xml' })
|
|
138
|
+
# end
|
|
139
|
+
# end
|
|
140
|
+
|
|
141
|
+
# puts "is not: #{Benchmark.measure { request("") }.to_s.chomp}"
|
|
142
|
+
# puts "is nil: #{Benchmark.measure { request(nil) }.to_s.chomp}"
|
|
143
|
+
end
|
|
144
|
+
end
|
data/test/test_java.rb
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'build_lib', '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 << 'build_lib/bcprov-jdk15-144.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
|
+
CipherSpec = org.jruby.ext.openssl.impl.CipherSpec unless defined?(CipherSpec)
|
|
19
|
+
Digest = org.jruby.ext.openssl.impl.Digest unless defined?(Digest)
|
|
20
|
+
EncContent = org.jruby.ext.openssl.impl.EncContent unless defined?(EncContent)
|
|
21
|
+
Encrypt = org.jruby.ext.openssl.impl.Encrypt unless defined?(Encrypt)
|
|
22
|
+
Envelope = org.jruby.ext.openssl.impl.Envelope unless defined?(Envelope)
|
|
23
|
+
IssuerAndSerial = org.jruby.ext.openssl.impl.IssuerAndSerial unless defined?(IssuerAndSerial)
|
|
24
|
+
RecipInfo = org.jruby.ext.openssl.impl.RecipInfo unless defined?(RecipInfo)
|
|
25
|
+
SignEnvelope = org.jruby.ext.openssl.impl.SignEnvelope unless defined?(SignEnvelope)
|
|
26
|
+
Signed = org.jruby.ext.openssl.impl.Signed unless defined?(Signed)
|
|
27
|
+
SMIME = org.jruby.ext.openssl.impl.SMIME unless defined?(SMIME)
|
|
28
|
+
Mime = org.jruby.ext.openssl.impl.Mime unless defined?(Mime)
|
|
29
|
+
MimeHeader = org.jruby.ext.openssl.impl.MimeHeader unless defined?(MimeHeader)
|
|
30
|
+
MimeParam = org.jruby.ext.openssl.impl.MimeParam unless defined?(MimeParam)
|
|
31
|
+
BIO = org.jruby.ext.openssl.impl.BIO unless defined?(BIO)
|
|
32
|
+
PKCS7Exception = org.jruby.ext.openssl.impl.PKCS7Exception unless defined?(PKCS7Exception)
|
|
33
|
+
ASN1Registry = org.jruby.ext.openssl.impl.ASN1Registry unless defined?(ASN1Registry)
|
|
34
|
+
AlgorithmIdentifier = org.bouncycastle.asn1.x509.AlgorithmIdentifier unless defined?(AlgorithmIdentifier)
|
|
35
|
+
SignerInfoWithPkey = org.jruby.ext.openssl.impl.SignerInfoWithPkey unless defined?(SignerInfoWithPkey)
|
|
36
|
+
IssuerAndSerialNumber = org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber unless defined?(IssuerAndSerialNumber)
|
|
37
|
+
ASN1InputStream = org.bouncycastle.asn1.ASN1InputStream unless defined?(ASN1InputStream)
|
|
38
|
+
X509AuxCertificate = org.jruby.ext.openssl.x509store.X509AuxCertificate unless defined?(X509AuxCertificate)
|
|
39
|
+
|
|
40
|
+
ArrayList = java.util.ArrayList unless defined?(ArrayList)
|
|
41
|
+
CertificateFactory = java.security.cert.CertificateFactory unless defined?(CertificateFactory)
|
|
42
|
+
BCP = org.bouncycastle.jce.provider.BouncyCastleProvider unless defined?(BCP)
|
|
43
|
+
ByteArrayInputStream = java.io.ByteArrayInputStream unless defined?(ByteArrayInputStream)
|
|
44
|
+
BigInteger = java.math.BigInteger unless defined?(BigInteger)
|
|
45
|
+
Cipher = javax.crypto.Cipher unless defined?(Cipher)
|
|
46
|
+
|
|
47
|
+
DERInteger = org.bouncycastle.asn1.DERInteger
|
|
48
|
+
DERSet = org.bouncycastle.asn1.DERSet
|
|
49
|
+
DEROctetString = org.bouncycastle.asn1.DEROctetString
|
|
50
|
+
X509Name = org.bouncycastle.asn1.x509.X509Name
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
MimeEnvelopedString = File::read(File.join(File.dirname(__FILE__), 'java', 'pkcs7_mime_enveloped.message'))
|
|
54
|
+
MimeSignedString = File::read(File.join(File.dirname(__FILE__), 'java', 'pkcs7_mime_signed.message'))
|
|
55
|
+
MultipartSignedString = File::read(File.join(File.dirname(__FILE__), 'java', 'pkcs7_multipart_signed.message'))
|
|
56
|
+
|
|
57
|
+
X509CertString = <<CERT
|
|
58
|
+
-----BEGIN CERTIFICATE-----
|
|
59
|
+
MIICijCCAXKgAwIBAgIBAjANBgkqhkiG9w0BAQUFADA9MRMwEQYKCZImiZPyLGQB
|
|
60
|
+
GRYDb3JnMRkwFwYKCZImiZPyLGQBGRYJcnVieS1sYW5nMQswCQYDVQQDDAJDQTAe
|
|
61
|
+
Fw0wODA3MDgxOTE1NDZaFw0wODA3MDgxOTQ1NDZaMEQxEzARBgoJkiaJk/IsZAEZ
|
|
62
|
+
FgNvcmcxGTAXBgoJkiaJk/IsZAEZFglydWJ5LWxhbmcxEjAQBgNVBAMMCWxvY2Fs
|
|
63
|
+
aG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAy8LEsNRApz7U/j5DoB4X
|
|
64
|
+
BgO9Z8Atv5y/OVQRp0ag8Tqo1YewsWijxEWB7JOATwpBN267U4T1nPZIxxEEO7n/
|
|
65
|
+
WNa2ws9JWsjah8ssEBFSxZqdXKSLf0N4Hi7/GQ/aYoaMCiQ8jA4jegK2FJmXM71u
|
|
66
|
+
Pe+jFN/peeBOpRfyXxRFOYcCAwEAAaMSMBAwDgYDVR0PAQH/BAQDAgWgMA0GCSqG
|
|
67
|
+
SIb3DQEBBQUAA4IBAQCU879BALJIM9avHiuZ3WTjDy0UYP3ZG5wtuSqBSnD1k8pr
|
|
68
|
+
hXfRaga7mDj6EQaGUovImb+KrRi6mZc+zsx4rTxwBNJT9U8yiW2eYxmgcT9/qKrD
|
|
69
|
+
/1nz+e8NeUCCDY5UTUHGszZw5zLEDgDX2n3E/CDIZsoRSyq5vXq1jpfih/tSWanj
|
|
70
|
+
Y9uP/o8Dc7ZcRJOAX7NPu1bbZcbxEbZ8sMe5wZ5HNiAR6gnOrjz2Yyazb//PSskE
|
|
71
|
+
4flt/2h4pzGA0/ZHcnDjcoLdiLtInsqPOlVDLgqd/XqRYWtj84N4gw1iS9cHyrIZ
|
|
72
|
+
dqbS54IKvzElD+R0QVS2z6TIGJSpuSBnZ4yfuNuq
|
|
73
|
+
-----END CERTIFICATE-----
|
|
74
|
+
CERT
|
|
75
|
+
|
|
76
|
+
X509CRLString = <<CRL
|
|
77
|
+
----BEGIN X509 CRL-----
|
|
78
|
+
MIIBlTB/AgEBMA0GCSqGSIb3DQEBBQUAMD0xEzARBgoJkiaJk/IsZAEZFgNvcmcx
|
|
79
|
+
GTAXBgoJkiaJk/IsZAEZFglydWJ5LWxhbmcxCzAJBgNVBAMMAkNBFw0wODA3MTgx
|
|
80
|
+
NzQxMjhaFw0wODA3MTgxODA4MDhaoA4wDDAKBgNVHRQEAwIBATANBgkqhkiG9w0B
|
|
81
|
+
AQUFAAOCAQEASJaj1keN+tMmsF3QmjH2RhbW/9rZAl4gjv+uQQqrcS2ByfkXLU1d
|
|
82
|
+
l/8rCHeT/XMoeU6xhQNHPP3uZBwfuuETcp65BMBcZFOUhUR0U5AaGhvSDS/+6EsP
|
|
83
|
+
zFdQgAagmThFdN5ei9guTLqWwN0ZyqiaHyevFJuk+L9qbKavaSeKqfJbU7Sj/Z3J
|
|
84
|
+
WLKoixvyj3N6W7evygH80lTvjZugmxJ1/AjICVSYr1hpHHd6EWq0b0YFrGFmg27R
|
|
85
|
+
WmsAXd0QV5UChfAJ2+Cz5U1bPszvIJGrzfAIoLxHv5rI5rseQzqZdPaFSe4Oehln
|
|
86
|
+
9qEYmsK3PS6bYoQol0cgj97Ep4olS8CulA==
|
|
87
|
+
-----END X509 CRL-----
|
|
88
|
+
CRL
|
|
89
|
+
|
|
90
|
+
X509Cert = X509AuxCertificate.new(CertificateFactory.getInstance("X.509",BCP.new).generateCertificate(ByteArrayInputStream.new(X509CertString.to_java_bytes)))
|
|
91
|
+
X509CRL = CertificateFactory.getInstance("X.509",BCP.new).generateCRL(ByteArrayInputStream.new(X509CRLString.to_java_bytes))
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
files = File.join(File.dirname(__FILE__), 'java', 'test_*.rb')
|
|
95
|
+
Dir.glob(files).sort.each do |tc|
|
|
96
|
+
require tc
|
|
97
|
+
end
|
|
98
|
+
end
|