-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
3,353 additions
and
2,718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"canonicalized", | ||
"codecov", | ||
"feide", | ||
"HMAC", | ||
"reserialization", | ||
"wsfederation", | ||
"wssecurity" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,43 @@ | ||
var select = require('xml-crypto').xpath | ||
, dom = require('@xmldom/xmldom').DOMParser | ||
, SignedXml = require('xml-crypto').SignedXml | ||
, FileKeyInfo = require('xml-crypto').FileKeyInfo | ||
, fs = require('fs') | ||
|
||
function signXml(xml, xpath, key, dest) | ||
{ | ||
var sig = new SignedXml() | ||
sig.signingKey = fs.readFileSync(key) | ||
sig.addReference(xpath) | ||
sig.computeSignature(xml) | ||
fs.writeFileSync(dest, sig.getSignedXml()) | ||
/* eslint-disable no-console */ | ||
|
||
var select = require("xml-crypto").xpath, | ||
dom = require("@xmldom/xmldom").DOMParser, | ||
SignedXml = require("xml-crypto").SignedXml, | ||
FileKeyInfo = require("xml-crypto").FileKeyInfo, | ||
fs = require("fs"); | ||
|
||
function signXml(xml, xpath, key, dest) { | ||
var sig = new SignedXml(); | ||
sig.signingKey = fs.readFileSync(key); | ||
sig.addReference(xpath); | ||
sig.computeSignature(xml); | ||
fs.writeFileSync(dest, sig.getSignedXml()); | ||
} | ||
|
||
function validateXml(xml, key) | ||
{ | ||
var doc = new dom().parseFromString(xml) | ||
var signature = select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0] | ||
var sig = new SignedXml() | ||
sig.keyInfoProvider = new FileKeyInfo(key) | ||
sig.loadSignature(signature.toString()) | ||
var res = sig.checkSignature(xml) | ||
if (!res) console.log(sig.validationErrors) | ||
function validateXml(xml, key) { | ||
var doc = new dom().parseFromString(xml); | ||
var signature = select( | ||
"/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", | ||
doc | ||
)[0]; | ||
var sig = new SignedXml(); | ||
sig.keyInfoProvider = new FileKeyInfo(key); | ||
sig.loadSignature(signature.toString()); | ||
var res = sig.checkSignature(xml); | ||
if (!res) console.log(sig.validationErrors); | ||
return res; | ||
} | ||
|
||
var xml = "<library>" + | ||
"<book>" + | ||
"<name>Harry Potter</name>" + | ||
"</book>" + | ||
"</library>" | ||
var xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</library>"; | ||
|
||
//sign an xml document | ||
signXml(xml, | ||
"//*[local-name(.)='book']", | ||
"client.pem", | ||
"result.xml") | ||
signXml(xml, "//*[local-name(.)='book']", "client.pem", "result.xml"); | ||
|
||
console.log("xml signed succesfully") | ||
console.log("xml signed successfully"); | ||
|
||
var signedXml = fs.readFileSync("result.xml").toString() | ||
console.log("validating signature...") | ||
var signedXml = fs.readFileSync("result.xml").toString(); | ||
console.log("validating signature..."); | ||
|
||
//validate an xml document | ||
if (validateXml(signedXml, "client_public.pem")) | ||
console.log("signature is valid") | ||
else | ||
console.log("signature not valid") | ||
if (validateXml(signedXml, "client_public.pem")) console.log("signature is valid"); | ||
else console.log("signature not valid"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
var select = require('xpath').select | ||
var select = require("xpath").select; | ||
|
||
module.exports = require('./lib/signed-xml') | ||
module.exports.xpath = function(node, xpath) { | ||
return select(xpath, node) | ||
} | ||
module.exports = require("./lib/signed-xml"); | ||
module.exports.xpath = function (node, xpath) { | ||
return select(xpath, node); | ||
}; |
Oops, something went wrong.