Search in sources :

Example 1 with CounterSignatureProperty

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

the class DefaultProductionBindingsModule method configure.

@Override
protected void configure() {
    // Defaults for configurable components.
    bind(SignaturePropertiesProvider.class).to(DefaultSignaturePropertiesProvider.class);
    bind(DataObjectPropertiesProvider.class).toInstance(new DataObjectPropertiesProvider() {

        @Override
        public void provideProperties(DataObjectDesc dataObj) {
        // By default no properties are specified for a data object.
        }
    });
    bind(AlgorithmsProviderEx.class).to(DefaultAlgorithmsProviderEx.class);
    // Will wrap the AlgorithmsProviderEx in use
    bind(AlgorithmsProvider.class).to(AlgorithmsProvider_ExToDeprecated_Adapter.class);
    bind(BasicSignatureOptionsProvider.class).to(DefaultBasicSignatureOptionsProvider.class);
    bind(MessageDigestEngineProvider.class).to(DefaultMessageDigestProvider.class);
    bind(TimeStampTokenProvider.class).to(HttpTimeStampTokenProvider.class);
    // Backwards compatibility
    bind(TSAHttpData.class).toInstance(new TSAHttpData("http://tss.accv.es:8318/tsa"));
    // PropertiesDataObjectsGenerator is not configurable but the individual
    // generators may have dependencies.
    bind(PropertiesDataObjectsGenerator.class).to(PropertiesDataObjectsGeneratorImpl.class);
    bind(PropertyDataGeneratorsMapper.class).to(PropertyDataGeneratorsMapperImpl.class);
    // Ensure empty set when no bindings are defined
    Multibinder.newSetBinder(binder(), CustomPropertiesDataObjsStructureVerifier.class);
    // PropertyDataGeneratorsMapperImpl relies on the injector to get
    // the individual generators, so they need to be bound.
    // - SignedSignatureProperties
    bind(new TypeLiteral<PropertyDataObjectGenerator<SigningTimeProperty>>() {
    }).to(DataGenSigningTime.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SignerRoleProperty>>() {
    }).to(DataGenSignerRole.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SigningCertificateProperty>>() {
    }).to(DataGenSigningCertificate.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SignatureProductionPlaceProperty>>() {
    }).to(DataGenSigProdPlace.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SignaturePolicyIdentifierProperty>>() {
    }).to(DataGenSigPolicy.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SignaturePolicyImpliedProperty>>() {
    }).to(DataGenSigPolicyImplied.class);
    // - SignedDataObjectProperties
    bind(new TypeLiteral<PropertyDataObjectGenerator<DataObjectFormatProperty>>() {
    }).to(DataGenDataObjFormat.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<CommitmentTypeProperty>>() {
    }).to(DataGenCommitmentType.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<AllDataObjsCommitmentTypeProperty>>() {
    }).to(DataGenCommitmentTypeAllDataObjs.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<IndividualDataObjsTimeStampProperty>>() {
    }).to(DataGenIndivDataObjsTimeStamp.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<AllDataObjsTimeStampProperty>>() {
    }).to(DataGenAllDataObjsTimeStamp.class);
    // - UnsignedSignatureProperties
    bind(new TypeLiteral<PropertyDataObjectGenerator<CounterSignatureProperty>>() {
    }).to(DataGenCounterSig.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SignatureTimeStampProperty>>() {
    }).to(DataGenSigTimeStamp.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<CompleteCertificateRefsProperty>>() {
    }).to(DataGenCompleteCertRefs.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<CompleteRevocationRefsProperty>>() {
    }).to(DataGenCompleteRevocRefs.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<SigAndRefsTimeStampProperty>>() {
    }).to(DataGenSigAndRefsTimeStamp.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<CertificateValuesProperty>>() {
    }).to(DataGenCertificateValues.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<RevocationValuesProperty>>() {
    }).to(DataGenRevocationValues.class);
    bind(new TypeLiteral<PropertyDataObjectGenerator<ArchiveTimeStampProperty>>() {
    }).to(DataGenArchiveTimeStamp.class);
}
Also used : DefaultAlgorithmsProviderEx(xades4j.providers.impl.DefaultAlgorithmsProviderEx) AlgorithmsProviderEx(xades4j.providers.AlgorithmsProviderEx) SignaturePolicyIdentifierProperty(xades4j.properties.SignaturePolicyIdentifierProperty) SigAndRefsTimeStampProperty(xades4j.properties.SigAndRefsTimeStampProperty) TSAHttpData(xades4j.providers.impl.TSAHttpData) SigningCertificateProperty(xades4j.properties.SigningCertificateProperty) CompleteCertificateRefsProperty(xades4j.properties.CompleteCertificateRefsProperty) DefaultSignaturePropertiesProvider(xades4j.providers.impl.DefaultSignaturePropertiesProvider) SignaturePropertiesProvider(xades4j.providers.SignaturePropertiesProvider) DataObjectDesc(xades4j.properties.DataObjectDesc) RevocationValuesProperty(xades4j.properties.RevocationValuesProperty) SignatureProductionPlaceProperty(xades4j.properties.SignatureProductionPlaceProperty) TypeLiteral(com.google.inject.TypeLiteral) CertificateValuesProperty(xades4j.properties.CertificateValuesProperty) MessageDigestEngineProvider(xades4j.providers.MessageDigestEngineProvider) AllDataObjsCommitmentTypeProperty(xades4j.properties.AllDataObjsCommitmentTypeProperty) CommitmentTypeProperty(xades4j.properties.CommitmentTypeProperty) DataObjectPropertiesProvider(xades4j.providers.DataObjectPropertiesProvider) SignatureTimeStampProperty(xades4j.properties.SignatureTimeStampProperty) AlgorithmsProvider(xades4j.providers.AlgorithmsProvider) AllDataObjsTimeStampProperty(xades4j.properties.AllDataObjsTimeStampProperty) ArchiveTimeStampProperty(xades4j.properties.ArchiveTimeStampProperty) SigningTimeProperty(xades4j.properties.SigningTimeProperty) SignerRoleProperty(xades4j.properties.SignerRoleProperty) SignaturePolicyImpliedProperty(xades4j.properties.SignaturePolicyImpliedProperty) DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) TimeStampTokenProvider(xades4j.providers.TimeStampTokenProvider) HttpTimeStampTokenProvider(xades4j.providers.impl.HttpTimeStampTokenProvider) AllDataObjsCommitmentTypeProperty(xades4j.properties.AllDataObjsCommitmentTypeProperty) CompleteRevocationRefsProperty(xades4j.properties.CompleteRevocationRefsProperty) CounterSignatureProperty(xades4j.properties.CounterSignatureProperty) DefaultBasicSignatureOptionsProvider(xades4j.providers.impl.DefaultBasicSignatureOptionsProvider) BasicSignatureOptionsProvider(xades4j.providers.BasicSignatureOptionsProvider) IndividualDataObjsTimeStampProperty(xades4j.properties.IndividualDataObjsTimeStampProperty)

Example 2 with CounterSignatureProperty

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

the class CounterSignatureVerifier method verify.

@Override
public QualifyingProperty verify(GenericDOMData propData, QualifyingPropertyVerificationContext ctx) throws InvalidPropertyException {
    XAdESVerificationResult res;
    try {
        Element sigElem = DOMHelper.getFirstChildElement(propData.getPropertyElement());
        res = verifier.verify(sigElem, null);
    } catch (XAdES4jException ex) {
        throw new CounterSignatureXadesVerificationException(ex);
    }
    // "Check that the enclosed signature correctly references the ds:SignatureValue
    // present in the countersigned XAdES signature."
    Node targetSigValueElem = ctx.getSignature().getElement().getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATUREVALUE).item(0);
    try {
        SignedInfo si = res.getXmlSignature().getSignedInfo();
        for (int i = 0; i < si.getLength(); i++) {
            Reference r = si.item(i);
            if (r.getContentsAfterTransformation().getSubNode() == targetSigValueElem)
                // The signature references the SignatureValue element.
                return new CounterSignatureProperty(res);
        }
        throw new CounterSignatureSigValueRefException();
    } catch (XMLSecurityException e) {
        // Shouldn't happen because the signature was already verified.
        throw new CounterSignatureVerificationException(e);
    }
}
Also used : XAdES4jException(xades4j.XAdES4jException) Reference(org.apache.xml.security.signature.Reference) CounterSignatureProperty(xades4j.properties.CounterSignatureProperty) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) SignedInfo(org.apache.xml.security.signature.SignedInfo)

Example 3 with CounterSignatureProperty

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

the class SignerBESTest method testSignBESWithCounterSig.

@Test
public void testSignBESWithCounterSig() throws Exception {
    System.out.println("signBESWithCounterSig");
    Document doc = getTestDocument();
    Element elemToSign = doc.getDocumentElement();
    XadesBesSigningProfile profile = new XadesBesSigningProfile(keyingProviderMy);
    final XadesSigner counterSigner = profile.newSigner();
    profile.withSignaturePropertiesProvider(new SignaturePropertiesProvider() {

        @Override
        public void provideProperties(SignaturePropertiesCollector signedPropsCol) {
            signedPropsCol.addCounterSignature(new CounterSignatureProperty(counterSigner));
            signedPropsCol.setSignerRole(new SignerRoleProperty("CounterSignature maniac"));
        }
    });
    SignerBES signer = (SignerBES) profile.newSigner();
    DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform());
    SignedDataObjects dataObjs = new SignedDataObjects().withSignedDataObject(obj1);
    signer.sign(dataObjs, elemToSign);
    outputDocument(doc, "document.signed.bes.cs.xml");
}
Also used : Element(org.w3c.dom.Element) SignerRoleProperty(xades4j.properties.SignerRoleProperty) SignaturePropertiesCollector(xades4j.providers.SignaturePropertiesCollector) EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) Document(org.w3c.dom.Document) SignaturePropertiesProvider(xades4j.providers.SignaturePropertiesProvider) DataObjectDesc(xades4j.properties.DataObjectDesc) CounterSignatureProperty(xades4j.properties.CounterSignatureProperty) Test(org.junit.Test)

Example 4 with CounterSignatureProperty

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

the class XadesSignatureFormatExtenderImplTest method testEnrichSignatureWithNestedCounterSig.

@Test
public void testEnrichSignatureWithNestedCounterSig() throws Exception {
    System.out.println("enrichSignatureWithNestedCounterSig");
    Document doc = getDocument("document.signed.bes.cs.xml");
    NodeList signatures = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
    // Existing counter signature is the last
    Element signatureNode = (Element) signatures.item(signatures.getLength() - 1);
    XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner();
    XadesSignatureFormatExtender extender = new XadesFormatExtenderProfile().getFormatExtender();
    XMLSignature sig = new XMLSignature(signatureNode, signatureNode.getOwnerDocument().getBaseURI());
    Collection<UnsignedSignatureProperty> usp = new ArrayList<UnsignedSignatureProperty>(1);
    usp.add(new CounterSignatureProperty(signer));
    extender.enrichSignature(sig, new UnsignedProperties(usp));
    outputDocument(doc, "document.signed.bes.cs.cs.xml");
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) UnsignedProperties(xades4j.properties.UnsignedProperties) XMLSignature(org.apache.xml.security.signature.XMLSignature) CounterSignatureProperty(xades4j.properties.CounterSignatureProperty) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) Test(org.junit.Test)

Aggregations

CounterSignatureProperty (xades4j.properties.CounterSignatureProperty)4 Element (org.w3c.dom.Element)3 Test (org.junit.Test)2 Document (org.w3c.dom.Document)2 DataObjectDesc (xades4j.properties.DataObjectDesc)2 SignerRoleProperty (xades4j.properties.SignerRoleProperty)2 SignaturePropertiesProvider (xades4j.providers.SignaturePropertiesProvider)2 TypeLiteral (com.google.inject.TypeLiteral)1 ArrayList (java.util.ArrayList)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 XMLSignature (org.apache.xml.security.signature.XMLSignature)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 XAdES4jException (xades4j.XAdES4jException)1 EnvelopedSignatureTransform (xades4j.algorithms.EnvelopedSignatureTransform)1 AllDataObjsCommitmentTypeProperty (xades4j.properties.AllDataObjsCommitmentTypeProperty)1 AllDataObjsTimeStampProperty (xades4j.properties.AllDataObjsTimeStampProperty)1 ArchiveTimeStampProperty (xades4j.properties.ArchiveTimeStampProperty)1