Search in sources :

Example 1 with GenericDOMData

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

the class DefaultVerificationBindingsModule method configure.

@Override
protected void configure() {
    bind(MessageDigestEngineProvider.class).to(DefaultMessageDigestProvider.class);
    bind(TimeStampVerificationProvider.class).to(DefaultTimeStampVerificationProvider.class);
    bind(SignaturePolicyDocumentProvider.class).toInstance(new SignaturePolicyDocumentProvider() {

        @Override
        public InputStream getSignaturePolicyDocumentStream(ObjectIdentifier sigPolicyId) {
            return null;
        }
    });
    // QualifyingPropertiesVerifier is not configurable but the individual
    // verifiers may have dependencies.
    bind(QualifyingPropertiesVerifier.class).to(QualifyingPropertiesVerifierImpl.class);
    bind(QualifyingPropertyVerifiersMapper.class).to(QualifyingPropertyVerifiersMapperImpl.class);
    // customGlobalStructureVerifiers.add(new CustomPropertiesDataObjsStructureVerifier()
    // {
    // @Override
    // public void verifiy(DataGetter<PropertyDataObject> dataObjsGetter) throws PropertyDataStructureException
    // {
    // if (dataObjsGetter.getOfType(SigningCertificateData.class).isEmpty())
    // throw new PropertyDataStructureException("property is required and isn't present", SigningCertificateProperty.PROP_NAME);
    // }
    // });
    // QualifyingPropertyVerifiersMapperImpl relies on the injector to get
    // the individual verifiers, so they need to be bound.
    // - SignedSignatureProperties
    bindBuiltInVerifier(SigningTimeData.class, SigningTimeVerifier.class);
    bindBuiltInVerifier(SignerRoleData.class, SignerRoleVerifier.class);
    bindBuiltInVerifier(SignatureProdPlaceData.class, SigProdPlaceVerifier.class);
    bindBuiltInVerifier(SigningCertificateData.class, SigningCertificateVerifier.class);
    bindBuiltInVerifier(SignaturePolicyData.class, SignaturePolicyVerifier.class);
    // - SignedDataObjectProperties
    bindBuiltInVerifier(CommitmentTypeData.class, CommitmentTypeVerifier.class);
    bindBuiltInVerifier(DataObjectFormatData.class, DataObjFormatVerifier.class);
    bindBuiltInVerifier(AllDataObjsTimeStampData.class, AllDataObjsTimeStampVerifier.class);
    bindBuiltInVerifier(IndividualDataObjsTimeStampData.class, IndivDataObjsTimeStampVerifier.class);
    // - UnsignedSignatureProperties
    bindBuiltInVerifier(SignatureTimeStampData.class, SignatureTimeStampVerifier.class);
    bindBuiltInVerifier(CompleteCertificateRefsData.class, CompleteCertRefsVerifier.class);
    bindBuiltInVerifier(CompleteRevocationRefsData.class, CompleteRevocRefsVerifier.class);
    MapBinder<QName, QualifyingPropertyVerifier> unkownElemsBinder = MapBinder.newMapBinder(binder(), QName.class, QualifyingPropertyVerifier.class);
    unkownElemsBinder.addBinding(new QName(QualifyingProperty.XADES_XMLNS, CounterSignatureProperty.PROP_NAME)).to(CounterSignatureVerifier.class);
    // Verification based on XML elements names.
    bind(new TypeLiteral<QualifyingPropertyVerifier<GenericDOMData>>() {
    }).to(GenericDOMDataVerifier.class);
    // Ensure empty sets when no bindings are defined
    Multibinder.newSetBinder(binder(), RawSignatureVerifier.class);
    Multibinder.newSetBinder(binder(), CustomSignatureVerifier.class);
    Multibinder.newSetBinder(binder(), CustomPropertiesDataObjsStructureVerifier.class);
}
Also used : TimeStampVerificationProvider(xades4j.providers.TimeStampVerificationProvider) DefaultTimeStampVerificationProvider(xades4j.providers.impl.DefaultTimeStampVerificationProvider) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) GenericDOMData(xades4j.properties.data.GenericDOMData) SignaturePolicyDocumentProvider(xades4j.providers.SignaturePolicyDocumentProvider) TypeLiteral(com.google.inject.TypeLiteral) MessageDigestEngineProvider(xades4j.providers.MessageDigestEngineProvider) ObjectIdentifier(xades4j.properties.ObjectIdentifier)

Example 2 with GenericDOMData

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

the class TestElemDOMVerifier method testVerify.

@Test
public void testVerify() throws Exception {
    GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem"));
    QualifyingPropertyVerificationContext ctx = null;
    GenericDOMDataVerifier instance = new GenericDOMDataVerifier(customElemVerifiers);
    QualifyingProperty result = instance.verify(propData, ctx);
    assertEquals(result.getName(), "Elem");
}
Also used : GenericDOMData(xades4j.properties.data.GenericDOMData) QualifyingProperty(xades4j.properties.QualifyingProperty) Test(org.junit.Test)

Example 3 with GenericDOMData

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

the class FromXmlUnknownUnsignedDataObjPropsConv method convertFromObjectTree.

@Override
public void convertFromObjectTree(XmlUnsignedDataObjectPropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
    for (XmlAnyType xmlUnsignedDtaObjProp : xmlProps.getUnsignedDataObjectProperty()) {
        // <xsd:complexType name="UnsignedDataObjectPropertiesType">
        // <xsd:sequence>
        // <xsd:element name="UnsignedDataObjectProperty" type="AnyType"
        // maxOccurs="unbounded"/>
        // </xsd:sequence>
        // <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
        // </xsd:complexType>
        // 
        // I assumed that there is only one "top" element inside UnsignedDataObjectProperty,
        // which is the property element. The AnyType schema allows for multiple
        // elements but since the UnsignedDataObjectProperty has to be present,
        // it makes sense that it has only one child.
        List<Element> propElemContent = CollectionUtils.filterByType(xmlUnsignedDtaObjProp.getContent(), Element.class);
        if (!this.acceptUnknown)
            throw new PropertyUnmarshalException("Unknown properties were found", "Unknown");
        if (propElemContent.size() > 1)
            throw new PropertyUnmarshalException("Multiple children elements in UnsignedDataObjectProperty", "Unknown");
        propertyDataCollector.addGenericDOMData(new GenericDOMData(propElemContent.get(0)));
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) Element(org.w3c.dom.Element) GenericDOMData(xades4j.properties.data.GenericDOMData)

Example 4 with GenericDOMData

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

the class DataGenCounterSig method generatePropertyData.

/*
     * XAdES section 7.2.4.2:
     * "The content of this property is a XMLDSIG or XAdES signature whose ds:SignedInfo
     * MUST contain one ds:Reference element referencing the ds:SignatureValue element
     * of the embedding and countersigned XAdES signature. The content of the ds:DigestValue
     * in the aforementioned ds:Reference element of the countersignature MUST be the
     * base-64 encoded digest of the complete (and canonicalized) ds:SignatureValue
     * element (i.e. including the starting and closing tags) of the embedding and
     * countersigned XAdES signature."
     */
/* The ds:Reference element described above can be obtained with the default
     * XML-DSIG behaviour. We just need to reference the ds:SignatureValue element.
     */
@Override
public PropertyDataObject generatePropertyData(CounterSignatureProperty prop, PropertiesDataGenerationContext ctx) throws PropertyDataGenerationException {
    // The element has to be in the document tree for the references to be
    // resolved. UGLY WORKAROUND.
    Element qPs = DOMHelper.getFirstDescendant(ctx.getTargetXmlSignature().getElement(), QualifyingProperty.XADES_XMLNS, QualifyingProperty.QUALIFYING_PROPS_TAG);
    // Create the CounterSignature property element.
    Element counterSigElem = ctx.createElementInSignatureDoc("CounterSignature", qPs.getPrefix(), QualifyingProperty.XADES_XMLNS);
    qPs.appendChild(counterSigElem);
    try {
        // Rerence to the ds:SignatureValue element. This assumes that the
        // QualifyingProperties are in the signature's document and that the
        // SignatureValue element has an Id.
        Element sigValueElem = DOMHelper.getFirstDescendant(ctx.getTargetXmlSignature().getElement(), Constants.SignatureSpecNS, Constants._TAG_SIGNATUREVALUE);
        String sigValueId = sigValueElem.getAttribute(Constants._ATT_ID);
        DataObjectReference sigValueRef = new DataObjectReference('#' + sigValueId).withType(CounterSignatureProperty.COUNTER_SIGNATURE_TYPE_URI);
        XadesSigner counterSigner = prop.getCounterSigSigner();
        if (null == counterSigner)
            throw new PropertyDataGenerationException(prop, "signer not specified");
        try {
            SignedDataObjects objs = prop.getSignedDataObjectsForCounterSig();
            if (null == objs)
                objs = new SignedDataObjects();
            objs.withSignedDataObject(sigValueRef);
            counterSigner.sign(objs, counterSigElem);
        } catch (XAdES4jException ex) {
            throw new PropertyDataGenerationException(prop, "cannot apply counter signature", ex);
        }
    } finally {
        qPs.removeChild(counterSigElem);
    }
    return new GenericDOMData(counterSigElem);
}
Also used : XAdES4jException(xades4j.XAdES4jException) Element(org.w3c.dom.Element) GenericDOMData(xades4j.properties.data.GenericDOMData)

Example 5 with GenericDOMData

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

the class TestElemDOMVerifier method testVerifyNoVerifier.

@Test(expected = InvalidPropertyException.class)
public void testVerifyNoVerifier() throws Exception {
    GenericDOMData propData = new GenericDOMData(testDocument.createElementNS("http://test.generic.dom", "Elem"));
    QualifyingPropertyVerificationContext ctx = null;
    GenericDOMDataVerifier instance = new GenericDOMDataVerifier(new HashMap<QName, QualifyingPropertyVerifier>(0));
    instance.verify(propData, ctx);
}
Also used : QName(javax.xml.namespace.QName) GenericDOMData(xades4j.properties.data.GenericDOMData) Test(org.junit.Test)

Aggregations

GenericDOMData (xades4j.properties.data.GenericDOMData)6 QName (javax.xml.namespace.QName)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 TypeLiteral (com.google.inject.TypeLiteral)1 InputStream (java.io.InputStream)1 Node (org.w3c.dom.Node)1 XAdES4jException (xades4j.XAdES4jException)1 ObjectIdentifier (xades4j.properties.ObjectIdentifier)1 QualifyingProperty (xades4j.properties.QualifyingProperty)1 PropertyDataObject (xades4j.properties.data.PropertyDataObject)1 MessageDigestEngineProvider (xades4j.providers.MessageDigestEngineProvider)1 SignaturePolicyDocumentProvider (xades4j.providers.SignaturePolicyDocumentProvider)1 TimeStampVerificationProvider (xades4j.providers.TimeStampVerificationProvider)1 DefaultTimeStampVerificationProvider (xades4j.providers.impl.DefaultTimeStampVerificationProvider)1 XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)1