IIS 客户端证书映射身份验证

您所在的位置:网站首页 服务端验证客户端证书 IIS 客户端证书映射身份验证

IIS 客户端证书映射身份验证

2024-07-17 03:22| 来源: 网络整理| 查看: 265

IIS 客户端证书映射身份验证 项目 03/25/2024

概述

元素的 元素指定使用 IIS 的客户端证书映射身份验证的设置。

使用 IIS 映射客户端证书有两种不同的方法:

一对一映射 - 这些映射将单个客户端证书与单个用户帐户进行一对一匹配;每个客户端证书将映射到一个用户帐户。 多对一映射 - 这些映射根据客户端证书中的子字段将多个证书与用户帐户进行匹配。

注意

使用 IIS 的客户端证书映射身份验证与使用 Active Directory 的客户端证书映射在以下几个方面有所不同:

使用 Active Directory 的客户端证书映射身份验证 - 这种身份验证方法要求 IIS 7 服务器和客户端计算机是 Active Directory 域的成员,并且用户帐户存储在 Active Directory 中。 由于需要往返 Active Directory 服务器,此客户端证书映射身份验证方法性能有所降低。 IIS 客户端证书映射身份验证 - 此方法不需要 Active Directory,因此适用于独立服务器。 这种客户端证书身份验证方法提高了性能,但需要更多配置,并且需要访问客户端证书才能创建映射。

有关详细信息,请参阅 Microsoft TechNet 网站上的 在 IIS 7.0 中配置身份验证。

兼容性 版本 说明 IIS 10.0 元素在 IIS 10.0 中未进行修改。 IIS 8.5 元素在 IIS 8.5 中未进行修改。 IIS 8.0 元素在 IIS 8.0 中未进行修改。 IIS 7.5 元素在 IIS 7.5 中未进行修改。 IIS 7.0 IIS 7.0 中引入了 元素的 元素。 IIS 6.0 元素取代了 IIS 6.0 IIsCertMapper 元数据库对象。

安装

元素在 IIS 7 及更高版本的默认安装中不可用。 若要安装它,请使用以下步骤。

Windows Server 2012 或 Windows Server 2012 R2 在任务栏上,单击 “服务器管理器”。 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。 在“服务器角色”页上,依次展开“Web 服务器 (IIS)”、“Web 服务器”和“安全性”,然后选择“IIS 客户端证书映射身份验证”。 单击 “下一步” 。 在“选择功能”页上,单击“下一步”。 在“确认安装选择”页上,单击“安装”。 在“结果” 页面中单击“关闭” 。 Windows 8 或 Windows 8.1 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”。 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。 依次展开“Internet Information Services”、“万维网服务”和“安全性”,然后选择“IIS 客户端证书映射身份验证”。 单击“确定”。 单击“关闭” 。 Windows Server 2008 或 Windows Server 2008 R2 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器(IIS)”。 在“Web 服务器(IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。 在“添加角色服务向导”的“选择角色服务”页上,选择“IIS 客户端证书映射身份验证”,然后单击“下一步”。 在“确认安装选择”页中,单击“安装”。 在“结果” 页面中单击“关闭” 。 Windows Vista 或 Windows 7 在任务栏上,单击“开始”,然后单击“控制面板”。 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。 展开“Internet Information Services”,然后选择“IIS 客户端证书映射身份验证”,然后单击“确定”。

操作方式

IIS 7 中没有用于配置 IIS 客户端证书映射身份验证的用户界面。 有关如何以编程方式配置 IIS 客户端证书映射身份验证的示例,请参阅本文档的代码示例部分。

配置

元素的 元素可在服务器和站点级别进行配置。

特性 属性 说明 defaultLogonDomain 可选的 String 属性。

指定服务器对用户进行身份验证所使用的默认域。

enabled 可选布尔属性。

指定是否启用使用 IIS 的客户端证书映射身份验证。

默认为 false。

logonMethod 可选的枚举属性。

logonMethod 属性可以是下列可能值之一。 (有关这些值的详细信息,请参阅 LogonUser。)

默认为 ClearText。

值 说明 Batch 此登录类型适用于批处理服务器,无需用户直接干预即可代表用户执行进程。

数值为 1。

ClearText 此登录类型保留身份验证包中的姓名和密码,从而允许服务器在模拟客户端时连接到其他网络服务器。

数值为 3。

Interactive 此登录类型适用于以交互方式使用计算机的用户。

数值为 0。

Network 此登录类型适用于高性能服务器对明文密码进行身份验证。 不会缓存此登录类型的凭据。

数值为 2。

manyToOneCertificateMappingsEnabled 可选布尔属性。

指定是否启用多对一映射

默认值为 true。

oneToOneCertificateMappingsEnabled 可选布尔属性。

指定是否启用一对一映射

默认值为 true。

子元素 元素 说明 manyToOneMappings 可选元素。

将客户端证书映射到一组通配符条件,这些条件对证书进行身份验证并分配用户帐户。

oneToOneMappings 可选元素。

指定一对一客户端证书映射。

配置示例

以下配置示例对默认网站执行以下操作:

使用多对一证书映射启用 IIS 客户端证书映射身份验证。 根据与 Contoso 匹配的客户端证书主题中的组织字段,为用户帐户创建多对一证书映射规则。 将站点配置为要求 SSL 并协商客户端证书。

以下配置示例启用了使用默认网站的一对一证书映射的 IIS 客户端证书映射身份验证,为用户帐户创建单个一对一证书映射,并将站点配置为要求 SSL 并协商客户端证书。

如何从客户端证书检索 Base-64 编码字符串

注意

若要检索本主题中所有示例的 Base-64 编码证书数据,可以使用以下步骤导出证书:

单击“开始”,然后单击“运行”。

键入 MMC,然后单击“确定”。

当 Microsoft 管理控制台打开时,单击“文件”,然后单击“添加/删除管理单元”。

在“添加或删除管理单元”对话框中:

突出显示可用管理单元列表中的“证书”,然后单击“添加”。 选择以管理“我的用户帐户”的证书,然后单击“完成”。 单击 “确定” 关闭对话框。

在“Microsoft 管理控制台”中:

依次展开“证书 - 当前用户”、“个人”和“证书”。 在证书列表中,右键单击要导出的证书,然后单击“所有任务”和“导出”。

当“证书导出向导”打开时:

单击 “下一步” 。 选择“不,不导出私钥”,然后单击“下一步”。 选择“Base-64 编码的 X.509 9 (.CER)”作为导出格式,然后单击“下一步”。 选择将证书保存到桌面并命名为“MyCertificate.cer”,然后单击“下一步”。 单击“完成”;应看到一个对话框,提示导出成功。

关闭 Microsoft 管理控制台。

使用 Windows 记事本打开导出的 MyCertificate.cer 文件:

删除文本开头的“-----BEGIN CERTIFICATE-----”。 删除文本末尾的“-----END CERTIFICATE-----”。 将所有行连接成一行文本,这是用于本主题中所有示例的 Base-64 编码证书数据。

代码示例

以下代码示例对默认网站执行以下操作:

使用多对一证书映射启用 IIS 客户端证书映射身份验证。 根据与 Contoso 匹配的客户端证书主题中的组织字段,为用户帐户创建多对一证书映射规则。 将站点配置为要求 SSL 并协商客户端证书。 AppCmd.exe appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /enabled:"True" /manyToOneCertificateMappingsEnabled:"True" /commit:apphost appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /+"manyToOneMappings.[name='Contoso Employees',enabled='True',permissionMode='Allow',userName='Username',password='Password']" /commit:apphost appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/iisClientCertificateMappingAuthentication /+"manyToOneMappings.[name='Contoso Employees'].rules.[certificateField='Subject',certificateSubField='O',matchCriteria='Contoso',compareCaseSensitive='True']" /commit:apphost appcmd.exe set config "Default Web Site" -section:system.webServer/security/access /sslFlags:"Ssl, SslNegotiateCert" /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

C# using System; using System.Text; using Microsoft.Web.Administration; internal static class Sample { private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection iisClientCertificateMappingAuthenticationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site"); iisClientCertificateMappingAuthenticationSection["enabled"] = true; iisClientCertificateMappingAuthenticationSection["manyToOneCertificateMappingsEnabled"] = true; ConfigurationElementCollection manyToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("manyToOneMappings"); ConfigurationElement addElement = manyToOneMappingsCollection.CreateElement("add"); addElement["name"] = @"Contoso Employees"; addElement["enabled"] = true; addElement["permissionMode"] = @"Allow"; addElement["userName"] = @"Username"; addElement["password"] = @"Password"; ConfigurationElementCollection rulesCollection = addElement.GetCollection("rules"); ConfigurationElement addElement1 = rulesCollection.CreateElement("add"); addElement1["certificateField"] = @"Subject"; addElement1["certificateSubField"] = @"O"; addElement1["matchCriteria"] = @"Contoso"; addElement1["compareCaseSensitive"] = true; rulesCollection.Add(addElement1); manyToOneMappingsCollection.Add(addElement); ConfigurationSection accessSection = config.GetSection("system.webServer/security/access", "Default Web Site"); accessSection["sslFlags"] = @"Ssl, SslNegotiateCert"; serverManager.CommitChanges(); } } } VB.NET Imports System Imports System.Text Imports Microsoft.Web.Administration Module Sample Sub Main() Dim serverManager As ServerManager = New ServerManager Dim config As Configuration = serverManager.GetApplicationHostConfiguration Dim iisClientCertificateMappingAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site") iisClientCertificateMappingAuthenticationSection("enabled") = True iisClientCertificateMappingAuthenticationSection("manyToOneCertificateMappingsEnabled") = True Dim manyToOneMappingsCollection As ConfigurationElementCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("manyToOneMappings") Dim addElement As ConfigurationElement = manyToOneMappingsCollection.CreateElement("add") addElement("name") = "Contoso Employees" addElement("enabled") = True addElement("permissionMode") = "Allow" addElement("userName") = "Username" addElement("password") = "Password" Dim rulesCollection As ConfigurationElementCollection = addElement.GetCollection("rules") Dim addElement1 As ConfigurationElement = rulesCollection.CreateElement("add") addElement1("certificateField") = "Subject" addElement1("certificateSubField") = "O" addElement1("matchCriteria") = "Contoso" addElement1("compareCaseSensitive") = True rulesCollection.Add(addElement1) manyToOneMappingsCollection.Add(addElement) Dim accessSection As ConfigurationSection = config.GetSection("system.webServer/security/access", "Default Web Site") accessSection("sslFlags") = "Ssl, SslNegotiateCert" serverManager.CommitChanges() End Sub End Module JavaScript var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager'); adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"; var iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site"); iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = true; iisClientCertificateMappingAuthenticationSection.Properties.Item("manyToOneCertificateMappingsEnabled").Value = true; var manyToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("manyToOneMappings").Collection; var addElement = manyToOneMappingsCollection.CreateNewElement("add"); addElement.Properties.Item("name").Value = "Contoso Employees"; addElement.Properties.Item("enabled").Value = true; addElement.Properties.Item("permissionMode").Value = "Allow"; addElement.Properties.Item("userName").Value = "Username"; addElement.Properties.Item("password").Value = "Password"; var rulesCollection = addElement.ChildElements.Item("rules").Collection; var addElement1 = rulesCollection.CreateNewElement("add"); addElement1.Properties.Item("certificateField").Value = "Subject"; addElement1.Properties.Item("certificateSubField").Value = "O"; addElement1.Properties.Item("matchCriteria").Value = "Contoso"; addElement1.Properties.Item("compareCaseSensitive").Value = true; rulesCollection.AddElement(addElement1); manyToOneMappingsCollection.AddElement(addElement); var accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site"); accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert"; adminManager.CommitChanges(); VBScript Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager") adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" Set iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site") iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = True iisClientCertificateMappingAuthenticationSection.Properties.Item("manyToOneCertificateMappingsEnabled").Value = True Set manyToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("manyToOneMappings").Collection Set addElement = manyToOneMappingsCollection.CreateNewElement("add") addElement.Properties.Item("name").Value = "Contoso Employees" addElement.Properties.Item("enabled").Value = True addElement.Properties.Item("permissionMode").Value = "Allow" addElement.Properties.Item("userName").Value = "Username" addElement.Properties.Item("password").Value = "Password" Set rulesCollection = addElement.ChildElements.Item("rules").Collection Set addElement1 = rulesCollection.CreateNewElement("add") addElement1.Properties.Item("certificateField").Value = "Subject" addElement1.Properties.Item("certificateSubField").Value = "O" addElement1.Properties.Item("matchCriteria").Value = "Contoso" addElement1.Properties.Item("compareCaseSensitive").Value = True rulesCollection.AddElement(addElement1) manyToOneMappingsCollection.AddElement(addElement) Set accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site") accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert" adminManager.CommitChanges()

以下代码示例启用了使用默认网站的一对一证书映射的 IIS 客户端证书映射身份验证,为用户帐户创建单个一对一证书映射,并将站点配置为要求 SSL 并协商客户端证书。

注意

若要检索下面列出的代码示例的 Base-64 编码证书数据,可以使用本文档的“配置详细信息”部分中列出的步骤导出证书。

AppCmd.exe

注意

由于 AppCmd.exe 无法分析证书字符串中的某些字符,因此不应使用 AppCmd.exe 来配置 IIS 一对一证书映射。

C# using System; using System.Text; using Microsoft.Web.Administration; internal static class Sample { private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection iisClientCertificateMappingAuthenticationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site"); iisClientCertificateMappingAuthenticationSection["enabled"] = true; iisClientCertificateMappingAuthenticationSection["oneToOneCertificateMappingsEnabled"] = true; ConfigurationElementCollection oneToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("oneToOneMappings"); ConfigurationElement addElement = oneToOneMappingsCollection.CreateElement("add"); addElement["enabled"] = true; addElement["userName"] = @"Username"; addElement["password"] = @"Password"; addElement["certificate"] = @"Base-64-Encoded-Certificate-Data"; oneToOneMappingsCollection.Add(addElement); ConfigurationSection accessSection = config.GetSection("system.webServer/security/access", "Default Web Site"); accessSection["sslFlags"] = @"Ssl, SslNegotiateCert"; serverManager.CommitChanges(); } } } VB.NET Imports System Imports System.Text Imports Microsoft.Web.Administration Module Sample Sub Main() Dim serverManager As ServerManager = New ServerManager Dim config As Configuration = serverManager.GetApplicationHostConfiguration Dim iisClientCertificateMappingAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site") iisClientCertificateMappingAuthenticationSection("enabled") = True iisClientCertificateMappingAuthenticationSection("oneToOneCertificateMappingsEnabled") = True Dim oneToOneMappingsCollection As ConfigurationElementCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("oneToOneMappings") Dim addElement As ConfigurationElement = oneToOneMappingsCollection.CreateElement("add") addElement("enabled") = True addElement("userName") = "Username" addElement("password") = "Password" addElement("certificate") = "Base-64-Encoded-Certificate-Data" oneToOneMappingsCollection.Add(addElement) Dim accessSection As ConfigurationSection = config.GetSection("system.webServer/security/access", "Default Web Site") accessSection("sslFlags") = "Ssl, SslNegotiateCert" serverManager.CommitChanges() End Sub End Module JavaScript var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager'); adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"; var iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site"); iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = true; iisClientCertificateMappingAuthenticationSection.Properties.Item("oneToOneCertificateMappingsEnabled").Value = true; var oneToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("oneToOneMappings").Collection; var addElement = oneToOneMappingsCollection.CreateNewElement("add"); addElement.Properties.Item("enabled").Value = true; addElement.Properties.Item("userName").Value = "Username"; addElement.Properties.Item("password").Value = "Password"; addElement.Properties.Item("certificate").Value = "Base-64-Encoded-Certificate-Data"; oneToOneMappingsCollection.AddElement(addElement); var accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site"); accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert"; adminManager.CommitChanges(); VBScript Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager") adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" Set iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site") iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = True iisClientCertificateMappingAuthenticationSection.Properties.Item("oneToOneCertificateMappingsEnabled").Value = True Set oneToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("oneToOneMappings").Collection Set addElement = oneToOneMappingsCollection.CreateNewElement("add") addElement.Properties.Item("enabled").Value = True addElement.Properties.Item("userName").Value = "Username" addElement.Properties.Item("password").Value = "Password" addElement.Properties.Item("certificate").Value = "Base-64-Encoded-Certificate-Data" oneToOneMappingsCollection.AddElement(addElement) Set accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site") accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert" adminManager.CommitChanges()


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3