Tri*_*ack 7 ssl networking curl client-certificates
我正在尝试发送一个简单的 curl 请求:
curl -k -i --key ./key.pem --cert ./cert.pem https://target_ip/whatever/
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是它不发送任何证书。验证显然通过,否则我会收到诸如密钥不匹配之类的错误,但是我可以在wireshark中看到证书没有在客户端Hello的TCP连接中发送。开关喜欢--verbose或--cacert不做太多。
我能够通过邮递员成功发送完全相同的证书。
我尝试从各种来源发送相同的 curl 请求,例如我的 WSL2 ubuntu、云中的 debian 容器、VM,...
为什么不发送证书的任何提示?
编辑 I - curl -v 的输出
* Trying 52.xxx.xxx.xx:443...
* TCP_NODELAY set
* Connected to 52.xxx.xxx.xx (52.xxx.xxx.xx) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: CN=NGINXIngressController
* start date: Aug 10 18:08:13 2020 GMT
* expire date: Aug 10 18:08:13 2021 GMT
* issuer: CN=NGINXIngressController
* SSL certificate verify result: self signed certificate (18), continuing anyway.
> GET /whatever/ HTTP/1.1
> Host: custom.localhost.dev
> User-Agent: curl/7.68.0
> Accept: */*
> Authorization: Bearer eyJ0...
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden
< Server: nginx/1.19.0
Server: nginx/1.19.0
< Date: Mon, 10 Aug 2020 22:23:24 GMT
Date: Mon, 10 Aug 2020 22:23:24 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 153
Content-Length: 153
< Connection: keep-alive
Connection: keep-alive
<
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.19.0</center>
</body>
</html>
* Connection #0 to host 52.xxx.xxx.xx left intact
Run Code Online (Sandbox Code Playgroud)
编辑二-wireshark 捕获
匿名 pcap 似乎太麻烦了,所以这里只是一些快照。希望你能看到你需要的一切。我已经突出显示了我没有(没有)看到正在发送的证书的数据包。请注意,我在 Windows 工作站上运行邮递员,而 curl 在 WSL2 中,因此源地址不同。不过,其他 curl 主机的行为确实相同。
卷曲
邮差
编辑 III - 客户问候
卷曲
邮差
ClientHello 显示了一个明显的区别:邮递员使用server_name扩展 (SNI) 来提供预期的主机名,而 curl 则没有。
这可能会触发 Web 服务器中配置的不同部分:邮递员触发对特定虚拟主机的访问,server_name而 curl 可能会遇到默认配置。假设只有特定的虚拟主机启用客户端证书,这就解释了为什么服务器只将 CertificateRequest 发送给邮递员而不是 curl。
目前还不清楚这个主机名是什么,但根据长度,它不能是 IP 地址。因此邮递员不知何故必须知道服务器的预期主机名,即使它声称访问是https://target_ip/仅使用的,即没有给定的主机名。curl 无法从此 URL 派生预期的主机名,因此无法设置server_name. 要使 curlserver_name在仍然能够访问特定 IP 的同时知道要设置的主机名,请使用以下--resolve选项:
curl --resolve hostname:443:target_ip https://hostname/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2825 次 |
| 最近记录: |