Search in sources :

Example 1 with DataObjectFormatProperty

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

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

the class DataObjFormatVerifier method verify.

@Override
public QualifyingProperty verify(DataObjectFormatData propData, QualifyingPropertyVerificationContext ctx) throws DataObjectFormatVerificationException {
    QualifyingPropertyVerificationContext.SignedObjectsData signedObjsData = ctx.getSignedObjectsData();
    String encoding = propData.getEncoding(), mimeType = propData.getMimeType();
    // XAdES G.2.2.8: "The verifier should check that the ObjectReference element
    // actually references one ds:Reference element from the signature."
    RawDataObjectDesc signedObj = signedObjsData.findSignedDataObject(propData.getObjectRef());
    if (null == signedObj)
        throw new DataObjectFormatReferenceException(propData.getObjectRef());
    // "In addition, should this property refer to a ds:Reference that in turn
    // refers to a ds:Object, the verifier should check the values of attributes
    // MimeType and Encoding (...)."
    Reference signedObjRef = signedObj.getReference();
    if (Reference.OBJECT_URI.equals(signedObjRef.getType())) {
        // Get the referenced Object.
        ObjectContainer signedObjObj = signedObjsData.findXMLObject(signedObjRef.getURI());
        if (null == signedObjObj)
            throw new DataObjectFormatReferenceException(signedObjRef.getURI());
        String objEncoding = signedObjObj.getEncoding(), objMimeType = signedObjObj.getMimeType();
        // Compare 'encoding' and 'mimeType', if present on both.
        if (StringUtils.differentStringsIfNotNullNorEmpty(objEncoding, encoding) || StringUtils.differentStringsIfNotNullNorEmpty(objMimeType, mimeType))
            throw new DataObjectFormatMismatchException(mimeType, encoding, signedObjRef, signedObjObj);
    }
    // Create the property.
    DataObjectFormatProperty formatProp = new DataObjectFormatProperty(mimeType, encoding);
    formatProp.withDescription(propData.getDescription());
    Collection<String> docsUris = propData.getDocumentationUris();
    if (docsUris != null)
        formatProp.withDocumentationUris(docsUris);
    formatProp.withIdentifier(propData.getIdentifier());
    // Associate the property to the data object.
    signedObj.withDataObjectFormat(formatProp);
    return formatProp;
}
Also used : Reference(org.apache.xml.security.signature.Reference) DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) ObjectContainer(org.apache.xml.security.signature.ObjectContainer)

Example 3 with DataObjectFormatProperty

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

the class PropertiesBagTest method testPut.

// @Test
// public void jaxbTest() throws Exception
// {
// 
// DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
// fac.setNamespaceAware(true);
// Document doc = fac.newDocumentBuilder().parse(new FileInputStream(".\\src\\test\\resources\\dummy.xml"));
// 
// // Create the JAXB unmarshaller.
// JAXBContext jaxbContext = JAXBContext.newInstance(XmlQualifyingPropertiesType.class);
// // Create the JAXB unmarshaller and unmarshalProperties the root JAXB element
// Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// ValidationEventCollector col = new ValidationEventCollector();
// unmarshaller.setEventHandler(col);
// JAXBElement<XmlQualifyingPropertiesType> qualifPropsElem = (JAXBElement<XmlQualifyingPropertiesType>)unmarshaller.unmarshal(doc.getDocumentElement());
// 
// //int size = qualifPropsElem.getValue().getUnsignedProperties().getUnsignedDataObjectProperties().getUnsignedDataObjectProperty().size();
// 
// Calendar c = qualifPropsElem.getValue().getSignedProperties().getSignedSignatureProperties().getSigningTime();
// 
// XmlCertIDListType certs = qualifPropsElem.getValue().getSignedProperties().getSignedSignatureProperties().getSigningCertificate();
// Object iss = certs.getCert().get(0).getIssuerSerial();
// if (null == iss)
// System.out.println("WAS NULL");
// }
/**
 * Test of put method, of class PropertiesSet.
 */
@Test(expected = IllegalStateException.class)
public void testPut() {
    System.out.println("put");
    SigningTimeProperty prop1 = new SigningTimeProperty(), prop2 = new SigningTimeProperty();
    DataObjectFormatProperty prop3 = new DataObjectFormatProperty();
    PropertiesSet instance = new PropertiesSet(2);
    instance.put(prop1);
    instance.put(prop3);
    instance.put(prop2);
}
Also used : SigningTimeProperty(xades4j.properties.SigningTimeProperty) DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) Test(org.junit.Test)

Example 4 with DataObjectFormatProperty

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

the class SignerBESTest method testSignBESDetachedWithXPathAndNamespaces.

@Test
public void testSignBESDetachedWithXPathAndNamespaces() throws Exception {
    System.out.println("signBESDetachedWithXPathAndNamespaces");
    Document doc = getNewDocument();
    XadesSigner signer = new XadesBesSigningProfile(keyingProviderMy).withBasicSignatureOptionsProvider(MyBasicSignatureOptionsProvider.class).newSigner();
    DataObjectDesc obj1 = new DataObjectReference("document.xml").withTransform(new XPathTransform("/collection/album/foo:tracks").withNamespace("foo", "http://test.xades4j/tracks")).withDataObjectFormat(new DataObjectFormatProperty("text/xml"));
    DataObjectDesc obj2 = new DataObjectReference("document.xml").withTransform(XPath2Filter.intersect("/collection/album/bar:tracks/bar:song[@tracknumber = 1]").withNamespace("bar", "http://test.xades4j/tracks"));
    SignedDataObjects objs = new SignedDataObjects(obj1, obj2).withBaseUri(new File("src/test/xml/").toURI().toString());
    signer.sign(objs, doc);
    outputDocument(doc, "detached.bes.xml");
}
Also used : DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) XPathTransform(xades4j.algorithms.XPathTransform) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) File(java.io.File) Test(org.junit.Test)

Example 5 with DataObjectFormatProperty

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

the class SignerBESTest method testSignBESExtrnlRes.

@Test
public void testSignBESExtrnlRes() throws Exception {
    System.out.println("signBESExtrnlRes");
    Document doc = getNewDocument();
    SignerBES signer = (SignerBES) new XadesBesSigningProfile(keyingProviderNist).newSigner();
    DataObjectDesc obj1 = new DataObjectReference("rfc3161.txt").withDataObjectFormat(new DataObjectFormatProperty("text/plain").withDescription("Internet X.509 Public Key Infrastructure Time-Stamp Protocol (TSP)")).withDataObjectTimeStamp(new IndividualDataObjsTimeStampProperty());
    signer.sign(new SignedDataObjects(obj1).withBaseUri("http://www.ietf.org/rfc/"), doc);
    outputDocument(doc, "document.signed.bes.extres.xml");
}
Also used : DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) IndividualDataObjsTimeStampProperty(xades4j.properties.IndividualDataObjsTimeStampProperty) Test(org.junit.Test)

Aggregations

DataObjectFormatProperty (xades4j.properties.DataObjectFormatProperty)6 Test (org.junit.Test)4 DataObjectDesc (xades4j.properties.DataObjectDesc)4 Document (org.w3c.dom.Document)3 IndividualDataObjsTimeStampProperty (xades4j.properties.IndividualDataObjsTimeStampProperty)3 AllDataObjsCommitmentTypeProperty (xades4j.properties.AllDataObjsCommitmentTypeProperty)2 CommitmentTypeProperty (xades4j.properties.CommitmentTypeProperty)2 SigningTimeProperty (xades4j.properties.SigningTimeProperty)2 TypeLiteral (com.google.inject.TypeLiteral)1 File (java.io.File)1 ObjectContainer (org.apache.xml.security.signature.ObjectContainer)1 Reference (org.apache.xml.security.signature.Reference)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 EnvelopedSignatureTransform (xades4j.algorithms.EnvelopedSignatureTransform)1 XPathTransform (xades4j.algorithms.XPathTransform)1 AllDataObjsTimeStampProperty (xades4j.properties.AllDataObjsTimeStampProperty)1 ArchiveTimeStampProperty (xades4j.properties.ArchiveTimeStampProperty)1 CertificateValuesProperty (xades4j.properties.CertificateValuesProperty)1 CompleteCertificateRefsProperty (xades4j.properties.CompleteCertificateRefsProperty)1