Search in sources :

Example 1 with GenericAlgorithm

use of xades4j.algorithms.GenericAlgorithm 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 GenericAlgorithm

use of xades4j.algorithms.GenericAlgorithm in project xades4j by luisgoncalves.

the class SignatureUtils method processReferences.

static ReferencesRes processReferences(XMLSignature signature) throws QualifyingPropertiesIncorporationException, XAdES4jXMLSigException {
    SignedInfo signedInfo = signature.getSignedInfo();
    List<RawDataObjectDesc> dataObjsReferences = new ArrayList<RawDataObjectDesc>(signedInfo.getLength() - 1);
    Reference signedPropsRef = null;
    for (int i = 0; i < signedInfo.getLength(); i++) {
        Reference ref;
        try {
            ref = signedInfo.item(i);
        } catch (XMLSecurityException ex) {
            throw new XAdES4jXMLSigException(String.format("Cannot process the %dth reference", i), ex);
        }
        String refTypeUri = ref.getType();
        // with its value set to: http://uri.etsi.org/01903#SignedProperties."
        if (QualifyingProperty.SIGNED_PROPS_TYPE_URI.equals(refTypeUri)) {
            if (signedPropsRef != null) {
                throw new QualifyingPropertiesIncorporationException("Multiple references to SignedProperties");
            }
            signedPropsRef = ref;
        } else {
            RawDataObjectDesc dataObj = new RawDataObjectDesc(ref);
            dataObjsReferences.add(dataObj);
            try {
                Transforms transfs = ref.getTransforms();
                if (transfs != null) {
                    for (int j = 0; j < transfs.getLength(); ++j) {
                        dataObj.withTransform(new GenericAlgorithm(transfs.item(j).getURI()));
                    }
                }
            } catch (XMLSecurityException ex) {
                throw new XAdES4jXMLSigException("Cannot process transfroms", ex);
            }
        }
    }
    if (null == signedPropsRef) // !!!
    // Still may be a XAdES signature, if the signing certificate is
    // protected. For now, that scenario is not supported.
    {
        throw new QualifyingPropertiesIncorporationException("SignedProperties reference not found");
    }
    return new ReferencesRes(dataObjsReferences, signedPropsRef);
}
Also used : Reference(org.apache.xml.security.signature.Reference) Transforms(org.apache.xml.security.transforms.Transforms) ArrayList(java.util.ArrayList) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) SignedInfo(org.apache.xml.security.signature.SignedInfo) XAdES4jXMLSigException(xades4j.XAdES4jXMLSigException)

Example 3 with GenericAlgorithm

use of xades4j.algorithms.GenericAlgorithm in project xades4j by luisgoncalves.

the class DataObjectDescTest method testWithTransform.

@Test
public void testWithTransform() throws Exception {
    System.out.println("withTransform");
    Document doc = SignatureServicesTestBase.getNewDocument();
    DataObjectDesc instance = new DataObjectDescTestImpl().withTransform(new XPathTransform("xpath")).withTransform(XPath2Filter.subtract("xpath1").intersect("xpath2")).withTransform(new GenericAlgorithm("uri", doc.createElement("param1"), doc.createElement("param2")));
    Algorithm[] transforms = instance.getTransforms().toArray(new Algorithm[0]);
    assertEquals(3, transforms.length);
    assertEquals(XPathTransform.class, transforms[0].getClass());
    assertEquals(XPath2FilterTransform.class, transforms[1].getClass());
    assertEquals(GenericAlgorithm.class, transforms[2].getClass());
}
Also used : XPathTransform(xades4j.algorithms.XPathTransform) Document(org.w3c.dom.Document) Algorithm(xades4j.algorithms.Algorithm) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) GenericAlgorithm(xades4j.algorithms.GenericAlgorithm) Test(org.junit.Test)

Aggregations

GenericAlgorithm (xades4j.algorithms.GenericAlgorithm)3 Algorithm (xades4j.algorithms.Algorithm)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 Reference (org.apache.xml.security.signature.Reference)1 SignedInfo (org.apache.xml.security.signature.SignedInfo)1 Transforms (org.apache.xml.security.transforms.Transforms)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 XAdES4jXMLSigException (xades4j.XAdES4jXMLSigException)1 XPathTransform (xades4j.algorithms.XPathTransform)1 XmlEncapsulatedPKIDataType (xades4j.xml.bind.xades.XmlEncapsulatedPKIDataType)1 XmlXAdESTimeStampType (xades4j.xml.bind.xades.XmlXAdESTimeStampType)1 XmlCanonicalizationMethodType (xades4j.xml.bind.xmldsig.XmlCanonicalizationMethodType)1