Skip to content

Commit 00bec0d

Browse files
committed
ssl: do not enable OpenSSL::SSL::OP_ALL by default
Respect the SSL options set by default by SSL_CTX() and by the system-wide OpenSSL configuration file. OpenSSL::SSL::SSLContext#initialize currently adds OpenSSL::SSL::OP_ALL on top of the default SSL options. Let's stop doing it. OpenSSL::SSL::OP_ALL is a set of options that changes OpenSSL's behavior to workaround various TLS implementation bugs. Using it is considered usually safe, but is not completely harmless.
1 parent 9120fcd commit 00bec0d

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/openssl/ssl.rb

Lines changed: 0 additions & 1 deletion
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

test/openssl/test_ssl.rb

Lines changed: 30 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,29 @@ 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+
end;
61+
}
62+
end
63+
3664
def test_ssl_with_server_cert
3765
ctx_proc = -> ctx {
3866
ctx.cert = @svr_cert

0 commit comments

Comments
 (0)