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);
}
}
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()));
}
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"));
}
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");
}
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");
}
Aggregations