On Ubuntu trusty-64 with rvm and ruby 2.0.0-p353 using curb 0.8.5 I try to make post request.

When I perform it in command line using curl it makes request and returns ok, but when I do the same request in ruby, it fails with error reading X.509 key or certificate file message. In both cases I use just the same certificate.

vagrant@cabinet:~/app$ curl -k --cert certs/ds_admin.pem --cert-type PEM https://pim.somewhere.ru:5543/authentication/user/login/? --data "{\"login\":\"+71111111150\",\"password\":\"qwerty123\"}" -v

* Hostname was NOT found in DNS cache 151.209.250.186
*   Trying 151.209.250.186...
* Connected to pim.somewhere.ru (151.209.250.186) port 5543 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES128-SHA
* Server certificate:
*        subject: C=RU; O=BE; OU=test env; CN=*.somewhere.ru
*        start date: 2013-02-27 15:09:21 GMT
*        expire date: 2015-11-24 15:09:21 GMT
*        issuer: C=RU; O=BE; OU=test env; CN=*.somewhere.ru
*        SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /authentication/user/login/? HTTP/1.1
> User-Agent: curl/7.35.0
> Host: pim.somewhere.ru:5543
> Accept: */*
> Content-Length: 47
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 47 out of 47 bytes
* SSLv3, TLS handshake, Hello request (0):
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Request CERT (13):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS handshake, CERT verify (15):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
< HTTP/1.1 200 OK
< Content-Length: 325
< Content-Type: application/json; charset=utf-8
* Server Microsoft-HTTPAPI/2.0 is not blacklisted
< Server: Microsoft-HTTPAPI/2.0
< Date: Wed, 30 Jul 2014 06:15:58 GMT
< 
* Connection #0 to host pim.somewhere.ru left intact
{"Token":"re7hCmYB4hCjJRphLS4dK58nNAkIvHZYVbY9ie94vICPbJadauLclDjPKFLz9lGCz6jjex3GFTL7NmxBofOP70bx6Abin+UrXZj\/N5PEFi3jYR9LIaIxgz5AXYoLxr1kismBZgjvQYCIndhr8lwNpw==|2014-07-30T08:15:58","User":{"FirstName":"First","LastName":"Last","Login":"+71111111150","UserId":"UAS100004","UserNativeId":"1-156LVK","UserSysName":"siebel"}}

In Rails console by using curb

From: /home/vagrant/app/app/models/uas/query.rb @ line 49 Uas::Query.client:

    44: def self.client(url)
    45:   url = "#{Rails.configuration.uas_url}/#{url}"
    46:
    47:   Curl::Easy.new(url) do |curl|
    48:     curl.use_ssl = 1
 => 49:     binding.pry
    50:     curl.cert = Rails.configuration.uas_sertificate
    51:     curl.ssl_verify_peer = false
    52:     curl.ssl_verify_host = false
    53:     curl.verbose = true
    54:   end
    55: end

[1] pry(Uas::Query)> c
Request post user/login/?
{:login=>"+71111111150", :password=>"qwerty123"}
* Hostname was NOT found in DNS cache
*   Trying 151.209.250.186...
* Connected to pim.somewhere.ru (151.209.250.186) port 5543 (#0)
* found 164 certificates in /etc/ssl/certs/ca-certificates.crt
* error reading X.509 key or certificate file
* Closing connection 0
Curl::Err::SSLConnectError: Curl::Err::SSLConnectError

I checked Rails.configuration.uas_sertificate - it's the certificate and could be read by File.read(Rails.configuration.uas_sertificate)

How can I fix it?

1

There are 1 best solutions below

0
On

In my vagrant box I got installed two libcurl packages:

  • libcurl4-openssl-dev
  • libcurl4-gnutls-dev

from which the second one was used for compiling curb gem native extension. I guess it was used due to it was installed after the libcurl4-openssl-dev package.

After I removed libcurl4-gnutls-dev from packages installation list and rebuilt vagrant box, curb had accepted the certificate.