Search in sources :

Example 1 with PropertyDataObject

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

use of xades4j.properties.data.PropertyDataObject 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)

Example 3 with PropertyDataObject

use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.

the class XadesVerifierImpl method verify.

@Override
public XAdESVerificationResult verify(Element signatureElem, SignatureSpecificVerificationOptions verificationOptions) throws XAdES4jException {
    if (null == signatureElem) {
        throw new NullPointerException("Signature node not specified");
    }
    if (null == verificationOptions) {
        verificationOptions = SignatureSpecificVerificationOptions.empty;
    }
    /* Unmarshal the signature */
    XMLSignature signature;
    try {
        signature = new XMLSignature(signatureElem, verificationOptions.getBaseUri(), this.secureValidation);
    } catch (XMLSecurityException ex) {
        throw new UnmarshalException("Bad XML signature", ex);
    }
    String signatureId = signature.getId();
    if (null == signatureId) {
        throw new UnmarshalException("XML signature doesn't have an Id");
    }
    ReferencesRes referencesRes = SignatureUtils.processReferences(signature);
    /* Apply early verifiers */
    RawSignatureVerifierContext rawCtx = new RawSignatureVerifierContext(signature);
    for (RawSignatureVerifier rawSignatureVerifier : this.rawSigVerifiers) {
        rawSignatureVerifier.verify(rawCtx);
    }
    /* Get and check the QualifyingProperties element */
    Element qualifyingPropsElem = SignatureUtils.getQualifyingPropertiesElement(signature);
    SignatureUtils.checkSignedPropertiesIncorporation(qualifyingPropsElem, referencesRes.signedPropsReference);
    // Check the QualifyingProperties 'Target' attribute.
    Node targetAttr = qualifyingPropsElem.getAttributeNodeNS(null, QualifyingProperty.TARGET_ATTR);
    if (null == targetAttr) {
        targetAttr = qualifyingPropsElem.getAttributeNodeNS(QualifyingProperty.XADES_XMLNS, QualifyingProperty.TARGET_ATTR);
        if (null == targetAttr) {
            throw new QualifyingPropertiesIncorporationException("QualifyingProperties Target attribute not present");
        }
    }
    String targetValue = targetAttr.getNodeValue();
    if (null == targetValue || !targetValue.startsWith("#") || !targetValue.substring(1).equals(signatureId)) {
        throw new QualifyingPropertiesIncorporationException("QualifyingProperties target doesn't match the signature's Id");
    }
    /* Unmarshal the qualifying properties */
    QualifPropsDataCollectorImpl propsDataCollector = new QualifPropsDataCollectorImpl();
    qualifPropsUnmarshaller.unmarshalProperties(qualifyingPropsElem, propsDataCollector);
    Collection<PropertyDataObject> qualifPropsData = propsDataCollector.getPropertiesData();
    /* Certification path */
    KeyInfoRes keyInfoRes = SignatureUtils.processKeyInfo(signature.getKeyInfo());
    Date validationDate = getValidationDate(qualifPropsData, signature, verificationOptions);
    ValidationData certValidationRes = this.certificateValidator.validate(keyInfoRes.certSelector, validationDate, keyInfoRes.keyInfoCerts);
    if (null == certValidationRes || certValidationRes.getCerts().isEmpty()) {
        throw new NullPointerException("Certificate validator returned null or empty data");
    }
    X509Certificate validationCert = certValidationRes.getCerts().get(0);
    /* Signature verification */
    // Core XML-DSIG verification.
    doCoreVerification(signature, verificationOptions, validationCert);
    // Create the properties verification context.
    QualifyingPropertyVerificationContext qPropsCtx = new QualifyingPropertyVerificationContext(signature, new QualifyingPropertyVerificationContext.CertificationChainData(certValidationRes.getCerts(), certValidationRes.getCrls(), keyInfoRes.issuerSerial), /**/
    new QualifyingPropertyVerificationContext.SignedObjectsData(referencesRes.dataObjsReferences, signature));
    // Verify the properties. Data structure verification is included.
    Collection<PropertyInfo> props = this.qualifyingPropertiesVerifier.verifyProperties(qualifPropsData, qPropsCtx);
    XAdESVerificationResult res = new XAdESVerificationResult(XAdESFormChecker.checkForm(props), signature, certValidationRes, props, referencesRes.dataObjsReferences);
    // Apply the custom signature verifiers.
    for (CustomSignatureVerifier customVer : this.customSigVerifiers) {
        customVer.verify(res, qPropsCtx);
    }
    return res;
}
Also used : ReferencesRes(xades4j.verification.SignatureUtils.ReferencesRes) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) KeyInfoRes(xades4j.verification.SignatureUtils.KeyInfoRes) XMLSignature(org.apache.xml.security.signature.XMLSignature) UnmarshalException(xades4j.xml.unmarshalling.UnmarshalException) PropertyDataObject(xades4j.properties.data.PropertyDataObject) RawSignatureVerifierContext(xades4j.verification.RawSignatureVerifier.RawSignatureVerifierContext) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate) ValidationData(xades4j.providers.ValidationData)

Example 4 with PropertyDataObject

use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.

the class QualifyingPropertiesVerifierImpl method verifyProperties.

@Override
public Collection<PropertyInfo> verifyProperties(Collection<PropertyDataObject> unmarshalledProperties, QualifyingPropertyVerificationContext ctx) throws PropertyDataStructureException, InvalidPropertyException, QualifyingPropertyVerifierNotAvailableException {
    dataObjectsStructureVerifier.verifiyPropertiesDataStructure(unmarshalledProperties);
    Collection<PropertyInfo> props = new ArrayList<PropertyInfo>(unmarshalledProperties.size());
    for (PropertyDataObject propData : unmarshalledProperties) {
        QualifyingPropertyVerifier<PropertyDataObject> propVerifier = this.propertyVerifiersMapper.getVerifier(propData);
        QualifyingProperty p = propVerifier.verify(propData, ctx);
        if (null == p)
            throw new PropertyVerifierErrorException(propData.getClass().getName());
        props.add(new PropertyInfo(propData, p));
    }
    return Collections.unmodifiableCollection(props);
}
Also used : ArrayList(java.util.ArrayList) PropertyDataObject(xades4j.properties.data.PropertyDataObject) QualifyingProperty(xades4j.properties.QualifyingProperty)

Example 5 with PropertyDataObject

use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.

the class ToXmlCommitmentTypeConverter method convertIntoObjectTree.

@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlSignedPropertiesType xmlProps, Document doc) {
    CommitmentTypeData commitmentTypeData = (CommitmentTypeData) propData;
    // Create the JAXB CommitmentTypeIndication and add it to SignedDataObjectProperties.
    XmlCommitmentTypeIndicationType xmlCommitmentTypeProp = new XmlCommitmentTypeIndicationType();
    xmlProps.getSignedDataObjectProperties().getCommitmentTypeIndication().add(xmlCommitmentTypeProp);
    XmlIdentifierType xmlIdentifier = new XmlIdentifierType();
    xmlIdentifier.setValue(commitmentTypeData.getUri());
    XmlObjectIdentifierType xmlObjectId = new XmlObjectIdentifierType();
    xmlObjectId.setDescription(commitmentTypeData.getDescription());
    xmlObjectId.setIdentifier(xmlIdentifier);
    xmlCommitmentTypeProp.setCommitmentTypeId(xmlObjectId);
    Collection<String> refsUris = commitmentTypeData.getObjReferences();
    if (null == refsUris) {
        xmlCommitmentTypeProp.setAllSignedDataObjects();
    } else {
        xmlCommitmentTypeProp.getObjectReference().addAll(refsUris);
    }
    Collection qualifiers = commitmentTypeData.getQualifiers();
    if (!qualifiers.isEmpty()) {
        XmlCommitmentTypeQualifiersListType xmlQualifiers = new XmlCommitmentTypeQualifiersListType();
        for (Object q : qualifiers) {
            XmlAnyType xmlQualifier = new XmlAnyType();
            xmlQualifier.getContent().add(q);
            xmlQualifiers.getCommitmentTypeQualifier().add(xmlQualifier);
        }
        xmlCommitmentTypeProp.setCommitmentTypeQualifiers(xmlQualifiers);
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) XmlIdentifierType(xades4j.xml.bind.xades.XmlIdentifierType) XmlCommitmentTypeIndicationType(xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType) XmlObjectIdentifierType(xades4j.xml.bind.xades.XmlObjectIdentifierType) XmlCommitmentTypeQualifiersListType(xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType) Collection(java.util.Collection) PropertyDataObject(xades4j.properties.data.PropertyDataObject) CommitmentTypeData(xades4j.properties.data.CommitmentTypeData)

Aggregations

PropertyDataObject (xades4j.properties.data.PropertyDataObject)8 Node (org.w3c.dom.Node)4 ArrayList (java.util.ArrayList)2 Element (org.w3c.dom.Element)2 QualifyingProperty (xades4j.properties.QualifyingProperty)2 X509Certificate (java.security.cert.X509Certificate)1 Collection (java.util.Collection)1 Date (java.util.Date)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 XMLSignature (org.apache.xml.security.signature.XMLSignature)1 Document (org.w3c.dom.Document)1 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)1 Algorithm (xades4j.algorithms.Algorithm)1 CommitmentTypeData (xades4j.properties.data.CommitmentTypeData)1 GenericDOMData (xades4j.properties.data.GenericDOMData)1 ValidationData (xades4j.providers.ValidationData)1 RawSignatureVerifierContext (xades4j.verification.RawSignatureVerifier.RawSignatureVerifierContext)1 KeyInfoRes (xades4j.verification.SignatureUtils.KeyInfoRes)1 ReferencesRes (xades4j.verification.SignatureUtils.ReferencesRes)1 XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)1