.net - 为什么在使用 WCF 服务时客户端应用程序需要证书的私钥?
问题描述
设想
X.509 证书:组织提供的证书用于服务器-客户端身份验证。该证书同时用于服务器和客户端身份验证。
WCF 服务: WCF 服务托管在 IIS 中并在开发服务器上运行。它由 X.509 pfx 证书(由组织提供,非自签名)保护。它在其配置中使用消息安全性。.Pfx
证书已通过 mmc 在本地计算机上的个人-> 证书和受信任的根证书颁发机构-> 证书中成功导入到开发服务器上
客户端:它使用与服务相同的绑定结构。该.cer
文件(在开发服务器上使用的相同证书)在我的本地导入到个人-> 证书和受信任的根证书颁发机构-> 证书中。
服务配置:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"
minFreeMemoryPercentageToActivateService="0" />
<services>
<service name="WCF_HOST.Service1" behaviorConfiguration="customBehaviour">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:57104/Service1" />
<!--<add baseAddress = "http://****:57104/Service1" />-->
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="customWsHttpBinding"
contract="WCF_HOST.IService1">
</endpoint>
<endpoint
address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="customWsHttpBinding">
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
<!--<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />-->
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="customBehaviour">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
<serviceCredentials>
<serviceCertificate findValue="tempCert"
storeLocation="LocalMachine" storeName="My"
x509FindType="FindBySubjectName" />
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust"
revocationMode="NoCheck" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="customWsHttpBinding">
<security mode="Message">
<message clientCredentialType="Certificate" negotiateServiceCredential="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
address="http://****:57104/Service1.svc"
binding="wsHttpBinding"
bindingConfiguration="customWsHttpBinding"
behaviorConfiguration="customBehavior"
contract="ServiceClient.IService1">
<identity>
<dns value="tempCert"/>
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="customBehavior">
<clientCredentials>
<serviceCertificate>
<defaultCertificate findValue="he f5 l9 f9 41 e1 f5 ea 20 ef 55 bc 99 4c ca 5b c4 c5 31 d9" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint"/>
<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
</serviceCertificate>
<clientCertificate
findValue="tempCert"
storeLocation="CurrentUser"
storeName="My" x509FindType="FindBySubjectName"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
证书说明
问题
当我尝试在
webmethod
调用时使用服务时,它会引发异常证书“CN=tempCert, OU=***19, O=****Inc., C=SG”必须有私钥。该进程必须具有私钥的访问权限
为什么客户端应用程序在这里需要一个私钥?
如果我向
.pfx
客户端应用程序提供相同的证书(在服务器上使用),它就可以工作。如何以及为什么?在这个问题上浪费了无数个小时,非常感谢任何帮助/建议。
解决方案
推荐阅读
- java - junit java错误消息的参数化测试构造函数:测试类应该有一个公共零参数构造函数
- aws-codebuild - CodeBuild 命令中的条件语句 - JSON
- r - 在 R 中创建 3D 曲线
- vb.net - WebView2 - VB.NET - 没有可用的 ZoomFactor
- c++ - 如何在 Windows 上分发 Gtkmm 应用程序?
- spring - 哪一个是好的微服务设计?
- reactjs - 如何检查我的应用程序是否在 x 时间段内向某个端点发送了请求?
- sql-server - 从 SQL Server 的给定字符串中提取最后一个整数数据的最佳选择
- javascript - 光滑的轮播显示两行而不是一行
- vue.js - 在 VS Code 中调试 Vue.js 已损坏