@Override public Output get(Input input) throws Exception { Transform transform = input.getSignatureFactory().newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null); Reference ref = input.getSignatureFactory().newReference("#propertiesObject", input.getSignatureFactory().newDigestMethod(input.getContentDigestAlgorithm(), null), Collections.singletonList(transform), null, null); String doc2 = "<ts:timestamp xmlns:ts=\"http:/timestamp\">" + System.currentTimeMillis() + "</ts:timestamp>"; InputStream is = new ByteArrayInputStream(doc2.getBytes("UTF-8")); Document doc = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).parse(is); DOMStructure structure = new DOMStructure(doc.getDocumentElement()); SignatureProperty prop = input.getSignatureFactory().newSignatureProperty(Collections.singletonList(structure), input.getSignatureId(), "property"); SignatureProperties properties = input.getSignatureFactory().newSignatureProperties(Collections.singletonList(prop), "properties"); XMLObject propertiesObject = input.getSignatureFactory().newXMLObject(Collections.singletonList(properties), "propertiesObject", null, null); XmlSignatureProperties.Output result = new Output(); result.setReferences(Collections.singletonList(ref)); result.setObjects(Collections.singletonList(propertiesObject)); return result; }
@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); } }
public static void main(String[] args) throws Exception { KeyInfoFactory fac = KeyInfoFactory.getInstance(); KeyInfo ki = fac.newKeyInfo (Collections.singletonList(fac.newKeyName("foo")), "keyid"); try { ki.marshal(null, null); throw new Exception("Should raise a NullPointerException"); } catch (NullPointerException npe) {} DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().newDocument(); Element elem = doc.createElementNS("http://acme.org", "parent"); doc.appendChild(elem); DOMStructure parent = new DOMStructure(elem); ki.marshal(parent, null); Element kiElem = DOMUtils.getFirstChildElement(elem); if (!kiElem.getLocalName().equals("KeyInfo")) { throw new Exception ("Should be KeyInfo element: " + kiElem.getLocalName()); } Element knElem = DOMUtils.getFirstChildElement(kiElem); if (!knElem.getLocalName().equals("KeyName")) { throw new Exception ("Should be KeyName element: " + knElem.getLocalName()); } }
@org.junit.Test public void testSignTemplateWithObjectNSDefs() throws Exception { String base = System.getProperty("basedir") == null ? "./" : System.getProperty("basedir"); File f = new File(base + "/src/test/resources/javax/xml/crypto/dsig/" + "signature-enveloping-rsa-template.xml"); Document doc = XMLUtils.createDocumentBuilder(false).parse(new FileInputStream(f)); // Find Signature element NodeList nl = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); if (nl.getLength() == 0) { throw new Exception("Cannot find Signature element"); } DOMStructure domSignature = new DOMStructure(nl.item(0)); // unmarshal the XMLSignature XMLSignature signature = fac.unmarshalXMLSignature(domSignature); // create copy of Signature XMLSignature newSignature = fac.newXMLSignature (signature.getSignedInfo(), null, signature.getObjects(), signature.getId(), signature.getSignatureValue().getId()); // Sign the template Node parent = domSignature.getNode().getParentNode(); DOMSignContext signContext = new DOMSignContext(SIGN_KEYS[0], parent); // remove the signature node (since it will get recreated) parent.removeChild(domSignature.getNode()); newSignature.sign(signContext); TestUtils.validateSecurityOrEncryptionElement(parent.getLastChild()); // check that Object element retained namespace definitions Element objElem = (Element)parent.getFirstChild().getLastChild(); Attr a = objElem.getAttributeNode("xmlns:test"); if (!a.getValue().equals("http://www.example.org/ns")) { throw new Exception("Object namespace definition not retained"); } }
@org.junit.Test public void testCreateSignatureWithEmptyId() throws Exception { // create references DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null); List<Reference> refs = Collections.singletonList (fac.newReference("#", dm)); // create SignedInfo CanonicalizationMethod cm = fac.newCanonicalizationMethod (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null); SignedInfo si = fac.newSignedInfo(cm, SIG_METHODS[1], refs); // create object with empty id Document doc = TestUtils.newDocument(); XMLObject obj = fac.newXMLObject(Collections.singletonList (new DOMStructure(doc.createTextNode("I am the text."))), "", "text/plain", null); KeyInfo ki = kifac.newKeyInfo(Collections.singletonList (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[1]))); // create XMLSignature XMLSignature sig = fac.newXMLSignature(si, ki, Collections.singletonList(obj), "signature", null); DOMSignContext dsc = new DOMSignContext(SIGN_KEYS[1], doc); sig.sign(dsc); }
private void test_create_signature_enveloping( SignatureMethod sm, DigestMethod dm, KeyInfo ki, Key signingKey, KeySelector ks ) throws Exception { // create reference Reference ref = fac.newReference("#DSig.Object_1", dm, null, XMLObject.TYPE, null); // create SignedInfo SignedInfo si = fac.newSignedInfo(withoutComments, sm, Collections.singletonList(ref)); Document doc = db.newDocument(); // create Objects Element webElem = doc.createElementNS(null, "Web"); Text text = doc.createTextNode("up up and away"); webElem.appendChild(text); XMLObject obj = fac.newXMLObject(Collections.singletonList (new DOMStructure(webElem)), "DSig.Object_1", "text/xml", null); // create XMLSignature XMLSignature sig = fac.newXMLSignature (si, ki, Collections.singletonList(obj), null, null); DOMSignContext dsc = new DOMSignContext(signingKey, doc); dsc.setDefaultNamespacePrefix("dsig"); sig.sign(dsc); TestUtils.validateSecurityOrEncryptionElement(doc.getDocumentElement()); // XMLUtils.outputDOM(doc.getDocumentElement(), System.out); DOMValidateContext dvc = new DOMValidateContext (ks, doc.getDocumentElement()); XMLSignature sig2 = fac.unmarshalXMLSignature(dvc); assertTrue(sig.equals(sig2)); assertTrue(sig2.validate(dvc)); }
protected Node getNodeForMessageBodyInEnvelopingCase(Input input) throws Exception { //NOPMD Node node; List<Reference> relevantReferences = getReferencesForMessageMapping(input); List<XMLObject> relevantObjects = getObjectsForMessageMapping(input); DOMStructure domStruc = getDomStructureForMessageBody(relevantReferences, relevantObjects); node = domStruc.getNode(); return node; }
/** * 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; }
/** * Returns a configuration for an XSL transformation. * * @param is * input stream of the XSL * @return XSL transform * @throws IllegalArgumentException * if <tt>is</tt> is <code>null</code> * @throws Exception * if an error during the reading of the XSL file occurs */ public static AlgorithmMethod getXslTranform(InputStream is) throws SAXException, IOException, ParserConfigurationException { if (is == null) { throw new IllegalArgumentException("is must not be null"); } Document doc = parseInput(is); DOMStructure stylesheet = new DOMStructure(doc.getDocumentElement()); XSLTTransformParameterSpec spec = new XSLTTransformParameterSpec(stylesheet); XmlSignatureTransform transformXslt = new XmlSignatureTransform(); transformXslt.setAlgorithm(Transform.XSLT); transformXslt.setParameterSpec(spec); return transformXslt; }
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 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); }
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 manifestHashAlgorithmElement = document.createElementNS(OFFICE_DIGSIG_NS, "ManifestHashAlgorithm"); manifestHashAlgorithmElement.setTextContent("http://www.w3.org/2000/09/xmldsig#sha1"); signatureInfoElement.appendChild(manifestHashAlgorithmElement); 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); 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); }
@Override public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException { super.marshalParams(parent, context); Node node = ((DOMStructure) parent).getNode(); Document doc = node.getOwnerDocument(); Element tp = XMLHelper.constructElement(doc, WSSecurityConstants.WSSE_NS, "TransformationParameters", WSSecurityConstants.WSSE_PREFIX); Element cm = XMLHelper.constructElement(doc, XMLSignature.XMLNS, "CanonicalizationMethod", "ds"); tp.appendChild(cm); cm.setAttributeNS(null, "Algorithm", "http://www.w3.org/2001/10/xml-exc-c14n#"); node.appendChild(tp); log.debug("Marshall: " + XMLHelper.nodeToString(node)); }
private static void sign(Document document, DigitalSignatureServiceSession session) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MarshalException, XMLSignatureException { Key key = new SecretKeySpec(session.getKey(), "HMACSHA1"); Node parentElement = document.getElementsByTagNameNS("urn:oasis:names:tc:dss:1.0:core:schema", "OptionalInputs") .item(0); DOMSignContext domSignContext = new DOMSignContext(key, parentElement); domSignContext.setDefaultNamespacePrefix("ds"); // XMLDSigRI Websphere work-around XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance("DOM", new XMLDSigRI()); List<Transform> transforms = new LinkedList<Transform>(); transforms.add(xmlSignatureFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)); transforms.add( xmlSignatureFactory.newTransform(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null)); Reference reference = xmlSignatureFactory.newReference("", xmlSignatureFactory.newDigestMethod(DigestMethod.SHA1, null), transforms, null, null); SignedInfo signedInfo = xmlSignatureFactory.newSignedInfo( xmlSignatureFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null), xmlSignatureFactory.newSignatureMethod(SignatureMethod.HMAC_SHA1, null), Collections.singletonList(reference)); Element securityTokenReferenceElement = getSecurityTokenReference(session); KeyInfoFactory keyInfoFactory = xmlSignatureFactory.getKeyInfoFactory(); DOMStructure securityTokenReferenceDOMStructure = new DOMStructure(securityTokenReferenceElement); KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(securityTokenReferenceDOMStructure)); XMLSignature xmlSignature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); xmlSignature.sign(domSignContext); }
/** * Retorna o XML que contem SigningCertificate, que eh uma das propriedades assinadas obrigatorias da ICP-BRASIL. * contem cert = conforme DOC-ICP-04; CertDigest: /DigestMethod e /DigestValue; IssuerSerial: /X509IssuerName e /X509SerialNumber * @param ix indica de qual a assinatura. * @return org.w3c.NodeList contendo SigningCertificate ou nulo * @throws Exception */ public NodeList getSigningCertificate(int ix) throws Exception{ NodeList nodeSigningCertificate = null; if (this.getAssinaturas().isEmpty()){ return null; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); nodeSigningCertificate = el.getElementsByTagName("SigningCertificate"); break; } } // se a lista estiver vazia retornar� nulo if (nodeSigningCertificate.getLength() < 1){ nodeSigningCertificate = null; } } } } return nodeSigningCertificate; }
/** * Retorna SignaturePolicyIdentifier, que identifica qual eh a politica de assinatura. * Eh uma das propriedades assinadas obrigatorias da ICP-BRASIL. Atualmente contem dos atributos: * SigPolicyId e SPURI * * @param ix indica de qual a assinatura. * @return NodeList da politica de assinatura ou nulo. * @throws DOMException */ public NodeList getSignaturePolicyIdentifier(int ix) throws DOMException { NodeList signaturePolicyIdentifier = null; if (this.getAssinaturas().isEmpty()){ return signaturePolicyIdentifier; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); signaturePolicyIdentifier = el.getElementsByTagName("SignaturePolicyIdentifier"); // se a lista estiver vazia retornar� nulo break; } } if (signaturePolicyIdentifier.getLength() < 1){ signaturePolicyIdentifier = null; } } } } return signaturePolicyIdentifier; }
/** * Retorna SigPolicyId, que e uma das propriedades de SignaturePolicyIdentifier * @param ix indica de qual a assinatura. * @return String de SigPolicyId * @throws DOMException */ public String getSigPolicyId(int ix) throws DOMException { String sigPolicyId = null; if (this.getAssinaturas().isEmpty()){ return sigPolicyId; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); NodeList nodeSigId = el.getElementsByTagName("SigPolicyId"); if (nodeSigId.getLength() > 0){ sigPolicyId = nodeSigId.item(0).getTextContent(); } break; } } } } } return sigPolicyId; }
/** * Retorna SPURI, que eh uma das propriedades de SignaturePolicyIdentifier * @param ix indica de qual a assinatura. * @return String de SPURI * @throws DOMException */ public String getSPURI(int ix) throws DOMException { String SPURI = null; if (this.getAssinaturas().isEmpty()){ return SPURI; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); NodeList nodeSPURI = el.getElementsByTagName("SPURI"); if (nodeSPURI.getLength() > 0){ SPURI = nodeSPURI.item(0).getTextContent(); } break; } } } } } return SPURI; }
/** * Retorna DataObjectFormat do objeto Assinado * Eh uma das propriedades assinadas obrigatorias da ICP-BRASIL. Nao faz muito sentido para ENVELOPEDXML. * @param ix indica de qual a assinatura. * @return String com formato (MimeTye) do conteudo assinado. * @throws Exception */ public String getDataObjectFormat(int ix) throws DOMException { String dataObjectFormat = null; if (this.getAssinaturas().isEmpty()){ return dataObjectFormat; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); NodeList nodeMimeType = el.getElementsByTagName("MimeType"); if (nodeMimeType.getLength() > 0 ){ dataObjectFormat = nodeMimeType.item(0).getTextContent(); } break; } } } } } return dataObjectFormat; }
/** * Retorna um NodeList da propriedade CounterSignature, se houver. * esta lista contem o elemento Signature que foi contra assinado, este por sua vez * tambem pode possuir um elemento CounterSignature recursivamente igual. * * @param ix -> indice da assinatura * @return NodeList -> CounterSignature ou nulo * @throws Exception */ public NodeList getContraAssinatura(int ix) throws Exception{ NodeList nodeContraAssiantura = null; if (this.getAssinaturas().isEmpty()){ return nodeContraAssiantura; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); nodeContraAssiantura = el.getElementsByTagName("CounterSignature"); break; } } // se a lista estiver vazia retornar� nulo if (nodeContraAssiantura.getLength() < 1){ nodeContraAssiantura = null; } } } } return nodeContraAssiantura; }
/** * Retorna a data de Assinatura contida em SigningTime * Nao eh carimbo de tempo. * @param ix indica de qual a assinatura. * @return Date com data da assinatura * @throws ParseException * @throws DOMException */ public Date getDataAssinatura(int ix) throws DOMException, ParseException { Date dataAssinatura = null; if (this.getAssinaturas().isEmpty()){ return dataAssinatura; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); NodeList nodeQualifying = el.getElementsByTagName("SigningTime"); if (nodeQualifying.getLength() > 0){ Locale locale = new Locale("pt","BR"); SimpleDateFormat formatador = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",locale); dataAssinatura = (Date)formatador.parse(nodeQualifying.item(0).getTextContent()); } break; } } } } } return dataAssinatura; }
/** * Retorna SignaturePolicyIdentifier, que identifica qual eh a politica de assinatura. * Eh uma das propriedades assinadas obrigatorias da ICP-BRASIL. Atualmente contem dos atributos: * SigPolicyId e SPURI * * @param ix indica de qual a assinatura. * @return NodeList da politica de assinatura ou nulo. * @throws DOMException */ public NodeList getSignaturePolicyIdentifier(int ix) throws DOMException { NodeList signaturePolicyIdentifier = null; if (this.getAssinaturas().isEmpty()){ return signaturePolicyIdentifier; } if (!this.getAssinaturas().get(ix).getObjects().isEmpty()){ DOMXMLObject objDX = null; Iterator<?> it = this.getAssinaturas().get(ix).getObjects().iterator(); while (it.hasNext()) { Object ob1 = it.next(); if (ob1 instanceof DOMXMLObject){ objDX = (DOMXMLObject) ob1; for (int i=0; i < objDX.getContent().size();i++){ DOMStructure Dos = (DOMStructure) objDX.getContent().get(i); if (Dos.getNode().getLocalName() == "QualifyingProperties"){ Element el = (Element) Dos.getNode(); signaturePolicyIdentifier = el.getElementsByTagName("SignaturePolicyIdentifier"); break; } } // se a lista estiver vazia retornar� nulo if (signaturePolicyIdentifier.getLength() < 1){ signaturePolicyIdentifier = null; } } } } return signaturePolicyIdentifier; }