6

如何从使用 C# 的应用程序中使用 netsh 设置 clientcertnegotiation=enable 的等效项(无需执行命令行)。

netsh http add sslcert ipport=0.0.0.0:8000 certhash=2064a43f429fe97746ce0c1c9adcd4ea93415f6d appid={4dc3e181-e14b-4a21-b022-59fc669b0914} clientcertnegotiation=enable

以下代码成功添加了证书

using (var manager = new ServerManager())
        {
            var siteBindings = from s1 in manager.Sites
                               from b1 in s1.Bindings
                               where b1.Protocol.Equals("https")
                               select new {SiteName = s1.Name, Binding = b1};

            foreach (var siteBinding in siteBindings)
            {
                siteBinding.Binding.CertificateHash = cert.GetCertHash();
            }

            // This is correctly setting the values on the Ssl Cert configuration section in IIS
            var config = manager.GetApplicationHostConfiguration();
            var accessSection = config.GetSection("system.webServer/security/access", "WebActivationService");
            accessSection["sslFlags"] = @"Ssl, SslRequireCert";

            manager.CommitChanges();
        }

但运行 netsh http show sslcert 会显示它取消了协商客户端证书

IP:port                 : 0.0.0.0:8000
Certificate Hash        : 2064a43f429fe97746ce0c1c9adcd4ea93415f6d
Application ID          : {4dc3e181-e14b-4a21-b022-59fc669b0914}
Certificate Store Name  : MY
Verify Client Certificate Revocation    : Enabled
Verify Revocation Using Cached Client Certificate Only    : Disabled
Usage Check    : Enabled
Revocation Freshness Time : 0
URL Retrieval Timeout   : 0
Ctl Identifier          : (null)
Ctl Store Name          : (null)
DS Mapper Usage    : Disabled
Negotiate Client Certificate    : Disabled

删除和重新创建绑定具有相同的效果

4

3 回答 3

2

从 windows server 2003 + 可以使用以下内容:

ULONG HttpSetServiceConfiguration(
  __in  HANDLE ServiceHandle,
  __in  HTTP_SERVICE_CONFIG_ID ConfigId,
  __in  PVOID pConfigInformation,
  __in  ULONG ConfigInformationLength,
  __in  LPOVERLAPPED pOverlapped
);

http://msdn.microsoft.com/en-us/library/windows/desktop/aa364503(v=vs.85).aspx

于 2012-02-16T16:14:45.417 回答
0

对我来说,似乎缺少一些基本设置...有关如何通过一些解释执行此操作的代码示例,请参见http://www.iis.net/ConfigReference/system.webServer/security/authentication/iisClientCertificateMappingAuthentication#006

于 2011-08-10T13:11:27.157 回答
0

您希望使用https://www.iis.net/ConfigReference/system.applicationHost/sites/site/ftpServer/security/sslClientCertificates中描述的示例启用客户端证书检查。

您需要将 clientCertificatePolicy 设置为 CertRequire 以使非客户端身份验证连接失败。根据您是否要将证书映射到实际的 Windows 用户,您需要将 useActiveDirectoryMapping 设置为正确的值。

于 2011-08-10T16:04:08.553 回答