authentication - IIS 7.5 和客户端身份验证

标签 authentication client certificate iis-7.5

我必须做一个概念证明,到目前为止,我主要发现引用 IIS6 的旧文章没有帮助。

总之我有以下要求。

我需要保护一个文件/页面,而这一个文件/页面仅使用客户端证书。站点的其余部分确实需要在 SSL 下继续运行,但不需要客户端证书,只需这个文件。禁止用户映射,因为映射将通过 C#/VB.NET 以编程方式完成。

现在我知道这应该不难。我的意思是我应该可以访问 Request.ClientCertificate 属性,但我的问题是,在我的测试中,我无法获得客户端证书来通过网络传输。

我已经在一个文件夹上设置了 IIS(只是为了让我的生活简单)需要 SSL 并接受客户端证书以及需要客户端证书,但是一旦访问该页面,我从 iis 得到的只是HTTP/1.1 403 Forbidden .我从来没有被要求选择一个客户端证书发送到服务器,它只是在我的请求中喷出并丢弃它。

当我使用一些代码来测试它时,它变得更加奇怪。在此客户端代码中,CertPolicy 类仅从忽略证书错误的方法返回 true,而 test.cer 是使用 MakeCert 制作的自签名证书。只是为了说清楚,只有客户端证书如果是自签名的,主证书是正确签名的,但我经常玩 fiddler ,我不信任那个证书,所以这就是我有 hacky 回调的原因。

Dim Cert As X509Certificate = X509Certificate.CreateFromCertFile("Cert\test.cer")
' Handle any certificate errors on the certificate from the server.
ServicePointManager.CertificatePolicy = New CertPolicy()
' You must change the URL to point to your Web server.
Dim Request As HttpWebRequest = DirectCast(WebRequest.Create("https://local.domain.com/Cert/Server/"), HttpWebRequest)
Request.ClientCertificates.Add(Cert)
Request.UserAgent = "Client Cert Sample"
Request.Method = "GET"

Dim sr As StreamReader
Using Response As HttpWebResponse = DirectCast(Request.GetResponse, HttpWebResponse)
    ' Print the repsonse headers.
    output.AppendFormat("{0}\r\n", Response.Headers)
    output.AppendLine()
    ' Get the certificate data.
    sr = New StreamReader(Response.GetResponseStream, Encoding.Default)
    Dim count As Integer
    Dim ReadBuf() As Char = New Char((1024) - 1) {}
    Do
        count = sr.Read(ReadBuf, 0, 1024)
        If Not 0 = count Then
            output.AppendLine(New String(ReadBuf))
        End If
    Loop While (count > 0)
End Using

目标页面只返回附加的证书数量,如果我将 IIS 设置为接受或忽略客户端证书但不需要,它总是返回。
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)
    Dim cs As HttpClientCertificate = Request.ClientCertificate
    Response.Write(cs.Count)
    Response.End()
End Sub

如果有人可以帮助我了解如何配置 IIS7.5 以允许将客户端证书附加到请求并直接通过,那就太好了。

最佳答案

这是一个老问题,但我在寻找自己的答案时发现了它,并认为应该回答它。在网站的 web.config 中,要启用客户端证书,您必须首先确保安装了身份验证模块,然后启用该功能:

<location path="yourpath">
  <system.webServer>
    <security>
      <access sslFlags="Ssl, SslNegotiateCert"/> <!-- or SslRequireCert --> 
      <authentication>
        <iisClientCertificateMappingAuthentication enabled="true" 
            oneToOneCertificateMappingsEnabled="true"> 
            <!-- or manyToOneCertificateMappingsEnabled="true" -->
        </iisClientCertificateMappingAuthentication>
      </authentication>
    </security>
  </system.webServer>
</location>

然后在 iisClientCertificateMappingAuthentication 中添加一对一或多对一映射。元素。

关于authentication - IIS 7.5 和客户端身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3553057/

相关文章:

jquery - Ajax 回调如何意识到用户的身份验证 session 已超时?

c# - ASP.NET Core WebAPI Cookie + JWT 认证

WCF 客户端代理异常 - "Type cannot be added to list of known types"

c# - 使用证书签署文件

新 mac 机器上的 iPhone 证书和配置...等?

c - 如何获取整个X509证书的大小

performance - Linux - HTPASSWD 文件太大? (超过2000个用户)

javascript - 获取站点加载脚本和库的进度

design-patterns - 在客户端-服务器架构中使用 MVC( Model View Controller )

docker - Docker上的Elastic 6:无法设置密码