2014-04-30 71 views
2

我注意到在我的文檔中使用xades4j進行了簽名,但簽名簽名的引用中沒有Type =「.. CountersignedSignature」。 document.signed.bes.cs.xml中的xades4j單元測試也是如此。xades4j中缺少CountersignedSignature類型

在另一方面,在xades4j.properties.CounterSignatureProperty我可以看到規定的下列財產:

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

我怎麼能強迫的XAdES使用該屬性?如果缺少type屬性,我在驗證其他第三方軟件中的文檔時遇到問題。

我用寫在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)); 

在此先感謝!


EDIT1: 我補充一點,我知道該解決方案通過修改xades4j來源,但我會用我可以只適用於我的源代碼的解決方案更感興趣。

回答

2

的XAdES的規範定義了兩種機制來管理計數器簽名:

  1. 使用上的任意簽名Type屬性
  2. 使用CounterSignature屬性,它包含一個計數器簽名實際上是一個封裝的簽名(包含在原來的一個)。

XAdES4j使用第二種方法,因此不包括Type屬性。此外,無法在API上執行它的存在。也就是說,我可以檢查是否容易包含該屬性。

+0

如果是關於更改xades4j,則可以通過修改src/main/java/xades4j/production/DataGenCounterSig.java來添加此項:'sigValueRef = sigValueRef.withType(CounterSignatureProperty.COUNTER_SIGNATURE_TYPE_URI);'(http:// www。 speedyshare.com/Cgc2j/DataGenCounterSig.java)。無論如何,我必須這樣做,但它是硬編碼的。另一方面,這個屬性是可選的,所以添加Type總是不應該破壞任何東西。 –

+0

是的,就是這樣。該屬性不是必需的,因爲它是多餘的,但它不應該是一個問題。我會更新xades4j源代碼。 – lgoncalves