devtools::install_github() - Ignore SSL cert verification failure - r

I'm trying to get devtools::install_github() working behind my corporate proxy on Windows 7.
So far I've had to do the following:
> library(httr)
> library(devtools)
> set_config(use_proxy("123.123.123.123",8080))
> devtools::install_github("rstudio/ggvis")
Installing github repo ggvis/master from rstudio
Downloading master.zip from https://github.com/rstudio/ggvis/archive/master.zip
Error in function (type, msg, asError = TRUE) :
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Apparently we have some kind of certificate server replacing SSL certs with our own corporate SSL certs (confirmed by going to https://github.com and examining the cert).
Anyhow, just wondering if there's a way to ignore that cert error and proceed with the installation?

One way to handle the problem is to set the CURLOPT_SSL_VERIFYPEER to false. This option determines whether curl verifies the authenticity of the peer's certificate. A value of 1 means curl verifies; 0 (zero) means it doesn't.
http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html
The relevant option needs to be passed to RCurl. In RCurl the CURLOPT_ is removed letters arre lowercase and the underscore is changed to ..
set_config( config( ssl.verifypeer = 0L ) )
will pass the relevant option to RCurl when using httr.
UPDATE:
The httr since this answer was written has moved from RCurl as an underlying dependence to the curl package. cURL options are now specified
with underscores so the above would be:
set_config( config( ssl_verifypeer = 0L ) )
in the current version of httr.

I tired #jdharrisonbut method but it didn't worked for me.
A Quick fix to avoid using https connection, is by replacing https by http. you install a package from cran by this method.
install.packages("http://cran.r-project.org/src/contrib/ggvis_0.4.4.tar.gz", repo=NULL, type="source")

Related

Setting curl proxy options in R

I'm running R on a Windows machine behind a corporate proxy. When running R 3.3.2 and version 2.3 of the curl package, this works:
curl::curl_fetch_memory("https://google.com")
Also note the following:
> curl::curl_options(filter = "sslcert")
sslcert sslcerttype
10025 10086
However, this is what happens when running R 3.4.1 and curl 2.8:
> curl::curl_fetch_memory("https://google.com")
Error in curl::curl_fetch_memory("https://google.com") :
error setting certificate verify locations:
CAfile: /mingw32/ssl/certs/ca-bundle.crt
CApath: none
Note:
> curl::curl_options(filter = "sslcert")
proxy_sslcert proxy_sslcerttype sslcert sslcerttype
10254 10255 10025 10086
I gather from the curl source code that these two new options were added in between these two versions.
Since this is the only relevant difference that I can find, my hunch is that curl is looking for the proxy_sslcert in the wrong path. But I can't figure out how to change that variable, nor what I should change it to. Also, what are the numbers shown (10254, etc)?
I don't actually need to use curl specifically, but a lot of other packages rely on it, e.g.
> httr::GET("https://google.com")
Error in curl::curl_fetch_memory(url, handle = handle) :
error setting certificate verify locations:
CAfile: /mingw32/ssl/certs/ca-bundle.crt
CApath: none

SSL Connect Error when Calling Companies House API from R on remote Linux Server

I want to call the Companies House API from within R on a remote Linux server running Ubuntu 14.04 LTS.
I am starting R from the terminal, and am using the 'httr' package and making the following GET request (using 'Paul+Dodd' as an example search term):
call <- GET("https://api.companieshouse.gov.uk/search/companies?q=Paul+Dodd&items_per_page=50&start_index=1", authenticate("API_KEY_HERE", ""))
You can apply for a Companies House API key and get more information on the API here:
https://developer.companieshouse.gov.uk/api/docs/index.html
The response from the API call should be a complex list of company information.
However I am getting the following error:
Error in curl::curl_fetch_memory(url, handle = handle) :
SSL connect error
I have tried set_config( config( ssl_verifypeer = 0L ) ), which occasionally gives the correct response object but usually gives either the SSL error above or the following error:
Failure when receiving data from the peer
The above API call works when running R on my Windows desktop (running Windows 7) and on my mac. The API call works from multiple IP addresses.
I have installed the following dependencies on the remote server and have upgraded and updated but the error persists:
sudo apt-get upgrade
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libssl-dev
Finally, when I exit R and run the API call in the remote server's terminal I get the correct response. The command I used is as follows:
curl -u"API_KEY_HERE": https://api.companieshouse.gov.uk/search/companies?q=Paul+Dodd&items_per_page=50&start_index=1
I suspect the SSL connect error in R may be an issue with CA certificates, however I am at the limit of my knowledge of SSL. Do you have any suggestions as to how I might fix this so that I can call the API from within R using httr?
After some trial and error, I found that installing the following packages:
jsonlite, mime, curl (≥ 0.9.1), openssl (≥ 0.8), R6 using:
install.packages("package_name")
solved the issue.

Cannot Install R Packages from github [duplicate]

I am trying to install a package from github in R, however I am getting the following error:
> install_github("jmp75/rClr", build_vignettes=TRUE)
Downloading github repo jmp75/rClr#master
Error in curl::curl_fetch_memory(url, handle = handle) :
Peer certificate cannot be authenticated with given CA certificates
I have set the RCurl options as such:
options(RCurlOptions = c(getOption("RCurlOptions"), ssl.verifypeer = FALSE, ssl.verifyhost = FALSE ) )
After checking the setting:
getOption("RCurlOptions")
we see....
$cainfo
[1] "C:/_CODE/R/Library/RCurl/etc/ca-bundle.crt"
$ssl.verifypeer
[1] FALSE
$ssl.verifyhost
[1] FALSE
Still I get the error:
Downloading github repo jmp75/rClr#master
Error in curl::curl_fetch_memory(url, handle = handle) :
Peer certificate cannot be authenticated with given CA certificates
any clues
Does this work? I had to change this bit of code recently from ssl.verifypeer to ssl_verifypeer
library(httr)
set_config(config(ssl_verifypeer = 0L))
see here devtools::install_github() - Ignore SSL cert verification failure

HTTR package: SSL certificate error, SSL3_GET_SERVER_CERTIFICATE

I am facing a challenge when trying to use the HTTR package in R and the GET() function:
pg2 = GET("http://httpbin.org/basic-auth/user/passwd", authenticate("user","passwd"))
and i am getting the below error:
Error in function (type, msg, asError = TRUE) :
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
I have searched on the web and found that I need to update the .Rprofile file using the below command line:
options(RCurlOptions = list(verbose = FALSE, capath = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE))
but still it doesn't work and I keep getting the same error message.
also when i tried the below code
> HEAD("https://www.google.com", verbose())
About to connect() to www.google.com port 443 (#0)
Trying 173.194.32.211... * connected
Connected to www.google.com (173.194.32.211) port 443 (#0)
successfully set certificate verify locations:
CAfile: C:/Users/malek.safa/Documents/R/win-library/3.0/httr/cacert.pem
CApath: none
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Closing connection #0
Error in function (type, msg, asError = TRUE) :
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
you can see that it is still looking for the CA in the cacert.pm file
I spent about five hours playing with curl and RCurl. I was able to get it working. The option you want is cainfo, not capath. Capath tells RCurl where to look for the certificate file. Cainfo specifies a file.
This works for me with RCurl.
library(RCurl)
cer_file <- "/home/user/curltest/cacert.pem"
server_url <- "some_server"
getURL(server_url, cainfo=cer_file)
Now the question is how to get httr to understand this setting. The documentation talks about a default ca_cert, but doesn't explain how to use a different cert. In my case, I'm connecting to an intranet site that wouldn't be in the default cert. The answer lies in config.R. Httr allows us to set RCurl configuration options as I've done below.
cer_file <- "/home/me/curltest/cacert.pem"
GET(login_url, config=list(cainfo=cer_file))
If you are connecting to the internet, you probably just need to update the default cacert that comes with HTTR. The Readme shows you how to do this. This way you don't need to specify the cert in every call.
setwd("path to httr package")
GET("https://raw.githubusercontent.com/bagder/ca-bundle/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt",
write_disk("inst/cacert.pem", overwrite = TRUE))

RCurl and self-signed certificate issues

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:
I have saved a copy of the certificate to disk (~/cert.pem).
I have been able to use this very same file to connect to the server using python-requests and the 'verify' option, and succeeded.
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.
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?
You can try:
library ("RCurl")
URL1 <- "https://data.mexbt.com/ticker/btcusd"
getURL(URL1,cainfo=system.file("CurlSSL","cacert.pem",package="RCurl"))
Coming back to this issue I just wanted to point out that if you are still using RCurl, you should be using httr (which uses curl) instead.
I have confirmed that using config(cainfo="/path/to/certificate") with httr connections will work as intended.

Resources