JRuby-OpenSSL 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ == 0.1
2
+
3
+ - PLEASE NOTE: This release is not compatible with JRuby releases earlier than
4
+ 1.0.3 or 1.1b2. If you must use JRuby 1.0.2 or earlier, please install the
5
+ 0.6 release.
6
+ - Release coincides with JRuby 1.0.3 and JRuby 1.1b2 releases
7
+ - Simultaneous support for JRuby trunk and 1.0 branch
8
+ - Start of support for OpenSSL::BN
9
+
10
+ == 0.0.5 and prior
11
+
12
+ - Initial versions with maintenance updates
@@ -0,0 +1,30 @@
1
+ JRuby-OpenSSL is distributed under the same license as JRuby (http://www.jruby.org/).
2
+
3
+ Version: CPL 1.0/GPL 2.0/LGPL 2.1
4
+
5
+ The contents of this file are subject to the Common Public
6
+ License Version 1.0 (the "License"); you may not use this file
7
+ except in compliance with the License. You may obtain a copy of
8
+ the License at http://www.eclipse.org/legal/cpl-v10.html
9
+
10
+ Software distributed under the License is distributed on an "AS
11
+ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
12
+ implied. See the License for the specific language governing
13
+ rights and limitations under the License.
14
+
15
+ Copyright (C) 2007 Ola Bini <ola.bini@gmail.com>
16
+
17
+ Alternatively, the contents of this file may be used under the terms of
18
+ either of the GNU General Public License Version 2 or later (the "GPL"),
19
+ or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20
+ in which case the provisions of the GPL or the LGPL are applicable instead
21
+ of those above. If you wish to allow use of your version of this file only
22
+ under the terms of either the GPL or the LGPL, and not to allow others to
23
+ use your version of this file under the terms of the CPL, indicate your
24
+ decision by deleting the provisions above and replace them with the notice
25
+ and other provisions required by the GPL or the LGPL. If you do not delete
26
+ the provisions above, a recipient may use your version of this file under
27
+ the terms of any one of the CPL, the GPL or the LGPL.
28
+
29
+ JRuby-OpenSSL includes software by the Legion of the Bouncy Castle
30
+ (http://bouncycastle.org/license.html).
@@ -0,0 +1,18 @@
1
+ JRuby-OpenSSL is an add-on gem for JRuby that emulates the Ruby OpenSSL native library.
2
+
3
+ JRuby offers *just enough* compatibility for most Ruby applications that use OpenSSL.
4
+
5
+ Libraries that appear to work fine:
6
+
7
+ Rails, Net::HTTPS
8
+
9
+ Notable libraries that do *not* yet work include:
10
+
11
+ Net::SSH, Net::SFTP, etc.
12
+
13
+ Please report bugs and incompatibilities (preferably with testcases) to either the JRuby
14
+ mailing list [1] or the JRuby bug tracker [2].
15
+
16
+ [1]: http://xircles.codehaus.org/projects/jruby/lists
17
+
18
+ [2]: http://jira.codehaus.org/browse/JRUBY
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ module Jopenssl
2
+ module Version
3
+ VERSION = "0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ =begin
2
+ = $RCSfile: openssl.rb,v $ -- 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,v 1.1 2003/07/23 16:11:29 gotoyuzo Exp $
15
+ =end
16
+
17
+ require 'jopenssl'
18
+
19
+ require 'openssl/bn'
20
+ require 'openssl/cipher'
21
+ require 'openssl/digest'
22
+ require 'openssl/ssl'
23
+ require 'openssl/x509'
24
+
@@ -0,0 +1,35 @@
1
+ =begin
2
+ = $RCSfile: bn.rb,v $ -- Ruby-space definitions that completes C-space funcs for BN
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: bn.rb,v 1.1 2003/07/23 16:11:30 gotoyuzo Exp $
15
+ =end
16
+
17
+ ##
18
+ # Should we care what if somebody require this file directly?
19
+ #require 'openssl'
20
+
21
+ module OpenSSL
22
+ class BN
23
+ include Comparable
24
+ end # BN
25
+ end # OpenSSL
26
+
27
+ ##
28
+ # Add double dispatch to Integer
29
+ #
30
+ class Integer
31
+ def to_bn
32
+ OpenSSL::BN::new(self)
33
+ end
34
+ end # Integer
35
+
@@ -0,0 +1,239 @@
1
+ =begin
2
+ = $RCSfile: buffering.rb,v $ -- Buffering mix-in module.
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: buffering.rb,v 1.5.2.4 2005/09/04 22:03:24 gotoyuzo Exp $
15
+ =end
16
+
17
+ module Buffering
18
+ include Enumerable
19
+ attr_accessor :sync
20
+ BLOCK_SIZE = 1024*16
21
+
22
+ def initialize(*args)
23
+ @eof = false
24
+ @rbuffer = ""
25
+ @sync = @io.sync
26
+ end
27
+
28
+ #
29
+ # for reading.
30
+ #
31
+ private
32
+
33
+ def fill_rbuff
34
+ begin
35
+ @rbuffer << self.sysread(BLOCK_SIZE)
36
+ rescue Errno::EAGAIN
37
+ retry
38
+ rescue EOFError
39
+ @eof = true
40
+ end
41
+ end
42
+
43
+ def consume_rbuff(size=nil)
44
+ if @rbuffer.empty?
45
+ nil
46
+ else
47
+ size = @rbuffer.size unless size
48
+ ret = @rbuffer[0, size]
49
+ @rbuffer[0, size] = ""
50
+ ret
51
+ end
52
+ end
53
+
54
+ public
55
+
56
+ def read(size=nil, buf=nil)
57
+ if size == 0
58
+ if buf
59
+ buf.clear
60
+ else
61
+ buf = ""
62
+ end
63
+ return @eof ? nil : buf
64
+ end
65
+ until @eof
66
+ break if size && size <= @rbuffer.size
67
+ fill_rbuff
68
+ end
69
+ ret = consume_rbuff(size) || ""
70
+ if buf
71
+ buf.replace(ret)
72
+ ret = buf
73
+ end
74
+ (size && ret.empty?) ? nil : ret
75
+ end
76
+
77
+ def readpartial(maxlen, buf=nil)
78
+ if maxlen == 0
79
+ if buf
80
+ buf.clear
81
+ else
82
+ buf = ""
83
+ end
84
+ return @eof ? nil : buf
85
+ end
86
+ if @rbuffer.empty?
87
+ begin
88
+ return sysread(maxlen, buf)
89
+ rescue Errno::EAGAIN
90
+ retry
91
+ end
92
+ end
93
+ ret = consume_rbuff(maxlen)
94
+ if buf
95
+ buf.replace(ret)
96
+ ret = buf
97
+ end
98
+ raise EOFError if ret.empty?
99
+ ret
100
+ end
101
+
102
+ def gets(eol=$/)
103
+ idx = @rbuffer.index(eol)
104
+ until @eof
105
+ break if idx
106
+ fill_rbuff
107
+ idx = @rbuffer.index(eol)
108
+ end
109
+ if eol.is_a?(Regexp)
110
+ size = idx ? idx+$&.size : nil
111
+ else
112
+ size = idx ? idx+eol.size : nil
113
+ end
114
+ consume_rbuff(size)
115
+ end
116
+
117
+ def each(eol=$/)
118
+ while line = self.gets(eol)
119
+ yield line
120
+ end
121
+ end
122
+ alias each_line each
123
+
124
+ def readlines(eol=$/)
125
+ ary = []
126
+ while line = self.gets(eol)
127
+ ary << line
128
+ end
129
+ ary
130
+ end
131
+
132
+ def readline(eol=$/)
133
+ raise EOFError if eof?
134
+ gets(eol)
135
+ end
136
+
137
+ def getc
138
+ c = read(1)
139
+ c ? c[0] : nil
140
+ end
141
+
142
+ def each_byte
143
+ while c = getc
144
+ yield(c)
145
+ end
146
+ end
147
+
148
+ def readchar
149
+ raise EOFError if eof?
150
+ getc
151
+ end
152
+
153
+ def ungetc(c)
154
+ @rbuffer[0,0] = c.chr
155
+ end
156
+
157
+ def eof?
158
+ fill_rbuff if !@eof && @rbuffer.empty?
159
+ @eof && @rbuffer.empty?
160
+ end
161
+ alias eof eof?
162
+
163
+ #
164
+ # for writing.
165
+ #
166
+ private
167
+
168
+ def do_write(s)
169
+ @wbuffer = "" unless defined? @wbuffer
170
+ @wbuffer << s
171
+ @sync ||= false
172
+ if @sync or @wbuffer.size > BLOCK_SIZE or idx = @wbuffer.rindex($/)
173
+ remain = idx ? idx + $/.size : @wbuffer.length
174
+ nwritten = 0
175
+ while remain > 0
176
+ str = @wbuffer[nwritten,remain]
177
+ begin
178
+ nwrote = syswrite(str)
179
+ rescue Errno::EAGAIN
180
+ retry
181
+ end
182
+ remain -= nwrote
183
+ nwritten += nwrote
184
+ end
185
+ @wbuffer[0,nwritten] = ""
186
+ end
187
+ end
188
+
189
+ public
190
+
191
+ def write(s)
192
+ do_write(s)
193
+ s.length
194
+ end
195
+
196
+ def << (s)
197
+ do_write(s)
198
+ self
199
+ end
200
+
201
+ def puts(*args)
202
+ s = ""
203
+ if args.empty?
204
+ s << "\n"
205
+ end
206
+ args.each{|arg|
207
+ s << arg.to_s
208
+ if $/ && /\n\z/ !~ s
209
+ s << "\n"
210
+ end
211
+ }
212
+ do_write(s)
213
+ nil
214
+ end
215
+
216
+ def print(*args)
217
+ s = ""
218
+ args.each{ |arg| s << arg.to_s }
219
+ do_write(s)
220
+ nil
221
+ end
222
+
223
+ def printf(s, *args)
224
+ do_write(s % args)
225
+ nil
226
+ end
227
+
228
+ def flush
229
+ osync = @sync
230
+ @sync = true
231
+ do_write ""
232
+ @sync = osync
233
+ end
234
+
235
+ def close
236
+ flush rescue nil
237
+ sysclose
238
+ end
239
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+ = $RCSfile: cipher.rb,v $ -- Ruby-space predefined Cipher 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: cipher.rb,v 1.1.2.2 2006/06/20 11:18:15 gotoyuzo Exp $
15
+ =end
16
+
17
+ ##
18
+ # Should we care what if somebody require this file directly?
19
+ #require 'openssl'
20
+
21
+ module OpenSSL
22
+ module Cipher
23
+ %w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|name|
24
+ klass = Class.new(Cipher){
25
+ define_method(:initialize){|*args|
26
+ cipher_name = args.inject(name){|n, arg| "#{n}-#{arg}" }
27
+ super(cipher_name)
28
+ }
29
+ }
30
+ const_set(name, klass)
31
+ }
32
+
33
+ %w(128 192 256).each{|keylen|
34
+ klass = Class.new(Cipher){
35
+ define_method(:initialize){|mode|
36
+ mode ||= "CBC"
37
+ cipher_name = "AES-#{keylen}-#{mode}"
38
+ super(cipher_name)
39
+ }
40
+ }
41
+ const_set("AES#{keylen}", klass)
42
+ }
43
+
44
+ class Cipher
45
+ def random_key
46
+ str = OpenSSL::Random.random_bytes(self.key_len)
47
+ self.key = str
48
+ return str
49
+ end
50
+
51
+ def random_iv
52
+ str = OpenSSL::Random.random_bytes(self.iv_len)
53
+ self.iv = str
54
+ return str
55
+ end
56
+ end
57
+ end # Cipher
58
+ end # OpenSSL
@@ -0,0 +1,48 @@
1
+ =begin
2
+ = $RCSfile: digest.rb,v $ -- 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: digest.rb,v 1.1.2.2 2006/06/20 11:18:15 gotoyuzo Exp $
15
+ =end
16
+
17
+ ##
18
+ # Should we care what if somebody require this file directly?
19
+ #require 'openssl'
20
+
21
+ module OpenSSL
22
+ module Digest
23
+
24
+ alg = %w(DSS DSS1 MD2 MD4 MD5 MDC2 RIPEMD160 SHA SHA1)
25
+ if OPENSSL_VERSION_NUMBER > 0x00908000
26
+ alg += %w(SHA224 SHA256 SHA384 SHA512)
27
+ end
28
+ alg.each{|name|
29
+ klass = Class.new(Digest){
30
+ define_method(:initialize){|*data|
31
+ if data.length > 1
32
+ raise ArgumentError,
33
+ "wrong number of arguments (#{data.length} for 1)"
34
+ end
35
+ super(name, data.first)
36
+ }
37
+ }
38
+ singleton = (class <<klass; self; end)
39
+ singleton.class_eval{
40
+ define_method(:digest){|data| Digest.digest(name, data) }
41
+ define_method(:hexdigest){|data| Digest.hexdigest(name, data) }
42
+ }
43
+ const_set(name, klass)
44
+ }
45
+
46
+ end # Digest
47
+ end # OpenSSL
48
+