【发布时间】:2011-02-16 19:07:27
【问题描述】:
我正在尝试创建一个 WCF 服务,该服务将使用带有证书的消息模式安全性。当我在 IIS 和 cassini 中运行服务代码时,我收到以下消息
很可能是证书 'CN=TempCA' 可能没有私钥 能够进行密钥交换或 进程可能没有访问权限 私钥
我使用以下命令创建了证书
makecert -n "CN=TempCA" -r -sv TempCA.pvk TempCA.cer -sky Exchange -pe
makecert -sk SignedByCA -iv TempCA.pvk -n "CN=SignedByCA" -ic TempCA.cer SignedByCA.cer -sr localmachine -ss My
TempCA.cer 已导入“Trusted Root Certification Authorities\Certificates”,SignedByCA.cer 已导入“Personal\Certificates”
然后我运行了以下命令
pvk2pfx.exe -pvk TempCA.pvk -spc TempCA.cer
并将 TempCA.pfx 导入“Personal\Certificates”
服务配置文件如下(取自 MSDN 教程并为我的项目修改)
<system.serviceModel>
<services>
<service name="Service.Service1" behaviorConfiguration="wsHttpEnpointBinding">
<endpoint address="http://localhost:5372/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding" name="wsHttpEndpoint"
contract="Service.Contracts.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wsHttpEnpointBinding">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
<serviceCredentials>
<!-- Certificate storage path on the server -->
<serviceCertificate findValue="TempCA" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />
<issuedTokenAuthentication allowUntrustedRsaIssuers="true" />
<!-- Certificate storage path in the client -->
<clientCertificate>
<certificate findValue="TempCA" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="wsHttpEnpointBinding">
<clientCredentials>
<clientCertificate findValue="TempCA" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
<serviceCertificate>
<authentication certificateValidationMode="None" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="Message">
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
我花了相当多的时间试图解决这个问题,但我没有取得任何实际进展......
【问题讨论】:
标签: .net wcf x509certificate