【问题标题】:Missing CountersignedSignature type in xades4jxades4j 中缺少会签签名类型
【发布时间】:2014-04-30 17:51:55
【问题描述】:

我注意到在我使用 xades4j 会签的文档中,会签签名的参考中没有 Type="..CountersignedSignature"。 document.signed.bes.cs.xml 中的 xades4j 单元测试也是如此。

另一方面,在xades4j.properties.CounterSignatureProperty 中,我可以看到定义了以下属性:

public String COUNTER_SIGNATURE_TYPE_URI = "http://uri.etsi.org/01903#CountersignedSignature";

如何强制 xades 使用该属性?如果缺少 type 属性,我在其他 3rd 方软件中验证文档时遇到问题。

我使用了用 SignerBESTest 编写的代码。

Document doc = getTestDocument();
Element elemToSign = doc.getDocumentElement();

XadesBesSigningProfile profile = new XadesBesSigningProfile(keyingProviderMy);
final XadesSigner counterSigner = profile.newSigner();
profile.withSignaturePropertiesProvider(new SignaturePropertiesProvider() {
@Override
public void provideProperties(final SignaturePropertiesCollector signedPropsCol) {
    signedPropsCol.addCounterSignature(new CounterSignatureProperty(counterSigner));
    signedPropsCol.setSignerRole(new SignerRoleProperty("CounterSignature"));
}
});
final XadesSignatureFormatExtender extender = new XadesFormatExtenderProfile().getFormatExtender();

final List<UnsignedSignatureProperty> unsignedProps = new ArrayList<UnsignedSignatureProperty>();
unsignedProps.add(new CounterSignatureProperty(counterSigner));

org.apache.xml.security.Init.init();
final Element sigElem = (Element) documentSource.getElementsByTagName("ds:Signature").item(0);
final XMLSignature xmlSig = new XMLSignature(sigElem, documentSource.getBaseURI());
extender.enrichSignature(xmlSig, new UnsignedProperties(unsignedProps));

提前致谢!


编辑1: 我将补充一点,我通过修改 xades4j 源知道解决方案,但我会对只能在我的源代码中应用的解决方案更感兴趣。

【问题讨论】:

    标签: java xades4j


    【解决方案1】:

    XAdES 规范定义了两种管理计数器签名的机制:

    1. 在任意签名上使用Type 属性
    2. 使用CounterSignature 属性,其中包含实际上是封装签名(包含在原始签名中)的反签名。

    XAdES4j 使用第二种方法,因此不包括Type 属性。此外,无法强制其在 API 上的存在。也就是说,我可能会检查是否容易包含该属性。

    【讨论】:

    • 如果是关于更改 xades4j,则可以通过修改 src/main/java/xades4j/production/DataGenCounterSig.java 来添加:sigValueRef = sigValueRef.withType(CounterSignatureProperty.COUNTER_SIGNATURE_TYPE_URI); (speedyshare.com/Cgc2j/DataGenCounterSig.java)。无论如何我都必须这样做,但它是硬编码的。另一方面,这个属性是可选的,所以添加类型总是不应该破坏任何东西。
    • 是的,就是这样。该属性不是必需的,因为它是多余的,但它不应该是一个问题。我会更新 xades4j 源代码。
    猜你喜欢
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多