Search in sources :

Example 1 with DOMStructure

use of javax.xml.crypto.dom.DOMStructure 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 2 with DOMStructure

use of javax.xml.crypto.dom.DOMStructure in project camel by apache.

the class XmlSignatureHelper method getXslTranform.

/**
     * 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;
}
Also used : XSLTTransformParameterSpec(javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec) DOMStructure(javax.xml.crypto.dom.DOMStructure) Document(org.w3c.dom.Document)

Example 3 with DOMStructure

use of javax.xml.crypto.dom.DOMStructure 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 4 with DOMStructure

use of javax.xml.crypto.dom.DOMStructure in project jdk8u_jdk by JetBrains.

the class Marshal method main.

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());
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) KeyInfo(javax.xml.crypto.dsig.keyinfo.KeyInfo) Element(org.w3c.dom.Element) DOMStructure(javax.xml.crypto.dom.DOMStructure) Document(org.w3c.dom.Document) KeyInfoFactory(javax.xml.crypto.dsig.keyinfo.KeyInfoFactory)

Example 5 with DOMStructure

use of javax.xml.crypto.dom.DOMStructure in project poi by apache.

the class RelationshipTransformService method marshalParams.

@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
    LOG.log(POILogger.DEBUG, "marshallParams(parent,context)");
    DOMStructure domParent = (DOMStructure) parent;
    Element parentNode = (Element) domParent.getNode();
    // parentNode.setAttributeNS(XML_NS, "xmlns:mdssi", XML_DIGSIG_NS);
    Document doc = parentNode.getOwnerDocument();
    for (String sourceId : this.sourceIds) {
        RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();
        relRef.addNewRelationshipReference().setSourceId(sourceId);
        Node n = relRef.getRelationshipReference().getDomNode();
        n = doc.importNode(n, true);
        parentNode.appendChild(n);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) DOMStructure(javax.xml.crypto.dom.DOMStructure) RelationshipReferenceDocument(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.RelationshipReferenceDocument) Document(org.w3c.dom.Document) TransformDocument(org.w3.x2000.x09.xmldsig.TransformDocument) RelationshipsDocument(org.openxmlformats.schemas.xpackage.x2006.relationships.RelationshipsDocument) RelationshipReferenceDocument(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.RelationshipReferenceDocument)

Aggregations

DOMStructure (javax.xml.crypto.dom.DOMStructure)12 Element (org.w3c.dom.Element)7 XMLStructure (javax.xml.crypto.XMLStructure)5 Reference (javax.xml.crypto.dsig.Reference)5 XMLObject (javax.xml.crypto.dsig.XMLObject)5 ArrayList (java.util.ArrayList)4 Document (org.w3c.dom.Document)4 Node (org.w3c.dom.Node)4 SignatureProperties (javax.xml.crypto.dsig.SignatureProperties)3 SignatureProperty (javax.xml.crypto.dsig.SignatureProperty)3 Transform (javax.xml.crypto.dsig.Transform)3 X509Certificate (java.security.cert.X509Certificate)2 Map (java.util.Map)2 KeyInfo (javax.xml.crypto.dsig.keyinfo.KeyInfo)2 KeyInfoFactory (javax.xml.crypto.dsig.keyinfo.KeyInfoFactory)2 CTSignatureInfoV1 (com.microsoft.schemas.office.x2006.digsig.CTSignatureInfoV1)1 SignatureInfoV1Document (com.microsoft.schemas.office.x2006.digsig.SignatureInfoV1Document)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1