Search in sources :

Example 1 with XMLObject

use of javax.xml.crypto.dsig.XMLObject in project camel by apache.

the class XmlSignerProcessor method getObjects.

protected List<? extends XMLObject> getObjects(XmlSignatureProperties.Input input, XmlSignatureProperties.Output properties) throws Exception {
    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;
}
Also used : ArrayList(java.util.ArrayList) XMLObject(javax.xml.crypto.dsig.XMLObject)

Example 2 with XMLObject

use of javax.xml.crypto.dsig.XMLObject in project camel by apache.

the class XAdESSignatureProperties method get.

@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()) {
        // enveloping
        doc = (Document) parent;
    } else {
        // enveloped
        doc = parent.getOwnerDocument();
    }
    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;
}
Also used : Reference(javax.xml.crypto.dsig.Reference) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DOMStructure(javax.xml.crypto.dom.DOMStructure) XMLObject(javax.xml.crypto.dsig.XMLObject) Transform(javax.xml.crypto.dsig.Transform) Document(org.w3c.dom.Document)

Example 3 with XMLObject

use of javax.xml.crypto.dsig.XMLObject in project camel by apache.

the class DefaultXmlSignature2Message method addManifestReferencedObjects.

@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);
        }
    }
}
Also used : Reference(javax.xml.crypto.dsig.Reference) XMLObject(javax.xml.crypto.dsig.XMLObject) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Manifest(javax.xml.crypto.dsig.Manifest)

Example 4 with XMLObject

use of javax.xml.crypto.dsig.XMLObject in project camel by apache.

the class DefaultXmlSignature2Message method getNodeForMessageBodyInEnvelopingCase.

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;
}
Also used : Reference(javax.xml.crypto.dsig.Reference) Node(org.w3c.dom.Node) DOMStructure(javax.xml.crypto.dom.DOMStructure) XMLObject(javax.xml.crypto.dsig.XMLObject)

Example 5 with XMLObject

use of javax.xml.crypto.dsig.XMLObject in project poi by apache.

the class OOXMLSignatureFacet method addManifestObject.

protected void addManifestObject(Document document, List<Reference> references, List<XMLObject> objects) throws XMLSignatureException {
    List<Reference> manifestReferences = new ArrayList<Reference>();
    addManifestReferences(manifestReferences);
    Manifest manifest = getSignatureFactory().newManifest(manifestReferences);
    // really has to be this value.
    String objectId = "idPackageObject";
    List<XMLStructure> objectContent = new ArrayList<XMLStructure>();
    objectContent.add(manifest);
    addSignatureTime(document, objectContent);
    XMLObject xo = getSignatureFactory().newXMLObject(objectContent, objectId, null, null);
    objects.add(xo);
    Reference reference = newReference("#" + objectId, null, XML_DIGSIG_NS + "Object", null, null);
    references.add(reference);
}
Also used : Reference(javax.xml.crypto.dsig.Reference) ArrayList(java.util.ArrayList) XMLObject(javax.xml.crypto.dsig.XMLObject) XMLStructure(javax.xml.crypto.XMLStructure) Manifest(javax.xml.crypto.dsig.Manifest)

Aggregations

XMLObject (javax.xml.crypto.dsig.XMLObject)12 Reference (javax.xml.crypto.dsig.Reference)10 ArrayList (java.util.ArrayList)8 XMLStructure (javax.xml.crypto.XMLStructure)5 DOMStructure (javax.xml.crypto.dom.DOMStructure)5 Manifest (javax.xml.crypto.dsig.Manifest)4 Transform (javax.xml.crypto.dsig.Transform)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 XMLSignature (javax.xml.crypto.dsig.XMLSignature)2 XMLSignatureException (javax.xml.crypto.dsig.XMLSignatureException)2 XMLSignatureFactory (javax.xml.crypto.dsig.XMLSignatureFactory)2 Node (org.w3c.dom.Node)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1