Using PKCS12 Cert for OpenSSL

Hello everyone,
    I'm having an issue trying to setup my RoR app to use a particular
certificate for an XML transaction... The certificate I'm given is a
.p12 file, containing 3 certificates and a private key. The certificates
are: CA root, CA intermediate, and CA issuing. This is the first time
I've really done any kind of secure XML send / receive transaction and
I'm getting a bit stuck -- perhaps you all can drop some knowledge on me
:slight_smile:

So I've converted my .p12 certificate into a .cer (with the 3
certificates inside, marked by ---BEGIN CERTIFICATE--- and ---END
CERTIFICATE---) and .key file (with the private key).

Here's my ruby code. I've mostly been testing in console.

url = URI.parse(test_url) # Testing
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.cert =
OpenSSL::X509::Certificate.new(File.read(File.join(Rails.root.join('lib/api'),
"test.cer")))
http.key =
OpenSSL::PKey::RSA.new((File.read(File.join(Rails.root.join('lib/api'),
"test.key"))),cert_password)

response = http.post(url.host, known_good_xml)

Here is the result of the last line:
OpenSSL::SSL::SSLError: SSL_CTX_use_PrivateKey:: key values mismatch

Since I'm new to this, I'm having a hard time trying to figure out
whether my problem is with my cert, my ruby code, or whatever...

Any and all help is appreciated!

Thanks,
- Jeff

···

--
Posted via http://www.ruby-forum.com/.

Just as a precaution, becareful you haven't pasted any additional spaces
into either file. Windows copy/paste has niche for doing that.

···

On Oct 10, 2011 2:58 PM, "Jeff Miller" <loadeddesigns@gmail.com> wrote:

Hello everyone,
   I'm having an issue trying to setup my RoR app to use a particular
certificate for an XML transaction... The certificate I'm given is a
.p12 file, containing 3 certificates and a private key. The certificates
are: CA root, CA intermediate, and CA issuing. This is the first time
I've really done any kind of secure XML send / receive transaction and
I'm getting a bit stuck -- perhaps you all can drop some knowledge on me
:slight_smile:

So I've converted my .p12 certificate into a .cer (with the 3
certificates inside, marked by ---BEGIN CERTIFICATE--- and ---END
CERTIFICATE---) and .key file (with the private key).

Here's my ruby code. I've mostly been testing in console.

url = URI.parse(test_url) # Testing
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.cert =

OpenSSL::X509::Certificate.new(File.read(File.join(Rails.root.join('lib/api'),
"test.cer")))
http.key =
OpenSSL::PKey::RSA.new((File.read(File.join(Rails.root.join('lib/api'),
"test.key"))),cert_password)

response = http.post(url.host, known_good_xml)

Here is the result of the last line:
OpenSSL::SSL::SSLError: SSL_CTX_use_PrivateKey:: key values mismatch

Since I'm new to this, I'm having a hard time trying to figure out
whether my problem is with my cert, my ruby code, or whatever...

Any and all help is appreciated!

Thanks,
- Jeff

--
Posted via http://www.ruby-forum.com/\.