最近、camel の xml セキュリティ コンポーネントを使用して XML 入力を渡し、署名を取得するようになりました。出力 XML が正規化されていない XML で署名されていることを発見しました。このケースは、my が response.xml に空の要素を含む場合に発生します。「direct:detachedSign」ルートからの出力は、署名が要素で計算されることを示しています。
Q: シグネチャ ルートの出力に CanonicalizationMethod と Transform があるのに、まだ非正規要素があるのはなぜですか?
使用された入力 response.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:response xmlns:ns2="http://www.w3.org/2000/09/xmldsig#"
xmlns:ns3="http://example.com">
<sampleHolder ID="myUniqueID">
<sample></sample>
</sampleHolder>
</ns3:response>
非正規の署名済み要素を含む署名ルートからの output.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns3:response xmlns:ns3="http://example.com" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#">
<sampleHolder ID="myUniqueID">
<sample/>
</sampleHolder>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#myUniqueID">
<Transforms>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>...</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>...</SignatureValue>
<KeyInfo>...</KeyInfo>
</Signature>
</ns3:response>
署名と検証のための SignAndVerifiyXmlSignatureRoutes.java
public class SignAndVerifiyXmlSignatureRoutes extends RouteBuilder {
@Override
public final void configure() throws Exception {
// Detached signature
from("direct:detachedSign")//
.to("xmlsecurity:sign://detached"//
+ "?keyAccessor=#jksKeyAccessor"//
+ "&xpathsToIdAttributes=#xpathsToIdAttributesBean"//
+ "&schemaResourceUri=xsd/response.xsd"//
+ "&signatureId="//
+ "&prefixForXmlSignatureNamespace=" //
+ "&canonicalizationMethod=#canonicalizationBean" //
+ "&signatureAlgorithm=http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" //
+ "&digestAlgorithm=http://www.w3.org/2001/04/xmlenc#sha256"//
+ "&transformMethods=#transformMethodsBean" //
+ "&clearHeaders=false"); //
from("direct:verify")//
.to("xmlsecurity:verify://detached?keySelector=#jksKeySelector" + //
"&schemaResourceUri=xsd/response.xsd");
}
}