1
我試圖用camel生成一個分離的XML簽名文檔。我注意到,如果我篡改名稱空間的名稱,文檔就會失效。例如。從「soap」變爲「soap1」命名空間使得文檔無效。我得到一個:XML根元素中的更改是否應更改子元素的簽名值?
org.apache.camel.component.xmlsecurity.api.XmlSignatureInvalidValueException:
Signature validation failed. The signature value could not be
validated by the public key. Either the message has been
tampered or the public key is not correct.
應該是這樣嗎?
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<anotherSample attr="1234"/>
<sample ID="sampleID"/>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference URI="#sampleID">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>....</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>...</ds:SignatureValue>
<ds:KeyInfo>....</ds:KeyInfo>
</ds:Signature>
</soap:Body>
</soap:Envelope>
是的,這是正確的。壓縮命名空間意味着你篡改郵件,因此簽名是無效的。整個文檔用於數字簽名。 – Namphibian
看來我的錯誤印象是簽名忽略了在簽名元素之外發生的事情。但這是不正確的,因爲它會允許XML包裝攻擊。 –
它取決於ds:SignedInfo中使用的規範化算法。如果您使用「獨佔」規範化(http://www.w3.org/TR/xml-exc-c14n/),則子元素不會繼承父項的名稱空間。 – Moez