我试图让托管在IIS将使用X.509证书,邮件安全和与需要相互验证SSL运输安全WCF4服务(项目规范要求使用WS-Security 和 SSL,AFAIK只有一个通常是要走的路,但没关系)。WCF 4 - TransportWithMessageCredential使用X.509证书运输和信息安全
我做了我TestRootCA并用它来颁发服务器证书(本地主机)和客户端证书(TestUser用户)。我首先只想建立和测试传输安全性,所以我配置IIS使用https,配置的SSL证书(我制作的localhost证书),并将IIS配置为,要求客户端提供客户端证书。然后我修改了服务web.config,创建了相应的svcutil.conf,并运行了svcutil,成功为我的测试WinForms应用程序创建了客户端代理类和app.config。
var client = new ServiceClient();
client.ClientCredentials.ClientCertificate.SetCertificate(System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectDistinguishedName, "CN=TestUser");
MessageBox.Show(client.GetData(42));
到目前为止好:我通过调用创建代理客户端时设置的证书。但是,当我修改服务的web.config以使用TrasportWithMessageCredential(而不是传输)并指定“Certificate”作为clientCredentialType以获得邮件安全性时,我获得HTTP 403 - The HTTP request was forbidden with client authentication scheme 'Anonymous'
,即使我指定了“Certificate”。
我最后的web.config文件看起来是这样的:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate"/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="serviceBehavior" name="Service">
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" name="wsHttpEndpoint" contract="IService" />
<endpoint address="mex" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" name="mexEndpoint" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
和我的客户app.conf:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate"/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/WCFTestService/Service.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpoint" contract="IService" name="wsHttpEndpoint" />
</client>
</system.serviceModel>
任何想法?
编辑:
我已经成功地得到它通过更改IIS设置SSL客户端证书的工作从需要到接受。看来,当我介绍了使用SSL使用过的运输安全证书信息安全,客户端使用通过SSL相互认证的证书,邮件签名,但不(它试图身份登录,即使它有指定的证书匿名 )。
不知道为什么发生这种情况,我想从专家:)一些评论。
还没有尝试过这一点,但即使它能够工作,在* server * config中指定* client *证书的需求也是一个交易断路器。服务器事先并不知道客户端证书(并且有许多不同的客户端),它使用链式信任(如果客户端证书的有效性是有效的,那么客户端证书被接受并用作标识)。 –
这解决了我得到的错误“HTTP请求被客户端身份验证方案'Anonymous'禁止”。我只有指定的服务器证书。谢谢 – Nanook