Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Client certificates with https

Thread Tools

Client certificates with https

Posts: n/a
In order to connect to my secure payment gateway I need to supply a
certificate they provide for me in the form of a PEM file. In all of
their example code they accomplish this by setting a path to that file
in curl's options, and while I know there is a Ruby extension that
makes libcurl available, I am wondering if it is possible to accomplish
this same thing using the built-in functionality of NET::HTTP and

Looking through the OpenSSL "documentation" I see that there are
writable attributes named "cert" and "key" that would seem to provide
this ability, but I have no idea what I'm supposed to pass where. Does
it want a path or the actual data, and do I need to supply values for
both if the PEM file contains both the key and certificate in one
place? I'm rather new to Ruby and honestly have not been able to figure
out how anyone is expected to find anything in these three-paned RDoc
windows unless they already know where it is, so any info would be
greatly appreciated.

Reply With Quote
Posts: n/a
I'm pathetically replying to my own post with the solution I have come
up with since there is absolutely no example code for getting Ruby to
talk to the Linkpoint gateway out there. Hopefully it will get indexed
and help someone else who finds themselves in a similar position

This example posts a phony order to the testing server. In order to
talk to the real server, you'll simply need to change the host to
"" in the URL.

You'll need to supply your store number in the "configfile" element of
the XML, and you'll need to provide a valid path to your own PEM file
to Once those things are done, you should get a response and
be ready to take it from there.



require 'net/https'
require 'uri'
require 'rexml/document'

xml_string = <<-END_XML






<configfile>PUT YOUR STORE NUMBER HERE!!!!!!!!!</configfile>











#Parse the URL to the Linkpoint gateway script.
uri = URI.parse('')

#Read the PEM file into a string. You'll need to supply your own path
to your own PEM file here obviously
pem_file ='/home/yourdomain/storenumber.pem')

#Create a new HTTP connection and configure it for SSL
#with a client-side certificate which we build from the
#PEM file's data.
connection =, uri.port)
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
connection.cert =
connection.key =

#Send the XML as POST data after ridding it of excess whitespace.
raw_response =, xml_string.gsub!(/\s/, ''))

#Parse the (invalid!) XML response into an array of values for ease of
#REXML will complain about the multiple root elements unless we wrap
#Linkpoint sends us up in another set of tags.
response_doc_root ="<doc>#{raw_response.body}</doc>").root

#Build a hash containing the key/value pairs from the response.
response_values =

response_doc_root.each_element() {|element|
response_values["#{}"] = element.text if element.text !=
nil }

#Process those values however you like. This just prints them out.
response_values.each() {|key, val| puts "#{key} => #{val}\n" }


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
python xmlrpc client with ssl client certificates and standard modules News123 Python 9 02-15-2012 01:04 PM
Problems using client certificates with net/https Jim Clark Ruby 4 12-03-2007 03:19 AM
Problems with IOS HTTPS and Certificates S. Schmid Cisco 1 09-06-2006 09:39 AM
Are SSL certificates and x.509 certificates the same? n33470 ASP .Net Web Services 0 12-14-2005 03:30 PM
Self-issued certificates and commercial certificates. Lord Amoeba Computer Security 2 05-05-2004 01:40 PM