Skip to content

Instantly share code, notes, and snippets.

@MattPorto
Created August 15, 2017 21:30
Show Gist options
  • Save MattPorto/6091037c6e7553334eedbdef69e0960c to your computer and use it in GitHub Desktop.
Save MattPorto/6091037c6e7553334eedbdef69e0960c to your computer and use it in GitHub Desktop.
# Faraday customs method:
class FaradayHttp
def with_openssl
system "openssl pkcs12 -in my-certificate-path -out certificate-output-path -nodes -password pass:certificate-password"
def cert_object
OpenSSL::X509::Certificate.new File.read("certificate-output-path")
end
# create PKey
def key_object
OpenSSL::PKey.read File.read("certificate-output-path")
end
faraday = Faraday::Connection.new 'https://example-site.com',
:ssl => {
certificate: cert_object,
private_key: key_object,
version: :SSLv3,
verify: false
}
faraday
end
end
# Controller that try to connect with the ssl server:
agent = FaradayHttp.new.with_openssl
page = agent.get '/login_path'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment