No announcement yet.

Web Service sender and WSSE

  • Filter
  • Time
  • Show
Clear All
new posts

  • Web Service sender and WSSE

    We need to digitally sign a timestamp within a SOAP message. Is this doable from within Mirth? We have the SSH extension but I don't know whether it handles this.


    Here's an example message we've been provided; presumably it is the Signature tag that we'll need to generate based on the message's timestamp:
    <soap:Envelope xmlns:soap="" xmlns:urn="urn:cdc:iisb:2011">
    <wsse:Security xmlns:wsse="" xmlns:wsu="">
    <ds:Signature Id="SIG-D8234953C823AFAE2415536312716865" xmlns:ds="">
    <ds:CanonicalizationMethod Algorithm="">
    <ec:InclusiveNamespaces PrefixList="soap urn" xmlns:ec=""/>
    <ds:SignatureMethod Algorithm=""/>
    <ds:Reference URI="#TS-D8234953C823AFAE2415536312715641">
    <ds:Transform Algorithm="">
    <ec:InclusiveNamespaces PrefixList="wsse soap urn" xmlns:ec=""/>
    <dsigestMethod Algorithm=""/>
    <dsigestValue>Content Redacted
    <ds:SignatureValue>Content Redacted</ds:SignatureValue>
    <ds:KeyInfo Id="KI-D8234953C823AFAE2415536312716723">
    <wsse:SecurityTokenReference wsu:Id="STRD8234953C823AFAE2415536312716744">
    <wsse:KeyIdentifier EncodingType="" ValueType="">
    Content Redacted
    <wsu:Timestamp wsu:Id="TS-D8234953C823AFAE2415536312715641">
    <urn:username>Content Redacted – User name provided by DOH</urn:username>
    <urnassword>Content Redacted – Password provided by DOH</urnassword>
    <urn:facilityID>Content Redacted – Facility ID provided by OHP</urn:facilityID>
    <urn:hl7Message>Content Redacted – Message content information available DOH


  • #2
    It's likely doable. Most things are.

    I assume you meant the SSL (not SSH) extension, and as far as I know that is only for setting up encrypted tunnels, not for digital signatures.

    I'm afraid I don't know enough about your requirements to give you a definite answer.


    • #3
      Yes, SSL extension. Thank you so much. Is anyone else able to offer a definite answer?


      • #4
        You don't have the requirements of what you're trying to do?


        • #5
          The requirement is to apply a digital signature to fields including the timestamp, as described in WSSE, and include it in the SOAP message.

          As an aside, when you cannot actually be helpful, there is absolutely no need to post.


          • #6
            Hi mitch_nchin

            Did you find a solution to sign a timestamp ?

            I have the same problem, add a signed timestamp in SOAP WSS request.

            Thanks for help


            • #7
              Just an FYI we did add this ability with a new commercial extension in 3.6, the Interoperability Connector Suite. The NHIN-compliant assertion and timestamp are both automatically signed, and it integrates with the SSL Manager so you can choose which local cert/keypair you want to sign with.

              Otherwise, I would look into a third-party library like CryptoJS. I think you should be able to create signatures and set them in the SOAP header with that.
              Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

              Nicholas Rupley
              Work: 949-237-6069
              Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

              - How do I foo?
              - You just bar.


              • #8
                Hi folks,

                I’m not sure if you found a solution that works for you yet, but you should be able to implement the functionality you’re describing here using the Java XML-DSig API, which is available pretty much out of the box with commercial and open source java implementations (and accessible via Mirth Connect). That message envelop you initially included looks strikingly similar to the requirements defined by WAIIS/OneHealthPort, which I think I ended up implementing something like:

                // Generate our dynamic message values
                var timestampId = UUIDGenerator.getUUID();
                var createdTimestamp = new Date().toISOString();
                var expiresTimestamp = new Date((new Date()).getTime() + 1000*10).toISOString();
                var hl7Message = xmlToHL7(msg);
                var soapEnvelope = "<soap:Envelope xmlns:soap=\"\" xmlns:urn=\"urn:cdc:iisb:2011\">" +
                					"<soap:Header>" +
                						"<wsse:Security xmlns:wsse=\"\" xmlns:wsu=\"\">" +
                							"<wsu:Timestamp wsu:Id=\"" + timestampId + "\">" +
                								"<wsu:Created>" + createdTimestamp + "</wsu:Created>" +
                								"<wsu:Expires>" + expiresTimestamp + "</wsu:Expires>" +
                							"</wsu:Timestamp>" +
                						"</wsse:Security>" +
                					"</soap:Header>" +
                					"<soap:Body>" +
                						"<urn:submitSingleMessage>" +
                							"<urn:username>username</urn:username>" +
                							"<urn:password>password</urn:password>" +
                							"<urn:facilityID>facility</urn:facilityID>" +
                							"<urn:hl7Message><![CDATA[" + hl7Message +"]]></urn:hl7Message>" +
                						"</urn:submitSingleMessage>" +
                					"</soap:Body>" +
                var soapString = new java.lang.String(soapEnvelope);
                // Build our XML DOM for signature
                var documentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
                var document = documentBuilderFactory.newDocumentBuilder().parse(new"utf-8")));
                // Configure Digital Signature utilities for required crypto operations
                var xmlDsigFactory = javax.xml.crypto.dsig.XMLSignatureFactory.getInstance("DOM");
                var parameterSpec = new javax.xml.crypto.dsig.spec.ExcC14NParameterSpec();
                var reference = xmlDsigFactory.newReference
                	"#" + timestampId,
                	xmlDsigFactory.newDigestMethod(javax.xml.crypto.dsig.DigestMethod.SHA1, null),
                	java.util.Collections.singletonList(xmlDsigFactory.newTransform("", parameterSpec)),
                	null, //type
                	null //id
                var signedInfo = xmlDsigFactory.newSignedInfo
                	xmlDsigFactory.newSignatureMethod(javax.xml.crypto.dsig.SignatureMethod.RSA_SHA1, null),
                // Fetch our certificate and key
                var certificate;
                	var inputStream = new“/path/to/your/cert”);
                	var certificateFactory ="X.509");
                	certificate = certificateFactory.generateCertificate(inputStream);
                	if (inputStream != null)
                var privateKey;
                var keyFactory ="RSA");
                var keySpec = new“/path/to/your/pkcs8”).toPath()));
                privateKey = keyFactory.generatePrivate(keySpec);
                // Generate the KeyInfo for our signature
                var keyInfoFactory = xmlDsigFactory.getKeyInfoFactory();
                var x509Content = new java.util.ArrayList();
                var x509Data = keyInfoFactory.newX509Data(x509Content);
                var keyInfo = keyInfoFactory.newKeyInfo(java.util.Collections.singletonList(x509Data));
                // Sign the document (timestamp element)
                var timestampElement = document.getElementsByTagNameNS("", "Timestamp").item(0);
                var securityElement = document.getElementsByTagNameNS("", "Security").item(0);
                var domSignContext = new javax.xml.crypto.dsig.dom.DOMSignContext(privateKey, securityElement);
                domSignContext.setIdAttributeNS(timestampElement,"", "Id");
                var xmlSignature = xmlDsigFactory.newXMLSignature(signedInfo, keyInfo);
                // Define any formatting preferences get the signed document as a string
                var transformerFactory = javax.xml.transform.TransformerFactory.newInstance();
                var transformer = transformerFactory.newTransformer();
                transformer.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
                var stringWriter = new;
                transformer.transform(new javax.xml.transform.dom.DOMSource(document), new;
                channelMap.put("soapMessage", stringWriter.toString());
                Obviously, you would want to adapt the above code to your specific use-case/requirements (transforms, canonicalization methods, keyinfo types, etc.), but it ought to provide some sense of how you could leverage the provided XML-DSig utilities to get it done. The transformer above could potentially operate as a destination transformer, with a source connector that polls files, or gets hl7v2 messages over MLLP, etc. One drawback is that you don't get to leverage the fancy Mirth features that come from WDSL-generated SOAP Envelopes in the destination connector (the example above then puts the message body to the channel map, which then makes it available to an HTTP Sender which is manually configured to invoke the expected SOAP operation). There's an old how-to on the Java dsig API here:

                Fortunately I don't think much has changed in there since 2007...


                • #9
                  Just seeing this. THANK YOU skirby!!