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,139 +0,0 @@
1
- #--
2
- #
3
- # $RCSfile$
4
- #
5
- # = Ruby-space definitions that completes C-space funcs for X509 and 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
- module X509
23
- class Name
24
- module RFC2253DN
25
- Special = ',=+<>#;'
26
- HexChar = /[0-9a-fA-F]/
27
- HexPair = /#{HexChar}#{HexChar}/
28
- HexString = /#{HexPair}+/
29
- Pair = /\\(?:[#{Special}]|\\|"|#{HexPair})/
30
- StringChar = /[^\\"#{Special}]/
31
- QuoteChar = /[^\\"]/
32
- AttributeType = /[a-zA-Z][0-9a-zA-Z]*|[0-9]+(?:\.[0-9]+)*/
33
- AttributeValue = /
34
- (?!["#])((?:#{StringChar}|#{Pair})*)|
35
- \#(#{HexString})|
36
- "((?:#{QuoteChar}|#{Pair})*)"
37
- /x
38
- TypeAndValue = /\A(#{AttributeType})=#{AttributeValue}/
39
-
40
- module_function
41
-
42
- def expand_pair(str)
43
- return nil unless str
44
- return str.gsub(Pair){
45
- pair = $&
46
- case pair.size
47
- when 2 then pair[1,1]
48
- when 3 then Integer("0x#{pair[1,2]}").chr
49
- else raise OpenSSL::X509::NameError, "invalid pair: #{str}"
50
- end
51
- }
52
- end
53
-
54
- def expand_hexstring(str)
55
- return nil unless str
56
- der = str.gsub(HexPair){$&.to_i(16).chr }
57
- a1 = OpenSSL::ASN1.decode(der)
58
- return a1.value, a1.tag
59
- end
60
-
61
- def expand_value(str1, str2, str3)
62
- value = expand_pair(str1)
63
- value, tag = expand_hexstring(str2) unless value
64
- value = expand_pair(str3) unless value
65
- return value, tag
66
- end
67
-
68
- def scan(dn)
69
- str = dn
70
- ary = []
71
- while true
72
- if md = TypeAndValue.match(str)
73
- remain = md.post_match
74
- type = md[1]
75
- value, tag = expand_value(md[2], md[3], md[4]) rescue nil
76
- if value
77
- type_and_value = [type, value]
78
- type_and_value.push(tag) if tag
79
- ary.unshift(type_and_value)
80
- if remain.length > 2 && remain[0] == ?,
81
- str = remain[1..-1]
82
- next
83
- elsif remain.length > 2 && remain[0] == ?+
84
- raise OpenSSL::X509::NameError,
85
- "multi-valued RDN is not supported: #{dn}"
86
- elsif remain.empty?
87
- break
88
- end
89
- end
90
- end
91
- msg_dn = dn[0, dn.length - str.length] + " =>" + str
92
- raise OpenSSL::X509::NameError, "malformed RDN: #{msg_dn}"
93
- end
94
- return ary
95
- end
96
- end
97
-
98
- class << self
99
- def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE)
100
- ary = OpenSSL::X509::Name::RFC2253DN.scan(str)
101
- self.new(ary, template)
102
- end
103
-
104
- def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE)
105
- ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=", 2) }
106
- self.new(ary, template)
107
- end
108
-
109
- alias parse parse_openssl
110
- end
111
-
112
- def pretty_print(q)
113
- q.object_group(self) {
114
- q.text ' '
115
- q.text to_s(OpenSSL::X509::Name::RFC2253)
116
- }
117
- end
118
- end
119
-
120
- class StoreContext
121
- def cleanup
122
- warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE
123
- end
124
- end
125
-
126
- class Certificate
127
- def pretty_print(q)
128
- q.object_group(self) {
129
- q.breakable
130
- q.text 'subject='; q.pp self.subject; q.text ','; q.breakable
131
- q.text 'issuer='; q.pp self.issuer; q.text ','; q.breakable
132
- q.text 'serial='; q.pp self.serial; q.text ','; q.breakable
133
- q.text 'not_before='; q.pp self.not_before; q.text ','; q.breakable
134
- q.text 'not_after='; q.pp self.not_after
135
- }
136
- end
137
- end
138
- end
139
- end
@@ -1,22 +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$
15
- =end
16
-
17
- require 'openssl/bn'
18
- require 'openssl/cipher'
19
- require 'openssl/config'
20
- require 'openssl/digest'
21
- require 'openssl/x509'
22
- require 'openssl/ssl'
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: false
2
- #--
3
- #
4
- # = Ruby-space definitions that completes C-space funcs for BN
5
- #
6
- # = Info
7
- # 'OpenSSL for Ruby 2' project
8
- # Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
9
- # All rights reserved.
10
- #
11
- # = Licence
12
- # This program is licensed under the same licence as Ruby.
13
- # (See the file 'LICENCE'.)
14
- #++
15
-
16
- module OpenSSL
17
- class BN
18
- def pretty_print(q)
19
- q.object_group(self) {
20
- q.text ' '
21
- q.text to_i.to_s
22
- }
23
- end
24
- end # BN
25
- end # OpenSSL
26
-
27
- ##
28
- #--
29
- # Add double dispatch to Integer
30
- #++
31
- class Integer
32
- # Casts an Integer as an OpenSSL::BN
33
- #
34
- # See `man bn` for more info.
35
- def to_bn
36
- OpenSSL::BN::new(self)
37
- end
38
- end # Integer
@@ -1,455 +0,0 @@
1
- # coding: binary
2
- # frozen_string_literal: false
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 licensed under the same licence as Ruby.
11
- # (See the file 'LICENCE'.)
12
- #++
13
-
14
- ##
15
- # OpenSSL IO buffering mix-in module.
16
- #
17
- # This module allows an OpenSSL::SSL::SSLSocket to behave like an IO.
18
- #
19
- # You typically won't use this module directly, you can see it implemented in
20
- # OpenSSL::SSL::SSLSocket.
21
-
22
- module OpenSSL::Buffering
23
- include Enumerable
24
-
25
- ##
26
- # The "sync mode" of the SSLSocket.
27
- #
28
- # See IO#sync for full details.
29
-
30
- attr_accessor :sync
31
-
32
- ##
33
- # Default size to read from or write to the SSLSocket for buffer operations.
34
-
35
- BLOCK_SIZE = 1024*16
36
-
37
- ##
38
- # Creates an instance of OpenSSL's buffering IO module.
39
-
40
- def initialize(*)
41
- # super
42
- @eof = false
43
- @rbuffer = ""
44
- @sync = @io.sync
45
- end
46
-
47
- #
48
- # for reading.
49
- #
50
- private
51
-
52
- ##
53
- # Fills the buffer from the underlying SSLSocket
54
-
55
- def fill_rbuff
56
- begin
57
- @rbuffer << self.sysread(BLOCK_SIZE)
58
- rescue Errno::EAGAIN
59
- retry
60
- rescue EOFError
61
- @eof = true
62
- end
63
- end
64
-
65
- ##
66
- # Consumes _size_ bytes from the buffer
67
-
68
- def consume_rbuff(size=nil)
69
- if @rbuffer.empty?
70
- nil
71
- else
72
- size = @rbuffer.size unless size
73
- ret = @rbuffer[0, size]
74
- @rbuffer[0, size] = ""
75
- ret
76
- end
77
- end
78
-
79
- public
80
-
81
- ##
82
- # Reads _size_ bytes from the stream. If _buf_ is provided it must
83
- # reference a string which will receive the data.
84
- #
85
- # See IO#read for full details.
86
-
87
- def read(size=nil, buf=nil)
88
- if size == 0
89
- if buf
90
- buf.clear
91
- return buf
92
- else
93
- return ""
94
- end
95
- end
96
- until @eof
97
- break if size && size <= @rbuffer.size
98
- fill_rbuff
99
- end
100
- ret = consume_rbuff(size) || ""
101
- if buf
102
- buf.replace(ret)
103
- ret = buf
104
- end
105
- (size && ret.empty?) ? nil : ret
106
- end
107
-
108
- ##
109
- # Reads at most _maxlen_ bytes from the stream. If _buf_ is provided it
110
- # must reference a string which will receive the data.
111
- #
112
- # See IO#readpartial for full details.
113
-
114
- def readpartial(maxlen, buf=nil)
115
- if maxlen == 0
116
- if buf
117
- buf.clear
118
- return buf
119
- else
120
- return ""
121
- end
122
- end
123
- if @rbuffer.empty?
124
- begin
125
- return sysread(maxlen, buf)
126
- rescue Errno::EAGAIN
127
- retry
128
- end
129
- end
130
- ret = consume_rbuff(maxlen)
131
- if buf
132
- buf.replace(ret)
133
- ret = buf
134
- end
135
- ret
136
- end
137
-
138
- ##
139
- # Reads at most _maxlen_ bytes in the non-blocking manner.
140
- #
141
- # When no data can be read without blocking it raises
142
- # OpenSSL::SSL::SSLError extended by IO::WaitReadable or IO::WaitWritable.
143
- #
144
- # IO::WaitReadable means SSL needs to read internally so read_nonblock
145
- # should be called again when the underlying IO is readable.
146
- #
147
- # IO::WaitWritable means SSL needs to write internally so read_nonblock
148
- # should be called again after the underlying IO is writable.
149
- #
150
- # OpenSSL::Buffering#read_nonblock needs two rescue clause as follows:
151
- #
152
- # # emulates blocking read (readpartial).
153
- # begin
154
- # result = ssl.read_nonblock(maxlen)
155
- # rescue IO::WaitReadable
156
- # IO.select([io])
157
- # retry
158
- # rescue IO::WaitWritable
159
- # IO.select(nil, [io])
160
- # retry
161
- # end
162
- #
163
- # Note that one reason that read_nonblock writes to the underlying IO is
164
- # when the peer requests a new TLS/SSL handshake. See openssl the FAQ for
165
- # more details. http://www.openssl.org/support/faq.html
166
- #
167
- # By specifying a keyword argument _exception_ to +false+, you can indicate
168
- # that read_nonblock should not raise an IO::Wait*able exception, but
169
- # return the symbol +:wait_writable+ or +:wait_readable+ instead. At EOF,
170
- # it will return +nil+ instead of raising EOFError.
171
-
172
- def read_nonblock(maxlen, buf=nil, exception: true)
173
- if maxlen == 0
174
- if buf
175
- buf.clear
176
- return buf
177
- else
178
- return ""
179
- end
180
- end
181
- if @rbuffer.empty?
182
- return sysread_nonblock(maxlen, buf, exception: exception)
183
- end
184
- ret = consume_rbuff(maxlen)
185
- if buf
186
- buf.replace(ret)
187
- ret = buf
188
- end
189
- ret
190
- end
191
-
192
- ##
193
- # Reads the next "line" from the stream. Lines are separated by _eol_. If
194
- # _limit_ is provided the result will not be longer than the given number of
195
- # bytes.
196
- #
197
- # _eol_ may be a String or Regexp.
198
- #
199
- # Unlike IO#gets the line read will not be assigned to +$_+.
200
- #
201
- # Unlike IO#gets the separator must be provided if a limit is provided.
202
-
203
- def gets(eol=$/, limit=nil)
204
- idx = @rbuffer.index(eol)
205
- until @eof
206
- break if idx
207
- fill_rbuff
208
- idx = @rbuffer.index(eol)
209
- end
210
- if eol.is_a?(Regexp)
211
- size = idx ? idx+$&.size : nil
212
- else
213
- size = idx ? idx+eol.size : nil
214
- end
215
- if size && limit && limit >= 0
216
- size = [size, limit].min
217
- end
218
- consume_rbuff(size)
219
- end
220
-
221
- ##
222
- # Executes the block for every line in the stream where lines are separated
223
- # by _eol_.
224
- #
225
- # See also #gets
226
-
227
- def each(eol=$/)
228
- while line = self.gets(eol)
229
- yield line
230
- end
231
- end
232
- alias each_line each
233
-
234
- ##
235
- # Reads lines from the stream which are separated by _eol_.
236
- #
237
- # See also #gets
238
-
239
- def readlines(eol=$/)
240
- ary = []
241
- while line = self.gets(eol)
242
- ary << line
243
- end
244
- ary
245
- end
246
-
247
- ##
248
- # Reads a line from the stream which is separated by _eol_.
249
- #
250
- # Raises EOFError if at end of file.
251
-
252
- def readline(eol=$/)
253
- raise EOFError if eof?
254
- gets(eol)
255
- end
256
-
257
- ##
258
- # Reads one character from the stream. Returns nil if called at end of
259
- # file.
260
-
261
- def getc
262
- read(1)
263
- end
264
-
265
- ##
266
- # Calls the given block once for each byte in the stream.
267
-
268
- def each_byte # :yields: byte
269
- while c = getc
270
- yield(c.ord)
271
- end
272
- end
273
-
274
- ##
275
- # Reads a one-character string from the stream. Raises an EOFError at end
276
- # of file.
277
-
278
- def readchar
279
- raise EOFError if eof?
280
- getc
281
- end
282
-
283
- ##
284
- # Pushes character _c_ back onto the stream such that a subsequent buffered
285
- # character read will return it.
286
- #
287
- # Unlike IO#getc multiple bytes may be pushed back onto the stream.
288
- #
289
- # Has no effect on unbuffered reads (such as #sysread).
290
-
291
- def ungetc(c)
292
- @rbuffer[0,0] = c.chr
293
- end
294
-
295
- ##
296
- # Returns true if the stream is at file which means there is no more data to
297
- # be read.
298
-
299
- def eof?
300
- fill_rbuff if !@eof && @rbuffer.empty?
301
- @eof && @rbuffer.empty?
302
- end
303
- alias eof eof?
304
-
305
- #
306
- # for writing.
307
- #
308
- private
309
-
310
- ##
311
- # Writes _s_ to the buffer. When the buffer is full or #sync is true the
312
- # buffer is flushed to the underlying socket.
313
-
314
- def do_write(s)
315
- @wbuffer = "" unless defined? @wbuffer
316
- @wbuffer << s
317
- @wbuffer.force_encoding(Encoding::BINARY)
318
- @sync ||= false
319
- if @sync or @wbuffer.size > BLOCK_SIZE
320
- until @wbuffer.empty?
321
- begin
322
- nwrote = syswrite(@wbuffer)
323
- rescue Errno::EAGAIN
324
- retry
325
- end
326
- @wbuffer[0, nwrote] = ""
327
- end
328
- end
329
- end
330
-
331
- public
332
-
333
- ##
334
- # Writes _s_ to the stream. If the argument is not a String it will be
335
- # converted using +.to_s+ method. Returns the number of bytes written.
336
-
337
- def write(*s)
338
- s.inject(0) do |written, str|
339
- do_write(str)
340
- written + str.bytesize
341
- end
342
- end
343
-
344
- ##
345
- # Writes _s_ in the non-blocking manner.
346
- #
347
- # If there is buffered data, it is flushed first. This may block.
348
- #
349
- # write_nonblock returns number of bytes written to the SSL connection.
350
- #
351
- # When no data can be written without blocking it raises
352
- # OpenSSL::SSL::SSLError extended by IO::WaitReadable or IO::WaitWritable.
353
- #
354
- # IO::WaitReadable means SSL needs to read internally so write_nonblock
355
- # should be called again after the underlying IO is readable.
356
- #
357
- # IO::WaitWritable means SSL needs to write internally so write_nonblock
358
- # should be called again after underlying IO is writable.
359
- #
360
- # So OpenSSL::Buffering#write_nonblock needs two rescue clause as follows.
361
- #
362
- # # emulates blocking write.
363
- # begin
364
- # result = ssl.write_nonblock(str)
365
- # rescue IO::WaitReadable
366
- # IO.select([io])
367
- # retry
368
- # rescue IO::WaitWritable
369
- # IO.select(nil, [io])
370
- # retry
371
- # end
372
- #
373
- # Note that one reason that write_nonblock reads from the underlying IO
374
- # is when the peer requests a new TLS/SSL handshake. See the openssl FAQ
375
- # for more details. http://www.openssl.org/support/faq.html
376
- #
377
- # By specifying a keyword argument _exception_ to +false+, you can indicate
378
- # that write_nonblock should not raise an IO::Wait*able exception, but
379
- # return the symbol +:wait_writable+ or +:wait_readable+ instead.
380
-
381
- def write_nonblock(s, exception: true)
382
- flush
383
- syswrite_nonblock(s, exception: exception)
384
- end
385
-
386
- ##
387
- # Writes _s_ to the stream. _s_ will be converted to a String using
388
- # +.to_s+ method.
389
-
390
- def <<(s)
391
- do_write(s)
392
- self
393
- end
394
-
395
- ##
396
- # Writes _args_ to the stream along with a record separator.
397
- #
398
- # See IO#puts for full details.
399
-
400
- def puts(*args)
401
- s = ""
402
- if args.empty?
403
- s << "\n"
404
- end
405
- args.each{|arg|
406
- s << arg.to_s
407
- s.sub!(/(?<!\n)\z/, "\n")
408
- }
409
- do_write(s)
410
- nil
411
- end
412
-
413
- ##
414
- # Writes _args_ to the stream.
415
- #
416
- # See IO#print for full details.
417
-
418
- def print(*args)
419
- s = ""
420
- args.each{ |arg| s << arg.to_s }
421
- do_write(s)
422
- nil
423
- end
424
-
425
- ##
426
- # Formats and writes to the stream converting parameters under control of
427
- # the format string.
428
- #
429
- # See Kernel#sprintf for format string details.
430
-
431
- def printf(s, *args)
432
- do_write(s % args)
433
- nil
434
- end
435
-
436
- ##
437
- # Flushes buffered data to the SSLSocket.
438
-
439
- def flush
440
- osync = @sync
441
- @sync = true
442
- do_write ""
443
- return self
444
- ensure
445
- @sync = osync
446
- end
447
-
448
- ##
449
- # Closes the SSLSocket and flushes any unwritten data.
450
-
451
- def close
452
- flush rescue nil
453
- sysclose
454
- end
455
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: false
2
- #--
3
- # = Ruby-space predefined Cipher subclasses
4
- #
5
- # = Info
6
- # 'OpenSSL for Ruby 2' project
7
- # Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
8
- # All rights reserved.
9
- #
10
- # = Licence
11
- # This program is licensed under the same licence as Ruby.
12
- # (See the file 'LICENCE'.)
13
- #++
14
-
15
- module OpenSSL
16
- class Cipher
17
-
18
- # Deprecated.
19
- #
20
- # This class is only provided for backwards compatibility.
21
- # Use OpenSSL::Cipher.
22
- class Cipher < Cipher; end
23
- deprecate_constant :Cipher
24
- end # Cipher
25
- end # OpenSSL