I'm running a ruby on rails application (rails 4.x) and I have a protected resource that needs authentication using a client certificate. I need to force the client to authenticate with its certifcate. Is that even possible from a rails controller or is this handled in an upper layer that has my server cert?
I'm able to do requests from rails to another server and authenticate with my rails certificate, however the other way around doesn't seem possible.
This is how I authenticate from my rails app to another server
# Example usage:
req = HttpsReq.new
response = req.http.request Net::HTTP::Get.new "/api/users"
require 'openssl'
require 'net/http'
require 'json'
class HttpsReq
DEFAULT_OPTIONS = {
use_ssl: true,
verify_mode: OpenSSL::SSL::VERIFY_PEER,
keep_alive_timeout: 30,
ssl_version: :TLSv1_2,
ca_file: File.join(File.dirname(__FILE__), "cacert.pem"),
cert: OpenSSL::X509::Certificate.new(Base64.decode64(ENV['CLIENT_CERT_PEM'])),
key: OpenSSL::PKey::RSA.new(Base64.decode64(ENV['CLIENT_KEY_PEM']), ENV['CLIENT_KEY_PASSWORD'])
}
def initialize(http = nil)
if http
@http = http
else
@http = Net::HTTP.start(ENV['SECURE_SERVER'], 8080, DEFAULT_OPTIONS)
end
end
end