Search in sources :

Example 1 with QualifyingProperty

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

the class PropertiesDataObjectsGeneratorImpl method doGenPropsData.

private <TProp extends QualifyingProperty> Collection<PropertyDataObject> doGenPropsData(Collection<TProp> props, PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException, PropertyDataStructureException {
    Collection<PropertyDataObject> propsData = new ArrayList<PropertyDataObject>(props.size());
    for (TProp p : props) {
        PropertyDataObjectGenerator<TProp> dataGen = this.propsDataGensMapper.getGenerator(p);
        PropertyDataObject pData = dataGen.generatePropertyData(p, ctx);
        if (null == pData)
            throw new PropertyDataGeneratorErrorException((QualifyingProperty) p);
        propsData.add(pData);
    }
    dataObjectsStructureVerifier.verifiyPropertiesDataStructure(propsData);
    return propsData;
}
Also used : ArrayList(java.util.ArrayList) PropertyDataObject(xades4j.properties.data.PropertyDataObject) QualifyingProperty(xades4j.properties.QualifyingProperty)

Example 2 with QualifyingProperty

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

the class TestElemDOMVerifier method testVerify.

@Test
public void testVerify() throws Exception {
    GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem"));
    QualifyingPropertyVerificationContext ctx = null;
    GenericDOMDataVerifier instance = new GenericDOMDataVerifier(customElemVerifiers);
    QualifyingProperty result = instance.verify(propData, ctx);
    assertEquals(result.getName(), "Elem");
}
Also used : GenericDOMData(xades4j.properties.data.GenericDOMData) QualifyingProperty(xades4j.properties.QualifyingProperty) Test(org.junit.Test)

Example 3 with QualifyingProperty

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

the class TimeStampVerifierBase method verify.

@Override
public final QualifyingProperty verify(TData propData, QualifyingPropertyVerificationContext ctx) throws InvalidPropertyException {
    try {
        TimeStampDigestInput digestInput = this.tsInputFactory.newTimeStampDigestInput(propData.getCanonicalizationAlgorithm());
        QualifyingProperty prop = addPropSpecificTimeStampInputAndCreateProperty(propData, digestInput, ctx);
        byte[] data = digestInput.getBytes();
        /**
         * Verify the time-stamp tokens on a time-stamp property data object. All
         * the tokens are verified, but the returned time-stamp is from the last token.
         */
        List<byte[]> tokens = propData.getTimeStampTokens();
        Date ts = null;
        for (byte[] tkn : tokens) {
            ts = this.tsVerifier.verifyToken(tkn, data);
        }
        // By convention all timestamp property types have a setTime(Date) method
        Method setTimeMethod = prop.getClass().getMethod("setTime", Date.class);
        setTimeMethod.invoke(prop, ts);
        return prop;
    } catch (UnsupportedAlgorithmException ex) {
        throw getEx(ex, this.propName);
    } catch (CannotAddDataToDigestInputException ex) {
        throw new TimeStampDigestInputException(this.propName, ex);
    } catch (TimeStampTokenVerificationException ex) {
        throw getEx(ex, this.propName);
    } catch (Exception ex) {
        // Exceptions related to setTimeMethod.invoke(...)
        throw getEx(ex, this.propName);
    }
}
Also used : CannotAddDataToDigestInputException(xades4j.utils.CannotAddDataToDigestInputException) TimeStampDigestInput(xades4j.utils.TimeStampDigestInput) UnsupportedAlgorithmException(xades4j.UnsupportedAlgorithmException) QualifyingProperty(xades4j.properties.QualifyingProperty) Method(java.lang.reflect.Method) TimeStampTokenVerificationException(xades4j.providers.TimeStampTokenVerificationException) Date(java.util.Date) CannotAddDataToDigestInputException(xades4j.utils.CannotAddDataToDigestInputException) TimeStampTokenStructureException(xades4j.providers.TimeStampTokenStructureException) UnsupportedAlgorithmException(xades4j.UnsupportedAlgorithmException) TimeStampTokenDigestException(xades4j.providers.TimeStampTokenDigestException) TimeStampTokenVerificationException(xades4j.providers.TimeStampTokenVerificationException) TimeStampTokenSignatureException(xades4j.providers.TimeStampTokenSignatureException)

Example 4 with QualifyingProperty

use of xades4j.properties.QualifyingProperty 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 QualifyingProperty

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

the class TimeStampCoherenceVerifier method verify.

@Override
public void verify(XAdESVerificationResult verificationData, QualifyingPropertyVerificationContext ctx) throws TimeStampCoherenceException {
    DataGetter<QualifyingProperty> propsGetter = verificationData.getPropertiesFilter();
    Collection<SignatureTimeStampProperty> sigTimeStamps = propsGetter.getOfType(SignatureTimeStampProperty.class);
    Collection<AllDataObjsTimeStampProperty> allDataObjsTimeStamps = propsGetter.getOfType(AllDataObjsTimeStampProperty.class);
    Collection<IndividualDataObjsTimeStampProperty> indivDataObjsTimeStamps = propsGetter.getOfType(IndividualDataObjsTimeStampProperty.class);
    for (SignatureTimeStampProperty sigTs : sigTimeStamps) {
        for (IndividualDataObjsTimeStampProperty indivDObjTs : indivDataObjsTimeStamps) {
            if (sigTs.getTime().before(indivDObjTs.getTime()))
                throw new TimeStampCoherenceException(SignatureTimeStampProperty.PROP_NAME, "time-stamp not posterior to data objects time-stamps");
        }
        for (AllDataObjsTimeStampProperty allDObjTs : allDataObjsTimeStamps) {
            if (sigTs.getTime().before(allDObjTs.getTime()))
                throw new TimeStampCoherenceException(SignatureTimeStampProperty.PROP_NAME, "time-stamp not posterior to data objects time-stamps");
        }
    }
}
Also used : SignatureTimeStampProperty(xades4j.properties.SignatureTimeStampProperty) AllDataObjsTimeStampProperty(xades4j.properties.AllDataObjsTimeStampProperty) QualifyingProperty(xades4j.properties.QualifyingProperty) IndividualDataObjsTimeStampProperty(xades4j.properties.IndividualDataObjsTimeStampProperty)

Aggregations

QualifyingProperty (xades4j.properties.QualifyingProperty)7 ArrayList (java.util.ArrayList)3 SignatureTimeStampProperty (xades4j.properties.SignatureTimeStampProperty)2 PropertyDataObject (xades4j.properties.data.PropertyDataObject)2 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)1 AllDataObjsTimeStampProperty (xades4j.properties.AllDataObjsTimeStampProperty)1 IndividualDataObjsTimeStampProperty (xades4j.properties.IndividualDataObjsTimeStampProperty)1 QualifyingProperties (xades4j.properties.QualifyingProperties)1 SignedDataObjectProperty (xades4j.properties.SignedDataObjectProperty)1 SignedProperties (xades4j.properties.SignedProperties)1 SignedSignatureProperty (xades4j.properties.SignedSignatureProperty)1 UnsignedDataObjectProperty (xades4j.properties.UnsignedDataObjectProperty)1 UnsignedProperties (xades4j.properties.UnsignedProperties)1 UnsignedSignatureProperty (xades4j.properties.UnsignedSignatureProperty)1 GenericDOMData (xades4j.properties.data.GenericDOMData)1 TimeStampTokenDigestException (xades4j.providers.TimeStampTokenDigestException)1