一些背景资料:  为了提供我使用的客户端和服务器端(WCF)证书的认证,并使用一个证书的所有客户端(手动从应用程序目录加载它 - 而不是最安全的方式,但它并不需要管理证书存储和制作安装更加困难):

        AddressHeader hostHdr = AddressHeader.CreateAddressHeader(ServiceFactory.CLIENT_HOST_HEADER, ServiceFactory.NAMESPACE, hostName);
        builder.Headers.Add(hostHdr);
        builder.Identity = new X509CertificateEndpointIdentity(GetServiceCertificate(name));


        _factory = new ChannelFactory<T>(name, builder.ToEndpointAddress());
        _factory.Credentials.ClientCertificate.Certificate = GetClientCertificate(name);
        X509ServiceCertificateAuthentication auth = _factory.Credentials.ServiceCertificate.Authentication;

        auth.CertificateValidationMode =X509CertificateValidationMode.Custom;
        auth.CustomCertificateValidator = new CustomCertificateValidator(new[] {GetServiceCertificate(name)});

这是客户端,服务器端和主机设置如下所示:

private void CertificateSetup(ServiceHost host)
    {
        if (ServiceCertificate != null)
            host.Credentials.ServiceCertificate.Certificate = ServiceCertificate;

        X509ClientCertificateAuthentication authentication =
                        host.Credentials.ClientCertificate.Authentication;

        authentication.CertificateValidationMode =
            X509CertificateValidationMode.Custom;

        authentication.CustomCertificateValidator =
            new CustomCertificateValidator(new [] {ClientCertificate});
    }

这工作正常,并允许签署的消息,但只要在以下的方式设置安全模式:

      <security mode="Message">            
        <message clientCredentialType="Certificate" />
      </security>

但我需要

string name = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;

以某种方式获得的WindowsIdentity在ServiceSecurityContext。  混合(运输和消息)安全模式是没有帮助的,因为我不知道为什么,但即使我在配置运输部分模式的基础设施将Windows clientCredentials尝试建立SSL连接。

任何想法????


证书用于消息签名,即。证明对方是无论是实际的客户端或服务(人在这方面的中间人)。但在系统授权开发部分在ServiceSecurityContect依靠的WindowsIdentity。所有我想要的,包括在的WindowsIdentity sec.context,同时PrimaryIdentity是X509CertIdentity。 所以,我需要知道哪个域用户请求的服务操作服务器端。

有帮助吗?

解决方案

尝试此链接重新:模拟:

http://msdn.microsoft.com/en-us/library /ms730088.aspx

这是一节 - “映射客户端证书到Windows帐户”,好像你以后

与客户端配置:

authentication mapClientCertificateToWindowsAccount="true" 

客户端的代码:

”创建的结合,其设定证书作为客户端的凭证类型。

Dim b As WSHttpBinding = New WSHttpBinding()

b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate

”创建证书映射到一个Windows帐户的服务的主机。

Dim httpUri As Uri = New Uri("http://localhost/Calculator")

Dim sh As ServiceHost = New ServiceHost(GetType(HelloService), httpUri)

sh.Credentials.ClientCertificate.Authentication.MapClientCertificateToWindowsAccount = True

希望帮助

其他提示

如果您正在使用的邮件安全每端证书保护它,我不明白为什么你会需要一个Windows身份?什么是背后的原因何在呢?

也许这链路将使用的 - 第6及7对证书authentiaction,其工作方式类似于SSL的配置设置的细节:

http://www.codeproject.com/KB/WCF/wcf_certificates.aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top