【问题标题】:curl with `-k` and without `-k`curl 使用 `-k` 和没有 `-k`
【发布时间】:2017-06-11 09:35:20
【问题描述】:

当我使用curl 没有 -k 打开一个网址时,我的请求通过了,我能够看到预期的结果。

$ curl -vvv https://MYHOSTNAME/wex/archive.info -A SUKU$RANDOM
*   Trying 10.38.202.192...
* Connected to MYHOSTNAME (10.38.202.192) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.MYCNAME
* Server certificate: ProdIssuedCA1
* Server certificate: InternalRootCA
> GET /wex/archive.info HTTP/1.1
> Host: MYHOSTNAME
> User-Agent: SUKU19816
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.10.2
< Date: Thu, 26 Jan 2017 01:08:40 GMT
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 19
< Connection: keep-alive
< Set-Cookie: JSESSIONID=1XXXXXXXX3E58093E816FE62D81; Path=/wex/; HttpOnly
< X-WebProxy-Id: 220ffb81872a
< 




status=Running
* Connection #0 to host MYHOSTNAME left intact

但是当我打开相同的网址时 with -k 它失败了。对我来说它没有任何意义,因为据我了解-k 的目的只是跳过证书验证

$ curl -vvv https://MYHOSTNAME/wex/archive.info -A SUKU$RANDOM -k
*   Trying 10.38.202.192...
* Connected to MYHOSTNAME (10.38.202.192) port 443 (#0)
* Server aborted the SSL handshake
* Closing connection 0
curl: (35) Server aborted the SSL handshake

请求流程:

  1. HAPROXY 机器上发生 SSL 终止
  2. HAPROXY 会将请求转发给 nginx

【问题讨论】:

    标签: ssl curl nginx haproxy insecure-connection


    【解决方案1】:

    对于解决此类问题,--resolve option 可能很有用:

    curl -k -I --resolve www.example.com:80:192.0.2.1 https://www.example.com/
    

    为特定主机和端口对提供自定义地址。使用 这样,您可以使 curl 请求使用指定的地址并 防止使用其他正常解析的地址。考虑 它是命令行上提供的一种 /etc/hosts 替代方案。这 端口号应该是用于特定协议的号码 主机将用于。这意味着如果需要,您需要多个条目 为同一主机提供不同端口的地址。

    特别是如果您尝试从中获取的站点使用 SNI:在这种情况下,您可以使用 --resolve 选项来指定在 TLS 客户端 hello 中使用的服务器名称。

    尝试一个故障排除步骤:更新 curlcompile it yourself from the sources 并重试。一方面,某些curl 版本(例如MacOS)可能不会为-k/--insecure 发送SNI。

    如果这是您遇到的问题,并且您无法替换 curlthere’s a workaround you can use,这主要涉及创建您自己的 CA、私钥和 CSR,并调整您的 haproxy。

    设置完成后,您可以使用--cacert--capath 代替指定-k/--insecure

    curl https://example.com/api/endpoint --cacert certs/servers/example.com/chain.pem
    curl https://example.com/api/endpoint --capath certs/ca
    

    如果您遇到的问题是由 SNI 引起的,您也可以使用 https://sni.velox.ch/ 之类的网站进行故障排除:

    curl --insecure https://sni.velox.ch/
    

    否则,如果不是 SNI,那么我记得在某处看到 -k/--insecure 在某些代理配置下可能无法按预期工作。因此,如果您从客户端通过某种代理,并且您可以在没有代理的情况下以某种方式直接进行测试,那可能值得探索。

    【讨论】:

    猜你喜欢
    • 2021-04-20
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多