How to insert SignedDataObject (ds:Object) into CounterSignature element of xades:UngignedProperties

StackOverflow https://stackoverflow.com/questions/20157539

  •  04-08-2022
  •  | 
  •  

Question

I need to insert a ds:Object - named "xmldsig-my-object" into CounterSignature to form the following xml structure with xades4j library:

<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>

I produce the xades signature and then enrich it with counter-signature (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;
    }

What should I do to add an Object to CouterSignature's SignedInfo References like in the usual way:

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);
Was it helpful?

Solution

currently there's no way of adding other data objects to a counter signature. The generation of the Countersignature property includes a single data object that references the ds:SignatureValue element of the target signature:

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

The CounterSignatureProperty class could probably get an instance of SignedDataObjects to be included in the counter signature:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top