2

我有自己的使用日内瓦框架的 STS。有一个带有 MutualCertificateBinding 的端点,如下

  • 使用 AsymmetricSecurityBindingElement
  • 保护级别是标志
  • 通过 https

我已经复制了它的一部分 wsdl 如下以供参考

<sp:AsymmetricBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
    <wsp:Policy>
        <sp:InitiatorToken>
            <wsp:Policy>
                <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                    <wsp:Policy>
                        <sp:WssX509V3Token10/>
                    </wsp:Policy>
                </sp:X509Token>
            </wsp:Policy>
        </sp:InitiatorToken>
        <sp:RecipientToken>
            <wsp:Policy>
                <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
                    <wsp:Policy>
                        <sp:WssX509V3Token10/>
                    </wsp:Policy>
                </sp:X509Token>
            </wsp:Policy>
        </sp:RecipientToken>
        ...
</sp:AsymmetricBinding>

我已经制作了一个 C# 客户端应用程序,它使用非对称密钥从 mySTS 协商安全令牌,UseKey 是一个 X509Certificate。它工作得很好。

我还直接对 mySTS 进行了 Java serlet 调用以发出令牌,它使用 PublicKey 类型,UseKey 手动设置为 RST 作为 X509 证书。它也可以正常工作,带有以下代码片段

SecurityTokenService sts = new SecurityTokenService(new URL(Constant.StsMexEndpointAddress));
IWSTrust13Sync stsService = sts.getMutualCertificateWithMessageSecurityBindingIWSTrust13Sync();
RequestSecurityTokenType rst = new RequestSecurityTokenType();
rst.getAny().add(getRequestTypeElement());
rst.getAny().add(getTokenTypeElement());
rst.getAny().add(getKeyTypeElement());
rst.getAny().add(getApplyToElement());
rst.getAny().add(getUseKeyElement());
return message;
token = stsService.trust13Issue(rst);

public static Element getUseKeyElement(){
//code to generate UseKey element manually, it is a BinarySecurityToken
}

我们的客户端使用另一个 Java servlet 调用由 mySTS 保护的 java 服务。Metro 会自动处理 STS 调用,下面是 java 服务的配置方式(使用 STS Issued Endorsing Token)

  • 代币类型:2.0
  • 密钥类型:公共
  • 密钥大小:256

下面是调用java服务的代码片段

STSIssuedTokenConfiguration config = new MySTSIssuesTokenConfiguration();
STSIssuedTokenFeature feature = new STSIssuedTokenFeature(config);

//Initialize UserContext service with STS configuration above
Service_Service service = new Service_Service();
Service stub = service.getServicePort(new WebServiceFeature[]{feature});
stub.ping();

STS 在尝试解析 UseKey 元素时抛出异常。它看起来像下面

Handling an exception. Exception details: System.IdentityModel.Protocols.WSTrust.InvalidRequestException: ID3092: The specified UseKey 'SecurityKeyIdentifier
    (
    IsReadOnly = False,
    Count = 1,
    Clause[0] = RsaKeyIdentifierClause(Modulus = sH/OHZwDUBExFgbLTslliY4xH3jP63vQ1F3yKxwjcK3jfYeiM3IC6ag6RARLMdX3emhjMu2djCt+/eTB9nq2yMs51kesev23yfywjIkcpZI5c1yb3wL7I+Fh+aa+bDqo0VNjoCeHlevjTVxc82l+q5iPkTZJ7rfe+jZUfZNl+D8=, Exponent = AQAB)
    )
' cannot be resolved to a token that would prove the client's possession of the private key.
   at System.IdentityModel.Protocols.WSTrust.WSTrustSerializationHelper.ReadRSTXml(XmlReader reader, RequestSecurityToken rst, WSTrustSerializationContext context, WSTrustConstantsAdapter trustConstants)
   at System.IdentityModel.Protocols.WSTrust.WSTrust13RequestSerializer.ReadXmlElement(XmlReader reader, RequestSecurityToken rst, WSTrustSerializationContext context)
   at System....

我试图比较从 2 个 Java servlet 发送的 2 条消息。一个是由我的 servlet 以编程方式发送的,另一个是由我的客户的 servlet 发送的 Metro 生成的,我能看到的唯一不同是关于 UseKey 元素我的一个运行良好

<UseKey>
  <BinarySecurityToken:BinarySecurityToken
    xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:BinarySecurityToken="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:d5p1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">MIIDCTCCAfGgAw.....25C057w==
  </BinarySecurityToken:BinarySecurityToken>
</UseKey>

我的一个客户不起作用(由 Metro 框架生成)

<trust:UseKey>
   <ns10:KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
       <KeyValue>
           <RSAKeyValue>
               <Modulus>sH/OHZwDUBExFgbLTsll...rfe+jZUfZNl+D8=</Modulus>
                  <Exponent>AQAB</Exponent>
            </RSAKeyValue>
        </KeyValue>
   </ns10:KeyInfo>
 </trust:UseKey>

AFAI 可以看到,失败是因为 STS 无法解析 RSA KeyValue 的 UseKey 元素,而它的 UseKeyResolver 只有一个由请求的 InitiatorToken 发起的 X509SecurityTokenResolver。

所以我的问题是

  1. 调用 java 服务时是否可以通过编程方式设置 UseKey?
  2. 有没有让 STS 解析 UseKey 元素?
4

0 回答 0