代码之家  ›  专栏  ›  技术社区  ›  Rajat Nigam

预期签名算法不匹配

  •  0
  • Rajat Nigam  · 技术社区  · 9 年前

    我正在尝试实现SSO。在SP的元数据中,我已将签名和加密算法设置为sha256

        <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <ds:SignedInfo>
                <ds:CanonicalizationMethod Algorithm="" />
                <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
                <ds:Reference URI="">
                    <ds:Transforms>
                        <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                        <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                    </ds:Transforms>
                    <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                    <ds:DigestValue />
                </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue />
        </ds:Signature>
    

    在我的身份验证请求中,我还将请求发送为:

     Signature signature = (Signature) Configuration.getBuilderFactory()
            .getBuilder(Signature.DEFAULT_ELEMENT_NAME)
            .buildObject(Signature.DEFAULT_ELEMENT_NAME);
        signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
        authnRequest.setSignature(signature);
        ((SAMLObjectContentReference)signature.getContentReferences().get(0)).setDigestAlgorithm(EncryptionConstants.ALGO_ID_DIGEST_SHA256);  
    

    在依赖方的“高级”选项卡下的IDP端,我交叉检查SHA-256设置为哈希算法,但现在当我发送身份验证请求时,我得到的错误是:

      `SAML request is not signed with expected signature algorithm. SAML request is signed with signature algorithm` http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 . Expected signature algorithm is http://www.w3.org/2000/09/xmldsig#rsa-sha1 
    

    如果我遗漏了什么,请帮助我解决这个问题。

    1 回复  |  直到 9 年前
        1
  •  0
  •   Rajat Nigam    9 年前

    这对我有用!

    在向IDP发送身份验证请求时,我必须设置这两行。

    BasicSecurityConfiguration config = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration();
    config.registerSignatureAlgorithmURI("RSA", SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
    

    这将全局设置算法,当您有多个具有不同签名算法的客户端时将不起作用