Search in sources :

Example 11 with DataObjectDesc

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

the class DataGenIndivDataObjsTimeStamp method addPropSpecificTimeStampInput.

@Override
protected void addPropSpecificTimeStampInput(IndividualDataObjsTimeStampProperty prop, TimeStampDigestInput digestInput, PropertiesDataGenerationContext ctx) throws CannotAddDataToDigestInputException {
    Collection<DataObjectDesc> targetDataObjs = prop.getTargetDataObjects();
    Map<DataObjectDesc, Reference> refsMaps = ctx.getReferencesMappings();
    for (DataObjectDesc dataObj : targetDataObjs) {
        Reference r = refsMaps.get(dataObj);
        digestInput.addReference(r);
    }
}
Also used : Reference(org.apache.xml.security.signature.Reference) DataObjectDesc(xades4j.properties.DataObjectDesc)

Example 12 with DataObjectDesc

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

the class SignedDataObjectsProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    System.out.println("process");
    Document doc = getNewDocument();
    SignedDataObjects dataObjsDescs = new SignedDataObjects().withSignedDataObject(new DataObjectReference("uri").withTransform(new EnvelopedSignatureTransform())).withSignedDataObject(new EnvelopedXmlObject(doc.createElement("test1"))).withSignedDataObject(new EnvelopedXmlObject(doc.createElement("test2"), "text/xml", null));
    XMLSignature xmlSignature = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);
    xmlSignature.setId("sigId");
    AllwaysNullAlgsParamsMarshaller algsParamsMarshaller = new AllwaysNullAlgsParamsMarshaller();
    SignedDataObjectsProcessor processor = new SignedDataObjectsProcessor(new TestAlgorithmsProvider(), algsParamsMarshaller);
    Map<DataObjectDesc, Reference> result = processor.process(dataObjsDescs, xmlSignature);
    assertEquals(dataObjsDescs.getDataObjectsDescs().size(), result.size());
    assertEquals(2, xmlSignature.getObjectLength());
    assertEquals(xmlSignature.getSignedInfo().getLength(), dataObjsDescs.getDataObjectsDescs().size());
    assertEquals(1, algsParamsMarshaller.getInvokeCount());
    Reference ref = xmlSignature.getSignedInfo().item(0);
    assertEquals(1, ref.getTransforms().getLength());
    ObjectContainer obj = xmlSignature.getObjectItem(1);
    assertEquals("text/xml", obj.getMimeType());
    assertTrue(StringUtils.isNullOrEmptyString(obj.getEncoding()));
}
Also used : Reference(org.apache.xml.security.signature.Reference) EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) XMLSignature(org.apache.xml.security.signature.XMLSignature) ObjectContainer(org.apache.xml.security.signature.ObjectContainer) Test(org.junit.Test)

Example 13 with DataObjectDesc

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

the class SignedDataObjectsProcessorTest method testAddNullReference.

@Test
public void testAddNullReference() throws Exception {
    System.out.println("addNullReference");
    Document doc = SignatureServicesTestBase.getNewDocument();
    SignedDataObjects dataObjsDescs = new SignedDataObjects().withSignedDataObject(new AnonymousDataObjectReference("data".getBytes()));
    XMLSignature xmlSignature = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);
    xmlSignature.setId("sigId");
    SignedDataObjectsProcessor processor = new SignedDataObjectsProcessor(new TestAlgorithmsProvider(), new AllwaysNullAlgsParamsMarshaller());
    Map<DataObjectDesc, Reference> result = processor.process(dataObjsDescs, xmlSignature);
    assertEquals(1, result.size());
    assertEquals(0, xmlSignature.getObjectLength());
    assertEquals(1, xmlSignature.getSignedInfo().getLength());
    Reference r = xmlSignature.getSignedInfo().item(0);
    assertNull(r.getElement().getAttributeNodeNS(Constants.SignatureSpecNS, "URI"));
}
Also used : XMLSignature(org.apache.xml.security.signature.XMLSignature) Reference(org.apache.xml.security.signature.Reference) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) Test(org.junit.Test)

Example 14 with DataObjectDesc

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

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

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