简体   繁体   English

在IIS 6上使用ASP.NET MVC站点的客户端证书

[英]Working with client certificates for an ASP.NET MVC site on IIS 6

Wanting to implement authentication by client certificates I am experiencing some issues. 想要通过客户端证书实现身份验证我遇到了一些问题。

First some facts 首先是一些事实

The whole site is using SSL. 整个网站都在使用SSL。 I am using IIS 6 (on Windows Server 2003) and have configured the site to accept client certificates, not requiring them. 我正在使用IIS 6(在Windows Server 2003上),并已将站点配置为接受客户端证书,而不是它们。 Most browsers are however implemented in a way so that they will only ask the user for a certificate when it is strictly required. 然而,大多数浏览器以某种方式实现,以便它们仅在严格要求时才询问用户证书。 Because of this the authentication model isn't really useful. 因此,身份验证模型并不真正有用。

Suggestions of my own 我自己的建议

My first idea was to set the HttpResponse.Status property but it requires the characters before the first space to be an integer. 我的第一个想法是设置HttpResponse.Status属性,但它要求第一个空格之前的字符是一个整数。 The useful status for getting a browser to send a client certificate is 403.7 Client certificate required so this will not work (unless you can overwrite it). 获取浏览器发送客户端证书的有用状态是403.7 Client certificate required因此这将不起作用(除非您可以覆盖它)。

I also thought that I would just configure IIS to require client certificates for a specific paths, but this - of cource - works only with physical files and not with routing. 我还认为我只是将IIS配置为需要特定路径的客户端证书,但这个 - 源代码 - 仅适用于物理文件而不适用于路由。

A possible solution is to make a specific folder and require client certificates for it which is more of a hack than a solution. 一个可能的解决方案是创建一个特定的文件夹,并要求它的客户端证书,这是一个黑客而不是解决方案。 So I would like to avoid this if someone has a better proposal. 如果有人有更好的建议,我想避免这种情况。

Clarifications 澄清

I have tested the browser response of both Internet Explorer, Firefox and Chrome (I use Chrome as my primary browser and Firefox as secondary). 我测试了Internet Explorer,Firefox和Chrome的浏览器响应(我使用Chrome作为主浏览器,Firefox作为辅助浏览器)。 None of the browsers asks for the client certificate unless I - in IIS - configure it as required. 除非我 - 在IIS中 - 根据需要配置它,否则所有浏览器都不会要求提供客户端证书。

The HTTP status code 403.7 is due to my understanding allowed as the RFC 2616 only defines the status code as the first three digits. HTTP状态代码403.7是由于我的理解允许,因为RFC 2616仅将状态代码定义为前三位数。 As IIS 6 returns the 403.7 when a client certificate is required, I thought sending it would force IIS into a special mode triggering a requirement. 当IIS 6在需要客户端证书时返回403.7,我认为发送它会强制IIS进入触发需求的特殊模式。

I guess the problem now is how to configure IIS for requiring a certficate given an virtual path and not a physical. 我想现在的问题是如何配置IIS以获得给定虚拟路径而不是物理路径的证书。

There's no difference in the CertificateRequest message sent by a server when the certificate is merely requested, rather than required. 仅在请求证书时,服务器发送的CertificateRequest消息没有区别,而不是必需的。 The server makes the same request in both cases, and simply terminates the handshake when a client fails to provide a required certificate. 服务器在两种情况下都发出相同的请求,并在客户端无法提供所需证书时简单地终止握手。 Thus, if your browser appears to be ignoring "requests", it should appear to ignore "requirements" too. 因此,如果您的浏览器似乎忽略了“请求”,它似乎也会忽略“要求”。

Check for the following: 检查以下内容:

  • Is your browser configured to ignore all certificate requests, never sending one? 您的浏览器是否配置为忽略所有证书请求,从不发送一个?
  • Is your browser configured to use a given certificate without prompting the user? 您的浏览器是否配置为使用给定的证书而不提示用户? (In other words, how do you know that the browser isn't sending a certificate?) (换句话说,你怎么知道浏览器没有发送证书?)
  • Is your server actually requesting a certificate? 您的服务器实际上是在申请证书吗?

The way I test this last case is with the OpenSSL (also available in Cygwin ) tool: 我测试最后一种情况的方法是使用OpenSSL (也可以在Cygwin中使用 )工具:

openssl s_client -connect server.y.com:443 -msg

After the server sends its Certificate message, it will insert a CertificateRequest method which is absent if it is not requesting client authentication. 服务器发送其证书消息后,它将插入一个CertificateRequest方法,如果它没有请求客户端身份验证,则该方法不存在。 The s_client output looks like this: s_client输出如下所示:

<<< TLS 1.0 Handshake [length 0008], CertificateRequest
    0d 00 00 04 01 01 00 00

I'm not sure how it works if the server uses client authentication only on specific paths, because the initial SSL handshake is complete before the client transmits the HTTP request. 如果服务器仅在特定路径上使用客户端身份验证,我不确定它是如何工作的,因为在客户端传输HTTP请求之前,初始SSL握手已完成。 It would be reasonable for the server to request a new handshake at this point, but I've never tested to see what servers support this. 此时服务器请求新的握手是合理的,但我从未测试过要查看哪些服务器支持此操作。

You can fake an HTTP request via s_client by hand, entering: 您可以通过s_client手动伪造HTTP请求,输入:

GET /your/path/here HTTP/1.1[Enter]
Host: server.y.com:443[Enter]
[Enter]

If you never see a CertificateRequest message at all, your server isn't set up correctly. 如果您根本看不到CertificateRequest消息,则说明您的服务器设置不正确。

Specifying security constraints based on directory structure is quite common and can actually simplify administration of security nicely. 根据目录结构指定安全性约束是很常见的,实际上可以很好地简化安全性管理。 Don't feel bad about it if this offers a solution for you. 如果能为您提供解决方案,请不要为此感到难过。

403.7 is not an HTTP status code. 403.7不是HTTP状态代码。 Is that some Microsoft "embrace, extend, and extinguish" subterfuge? 这是微软“拥抱,延伸和消灭”一些诡计吗? In any case, it doesn't sound like the right direction to pursue, since this is a transport layer problem, not an application layer problem. 在任何情况下,它听起来都不是正确的方向,因为这是传输层问题,而不是应用层问题。

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

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