【问题标题】:WCF and SSL Mutual Authentication 403 - Forbidden: Access is deniedWCF 和 SSL 相互身份验证 403 - 禁止访问:访问被拒绝
【发布时间】:2011-04-06 20:31:02
【问题描述】:

我创建了一个 wcf 数据服务并通过 HTTP 公开它,需要 SSL。 我正在尝试设置服务和客户端都通过证书进行身份验证(相互身份验证)。 我正在使用开发人员证书。 因此,我将服务器的证书添加到客户端的受信任人员存储中。

但我仍然遇到异常:“403 - 禁止访问:访问被拒绝。”

1- 这是我的服务器配置:

 <system.serviceModel>
    <bindings>
        <webHttpBinding>
            <binding name="webHttpBindingConfig">
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <behaviors>

    </behaviors>
    <services>
        <service behaviorConfiguration="" name="PricingDataService">
            <endpoint address="https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc"
                binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig"
                name="webHttpEndpoint" contract="System.Data.Services.IRequestHandler" />
        </service>
    </services>

如何让服务器识别客户端的证书? (它也应该是开发者证书)。

2- 这是我的客户端配置:

  <system.serviceModel>
    <bindings>
        <webHttpBinding>
            <binding name="webHttpBindingConfig">
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="clientCredentialBehavior">
          <clientCredentials>
            <clientCertificate storeName="TrustedPeople" storeLocation="LocalMachine"
                                x509FindType="FindBySubjectName" findValue="tempClientcert" />
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
        <endpoint address="https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc"
            binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig"
            contract="System.Data.Services.IRequestHandler" name="" kind=""
            endpointConfiguration="" behaviorConfiguration="clientCredentialBehavior">
            <identity>
              <dns value="MyServiceSecure"/>
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

3- 这是我用来调用 wcf 代码的代码:

> MyServiceContext service = new MyServiceContext (
            new Uri("https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc"));

service.SendingRequest += this.OnSendingRequest_AddCertificate;


//
private void OnSendingRequest_AddCertificate(object sender, SendingRequestEventArgs args)
    {
        if (null != ClientCertificate)
            (args.Request as HttpWebRequest).ClientCertificates.Add(X509Certificate.CreateFromCertFile(@"C:\Localhost.cer"););
    }

我是否要在服务器上创建证书然后将其安装在客户端上?

【问题讨论】:

    标签: c# .net wcf ssl


    【解决方案1】:

    我认为您的证书可能有误,但首先要在 IIS 中验证网站“SSL 设置”下的“客户端证书”是否设置为“接受”或“要求”(以最适合您的为准)。

    我相信,出于您的目的,在 IIS 中为服务器创建自签名证书,然后将此证书导出到 .pfx 文件并将其安装到您受信任的根目录中应该可以工作。

    如果这对你没有帮助,我会看看这个问题:Using makecert for Development SSL

    【讨论】:

    • 好的,所以我在服务器上创建一个证书并将其导出到客户端计算机。如何让服务器识别并允许客户端访问它? (我的网站 SSL 设置设置为 Require)。
    • 我不完全确定您遇到了什么问题,但首先您需要为网站创建一个 HTTPS 绑定,请参阅learn.iis.net/page.aspx/144/how-to-set-up-ssl-on-iis-7 这能回答您的问题吗?
    • 我无法让服务器识别客户端的证书。
    • 我想进行相互身份验证,服务器通过要求客户端证书对客户端进行身份验证。到目前为止,服务器无法识别客户端的证书并拒绝其访问。
    • 在我看来,客户端证书在某种程度上与服务器证书没有关联,但我不知道在你的情况下如何解决这个问题。我确实找到了这篇文章,它可能对你有所帮助:viisual.net/configuration/IIS7-CTLs.htm
    猜你喜欢
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    相关资源
    最近更新 更多