Search in sources :

Example 1 with SignaturePolicyData

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

the class DataGenSigPolicy method generatePropertyData.

@Override
public PropertyDataObject generatePropertyData(SignaturePolicyIdentifierProperty prop, PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException {
    try {
        // Digest the policy document.
        String digestAlgUri = this.algorithmsProvider.getDigestAlgorithmForReferenceProperties();
        MessageDigest md = this.messageDigestProvider.getEngine(digestAlgUri);
        byte[] policyDigest = MessageDigestUtils.digestStream(md, prop.getPolicyDocumentStream());
        return new SignaturePolicyData(prop.getIdentifier(), digestAlgUri, policyDigest, prop.getLocationUrl());
    } catch (IOException ex) {
        throw new PropertyDataGenerationException(prop, "Cannot digest signature policy", ex);
    } catch (UnsupportedAlgorithmException ex) {
        throw new PropertyDataGenerationException(prop, ex.getMessage(), ex);
    }
}
Also used : UnsupportedAlgorithmException(xades4j.UnsupportedAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) SignaturePolicyData(xades4j.properties.data.SignaturePolicyData)

Example 2 with SignaturePolicyData

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

the class FromXmlSignaturePolicyConverter method convertFromObjectTree.

@Override
public void convertFromObjectTree(XmlSignedSignaturePropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
    XmlSignaturePolicyIdentifierType xmlSigPolicy = xmlProps.getSignaturePolicyIdentifier();
    if (null == xmlSigPolicy)
        return;
    if (xmlSigPolicy.getSignaturePolicyImplied() != null) {
        propertyDataCollector.setSignaturePolicy(new SignaturePolicyData());
        return;
    }
    XmlSignaturePolicyIdType xmlPolicyId = xmlSigPolicy.getSignaturePolicyId();
    if (xmlPolicyId.getTransforms() != null)
        throw new PropertyUnmarshalException("Signature policy transforms are not supported", SignaturePolicyBase.PROP_NAME);
    propertyDataCollector.setSignaturePolicy(new SignaturePolicyData(FromXmlUtils.getObjectIdentifier(xmlPolicyId.getSigPolicyId()), xmlPolicyId.getSigPolicyHash().getDigestMethod().getAlgorithm(), xmlPolicyId.getSigPolicyHash().getDigestValue(), getLocationUrl(xmlPolicyId)));
}
Also used : SignaturePolicyData(xades4j.properties.data.SignaturePolicyData) XmlSignaturePolicyIdType(xades4j.xml.bind.xades.XmlSignaturePolicyIdType) XmlSignaturePolicyIdentifierType(xades4j.xml.bind.xades.XmlSignaturePolicyIdentifierType)

Example 3 with SignaturePolicyData

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

the class ToXmlSignaturePolicyConverter method convertIntoObjectTree.

@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlSignedPropertiesType xmlProps, Document doc) {
    SignaturePolicyData sigPolicyData = (SignaturePolicyData) propData;
    XmlSignaturePolicyIdentifierType xmlSigPolicy = new XmlSignaturePolicyIdentifierType();
    if (null == sigPolicyData.getIdentifier()) {
        xmlSigPolicy.setSignaturePolicyImplied();
    } else {
        xmlSigPolicy.setSignaturePolicyId(getSignaturePolicy(sigPolicyData, doc));
    }
    xmlProps.getSignedSignatureProperties().setSignaturePolicyIdentifier(xmlSigPolicy);
}
Also used : SignaturePolicyData(xades4j.properties.data.SignaturePolicyData) XmlSignaturePolicyIdentifierType(xades4j.xml.bind.xades.XmlSignaturePolicyIdentifierType)

Aggregations

SignaturePolicyData (xades4j.properties.data.SignaturePolicyData)3 XmlSignaturePolicyIdentifierType (xades4j.xml.bind.xades.XmlSignaturePolicyIdentifierType)2 IOException (java.io.IOException)1 MessageDigest (java.security.MessageDigest)1 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)1 XmlSignaturePolicyIdType (xades4j.xml.bind.xades.XmlSignaturePolicyIdType)1