@Test() public void select_wrong_structType() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); ArrayList<XMLStructure> list = new ArrayList<XMLStructure>(); KeyName struct = mock(KeyName.class); list.add(struct); doReturn(list).when(keyinfo).getContent(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getMessage().contains("No X509Data element found.")); } }
@Test() public void select_x509Data_empty() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); ArrayList<XMLStructure> list = new ArrayList<XMLStructure>(); X509Data x509Data = mock(X509Data.class); list.add(x509Data); doReturn(list).when(keyinfo).getContent(); doReturn(new ArrayList<Object>()).when(x509Data).getContent(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getMessage().contains("No X509Data element found.")); } }
@Test() public void select_x509Data_noCertificate() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); ArrayList<XMLStructure> list = new ArrayList<XMLStructure>(); X509Data x509Data = mock(X509Data.class); list.add(x509Data); doReturn(list).when(keyinfo).getContent(); ArrayList<Object> x509DataContent = new ArrayList<Object>(); x509DataContent.add(new String()); doReturn(x509DataContent).when(x509Data).getContent(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getMessage().contains("No X509Data element found.")); } }
@Test() public void select_publicKey_exception() throws Exception { // given selector = spy(new X509KeySelector(keystore)); KeyInfo keyinfo = mock(KeyInfo.class); ArrayList<XMLStructure> list = new ArrayList<XMLStructure>(); X509Data x509Data = mock(X509Data.class); list.add(x509Data); doReturn(list).when(keyinfo).getContent(); ArrayList<Object> x509DataContent = new ArrayList<Object>(); x509DataContent.add(mock(X509Certificate.class)); doReturn(x509DataContent).when(x509Data).getContent(); doThrow(new KeyStoreException("key exception")).when(selector) .getPublicKeyFromKeystore(any(X509Certificate.class), any(SignatureMethod.class)); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getCause().getMessage().contains("key exception")); } }
@Test() public void select_wrong_structType() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); ArrayList<XMLStructure> list = new ArrayList<XMLStructure>(); KeyName struct = mock(KeyName.class); list.add(struct); doReturn(list).when(keyinfo).getContent(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getMessage().contains( "No RSA/DSA KeyValue element found")); } }
@Test() public void select_publicKey_exception() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); ArrayList<XMLStructure> list = new ArrayList<XMLStructure>(); KeyValue struct = mock(KeyValue.class); list.add(struct); doReturn(list).when(keyinfo).getContent(); doThrow(new KeyException("test")).when(struct).getPublicKey(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getCause().getMessage().contains("test")); } }
/** * Marshals a {@link PGPData} * * @param xwriter * @param pgpData * @param dsPrefix * @param context * @throws MarshalException */ public static void marshalPGPData(XmlWriter xwriter, PGPData pgpData, String dsPrefix, XMLCryptoContext context) throws MarshalException { xwriter.writeStartElement(dsPrefix, "PGPData", XMLSignature.XMLNS); // create and append PGPKeyID element byte[] keyId = pgpData.getKeyId(); if (keyId != null) { xwriter.writeTextElement(dsPrefix, "PGPKeyID", XMLSignature.XMLNS, Base64.encode(keyId)); } // create and append PGPKeyPacket element byte[] keyPacket = pgpData.getKeyPacket(); if (keyPacket != null) { xwriter.writeTextElement(dsPrefix, "XMLSignature.XMLNS", XMLSignature.XMLNS, Base64.encode(keyPacket)); } // create and append any elements @SuppressWarnings("unchecked") List<XMLStructure> externalElements = pgpData.getExternalElements(); for (XMLStructure externalItem : externalElements) { xwriter.marshalStructure(externalItem, dsPrefix, context); } xwriter.writeEndElement(); // "PGPData" }
public XMLStructure dereferenceAsXMLStructure(XMLCryptoContext context) throws URIReferenceException { DocumentBuilder db = null; boolean secVal = Utils.secureValidation(context); try { ApacheData data = (ApacheData)dereference(context); db = XMLUtils.createDocumentBuilder(false, secVal); Document doc = db.parse(new ByteArrayInputStream (data.getXMLSignatureInput().getBytes())); Element kiElem = doc.getDocumentElement(); if (kiElem.getLocalName().equals("X509Data") && XMLSignature.XMLNS.equals(kiElem.getNamespaceURI())) { return new DOMX509Data(kiElem); } else { return null; // unsupported } } catch (Exception e) { throw new URIReferenceException(e); } finally { if (db != null) { XMLUtils.repoolDocumentBuilder(db); } } }
/** * Creates a <code>DOMKeyInfo</code>. * * @param content a list of one or more {@link XMLStructure}s representing * key information types. The list is defensively copied to protect * against subsequent modification. * @param id an ID attribute * @throws NullPointerException if <code>content</code> is <code>null</code> * @throws IllegalArgumentException if <code>content</code> is empty * @throws ClassCastException if <code>content</code> contains any entries * that are not of type {@link XMLStructure} */ public DOMKeyInfo(List<? extends XMLStructure> content, String id) { if (content == null) { throw new NullPointerException("content cannot be null"); } this.keyInfoTypes = Collections.unmodifiableList(new ArrayList<XMLStructure>(content)); if (this.keyInfoTypes.isEmpty()) { throw new IllegalArgumentException("content cannot be empty"); } for (int i = 0, size = this.keyInfoTypes.size(); i < size; i++) { if (!(this.keyInfoTypes.get(i) instanceof XMLStructure)) { throw new ClassCastException ("content["+i+"] is not a valid KeyInfo type"); } } this.id = id; }
private static void marshalInternal(XmlWriter xwriter, KeyInfo ki, String dsPrefix, XMLCryptoContext context, boolean declareNamespace) throws MarshalException { xwriter.writeStartElement(dsPrefix, "KeyInfo", XMLSignature.XMLNS); if (declareNamespace) { xwriter.writeNamespace(dsPrefix, XMLSignature.XMLNS); } xwriter.writeIdAttribute("", "", "Id", ki.getId()); // create and append KeyInfoType elements List<XMLStructure> keyInfoTypes = getContent(ki); for (XMLStructure kiType : keyInfoTypes) { xwriter.marshalStructure(kiType, dsPrefix, context); } xwriter.writeEndElement(); // "KeyInfo" }
@org.junit.Test @SuppressWarnings("unchecked") public void testgetContent() { KeyInfo[] infos = new KeyInfo[2]; infos[0] = fac.newKeyInfo (Collections.singletonList(fac.newKeyName("foo")), "skeleton"); infos[1] = fac.newKeyInfo (Collections.singletonList(fac.newKeyName("foo"))); for (int j = 0; j < infos.length; j++) { KeyInfo ki = infos[j]; List<XMLStructure> li = ki.getContent(); assertNotNull(ki.getContent()); Object[] content = li.toArray(); for (int i = 0; i < content.length; i++) { if (!(content[i] instanceof XMLStructure)) { fail("KeyInfo element has the wrong type"); } } } }
@Override public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException { for (final Object object : keyInfo.getContent()) { final XMLStructure info = (XMLStructure) object; if (info instanceof X509Data) { final X509Data x509Data = (X509Data) info; for (final Object certificado : x509Data.getContent()) { if (certificado instanceof X509Certificate) { final X509Certificate x509Certificate = (X509Certificate) certificado; if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) { return new KeySelectorResult() { @Override public Key getKey() { return x509Certificate.getPublicKey(); } }; } } } } } throw new KeySelectorException("N\u00e3o foi localizada a chave do certificado."); }
@Override public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException { LOG.debug("marshallParams(parent,context)"); DOMStructure domParent = (DOMStructure) parent; Node parentNode = domParent.getNode(); Element parentElement = (Element) parentNode; parentElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi", "http://schemas.openxmlformats.org/package/2006/digital-signature"); Document document = parentNode.getOwnerDocument(); for (String sourceId : this.sourceIds) { Element relationshipReferenceElement = document.createElementNS( "http://schemas.openxmlformats.org/package/2006/digital-signature", "mdssi:RelationshipReference"); relationshipReferenceElement.setAttribute("SourceId", sourceId); parentElement.appendChild(relationshipReferenceElement); } for (String sourceType : this.sourceTypes) { Element relationshipsGroupReferenceElement = document.createElementNS( "http://schemas.openxmlformats.org/package/2006/digital-signature", "mdssi:RelationshipsGroupReference"); relationshipsGroupReferenceElement.setAttribute("SourceType", sourceType); parentElement.appendChild(relationshipsGroupReferenceElement); } }
@Override public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException { for (final Object object : keyInfo.getContent()) { final XMLStructure info = (XMLStructure) object; if (info instanceof X509Data) { final X509Data x509Data = (X509Data) info; for (final Object certificado : x509Data.getContent()) { if (certificado instanceof X509Certificate) { final X509Certificate x509Certificate = (X509Certificate) certificado; if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) { return new KeySelectorResult() { @Override public Key getKey() { return x509Certificate.getPublicKey(); } }; } } } } } throw new KeySelectorException("Nao foi localizada a chave do certificado."); }
@Override public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException { if ( keyInfo == null ) { throw new KeySelectorException ( "Null KeyInfo object!" ); } final SignatureMethod sm = (SignatureMethod)method; final List<?> list = keyInfo.getContent (); for ( int i = 0; i < list.size (); i++ ) { final XMLStructure xmlStructure = (XMLStructure)list.get ( i ); if ( xmlStructure instanceof KeyValue ) { try { final PublicKey pk = ( (KeyValue)xmlStructure ).getPublicKey (); // make sure algorithm is compatible with method if ( algEquals ( sm.getAlgorithm (), pk.getAlgorithm () ) ) { return new SimpleKeySelectorResult ( pk ); } } catch ( final KeyException ke ) { throw new KeySelectorException ( ke ); } } } throw new KeySelectorException ( "No KeyValue element found!" ); }
@Override public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException { if ( keyInfo == null ) { throw new KeySelectorException ( "Null KeyInfo object!" ); } final SignatureMethod sm = (SignatureMethod)method; final List<?> list = keyInfo.getContent (); for ( final Object l : list ) { final XMLStructure xmlStructure = (XMLStructure)l; if ( xmlStructure instanceof X509Data ) { for ( final Object o : ( (X509Data)xmlStructure ).getContent () ) { KeySelectorResult result = null; if ( o instanceof X509Certificate ) { result = findPublicKey ( (X509Certificate)o, sm ); } if ( result != null ) { return result; } } } } throw new KeySelectorException ( "No KeyValue element found!" ); }
@Test() public void select_xmlStruct_empty() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); doReturn(new ArrayList<XMLStructure>()).when(keyinfo).getContent(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getMessage().contains("No X509Data element found.")); } }
@Test() public void select_xmlStruct_empty() throws Exception { // given KeyInfo keyinfo = mock(KeyInfo.class); doReturn(new ArrayList<XMLStructure>()).when(keyinfo).getContent(); // when try { selector.select(keyinfo, null, null, null); fail(); } catch (KeySelectorException e) { assertTrue(e.getMessage().contains( "No RSA/DSA KeyValue element found")); } }
@Override public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod, XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) { throw new KeySelectorException("Null KeyInfo object!"); } @SuppressWarnings("unchecked") List<XMLStructure> list = keyInfo.getContent(); for (XMLStructure xmlStructure : list) { if (xmlStructure instanceof X509Data) { X509Data x509Data = (X509Data) xmlStructure; @SuppressWarnings("rawtypes") List content = x509Data.getContent(); for (int i = 0; i < content.size(); i++) { Object x509Content = content.get(i); if (x509Content instanceof X509Certificate) { X509Certificate certificate = (X509Certificate) x509Content; try { return getPublicKeyFromKeystore(certificate, (SignatureMethod) algorithmMethod); } catch (KeyStoreException e) { throw new KeySelectorException(e); } } } } } throw new KeySelectorException("No X509Data element found."); }
@Override public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod algorithmMethod, XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) { throw new KeySelectorException("Null KeyInfo object!"); } @SuppressWarnings("unchecked") List<XMLStructure> list = keyInfo.getContent(); for (XMLStructure xmlStructure : list) { if (xmlStructure instanceof KeyValue) { PublicKey publicKey = null; try { publicKey = ((KeyValue) xmlStructure).getPublicKey(); } catch (KeyException ke) { throw new KeySelectorException(ke); } if (algorithmCompatibleWithMethod( algorithmMethod.getAlgorithm(), publicKey.getAlgorithm())) { return new SimpleKeySelectorResult(publicKey); } } } throw new KeySelectorException("No RSA/DSA KeyValue element found"); }
@Override public void marshalStructure(XMLStructure toMarshal, String dsPrefix, XMLCryptoContext context) throws MarshalException { // look for the first isInstance match, and marshal to that. for (int idx = 0 ; idx < m_marshallers.size() ; idx++) { @SuppressWarnings("unchecked") XmlWriter.ToMarshal<XMLStructure> marshaller = (ToMarshal<XMLStructure>) m_marshallers.get(idx); if (marshaller.clazzToMatch.isInstance(toMarshal)) { marshaller.marshalObject(this, toMarshal, dsPrefix, context); return; } } throw new IllegalArgumentException("Unable to marshal unexpected object of class " + toMarshal.getClass().toString()); }
/** * Creates a <code>DOMKeyInfo</code> from XML. * * @param kiElem KeyInfo element */ public DOMKeyInfo(Element kiElem, XMLCryptoContext context, Provider provider) throws MarshalException { id = DOMUtils.getIdAttributeValue(kiElem, "Id"); // get all children nodes List<XMLStructure> content = new ArrayList<XMLStructure>(); Node firstChild = kiElem.getFirstChild(); if (firstChild == null) { throw new MarshalException("KeyInfo must contain at least one type"); } while (firstChild != null) { if (firstChild.getNodeType() == Node.ELEMENT_NODE) { Element childElem = (Element)firstChild; String localName = childElem.getLocalName(); String namespace = childElem.getNamespaceURI(); if (localName.equals("X509Data") && XMLSignature.XMLNS.equals(namespace)) { content.add(new DOMX509Data(childElem)); } else if (localName.equals("KeyName") && XMLSignature.XMLNS.equals(namespace)) { content.add(new DOMKeyName(childElem)); } else if (localName.equals("KeyValue") && XMLSignature.XMLNS.equals(namespace)) { content.add(DOMKeyValue.unmarshal(childElem)); } else if (localName.equals("RetrievalMethod") && XMLSignature.XMLNS.equals(namespace)) { content.add(new DOMRetrievalMethod(childElem, context, provider)); } else if (localName.equals("PGPData") && XMLSignature.XMLNS.equals(namespace)) { content.add(new DOMPGPData(childElem)); } else { //may be MgmtData, SPKIData or element from other namespace content.add(new javax.xml.crypto.dom.DOMStructure(childElem)); } } firstChild = firstChild.getNextSibling(); } keyInfoTypes = Collections.unmodifiableList(content); }
@Override public void marshal(XMLStructure parent, XMLCryptoContext context) throws MarshalException { if (parent == null) { throw new NullPointerException("parent is null"); } if (!(parent instanceof javax.xml.crypto.dom.DOMStructure)) { throw new ClassCastException("parent must be of type DOMStructure"); } internalMarshal( (javax.xml.crypto.dom.DOMStructure) parent, context); }
@org.junit.Test public void testisFeatureSupported() { List<XMLStructure> list = new ArrayList<XMLStructure>(); list.add(new TestUtils.MyOwnXMLStructure()); SignatureProperty prop = factory.newSignatureProperty (list, target, id); try { prop.isFeatureSupported(null); fail("Should raise a NPE for null feature"); } catch (NullPointerException npe) {} assertTrue(!prop.isFeatureSupported("not supported")); }
@org.junit.Test public void testisFeatureSupported() { List<XMLStructure> list = new ArrayList<XMLStructure>(); list.add(new TestUtils.MyOwnXMLStructure()); XMLObject obj = factory.newXMLObject(list, id, mimeType, encoding); try { obj.isFeatureSupported(null); fail("Should raise a NPE for null feature"); } catch (NullPointerException npe) {} assertTrue(!obj.isFeatureSupported("not supported")); }
private static X509Certificate extractCertificate(XMLSignature signature) { LOG.debug("Extracting certificate from XML signature..."); X509Certificate certificate = null; for (Object o1 : signature.getKeyInfo().getContent()) { XMLStructure info = (XMLStructure) o1; if (!(info instanceof X509Data)) { continue; } X509Data x509Data = (X509Data) info; for (Object o : x509Data.getContent()) { if (o instanceof X509Certificate) { certificate = (X509Certificate) o; break; } } // Do not keep on searching if the certificate has been found if (certificate != null) { break; } } LOG.debug("Certificate found in XML signature: {}", certificate); return certificate; }
/** * Returns the DOM structure which is transformed to a byte array and set to * the camel message body. * * @param relevantReferences * input from method * {@link #getReferencesForMessageMapping(ReferencesAndObjects)} * @param relevantObjects * input from method * {@link #getObjectsForMessageMapping(ReferencesAndObjects)} * @return dom structure * @throws Exception * if an error occurs */ protected DOMStructure getDomStructureForMessageBody(List<Reference> relevantReferences, List<XMLObject> relevantObjects) throws Exception { //NOPMD List<XMLObject> referencedObjects = getReferencedSameDocumentObjects(relevantReferences, relevantObjects); if (referencedObjects.isEmpty()) { throw new XmlSignatureException( String.format("Unsupported XML signature document: Content object not found in the enveloping XML signature.")); } if (referencedObjects.size() > 1) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < referencedObjects.size(); i++) { XMLObject xmlOb = referencedObjects.get(i); sb.append(xmlOb.getId()); if (i < referencedObjects.size() - 1) { sb.append(", "); } } throw new XmlSignatureException(String.format( "Unsupported XML signature document: More than one content objects found. Object IDs: %s", sb.toString())); } @SuppressWarnings("unchecked") List<XMLStructure> structures = referencedObjects.get(0).getContent(); if (structures.size() == 0) { throw new XmlSignatureException( "Unsupported XML signature: XML signature is not enveloping; content not found in XML signature: structure list is empty."); } if (structures.size() > 1) { throw new XmlSignatureException("Unsupported XML signature: more than one structure elements in referenced content object."); } XMLStructure structure = structures.get(0); // only dom currently supported DOMStructure domStruc = (DOMStructure) structure; return domStruc; }
protected Manifest getReferencedManifest(List<XMLObject> objects, String id) { for (XMLObject xo : objects) { @SuppressWarnings("unchecked") List<XMLStructure> content = xo.getContent(); for (XMLStructure xs : content) { if (xs instanceof Manifest) { Manifest man = (Manifest) xs; if (id.equals(man.getId())) { return man; } } } } return null; }
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) { throw new KeySelectorException("Null KeyInfo object!"); } SignatureMethod sm = (SignatureMethod) method; @SuppressWarnings("rawtypes") List list = keyInfo.getContent(); for (int i = 0; i < list.size(); i++) { XMLStructure xmlStructure = (XMLStructure) list.get(i); if (xmlStructure instanceof KeyValue) { PublicKey pk = null; try { pk = ((KeyValue) xmlStructure).getPublicKey(); } catch (KeyException ke) { throw new KeySelectorException(ke); } // make sure algorithm is compatible with method if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) { return new SimpleKeySelectorResult(pk); } } } throw new KeySelectorException("No KeyValue element found!"); }
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); 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); }
private void addManifestObject(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { Manifest manifest = constructManifest(signatureFactory, document); String objectId = "idPackageObject"; // really has to be this value. List<XMLStructure> objectContent = new LinkedList<XMLStructure>(); objectContent.add(manifest); addSignatureTime(signatureFactory, document, signatureId, objectContent); 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); }
private void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<XMLStructure> objectContent) { /* * 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); }