jruby-openssl 0.9.20-java → 0.10.7-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +132 -1
  3. data/LICENSE.txt +1 -1
  4. data/Mavenfile +49 -69
  5. data/README.md +14 -16
  6. data/Rakefile +4 -0
  7. data/lib/jopenssl/_compat23.rb +71 -0
  8. data/lib/jopenssl/load.rb +21 -12
  9. data/lib/jopenssl/version.rb +8 -10
  10. data/lib/jopenssl.jar +0 -0
  11. data/lib/jopenssl19/openssl/ssl-internal.rb +104 -0
  12. data/lib/jopenssl22/openssl/ssl.rb +16 -16
  13. data/lib/jopenssl23/openssl/bn.rb +2 -1
  14. data/lib/jopenssl23/openssl/buffering.rb +39 -35
  15. data/lib/jopenssl23/openssl/config.rb +12 -11
  16. data/lib/jopenssl23/openssl/digest.rb +1 -1
  17. data/lib/jopenssl23/openssl/pkey.rb +22 -34
  18. data/lib/jopenssl23/openssl/ssl.rb +210 -125
  19. data/lib/jopenssl23/openssl/x509.rb +76 -1
  20. data/lib/jopenssl23/openssl.rb +1 -1
  21. data/lib/openssl/bn.rb +1 -3
  22. data/lib/openssl/buffering.rb +1 -3
  23. data/lib/openssl/cipher.rb +1 -3
  24. data/lib/openssl/config.rb +10 -4
  25. data/lib/openssl/digest.rb +1 -3
  26. data/lib/openssl/pkcs12.rb +1 -3
  27. data/lib/openssl/pkcs5.rb +22 -0
  28. data/lib/openssl/ssl-internal.rb +1 -3
  29. data/lib/openssl/ssl.rb +1 -3
  30. data/lib/openssl/x509-internal.rb +1 -3
  31. data/lib/openssl/x509.rb +1 -3
  32. data/lib/org/bouncycastle/bcpkix-jdk15on/1.68/bcpkix-jdk15on-1.68.jar +0 -0
  33. data/lib/org/bouncycastle/bcprov-jdk15on/1.68/bcprov-jdk15on-1.68.jar +0 -0
  34. data/lib/org/bouncycastle/bctls-jdk15on/1.68/bctls-jdk15on-1.68.jar +0 -0
  35. data/pom.xml +100 -322
  36. metadata +19 -75
  37. data/integration/1.47/pom.xml +0 -15
  38. data/integration/1.48/pom.xml +0 -15
  39. data/integration/1.49/pom.xml +0 -15
  40. data/integration/1.50/pom.xml +0 -15
  41. data/integration/Mavenfile +0 -57
  42. data/integration/pom.xml +0 -122
  43. data/lib/jopenssl18/openssl/bn.rb +0 -25
  44. data/lib/jopenssl18/openssl/buffering.rb +0 -241
  45. data/lib/jopenssl18/openssl/cipher.rb +0 -28
  46. data/lib/jopenssl18/openssl/config.rb +0 -316
  47. data/lib/jopenssl18/openssl/digest.rb +0 -32
  48. data/lib/jopenssl18/openssl/pkcs7.rb +0 -25
  49. data/lib/jopenssl18/openssl/ssl-internal.rb +0 -112
  50. data/lib/jopenssl18/openssl/ssl.rb +0 -1
  51. data/lib/jopenssl18/openssl/x509-internal.rb +0 -110
  52. data/lib/jopenssl18/openssl/x509.rb +0 -1
  53. data/lib/jopenssl18/openssl.rb +0 -23
  54. data/lib/jopenssl24.rb +0 -112
  55. data/lib/openssl/pkcs7.rb +0 -5
  56. data/lib/org/bouncycastle/bcpkix-jdk15on/1.56/bcpkix-jdk15on-1.56.jar +0 -0
  57. data/lib/org/bouncycastle/bcprov-jdk15on/1.56/bcprov-jdk15on-1.56.jar +0 -0
@@ -1,316 +0,0 @@
1
- =begin
2
- = Ruby-space definitions that completes C-space funcs for Config
3
-
4
- = Info
5
- Copyright (C) 2010 Hiroshi Nakamura <nahi@ruby-lang.org>
6
-
7
- = Licence
8
- This program is licenced under the same licence as Ruby.
9
- (See the file 'LICENCE'.)
10
-
11
- =end
12
-
13
- ##
14
- # Should we care what if somebody require this file directly?
15
- #require 'openssl'
16
- require 'stringio'
17
-
18
- module OpenSSL
19
- class Config
20
- include Enumerable
21
-
22
- class << self
23
- def parse(str)
24
- c = new()
25
- parse_config(StringIO.new(str)).each do |section, hash|
26
- c[section] = hash
27
- end
28
- c
29
- end
30
-
31
- alias load new
32
-
33
- def parse_config(io)
34
- begin
35
- parse_config_lines(io)
36
- rescue ConfigError => e
37
- e.message.replace("error in line #{io.lineno}: " + e.message)
38
- raise
39
- end
40
- end
41
-
42
- def get_key_string(data, section, key) # :nodoc:
43
- if v = data[section] && data[section][key]
44
- return v
45
- elsif section == 'ENV'
46
- if v = ENV[key]
47
- return v
48
- end
49
- end
50
- if v = data['default'] && data['default'][key]
51
- return v
52
- end
53
- end
54
-
55
- private
56
-
57
- def parse_config_lines(io)
58
- section = 'default'
59
- data = {section => {}}
60
- while definition = get_definition(io)
61
- definition = clear_comments(definition)
62
- next if definition.empty?
63
- if definition[0] == ?[
64
- if /\[([^\]]*)\]/ =~ definition
65
- section = $1.strip
66
- data[section] ||= {}
67
- else
68
- raise ConfigError, "missing close square bracket"
69
- end
70
- else
71
- if /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/ =~ definition
72
- if $2
73
- section = $1
74
- key = $2
75
- else
76
- key = $1
77
- end
78
- value = unescape_value(data, section, $3)
79
- (data[section] ||= {})[key] = value.strip
80
- else
81
- raise ConfigError, "missing equal sign"
82
- end
83
- end
84
- end
85
- data
86
- end
87
-
88
- # escape with backslash
89
- QUOTE_REGEXP_SQ = /\A([^'\\]*(?:\\.[^'\\]*)*)'/
90
- # escape with backslash and doubled dq
91
- QUOTE_REGEXP_DQ = /\A([^"\\]*(?:""[^"\\]*|\\.[^"\\]*)*)"/
92
- # escaped char map
93
- ESCAPE_MAP = {
94
- "r" => "\r",
95
- "n" => "\n",
96
- "b" => "\b",
97
- "t" => "\t",
98
- }
99
-
100
- def unescape_value(data, section, value)
101
- scanned = []
102
- while m = value.match(/['"\\$]/)
103
- scanned << m.pre_match
104
- c = m[0]
105
- value = m.post_match
106
- case c
107
- when "'"
108
- if m = value.match(QUOTE_REGEXP_SQ)
109
- scanned << m[1].gsub(/\\(.)/, '\\1')
110
- value = m.post_match
111
- else
112
- break
113
- end
114
- when '"'
115
- if m = value.match(QUOTE_REGEXP_DQ)
116
- scanned << m[1].gsub(/""/, '').gsub(/\\(.)/, '\\1')
117
- value = m.post_match
118
- else
119
- break
120
- end
121
- when "\\"
122
- c = value.slice!(0, 1)
123
- scanned << (ESCAPE_MAP[c] || c)
124
- when "$"
125
- ref, value = extract_reference(value)
126
- refsec = section
127
- if ref.index('::')
128
- refsec, ref = ref.split('::', 2)
129
- end
130
- if v = get_key_string(data, refsec, ref)
131
- scanned << v
132
- else
133
- raise ConfigError, "variable has no value"
134
- end
135
- else
136
- raise 'must not reaced'
137
- end
138
- end
139
- scanned << value
140
- scanned.join
141
- end
142
-
143
- def extract_reference(value)
144
- rest = ''
145
- if m = value.match(/\(([^)]*)\)|\{([^}]*)\}/)
146
- value = m[1] || m[2]
147
- rest = m.post_match
148
- elsif [?(, ?{].include?(value[0])
149
- raise ConfigError, "no close brace"
150
- end
151
- if m = value.match(/[a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]*)?/)
152
- return m[0], m.post_match + rest
153
- else
154
- raise
155
- end
156
- end
157
-
158
- def clear_comments(line)
159
- # FCOMMENT
160
- if m = line.match(/\A([\t\n\f ]*);.*\z/)
161
- return m[1]
162
- end
163
- # COMMENT
164
- scanned = []
165
- while m = line.match(/[#'"\\]/)
166
- scanned << m.pre_match
167
- c = m[0]
168
- line = m.post_match
169
- case c
170
- when '#'
171
- line = nil
172
- break
173
- when "'", '"'
174
- regexp = (c == "'") ? QUOTE_REGEXP_SQ : QUOTE_REGEXP_DQ
175
- scanned << c
176
- if m = line.match(regexp)
177
- scanned << m[0]
178
- line = m.post_match
179
- else
180
- scanned << line
181
- line = nil
182
- break
183
- end
184
- when "\\"
185
- scanned << c
186
- scanned << line.slice!(0, 1)
187
- else
188
- raise 'must not reaced'
189
- end
190
- end
191
- scanned << line
192
- scanned.join
193
- end
194
-
195
- def get_definition(io)
196
- if line = get_line(io)
197
- while /[^\\]\\\z/ =~ line
198
- if extra = get_line(io)
199
- line += extra
200
- else
201
- break
202
- end
203
- end
204
- return line.strip
205
- end
206
- end
207
-
208
- def get_line(io)
209
- if line = io.gets
210
- line.gsub(/[\r\n]*/, '')
211
- end
212
- end
213
- end
214
-
215
- def initialize(filename = nil)
216
- @data = {}
217
- if filename
218
- File.open(filename.to_s) do |file|
219
- Config.parse_config(file).each do |section, hash|
220
- self[section] = hash
221
- end
222
- end
223
- end
224
- end
225
-
226
- def get_value(section, key)
227
- if section.nil?
228
- raise TypeError.new('nil not allowed')
229
- end
230
- section = 'default' if section.empty?
231
- get_key_string(section, key)
232
- end
233
-
234
- def value(arg1, arg2 = nil)
235
- warn('Config#value is deprecated; use Config#get_value')
236
- if arg2.nil?
237
- section, key = 'default', arg1
238
- else
239
- section, key = arg1, arg2
240
- end
241
- section ||= 'default'
242
- section = 'default' if section.empty?
243
- get_key_string(section, key)
244
- end
245
-
246
- def add_value(section, key, value)
247
- check_modify
248
- (@data[section] ||= {})[key] = value
249
- end
250
-
251
- def [](section)
252
- @data[section] || {}
253
- end
254
-
255
- def section(name)
256
- warn('Config#section is deprecated; use Config#[]')
257
- @data[name] || {}
258
- end
259
-
260
- def []=(section, pairs)
261
- check_modify
262
- @data[section] ||= {}
263
- pairs.each do |key, value|
264
- self.add_value(section, key, value)
265
- end
266
- end
267
-
268
- def sections
269
- @data.keys
270
- end
271
-
272
- def to_s
273
- ary = []
274
- @data.keys.sort.each do |section|
275
- ary << "[ #{section} ]\n"
276
- @data[section].keys.each do |key|
277
- ary << "#{key}=#{@data[section][key]}\n"
278
- end
279
- ary << "\n"
280
- end
281
- ary.join
282
- end
283
-
284
- def each
285
- @data.each do |section, hash|
286
- hash.each do |key, value|
287
- yield(section, key, value)
288
- end
289
- end
290
- end
291
-
292
- def inspect
293
- "#<#{self.class.name} sections=#{sections.inspect}>"
294
- end
295
-
296
- protected
297
-
298
- def data
299
- @data
300
- end
301
-
302
- private
303
-
304
- def initialize_copy(other)
305
- @data = other.data.dup
306
- end
307
-
308
- def check_modify
309
- raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen?
310
- end
311
-
312
- def get_key_string(section, key)
313
- Config.get_key_string(@data, section, key)
314
- end
315
- end
316
- end
@@ -1,32 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- Ruby-space predefined Digest subclasses
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id$
15
- =end
16
-
17
- ##
18
- # Should we care what if somebody require this file directly?
19
- #require 'openssl'
20
-
21
- module OpenSSL
22
- class Digest
23
- # This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future.
24
- class Digest < Digest
25
- def initialize(*args)
26
- # add warning
27
- super(*args)
28
- end
29
- end
30
- end # Digest
31
- end # OpenSSL
32
-
@@ -1,25 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- PKCS7
3
-
4
- = Licence
5
- This program is licenced under the same licence as Ruby.
6
- (See the file 'LICENCE'.)
7
-
8
- = Version
9
- $Id: digest.rb 12148 2007-04-05 05:59:22Z technorama $
10
- =end
11
-
12
- module OpenSSL
13
- class PKCS7
14
- # This class is only provided for backwards compatibility. Use OpenSSL::PKCS7 in the future.
15
- class PKCS7 < PKCS7
16
- def initialize(*args)
17
- super(*args)
18
-
19
- warn("Warning: OpenSSL::PKCS7::PKCS7 is deprecated after Ruby 1.9; use OpenSSL::PKCS7 instead")
20
- end
21
- end
22
-
23
- end # PKCS7
24
- end # OpenSSL
25
-
@@ -1,112 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- Ruby-space definitions that completes C-space funcs for SSL
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id$
15
- =end
16
-
17
- require "openssl/buffering"
18
- require 'fcntl' # used by OpenSSL::SSL::Nonblock (if loaded)
19
-
20
- module OpenSSL
21
- module SSL
22
-
23
- def verify_certificate_identity(cert, hostname)
24
- should_verify_common_name = true
25
- cert.extensions.each{|ext|
26
- next if ext.oid != "subjectAltName"
27
- ext.value.split(/,\s+/).each{|general_name|
28
- if /\ADNS:(.*)/ =~ general_name
29
- should_verify_common_name = false
30
- reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+")
31
- return true if /\A#{reg}\z/i =~ hostname
32
- # NOTE: somehow we need the IP: canonical form
33
- # seems there were failures elsewhere when not
34
- # not sure how that's possible possible to-do!
35
- elsif /\AIP(?: Address)?:(.*)/ =~ general_name
36
- #elsif /\AIP Address:(.*)/ =~ general_name
37
- should_verify_common_name = false
38
- return true if $1 == hostname
39
- end
40
- }
41
- }
42
- if should_verify_common_name
43
- cert.subject.to_a.each{|oid, value|
44
- if oid == "CN"
45
- reg = Regexp.escape(value).gsub(/\\\*/, "[^.]+")
46
- return true if /\A#{reg}\z/i =~ hostname
47
- end
48
- }
49
- end
50
- return false
51
- end
52
- module_function :verify_certificate_identity
53
-
54
- class SSLSocket
55
- include Buffering
56
- include SocketForwarder
57
- include Nonblock
58
-
59
- def post_connection_check(hostname)
60
- unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname)
61
- raise SSLError, "hostname was not match with the server certificate"
62
- end
63
- return true
64
- end
65
-
66
- end
67
-
68
- class SSLServer
69
- include SocketForwarder
70
- attr_accessor :start_immediately
71
-
72
- def initialize(svr, ctx)
73
- @svr = svr
74
- @ctx = ctx
75
- unless ctx.session_id_context
76
- session_id = OpenSSL::Digest::MD5.hexdigest($0)
77
- @ctx.session_id_context = session_id
78
- end
79
- @start_immediately = true
80
- end
81
-
82
- def to_io
83
- @svr
84
- end
85
-
86
- def listen(backlog=5)
87
- @svr.listen(backlog)
88
- end
89
-
90
- def shutdown(how=Socket::SHUT_RDWR)
91
- @svr.shutdown(how)
92
- end
93
-
94
- def accept
95
- sock = @svr.accept
96
- begin
97
- ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
98
- ssl.sync_close = true
99
- ssl.accept if @start_immediately
100
- ssl
101
- rescue SSLError => ex
102
- sock.close
103
- raise ex
104
- end
105
- end
106
-
107
- def close
108
- @svr.close
109
- end
110
- end
111
- end
112
- end
@@ -1 +0,0 @@
1
- require 'openssl'
@@ -1,110 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id$
15
- =end
16
-
17
- module OpenSSL
18
- module X509
19
- class Name
20
- module RFC2253DN
21
- Special = ',=+<>#;'
22
- HexChar = /[0-9a-fA-F]/
23
- HexPair = /#{HexChar}#{HexChar}/
24
- HexString = /#{HexPair}+/
25
- Pair = /\\(?:[#{Special}]|\\|"|#{HexPair})/
26
- StringChar = /[^#{Special}\\"]/
27
- QuoteChar = /[^\\"]/
28
- AttributeType = /[a-zA-Z][0-9a-zA-Z]*|[0-9]+(?:\.[0-9]+)*/
29
- AttributeValue = /
30
- (?!["#])((?:#{StringChar}|#{Pair})*)|
31
- \#(#{HexString})|
32
- "((?:#{QuoteChar}|#{Pair})*)"
33
- /x
34
- TypeAndValue = /\A(#{AttributeType})=#{AttributeValue}/
35
-
36
- module_function
37
-
38
- def expand_pair(str)
39
- return nil unless str
40
- return str.gsub(Pair){
41
- pair = $&
42
- case pair.size
43
- when 2 then pair[1,1]
44
- when 3 then Integer("0x#{pair[1,2]}").chr
45
- else raise OpenSSL::X509::NameError, "invalid pair: #{str}"
46
- end
47
- }
48
- end
49
-
50
- def expand_hexstring(str)
51
- return nil unless str
52
- der = str.gsub(HexPair){$&.to_i(16).chr }
53
- a1 = OpenSSL::ASN1.decode(der)
54
- return a1.value, a1.tag
55
- end
56
-
57
- def expand_value(str1, str2, str3)
58
- value = expand_pair(str1)
59
- value, tag = expand_hexstring(str2) unless value
60
- value = expand_pair(str3) unless value
61
- return value, tag
62
- end
63
-
64
- def scan(dn)
65
- str = dn
66
- ary = []
67
- while true
68
- if md = TypeAndValue.match(str)
69
- matched = md.to_s
70
- remain = md.post_match
71
- type = md[1]
72
- value, tag = expand_value(md[2], md[3], md[4]) rescue nil
73
- if value
74
- type_and_value = [type, value]
75
- type_and_value.push(tag) if tag
76
- ary.unshift(type_and_value)
77
- if remain.length > 2 && remain[0] == ?,
78
- str = remain[1..-1]
79
- next
80
- elsif remain.length > 2 && remain[0] == ?+
81
- raise OpenSSL::X509::NameError,
82
- "multi-valued RDN is not supported: #{dn}"
83
- elsif remain.empty?
84
- break
85
- end
86
- end
87
- end
88
- msg_dn = dn[0, dn.length - str.length] + " =>" + str
89
- raise OpenSSL::X509::NameError, "malformed RDN: #{msg_dn}"
90
- end
91
- return ary
92
- end
93
- end
94
-
95
- class <<self
96
- def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE)
97
- ary = OpenSSL::X509::Name::RFC2253DN.scan(str)
98
- self.new(ary, template)
99
- end
100
-
101
- def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE)
102
- ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=", 2) }
103
- self.new(ary, template)
104
- end
105
-
106
- alias parse parse_openssl
107
- end
108
- end
109
- end
110
- end
@@ -1 +0,0 @@
1
- require 'openssl'
@@ -1,23 +0,0 @@
1
- =begin
2
- = $RCSfile$ -- Loader for all OpenSSL C-space and Ruby-space definitions
3
-
4
- = Info
5
- 'OpenSSL for Ruby 2' project
6
- Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
7
- All rights reserved.
8
-
9
- = Licence
10
- This program is licenced under the same licence as Ruby.
11
- (See the file 'LICENCE'.)
12
-
13
- = Version
14
- $Id: openssl.rb 12496 2007-06-08 15:02:04Z technorama $
15
- =end
16
-
17
- require 'openssl/bn'
18
- require 'openssl/cipher'
19
- require 'openssl/config'
20
- require 'openssl/digest'
21
- require 'openssl/pkcs7'
22
- require 'openssl/ssl-internal'
23
- require 'openssl/x509-internal'