所以我一直在尝试为我的客户和服务设置证书身份验证。最终目标是根据客户端连接的证书对数据进行分区(即证书成为他们进入更大系统的凭据,并且他们的数据基于这些凭据进行分区)。
我已经能够在客户端和服务器端成功设置它。我已经创建了一个证书和一个私钥,将它们安装在我的计算机上,并设置了我的服务器,以便 1)它具有基于证书的服务凭据和 2)如果客户端在没有提供基于证书的凭据的情况下进行连接,则异常是抛出。
然后我所做的是创建一个简单的客户端并将证书凭据添加到配置中,并尝试在服务上调用一个简单的操作。
看起来客户端连接正常,并且看起来证书已被服务器接受,但我确实得到了这个:
安全协商异常:
“调用者未经服务验证。”
这对我来说似乎很模棱两可。请注意,我正在使用 wsHttpBinding,据推测它默认为 Windows auth 以确保传输安全......但是所有这些进程都作为我的用户帐户运行,因为我在调试环境中运行。
这是我的服务器配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding">
<security mode="Message">
<transport clientCredentialType="None"/>
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint binding="wsHttpBinding" bindingConfiguration="MyServiceBinding" contract="IMyContract"/>
<endpoint binding="mexHttpBinding" address="mex" contract="IMetadataExchange">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<serviceCertificate storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" findValue="tmp123"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
这是我的客户端配置——请注意,我使用的客户端证书与我在服务上使用的证书相同:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Message">
<!--<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>-->
<message clientCredentialType="Certificate" negotiateServiceCredential="true" algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50120/UserServices.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService" behaviorConfiguration="IMyService_Behavior" contract="UserServices.IUserServices" name="WSHttpBinding_IMyService">
<identity>
<certificate encodedValue="Some RSA stuff"/>
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="IMyService_Behavior">
<clientCredentials>
<clientCertificate storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" findValue="tmp123"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
任何人都可以帮助提供一些关于这里可能发生的事情的见解吗?
谢谢,