如何将SignedDataObject(ds:Object)插入xades:UngignedProperties的CounterSignature元素中

时间:2013-11-23 01:48:39

标签: xades4j

我需要在CounterSignature中插入一个ds:Object - 名为“xmldsig-my-object”,以便与xades4j库形成以下xml结构:

<ds:Signature>
...
  <ds:Object>
    ...
    <xades:UnsignedProperties>
      <xades:UnsignedSignatureProperties>
        <xades:CounterSignature>
          <ds:Signature>
            <ds:SignedInfo>
              <ds:Reference Id... Type="xmldsig#Object" URI="xmldsig-my-object">
               // !!! here I need to add reference to my-object
              </ds:Reference>
            </ds:SignedInfo>
            <ds:Object Id="xmldsig-my-object">
              // !!! here I need to add my-object
            </ds:Object>
          </ds:Signature>
       </xades:CounterSignature>
     </xades:UnsignedSignatureProperties>
    </xades:UnsignedProperties>
  </ds:Object>
</ds:Signature>

我生成xades签名,然后使用反签名(Element signatureNode)来丰富它:

    Element signatureNode = ...;
    XadesSignatureFormatExtender extender = new XadesFormatExtenderProfile()
                                            .getFormatExtender();
    XMLSignature sig = new XMLSignature(signatureNodeToEnrich, "");
    try {
        final XadesSigner counterSigner = 
            new XadesTSigningProfile(myKeyingDataProvider)
                .withPolicyProvider(mySignaturePolicyInfoProvider)
                .withAlgorithmsProviderEx(myXadesAlgorithmsProviderEx)
                .withTimeStampTokenProvider(myTimeStampTokenProvider())
                .newSigner();
        Collection<UnsignedSignatureProperty> usp = new ArrayList<>(1);
        usp.add(new CounterSignatureProperty(counterSigner));

        extender.enrichSignature(sig, new UnsignedProperties(usp));        
    } catch (Exception exc) {
        exc.printStackTrace(System.out);
        throw exc;
    }

如何将对象添加到CouterSignature的SignedInfo参考中  像往常一样:

SignedDataObjects signedObjs = new SignedDataObjects();
 Document docObj1 = createDocument();
    .....................
 DataObjectDesc myObj1 = new EnvelopedXmlObject(..., "text/xml", null);
 signedObjs.withSignedDataObject(myObj1);
 signer = new XadesTSigningProfile(...).newSigner();
 signer.sign(signedObjs, docDest);

1 个答案:

答案 0 :(得分:0)

目前无法将其他数据对象添加到计数器签名中。 Countersignature属性的生成包括引用目标签名的ds:SignatureValue元素的单个数据对象:

https://code.google.com/p/xades4j/source/browse/trunk/src/main/java/xades4j/production/DataGenCounterSig.java

CounterSignatureProperty类可能会将SignedDataObjects的实例包含在计数器签名中:

https://code.google.com/p/xades4j/source/browse/trunk/src/main/java/xades4j/properties/CounterSignatureProperty.java