【问题标题】:App.Config for Federated Security with client certificate in Thinktecture IdentityServerApp.Config for Federated Security 与 Thinktecture IdentityServer 中的客户端证书
【发布时间】:2014-04-22 05:58:00
【问题描述】:

目前,我可以通过首先通过 WS-Trust 端点使用证书凭证从 STS 建立安全令牌,然后在通道工厂上调用 CreateChannelWithIssuedToken() 来建立带有 IssuedToken 的 WCF 通道。见How to specify a certificate as the credentials for a wsTrustChannel with Thinktecture IdentityServer

但是,不要这样做:

var securityToken = GetMeASecurityTokenFromTheSts();
var myServiceChannelFactory = new ChannelFactory<IMyService>();
myServiceChannelFactory.CreateChannelWithIssuedToken(securityToken);

理想情况下,我希望这样做(并让安全令牌的颁发者根据通过的证书自动颁发令牌)。

var myClient = new MyServiceClient();

我的问题是 - 可以像下面这样配置绑定来指定 ThinkTecture IdentityServer STS 是安全令牌的颁发者吗?

<bindings>
  <ws2007FederationHttpBinding>
    <binding name="WS2007FederationHttpBinding">
      <security mode="TransportWithMessageCredential">
        <message issuedKeyType="BearerKey" issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0">
          <issuer address="https://mymachine/myidserver/issue/wstrust/mixed/certificate">
            <identity>
              <certificateReference storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="XXXXXXXXXXXXXXXXXXXXXXXXX"/>
            </identity>
          </issuer>
          <issuerMetadata address="https://mymachine/myidserver/FederationMetadata/2007-06/FederationMetadata.xml" />
          <tokenRequestParameters>
            <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
              <trust:TokenType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</trust:TokenType>
              <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
              <trust:Claims Dialect="http://schemas.xmlsoap.org/ws/2005/05/identity"
                xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                <wsid:ClaimType Uri="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"
                  xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
              </trust:Claims>
              <trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm>
              <trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm>
            </trust:SecondaryParameters>
          </tokenRequestParameters>
        </message>
      </security>
    </binding>
  </ws2007FederationHttpBinding>
</bindings>

如果是这样 - 我在配置这部分绑定时遇到了很多麻烦:

<issuer address="https://mymachine/myidserver/issue/wstrust/mixed/certificate">
    <identity>
        <certificateReference storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="XXXXXXXXXXXXXXXXXXXXXXXXX"/>
    </identity>
</issuer>

我的主要困惑是:issuer config 元素似乎将绑定、行为和端点都封装在一个元素中。可以配置绑定 - 显然必须配置,因为上面的 issuer 元素抱怨没有配置绑定。但是如何为颁发者通道指定 SSL 证书,因为这是一个行为配置,并且似乎没有任何方法可以为颁发者端点设置行为。

【问题讨论】:

    标签: ws-federation thinktecture-ident-server ws-trust


    【解决方案1】:

    使用仅配置方法确实存在将令牌生命周期绑定到代理生命周期的问题。此外,您在 IdentityServer 中配置的领域 (appliesTo) 必须与 WCF 服务的物理 URL 匹配。两者都不实用,更推荐使用“手动”WSTrustChannelFactory 方法。

    也就是说,svcutil(或“添加服务引用”)会为您创建所有必要的客户端配置。您只需要确保在 WCF 服务配置中指向 IdentityServer 的 MEX 端点,例如:

    <bindings>
          <ws2007FederationHttpBinding>
            <binding>
              <security mode="TransportWithMessageCredential">
                <message establishSecurityContext="false"
                         issuedKeyType="BearerKey">
                  <issuerMetadata address="https://identity.thinktecture.com/idsrvsample/issue/wstrust/mex" />
                </message>
              </security>
            </binding>
          </ws2007FederationHttpBinding>
        </bindings>
    

    https://github.com/thinktecture/Thinktecture.IdentityServer.v2/blob/master/samples/MVC%20and%20WCF%20RP%20(SAML)/Web/Web.config

    ...顺便说一句,MEF 问题已修复。

    【讨论】:

    • 啊——非常感谢 Dominick——这是一个很好的答案,因为它证实了我对 ws2007FederationHttpBinding 与 STS 自动连接的一些缺点的怀疑。它还证实,在我的情况下,我必须使用“手动”WSTrustChannelFactory 方法,因为我正在验证一个没有物理 URL 的服务器进程。
    【解决方案2】:

    您可以为发行者设置绑定配置。证书的使用将在 MyServiceClient 行为中设置。我没有测试过这个配置,但它可以工作。

    这是你修改后的配置

    <bindings>
        <ws2007FederationHttpBinding>
            <binding name="WS2007FederationHttpBinding">
                <security mode="TransportWithMessageCredential">
                    <message issuedKeyType="BearerKey" issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0">
                        <issuer address="https://mymachine/myidserver/issue/wstrust/mixed/certificate" binding="ws2007HttpBinding" 
                      bindingConfiguration="issuerBindingConfig">
                        </issuer>
                        <issuerMetadata address="https://mymachine/myidserver/FederationMetadata/2007-06/FederationMetadata.xml" />
                        <tokenRequestParameters>
                            <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                                <trust:TokenType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</trust:TokenType>
                                <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
                                <trust:Claims Dialect="http://schemas.xmlsoap.org/ws/2005/05/identity"
                xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                                    <wsid:ClaimType Uri="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"
                  xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity" />
                                </trust:Claims>
                                <trust:CanonicalizationAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm>
                                <trust:EncryptionAlgorithm xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm>
                            </trust:SecondaryParameters>
                        </tokenRequestParameters>
                    </message>
                </security>
            </binding>
        </ws2007FederationHttpBinding>
    
        <ws2007HttpBinding>
            <!--SWACA RAWS Client authentication binding-->
            <binding name="issuerBindingConfig">
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" />
                    <message clientCredentialType="Certificate" establishSecurityContext="false" />
                </security>
            </binding>
        </ws2007HttpBinding>
    </bindings>
    
    
    <endpointBehaviors>
        <behavior name="MyServiceClient">
            <clientCredentials supportInteractive="false">
                <clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="XXXXXXXXXXXXXXXXXXXXXXXXX" />
            </clientCredentials>
        </behavior>
    </endpointBehaviors>
    

    但是请记住,如果您这样做,那么每个new MyServiceClient() 实际上都会从 STS 请求一个令牌。当我们在系统中使用这种方法时,我们遇到了一些关于 IdentityServer 的MEF threadsafety 问题。

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 2014-08-01
      • 2014-09-25
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 2015-04-17
      • 2012-05-01
      • 2014-09-05
      相关资源
      最近更新 更多