Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use system OpenSSL cert file and dir if available #770

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/excon/ssl_socket.rb
Expand Up @@ -39,15 +39,14 @@ def initialize(data = {})
ssl_context.max_version = @data[:ssl_max_version]
end


if @data[:ssl_verify_peer]
# turn verification on
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER

if (ca_file = @data[:ssl_ca_file] || ENV['SSL_CERT_FILE'])
if (ca_file = @data[:ssl_ca_file] || ENV['SSL_CERT_FILE'] || use_if_readable(OpenSSL::X509::DEFAULT_CERT_FILE))
ssl_context.ca_file = ca_file
end
if (ca_path = @data[:ssl_ca_path] || ENV['SSL_CERT_DIR'])
if (ca_path = @data[:ssl_ca_path] || ENV['SSL_CERT_DIR'] || use_if_readable(OpenSSL::X509::DEFAULT_CERT_DIR))
ssl_context.ca_path = ca_path
end
if (cert_store = @data[:ssl_cert_store])
Expand Down Expand Up @@ -190,5 +189,10 @@ def client_key_pass
@data[:client_key_pass] || @data[:private_key_pass]
end

def use_if_readable(filename)
return filename if File.readable?(filename)

nil
end
end
end