Search in sources :

Example 1 with XmlXAdESTimeStampType

use of xades4j.xml.bind.xades.XmlXAdESTimeStampType in project xades4j by luisgoncalves.

the class FromXmlBaseTimeStampConverter method convertTimeStamps.

protected void convertTimeStamps(List<XmlXAdESTimeStampType> xmlTimeStamps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
    if (null == xmlTimeStamps || xmlTimeStamps.isEmpty())
        return;
    for (XmlXAdESTimeStampType xmlTS : xmlTimeStamps) {
        if (!xmlTS.getReferenceInfo().isEmpty())
            throw new PropertyUnmarshalException("ReferenceInfo is not supported in XAdESTimeStamp", propName);
        Algorithm c14n;
        XmlCanonicalizationMethodType xmlCanonMethod = xmlTS.getCanonicalizationMethod();
        if (null == xmlCanonMethod) {
            c14n = new GenericAlgorithm(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
        } else {
            List params = CollectionUtils.filterByType(xmlCanonMethod.getContent(), Element.class);
            c14n = new GenericAlgorithm(xmlCanonMethod.getAlgorithm(), params);
        }
        TPropData tsData = createTSData(c14n);
        List<Object> tsTokens = xmlTS.getEncapsulatedTimeStampOrXMLTimeStamp();
        if (tsTokens.isEmpty())
            throw new PropertyUnmarshalException("No time-stamp tokens", propName);
        for (Object tkn : tsTokens) {
            if (!(tkn instanceof XmlEncapsulatedPKIDataType))
                throw new PropertyUnmarshalException("XML time-stamps are not supported", propName);
            tsData.addTimeStampToken(((XmlEncapsulatedPKIDataType) tkn).getValue());
        }
        doSpecificConvert(xmlTS, tsData);
        setTSData(tsData, propertyDataCollector);
    }
}
Also used : XmlEncapsulatedPKIDataType(xades4j.xml.bind.xades.XmlEncapsulatedPKIDataType) XmlXAdESTimeStampType(xades4j.xml.bind.xades.XmlXAdESTimeStampType) List(java.util.List) Algorithm(xades4j.algorithms.Algorithm) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) XmlCanonicalizationMethodType(xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType)

Example 2 with XmlXAdESTimeStampType

use of xades4j.xml.bind.xades.XmlXAdESTimeStampType in project xades4j by luisgoncalves.

the class ToXmlArchiveTimeStampConverter method insertIntoObjectTree.

@Override
protected void insertIntoObjectTree(XmlXAdESTimeStampType xmlTimeStamp, XmlUnsignedPropertiesType xmlProps, ArchiveTimeStampData propData) {
    JAXBElement<XmlXAdESTimeStampType> xmlArchTS = new ObjectFactory().createArchiveTimeStampV2(xmlTimeStamp);
    xmlProps.getUnsignedSignatureProperties().getAny().add(xmlArchTS);
}
Also used : ObjectFactory(xades4j.xml.bind.xades.ObjectFactory) XmlXAdESTimeStampType(xades4j.xml.bind.xades.XmlXAdESTimeStampType)

Example 3 with XmlXAdESTimeStampType

use of xades4j.xml.bind.xades.XmlXAdESTimeStampType in project xades4j by luisgoncalves.

the class ToXmlBaseTimeStampConverter method convertIntoObjectTree.

@Override
public final void convertIntoObjectTree(PropertyDataObject propData, TXml xmlProps, Document doc) {
    TData tsData = (TData) propData;
    XmlXAdESTimeStampType xmlTimeStamp = new XmlXAdESTimeStampType();
    // Canonicalization method
    XmlCanonicalizationMethodType xmlCanon = new XmlCanonicalizationMethodType();
    xmlTimeStamp.setCanonicalizationMethod(xmlCanon);
    Algorithm c14n = tsData.getCanonicalizationAlgorithm();
    xmlCanon.setAlgorithm(c14n.getUri());
    try {
        List<Node> c14nParams = this.algorithmsParametersMarshallingProvider.marshalParameters(c14n, doc);
        if (c14nParams != null) {
            xmlCanon.getContent().addAll(c14nParams);
        }
    } catch (UnsupportedAlgorithmException ex) {
        // Do not throw any specific exception for now.
        throw new IllegalArgumentException("Cannot marshall algorithm parameters", ex);
    }
    // Time-stamp tokens
    List<byte[]> tsTokens = tsData.getTimeStampTokens();
    List<Object> xmlTSTokens = xmlTimeStamp.getEncapsulatedTimeStampOrXMLTimeStamp();
    for (byte[] tsToken : tsTokens) {
        XmlEncapsulatedPKIDataType xmlTSTkn = new XmlEncapsulatedPKIDataType();
        xmlTSTkn.setValue(tsToken);
        xmlTSTokens.add(xmlTSTkn);
    }
    insertIntoObjectTree(xmlTimeStamp, xmlProps, tsData);
}
Also used : Node(org.w3c.dom.Node) Algorithm(xades4j.algorithms.Algorithm) UnsupportedAlgorithmException(xades4j.UnsupportedAlgorithmException) XmlEncapsulatedPKIDataType(xades4j.xml.bind.xades.XmlEncapsulatedPKIDataType) XmlXAdESTimeStampType(xades4j.xml.bind.xades.XmlXAdESTimeStampType) PropertyDataObject(xades4j.properties.data.PropertyDataObject) XmlCanonicalizationMethodType(xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType)

Aggregations

XmlXAdESTimeStampType (xades4j.xml.bind.xades.XmlXAdESTimeStampType)3 Algorithm (xades4j.algorithms.Algorithm)2 XmlEncapsulatedPKIDataType (xades4j.xml.bind.xades.XmlEncapsulatedPKIDataType)2 XmlCanonicalizationMethodType (xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType)2 List (java.util.List)1 Node (org.w3c.dom.Node)1 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)1 GenericAlgorithm (xades4j.algorithms.GenericAlgorithm)1 PropertyDataObject (xades4j.properties.data.PropertyDataObject)1 ObjectFactory (xades4j.xml.bind.xades.ObjectFactory)1