jruby-openssl 0.8.0.pre3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/Manifest.txt +5 -124
  2. data/Rakefile +3 -3
  3. data/lib/shared/jopenssl.jar +0 -0
  4. data/lib/shared/jopenssl/version.rb +1 -1
  5. metadata +10 -116
  6. data/test/1.8/ssl_server.rb +0 -99
  7. data/test/1.8/test_asn1.rb +0 -212
  8. data/test/1.8/test_cipher.rb +0 -193
  9. data/test/1.8/test_config.rb +0 -290
  10. data/test/1.8/test_digest.rb +0 -88
  11. data/test/1.8/test_ec.rb +0 -128
  12. data/test/1.8/test_hmac.rb +0 -46
  13. data/test/1.8/test_ns_spki.rb +0 -59
  14. data/test/1.8/test_pair.rb +0 -149
  15. data/test/1.8/test_pkcs7.rb +0 -489
  16. data/test/1.8/test_pkey_rsa.rb +0 -49
  17. data/test/1.8/test_ssl.rb +0 -1032
  18. data/test/1.8/test_x509cert.rb +0 -277
  19. data/test/1.8/test_x509crl.rb +0 -253
  20. data/test/1.8/test_x509ext.rb +0 -99
  21. data/test/1.8/test_x509name.rb +0 -290
  22. data/test/1.8/test_x509req.rb +0 -195
  23. data/test/1.8/test_x509store.rb +0 -246
  24. data/test/1.8/utils.rb +0 -144
  25. data/test/1.9/ssl_server.rb +0 -81
  26. data/test/1.9/test_asn1.rb +0 -589
  27. data/test/1.9/test_bn.rb +0 -23
  28. data/test/1.9/test_buffering.rb +0 -88
  29. data/test/1.9/test_cipher.rb +0 -107
  30. data/test/1.9/test_config.rb +0 -288
  31. data/test/1.9/test_digest.rb +0 -118
  32. data/test/1.9/test_engine.rb +0 -15
  33. data/test/1.9/test_hmac.rb +0 -32
  34. data/test/1.9/test_ns_spki.rb +0 -50
  35. data/test/1.9/test_ocsp.rb +0 -47
  36. data/test/1.9/test_pair.rb +0 -257
  37. data/test/1.9/test_pkcs12.rb +0 -209
  38. data/test/1.9/test_pkcs7.rb +0 -156
  39. data/test/1.9/test_pkey_dh.rb +0 -72
  40. data/test/1.9/test_pkey_dsa.rb +0 -224
  41. data/test/1.9/test_pkey_ec.rb +0 -182
  42. data/test/1.9/test_pkey_rsa.rb +0 -244
  43. data/test/1.9/test_ssl.rb +0 -499
  44. data/test/1.9/test_ssl_session.rb +0 -327
  45. data/test/1.9/test_x509cert.rb +0 -217
  46. data/test/1.9/test_x509crl.rb +0 -221
  47. data/test/1.9/test_x509ext.rb +0 -69
  48. data/test/1.9/test_x509name.rb +0 -366
  49. data/test/1.9/test_x509req.rb +0 -150
  50. data/test/1.9/test_x509store.rb +0 -229
  51. data/test/1.9/utils.rb +0 -304
  52. data/test/cert_with_ec_pk.cer +0 -27
  53. data/test/fixture/ca-bundle.crt +0 -2794
  54. data/test/fixture/ca_path/72fa7371.0 +0 -19
  55. data/test/fixture/ca_path/verisign.pem +0 -19
  56. data/test/fixture/cacert.pem +0 -23
  57. data/test/fixture/cert_localhost.pem +0 -19
  58. data/test/fixture/common.pem +0 -48
  59. data/test/fixture/ids_in_subject_rdn_set.pem +0 -31
  60. data/test/fixture/imaps/cacert.pem +0 -60
  61. data/test/fixture/imaps/server.crt +0 -61
  62. data/test/fixture/imaps/server.key +0 -15
  63. data/test/fixture/key_then_cert.pem +0 -34
  64. data/test/fixture/keypair.pem +0 -27
  65. data/test/fixture/localhost_keypair.pem +0 -18
  66. data/test/fixture/max.pem +0 -29
  67. data/test/fixture/purpose/b70a5bc1.0 +0 -24
  68. data/test/fixture/purpose/ca/PASSWD_OF_CA_KEY_IS_1234 +0 -0
  69. data/test/fixture/purpose/ca/ca_config.rb +0 -37
  70. data/test/fixture/purpose/ca/cacert.pem +0 -24
  71. data/test/fixture/purpose/ca/newcerts/2_cert.pem +0 -19
  72. data/test/fixture/purpose/ca/newcerts/3_cert.pem +0 -19
  73. data/test/fixture/purpose/ca/newcerts/4_cert.pem +0 -19
  74. data/test/fixture/purpose/ca/private/cakeypair.pem +0 -30
  75. data/test/fixture/purpose/ca/serial +0 -1
  76. data/test/fixture/purpose/cacert.pem +0 -24
  77. data/test/fixture/purpose/scripts/gen_cert.rb +0 -127
  78. data/test/fixture/purpose/scripts/gen_csr.rb +0 -50
  79. data/test/fixture/purpose/scripts/init_ca.rb +0 -66
  80. data/test/fixture/purpose/sslclient.pem +0 -19
  81. data/test/fixture/purpose/sslclient/csr.pem +0 -10
  82. data/test/fixture/purpose/sslclient/keypair.pem +0 -15
  83. data/test/fixture/purpose/sslclient/sslclient.pem +0 -19
  84. data/test/fixture/purpose/sslserver.pem +0 -19
  85. data/test/fixture/purpose/sslserver/csr.pem +0 -10
  86. data/test/fixture/purpose/sslserver/keypair.pem +0 -15
  87. data/test/fixture/purpose/sslserver/sslserver.pem +0 -19
  88. data/test/fixture/purpose/sslserver_no_dsig_in_keyUsage.pem +0 -19
  89. data/test/fixture/selfcert.pem +0 -23
  90. data/test/fixture/verisign.pem +0 -19
  91. data/test/fixture/verisign_c3.pem +0 -14
  92. data/test/ref/a.out +0 -0
  93. data/test/ref/compile.rb +0 -8
  94. data/test/ref/pkcs1 +0 -0
  95. data/test/ref/pkcs1.c +0 -21
  96. data/test/ruby/envutil.rb +0 -208
  97. data/test/ruby/ut_eof.rb +0 -128
  98. data/test/test_all.rb +0 -1
  99. data/test/test_certificate.rb +0 -132
  100. data/test/test_cipher.rb +0 -197
  101. data/test/test_imaps.rb +0 -107
  102. data/test/test_integration.rb +0 -144
  103. data/test/test_openssl.rb +0 -4
  104. data/test/test_parse_certificate.rb +0 -27
  105. data/test/test_pkcs7.rb +0 -56
  106. data/test/test_pkey_dsa.rb +0 -180
  107. data/test/test_pkey_rsa.rb +0 -329
  108. data/test/test_ssl.rb +0 -97
  109. data/test/test_x509store.rb +0 -168
@@ -1,212 +0,0 @@
1
- begin
2
- require "openssl"
3
- require File.join(File.dirname(__FILE__), "utils.rb")
4
- rescue LoadError
5
- end
6
- require 'test/unit'
7
-
8
- class OpenSSL::TestASN1 < Test::Unit::TestCase
9
- def test_decode
10
- subj = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=TestCA")
11
- key = OpenSSL::TestUtils::TEST_KEY_RSA1024
12
- now = Time.at(Time.now.to_i) # suppress usec
13
- s = 0xdeadbeafdeadbeafdeadbeafdeadbeaf
14
- exts = [
15
- ["basicConstraints","CA:TRUE,pathlen:1",true],
16
- ["keyUsage","keyCertSign, cRLSign",true],
17
- ["subjectKeyIdentifier","hash",false],
18
- ]
19
- dgst = OpenSSL::Digest::SHA1.new
20
- cert = OpenSSL::TestUtils.issue_cert(
21
- subj, key, s, now, now+3600, exts, nil, nil, dgst)
22
-
23
-
24
- asn1 = OpenSSL::ASN1.decode(cert)
25
- assert_equal(OpenSSL::ASN1::Sequence, asn1.class)
26
- assert_equal(3, asn1.value.size)
27
- tbs_cert, sig_alg, sig_val = *asn1.value
28
-
29
- assert_equal(OpenSSL::ASN1::Sequence, tbs_cert.class)
30
- assert_equal(8, tbs_cert.value.size)
31
-
32
- version = tbs_cert.value[0]
33
- assert_equal(:CONTEXT_SPECIFIC, version.tag_class)
34
- assert_equal(0, version.tag)
35
- assert_equal(1, version.value.size)
36
- assert_equal(OpenSSL::ASN1::Integer, version.value[0].class)
37
- assert_equal(2, version.value[0].value)
38
- assert_equal(OpenSSL::BN, version.value[0].value.class)
39
-
40
- serial = tbs_cert.value[1]
41
- assert_equal(OpenSSL::ASN1::Integer, serial.class)
42
- assert_equal(0xdeadbeafdeadbeafdeadbeafdeadbeaf, serial.value)
43
-
44
- sig = tbs_cert.value[2]
45
- assert_equal(OpenSSL::ASN1::Sequence, sig.class)
46
- assert_equal(2, sig.value.size)
47
- assert_equal(OpenSSL::ASN1::ObjectId, sig.value[0].class)
48
- assert_equal("1.2.840.113549.1.1.5", sig.value[0].oid)
49
- assert_equal(OpenSSL::ASN1::Null, sig.value[1].class)
50
-
51
- dn = tbs_cert.value[3] # issuer
52
- assert_equal(subj.hash, OpenSSL::X509::Name.new(dn).hash)
53
- assert_equal(OpenSSL::ASN1::Sequence, dn.class)
54
- assert_equal(3, dn.value.size)
55
- assert_equal(OpenSSL::ASN1::Set, dn.value[0].class)
56
- assert_equal(OpenSSL::ASN1::Set, dn.value[1].class)
57
- assert_equal(OpenSSL::ASN1::Set, dn.value[2].class)
58
- assert_equal(1, dn.value[0].value.size)
59
- assert_equal(1, dn.value[1].value.size)
60
- assert_equal(1, dn.value[2].value.size)
61
- assert_equal(OpenSSL::ASN1::Sequence, dn.value[0].value[0].class)
62
- assert_equal(OpenSSL::ASN1::Sequence, dn.value[1].value[0].class)
63
- assert_equal(OpenSSL::ASN1::Sequence, dn.value[2].value[0].class)
64
- assert_equal(2, dn.value[0].value[0].value.size)
65
- assert_equal(2, dn.value[1].value[0].value.size)
66
- assert_equal(2, dn.value[2].value[0].value.size)
67
- oid, value = *dn.value[0].value[0].value
68
- assert_equal(OpenSSL::ASN1::ObjectId, oid.class)
69
- assert_equal("0.9.2342.19200300.100.1.25", oid.oid)
70
- assert_equal(OpenSSL::ASN1::IA5String, value.class)
71
- assert_equal("org", value.value)
72
- oid, value = *dn.value[1].value[0].value
73
- assert_equal(OpenSSL::ASN1::ObjectId, oid.class)
74
- assert_equal("0.9.2342.19200300.100.1.25", oid.oid)
75
- assert_equal(OpenSSL::ASN1::IA5String, value.class)
76
- assert_equal("ruby-lang", value.value)
77
- oid, value = *dn.value[2].value[0].value
78
- assert_equal(OpenSSL::ASN1::ObjectId, oid.class)
79
- assert_equal("2.5.4.3", oid.oid)
80
- assert_equal(OpenSSL::ASN1::UTF8String, value.class)
81
- assert_equal("TestCA", value.value)
82
-
83
- validity = tbs_cert.value[4]
84
- assert_equal(OpenSSL::ASN1::Sequence, validity.class)
85
- assert_equal(2, validity.value.size)
86
- assert_equal(OpenSSL::ASN1::UTCTime, validity.value[0].class)
87
- assert_equal(now, validity.value[0].value)
88
- assert_equal(OpenSSL::ASN1::UTCTime, validity.value[1].class)
89
- assert_equal(now+3600, validity.value[1].value)
90
-
91
- dn = tbs_cert.value[5] # subject
92
- assert_equal(subj.hash, OpenSSL::X509::Name.new(dn).hash)
93
- assert_equal(OpenSSL::ASN1::Sequence, dn.class)
94
- assert_equal(3, dn.value.size)
95
- assert_equal(OpenSSL::ASN1::Set, dn.value[0].class)
96
- assert_equal(OpenSSL::ASN1::Set, dn.value[1].class)
97
- assert_equal(OpenSSL::ASN1::Set, dn.value[2].class)
98
- assert_equal(1, dn.value[0].value.size)
99
- assert_equal(1, dn.value[1].value.size)
100
- assert_equal(1, dn.value[2].value.size)
101
- assert_equal(OpenSSL::ASN1::Sequence, dn.value[0].value[0].class)
102
- assert_equal(OpenSSL::ASN1::Sequence, dn.value[1].value[0].class)
103
- assert_equal(OpenSSL::ASN1::Sequence, dn.value[2].value[0].class)
104
- assert_equal(2, dn.value[0].value[0].value.size)
105
- assert_equal(2, dn.value[1].value[0].value.size)
106
- assert_equal(2, dn.value[2].value[0].value.size)
107
- oid, value = *dn.value[0].value[0].value
108
- assert_equal(OpenSSL::ASN1::ObjectId, oid.class)
109
- assert_equal("0.9.2342.19200300.100.1.25", oid.oid)
110
- assert_equal(OpenSSL::ASN1::IA5String, value.class)
111
- assert_equal("org", value.value)
112
- oid, value = *dn.value[1].value[0].value
113
- assert_equal(OpenSSL::ASN1::ObjectId, oid.class)
114
- assert_equal("0.9.2342.19200300.100.1.25", oid.oid)
115
- assert_equal(OpenSSL::ASN1::IA5String, value.class)
116
- assert_equal("ruby-lang", value.value)
117
- oid, value = *dn.value[2].value[0].value
118
- assert_equal(OpenSSL::ASN1::ObjectId, oid.class)
119
- assert_equal("2.5.4.3", oid.oid)
120
- assert_equal(OpenSSL::ASN1::UTF8String, value.class)
121
- assert_equal("TestCA", value.value)
122
-
123
- pkey = tbs_cert.value[6]
124
- assert_equal(OpenSSL::ASN1::Sequence, pkey.class)
125
- assert_equal(2, pkey.value.size)
126
- assert_equal(OpenSSL::ASN1::Sequence, pkey.value[0].class)
127
- assert_equal(2, pkey.value[0].value.size)
128
- assert_equal(OpenSSL::ASN1::ObjectId, pkey.value[0].value[0].class)
129
- assert_equal("1.2.840.113549.1.1.1", pkey.value[0].value[0].oid)
130
- assert_equal(OpenSSL::ASN1::BitString, pkey.value[1].class)
131
- assert_equal(0, pkey.value[1].unused_bits)
132
- spkey = OpenSSL::ASN1.decode(pkey.value[1].value)
133
- assert_equal(OpenSSL::ASN1::Sequence, spkey.class)
134
- assert_equal(2, spkey.value.size)
135
- assert_equal(OpenSSL::ASN1::Integer, spkey.value[0].class)
136
- assert_equal(143085709396403084580358323862163416700436550432664688288860593156058579474547937626086626045206357324274536445865308750491138538454154232826011964045825759324933943290377903384882276841880081931690695505836279972214003660451338124170055999155993192881685495391496854691199517389593073052473319331505702779271, spkey.value[0].value)
137
- assert_equal(OpenSSL::ASN1::Integer, spkey.value[1].class)
138
- assert_equal(65537, spkey.value[1].value)
139
-
140
- extensions = tbs_cert.value[7]
141
- assert_equal(:CONTEXT_SPECIFIC, extensions.tag_class)
142
- assert_equal(3, extensions.tag)
143
- assert_equal(1, extensions.value.size)
144
- assert_equal(OpenSSL::ASN1::Sequence, extensions.value[0].class)
145
- assert_equal(3, extensions.value[0].value.size)
146
-
147
- ext = extensions.value[0].value[0] # basicConstraints
148
- assert_equal(OpenSSL::ASN1::Sequence, ext.class)
149
- assert_equal(3, ext.value.size)
150
- assert_equal(OpenSSL::ASN1::ObjectId, ext.value[0].class)
151
- assert_equal("2.5.29.19", ext.value[0].oid)
152
- assert_equal(OpenSSL::ASN1::Boolean, ext.value[1].class)
153
- assert_equal(true, ext.value[1].value)
154
- assert_equal(OpenSSL::ASN1::OctetString, ext.value[2].class)
155
- extv = OpenSSL::ASN1.decode(ext.value[2].value)
156
- assert_equal(OpenSSL::ASN1::Sequence, extv.class)
157
- assert_equal(2, extv.value.size)
158
- assert_equal(OpenSSL::ASN1::Boolean, extv.value[0].class)
159
- assert_equal(true, extv.value[0].value)
160
- assert_equal(OpenSSL::ASN1::Integer, extv.value[1].class)
161
- assert_equal(1, extv.value[1].value)
162
-
163
- ext = extensions.value[0].value[1] # keyUsage
164
- assert_equal(OpenSSL::ASN1::Sequence, ext.class)
165
- assert_equal(3, ext.value.size)
166
- assert_equal(OpenSSL::ASN1::ObjectId, ext.value[0].class)
167
- assert_equal("2.5.29.15", ext.value[0].oid)
168
- assert_equal(OpenSSL::ASN1::Boolean, ext.value[1].class)
169
- assert_equal(true, ext.value[1].value)
170
- assert_equal(OpenSSL::ASN1::OctetString, ext.value[2].class)
171
- extv = OpenSSL::ASN1.decode(ext.value[2].value)
172
- assert_equal(OpenSSL::ASN1::BitString, extv.class)
173
- str = "\000"; str[0] = 0b00000110
174
- assert_equal(str, extv.value)
175
-
176
- ext = extensions.value[0].value[2] # subjetKeyIdentifier
177
- assert_equal(OpenSSL::ASN1::Sequence, ext.class)
178
- assert_equal(2, ext.value.size)
179
- assert_equal(OpenSSL::ASN1::ObjectId, ext.value[0].class)
180
- assert_equal("2.5.29.14", ext.value[0].oid)
181
- assert_equal(OpenSSL::ASN1::OctetString, ext.value[1].class)
182
- extv = OpenSSL::ASN1.decode(ext.value[1].value)
183
- assert_equal(OpenSSL::ASN1::OctetString, extv.class)
184
- sha1 = OpenSSL::Digest::SHA1.new
185
- sha1.update(pkey.value[1].value)
186
- assert_equal(sha1.digest, extv.value)
187
-
188
- assert_equal(OpenSSL::ASN1::Sequence, sig_alg.class)
189
- assert_equal(2, sig_alg.value.size)
190
- assert_equal(OpenSSL::ASN1::ObjectId, pkey.value[0].value[0].class)
191
- assert_equal("1.2.840.113549.1.1.1", pkey.value[0].value[0].oid)
192
- assert_equal(OpenSSL::ASN1::Null, pkey.value[0].value[1].class)
193
-
194
- assert_equal(OpenSSL::ASN1::BitString, sig_val.class)
195
- cululated_sig = key.sign(OpenSSL::Digest::SHA1.new, tbs_cert.to_der)
196
- assert_equal(cululated_sig, sig_val.value)
197
- end
198
-
199
- def test_encode_boolean
200
- encode_decode_test(OpenSSL::ASN1::Boolean, [true, false])
201
- end
202
-
203
- def test_encode_integer
204
- encode_decode_test(OpenSSL::ASN1::Integer, [72, -127, -128, 128, -1, 0, 1, -(2**12345), 2**12345])
205
- end
206
-
207
- def encode_decode_test(type, values)
208
- values.each do |v|
209
- assert_equal(v, OpenSSL::ASN1.decode(type.new(v).to_der).value)
210
- end
211
- end
212
- end if defined?(OpenSSL)
@@ -1,193 +0,0 @@
1
- begin
2
- require "openssl"
3
- rescue LoadError
4
- end
5
- require "test/unit"
6
-
7
- if defined?(OpenSSL)
8
-
9
- class OpenSSL::TestCipher < Test::Unit::TestCase
10
- def setup
11
- @c1 = OpenSSL::Cipher::Cipher.new("DES-EDE3-CBC")
12
- @c2 = OpenSSL::Cipher::DES.new(:EDE3, "CBC")
13
- @key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
14
- @iv = "\0\0\0\0\0\0\0\0"
15
- @iv1 = "\1\1\1\1\1\1\1\1"
16
- @hexkey = "0000000000000000000000000000000000000000000000"
17
- @hexiv = "0000000000000000"
18
- @data = "DATA"
19
- end
20
-
21
- def teardown
22
- @c1 = @c2 = nil
23
- end
24
-
25
- def test_crypt
26
- @c1.encrypt.pkcs5_keyivgen(@key, @iv)
27
- @c2.encrypt.pkcs5_keyivgen(@key, @iv)
28
- s1 = @c1.update(@data) + @c1.final
29
- s2 = @c2.update(@data) + @c2.final
30
- assert_equal(s1, s2, "encrypt")
31
-
32
- @c1.decrypt.pkcs5_keyivgen(@key, @iv)
33
- @c2.decrypt.pkcs5_keyivgen(@key, @iv)
34
- assert_equal(@data, @c1.update(s1)+@c1.final, "decrypt")
35
- assert_equal(@data, @c2.update(s2)+@c2.final, "decrypt")
36
- end
37
-
38
- def test_info
39
- assert_equal("DES-EDE3-CBC", @c1.name, "name")
40
- assert_equal("DES-EDE3-CBC", @c2.name, "name")
41
- assert_kind_of(Fixnum, @c1.key_len, "key_len")
42
- assert_kind_of(Fixnum, @c1.iv_len, "iv_len")
43
- end
44
-
45
- def test_dup
46
- assert_equal(@c1.name, @c1.dup.name, "dup")
47
- assert_equal(@c1.name, @c1.clone.name, "clone")
48
- @c1.encrypt
49
- @c1.key = @key
50
- @c1.iv = @iv
51
- tmpc = @c1.dup
52
- s1 = @c1.update(@data) + @c1.final
53
- s2 = tmpc.update(@data) + tmpc.final
54
- assert_equal(s1, s2, "encrypt dup")
55
- end
56
-
57
- def test_reset
58
- @c1.encrypt
59
- @c1.key = @key
60
- @c1.iv = @iv
61
- s1 = @c1.update(@data) + @c1.final
62
- @c1.reset
63
- s2 = @c1.update(@data) + @c1.final
64
- assert_equal(s1, s2, "encrypt reset")
65
- end
66
-
67
- def test_set_iv
68
- @c1.encrypt
69
- @c1.key = @key
70
- @c1.iv = @iv
71
- s1 = @c1.update(@data) + @c1.final
72
- @c1.iv = @iv1
73
- s1 += @c1.update(@data) + @c1.final
74
- @c1.reset
75
- @c1.iv = @iv
76
- s2 = @c1.update(@data) + @c1.final
77
- @c1.iv = @iv1
78
- s2 += @c1.update(@data) + @c1.final
79
- assert_equal(s1, s2, "encrypt reset")
80
- end
81
-
82
- def test_empty_data
83
- @c1.encrypt
84
- assert_raise(ArgumentError){ @c1.update("") }
85
- end
86
-
87
- def test_disable_padding(padding=0)
88
- # assume a padding size of 8
89
- # encrypt the data with padding
90
- @c1.encrypt
91
- @c1.key = @key
92
- @c1.iv = @iv
93
- encrypted_data = @c1.update(@data) + @c1.final
94
- assert_equal(8, encrypted_data.size)
95
- # decrypt with padding disabled
96
- @c1.decrypt
97
- @c1.padding = padding
98
- decrypted_data = @c1.update(encrypted_data) + @c1.final
99
- # check that the result contains the padding
100
- assert_equal(8, decrypted_data.size)
101
- assert_equal(@data, decrypted_data[0...@data.size])
102
- end
103
-
104
- if RUBY_PLATFORM =~ /java/
105
- # JRuby extension - using Java padding types
106
-
107
- def test_disable_padding_javastyle
108
- test_disable_padding('NoPadding')
109
- end
110
-
111
- def test_iso10126_padding
112
- @c1.encrypt
113
- @c1.key = @key
114
- @c1.iv = @iv
115
- @c1.padding = 'ISO10126Padding'
116
- encrypted_data = @c1.update(@data) + @c1.final
117
- # decrypt with padding disabled to see the padding
118
- @c1.decrypt
119
- @c1.padding = 0
120
- decrypted_data = @c1.update(encrypted_data) + @c1.final
121
- assert_equal(@data, decrypted_data[0...@data.size])
122
- # last byte should be the amount of padding
123
- assert_equal(4, decrypted_data[-1])
124
- end
125
-
126
- def test_iso10126_padding_boundry
127
- @data = 'HELODATA' # 8 bytes, same as padding size
128
- @c1.encrypt
129
- @c1.key = @key
130
- @c1.iv = @iv
131
- @c1.padding = 'ISO10126Padding'
132
- encrypted_data = @c1.update(@data) + @c1.final
133
- # decrypt with padding disabled to see the padding
134
- @c1.decrypt
135
- @c1.padding = 0
136
- decrypted_data = @c1.update(encrypted_data) + @c1.final
137
- assert_equal(@data, decrypted_data[0...@data.size])
138
- # padding should be one whole block
139
- assert_equal(8, decrypted_data[-1])
140
- end
141
- end
142
-
143
- if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00907000
144
- def test_ciphers
145
- OpenSSL::Cipher.ciphers.each{|name|
146
- assert(OpenSSL::Cipher::Cipher.new(name).is_a?(OpenSSL::Cipher::Cipher))
147
- }
148
- end
149
-
150
- def test_AES
151
- pt = File.read(__FILE__)
152
- %w(ECB CBC CFB OFB).each{|mode|
153
- c1 = OpenSSL::Cipher::AES256.new(mode)
154
- c1.encrypt
155
- assert_nothing_raised('This test fails w/o Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files') do
156
- c1.pkcs5_keyivgen("passwd")
157
- end
158
- ct = c1.update(pt) + c1.final
159
-
160
- c2 = OpenSSL::Cipher::AES256.new(mode)
161
- c2.decrypt
162
- c2.pkcs5_keyivgen("passwd")
163
- assert_equal(pt, c2.update(ct) + c2.final)
164
- }
165
- end
166
- end
167
-
168
- # JRUBY-4028
169
- def test_jruby_4028
170
- key = "0599E113A7EE32A9"
171
- data = "1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
172
- c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
173
- c1.padding = 0
174
- c1.iv = "0" * 8
175
- c1.encrypt
176
- c1.key = key
177
- e = c1.update data
178
- e << c1.final
179
-
180
- c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
181
- c2.padding = 0
182
- c2.iv = "0" * 8
183
- c2.decrypt
184
- c2.key = key
185
- d = c2.update e
186
- d << c2.final
187
-
188
- assert_equal "\342\320B.\300&X\310\344\253\025\215\017*\22015\344\024D\342\213\361\336\311\271\326\016\243\214\026\2545\002\237,\017s\202\316&Ew\323\221H\376\200\304\201\365\332Im\240\361\037\246\3536\001A2\341\324o0\350\364%=\325\330\240\324u\225\304h\277\272\361f\024\324\352\336\353N\002/]C\370!\003)\212oa\225\207\333\340\245\207\024\351\037\327[\212\001{\216\f\315\345\372\v\226\r\233?\002\vJK", e
189
- assert_equal data, d
190
- end
191
- end
192
-
193
- end
@@ -1,290 +0,0 @@
1
- require 'openssl'
2
- require "test/unit"
3
- require 'tempfile'
4
- require File.join(File.dirname(__FILE__), "utils.rb")
5
-
6
- class OpenSSL::TestConfig < Test::Unit::TestCase
7
- def setup
8
- file = Tempfile.open("openssl.cnf")
9
- file << <<__EOD__
10
- HOME = .
11
- [ ca ]
12
- default_ca = CA_default
13
- [ CA_default ]
14
- dir = ./demoCA
15
- certs = ./certs
16
- __EOD__
17
- file.close
18
- @it = OpenSSL::Config.new(file.path)
19
- end
20
-
21
- def TODO_test_constants
22
- assert(defined?(OpenSSL::Config::DEFAULT_CONFIG_FILE))
23
- assert_nothing_raised do
24
- OpenSSL::Config.load(OpenSSL::Config::DEFAULT_CONFIG_FILE)
25
- end
26
- end
27
-
28
- def test_s_parse
29
- c = OpenSSL::Config.parse('')
30
- assert_equal("[ default ]\n\n", c.to_s)
31
- c = OpenSSL::Config.parse(@it.to_s)
32
- assert_equal(['CA_default', 'ca', 'default'], c.sections.sort)
33
- end
34
-
35
- def test_s_parse_format
36
- c = OpenSSL::Config.parse(<<__EOC__)
37
- baz =qx\t # "baz = qx"
38
-
39
- foo::bar = baz # shortcut section::key format
40
- default::bar = baz # ditto
41
- a=\t \t # "a = ": trailing spaces are ignored
42
- =b # " = b": empty key
43
- =c # " = c": empty key (override the above line)
44
- d= # "c = ": trailing comment is ignored
45
-
46
- sq = 'foo''b\\'ar'
47
- dq ="foo""''\\""
48
- dq2 = foo""bar
49
- esc=a\\r\\n\\b\\tb
50
- foo\\bar = foo\\b\\\\ar
51
- foo\\bar::foo\\bar = baz
52
- [default1 default2]\t\t # space is allowed in section name
53
- fo =b ar # space allowed in value
54
- [emptysection]
55
- [doller ]
56
- foo=bar
57
- bar = $(foo)
58
- baz = 123$(default::bar)456${foo}798
59
- qux = ${baz}
60
- quxx = $qux.$qux
61
- __EOC__
62
- assert_equal(['default', 'default1 default2', 'doller', 'emptysection', 'foo', 'foo\\bar'], c.sections.sort)
63
- assert_equal(['', 'a', 'bar', 'baz', 'd', 'dq', 'dq2', 'esc', 'foo\\bar', 'sq'], c['default'].keys.sort)
64
- assert_equal('c', c['default'][''])
65
- assert_equal('', c['default']['a'])
66
- assert_equal('qx', c['default']['baz'])
67
- assert_equal('', c['default']['d'])
68
- assert_equal('baz', c['default']['bar'])
69
- assert_equal("foob'ar", c['default']['sq'])
70
- assert_equal("foo''\"", c['default']['dq'])
71
- assert_equal("foobar", c['default']['dq2'])
72
- assert_equal("a\r\n\b\tb", c['default']['esc'])
73
- assert_equal("foo\b\\ar", c['default']['foo\\bar'])
74
- assert_equal('baz', c['foo']['bar'])
75
- assert_equal('baz', c['foo\\bar']['foo\\bar'])
76
- assert_equal('b ar', c['default1 default2']['fo'])
77
-
78
- # dolloer
79
- assert_equal('bar', c['doller']['foo'])
80
- assert_equal('bar', c['doller']['bar'])
81
- assert_equal('123baz456bar798', c['doller']['baz'])
82
- assert_equal('123baz456bar798', c['doller']['qux'])
83
- assert_equal('123baz456bar798.123baz456bar798', c['doller']['quxx'])
84
-
85
- excn = assert_raise(OpenSSL::ConfigError) do
86
- OpenSSL::Config.parse("foo = $bar")
87
- end
88
- assert_equal("error in line 1: variable has no value", excn.message)
89
-
90
- excn = assert_raise(OpenSSL::ConfigError) do
91
- OpenSSL::Config.parse("foo = $(bar")
92
- end
93
- assert_equal("error in line 1: no close brace", excn.message)
94
-
95
- excn = assert_raise(OpenSSL::ConfigError) do
96
- OpenSSL::Config.parse("f o =b ar # no space in key")
97
- end
98
- assert_equal("error in line 1: missing equal sign", excn.message)
99
-
100
- excn = assert_raise(OpenSSL::ConfigError) do
101
- OpenSSL::Config.parse(<<__EOC__)
102
- # comment 1 # comments
103
-
104
- #
105
- # comment 2
106
- \t#comment 3
107
- [second ]\t
108
- [third # section not terminated
109
- __EOC__
110
- end
111
- assert_equal("error in line 7: missing close square bracket", excn.message)
112
- end
113
-
114
- def test_s_load
115
- # alias of new
116
- c = OpenSSL::Config.load
117
- assert_equal("", c.to_s)
118
- assert_equal([], c.sections)
119
- #
120
- file = Tempfile.open("openssl.cnf")
121
- file.close
122
- c = OpenSSL::Config.load(file.path)
123
- assert_equal("[ default ]\n\n", c.to_s)
124
- assert_equal(['default'], c.sections)
125
- end
126
-
127
- def test_initialize
128
- c = OpenSSL::Config.new
129
- assert_equal("", c.to_s)
130
- assert_equal([], c.sections)
131
- end
132
-
133
- def test_initialize_with_empty_file
134
- file = Tempfile.open("openssl.cnf")
135
- file.close
136
- c = OpenSSL::Config.new(file.path)
137
- assert_equal("[ default ]\n\n", c.to_s)
138
- assert_equal(['default'], c.sections)
139
- end
140
-
141
- def test_initialize_with_example_file
142
- assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
143
- end
144
-
145
- def test_get_value
146
- assert_equal('CA_default', @it.get_value('ca', 'default_ca'))
147
- assert_equal(nil, @it.get_value('ca', 'no such key'))
148
- assert_equal(nil, @it.get_value('no such section', 'no such key'))
149
- assert_equal('.', @it.get_value('', 'HOME'))
150
- assert_raise(TypeError) do
151
- @it.get_value(nil, 'HOME') # not allowed unlike Config#value
152
- end
153
- # fallback to 'default' ugly...
154
- assert_equal('.', @it.get_value('unknown', 'HOME'))
155
- end
156
-
157
- def test_get_value_ENV
158
- key = ENV.keys.first
159
- assert_not_nil(key) # make sure we have at least one ENV var.
160
- assert_equal(ENV[key], @it.get_value('ENV', key))
161
- end
162
-
163
- def test_value
164
- # supress deprecation warnings
165
- OpenSSL::TestUtils.silent do
166
- assert_equal('CA_default', @it.value('ca', 'default_ca'))
167
- assert_equal(nil, @it.value('ca', 'no such key'))
168
- assert_equal(nil, @it.value('no such section', 'no such key'))
169
- assert_equal('.', @it.value('', 'HOME'))
170
- assert_equal('.', @it.value(nil, 'HOME'))
171
- assert_equal('.', @it.value('HOME'))
172
- # fallback to 'default' ugly...
173
- assert_equal('.', @it.value('unknown', 'HOME'))
174
- end
175
- end
176
-
177
- def test_value_ENV
178
- OpenSSL::TestUtils.silent do
179
- key = ENV.keys.first
180
- assert_not_nil(key) # make sure we have at least one ENV var.
181
- assert_equal(ENV[key], @it.value('ENV', key))
182
- end
183
- end
184
-
185
- def test_aref
186
- assert_equal({'HOME' => '.'}, @it['default'])
187
- assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it['CA_default'])
188
- assert_equal({}, @it['no_such_section'])
189
- assert_equal({}, @it[''])
190
- end
191
-
192
- def test_section
193
- OpenSSL::TestUtils.silent do
194
- assert_equal({'HOME' => '.'}, @it.section('default'))
195
- assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it.section('CA_default'))
196
- assert_equal({}, @it.section('no_such_section'))
197
- assert_equal({}, @it.section(''))
198
- end
199
- end
200
-
201
- def test_sections
202
- assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
203
- @it['new_section'] = {'foo' => 'bar'}
204
- assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
205
- @it['new_section'] = {}
206
- assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
207
- end
208
-
209
- def test_add_value
210
- c = OpenSSL::Config.new
211
- assert_equal("", c.to_s)
212
- # add key
213
- c.add_value('default', 'foo', 'bar')
214
- assert_equal("[ default ]\nfoo=bar\n\n", c.to_s)
215
- # add another key
216
- c.add_value('default', 'baz', 'qux')
217
- assert_equal('bar', c['default']['foo'])
218
- assert_equal('qux', c['default']['baz'])
219
- # update the value
220
- c.add_value('default', 'baz', 'quxxx')
221
- assert_equal('bar', c['default']['foo'])
222
- assert_equal('quxxx', c['default']['baz'])
223
- # add section and key
224
- c.add_value('section', 'foo', 'bar')
225
- assert_equal('bar', c['default']['foo'])
226
- assert_equal('quxxx', c['default']['baz'])
227
- assert_equal('bar', c['section']['foo'])
228
- end
229
-
230
- def test_aset
231
- @it['foo'] = {'bar' => 'baz'}
232
- assert_equal({'bar' => 'baz'}, @it['foo'])
233
- @it['foo'] = {'bar' => 'qux', 'baz' => 'quxx'}
234
- assert_equal({'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
235
-
236
- # OpenSSL::Config is add only for now.
237
- @it['foo'] = {'foo' => 'foo'}
238
- assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
239
- # you cannot override or remove any section and key.
240
- @it['foo'] = {}
241
- assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
242
- end
243
-
244
- def test_each
245
- # each returns [section, key, value] array.
246
- ary = @it.map { |e| e }.sort { |a, b| a[0] <=> b[0] }
247
- assert_equal(4, ary.size)
248
- assert_equal('CA_default', ary[0][0])
249
- assert_equal('CA_default', ary[1][0])
250
- assert_equal(["ca", "default_ca", "CA_default"], ary[2])
251
- assert_equal(["default", "HOME", "."], ary[3])
252
- end
253
-
254
- def test_to_s
255
- c = OpenSSL::Config.parse("[empty]\n")
256
- assert_equal("[ default ]\n\n[ empty ]\n\n", c.to_s)
257
- end
258
-
259
- def test_inspect
260
- assert_match(/#<OpenSSL::Config sections=\[.*\]>/, @it.inspect)
261
- end
262
-
263
- def test_freeze
264
- c = OpenSSL::Config.new
265
- c['foo'] = [['key', 'value']]
266
- c.freeze
267
-
268
- # [ruby-core:18377]
269
- # RuntimeError for 1.9, TypeError for 1.8
270
- assert_raise(TypeError, /frozen/) do
271
- c['foo'] = [['key', 'wrong']]
272
- end
273
- end
274
-
275
- def test_dup
276
- assert(!@it.sections.empty?)
277
- c = @it.dup
278
- assert_equal(@it.sections.sort, c.sections.sort)
279
- @it['newsection'] = {'a' => 'b'}
280
- assert_not_equal(@it.sections.sort, c.sections.sort)
281
- end
282
-
283
- def test_clone
284
- assert(!@it.sections.empty?)
285
- c = @it.clone
286
- assert_equal(@it.sections.sort, c.sections.sort)
287
- @it['newsection'] = {'a' => 'b'}
288
- assert_not_equal(@it.sections.sort, c.sections.sort)
289
- end
290
- end