Ubuntu linux上的R和SSL/curl:在R中SSL连接失败,但在curl中工作

Ubuntu linux上的R和SSL/curl:在R中SSL连接失败,但在curl中工作,r,ubuntu,ssl,curl,R,Ubuntu,Ssl,Curl,我对如何进一步调查这一点有点不知所措,所以非常感谢各位指点 我正在运行Ubuntu17.04,我相信大概是因为在我升级的时候(之前运行的是16.10),我再也不能从R中更新(或使用“互联网上的任何东西”)任何东西了——它在SSL上什么都失败了。R之外的所有“正常”SSL通信都可以正常工作 例如,在执行install.packages(“curl”)时,我收到以下错误消息: Warning in install.packages : URL 'https://cran.rstudio.com/sr

我对如何进一步调查这一点有点不知所措,所以非常感谢各位指点

我正在运行Ubuntu17.04,我相信大概是因为在我升级的时候(之前运行的是16.10),我再也不能从R中更新(或使用“互联网上的任何东西”)任何东西了——它在SSL上什么都失败了。R之外的所有“正常”SSL通信都可以正常工作

例如,在执行
install.packages(“curl”)
时,我收到以下错误消息:

Warning in install.packages :
URL 'https://cran.rstudio.com/src/contrib/PACKAGES.rds': status was 'SSL connect error'
Warning in install.packages :
URL 'https://cran.rstudio.com/src/contrib/PACKAGES.gz': status was 'SSL connect error'
Warning in install.packages :
URL 'https://cran.rstudio.com/src/contrib/PACKAGES': status was 'SSL connect error'
Warning in install.packages :
... [etc] ...
但是,如果我运行
curl-v“https://cran.rstudio.com/src/contrib/PACKAGES.rds“-o test.curl
在命令行上,一切正常

*   Trying 10.26.0.19...
* TCP_NODELAY set
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to (nil) (10.26.0.19) port 3128 (#0)
* Establish HTTP proxy tunnel to cran.rstudio.com:443
* Proxy auth using Basic with user '[redacted]'
> CONNECT cran.rstudio.com:443 HTTP/1.1
> Host: cran.rstudio.com:443
> Proxy-Authorization: Basic [redacted]
> User-Agent: curl/7.52.1
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 Connection established
< 
* Proxy replied OK to CONNECT request
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /home/csafferling/programs/anaconda3/ssl/cacert.pem
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):{ [76 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):{ [4787 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: OU=Domain Control Validated; CN=cran.rstudio.com
*  start date: Jun 30 19:59:41 2015 GMT
*  expire date: Jun 30 19:59:41 2018 GMT
*  subjectAltName: host "cran.rstudio.com" matched cert's "cran.rstudio.com"
*  issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
*  SSL certificate verify ok.} [5 bytes data]
> GET /src/contrib/PACKAGES.rds HTTP/1.1
> Host: cran.rstudio.com
> User-Agent: curl/7.52.1
> Accept: */*
> { [5 bytes data]
< HTTP/1.1 200 OK
< Content-Length: 251020
< Connection: keep-alive
< Date: Wed, 12 Jul 2017 14:11:48 GMT
< Server: Apache/2.2.22 (Ubuntu)
< Last-Modified: Wed, 12 Jul 2017 13:02:43 GMT
< ETag: "d78fc54-3d48c-5541e6e7d22c0"
< Accept-Ranges: bytes
< Cache-Control: max-age=1800
< Expires: Wed, 12 Jul 2017 14:41:48 GMT
< Age: 1045
< X-Cache: Hit from cloudfront
< Via: 1.1 67284fcf464f6f1529cc1e521669622c.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: CqpfjeemEcxkxFYJueqzwUEu8Yh-qSenHJJiR2BdmqmAYLpu2_54dA==
< { [15891 bytes data]
* Curl_http_done: called premature == 0 100  245k  100  245k    0     0   583k      0 --:--:-- --:--:-- --:--:--  589k
* Connection #0 to host (nil) left intact
*正在尝试10.26.0.19。。。
*TCP_节点集
%总接收百分比%x平均速度时间电流
数据加载上载总左速度
0 0 0 0 0 0 0--:-:-:-:-:-:---0*已连接到(无)(10.26.0.19)端口3128(#0)
*建立到cran.rstudio.com的HTTP代理隧道:443
*与用户“[redact]”一起使用Basic进行代理身份验证
>连接cran.rstudio.com:443http/1.1
>主持人:cran.rstudio.com:443
>代理授权:基本[修订]
>用户代理:curl/7.52.1
>代理连接:保持活动状态
> 
GET/src/contrib/PACKAGES.rds HTTP/1.1
>主持人:cran.rstudio.com
>用户代理:curl/7.52.1
>接受:*/*
>{[5字节数据]
我注意到的一件事是,命令行
curl
使用了我安装的
anaconda
的CA,这确实很奇怪。也许R使用默认CA,但它们不工作?正如我所说,只有R不能与SSL一起工作,其他一切都可以工作


非常感谢您的帮助!

亲爱的Christoph Saffering

我的感觉是,默认情况下,您遇到了RStudio/R的CRAN
ssh问题

解决方案 将以下内容添加到目标机器
.Rprofile

options(download.file.method = "wget")
local({
         r<- getOption("repos");
         r["CRAN"] <-"https://cran.rstudio.com/"
         options(repos=r)
})
请注意,在即将发布的R3.2.2版本中,这将不再是必需的,因为默认方法相当于“wininet”

OSX和Linux 请注意,如果您从源代码构建R,则“libcurl”方法可能已在中编译,也可能未在中编译。如果未编译“libcurl”方法(即,capabilities(“libcurl”)==FALSE),则可以按照下面R早期版本的说明配置备用安全方法

R 3.1及更早版本 窗户

utils::setInternet2(TRUE)
options(download.file.method = "internal")
请注意,setInternet2(TRUE)是RStudio中的默认值,但不适用于R GUI。如果您不想在Windows上使用setInternet2(TRUE),则配置安全下载的唯一其他方法是在您的路径上设置“wget”或“curl”实用程序,如下文针对OS X和Linux所述

OSX

Linux

请注意,“curl”和“wget”方法可以在任何平台上工作,只要系统路径中有必要的二进制文件。上面的建议基于这样一个事实:“curl”包含在OS X中,“wget”包含在大多数Linux发行版中


ref:

谢谢你的帮助,Technophobe01!设置
选项(download.file.method=“wget”)
确实解决了这个问题。我想知道的是:我有
功能(“libcurl”)==TRUE
,但是将download.file设置为
libcurl
不起作用。我认为这不应该发生在R3.4上?Christoph-看看解决方案:
sudo apt get install libcurl4 openssl dev libxml2 dev libxslt dev libssl dev-y
sudo apt get install R-base R-base-dev-y
谢谢,但不幸的是没有我的安装程序确实缺少libxslt dev,但仍然不起作用。我保留了
wget
,这对
options(download.file.method = "libcurl")
utils::setInternet2(TRUE)
options(download.file.method = "internal")
options(download.file.method = "curl")
options(download.file.method = "wget")