345.6. 署名済み要素のシブリングとしての Detached XML 署名
2.14.0 以降
署名が、署名された要素のシブリングである detached 署名を作成できます。次の例には、2 つの detached 署名が含まれています。最初の署名は要素 C
用で、2 番目の署名は要素 A
用です。シグネチャーは ネストされて います。2 番目の署名は、最初の署名も含む要素 A
に対するものです。
Detached XML 署名の例
<?xml version="1.0" encoding="UTF-8" ?> <root> <A ID="IDforA"> <B> <C ID="IDforC"> <D>dvalue</D> </C> <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="_6bf13099-0568-4d76-8649-faf5dcb313c0"> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /> <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> <ds:Reference URI="#IDforC"> ... </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>aUDFmiG71</ds:SignatureValue> </ds:Signature> </B> </A> <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"Id="_6b02fb8a-30df-42c6-ba25-76eba02c8214"> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /> <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> <ds:Reference URI="#IDforA"> ... </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>q3tvRoGgc8cMUqUSzP6C21zb7tt04riPnDuk=</ds:SignatureValue> </ds:Signature> <root>
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<A ID="IDforA">
<B>
<C ID="IDforC">
<D>dvalue</D>
</C>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
Id="_6bf13099-0568-4d76-8649-faf5dcb313c0">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<ds:SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#IDforC">
...
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>aUDFmiG71</ds:SignatureValue>
</ds:Signature>
</B>
</A>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"Id="_6b02fb8a-30df-42c6-ba25-76eba02c8214">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<ds:SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#IDforA">
...
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>q3tvRoGgc8cMUqUSzP6C21zb7tt04riPnDuk=</ds:SignatureValue>
</ds:Signature>
<root>
この例は、複数の要素に署名できること、および要素ごとに署名がシブリングとして作成されることを示しています。署名する要素には、タイプ ID の属性が必要です。属性の ID タイプは、XML スキーマで定義する必要があります (オプション schemaResourceUri
を参照)。 タイプ ID の属性を指す XPATH 式のリストを指定します (オプション xpathsToIdAttributes
を参照)。これらの属性は、署名される要素を決定します。要素は、keyAccessor
Bean によって指定された同じキーによって署名されます。より高い (より深い) 階層レベルを持つ要素が最初に署名されます。この例では、要素 C
は要素 A
の前に署名されています。
Java DSL の例
from("direct:detached") .to("xmlsecurity:sign://detached?keyAccessor=#keyAccessorBeant&xpathsToIdAttributes=#xpathsToIdAttributesBean&schemaResourceUri=Test.xsd") .to("xmlsecurity:verify://detached?keySelector=#keySelectorBean&schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd") .to("mock:result");
from("direct:detached")
.to("xmlsecurity:sign://detached?keyAccessor=#keyAccessorBeant&xpathsToIdAttributes=#xpathsToIdAttributesBean&schemaResourceUri=Test.xsd")
.to("xmlsecurity:verify://detached?keySelector=#keySelectorBean&schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd")
.to("mock:result");
Spring の例
<bean id="xpathsToIdAttributesBean" class="java.util.ArrayList"> <constructor-arg type="java.util.Collection"> <list> <bean class="org.apache.camel.component.xmlsecurity.api.XmlSignatureHelper" factory-method="getXpathFilter"> <constructor-arg type="java.lang.String" value="/ns:root/a/@ID" /> <constructor-arg> <map key-type="java.lang.String" value-type="java.lang.String"> <entry key="ns" value="http://test" /> </map> </constructor-arg> </bean> </list> </constructor-arg> </bean> ... <from uri="direct:detached" /> <to uri="xmlsecurity:sign://detached?keyAccessor=#keyAccessorBean&xpathsToIdAttributes=#xpathsToIdAttributesBean&schemaResourceUri=Test.xsd" /> <to uri="xmlsecurity:verify://detached?keySelector=#keySelectorBean&schemaResourceUri=Test.xsd" /> <to uri="mock:result" />
<bean id="xpathsToIdAttributesBean" class="java.util.ArrayList">
<constructor-arg type="java.util.Collection">
<list>
<bean
class="org.apache.camel.component.xmlsecurity.api.XmlSignatureHelper"
factory-method="getXpathFilter">
<constructor-arg type="java.lang.String"
value="/ns:root/a/@ID" />
<constructor-arg>
<map key-type="java.lang.String" value-type="java.lang.String">
<entry key="ns" value="http://test" />
</map>
</constructor-arg>
</bean>
</list>
</constructor-arg>
</bean>
...
<from uri="direct:detached" />
<to
uri="xmlsecurity:sign://detached?keyAccessor=#keyAccessorBean&xpathsToIdAttributes=#xpathsToIdAttributesBean&schemaResourceUri=Test.xsd" />
<to
uri="xmlsecurity:verify://detached?keySelector=#keySelectorBean&schemaResourceUri=Test.xsd" />
<to uri="mock:result" />