Search in sources :

Example 1 with ObjectIdentifier

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

use of xades4j.properties.ObjectIdentifier in project xades4j by luisgoncalves.

the class SignaturePolicyDataStructureVerifier method verifyStructure.

@Override
public void verifyStructure(PropertyDataObject propData) throws PropertyDataStructureException {
    SignaturePolicyData sigPolicyData = (SignaturePolicyData) propData;
    String alg = sigPolicyData.getDigestAlgorithm();
    byte[] dig = sigPolicyData.getDigestValue();
    ObjectIdentifier id = sigPolicyData.getIdentifier();
    if (!ObjectUtils.allNull(alg, dig, id) && ObjectUtils.anyNull(alg, dig, id))
        throw new PropertyDataStructureException("all the properties must be specified", SignaturePolicyIdentifierProperty.PROP_NAME);
}
Also used : ObjectIdentifier(xades4j.properties.ObjectIdentifier)

Example 3 with ObjectIdentifier

use of xades4j.properties.ObjectIdentifier in project xades4j by luisgoncalves.

the class SignerEPESTest method testSignEPES.

@Test
public void testSignEPES() throws Exception {
    System.out.printf("signEPES: %s", locationUrl);
    System.out.println();
    Document doc = getTestDocument();
    Element elemToSign = doc.getDocumentElement();
    SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider() {

        @Override
        public SignaturePolicyBase getSignaturePolicy() {
            return new SignaturePolicyIdentifierProperty(new ObjectIdentifier("oid:/1.2.4.0.9.4.5", IdentifierType.OIDAsURI, "Policy description"), new ByteArrayInputStream("Test policy input stream".getBytes())).withLocationUrl(locationUrl);
        }
    };
    SignerEPES signer = (SignerEPES) new XadesEpesSigningProfile(keyingProviderMy, policyInfoProvider).newSigner();
    new Enveloped(signer).sign(elemToSign);
    outputDocument(doc, output);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SignaturePolicyInfoProvider(xades4j.providers.SignaturePolicyInfoProvider) Element(org.w3c.dom.Element) SignaturePolicyIdentifierProperty(xades4j.properties.SignaturePolicyIdentifierProperty) Document(org.w3c.dom.Document) ObjectIdentifier(xades4j.properties.ObjectIdentifier) Test(org.junit.Test)

Example 4 with ObjectIdentifier

use of xades4j.properties.ObjectIdentifier in project xades4j by luisgoncalves.

the class SignaturePolicyVerifier method verify.

@Override
public QualifyingProperty verify(SignaturePolicyData propData, QualifyingPropertyVerificationContext ctx) throws SignaturePolicyVerificationException {
    ObjectIdentifier policyId = propData.getIdentifier();
    if (null == policyId) {
        return new SignaturePolicyImpliedProperty();
    }
    // Get the policy document
    InputStream sigDocStream = this.policyDocumentProvider.getSignaturePolicyDocumentStream(policyId);
    if (null == sigDocStream) {
        throw new SignaturePolicyNotAvailableException(policyId, null);
    }
    try {
        MessageDigest md = this.messageDigestProvider.getEngine(propData.getDigestAlgorithm());
        byte[] sigDocDigest = MessageDigestUtils.digestStream(md, sigDocStream);
        // Check the document digest.
        if (!Arrays.equals(sigDocDigest, propData.getDigestValue())) {
            throw new SignaturePolicyDigestMismatchException(policyId);
        }
        return new SignaturePolicyIdentifierProperty(policyId, sigDocStream).withLocationUrl(propData.getLocationUrl());
    } catch (IOException ex) {
        throw new SignaturePolicyNotAvailableException(policyId, ex);
    } catch (UnsupportedAlgorithmException ex) {
        throw new SignaturePolicyCannotDigestException(policyId, ex);
    } finally {
        try {
            sigDocStream.close();
        } catch (IOException ex) {
            throw new SignaturePolicyNotAvailableException(policyId, ex);
        }
    }
}
Also used : InputStream(java.io.InputStream) SignaturePolicyIdentifierProperty(xades4j.properties.SignaturePolicyIdentifierProperty) UnsupportedAlgorithmException(xades4j.UnsupportedAlgorithmException) SignaturePolicyImpliedProperty(xades4j.properties.SignaturePolicyImpliedProperty) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) ObjectIdentifier(xades4j.properties.ObjectIdentifier)

Example 5 with ObjectIdentifier

use of xades4j.properties.ObjectIdentifier in project xades4j by luisgoncalves.

the class ToXmlDataObjectFormatConverter method getXmlObjId.

private XmlObjectIdentifierType getXmlObjId(DataObjectFormatData dataObjFormatData) {
    ObjectIdentifier identifier = dataObjFormatData.getIdentifier();
    if (null == identifier)
        return null;
    XmlObjectIdentifierType xmlObjId = ToXmlUtils.getXmlObjectId(identifier);
    // Documentation references
    Collection<String> docsUris = dataObjFormatData.getDocumentationUris();
    if (docsUris != null && !docsUris.isEmpty()) {
        XmlDocumentationReferencesType docRefs = new XmlDocumentationReferencesType();
        docRefs.getDocumentationReference().addAll(docsUris);
        xmlObjId.setDocumentationReferences(docRefs);
    }
    return xmlObjId;
}
Also used : XmlDocumentationReferencesType(xades4j.xml.bind.xades.XmlDocumentationReferencesType) XmlObjectIdentifierType(xades4j.xml.bind.xades.XmlObjectIdentifierType) ObjectIdentifier(xades4j.properties.ObjectIdentifier)

Aggregations

ObjectIdentifier (xades4j.properties.ObjectIdentifier)5 InputStream (java.io.InputStream)2 SignaturePolicyIdentifierProperty (xades4j.properties.SignaturePolicyIdentifierProperty)2 TypeLiteral (com.google.inject.TypeLiteral)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MessageDigest (java.security.MessageDigest)1 QName (javax.xml.namespace.QName)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)1 SignaturePolicyImpliedProperty (xades4j.properties.SignaturePolicyImpliedProperty)1 GenericDOMData (xades4j.properties.data.GenericDOMData)1 MessageDigestEngineProvider (xades4j.providers.MessageDigestEngineProvider)1 SignaturePolicyDocumentProvider (xades4j.providers.SignaturePolicyDocumentProvider)1 SignaturePolicyInfoProvider (xades4j.providers.SignaturePolicyInfoProvider)1 TimeStampVerificationProvider (xades4j.providers.TimeStampVerificationProvider)1 DefaultTimeStampVerificationProvider (xades4j.providers.impl.DefaultTimeStampVerificationProvider)1 XmlDocumentationReferencesType (xades4j.xml.bind.xades.XmlDocumentationReferencesType)1