IIS 10 和 HTTP/2 - 需要客户端证书 [英] IIS 10 and HTTP/2 - require client certificate

查看:56
本文介绍了IIS 10 和 HTTP/2 - 需要客户端证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently I'm testing web-application on IIS 10 using HTTP 1.1 and HTTP/2. My test application has one endpoint (/api/test) which returns just 'true'. I have 3 certificates:

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

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

Root CA and Server certificate installed on Windows Server 2016, and IIS website configured for listen https://example.net:8081/ using Server certificate. Also I configure website to require client certificate (it is important for my tests, I need server/client certificates validation).

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

I test my app via curl, and for http1.1 all works fine.

命令:

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 发送请求,它在服务器证书验证后失败.

But if I try to send request using http/2, it is failed after server certificate validation.

命令:

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 日志中,我看到下一条记录:

In IIS logs I see next records:

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 状态代码).

So, for http/2 it seems like client certificate absent (403.7 status code).

最后,如果我只是在 IIS 站点设置中将需要客户端证书"更改为忽略客户端证书" - http1.1 和 http/2 都可以使用.

And finally, if I'll just change 'require client certificate' to 'ignore client certificate' on IIS site settings - http1.1 and http/2 work both.

如何在 IIS 上使用带有 HTTP/2 的客户端证书?

How can I use client certificate with HTTP/2 on IIS?

推荐答案

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

After couple hours of research, I find out that the IIS 10 currently doesn't support HTTP/2 with client certificate verification.

https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/http2-on-iis#when-is-http2 不支持

在少数情况下,HTTP/2 不能与其他功能结合使用.在这些情况下,Windows 将回退到 HTTP/1.1 并继续事务.这可能涉及在握手期间协商 HTTP/1.1,或向客户端发送错误代码,指示其通过 HTTP/1.1 连接重试.

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 作为应用程序的代理,一切正常.

I was reconfigure my server to use nginx instead of IIS as a proxy for app, and all works fine.

这篇关于IIS 10 和 HTTP/2 - 需要客户端证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆