jerry
1
I have a .pem file that contains a private and a public key.
I need help in order to extract the certificate and to send the request using httpoison.
Below is how I am currently doing it in Ruby and sending the request through Faraday gem.
SSL_OPTS={client_cert: OpenSSL::X509::Certificate.new(File.read(pem_file)), client_key: OpenSSL::PKey::RSA.new(File.read(pem_file), 'testpem15')}
conn=Faraday.new(:url => "https://ip:port", :ssl=>SSL_OPTS,
:headers => HEADER) do |faraday|
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
I am, however, rewriting the application in Elixir.
Any help will be most appreciated.
Thanks.
Jerry
Off the top of my head, this should work:
HTTPoison.get("https://ip:port", [], ssl: [certfile: pem_file, password: 'testpem15'])
Note that the password needs to be a charlist.
3 Likes
jerry
3
Hello @voltone
Thanks for your response.
Below is what I get after I implemented your suggestion:
** (Poison.EncodeError) unable to encode value: {:options, {:certfile, {:ok, "Bag Attributes\n localKeyID:...
It’s a very long error. I’ve just truncated it.
What could I be doing wrong?
My code is below:
options = [ssl: [certfile: File.read(Path.expand("./partner.pem")), password: String.to_charlist("testpem15"), versions: [:'tlsv1.2']]]
result=HTTPoison.post(https://ip:port, str, req_header, options)
Thanks for your help.
Don’t read the file contents, just pass the path in the certfile option
2 Likes
jerry
5
Hello @voltone
Many thanks for the help offered me.
It worked perfectly.
Thanks so much.
Regards,
Jerry
1 Like