Search in sources :

Example 1 with UnsignedSignatureProperty

use of xades4j.properties.UnsignedSignatureProperty in project xades4j by luisgoncalves.

the class QualifyingPropertiesProcessor method getQualifyingProperties.

QualifyingProperties getQualifyingProperties(SignedDataObjects dataObjs, Collection<SignedSignatureProperty> formatSpecificSignedSigProps, Collection<UnsignedSignatureProperty> formatSpecificUnsignedSigProps) {
    /* **** Signature properties **** */
    // Collect the signature properties from the provider.
    SignaturePropertiesCollectorImpl signaturePropsCollector = new SignaturePropertiesCollectorImpl();
    sigPropsProvider.provideProperties(signaturePropsCollector);
    Collection<SignedSignatureProperty> collectedSignedSigProps = signaturePropsCollector.getSignedSigProps();
    Collection<SignedSignatureProperty> signedSigProps = new ArrayList<SignedSignatureProperty>(collectedSignedSigProps.size() + formatSpecificSignedSigProps.size());
    signedSigProps.addAll(collectedSignedSigProps);
    signedSigProps.addAll(formatSpecificSignedSigProps);
    Collection<UnsignedSignatureProperty> collectedUnsignedSigProps = signaturePropsCollector.getUnsignedSigProps();
    Collection<UnsignedSignatureProperty> unsignedSigProps = new ArrayList<UnsignedSignatureProperty>(collectedUnsignedSigProps.size() + formatSpecificUnsignedSigProps.size());
    unsignedSigProps.addAll(collectedUnsignedSigProps);
    unsignedSigProps.addAll(formatSpecificUnsignedSigProps);
    /* **** Data objects properties **** */
    Collection<DataObjectDesc> dataObjsInfo = dataObjs.getDataObjectsDescs();
    // The containers for all the specified signed data object properties. Since
    // some properties can be applied to multiple data objects, we need to rule
    // out repeated references (a Set is used).
    Set<SignedDataObjectProperty> signedDataObjProps = new HashSet<SignedDataObjectProperty>(dataObjsInfo.size());
    Set<UnsignedDataObjectProperty> unsignedDataObjProps = new HashSet<UnsignedDataObjectProperty>(0);
    // Add the global data object properties.
    signedDataObjProps.addAll(dataObjs.getSignedDataObjsProperties());
    unsignedDataObjProps.addAll(dataObjs.getUnsignedDataObjsProperties());
    // Add the properties specified for each data object.
    for (DataObjectDesc dataObjInfo : dataObjsInfo) {
        // If no properties were specified allow the provider to add them.
        if (!dataObjInfo.hasProperties())
            this.dataObjPropsProvider.provideProperties(dataObjInfo);
        signedDataObjProps.addAll(dataObjInfo.getSignedDataObjProps());
        unsignedDataObjProps.addAll(dataObjInfo.getUnsignedDataObjProps());
    }
    return new QualifyingProperties(new SignedProperties(signedSigProps, signedDataObjProps), new UnsignedProperties(unsignedSigProps, unsignedDataObjProps));
}
Also used : UnsignedDataObjectProperty(xades4j.properties.UnsignedDataObjectProperty) QualifyingProperties(xades4j.properties.QualifyingProperties) SignedSignatureProperty(xades4j.properties.SignedSignatureProperty) ArrayList(java.util.ArrayList) DataObjectDesc(xades4j.properties.DataObjectDesc) SignedDataObjectProperty(xades4j.properties.SignedDataObjectProperty) UnsignedProperties(xades4j.properties.UnsignedProperties) SignedProperties(xades4j.properties.SignedProperties) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) HashSet(java.util.HashSet)

Example 2 with UnsignedSignatureProperty

use of xades4j.properties.UnsignedSignatureProperty in project xades4j by luisgoncalves.

the class XadesSignatureFormatExtenderImplTest method testEnrichSignatureWithNestedCounterSig.

@Test
public void testEnrichSignatureWithNestedCounterSig() throws Exception {
    System.out.println("enrichSignatureWithNestedCounterSig");
    Document doc = getDocument("document.signed.bes.cs.xml");
    NodeList signatures = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
    // Existing counter signature is the last
    Element signatureNode = (Element) signatures.item(signatures.getLength() - 1);
    XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner();
    XadesSignatureFormatExtender extender = new XadesFormatExtenderProfile().getFormatExtender();
    XMLSignature sig = new XMLSignature(signatureNode, signatureNode.getOwnerDocument().getBaseURI());
    Collection<UnsignedSignatureProperty> usp = new ArrayList<UnsignedSignatureProperty>(1);
    usp.add(new CounterSignatureProperty(signer));
    extender.enrichSignature(sig, new UnsignedProperties(usp));
    outputDocument(doc, "document.signed.bes.cs.cs.xml");
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) UnsignedProperties(xades4j.properties.UnsignedProperties) XMLSignature(org.apache.xml.security.signature.XMLSignature) CounterSignatureProperty(xades4j.properties.CounterSignatureProperty) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) Test(org.junit.Test)

Example 3 with UnsignedSignatureProperty

use of xades4j.properties.UnsignedSignatureProperty in project xades4j by luisgoncalves.

the class XadesSignatureFormatExtenderImplTest method testEnrichSignatureWithA.

@Test
public void testEnrichSignatureWithA() throws Exception {
    System.out.println("enrichSignatureWithA");
    Document doc = getDocument("document.verified.c.xl.xml");
    Element signatureNode = (Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature").item(0);
    XadesSignatureFormatExtenderImpl instance = (XadesSignatureFormatExtenderImpl) new XadesFormatExtenderProfile().getFormatExtender();
    XMLSignature sig = new XMLSignature(signatureNode, "");
    Collection<UnsignedSignatureProperty> usp = new ArrayList<UnsignedSignatureProperty>(1);
    usp.add(new ArchiveTimeStampProperty());
    instance.enrichSignature(sig, new UnsignedProperties(usp));
    outputDocument(doc, "document.verified.c.xl.a.xml");
}
Also used : ArchiveTimeStampProperty(xades4j.properties.ArchiveTimeStampProperty) XMLSignature(org.apache.xml.security.signature.XMLSignature) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) Document(org.w3c.dom.Document) UnsignedProperties(xades4j.properties.UnsignedProperties) Test(org.junit.Test)

Example 4 with UnsignedSignatureProperty

use of xades4j.properties.UnsignedSignatureProperty in project xades4j by luisgoncalves.

the class XAdESVerificationResult method createQualifProps.

private QualifyingProperties createQualifProps() {
    Collection<QualifyingProperty> props = this.propertiesGetter.getAll();
    Collection<SignedSignatureProperty> ssp = CollectionUtils.filterByType(props, SignedSignatureProperty.class);
    Collection<SignedDataObjectProperty> sdop = CollectionUtils.filterByType(props, SignedDataObjectProperty.class);
    Collection<UnsignedSignatureProperty> usp = CollectionUtils.filterByType(props, UnsignedSignatureProperty.class);
    Collection<UnsignedDataObjectProperty> udop = CollectionUtils.filterByType(props, UnsignedDataObjectProperty.class);
    return new QualifyingProperties(new SignedProperties(ssp, sdop), new UnsignedProperties(usp, udop));
}
Also used : UnsignedDataObjectProperty(xades4j.properties.UnsignedDataObjectProperty) QualifyingProperties(xades4j.properties.QualifyingProperties) SignedSignatureProperty(xades4j.properties.SignedSignatureProperty) SignedDataObjectProperty(xades4j.properties.SignedDataObjectProperty) UnsignedProperties(xades4j.properties.UnsignedProperties) SignedProperties(xades4j.properties.SignedProperties) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) QualifyingProperty(xades4j.properties.QualifyingProperty)

Example 5 with UnsignedSignatureProperty

use of xades4j.properties.UnsignedSignatureProperty in project xades4j by luisgoncalves.

the class XadesVerifierImpl method verify.

@Override
public XAdESVerificationResult verify(Element signatureElem, SignatureSpecificVerificationOptions verificationOptions, XadesSignatureFormatExtender formatExtender, XAdESForm finalForm) throws XAdES4jException {
    if (null == finalForm || null == formatExtender) {
        throw new NullPointerException("'finalForm' and 'formatExtender' cannot be null");
    }
    // unnecessary processing.
    if (finalForm.before(XAdESForm.T) || finalForm.after(XAdESForm.X_L)) {
        throw new IllegalArgumentException("Signature format can only be extended to XAdES-T, C, X or X-L");
    }
    XAdESVerificationResult res = this.verify(signatureElem, verificationOptions);
    XAdESForm actualForm = res.getSignatureForm();
    if (actualForm.before(finalForm)) {
        // Valid form transitions:
        // * BES/EPES -> T
        // * BES/EPES -> C
        // * T -> C
        // * C -> X
        // * C -> X-L
        // * X -> X-L (not supported with the library defaults: X cannot be verified)
        // * X-L -> A (not supported with the library defaults: X-L cannot be verified)
        FormExtensionPropsCollector finalFormPropsColector = formsExtensionTransitions[actualForm.ordinal()][finalForm.ordinal()];
        if (null == finalFormPropsColector) {
            throw new InvalidFormExtensionException(actualForm, finalForm);
        }
        Collection<UnsignedSignatureProperty> usp = new ArrayList<UnsignedSignatureProperty>(3);
        finalFormPropsColector.addProps(usp, res);
        formatExtender.enrichSignature(res.getXmlSignature(), new UnsignedProperties(usp));
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) UnsignedProperties(xades4j.properties.UnsignedProperties)

Aggregations

UnsignedSignatureProperty (xades4j.properties.UnsignedSignatureProperty)7 ArrayList (java.util.ArrayList)6 UnsignedProperties (xades4j.properties.UnsignedProperties)6 XMLSignature (org.apache.xml.security.signature.XMLSignature)4 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 Test (org.junit.Test)3 QualifyingProperties (xades4j.properties.QualifyingProperties)3 SignedSignatureProperty (xades4j.properties.SignedSignatureProperty)3 DataObjectDesc (xades4j.properties.DataObjectDesc)2 SignedDataObjectProperty (xades4j.properties.SignedDataObjectProperty)2 SignedProperties (xades4j.properties.SignedProperties)2 UnsignedDataObjectProperty (xades4j.properties.UnsignedDataObjectProperty)2 PrivateKey (java.security.PrivateKey)1 X509Certificate (java.security.cert.X509Certificate)1 HashSet (java.util.HashSet)1 ObjectContainer (org.apache.xml.security.signature.ObjectContainer)1 Reference (org.apache.xml.security.signature.Reference)1 XMLSignatureException (org.apache.xml.security.signature.XMLSignatureException)1 Transforms (org.apache.xml.security.transforms.Transforms)1