DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Coding
  3. JavaScript
  4. WCF.js Message Level Signature? Check.

WCF.js Message Level Signature? Check.

Yaron Naveh user avatar by
Yaron Naveh
·
May. 27, 12 · Interview
Like (0)
Save
Tweet
Share
3.77K Views

Join the DZone community and get the full member experience.

Join For Free

This is a very exciting moment for Wcf.js. It now supports one of the WS-Security most common scenarios - x.509 digital signatures. This is the first WS-Security implementation ever in javascript to support this. This implementation relies on xml-crypto on which I told you last time.

Look at any of the following Wcf bindings:

<wsHttpBinding>
  <binding name="NewBinding1">
    <security>
      <message clientCredentialType="Certificate" />
    </security>
  </binding>
</wsHttpBinding>
<customBinding>
  <binding name="NewBinding0">
    <textMessageEncoding />
    <security authenticationMode="MutualCertificate"
              messageSecurityVersion="WSSecurity10...">
      <secureConversationBootstrap />
    </security>
    <httpTransport />
  </binding>
</customBinding>

Assume only signatures are used (no encryption):

[ServiceBehavior(ProtectionLevel=ProtectionLevel.SignOnly)]

Then a soap request would look like this:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" ... >
  <Header>
    <ws:Action>http://tempuri.org/IService/GetData</ws:Action>
    <ws:To>http://localhost:8888/</ws:To>
    <ws:MessageID>ca62b7d7-4f74-75ed-9f5c-b09b173f6747</ws:MessageID>
    <ws:ReplyTo>
      <ws:Address>...</ws:Address>
    </ws:ReplyTo>
    <o:Security>
      <u:Timestamp xmlns:wsu="..." wsu:Id="_1">
        <u:Created>2012-05-25T12:18:38Z</u:Created>
        <u:Expires>2012-05-25T12:23:38Z</u:Expires>
      </u:Timestamp>
      <o:BinarySecurityToken ValueType="..." EncodingType="..." u:Id="sec_0">
         MIIBxDCCAWI...
      </o:BinarySecurityToken>
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
          <CanonicalizationMethod Algorithm="...xml-exc-c14n#" />
          <SignatureMethod Algorithm="...rsa-sha1" />
          <Reference URI="#_0">
            <Transforms>
              <Transform Algorithm=".../xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="...xmldsig#sha1" />
            <DigestValue>fxQc0PEh2GHA43IXltm6gjbccsA=</DigestValue>
          </Reference>
          <Reference URI="#_1">
            <Transforms>
              <Transform Algorithm=".../xml-exc-c14n#" />
            </Transforms>
            <DigestMethod Algorithm="...xmldsig#sha1" />
            <DigestValue>L+vrfEszbn2ZtXiWfNyDG8nM1e8=</DigestValue>
          </Reference>
        </SignedInfo>
        <SignatureValue>AcOb1KJHpyQnnChEZFEL7g+LEXnv...</SignatureValue>
        <KeyInfo>
          <o:SecurityTokenReference>
            <o:Reference URI="#sec_0" ValueType="..." />
          </o:SecurityTokenReference>
        </KeyInfo>
      </Signature>
    </o:Security>
  </Header>
  <Body xmlns:wsu="..." wsu:Id="_0">
    <GetData xmlns="http://tempuri.org/">
      <value>123</value>
    </GetData>
  </Body>
</Envelope>

You can now interoperate with such services from javascript using Wcf.js with this code:

var wcf = require('wcf.js')
  , fs = require("fs")
  , TextMessageEncodingBindingElement = wcf.TextMessageEncodingBindingElement
  , HttpTransportBindingElement = wcf.HttpTransportBindingElement
  , SecurityBindingElement = wcf.SecurityBindingElement
  , CustomBinding = wcf.CustomBinding
  , Proxy = wcf.Proxy

var binding = new CustomBinding(
    [ new SecurityBindingElement({AuthenticationMode: "MutualCertificate"})
    , new TextMessageEncodingBindingElement(
                                 {MessageVersion: "Soap11WSAddressing10"})
    , new HttpTransportBindingElement()
    ])

var proxy = new Proxy(binding, "http://localhost:7171/Service")

proxy.ClientCredentials.ClientCertificate.Certificate =
        fs.readFileSync("client.pem").toString()

var message = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" +
                    "<Header />" +
                      "<Body>" +
                        "<GetData xmlns='http://tempuri.org/'>" +
                          "<value>123</value>" +
                        "</GetData>" +
                      "</Body>" +
                  "</Envelope>"

proxy.send(message, "http://tempuri.org/IService/GetData",
  function(message, ctx) {
    console.log(ctx)
  })

Note that a pem formatted certificate needs to be used. Wcf likes pfx formats more, so check out the instructions here on how to do the conversion.

You should also be aware that Wcf.js by default does no validate incoming signatures from the server. If you wish to validate them check out the sample here.

JavaScript Implementation Moment Binding (linguistics) Requests

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Power of Zero-Knowledge Proofs: Exploring the New ConsenSys zkEVM
  • Key Elements of Site Reliability Engineering (SRE)
  • DevOps vs Agile: Which Approach Will Win the Battle for Efficiency?
  • How To Use Linux Containers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: