【问题标题】:R and SSL/curl on Ubuntu linux: failed SSL connect in R, but works in curlUbuntu linux 上的 R 和 SSL/curl:在 R 中 SSL 连接失败,但在 curl 中有效
【发布时间】:2017-12-17 02:14:55
【问题描述】:

我对如何进一步调查这个问题有点茫然,因此我们将不胜感激。

我正在运行 Ubuntu 17.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

我注意到的一件事是命令行curl 使用我的anaconda 安装的CA,这确实很奇怪。也许 R 使用默认的 CA,但它们不起作用?就像我说的,只有 R 不能使用 SSL,其他的都可以。

非常感谢任何帮助!

【问题讨论】:

    标签: r ubuntu ssl curl


    【解决方案1】:

    亲爱的克里斯托夫·萨弗林,

    我的感觉是,您遇到了 RStudio / R 的 CRAN ssh by default 问题。

    解决方案

    将以下内容添加到您的目标机器.Rprofile

    options(download.file.method = "wget")
    local({
             r<- getOption("repos");
             r["CRAN"] <-"https://cran.rstudio.com/"
             options(repos=r)
    })
    

    说明

    安全下载方法

    当 R 通过 HTTP 传输文件(例如,使用 install.packages 或 download.file 函数)时,根据 download.file.method 选项选择下载方法。有几种方法可用,如果没有明确指定选项,则默认行为是使用 R 的内部 HTTP 实现。在许多情况下,此内部方法不支持 HTTPS 连接,因此您需要覆盖默认值。

    R 3.2

    R 3.2 包含两种新的下载方法(“libcurl”和“wininet”),它们都支持 HTTPS 连接。我们建议您在 R 3.2 下运行时使用这些新方法。添加到 .Rprofile 或 Rprofile.site 的必要代码如下:

    窗口

    options(download.file.method = "wininet")
    

    请注意,在即将发布的 R 3.2.2 版本中,这将不再是必需的,因为默认方法等同于“wininet”。

    OS X 和 Linux

    options(download.file.method = "libcurl")
    

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

    R 3.1 及更早版本

    窗户

    utils::setInternet2(TRUE)
    options(download.file.method = "internal")
    

    请注意,setInternet2(TRUE) 是 RStudio 中的默认值,但不适用于 R GUI。如果您不想在 Windows 上使用 setInternet2(TRUE),那么配置安全下载的唯一其他方法是在您的 PATH 上使用“wget”或“curl”实用程序,如下面的 OS X 和 Linux 所述。

    操作系统

    options(download.file.method = "curl")
    

    Linux

    options(download.file.method = "wget")
    

    请注意,只要所需的二进制文件位于系统 PATH 中,“curl”和“wget”方法就可以在任何平台上运行。上面的建议是基于“curl”包含在 OS X 中而“wget”包含在大多数 Linux 发行版中的事实。

    参考:https://support.rstudio.com/hc/en-us/articles/206827897-Secure-Package-Downloads-for-R

    【讨论】:

    • 感谢 Technophobe01 的帮助!设置options(download.file.method = "wget") 确实解决了这个问题。我想知道的一件事:我有capabilities("libcurl") == TRUE,但是将download.file 设置为libcurl 不起作用。我认为这不应该发生在 R 3.4 上?
    • Christoph - 看看github.com/hadley/devtools/issues/1244 解决方案: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,这对我有用。
    • 现在我注意到直接下载(例如在curl::curl() 中)效果不佳。叹。我正在手动下载作为该问题的解决方法。感谢您的所有帮助,这已经是向前迈出的一大步! :)
    • Christoph - 问题与 Anaconda 和 R 有关 github.com/ContinuumIO/anaconda-issues/issues/72 您可以删除 Conda 版本的 curl -> conda remove curl 并使用系统版本的 curl。有关其他选项,请参阅线程。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2021-02-02
    • 2016-04-19
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多