Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 452
Tom Rossi Avatar asked Mar 16 '23 03:03

Tom Rossi


1 Answers

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!

like image 50
Tom Rossi Avatar answered Mar 27 '23 18:03

Tom Rossi