protected List<XMLObject> getReferencedSameDocumentObjects(List<Reference> relevantReferences, List<XMLObject> relevantObjects) { List<XMLObject> referencedObjects = new ArrayList<XMLObject>(1); for (Reference ref : relevantReferences) { String refUri = getSameDocumentReferenceUri(ref); if (refUri == null) { continue; } XMLObject referencedOb = getReferencedObject(relevantObjects, refUri); if (referencedOb != null) { referencedObjects.add(referencedOb); continue; } // content could also be indirectly referenced via manifest addManifestReferencedObjects(relevantObjects, referencedObjects, refUri); } return referencedObjects; }
@SuppressWarnings("unchecked") protected void addManifestReferencedObjects(List<XMLObject> allObjects, List<XMLObject> referencedObjects, String manifestId) { Manifest manifest = getReferencedManifest(allObjects, manifestId); if (manifest == null) { return; } for (Reference manifestRef : (List<Reference>) manifest.getReferences()) { String manifestRefUri = getSameDocumentReferenceUri(manifestRef); if (manifestRefUri == null) { continue; } XMLObject manifestReferencedOb = getReferencedObject(allObjects, manifestRefUri); if (manifestReferencedOb != null) { referencedObjects.add(manifestReferencedOb); } } }
protected List<? extends XMLObject> getObjects(XmlSignatureProperties.Input input, XmlSignatureProperties.Output properties) throws Exception { //NOPMD if (SignatureType.enveloped == input.getSignatureType() || SignatureType.detached == input.getSignatureType()) { if (properties == null || properties.getObjects() == null) { return Collections.emptyList(); } return properties.getObjects(); } // enveloping signature --> add additional object final String objectId = getConfiguration().getContentObjectId(); LOG.debug("Object Content Id {}", objectId); XMLObject obj = createXMLObject(input.getSignatureFactory(), input.getMessageBodyNode(), objectId); if (properties == null || properties.getObjects() == null || properties.getObjects().isEmpty()) { return Collections.singletonList(obj); } List<XMLObject> result = new ArrayList<XMLObject>(properties.getObjects().size() + 1); result.add(obj); result.addAll(properties.getObjects()); return result; }
@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; }
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; }
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; }
protected XMLObject getReferencedObject(List<XMLObject> objects, String id) { for (XMLObject ob : objects) { if (id.equals(ob.getId())) { return ob; } } return null; }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); List<Transform> transforms = new LinkedList<Transform>(); Map<String, String> xpathNamespaceMap = new HashMap<String, String>(); xpathNamespaceMap.put("ds", "http://www.w3.org/2000/09/xmldsig#"); // XPath v1 - slow... // Transform envelopedTransform = signatureFactory.newTransform( // CanonicalizationMethod.XPATH, new XPathFilterParameterSpec( // "not(ancestor-or-self::ds:Signature)", // xpathNamespaceMap)); // XPath v2 - fast... List<XPathType> types = new ArrayList<XPathType>(1); types.add(new XPathType("/descendant::*[name()='ds:Signature']", XPathType.Filter.SUBTRACT, xpathNamespaceMap)); Transform envelopedTransform = signatureFactory.newTransform(CanonicalizationMethod.XPATH2, new XPathFilter2ParameterSpec(types)); transforms.add(envelopedTransform); Transform exclusiveTransform = signatureFactory.newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null); transforms.add(exclusiveTransform); Reference reference = signatureFactory.newReference("", digestMethod, transforms, null, this.dsReferenceId); references.add(reference); }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); List<Transform> transforms = new LinkedList<Transform>(); Transform envelopedTransform = signatureFactory.newTransform(CanonicalizationMethod.ENVELOPED, (TransformParameterSpec) null); transforms.add(envelopedTransform); Transform exclusiveTransform = signatureFactory.newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null); transforms.add(exclusiveTransform); Reference reference = signatureFactory.newReference("", digestMethod, transforms, null, null); references.add(reference); }
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); }
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"); addManifestObject(signatureFactory, document, signatureId, references, objects); addSignatureInfo(signatureFactory, document, signatureId, references, objects); }
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 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); }
@SuppressWarnings("unchecked") private XMLObject findObject(XMLSignature xmlSignature, String objectId) { List<XMLObject> objects = xmlSignature.getObjects(); for (XMLObject object : objects) { if (objectId.equals(object.getId())) { LOG.debug("Found \"" + objectId + "\" ds:object"); return object; } } return null; }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { DigestMethod digestMethod = signatureFactory.newDigestMethod(DigestMethod.SHA1, null); for (String uri : this.uris) { Reference reference = signatureFactory.newReference(uri, digestMethod); references.add(reference); } }
@Override public Output get(Input input) throws Exception { //NOPMD XmlSignatureProperties.Output result = new Output(); if (!isAddSignedSignatureProperties() && !isAddSignedDataObjectPropeties()) { LOG.debug("XAdES signature properties are empty. Therefore no XAdES element will be added to the signature."); return result; } String signedPropertiesId = "_" + UUID.randomUUID().toString(); List<Transform> transforms = Collections.emptyList(); Reference ref = input.getSignatureFactory().newReference("#" + signedPropertiesId, input.getSignatureFactory().newDigestMethod(input.getContentDigestAlgorithm(), null), transforms, "http://uri.etsi.org/01903#SignedProperties", null); Node parent = input.getParent(); Document doc; if (Node.DOCUMENT_NODE == parent.getNodeType()) { doc = (Document) parent; // enveloping } else { doc = parent.getOwnerDocument(); // enveloped } Element qualifyingProperties = createElement("QualifyingProperties", doc, input); setIdAttributeFromHeader(XmlSignatureConstants.HEADER_XADES_QUALIFYING_PROPERTIES_ID, qualifyingProperties, input); String signatureId = input.getSignatureId(); if (signatureId == null || signatureId.isEmpty()) { LOG.debug("No signature Id configured. Therefore a value is generated."); // generate one signatureId = "_" + UUID.randomUUID().toString(); // and set to output result.setSignatureId(signatureId); } setAttribute(qualifyingProperties, "Target", "#" + signatureId); Element signedProperties = createElement("SignedProperties", doc, input); qualifyingProperties.appendChild(signedProperties); setAttribute(signedProperties, "Id", signedPropertiesId); signedProperties.setIdAttribute("Id", true); addSignedSignatureProperties(doc, signedProperties, input); String contentReferenceId = addSignedDataObjectProperties(doc, signedProperties, input); result.setContentReferenceId(contentReferenceId); DOMStructure structure = new DOMStructure(qualifyingProperties); XMLObject propertiesObject = input.getSignatureFactory().newXMLObject(Collections.singletonList(structure), null, null, null); result.setReferences(Collections.singletonList(ref)); result.setObjects(Collections.singletonList(propertiesObject)); return result; }
/** XML objects list. */ List<? extends XMLObject> getObjects();
public List<? extends XMLObject> getObjects() { return objects; }
public void setObjects(List<? extends XMLObject> objects) { this.objects = objects; }
@SuppressWarnings("unchecked") protected void verify(InputStream input, final Message out) throws Exception { //NOPMD LOG.debug("Verification of XML signature document started"); final Document doc = parseInput(input, out); XMLSignatureFactory fac; // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { fac = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { fac = XMLSignatureFactory.getInstance("DOM"); } KeySelector selector = getConfiguration().getKeySelector(); if (selector == null) { throw new IllegalStateException("Wrong configuration. Key selector is missing."); } DOMValidateContext valContext = new DOMValidateContext(selector, doc); valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE); valContext.setProperty("org.jcp.xml.dsig.validateManifests", Boolean.TRUE); if (getConfiguration().getSecureValidation() == Boolean.TRUE) { valContext.setProperty("org.apache.jcp.xml.dsig.secureValidation", Boolean.TRUE); valContext.setProperty("org.jcp.xml.dsig.secureValidation", Boolean.TRUE); } setUriDereferencerAndBaseUri(valContext); setCryptoContextProperties(valContext); NodeList signatureNodes = getSignatureNodes(doc); List<XMLObject> collectedObjects = new ArrayList<XMLObject>(3); List<Reference> collectedReferences = new ArrayList<Reference>(3); int totalCount = signatureNodes.getLength(); for (int i = 0; i < totalCount; i++) { Element signatureNode = (Element) signatureNodes.item(i); valContext.setNode(signatureNode); final XMLSignature signature = fac.unmarshalXMLSignature(valContext); if (getConfiguration().getXmlSignatureChecker() != null) { XmlSignatureChecker.Input checkerInput = new CheckerInputBuilder().message(out).messageBodyDocument(doc) .keyInfo(signature.getKeyInfo()).currentCountOfSignatures(i + 1).currentSignatureElement(signatureNode) .objects(signature.getObjects()).signatureValue(signature.getSignatureValue()) .signedInfo(signature.getSignedInfo()).totalCountOfSignatures(totalCount) .xmlSchemaValidationExecuted(getSchemaResourceUri(out) != null).build(); getConfiguration().getXmlSignatureChecker().checkBeforeCoreValidation(checkerInput); } boolean coreValidity; try { coreValidity = signature.validate(valContext); } catch (XMLSignatureException se) { throw getConfiguration().getValidationFailedHandler().onXMLSignatureException(se); } // Check core validation status boolean goon = coreValidity; if (!coreValidity) { goon = handleSignatureValidationFailed(valContext, signature); } if (goon) { LOG.debug("XML signature {} verified", i + 1); } else { throw new XmlSignatureInvalidException("XML signature validation failed"); } collectedObjects.addAll(signature.getObjects()); collectedReferences.addAll(signature.getSignedInfo().getReferences()); } map2Message(collectedReferences, collectedObjects, out, doc); }
private void map2Message(final List<Reference> refs, final List<XMLObject> objs, Message out, final Document messageBodyDocument) throws Exception { //NOPMD XmlSignature2Message.Input refsAndObjects = new XmlSignature2Message.Input() { @Override public List<Reference> getReferences() { return refs; } @Override public List<XMLObject> getObjects() { return objs; } @Override public Document getMessageBodyDocument() { return messageBodyDocument; } @Override public Boolean omitXmlDeclaration() { return getConfiguration().getOmitXmlDeclaration(); } @Override public Object getOutputNodeSearch() { return getConfiguration().getOutputNodeSearch(); } @Override public String getOutputNodeSearchType() { return getConfiguration().getOutputNodeSearchType(); } @Override public Boolean getRemoveSignatureElements() { return getConfiguration().getRemoveSignatureElements(); } @Override public String getOutputXmlEncoding() { return getConfiguration().getOutputXmlEncoding(); } }; getConfiguration().getXmlSignature2Message().mapToMessage(refsAndObjects, out); }
XmlSignatureChecker.Input build() { return new XmlSignatureChecker.Input() { @Override public boolean isXmlSchemaValidationExecuted() { return xmlSchemaValidationExecuted; } @Override public int getTotalCountOfSignatures() { return totalCountOfSignatures; } @Override public SignedInfo getSignedInfo() { return signedInfo; } @Override public SignatureValue getSignatureValue() { return signatureValue; } @Override public List<? extends XMLObject> getObjects() { return objects; } @Override public Document getMessageBodyDocument() { return messageBodyDocument; } @Override public Message getMessage() { return message; } @Override public KeyInfo getKeyInfo() { return keyInfo; } @Override public Element getCurrentSignatureElement() { return currentSignatureElement; } @Override public int getCurrentCountOfSignatures() { return currentCountOfSignatures; } }; }
protected XMLObject createXMLObject(XMLSignatureFactory fac, Node node, String id) { return fac.newXMLObject(Collections.singletonList(new DOMStructure(node)), id, null, null); }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { // construct identity document IdentityType identity = this.objectFactory.createIdentityType(); String identityId = "identity-" + UUID.randomUUID().toString(); identity.setId(identityId); if (null != this.identityDTO) { identity.setFirstName(this.identityDTO.firstName); identity.setName(this.identityDTO.name); identity.setMiddleName(this.identityDTO.middleName); GenderType gender; if (this.identityDTO.male) { gender = GenderType.MALE; } else { gender = GenderType.FEMALE; } identity.setGender(gender); } if (null != this.photoData) { PhotoType photo = this.objectFactory.createPhotoType(); photo.setValue(this.photoData); photo.setMimeType("image/jpeg"); identity.setPhoto(photo); } // marshalling Node marshallNode = document.createElement("marshall-node"); try { this.marshaller.marshal(this.objectFactory.createIdentity(identity), marshallNode); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } Node identityNode = marshallNode.getFirstChild(); // ds:Object String objectId = "identity-object-" + UUID.randomUUID().toString(); List<XMLStructure> identityObjectContent = new LinkedList<XMLStructure>(); identityObjectContent.add(new DOMStructure(identityNode)); XMLObject identityObject = signatureFactory.newXMLObject(identityObjectContent, objectId, null, null); objects.add(identityObject); // ds:Reference DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); List<Transform> transforms = new LinkedList<Transform>(); Transform exclusiveTransform = signatureFactory.newTransform(CanonicalizationMethod.INCLUSIVE, (TransformParameterSpec) null); transforms.add(exclusiveTransform); Reference reference = signatureFactory.newReference("#" + objectId, digestMethod, transforms, REFERENCE_TYPE, null); references.add(reference); }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { // nothing to do here }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { // empty }
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { }
@SuppressWarnings("unchecked") public boolean isValidOOXMLSignature(XMLSignature xmlSignature, byte[] document) throws IOException, TransformerException, SAXException, ParserConfigurationException { // check c18n == http://www.w3.org/TR/2001/REC-xml-c14n-20010315 if (!xmlSignature.getSignedInfo().getCanonicalizationMethod().getAlgorithm() .equals(CanonicalizationMethod.INCLUSIVE)) { LOG.error("Invalid c18n method on OOXML Signature"); return false; } List<Reference> refs = xmlSignature.getSignedInfo().getReferences(); // check #idPackageObject reference Reference idPackageObjectRef = findReferenceFromURI(refs, "#idPackageObject"); if (null == idPackageObjectRef) { LOG.error("No \"idPackageObject\" reference found!"); return false; } // check idPackageObject element XMLObject idPackageObject = findObject(xmlSignature, "idPackageObject"); if (null == idPackageObject) { LOG.error("No \"idPackageObject\" object found!"); return false; } if (!isIdPackageObjectValid(xmlSignature.getId(), idPackageObject, document)) { LOG.error("Invalid \"idPackageObject\"."); return false; } // check #idOfficeObject reference Reference idOfficeObjectRef = findReferenceFromURI(refs, "#idOfficeObject"); if (null == idOfficeObjectRef) { LOG.error("No \"idOfficeObject\" reference found!"); return false; } // check idOfficeObject element XMLObject idOfficeObject = findObject(xmlSignature, "idOfficeObject"); if (null == idOfficeObject) { LOG.error("No \"idOfficeObject\" object found!"); return false; } if (!isIdOfficeObjectValid(xmlSignature.getId(), idOfficeObject)) { LOG.error("Invalid \"idOfficeObject\"."); return false; } return true; }
public XMLObject newXMLObject(List content, String id, String mimeType, String encoding) { throw new UnsupportedOperationException(); }
/** * Returns the objects which must be taken into account for the mapping to * the camel message. * * @param input * references and objects * @return relevant objects for the mapping to camel message * @throws Exception * if an error occurs */ protected List<XMLObject> getObjectsForMessageMapping(Input input) throws Exception { //NOPMD return input.getObjects(); }
/** * Returns the objects. If there were several signatures in the XML * document then all objects of all signatures are returned. * * @return objects, cannot be <code>null</code> */ List<XMLObject> getObjects();
/** * This method is being invoked by the XML signature service engine during * pre-sign phase. Via this method a signature facet implementation can add * signature facets to an XML signature. * * @param signatureFactory * @param document * @param signatureId * @param signingCertificateChain * the optional signing certificate chain * @param references * @param objects * @throws InvalidAlgorithmParameterException * @throws NoSuchAlgorithmException */ void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException;