List of usage examples for javax.xml.crypto.dsig XMLSignatureFactory newSignatureProperties
public abstract SignatureProperties newSignatureProperties(List<? extends SignatureProperty> properties, String id);
SignatureProperties
containing the specified list of SignatureProperty s and optional id. From source file:be.fedict.eid.applet.service.signer.odf.OpenOfficeSignatureFacet.java
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { LOG.debug("pre sign"); Element dateElement = document.createElementNS("", "dc:date"); dateElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:dc", "http://purl.org/dc/elements/1.1/"); DateTime dateTime = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); String now = fmt.print(dateTime); now = now.substring(0, now.indexOf("Z")); LOG.debug("now: " + now); dateElement.setTextContent(now);/*from w w w . j av a2 s .co m*/ String signaturePropertyId = "sign-prop-" + UUID.randomUUID().toString(); List<XMLStructure> signaturePropertyContent = new LinkedList<XMLStructure>(); signaturePropertyContent.add(new DOMStructure(dateElement)); SignatureProperty signatureProperty = signatureFactory.newSignatureProperty(signaturePropertyContent, "#" + signatureId, signaturePropertyId); List<XMLStructure> objectContent = new LinkedList<XMLStructure>(); List<SignatureProperty> signaturePropertiesContent = new LinkedList<SignatureProperty>(); signaturePropertiesContent.add(signatureProperty); SignatureProperties signatureProperties = signatureFactory .newSignatureProperties(signaturePropertiesContent, null); objectContent.add(signatureProperties); objects.add(signatureFactory.newXMLObject(objectContent, null, null, null)); DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); Reference reference = signatureFactory.newReference("#" + signaturePropertyId, digestMethod); references.add(reference); }
From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureFacet.java
private void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<XMLStructure> objectContent) { /*/* w w w . j a v a 2 s. c o m*/ * SignatureTime */ Element signatureTimeElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:SignatureTime"); signatureTimeElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi", OOXML_DIGSIG_NS); Element formatElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:Format"); formatElement.setTextContent("YYYY-MM-DDThh:mm:ssTZD"); signatureTimeElement.appendChild(formatElement); Element valueElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:Value"); Date now = this.clock.getTime(); DateTime dateTime = new DateTime(now.getTime(), DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); String nowStr = fmt.print(dateTime); LOG.debug("now: " + nowStr); valueElement.setTextContent(nowStr); signatureTimeElement.appendChild(valueElement); List<XMLStructure> signatureTimeContent = new LinkedList<XMLStructure>(); signatureTimeContent.add(new DOMStructure(signatureTimeElement)); SignatureProperty signatureTimeSignatureProperty = signatureFactory .newSignatureProperty(signatureTimeContent, "#" + signatureId, "idSignatureTime"); List<SignatureProperty> signaturePropertyContent = new LinkedList<SignatureProperty>(); signaturePropertyContent.add(signatureTimeSignatureProperty); SignatureProperties signatureProperties = signatureFactory.newSignatureProperties(signaturePropertyContent, "id-signature-time-" + UUID.randomUUID().toString()); objectContent.add(signatureProperties); }
From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureFacet.java
private void addSignatureInfo(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { List<XMLStructure> objectContent = new LinkedList<XMLStructure>(); Element signatureInfoElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureInfoV1"); signatureInfoElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", OFFICE_DIGSIG_NS); Element setupIDElement = document.createElementNS(OFFICE_DIGSIG_NS, "SetupID"); signatureInfoElement.appendChild(setupIDElement); Element signatureTextElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureText"); signatureInfoElement.appendChild(signatureTextElement); Element signatureImageElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureImage"); signatureInfoElement.appendChild(signatureImageElement); Element signatureCommentsElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureComments"); signatureInfoElement.appendChild(signatureCommentsElement); Element windowsVersionElement = document.createElementNS(OFFICE_DIGSIG_NS, "WindowsVersion"); windowsVersionElement.setTextContent("6.1"); signatureInfoElement.appendChild(windowsVersionElement); Element officeVersionElement = document.createElementNS(OFFICE_DIGSIG_NS, "OfficeVersion"); officeVersionElement.setTextContent("15.0"); signatureInfoElement.appendChild(officeVersionElement); Element applicationVersionElement = document.createElementNS(OFFICE_DIGSIG_NS, "ApplicationVersion"); applicationVersionElement.setTextContent("15.0"); signatureInfoElement.appendChild(applicationVersionElement); Element monitorsElement = document.createElementNS(OFFICE_DIGSIG_NS, "Monitors"); monitorsElement.setTextContent("1"); signatureInfoElement.appendChild(monitorsElement); Element horizontalResolutionElement = document.createElementNS(OFFICE_DIGSIG_NS, "HorizontalResolution"); horizontalResolutionElement.setTextContent("1366"); signatureInfoElement.appendChild(horizontalResolutionElement); Element verticalResolutionElement = document.createElementNS(OFFICE_DIGSIG_NS, "VerticalResolution"); verticalResolutionElement.setTextContent("768"); signatureInfoElement.appendChild(verticalResolutionElement); Element colorDepthElement = document.createElementNS(OFFICE_DIGSIG_NS, "ColorDepth"); colorDepthElement.setTextContent("32"); signatureInfoElement.appendChild(colorDepthElement); Element signatureProviderIdElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureProviderId"); signatureProviderIdElement.setTextContent("{00000000-0000-0000-0000-000000000000}"); signatureInfoElement.appendChild(signatureProviderIdElement); Element signatureProviderUrlElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureProviderUrl"); signatureInfoElement.appendChild(signatureProviderUrlElement); Element signatureProviderDetailsElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureProviderDetails"); signatureProviderDetailsElement.setTextContent("9"); signatureInfoElement.appendChild(signatureProviderDetailsElement); Element manifestHashAlgorithmElement = document.createElementNS(OFFICE_DIGSIG_NS, "ManifestHashAlgorithm"); manifestHashAlgorithmElement.setTextContent("http://www.w3.org/2000/09/xmldsig#sha1"); signatureInfoElement.appendChild(manifestHashAlgorithmElement); Element signatureTypeElement = document.createElementNS(OFFICE_DIGSIG_NS, "SignatureType"); signatureTypeElement.setTextContent("1"); signatureInfoElement.appendChild(signatureTypeElement); List<XMLStructure> signatureInfoContent = new LinkedList<XMLStructure>(); signatureInfoContent.add(new DOMStructure(signatureInfoElement)); SignatureProperty signatureInfoSignatureProperty = signatureFactory .newSignatureProperty(signatureInfoContent, "#" + signatureId, "idOfficeV1Details"); List<SignatureProperty> signaturePropertyContent = new LinkedList<SignatureProperty>(); signaturePropertyContent.add(signatureInfoSignatureProperty); SignatureProperties signatureProperties = signatureFactory.newSignatureProperties(signaturePropertyContent, null);//from w w w . ja v a2 s .c o m objectContent.add(signatureProperties); String objectId = "idOfficeObject"; objects.add(signatureFactory.newXMLObject(objectContent, objectId, null, null)); DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); Reference reference = signatureFactory.newReference("#" + objectId, digestMethod, null, "http://www.w3.org/2000/09/xmldsig#Object", null); references.add(reference); }
From source file:org.roda.common.certification.ODFSignatureUtils.java
private static List<XMLObject> getXMLObjectList(XMLSignatureFactory factory, Document docSignatures, String signatureId, String signaturePropertyId) { Element content = docSignatures.createElement("dc:date"); content.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SS"); content.setTextContent(sdf.format(new Date())); XMLStructure str = new DOMStructure(content); List<XMLStructure> contentList = new ArrayList<XMLStructure>(); contentList.add(str);//w w w. j a va2 s . c o m SignatureProperty sp = factory.newSignatureProperty(contentList, "#" + signatureId, signaturePropertyId); List<SignatureProperty> spList = new ArrayList<SignatureProperty>(); spList.add(sp); SignatureProperties sps = factory.newSignatureProperties(spList, null); List<SignatureProperties> spsList = new ArrayList<SignatureProperties>(); spsList.add(sps); XMLObject object = factory.newXMLObject(spsList, null, null, null); List<XMLObject> objectList = new ArrayList<XMLObject>(); objectList.add(object); return objectList; }
From source file:org.roda.core.plugins.plugins.characterization.ODFSignatureUtils.java
private static List<XMLObject> getXMLObjectList(XMLSignatureFactory factory, Document docSignatures, String signatureId, String signaturePropertyId) { Element content = docSignatures.createElement("dc:date"); content.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SS"); content.setTextContent(sdf.format(new Date())); XMLStructure str = new DOMStructure(content); List<XMLStructure> contentList = new ArrayList<>(); contentList.add(str);/*w w w . ja v a2 s. c o m*/ SignatureProperty sp = factory.newSignatureProperty(contentList, "#" + signatureId, signaturePropertyId); List<SignatureProperty> spList = new ArrayList<>(); spList.add(sp); SignatureProperties sps = factory.newSignatureProperties(spList, null); List<SignatureProperties> spsList = new ArrayList<>(); spsList.add(sps); XMLObject object = factory.newXMLObject(spsList, null, null, null); List<XMLObject> objectList = new ArrayList<>(); objectList.add(object); return objectList; }