ssl - 使用 `-k` 和不使用 `-k` 进行 curl

标签 ssl curl nginx haproxy insecure-connection

当我使用 curl 不带 -k 打开 url 时,我的请求通过了,我能够看到预期的结果。

$ 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

但是当我用 -k 打开相同的 url 时,它失败了。对我来说这没有任何意义,因为在我看来 -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

最佳答案

为了解决此类问题,--resolve option可能有用:

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

Provide a custom address for a specific host and port pair. Using this, you can make the curl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line. The port number should be the number used for the specific protocol the host will be used for. It means you need several entries if you want to provide address for the same host but different ports.

特别是如果您尝试从中获取的站点使用 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 代替指定 -k/--insecure --capath:

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 可能无法按预期使用某些代理配置。因此,如果您从客户端通过某种代理,并且可以在没有代理的情况下以某种方式直接进行测试,那么这可能值得探索。

关于ssl - 使用 `-k` 和不使用 `-k` 进行 curl ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41864571/

相关文章:

Java SSL 套接字不工作

git - 如何检查远程 git 存储库 URL 的有效性?

nginx - 子子域被 NGINX 中的子域覆盖

laravel - 使用反向代理Nginx时出现502错误的网关

ios - 带有 SSL 证书的 AFNetworking

rest - jquery 中对 rest api 的 ajax 调用不再有效,由过期的 ssl 证书引起?

ssl - 如何生成 PEM 文件来安装我自己的 SSL 证书?

c++ - 如何将此 curl 命令转换为 libcurl

json - 发送 JSON/XML/TXT/CSV 文件到 ElasticSearch

nginx - 非默认静态位置的 Flask nginx 和静态文件问题