Tom Rossi
Tom Rossi

Reputation: 12066

How to use a client certificate with HTTPS?

How do you provide all the details necessary to make an HTTPS request with an SSL client certificate?

Upvotes: 5

Views: 3300

Answers (1)

Tom Rossi
Tom Rossi

Reputation: 12066

Okay, so I looked all over and found bits and pieces of what I needed. I want to provide this for anyone else that is struggling. All of the files were put in a PEM format. I used the client.key file to create a CSR that was given to the server administrator. In return I got a P7B file that I then needed to be convert into PEM files. The root.cer and client.cer file came from the P7b.

  uri = URI.parse(my_url_stril)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.cert = OpenSSL::X509::Certificate.new(File.read("client.cer"))
  http.ca_file = 'root.cer'
  http.key = OpenSSL::PKey::RSA.new(File.read("client.key"))
  request = Net::HTTP::Post.new(uri.request_uri)
  request.body = body
  response = http.request(request)

Let me know if you need more details!

Upvotes: 9

Related Questions