我已经构建了一个WCF helloworld客户端和服务器。我想在它们之间使用证书身份验证。
我得到的错误是“调用者未经过服务验证。”
我使用makecert.exe创建了两个证书。客户端上的证书安装在“个人”和“受信任的人”和“第三方根证书颁发机构”下。我复制了证书,因为我不知道它是否应该只在一个标题下
我的服务器webconfig如下
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5.1"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="BusinessToBusiness" name="TestHelloWork.Service1">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="BindingConfig" contract="TestHelloWork.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://win-gat-web01:7777/Service1"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="BindingConfig">
<security>
<message clientCredentialType = "Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="BusinessToBusiness">
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode = "PeerTrust"/>
</clientCertificate>
<serviceCertificate findValue="WCfServer"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
</configuration>
客户端web.config如下所示
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1">
<security>
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://myserver:7777/Service.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1" behaviorConfiguration="CustomBehavior">
<identity>
<dns value="WCfServer" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="CustomBehavior">
<clientCredentials>
<clientCertificate findValue="WcfClient" x509FindType="FindBySubjectName"
storeLocation="CurrentUser" storeName="My" />
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端证书安装在“个人”
下知道可能出现什么问题吗?我用谷歌搜索并意识到他们应该在同一个域上?但他们是。当我的服务是外部服务时,域名将如何运作?
答案 0 :(得分:2)
尝试启用CAPI2日志。它是包含证书验证信息的特殊日志(默认情况下未启用)。如果您的问题在于证书验证程序失败,那么您将在那里找到有用的信息。寻找错误。就我而言,它就像是
就我而言,我已经
了但您正在使用PeerTrust
证书验证模式,因此根据WCF演示中的此评论,我有
将certificateValidationMode设置为PeerOrChainTrust意味着如果证书位于用户的受信任人存储中,则无需验证证书的颁发者链即可信任该证书。为方便起见,此处使用此设置,以便无需拥有证书颁发机构(CA)颁发的证书即可运行示例。
我认为证书应该像这样放置:
验证您是否已授予运行IIS WCF服务的AppPool的服务器私钥的权限(默认池为IIS APPPOOL\DefaultAppPool
)
可以使用mmc
或certlm.msc
通过正确克隆服务器证书然后All Tasks
- &gt;来完成Manage Private Keys ...
。验证您没有选择的AD,因为IIS APPPOOL是本地组。添加帐户IIS APPPOOL\your_pool_name
并点击“确定”。
如果您的AppPool中有默认设置,Identity
设置为AplicationPoolIdentity
,而不是自定义帐户(通常使用来自AD的托管服务帐户)和{{1} }设置为Load User Profile
。
答案 1 :(得分:0)
您遇到的WCF证书身份验证问题很可能与使用MakeCert生成自签名证书时使用的选项有关。
特别要确保您的证书支持必要的选项/目的。 (例如,证书的预期目的字段应包含适当的值,例如“服务器身份验证”或“客户端身份验证”。)
Microsoft的以下链接详细说明了该过程 https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-temporary-certificates-for-use-during-development
注意:我们的团队很幸运使用SelfCert工具快速生成开发的自签名证书。