Nikolai
Nikolai

Reputation: 1345

How to configure private key for SSL client in Ruby on Rails application

I need to debug OpenID authentication flow between Rails application and OpenID provider going over SSL. I want to configure Rails and wireshark with the same private key for SSL flow decryption.

I need to know if there is configuration option in Rails to force use private key for the SSL client.

Upvotes: 1

Views: 913

Answers (1)

Xavier Shay
Xavier Shay

Reputation: 4127

Use the cert and key options:

require "net/https"
require "uri"

uri = URI.parse("https://secure.com/")
pem = File.read("/path/to/my.pem")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(pem)
http.key = OpenSSL::PKey::RSA.new(pem)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

request = Net::HTTP::Get.new(uri.request_uri)

From http://www.rubyinside.com/nethttp-cheat-sheet-2940.html

Upvotes: 1

Related Questions