| 1 |
var ws = require('ws.js') |
| 2 |
, fs = require('fs') |
| 3 |
, sec = ws.Security |
| 4 |
, X509BinarySecurityToken = ws.X509BinarySecurityToken |
| 5 |
, FileKeyInfo = require('xml-crypto').FileKeyInfo |
| 6 |
|
| 7 |
|
| 8 |
var x509 = new X509BinarySecurityToken( |
| 9 |
{ "key": fs.readFileSync("client.pem").toString()}) |
| 10 |
var signature = new ws.Signature(x509) |
| 11 |
signature.addReference("//*[local-name(.)='Body']") |
| 12 |
signature.addReference("//*[local-name(.)='Timestamp']") |
| 13 |
|
| 14 |
//validateResponseSignature determines if we should validate any incoming signature. |
| 15 |
var sec = new ws.Security({"validateResponseSignature": true}, |
| 16 |
[ x509, |
| 17 |
signature |
| 18 |
]) |
| 19 |
|
| 20 |
//only required if you specified validateResponseSignature as true |
| 21 |
sec.options.responseKeyInfoProvider = new FileKeyInfo("server_public.pem") |
| 22 |
|
| 23 |
var handlers = |
| 24 |
[ new ws.Addr("http://www.w3.org/2005/08/addressing") |
| 25 |
, sec |
| 26 |
, new ws.Http() |
| 27 |
] |
| 28 |
|
| 29 |
request = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" + |
| 30 |
"<Header />" + |
| 31 |
"<Body>" + |
| 32 |
"<GetData xmlns='http://tempuri.org/'>" + |
| 33 |
"<value>123</value>" + |
| 34 |
"</GetData>" + |
| 35 |
"</Body>" + |
| 36 |
"</Envelope>" |
| 37 |
|
| 38 |
var ctx = { request: request |
| 39 |
, url: "http://localhost:7171/Service/sign_body_timestamp_wsa" |
| 40 |
, action: "http://tempuri.org/IService/GetData" |
| 41 |
, contentType: "text/xml" |
| 42 |
} |
| 43 |
|
| 44 |
ws.send(handlers, ctx, function(ctx) { |
| 45 |
console.log("status " + ctx.statusCode) |
| 46 |
console.log("messagse " + ctx.response) |
| 47 |
}) |