Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RCurl and self-signed certificate issues

Tags:

curl

macos

r

ssl

rcurl

I am having problems getting RCurl function getURL to access an HTTPS URL on a server that is using a self-signed certificate. I'm running R 3.0.2 on Mac OS X 10.9.2.

I have read the FAQ and the curl page on the subject. So this is where I stand:

  1. I have saved a copy of the certificate to disk (~/cert.pem).
  2. I have been able to use this very same file to connect to the server using python-requests and the 'verify' option, and succeeded.
  3. curl on the command-line seems to be ignoring the --cacert option. I succeeded in accessing the website with it after I flagged the certificate as trusted using the Mac OS X 'Keychain Access' app.
  4. RCurl stubbornly refuses to connect to the website with the following code:

    getURL("https://somesite.tld", verbose=T, cainfo=normalizePath("~/cert.pem"))

This is the output I get:

* Adding handle: conn: 0x7f92771b0400
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 38 (0x7f92771b0400) send_pipe: 1, recv_pipe: 0
* About to connect() to somesite.tld port 443 (#38)
*   Trying 42.42.42.42...
* Connected to somesite.tld (42.42.42.42) port 443 (#38)
* SSL certificate problem: Invalid certificate chain
* Closing connection 38

When I tested both curl with the --cacert option and the RCurl code above in a Linux VM with the same cert.pem file and exact same URL, it worked perfectly.

So equal tests on Linux and Mac OS X, and only on Mac OS X do they fail. Even adding the certificate to the keychain didn't work.

The only thing that does work is using ssl.verifypeer=FALSE, but I don't want to do that for security reasons.

I'm out of ideas here. Anyone else have any suggestions on how to get this to work?

like image 287
asieira Avatar asked Feb 26 '14 17:02

asieira


People also ask

How do you fix the certificate is not trusted because it is self-signed?

You will need to have a self-signed certificate removed and a trusted one reinstalled for everything to work properly. Note, if your server supports SNI technology, you will not need a dedicated IP address for every certificate installed on the server. You need to discuss this with your hosting provider.

What are the disadvantages of a self-signed certificate?

A self-signed SSL certificate does not provide sufficient protection to the data sent by a browser to the server. Unlike the certificates issued by reliable certification authorities, the identity of a self-signed SSL is verified by its owner.

Why we should not use self-signed certificate?

Importantly, private certificates still offer a high degree of identity assurance and trust since they were generated by a proper PKI. Self-signed certificates are very different from public and private certificates because they are not signed by a certificate authority and therefore provide no trust.


1 Answers

You can try:

library ("RCurl")
URL1 <- "https://data.mexbt.com/ticker/btcusd"
getURL(URL1,cainfo=system.file("CurlSSL","cacert.pem",package="RCurl"))
like image 72
IF.Francisco.ME Avatar answered Sep 24 '22 03:09

IF.Francisco.ME