Skip to content

Commit 15c140f

Browse files
committed
Override net/http in Ruby, to support LibreSSL
1 parent bc6c25d commit 15c140f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

overrides/gems/net/http.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Remove this module from LOAD_PATH, so we can load the real one
2+
gem_override_path = File.expand_path('..', __dir__) # parent dir, we're a subfolder
3+
$LOAD_PATH.reject! { |path| File.expand_path(path) == gem_override_path }
4+
5+
# Override net/http, the built-in HTTP module to inject our cert
6+
# This isn't necessary with OpenSSL (doesn't hurt), but LibreSSL ignores
7+
# the SSL_CERT_FILE setting, so we need to be more explicit:
8+
require 'net/http'
9+
module Net
10+
module HTTPHttpToolkitExtensions
11+
def ca_file=(path)
12+
# If you try to use a certificate, use ours instead
13+
super(ENV['SSL_CERT_FILE'])
14+
end
15+
16+
def cert_store=(store)
17+
# If you try to use a whole store of certs, use ours instead
18+
self.ca_file = ENV['SSL_CERT_FILE']
19+
end
20+
21+
def use_ssl=(val)
22+
# If you try to use SSL, make sure you trust our cert first
23+
self.ca_file = ENV['SSL_CERT_FILE']
24+
super(val)
25+
end
26+
end
27+
28+
class HTTP
29+
prepend HTTPHttpToolkitExtensions
30+
end
31+
end
32+
33+
# Put this override directory back on LOAD_PATH
34+
$LOAD_PATH.unshift(gem_override_path)

0 commit comments

Comments
 (0)