【问题标题】:wcf UserNamePasswordValidator class and client certificatewcf UserNamePasswordValidator 类和客户端证书
【发布时间】:2014-03-09 07:27:37
【问题描述】:

我在 wcf 中使用了自定义 UserNamePassword Validator 来实现安全性。为此,我创建了自签名证书。尝试使用 Web 服务时出现以下错误“无法为 SSL/TLS 安全通道建立信任关系权威”。在谷歌搜索了一段时间后,我发现证书需要安装在客户端中。所以我的问题是

1) Is it always required to install certificate on the client even if we used trusted third party?
2) Is it possible to implement UserNamePassword without any certificate?

【问题讨论】:

    标签: c# wcf ssl


    【解决方案1】:

    问题 1

    不,这不是必需的。

    在服务器端你应该添加这样的行为

    <behavior name="SecureBehavior">
      <serviceMetadata httpGetEnabled="true" />  
      <serviceCredentials>
        <!-- 
        The serviceCredentials behavior allows one to specify a custom validator for username/password combinations.                  
        -->
        <userNameAuthentication userNamePasswordValidationMode="Custom"
                                customUserNamePasswordValidatorType="[Your.Custom.WCFUserValidator], [AssemblyName]"/>
        <!-- 
        The serviceCredentials behavior allows one to define a service certificate.
        A service certificate is used by a client to authenticate the service and provide message protection.
        This configuration references the "localhost" certificate installed during the setup instructions.
        -->
        <serviceCertificate findValue="[certificateName]" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
      </serviceCredentials>
    </behavior>
    

    然后将行为添加到服务器端点

    <service name="[serviceName]" behaviorConfiguration="SecureBehavior">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsSecureConfig"
                      contract="[ContractName]" />
            <endpoint address="/MEX" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
    

    在客户端,您可以在配置文件中设置服务证书的公共部分,如下所示:

    <endpoint address="http://..."
            binding="wsHttpBinding"
            contract="..."
            name="serviceName">
          <identity>
            <certificate encodedValue="[Encoded Value]" />
          </identity>
        </endpoint>
    

    获取客户端配置的简单方法是通过 Visual Studio(添加服务引用上下文菜单)在客户端项目中添加对服务的服务引用。这将添加一个配置文件,其中包含可供使用的客户端。

    问题 2

    如果您使用自定义身份验证,则客户端凭据类型必须设置为 UserName。这使用户名和密码能够提交给服务以执行身份验证。是的,您必须使用证书。

    【讨论】:

    • 上面的配置是在webservice中对吧?我的意思是如何添加endcoded值
    • 我尝试过,但没有得到编码值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    • 2013-10-07
    • 1970-01-01
    • 2013-07-14
    相关资源
    最近更新 更多