Skip to content

Commit 63db970

Browse files
authored
Merge pull request #767 from rhenium/ky/ssl-respect-default-ssl-options
ssl: do not enable OpenSSL::SSL::OP_ALL by default
2 parents 3b3c950 + 77c3db2 commit 63db970

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,10 @@ ssl_info_cb(const SSL *ssl, int where, int val)
746746
}
747747

748748
/*
749-
* Gets various OpenSSL options.
749+
* call-seq:
750+
* ctx.options -> integer
751+
*
752+
* Gets various \OpenSSL options.
750753
*/
751754
static VALUE
752755
ossl_sslctx_get_options(VALUE self)
@@ -761,7 +764,17 @@ ossl_sslctx_get_options(VALUE self)
761764
}
762765

763766
/*
764-
* Sets various OpenSSL options.
767+
* call-seq:
768+
* ctx.options = integer
769+
*
770+
* Sets various \OpenSSL options. The options are a bit field and can be
771+
* combined with the bitwise OR operator (<tt>|</tt>). Available options are
772+
* defined as constants in OpenSSL::SSL that begin with +OP_+.
773+
*
774+
* For backwards compatibility, passing +nil+ has the same effect as passing
775+
* OpenSSL::SSL::OP_ALL.
776+
*
777+
* See also man page SSL_CTX_set_options(3).
765778
*/
766779
static VALUE
767780
ossl_sslctx_set_options(VALUE self, VALUE options)

lib/openssl/ssl.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class SSLContext
125125
# that this form is deprecated. New applications should use #min_version=
126126
# and #max_version= as necessary.
127127
def initialize(version = nil)
128-
self.options |= OpenSSL::SSL::OP_ALL
129128
self.ssl_version = version if version
130129
self.verify_mode = OpenSSL::SSL::VERIFY_NONE
131130
self.verify_hostname = false
@@ -145,7 +144,7 @@ def initialize(version = nil)
145144
# used.
146145
def set_params(params={})
147146
params = DEFAULT_PARAMS.merge(params)
148-
self.options = params.delete(:options) # set before min_version/max_version
147+
self.options |= params.delete(:options) # set before min_version/max_version
149148
params.each{|name, value| self.__send__("#{name}=", value) }
150149
if self.verify_mode != OpenSSL::SSL::VERIFY_NONE
151150
unless self.ca_file or self.ca_path or self.cert_store

test/openssl/test_ssl.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ def test_bad_socket
1515
end
1616
end
1717

18+
def test_ctx_setup
19+
ctx = OpenSSL::SSL::SSLContext.new
20+
assert_equal true, ctx.setup
21+
assert_predicate ctx, :frozen?
22+
assert_equal nil, ctx.setup
23+
end
24+
1825
def test_ctx_options
1926
ctx = OpenSSL::SSL::SSLContext.new
2027

21-
assert (OpenSSL::SSL::OP_ALL & ctx.options) == OpenSSL::SSL::OP_ALL,
22-
"OP_ALL is set by default"
2328
ctx.options = 4
2429
assert_equal 4, ctx.options & 4
2530
if ctx.options != 4
@@ -33,6 +38,31 @@ def test_ctx_options
3338
assert_equal nil, ctx.setup
3439
end
3540

41+
def test_ctx_options_config
42+
omit "LibreSSL does not support OPENSSL_CONF" if libressl?
43+
omit "OpenSSL < 1.1.1 does not support system_default" if openssl? && !openssl?(1, 1, 1)
44+
45+
Tempfile.create("openssl.cnf") { |f|
46+
f.puts(<<~EOF)
47+
openssl_conf = default_conf
48+
[default_conf]
49+
ssl_conf = ssl_sect
50+
[ssl_sect]
51+
system_default = ssl_default_sect
52+
[ssl_default_sect]
53+
Options = -SessionTicket
54+
EOF
55+
f.close
56+
57+
assert_separately([{ "OPENSSL_CONF" => f.path }, "-ropenssl"], <<~"end;")
58+
ctx = OpenSSL::SSL::SSLContext.new
59+
assert_equal OpenSSL::SSL::OP_NO_TICKET, ctx.options & OpenSSL::SSL::OP_NO_TICKET
60+
ctx.set_params
61+
assert_equal OpenSSL::SSL::OP_NO_TICKET, ctx.options & OpenSSL::SSL::OP_NO_TICKET
62+
end;
63+
}
64+
end
65+
3666
def test_ssl_with_server_cert
3767
ctx_proc = -> ctx {
3868
ctx.cert = @svr_cert

0 commit comments

Comments
 (0)