Skip to content

Commit 197b840

Browse files
committed
review openssl rb parts (based on MRI 2.6)
1 parent 0127052 commit 197b840

File tree

3 files changed

+137
-60
lines changed

3 files changed

+137
-60
lines changed

lib/jopenssl23/openssl/buffering.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,15 @@ def do_write(s)
316316
@wbuffer << s
317317
@wbuffer.force_encoding(Encoding::BINARY)
318318
@sync ||= false
319-
if @sync or @wbuffer.size > BLOCK_SIZE or idx = @wbuffer.rindex($/)
320-
remain = idx ? idx + $/.size : @wbuffer.length
321-
nwritten = 0
322-
while remain > 0
323-
str = @wbuffer[nwritten,remain]
319+
if @sync or @wbuffer.size > BLOCK_SIZE
320+
until @wbuffer.empty?
324321
begin
325-
nwrote = syswrite(str)
322+
nwrote = syswrite(@wbuffer)
326323
rescue Errno::EAGAIN
327324
retry
328325
end
329-
remain -= nwrote
330-
nwritten += nwrote
326+
@wbuffer[0, nwrote] = ""
331327
end
332-
@wbuffer[0,nwritten] = ""
333328
end
334329
end
335330

@@ -409,9 +404,7 @@ def puts(*args)
409404
end
410405
args.each{|arg|
411406
s << arg.to_s
412-
if $/ && /\n\z/ !~ s
413-
s << "\n"
414-
end
407+
s.sub!(/(?<!\n)\z/, "\n")
415408
}
416409
do_write(s)
417410
nil

lib/jopenssl23/openssl/ssl.rb

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,55 @@ module OpenSSL
1717
module SSL
1818
class SSLContext
1919
unless const_defined? :DEFAULT_PARAMS # JRuby does it in Java
20-
DEFAULT_PARAMS = { # :nodoc:
21-
:min_version => OpenSSL::SSL::TLS1_VERSION,
22-
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
23-
:verify_hostname => true,
24-
:options => -> {
25-
opts = OpenSSL::SSL::OP_ALL
26-
opts &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS
27-
opts |= OpenSSL::SSL::OP_NO_COMPRESSION
28-
opts
29-
}.call
30-
}
20+
DEFAULT_PARAMS = { # :nodoc:
21+
:min_version => OpenSSL::SSL::TLS1_VERSION,
22+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
23+
:verify_hostname => true,
24+
:options => -> {
25+
opts = OpenSSL::SSL::OP_ALL
26+
opts &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS
27+
opts |= OpenSSL::SSL::OP_NO_COMPRESSION
28+
opts
29+
}.call
30+
}
3131

32-
if !(OpenSSL::OPENSSL_VERSION.start_with?("OpenSSL") &&
33-
OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000)
34-
DEFAULT_PARAMS.merge!(
35-
ciphers: %w{
36-
ECDHE-ECDSA-AES128-GCM-SHA256
37-
ECDHE-RSA-AES128-GCM-SHA256
38-
ECDHE-ECDSA-AES256-GCM-SHA384
39-
ECDHE-RSA-AES256-GCM-SHA384
40-
DHE-RSA-AES128-GCM-SHA256
41-
DHE-DSS-AES128-GCM-SHA256
42-
DHE-RSA-AES256-GCM-SHA384
43-
DHE-DSS-AES256-GCM-SHA384
44-
ECDHE-ECDSA-AES128-SHA256
45-
ECDHE-RSA-AES128-SHA256
46-
ECDHE-ECDSA-AES128-SHA
47-
ECDHE-RSA-AES128-SHA
48-
ECDHE-ECDSA-AES256-SHA384
49-
ECDHE-RSA-AES256-SHA384
50-
ECDHE-ECDSA-AES256-SHA
51-
ECDHE-RSA-AES256-SHA
52-
DHE-RSA-AES128-SHA256
53-
DHE-RSA-AES256-SHA256
54-
DHE-RSA-AES128-SHA
55-
DHE-RSA-AES256-SHA
56-
DHE-DSS-AES128-SHA256
57-
DHE-DSS-AES256-SHA256
58-
DHE-DSS-AES128-SHA
59-
DHE-DSS-AES256-SHA
60-
AES128-GCM-SHA256
61-
AES256-GCM-SHA384
62-
AES128-SHA256
63-
AES256-SHA256
64-
AES128-SHA
65-
AES256-SHA
66-
}.join(":"),
67-
)
68-
end
32+
if !(OpenSSL::OPENSSL_VERSION.start_with?("OpenSSL") &&
33+
OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000)
34+
DEFAULT_PARAMS.merge!(
35+
ciphers: %w{
36+
ECDHE-ECDSA-AES128-GCM-SHA256
37+
ECDHE-RSA-AES128-GCM-SHA256
38+
ECDHE-ECDSA-AES256-GCM-SHA384
39+
ECDHE-RSA-AES256-GCM-SHA384
40+
DHE-RSA-AES128-GCM-SHA256
41+
DHE-DSS-AES128-GCM-SHA256
42+
DHE-RSA-AES256-GCM-SHA384
43+
DHE-DSS-AES256-GCM-SHA384
44+
ECDHE-ECDSA-AES128-SHA256
45+
ECDHE-RSA-AES128-SHA256
46+
ECDHE-ECDSA-AES128-SHA
47+
ECDHE-RSA-AES128-SHA
48+
ECDHE-ECDSA-AES256-SHA384
49+
ECDHE-RSA-AES256-SHA384
50+
ECDHE-ECDSA-AES256-SHA
51+
ECDHE-RSA-AES256-SHA
52+
DHE-RSA-AES128-SHA256
53+
DHE-RSA-AES256-SHA256
54+
DHE-RSA-AES128-SHA
55+
DHE-RSA-AES256-SHA
56+
DHE-DSS-AES128-SHA256
57+
DHE-DSS-AES256-SHA256
58+
DHE-DSS-AES128-SHA
59+
DHE-DSS-AES256-SHA
60+
AES128-GCM-SHA256
61+
AES256-GCM-SHA384
62+
AES128-SHA256
63+
AES256-SHA256
64+
AES128-SHA
65+
AES256-SHA
66+
}.join(":"),
67+
)
68+
end
6969
end
7070

7171
if defined?(OpenSSL::PKey::DH)
@@ -111,6 +111,21 @@ class SSLContext
111111
# callback must return an SSLContext for the server name or nil.
112112
attr_accessor :servername_cb
113113

114+
# call-seq:
115+
# SSLContext.new -> ctx
116+
# SSLContext.new(:TLSv1) -> ctx
117+
# SSLContext.new("SSLv23") -> ctx
118+
#
119+
# Creates a new SSL context.
120+
#
121+
# If an argument is given, #ssl_version= is called with the value. Note
122+
# that this form is deprecated. New applications should use #min_version=
123+
# and #max_version= as necessary.
124+
# def initialize(version = nil)
125+
# self.options |= OpenSSL::SSL::OP_ALL
126+
# self.ssl_version = version if version
127+
# end
128+
114129
##
115130
# call-seq:
116131
# ctx.set_params(params = {}) -> params

lib/jopenssl23/openssl/x509.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,54 @@
1414

1515
module OpenSSL
1616
module X509
17+
# class ExtensionFactory
18+
# def create_extension(*arg)
19+
# if arg.size > 1
20+
# create_ext(*arg)
21+
# else
22+
# send("create_ext_from_"+arg[0].class.name.downcase, arg[0])
23+
# end
24+
# end
25+
#
26+
# def create_ext_from_array(ary)
27+
# raise ExtensionError, "unexpected array form" if ary.size > 3
28+
# create_ext(ary[0], ary[1], ary[2])
29+
# end
30+
#
31+
# def create_ext_from_string(str) # "oid = critical, value"
32+
# oid, value = str.split(/=/, 2)
33+
# oid.strip!
34+
# value.strip!
35+
# create_ext(oid, value)
36+
# end
37+
#
38+
# def create_ext_from_hash(hash)
39+
# create_ext(hash["oid"], hash["value"], hash["critical"])
40+
# end
41+
# end
42+
#
43+
# class Extension
44+
# def ==(other)
45+
# return false unless Extension === other
46+
# to_der == other.to_der
47+
# end
48+
#
49+
# def to_s # "oid = critical, value"
50+
# str = self.oid
51+
# str << " = "
52+
# str << "critical, " if self.critical?
53+
# str << self.value.gsub(/\n/, ", ")
54+
# end
55+
#
56+
# def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
57+
# {"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
58+
# end
59+
#
60+
# def to_a
61+
# [ self.oid, self.value, self.critical? ]
62+
# end
63+
# end
64+
1765
class Name
1866
module RFC2253DN
1967
Special = ',=+<>#;'
@@ -117,6 +165,13 @@ def pretty_print(q)
117165
end
118166
end
119167

168+
# class Attribute
169+
# def ==(other)
170+
# return false unless Attribute === other
171+
# to_der == other.to_der
172+
# end
173+
# end
174+
120175
class StoreContext
121176
def cleanup
122177
warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE
@@ -135,5 +190,19 @@ def pretty_print(q)
135190
}
136191
end
137192
end
193+
194+
# class CRL
195+
# def ==(other)
196+
# return false unless CRL === other
197+
# to_der == other.to_der
198+
# end
199+
# end
200+
201+
# class Request
202+
# def ==(other)
203+
# return false unless Request === other
204+
# to_der == other.to_der
205+
# end
206+
# end
138207
end
139208
end

0 commit comments

Comments
 (0)