Skip to content

Commit 0d06604

Browse files
committed
[compat] sync-up more openssl.rb updates from upstream
1 parent adca91b commit 0d06604

File tree

3 files changed

+68
-48
lines changed

3 files changed

+68
-48
lines changed

lib/openssl/buffering.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize
3131

3232
force_encoding(BINARY)
3333
end
34-
34+
3535
def << string
3636
if string.encoding == BINARY
3737
super(string)
@@ -93,9 +93,7 @@ def consume_rbuff(size=nil)
9393
nil
9494
else
9595
size = @rbuffer.size unless size
96-
ret = @rbuffer[0, size]
97-
@rbuffer[0, size] = ""
98-
ret
96+
@rbuffer.slice!(0, size)
9997
end
10098
end
10199

lib/openssl/ssl.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ class SSLContext
8686
DEFAULT_CERT_STORE.set_default_paths
8787
DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
8888

89-
# A callback invoked when DH parameters are required.
89+
# A callback invoked when DH parameters are required for ephemeral DH key
90+
# exchange.
9091
#
91-
# The callback is invoked with the Session for the key exchange, an
92+
# The callback is invoked with the SSLSocket, a
9293
# flag indicating the use of an export cipher and the keylength
9394
# required.
9495
#
9596
# The callback must return an OpenSSL::PKey::DH instance of the correct
9697
# key length.
97-
98+
#
99+
# <b>Deprecated in version 3.0.</b> Use #tmp_dh= instead.
98100
attr_accessor :tmp_dh_callback
99101

100102
# A callback invoked at connect time to distinguish between multiple
@@ -117,6 +119,8 @@ class SSLContext
117119
# def initialize(version = nil)
118120
# self.options |= OpenSSL::SSL::OP_ALL
119121
# self.ssl_version = version if version
122+
# self.verify_mode = OpenSSL::SSL::VERIFY_NONE
123+
# self.verify_hostname = false
120124
# end
121125

122126
##
@@ -355,18 +359,18 @@ class SSLSocket
355359
include Buffering
356360
include SocketForwarder
357361

358-
# attr_reader :hostname
359-
#
360-
# # The underlying IO object.
361-
# attr_reader :io
362-
# alias :to_io :io
363-
#
364-
# # The SSLContext object used in this connection.
365-
# attr_reader :context
366-
#
367-
# # Whether to close the underlying socket as well, when the SSL/TLS
368-
# # connection is shut down. This defaults to +false+.
369-
# attr_accessor :sync_close
362+
#attr_reader :hostname
363+
364+
# The underlying IO object.
365+
#attr_reader :io
366+
#alias :to_io :io
367+
368+
# The SSLContext object used in this connection.
369+
#attr_reader :context
370+
371+
# Whether to close the underlying socket as well, when the SSL/TLS
372+
# connection is shut down. This defaults to +false+.
373+
#attr_accessor :sync_close
370374

371375
# call-seq:
372376
# ssl.sysclose => nil
@@ -379,7 +383,7 @@ def sysclose
379383
return if closed?
380384
stop
381385
io.close if sync_close
382-
end unless method_defined? :sysclose
386+
end
383387

384388
# call-seq:
385389
# ssl.post_connection_check(hostname) -> true
@@ -431,10 +435,6 @@ def tmp_dh_callback
431435
@context.tmp_dh_callback || OpenSSL::SSL::SSLContext::DEFAULT_TMP_DH_CALLBACK
432436
end
433437

434-
def tmp_ecdh_callback
435-
@context.tmp_ecdh_callback
436-
end
437-
438438
def session_new_cb
439439
@context.session_new_cb
440440
end

lib/openssl/x509.rb

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ def ==(other)
5050
to_der == other.to_der
5151
end
5252

53-
# def to_s # "oid = critical, value"
54-
# str = self.oid
55-
# str << " = "
56-
# str << "critical, " if self.critical?
57-
# str << self.value.gsub(/\n/, ", ")
58-
# end
59-
#
60-
# def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
61-
# {"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
62-
# end
63-
#
64-
# def to_a
65-
# [ self.oid, self.value, self.critical? ]
66-
# end
53+
def to_s # "oid = critical, value"
54+
str = self.oid
55+
str << " = "
56+
str << "critical, " if self.critical?
57+
str << self.value.gsub(/\n/, ", ")
58+
end
59+
60+
def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
61+
{"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
62+
end
63+
64+
def to_a
65+
[ self.oid, self.value, self.critical? ]
66+
end
6767

6868
module Helpers
6969
def find_extension(oid)
@@ -187,17 +187,17 @@ def ocsp_uris
187187

188188
private
189189

190-
def parse_aia_asn1
191-
ext = find_extension("authorityInfoAccess")
192-
return nil if ext.nil?
193-
194-
aia_asn1 = ASN1.decode(ext.value_der)
195-
if ext.critical? || aia_asn1.tag_class != :UNIVERSAL || aia_asn1.tag != ASN1::SEQUENCE
196-
raise ASN1::ASN1Error, "invalid extension"
197-
end
190+
def parse_aia_asn1
191+
ext = find_extension("authorityInfoAccess")
192+
return nil if ext.nil?
198193

199-
aia_asn1
194+
aia_asn1 = ASN1.decode(ext.value_der)
195+
if ext.critical? || aia_asn1.tag_class != :UNIVERSAL || aia_asn1.tag != ASN1::SEQUENCE
196+
raise ASN1::ASN1Error, "invalid extension"
200197
end
198+
199+
aia_asn1
200+
end
201201
end
202202
end
203203

@@ -265,7 +265,7 @@ def scan(dn)
265265
next
266266
elsif remain.length > 2 && remain[0] == ?+
267267
raise OpenSSL::X509::NameError,
268-
"multi-valued RDN is not supported: #{dn}"
268+
"multi-valued RDN is not supported: #{dn}"
269269
elsif remain.empty?
270270
break
271271
end
@@ -279,11 +279,29 @@ def scan(dn)
279279
end
280280

281281
class << self
282+
# Parses the UTF-8 string representation of a distinguished name,
283+
# according to RFC 2253.
284+
#
285+
# See also #to_utf8 for the opposite operation.
282286
def parse_rfc2253(str, template=OBJECT_TYPE_TEMPLATE)
283287
ary = OpenSSL::X509::Name::RFC2253DN.scan(str)
284288
self.new(ary, template)
285289
end
286290

291+
# Parses the string representation of a distinguished name. Two
292+
# different forms are supported:
293+
#
294+
# - \OpenSSL format (<tt>X509_NAME_oneline()</tt>) used by
295+
# <tt>#to_s</tt>. For example: <tt>/DC=com/DC=example/CN=nobody</tt>
296+
# - \OpenSSL format (<tt>X509_NAME_print()</tt>)
297+
# used by <tt>#to_s(OpenSSL::X509::Name::COMPAT)</tt>. For example:
298+
# <tt>DC=com, DC=example, CN=nobody</tt>
299+
#
300+
# Neither of them is standardized and has quirks and inconsistencies
301+
# in handling of escaped characters or multi-valued RDNs.
302+
#
303+
# Use of this method is discouraged in new applications. See
304+
# Name.parse_rfc2253 and #to_utf8 for the alternative.
287305
def parse_openssl(str, template=OBJECT_TYPE_TEMPLATE)
288306
if str.start_with?("/")
289307
# /A=B/C=D format
@@ -338,6 +356,10 @@ def pretty_print(q)
338356
q.text 'not_after='; q.pp self.not_after
339357
}
340358
end
359+
360+
def self.load_file(path)
361+
load(File.binread(path))
362+
end
341363
end
342364

343365
class CRL

0 commit comments

Comments
 (0)