jruby-openssl 0.11.0-java → 0.12.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +20 -0
  3. data/Mavenfile +21 -26
  4. data/README.md +3 -0
  5. data/Rakefile +21 -35
  6. data/lib/jopenssl/load.rb +0 -14
  7. data/lib/jopenssl/version.rb +1 -1
  8. data/lib/jopenssl.jar +0 -0
  9. data/lib/openssl/bn.rb +40 -9
  10. data/lib/openssl/buffering.rb +478 -9
  11. data/lib/openssl/cipher.rb +67 -9
  12. data/lib/openssl/config.rb +496 -12
  13. data/lib/openssl/digest.rb +73 -9
  14. data/lib/openssl/hmac.rb +13 -0
  15. data/lib/openssl/marshal.rb +30 -0
  16. data/lib/openssl/pkcs5.rb +3 -3
  17. data/lib/openssl/pkey.rb +42 -5
  18. data/lib/openssl/ssl.rb +543 -9
  19. data/lib/openssl/x509.rb +369 -9
  20. data/lib/openssl.rb +43 -1
  21. data/pom.xml +35 -127
  22. metadata +8 -42
  23. data/lib/jopenssl19/openssl/bn.rb +0 -29
  24. data/lib/jopenssl19/openssl/buffering.rb +0 -449
  25. data/lib/jopenssl19/openssl/cipher.rb +0 -28
  26. data/lib/jopenssl19/openssl/config.rb +0 -472
  27. data/lib/jopenssl19/openssl/digest.rb +0 -32
  28. data/lib/jopenssl19/openssl/ssl-internal.rb +0 -223
  29. data/lib/jopenssl19/openssl/ssl.rb +0 -2
  30. data/lib/jopenssl19/openssl/x509-internal.rb +0 -115
  31. data/lib/jopenssl19/openssl/x509.rb +0 -2
  32. data/lib/jopenssl19/openssl.rb +0 -22
  33. data/lib/jopenssl21/openssl/bn.rb +0 -28
  34. data/lib/jopenssl21/openssl/buffering.rb +0 -1
  35. data/lib/jopenssl21/openssl/cipher.rb +0 -1
  36. data/lib/jopenssl21/openssl/config.rb +0 -1
  37. data/lib/jopenssl21/openssl/digest.rb +0 -1
  38. data/lib/jopenssl21/openssl/ssl.rb +0 -1
  39. data/lib/jopenssl21/openssl/x509.rb +0 -119
  40. data/lib/jopenssl21/openssl.rb +0 -22
  41. data/lib/jopenssl22/openssl/bn.rb +0 -39
  42. data/lib/jopenssl22/openssl/buffering.rb +0 -456
  43. data/lib/jopenssl22/openssl/cipher.rb +0 -28
  44. data/lib/jopenssl22/openssl/config.rb +0 -313
  45. data/lib/jopenssl22/openssl/digest.rb +0 -54
  46. data/lib/jopenssl22/openssl/ssl.rb +0 -330
  47. data/lib/jopenssl22/openssl/x509.rb +0 -139
  48. data/lib/jopenssl22/openssl.rb +0 -22
  49. data/lib/jopenssl23/openssl/bn.rb +0 -38
  50. data/lib/jopenssl23/openssl/buffering.rb +0 -455
  51. data/lib/jopenssl23/openssl/cipher.rb +0 -25
  52. data/lib/jopenssl23/openssl/config.rb +0 -474
  53. data/lib/jopenssl23/openssl/digest.rb +0 -43
  54. data/lib/jopenssl23/openssl/pkey.rb +0 -25
  55. data/lib/jopenssl23/openssl/ssl.rb +0 -508
  56. data/lib/jopenssl23/openssl/x509.rb +0 -208
  57. data/lib/jopenssl23/openssl.rb +0 -19
  58. data/lib/openssl/ssl-internal.rb +0 -5
  59. data/lib/openssl/x509-internal.rb +0 -5
@@ -1,472 +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
- require 'stringio'
14
-
15
- module OpenSSL
16
- ##
17
- # = OpenSSL::Config
18
- #
19
- # Configuration for the openssl library.
20
- #
21
- # Many system's installation of openssl library will depend on your system
22
- # configuration. See the value of OpenSSL::Config::DEFAULT_CONFIG_FILE for
23
- # the location of the file for your host.
24
- #
25
- # See also http://www.openssl.org/docs/apps/config.html
26
- class Config
27
- include Enumerable
28
-
29
- class << self
30
-
31
- ##
32
- # Parses a given +string+ as a blob that contains configuration for openssl.
33
- #
34
- # If the source of the IO is a file, then consider using #parse_config.
35
- def parse(string)
36
- c = new()
37
- parse_config(StringIO.new(string)).each do |section, hash|
38
- c[section] = hash
39
- end
40
- c
41
- end
42
-
43
- ##
44
- # load is an alias to ::new
45
- alias load new
46
-
47
- ##
48
- # Parses the configuration data read from +io+, see also #parse.
49
- #
50
- # Raises a ConfigError on invalid configuration data.
51
- def parse_config(io)
52
- begin
53
- parse_config_lines(io)
54
- rescue ConfigError => e
55
- e.message.replace("error in line #{io.lineno}: " + e.message)
56
- raise
57
- end
58
- end
59
-
60
- def get_key_string(data, section, key) # :nodoc:
61
- if v = data[section] && data[section][key]
62
- return v
63
- elsif section == 'ENV'
64
- if v = ENV[key]
65
- return v
66
- end
67
- end
68
- if v = data['default'] && data['default'][key]
69
- return v
70
- end
71
- end
72
-
73
- private
74
-
75
- def parse_config_lines(io)
76
- section = 'default'
77
- data = {section => {}}
78
- while definition = get_definition(io)
79
- definition = clear_comments(definition)
80
- next if definition.empty?
81
- if definition[0] == ?[
82
- if /\[([^\]]*)\]/ =~ definition
83
- section = $1.strip
84
- data[section] ||= {}
85
- else
86
- raise ConfigError, "missing close square bracket"
87
- end
88
- else
89
- if /\A([^:\s]*)(?:::([^:\s]*))?\s*=(.*)\z/ =~ definition
90
- if $2
91
- section = $1
92
- key = $2
93
- else
94
- key = $1
95
- end
96
- value = unescape_value(data, section, $3)
97
- (data[section] ||= {})[key] = value.strip
98
- else
99
- raise ConfigError, "missing equal sign"
100
- end
101
- end
102
- end
103
- data
104
- end
105
-
106
- # escape with backslash
107
- QUOTE_REGEXP_SQ = /\A([^'\\]*(?:\\.[^'\\]*)*)'/
108
- # escape with backslash and doubled dq
109
- QUOTE_REGEXP_DQ = /\A([^"\\]*(?:""[^"\\]*|\\.[^"\\]*)*)"/
110
- # escaped char map
111
- ESCAPE_MAP = {
112
- "r" => "\r",
113
- "n" => "\n",
114
- "b" => "\b",
115
- "t" => "\t",
116
- }
117
-
118
- def unescape_value(data, section, value)
119
- scanned = []
120
- while m = value.match(/['"\\$]/)
121
- scanned << m.pre_match
122
- c = m[0]
123
- value = m.post_match
124
- case c
125
- when "'"
126
- if m = value.match(QUOTE_REGEXP_SQ)
127
- scanned << m[1].gsub(/\\(.)/, '\\1')
128
- value = m.post_match
129
- else
130
- break
131
- end
132
- when '"'
133
- if m = value.match(QUOTE_REGEXP_DQ)
134
- scanned << m[1].gsub(/""/, '').gsub(/\\(.)/, '\\1')
135
- value = m.post_match
136
- else
137
- break
138
- end
139
- when "\\"
140
- c = value.slice!(0, 1)
141
- scanned << (ESCAPE_MAP[c] || c)
142
- when "$"
143
- ref, value = extract_reference(value)
144
- refsec = section
145
- if ref.index('::')
146
- refsec, ref = ref.split('::', 2)
147
- end
148
- if v = get_key_string(data, refsec, ref)
149
- scanned << v
150
- else
151
- raise ConfigError, "variable has no value"
152
- end
153
- else
154
- raise 'must not reaced'
155
- end
156
- end
157
- scanned << value
158
- scanned.join
159
- end
160
-
161
- def extract_reference(value)
162
- rest = ''
163
- if m = value.match(/\(([^)]*)\)|\{([^}]*)\}/)
164
- value = m[1] || m[2]
165
- rest = m.post_match
166
- elsif [?(, ?{].include?(value[0])
167
- raise ConfigError, "no close brace"
168
- end
169
- if m = value.match(/[a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]*)?/)
170
- return m[0], m.post_match + rest
171
- else
172
- raise
173
- end
174
- end
175
-
176
- def clear_comments(line)
177
- # FCOMMENT
178
- if m = line.match(/\A([\t\n\f ]*);.*\z/)
179
- return m[1]
180
- end
181
- # COMMENT
182
- scanned = []
183
- while m = line.match(/[#'"\\]/)
184
- scanned << m.pre_match
185
- c = m[0]
186
- line = m.post_match
187
- case c
188
- when '#'
189
- line = nil
190
- break
191
- when "'", '"'
192
- regexp = (c == "'") ? QUOTE_REGEXP_SQ : QUOTE_REGEXP_DQ
193
- scanned << c
194
- if m = line.match(regexp)
195
- scanned << m[0]
196
- line = m.post_match
197
- else
198
- scanned << line
199
- line = nil
200
- break
201
- end
202
- when "\\"
203
- scanned << c
204
- scanned << line.slice!(0, 1)
205
- else
206
- raise 'must not reaced'
207
- end
208
- end
209
- scanned << line
210
- scanned.join
211
- end
212
-
213
- def get_definition(io)
214
- if line = get_line(io)
215
- while /[^\\]\\\z/ =~ line
216
- if extra = get_line(io)
217
- line += extra
218
- else
219
- break
220
- end
221
- end
222
- return line.strip
223
- end
224
- end
225
-
226
- def get_line(io)
227
- if line = io.gets
228
- line.gsub(/[\r\n]*/, '')
229
- end
230
- end
231
- end
232
-
233
- ##
234
- # Creates an instance of OpenSSL's configuration class.
235
- #
236
- # This can be used in contexts like OpenSSL::X509::ExtensionFactory.config=
237
- #
238
- # If the optional +filename+ parameter is provided, then it is read in and
239
- # parsed via #parse_config.
240
- #
241
- # This can raise IO exceptions based on the access, or availability of the
242
- # file. A ConfigError exception may be raised depending on the validity of
243
- # the data being configured.
244
- #
245
- def initialize(filename = nil)
246
- @data = {}
247
- if filename
248
- File.open(filename.to_s) do |file|
249
- Config.parse_config(file).each do |section, hash|
250
- self[section] = hash
251
- end
252
- end
253
- end
254
- end
255
-
256
- ##
257
- # Gets the value of +key+ from the given +section+
258
- #
259
- # Given the following configurating file being loaded:
260
- #
261
- # config = OpenSSL::Config.load('foo.cnf')
262
- # #=> #<OpenSSL::Config sections=["default"]>
263
- # puts config.to_s
264
- # #=> [ default ]
265
- # # foo=bar
266
- #
267
- # You can get a specific value from the config if you know the +section+
268
- # and +key+ like so:
269
- #
270
- # config.get_value('default','foo')
271
- # #=> "bar"
272
- #
273
- def get_value(section, key)
274
- if section.nil?
275
- raise TypeError.new('nil not allowed')
276
- end
277
- section = 'default' if section.empty?
278
- get_key_string(section, key)
279
- end
280
-
281
- ##
282
- #
283
- # *Deprecated*
284
- #
285
- # Use #get_value instead
286
- def value(arg1, arg2 = nil) # :nodoc:
287
- warn('Config#value is deprecated; use Config#get_value')
288
- if arg2.nil?
289
- section, key = 'default', arg1
290
- else
291
- section, key = arg1, arg2
292
- end
293
- section ||= 'default'
294
- section = 'default' if section.empty?
295
- get_key_string(section, key)
296
- end
297
-
298
- ##
299
- # Set the target +key+ with a given +value+ under a specific +section+.
300
- #
301
- # Given the following configurating file being loaded:
302
- #
303
- # config = OpenSSL::Config.load('foo.cnf')
304
- # #=> #<OpenSSL::Config sections=["default"]>
305
- # puts config.to_s
306
- # #=> [ default ]
307
- # # foo=bar
308
- #
309
- # You can set the value of +foo+ under the +default+ section to a new
310
- # value:
311
- #
312
- # config.add_value('default', 'foo', 'buzz')
313
- # #=> "buzz"
314
- # puts config.to_s
315
- # #=> [ default ]
316
- # # foo=buzz
317
- #
318
- def add_value(section, key, value)
319
- check_modify
320
- (@data[section] ||= {})[key] = value
321
- end
322
-
323
- ##
324
- # Get a specific +section+ from the current configuration
325
- #
326
- # Given the following configurating file being loaded:
327
- #
328
- # config = OpenSSL::Config.load('foo.cnf')
329
- # #=> #<OpenSSL::Config sections=["default"]>
330
- # puts config.to_s
331
- # #=> [ default ]
332
- # # foo=bar
333
- #
334
- # You can get a hash of the specific section like so:
335
- #
336
- # config['default']
337
- # #=> {"foo"=>"bar"}
338
- #
339
- def [](section)
340
- @data[section] || {}
341
- end
342
-
343
- ##
344
- # Deprecated
345
- #
346
- # Use #[] instead
347
- def section(name) # :nodoc:
348
- warn('Config#section is deprecated; use Config#[]')
349
- @data[name] || {}
350
- end
351
-
352
- ##
353
- # Sets a specific +section+ name with a Hash +pairs+
354
- #
355
- # Given the following configuration being created:
356
- #
357
- # config = OpenSSL::Config.new
358
- # #=> #<OpenSSL::Config sections=[]>
359
- # config['default'] = {"foo"=>"bar","baz"=>"buz"}
360
- # #=> {"foo"=>"bar", "baz"=>"buz"}
361
- # puts config.to_s
362
- # #=> [ default ]
363
- # # foo=bar
364
- # # baz=buz
365
- #
366
- # It's important to note that this will essentially merge any of the keys
367
- # in +pairs+ with the existing +section+. For example:
368
- #
369
- # config['default']
370
- # #=> {"foo"=>"bar", "baz"=>"buz"}
371
- # config['default'] = {"foo" => "changed"}
372
- # #=> {"foo"=>"changed"}
373
- # config['default']
374
- # #=> {"foo"=>"changed", "baz"=>"buz"}
375
- #
376
- def []=(section, pairs)
377
- check_modify
378
- @data[section] ||= {}
379
- pairs.each do |key, value|
380
- self.add_value(section, key, value)
381
- end
382
- end
383
-
384
- ##
385
- # Get the names of all sections in the current configuration
386
- def sections
387
- @data.keys
388
- end
389
-
390
- ##
391
- # Get the parsable form of the current configuration
392
- #
393
- # Given the following configuration being created:
394
- #
395
- # config = OpenSSL::Config.new
396
- # #=> #<OpenSSL::Config sections=[]>
397
- # config['default'] = {"foo"=>"bar","baz"=>"buz"}
398
- # #=> {"foo"=>"bar", "baz"=>"buz"}
399
- # puts config.to_s
400
- # #=> [ default ]
401
- # # foo=bar
402
- # # baz=buz
403
- #
404
- # You can parse get the serialized configuration using #to_s and then parse
405
- # it later:
406
- #
407
- # serialized_config = config.to_s
408
- # # much later...
409
- # new_config = OpenSSL::Config.parse(serialized_config)
410
- # #=> #<OpenSSL::Config sections=["default"]>
411
- # puts new_config
412
- # #=> [ default ]
413
- # foo=bar
414
- # baz=buz
415
- #
416
- def to_s
417
- ary = []
418
- @data.keys.sort.each do |section|
419
- ary << "[ #{section} ]\n"
420
- @data[section].keys.each do |key|
421
- ary << "#{key}=#{@data[section][key]}\n"
422
- end
423
- ary << "\n"
424
- end
425
- ary.join
426
- end
427
-
428
- ##
429
- # For a block.
430
- #
431
- # Receive the section and its pairs for the current configuration.
432
- #
433
- # config.each do |section, key, value|
434
- # # ...
435
- # end
436
- #
437
- def each
438
- @data.each do |section, hash|
439
- hash.each do |key, value|
440
- yield [section, key, value]
441
- end
442
- end
443
- end
444
-
445
- ##
446
- # String representation of this configuration object, including the class
447
- # name and its sections.
448
- def inspect
449
- "#<#{self.class.name} sections=#{sections.inspect}>"
450
- end
451
-
452
- protected
453
-
454
- def data # :nodoc:
455
- @data
456
- end
457
-
458
- private
459
-
460
- def initialize_copy(other)
461
- @data = other.data.dup
462
- end
463
-
464
- def check_modify
465
- raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen?
466
- end
467
-
468
- def get_key_string(section, key)
469
- Config.get_key_string(@data, section, key)
470
- end
471
- end
472
- end
@@ -1,32 +0,0 @@
1
- #--
2
- #
3
- # $RCSfile$
4
- #
5
- # = Ruby-space predefined Digest subclasses
6
- #
7
- # = Info
8
- # 'OpenSSL for Ruby 2' project
9
- # Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
10
- # All rights reserved.
11
- #
12
- # = Licence
13
- # This program is licenced under the same licence as Ruby.
14
- # (See the file 'LICENCE'.)
15
- #
16
- # = Version
17
- # $Id$
18
- #
19
- #++
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
-