使用xml签名时,整个xml文档都是混乱的

时间:2012-04-14 03:29:09

标签: java xml saml xml-signature saml-2.0

我正在使用xml签名来验证saml请求:

签署前的初始saml请求:

<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID
="abc" Version="2.0" IssueInstant="2012-04-14T8:55:05:31" ProtocolBinding="urn:o
asis:names:tc:SAML:2.0:bindings:HTTP-POST" AssertionConsumerServiceURL="http://l
ocalhost:8080/consumer.jsp"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0
:assertion">http://localhost:8080/saml/SProvider.jsp</saml:Issuer></samlp:AuthnR
equest>

签署xml文档然后将其转换为字符串(使用变换器)后,我得到以下内容:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?><samlp:AuthnReques
    t xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" AssertionConsumerServiceURL
    ="http://localhost:8080/consumer.jsp" ID="abc" IssueInstant="2012-04-14T8:55:05:
    31" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.
    0"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">http://localh
    ost:8080/saml/SProvider.jsp</saml:Issuer><Signature xmlns="http://www.w3.org/200
    0/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/
    TR/2001/REC-xml-c14n-20010315#WithComments"/><SignatureMethod Algorithm="http://
    www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform A
    lgorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><
    DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>J
    QV+Gff3C0PDb5zbaB62ItqWaJ/yIFgOVfANUehlJpQ=</DigestValue></Reference></SignedInf
    o><SignatureValue>PJCFgkGUlQiOVn6g0hTgbbHkqOGAKB5sA8QjcdKrR5R9zuyn9ymfFZMo1jqpxU
   //#here 3UOCz1BcxsWt6+ 
    CSFSAS0SaQstuN8ns/5ltIYu3LFUrpIT4eRHxbYEjf+CFj0c08lFB+BLK3Tx3vEi7nQF+X1rUvZX
    XZEUmaAMLqNdhRSqurY=</SignatureValue></Signature></samlp:AuthnRequest>


正如您所看到的,初始字符串中的第一个属性是ID但是在签署后,第一个attrubute是AssertionConsumerServiceURL。为什么变得混乱?此外,在签名文档中,请参阅#here(最后一行),有一个换行符。为什么有换行符。我认为加密值不包含换行符。我不明白发生了什么。请帮忙。

2 个答案:

答案 0 :(得分:2)

为了计算签名,XML文件必须是canonicalized。它必须采用标准格式供接收应用程序验证签名。

但是,我不认为需要发送规范化的;因为接收应用程序还必须规范化XML以计算签名以进行验证。因此,您可以在签名后尝试reformat it。但我不知道这是否有效,所以要彻底测试。

答案 1 :(得分:1)

请参阅此链接。 error due to xml signature。大多数人都说xml签名不能保证你对xml标签的排序。它还说这是由于规范化。但我不确定。我开始知道的一件事是,使用xml签名时并不罕见。