我注意到在我用 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 属性,我将无法在其他第 3 方软件中验证文档。
我使用了用 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 源知道解决方案,但我对只能在我的源代码中应用的解决方案更感兴趣。
最佳答案
XAdES 规范定义了两种管理计数器签名的机制:
- 对任意签名使用
Type
属性 - 使用
CounterSignature
属性,它包含一个计数器签名,它实际上是一个封装的签名(包含在原始签名中)。
XAdES4j 使用第二种方法,因此不包括 Type
属性。此外,也无法强制其在 API 上存在。也就是说,我可能会检查是否容易包含该属性。
关于java - xades4j 中缺少 CountersignedSignature 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23394852/