gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:53:11 25 4
gpt4 key购买 nike

当我使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com