C# WCF基于证书的身份验证问题。正在使用无效证书对服务进行身份验证
我是WCF服务的初学者。试图在WCF服务上实现基于证书的身份验证,但遇到了一个问题。服务需要来自调用客户端的特定证书。如果客户端未传递任何证书,服务器将抛出身份验证错误。但同时,服务调用正在使用客户端提供的任何证书传递身份验证(如果客户端提供特定证书,则服务假定进行身份验证) 以下是服务器配置的代码段: 服务配置:C# WCF基于证书的身份验证问题。正在使用无效证书对服务进行身份验证,c#,web-services,wcf,authentication,soap,C#,Web Services,Wcf,Authentication,Soap,我是WCF服务的初学者。试图在WCF服务上实现基于证书的身份验证,但遇到了一个问题。服务需要来自调用客户端的特定证书。如果客户端未传递任何证书,服务器将抛出身份验证错误。但同时,服务调用正在使用客户端提供的任何证书传递身份验证(如果客户端提供特定证书,则服务假定进行身份验证) 以下是服务器配置的代码段: 服务配置: <bindings> <wsHttpBinding> <binding name="MyWsHttpBinding&q
<bindings>
<wsHttpBinding>
<binding name="MyWsHttpBinding" maxReceivedMessageSize="2147483647" receiveTimeout="00:30:00">
<readerQuotas maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxArrayLength="2147483647"/>
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"/>
<message clientCredentialType="Certificate" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="ChainTrust" />
</clientCertificate>
<serviceCertificate findValue="e616ebcd940951794736624acc6484802018c8d4" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" />
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<CustomBehaviorExtensionElement/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehavior">
<MySchemaValidator validateRequest="True" validateReply="False">
<schemas>
<add location="App_Data\model-service.xsd"/>
</schemas>
</MySchemaValidator>
</behavior>
</endpointBehaviors>
<services>
<service name="MyService" behaviorConfiguration="MyServiceBehavior">
<endpoint binding="wsHttpBinding" bindingConfiguration="MyWsHttpBinding" contract="MyExchangeService" behaviorConfiguration="MyEndpointBehavior" bindingNamespace="http://www.mycompany.com/exchange/"/>
<endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex" name="mex"/>
</service>
</services>
问题的原因是您使用的安全模式是传输,因此只有以下代码有效:
<transport clientCredentialType="None" proxyCredentialType="None"/>
以下消息设置无效:
<message clientCredentialType="Certificate" algorithmSuite="Default"/>
将transport中的值更改为certificate,您也可以在官网上下载,有相关证书验证的示例,还有。我看到您代码中使用的证书验证模式是
ChainTrust
,使用信任手段-
如果链生成到受信任根存储中的证书颁发机构,则证书有效
这意味着,客户端不需要发送与您的服务web.config中提到的指纹完全相同的证书
事实上,其根/中间证书颁发机构存在于VM的受信任根存储中的任何证书都将通过验证
要确保客户端只能使用特定证书对您的服务进行身份验证,请将ChainTrust
更改为PeerTrust
,并将证书添加到VM证书存储(certmgr)上的受信任人员存储
如果你觉得这有用,请投票!谢谢:)将配置更改为:
。IIS在修改后引发以下错误:服务“SslRequireCert”的SSL设置与IIS“None”的设置不匹配。您可以参考: