ssl - IIS 10 和 HTTP/2 - 需要客户端证书

标签 ssl tls1.2 http2 client-certificates iis-10

目前,我正在使用 HTTP 1.1 和 HTTP/2 在 IIS 10 上测试 Web 应用程序。 我的测试应用程序有一个端点 (/api/test),它只返回“true”。 我有 3 个证书:

  • 根 CA(自签名)
  • 由根 CA 签署的服务器证书
  • 由根 CA 签署的客户端证书

安装在 Windows Server 2016 上的根 CA 和服务器证书,以及为监听配置的 IIS 网站 https://example.net:8081/使用服务器证书。此外,我将网站配置为需要客户端证书(这对我的测试很重要,我需要服务器/客户端证书验证)。

我通过 curl 测试我的应用程序,对于 http1.1 一切正常。

命令:

curl.exe --http1.1 --get --url https://example.net:8081/api/test --cacert E:\ca.pem --cert E:\client.pem --key E:\client.key --cert-type PEM --verbose

输出:

* TCP_NODELAY set
* Connected to example.net port 8081 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: E:\ca.pem
  CApath: none
* 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-ECDSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate: XXX
*  SSL certificate verify ok.
> GET /api/test HTTP/1.1
> Host: example.net:8081
> User-Agent: curl/7.61.1
> Accept: */*
>
* TLSv1.2 (IN), TLS handshake, Hello request (0):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (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, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS handshake, CERT verify (15):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
< Server: Kestrel
< Date: Tue, 18 Sep 2018 13:45:35 GMT
<
true* Connection #0 to host abrakadabra.cranecs.net left intact

但是如果我尝试使用 http/2 发送请求,则在服务器证书验证后失败。

命令:

curl.exe --http2 --get --url https://example.net:8081/api/test --cacert E:\ca.pem --cert E:\client.pem --key E:\client.key --cert-type PEM --verbose

输出:

* TCP_NODELAY set
* Connected to example.net port 8081 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: E:\ca.pem
  CApath: none
* 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-ECDSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate: XXX
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x1f635299100)
> GET /api/test HTTP/2
> Host: example.net:8081
> User-Agent: curl/7.61.1
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
* HTTP/2 stream 0 was not closed cleanly: HTTP_1_1_REQUIRED (err 13)
* stopped the pause stream!
* Connection #0 to host example.net left intact
curl: (92) HTTP/2 stream 0 was not closed cleanly: HTTP_1_1_REQUIRED (err 13)

在 IIS 日志中我看到下一条记录:

2018-09-18 13:46:00 172.32.0.193 GET /api/test - 8081 - 134.17.25.89 HTTP/1.1 curl/7.61.1 - 200 0 0 421
2018-09-18 13:55:01 172.32.0.193 GET /api/test - 8081 - 134.17.25.89 HTTP/2.0 curl/7.61.1 - 403 7 64 0

因此,对于 http/2,似乎缺少客户端证书(403.7 状态代码)。

最后,如果我只是将 IIS 站点设置中的“需要客户端证书”更改为“忽略客户端证书”——http1.1 和 http/2 都可以。

如何在 IIS 上将客户端证书与 HTTP/2 一起使用?

最佳答案

经过几个小时的研究,我发现 IIS 10 目前不支持带客户端证书验证的 HTTP/2。

https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/http2-on-iis#when-is-http2-not-supported

In a few cases, HTTP/2 can't be used in combination with other features. In these situations, Windows will fall back to HTTP/1.1 and continue the transaction. This may involve negotiating HTTP/1.1 during the handshake, or sending an error code to the client instructing it to retry over an HTTP/1.1 connection.

我正在重新配置我的服务器以使用 nginx 而不是 IIS 作为应用程序的代理,并且一切正常。

关于ssl - IIS 10 和 HTTP/2 - 需要客户端证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52388471/

相关文章:

java - 如何在 JAVA 中加速 tls 协商?

http - 如何将 Ruby on Rails 网站从 http 1 更新到 http 2

java - 间歇性 SSL 握手错误

php - 如何检查 PHP CURL SSL 是否有效

ssl - 多个 Internet 站点的 Lotus/IBM Domino 服务器 SSL 配置

ios - 来自 HTTPS URLSession.dataTask 的 0 字节数据

java - key 管理器可以引用 WildFly 中的凭证存储吗?

windows - login.live.com 的 s_client 证书验证在 Windows 中失败

Google Chrome 中的 HTTP/2 响应 header 字段不是 Pascal 大小写

amazon-web-services - AWS/ALB、http/2 和 GOAWAY