diff --git a/lib/samlp.js b/lib/samlp.js index e568f16..0a53d96 100644 --- a/lib/samlp.js +++ b/lib/samlp.js @@ -5,6 +5,7 @@ var xtend = require('xtend'); var utils = require('./utils'); var templates = require('./templates'); var encoders = require('./encoders'); +var signers = require('./signers'); var PassportProfileMapper = require('./claims/PassportProfileMapper'); var constants = require('./constants'); @@ -29,27 +30,8 @@ function buildSamlResponse(options) { .replace(/>(\s*)<') //unindent .trim(); - var sig = new SignedXml(null, { - signatureAlgorithm: constants.ALGORITHMS.SIGNATURE[options.signatureAlgorithm] - }); - - sig.addReference( - constants.ELEMENTS.RESPONSE.SIGNATURE_LOCATION_PATH, - ["http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/2001/10/xml-exc-c14n#"], - constants.ALGORITHMS.DIGEST[options.digestAlgorithm]); - - sig.signingKey = options.key; - - var pem = encoders.removeHeaders(options.cert); - sig.keyInfoProvider = { - getKeyInfo: function (key, prefix) { - prefix = prefix ? prefix + ':' : prefix; - return "<" + prefix + "X509Data><" + prefix + "X509Certificate>" + pem + ""; - } - }; - - sig.computeSignature(cannonicalized, { prefix: options.signatureNamespacePrefix, location: { action: 'after', reference: "//*[local-name(.)='Issuer']" }}); - SAMLResponse = sig.getSignedXml(); + options.reference = constants.ELEMENTS.RESPONSE.SIGNATURE_LOCATION_PATH; + return signers.signXml(options, cannonicalized); } return SAMLResponse; diff --git a/package.json b/package.json index b768230..ab7f8b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "samlp", - "version": "3.4.0", + "version": "3.4.1", "description": "SAML Protocol server middleware", "main": "lib/index.js", "scripts": { @@ -20,24 +20,24 @@ "license": "mit", "dependencies": { "@auth0/thumbprint": "0.0.6", - "ejs": "2.5.5", + "ejs": "2.6", "flowstate": "^0.4.0", "querystring": "^0.2.0", - "saml": "^0.12.1", - "xml-crypto": "^0.10.1", - "xmldom": "auth0/xmldom#v0.1.19-auth0_1", - "xpath": "0.0.5", - "xtend": "^1.0.3" + "saml": "0.13", + "xml-crypto": "1.4", + "xmldom": "github:auth0/xmldom#v0.1.19-auth0_1", + "xpath": "0.0.27", + "xtend": "4" }, "devDependencies": { - "body-parser": "^1.15.2", - "chai": "~1.5.0", - "cheerio": "~0.10.7", - "express": "~3.1.0", - "express-session": "^1.14.2", - "istanbul": "^0.4.5", - "mocha": "~1.8.1", - "request": "~2.14.0", - "uid2": "0.0.3" + "body-parser": "^1", + "chai": "4", + "cheerio": "^0.22.0", + "express": "^3", + "express-session": "^1", + "istanbul": "^0.4", + "mocha": "1", + "request": "~2.14", + "uid2": "0" } } diff --git a/test/samlp.tests.js b/test/samlp.tests.js index 264dddf..b0741c3 100644 --- a/test/samlp.tests.js +++ b/test/samlp.tests.js @@ -596,7 +596,7 @@ describe('samlp', function () { it('should return signature with the specified signatureNamespacePrefix inside the response', function(){ var doc = new xmldom.DOMParser().parseFromString(samlResponse); - var signature = doc.documentElement.getElementsByTagName('ds:Signature'); + var signature = doc.documentElement.getElementsByTagName('Signature'); expect(signature[0].parentNode.nodeName).to.equal('samlp:Response'); }); });