【问题标题】:WebAPI Certificates and Authentication - ELI5WebAPI 证书和身份验证 - ELI5
【发布时间】:2015-07-23 12:16:58
【问题描述】:

我确定我遗漏了一些关键事实,但我可以为您找到这些。我真的很困惑这一切需要如何运作:

  • 服务器 1 – IIS 8,托管供应商的 WebAPI、匿名和 Windows 身份验证。提供者是 Negotiate、NTLM。 HTTPS 和签名证书 (Cert1)。
  • 服务器 2 – IIS8,连接到服务器 1 的 WebAPI 的新 WebAPI。我假设我需要将 Cert1 存储在服务器 2 上。我们将有另一个证书 https (Cert2)
  • 服务器 3 – IIS 8,网站连接到服务器 2 的 webAPI。
  • 用户 - 连接到服务器 3 的浏览器,仅 Windows 身份验证。 每台服务器和用户的浏览器都连接到同一个 Active Directory。

我可以访问 Server1 的 web.config 来更改绑定,但不能更改代码。在 Visual Studio 2013 中,当我为 Server 2 添加服务引用时,web.config 是这样添加的:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ICoreWebService">
      <security mode="Transport">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Certificate" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="https://dave.domain.com/webService/CoreWebService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICoreWebService" contract="Dave.ICoreWebService" name="WSHttpBinding_ICoreWebService">
    <identity>
      <userPrincipalName value="Server1ServiceAccount@dave.domain.com" />
    </identity>
  </endpoint>
</client>

这是 Server1 的 WebAPI web.config

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <!-- The following block is used for secure connection (HTTPS)-->
    <binding name="DaveServiceBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:05:00" sendTimeout="00:05:00">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" />
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service name="Dave.WebService.CoreWebService" behaviorConfiguration="DaveWebServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="DaveWebServiceBinding" contract="Dave.WebService.ICoreWebService" />
    <endpoint address="wauth" binding="wsHttpBinding" bindingConfiguration="DaveWebServiceBindingWauth" contract="Dave.WebService.ICoreWebService" />
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="DaveWebServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Dave.WebService.WebServiceAuthValidator,Dave.WebService" />
      </serviceCredentials>
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

  1. 我在服务器 1 和服务器 2 之间的证书如何工作时遇到问题。我只需要下载 Cert1 并将其存储在 Server2 上?然后在我拨打电话时参考该证书。此代码未找到证书:

    svc.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine,
                StoreName.TrustedPublisher,
                X509FindType.FindBySubjectName, "CN = dave.domain.com, OU = ZZ123, O = Dave, Inc., L = Chicago, S = Illinois, C = US");
    
  2. 如何将 Windows 身份验证从用户冒泡到 server1?供应商的 API 将通过该消息进行身份验证。

现在,我可以在本地浏览到服务,但我一直卡在服务器 2 上并获取证书。我想确保我正确地存储和引用它。

提前致谢。

【问题讨论】:

    标签: c# asp.net-mvc rest iis asp.net-web-api


    【解决方案1】:

    主题名称必须是域,我使用 MMC 确保证书在它应该在的位置。

    MMC -> 证书(您可能需要在管理单元中添加它们)

    受信任的人 -> 证书。

    希望对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2012-09-12
      • 2014-04-05
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      相关资源
      最近更新 更多