Search in sources :

Example 1 with DataObjectDesc

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

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

the class Enveloped method sign.

/**
 * Creates an enveloped signature over an element. The element must have an
 * Id or be the document root if it doesn't. In the last case an empty (URI="")
 * reference is used.
 *
 * @param elementToSign the element that will be signed and will be the signature's parent
 *
 * @throws XAdES4jException see {@link XadesSigner#sign(xades4j.production.SignedDataObjects, org.w3c.dom.Node)}
 * @throws IllegalArgumentException if {@code elementToSign} doesn't have an Id and isn't the document root
 */
public void sign(Element elementToSign) throws XAdES4jException {
    String refUri;
    if (elementToSign.hasAttribute("Id"))
        refUri = '#' + elementToSign.getAttribute("Id");
    else {
        if (elementToSign.getParentNode().getNodeType() != Node.DOCUMENT_NODE)
            throw new IllegalArgumentException("Element without Id must be the document root");
        refUri = "";
    }
    DataObjectDesc dataObjRef = new DataObjectReference(refUri).withTransform(new EnvelopedSignatureTransform());
    signer.sign(new SignedDataObjects(dataObjRef), elementToSign);
}
Also used : EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) DataObjectDesc(xades4j.properties.DataObjectDesc)

Example 3 with DataObjectDesc

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

the class QualifyingPropertiesProcessor method getQualifyingProperties.

QualifyingProperties getQualifyingProperties(SignedDataObjects dataObjs, Collection<SignedSignatureProperty> formatSpecificSignedSigProps, Collection<UnsignedSignatureProperty> formatSpecificUnsignedSigProps) {
    /* **** Signature properties **** */
    // Collect the signature properties from the provider.
    SignaturePropertiesCollectorImpl signaturePropsCollector = new SignaturePropertiesCollectorImpl();
    sigPropsProvider.provideProperties(signaturePropsCollector);
    Collection<SignedSignatureProperty> collectedSignedSigProps = signaturePropsCollector.getSignedSigProps();
    Collection<SignedSignatureProperty> signedSigProps = new ArrayList<SignedSignatureProperty>(collectedSignedSigProps.size() + formatSpecificSignedSigProps.size());
    signedSigProps.addAll(collectedSignedSigProps);
    signedSigProps.addAll(formatSpecificSignedSigProps);
    Collection<UnsignedSignatureProperty> collectedUnsignedSigProps = signaturePropsCollector.getUnsignedSigProps();
    Collection<UnsignedSignatureProperty> unsignedSigProps = new ArrayList<UnsignedSignatureProperty>(collectedUnsignedSigProps.size() + formatSpecificUnsignedSigProps.size());
    unsignedSigProps.addAll(collectedUnsignedSigProps);
    unsignedSigProps.addAll(formatSpecificUnsignedSigProps);
    /* **** Data objects properties **** */
    Collection<DataObjectDesc> dataObjsInfo = dataObjs.getDataObjectsDescs();
    // The containers for all the specified signed data object properties. Since
    // some properties can be applied to multiple data objects, we need to rule
    // out repeated references (a Set is used).
    Set<SignedDataObjectProperty> signedDataObjProps = new HashSet<SignedDataObjectProperty>(dataObjsInfo.size());
    Set<UnsignedDataObjectProperty> unsignedDataObjProps = new HashSet<UnsignedDataObjectProperty>(0);
    // Add the global data object properties.
    signedDataObjProps.addAll(dataObjs.getSignedDataObjsProperties());
    unsignedDataObjProps.addAll(dataObjs.getUnsignedDataObjsProperties());
    // Add the properties specified for each data object.
    for (DataObjectDesc dataObjInfo : dataObjsInfo) {
        // If no properties were specified allow the provider to add them.
        if (!dataObjInfo.hasProperties())
            this.dataObjPropsProvider.provideProperties(dataObjInfo);
        signedDataObjProps.addAll(dataObjInfo.getSignedDataObjProps());
        unsignedDataObjProps.addAll(dataObjInfo.getUnsignedDataObjProps());
    }
    return new QualifyingProperties(new SignedProperties(signedSigProps, signedDataObjProps), new UnsignedProperties(unsignedSigProps, unsignedDataObjProps));
}
Also used : UnsignedDataObjectProperty(xades4j.properties.UnsignedDataObjectProperty) QualifyingProperties(xades4j.properties.QualifyingProperties) SignedSignatureProperty(xades4j.properties.SignedSignatureProperty) ArrayList(java.util.ArrayList) DataObjectDesc(xades4j.properties.DataObjectDesc) SignedDataObjectProperty(xades4j.properties.SignedDataObjectProperty) UnsignedProperties(xades4j.properties.UnsignedProperties) SignedProperties(xades4j.properties.SignedProperties) UnsignedSignatureProperty(xades4j.properties.UnsignedSignatureProperty) HashSet(java.util.HashSet)

Example 4 with DataObjectDesc

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

the class DataGenIndivDataObjsTimeStamp method createPropDataObj.

@Override
protected BaseXAdESTimeStampData createPropDataObj(IndividualDataObjsTimeStampProperty prop, Algorithm c14n, TimeStampTokenRes tsTknRes, PropertiesDataGenerationContext ctx) {
    Collection<DataObjectDesc> targetDataObjs = prop.getTargetDataObjects();
    Map<DataObjectDesc, Reference> refsMaps = ctx.getReferencesMappings();
    List<String> includes = new ArrayList<String>(targetDataObjs.size());
    for (DataObjectDesc dataObj : targetDataObjs) {
        Reference r = refsMaps.get(dataObj);
        includes.add('#' + r.getId());
    }
    prop.setTime(tsTknRes.timeStampTime);
    return new IndividualDataObjsTimeStampData(c14n, includes, tsTknRes.encodedTimeStampToken);
}
Also used : Reference(org.apache.xml.security.signature.Reference) ArrayList(java.util.ArrayList) DataObjectDesc(xades4j.properties.DataObjectDesc) IndividualDataObjsTimeStampData(xades4j.properties.data.IndividualDataObjsTimeStampData)

Example 5 with DataObjectDesc

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

the class OtherSignerTests method testSignAndAppendAsFirstChild.

@Test
public void testSignAndAppendAsFirstChild() throws Exception {
    System.out.println("signAndAppendAsFirstChild");
    Document doc = getTestDocument();
    Element root = doc.getDocumentElement();
    XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).newSigner();
    DataObjectDesc obj1 = new DataObjectReference('#' + root.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform());
    SignedDataObjects dataObjs = new SignedDataObjects(obj1);
    signer.sign(dataObjs, root, SignatureAppendingStrategies.AsFirstChild);
    Element firstChild = (Element) doc.getDocumentElement().getFirstChild();
    assertEquals(Constants._TAG_SIGNATURE, firstChild.getLocalName());
    assertEquals(Constants.SignatureSpecNS, firstChild.getNamespaceURI());
}
Also used : Element(org.w3c.dom.Element) EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) Test(org.junit.Test)

Aggregations

DataObjectDesc (xades4j.properties.DataObjectDesc)16 Document (org.w3c.dom.Document)8 Reference (org.apache.xml.security.signature.Reference)7 Test (org.junit.Test)7 EnvelopedSignatureTransform (xades4j.algorithms.EnvelopedSignatureTransform)5 Element (org.w3c.dom.Element)4 DataObjectFormatProperty (xades4j.properties.DataObjectFormatProperty)4 ArrayList (java.util.ArrayList)3 ObjectContainer (org.apache.xml.security.signature.ObjectContainer)3 XMLSignature (org.apache.xml.security.signature.XMLSignature)3 IndividualDataObjsTimeStampProperty (xades4j.properties.IndividualDataObjsTimeStampProperty)3 XMLSignatureException (org.apache.xml.security.signature.XMLSignatureException)2 Transforms (org.apache.xml.security.transforms.Transforms)2 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)2 AllDataObjsCommitmentTypeProperty (xades4j.properties.AllDataObjsCommitmentTypeProperty)2 CommitmentTypeProperty (xades4j.properties.CommitmentTypeProperty)2 CounterSignatureProperty (xades4j.properties.CounterSignatureProperty)2 QualifyingProperties (xades4j.properties.QualifyingProperties)2 SignedSignatureProperty (xades4j.properties.SignedSignatureProperty)2 SignerRoleProperty (xades4j.properties.SignerRoleProperty)2