设置 IIS 以要求客户端证书并使用匿名身份验证
我有一个 WCF Web 服务供我们的客户使用。我想使用客户端证书来保护它。我还将使用客户端证书来识别客户。
我已经使标识部分工作,但我不能使 IIS 需要客户端证书。
如果我将 IIS 设置为接受客户端证书,则通信正常,我可以使用以下方法获取客户端身份:
ServiceSecurityContext.Current.PrimaryIdentity.Name
Run Code Online (Sandbox Code Playgroud)
但是我也可以在没有客户端证书的情况下访问该站点。我不确定那些没有阅读 WSDL 的人是否可以做任何其他事情,但我不希望任何没有受信任证书的人能够获得任何信息。
如果我将 IIS 设置为需要客户端证书,我应该有权访问的测试客户端会收到错误消息:
客户端身份验证方案“匿名”禁止 HTTP 请求。
我只想允许那些拥有服务器信任的客户端证书的人访问。其他任何人都将被拒绝。
服务器 WCF 配置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="ChainTrust" />
</clientCertificate>
<serviceCertificate findValue="64343ee2c8338518e78ba698f3936dc92c90db57" x509FindType="FindByThumbprint" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="DefaultBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate" />
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WebService.Service" behaviorConfiguration="DefaultBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" contract="WebService.IService" />
<endpoint …
Run Code Online (Sandbox Code Playgroud)