简体   繁体   English

服务器不接受在HttpClientHandler上设置的证书

[英]Certificate set on HttpClientHandler not accepted by Server

The scenario is as follows: Users connect to a webserver using certificate authentication, the server is making calls to other services and I would like to forward/send the certificate that I received on the server to the authenticate the user by services. 方案如下:用户使用证书身份验证连接到Web服务器,服务器正在调用其他服务,我想转发/发送我在服务器上收到的证书,以通过服务对用户进行身份验证。

I am using the following code on the webserver to set the client certificate on HttpClientHandler and I can see in debug mode that the client certificate is valid in the HttpContext below. 我在网络服务器上使用以下代码在HttpClientHandler上设置客户端证书,并且在调试模式下可以看到客户端证书在下面的HttpContext中有效。

X509Certificate2 cert = new X509Certificate2(HttpContext.Request.ClientCertificate.Certificate);

var httpClientHandler = new WebRequestHandler();
httpClientHandler.UseDefaultCredentials = true;
httpClientHandler.PreAuthenticate = true;
httpClientHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
httpClientHandler.ClientCertificates.Add(cert);

When I receive the request in service code, the certificate has been stripped off (or it could be that the above code never sent it). 当我收到服务代码中的请求时,证书已被剥离(或者可能是上述代码从未发送过)。 Any ideas whats going on and what should be different in the code above? 有什么想法在上面的代码中发生了什么,什么应该与上面的代码有所不同?

FYI both the web-server and the services are running on the same machine. 仅供参考,Web服务器和服务都在同一台计算机上运行。 To be more precise the services run as applications within the same website on IIS 更精确地说,这些服务在IIS上的同一网站中作为应用程序运行

In your scenario, your site's clients will not be your services' clients; 在您的方案中,您网站的客户将不是您服务的客户; rather your site will be your services' client. 而是您的网站将成为您服务的客户。 As you say, "the [web] server [(ie site)] is making calls to other services". 如您所说,“ [Web]服务器[(即站点)]正在呼叫其他服务”。

The service requests that your site makes are going to have their own contexts distinct from requests sent to your site that trigger them. 您网站发出的服务请求将具有自己的上下文,这些上下文不同于发送给您网站的触发它们的请求。

I doubt that you want to reuse the client certificates from requests to your site in your site's corresponding service requests; 我怀疑您想在站点的相应服务请求中重用从请求到站点的客户端证书; it sounds like you only intend your site to call your services. 听起来您只打算让您的网站致电您的服务。 If you do, however, you can set up your services for client-certificate authentication (eg a related SO question speaks to doing this with a WCF service), get the client certificate from each request to your site, then use it in each related request that your site sends to your services. 但是,如果您这样做了,则可以设置用于客户端证书身份验证的服务(例如, 一个相关的SO问题涉及使用WCF服务执行此操作),从每个请求中获取客户端证书到您的站点,然后在每个相关请求中使用它。请求您的网站发送给您的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM