Search in sources :

Example 1 with TimeStampDigestInput

use of xades4j.utils.TimeStampDigestInput in project xades4j by luisgoncalves.

the class DataGenBaseTimeStamp method generatePropertyData.

@Override
public final PropertyDataObject generatePropertyData(TProp prop, PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException {
    Algorithm c14n = this.algsProvider.getCanonicalizationAlgorithmForTimeStampProperties();
    try {
        TimeStampDigestInput digestInput = this.tsInputFactory.newTimeStampDigestInput(c14n);
        addPropSpecificTimeStampInput(prop, digestInput, ctx);
        TimeStampTokenRes tsTknRes = this.tsTokenProvider.getTimeStampToken(digestInput.getBytes(), this.algsProvider.getDigestAlgorithmForTimeStampProperties());
        return createPropDataObj(prop, c14n, tsTknRes, ctx);
    } catch (UnsupportedAlgorithmException ex) {
        throw new PropertyDataGenerationException(prop, ex.getMessage(), ex);
    } catch (CannotAddDataToDigestInputException ex) {
        throw new PropertyDataGenerationException(prop, "cannot create time stamp input", ex);
    } catch (TimeStampTokenGenerationException ex) {
        throw new PropertyDataGenerationException(prop, "cannot get a time-stamp", ex);
    }
}
Also used : CannotAddDataToDigestInputException(xades4j.utils.CannotAddDataToDigestInputException) TimeStampDigestInput(xades4j.utils.TimeStampDigestInput) UnsupportedAlgorithmException(xades4j.UnsupportedAlgorithmException) TimeStampTokenRes(xades4j.providers.TimeStampTokenProvider.TimeStampTokenRes) Algorithm(xades4j.algorithms.Algorithm) TimeStampTokenGenerationException(xades4j.providers.TimeStampTokenGenerationException)

Example 2 with TimeStampDigestInput

use of xades4j.utils.TimeStampDigestInput 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)

Aggregations

UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)2 CannotAddDataToDigestInputException (xades4j.utils.CannotAddDataToDigestInputException)2 TimeStampDigestInput (xades4j.utils.TimeStampDigestInput)2 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Algorithm (xades4j.algorithms.Algorithm)1 QualifyingProperty (xades4j.properties.QualifyingProperty)1 TimeStampTokenDigestException (xades4j.providers.TimeStampTokenDigestException)1 TimeStampTokenGenerationException (xades4j.providers.TimeStampTokenGenerationException)1 TimeStampTokenRes (xades4j.providers.TimeStampTokenProvider.TimeStampTokenRes)1 TimeStampTokenSignatureException (xades4j.providers.TimeStampTokenSignatureException)1 TimeStampTokenStructureException (xades4j.providers.TimeStampTokenStructureException)1 TimeStampTokenVerificationException (xades4j.providers.TimeStampTokenVerificationException)1