第 374 章 XML 安全组件
从 Camel 版本 2.12 开始提供
使用这个 Apache Camel 组件,您可以生成并验证 XML 签名,如 W3C 标准 XML 签名语法和处理 中所述,如后续版本 1.1 中所述。有关 XML 加密支持,请参阅 XML 安全 数据格式。
您可以在此处找到 XML 签名简介。http://www.oracle.com/technetwork/articles/javase/dig-signatures-141823.html组件的实施基于 JSR 105,与 W3C 标准对应的 Java API,支持 JSR 105 的 Apache Santuario 和 JDK 提供程序。该实施将首先尝试使用 Apache Santuario 供应商;如果没有找到 Santuario 供应商,它将使用 JDK 提供程序。此外,实施还基于 DOM。
自 Camel 2.15.0 起,我们还为 signer 端点提供了对 XAdES-BES/EPES 的支持;请参阅部分"XAdES-BES/EPES for the Signer Endpoint"。
Maven 用户需要将以下依赖项添加到此组件的 pom.xml 中:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xmlsecurity</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
374.1. XML 签名封装模式 复制链接链接已复制到粘贴板!
XML 签名在信封、信封和分离的 XML 签名之间有所不同。在 信封的 XML 签名案例中,XML 签名由签名的 XML 文档嵌套;这意味着 XML 签名元素是父元素的子元素,属于签名的 XML 文档。在 信封 XML 签名案例中,XML 签名包含签名内容。所有其他情况都被称为 分离 XML 签名。从 2.14.0 开始,支持某种形式的分离 XML 签名。
在 信封 XML 签名 案例中,支持的 XML 签名具有以下结构(可由 []周围)。
<[parent element]>
... <!-- Signature element is added as last child of the parent element-->
<Signature Id="generated_unique_signature_id">
<SignedInfo>
<Reference URI="">
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
(<Transform>)* <!-- By default "http://www.w3.org/2006/12/xml-c14n11" is added to the transforms -->
<DigestMethod>
<DigestValue>
</Reference>
(<Reference URI="#[keyinfo_Id]">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<DigestMethod>
<DigestValue>
</Reference>)?
<!-- further references possible, see option 'properties' below -->
</SignedInfo>
<SignatureValue>
(<KeyInfo Id="[keyinfo_id]">)?
<!-- Object elements possible, see option 'properties' below -->
</Signature>
</[parent element]>
在 信封 XML 签名 问题单中,支持的生成的 XML 签名具有结构:
<Signature Id="generated_unique_signature_id">
<SignedInfo>
<Reference URI="#generated_unique_object_id" type="[optional_type_value]">
(<Transform>)* <!-- By default "http://www.w3.org/2006/12/xml-c14n11" is added to the transforms -->
<DigestMethod>
<DigestValue>
</Reference>
(<Reference URI="#[keyinfo_id]">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<DigestMethod>
<DigestValue>
</Reference>)?
<!-- further references possible, see option 'properties' below -->
</SignedInfo>
<SignatureValue>
(<KeyInfo Id="[keyinfo_id]">)?
<Object Id="generated_unique_object_id"/> <!-- The Object element contains the in-message body; the object ID can either be generated or set by the option parameter "contentObjectId" -->
<!-- Further Object elements possible, see option 'properties' below -->
</Signature>
从 2.14.0 分离 XML 签名 时,支持以下结构(请参阅子章节 XML 签名作为 Signed Element 的 Siblings):
(<[signed element] Id="[id_value]">
<!-- signed element must have an attribute of type ID -->
...
</[signed element]>
<other sibling/>*
<!-- between the signed element and the corresponding signature element, there can be other siblings.
Signature element is added as last sibling. -->
<Signature Id="generated_unique_ID">
<SignedInfo>
<CanonicalizationMethod>
<SignatureMethod>
<Reference URI="#[id_value]" type="[optional_type_value]">
<!-- reference URI contains the ID attribute value of the signed element -->
(<Transform>)* <!-- By default "http://www.w3.org/2006/12/xml-c14n11" is added to the transforms -->
<DigestMethod>
<DigestValue>
</Reference>
(<Reference URI="#[generated_keyinfo_Id]">
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<DigestMethod>
<DigestValue>
</Reference>)?
</SignedInfo>
<SignatureValue>
(<KeyInfo Id="[generated_keyinfo_id]">)?
</Signature>)+