Skip to content

Commit

Permalink
Merge commit 'da829fc0216ed961ea7cb8a6234df65a60f51114' into CB/query…
Browse files Browse the repository at this point in the history
…-string-signing

* commit 'da829fc0216ed961ea7cb8a6234df65a60f51114':
  Use crypto.randomBytes for ID generation (node-saml#235)
  BugFix: Fail gracefully when SAML Response is invalid. Fixes node-saml#238
  docs: Improve docs for privateKey format. Ref node-saml#230
  Drop support for Node versions < 4.
  v0.20.2
  • Loading branch information
cjbarth committed Sep 10, 2018
2 parents 511a7f8 + da829fc commit f266c34
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "iojs"
- "4.0"
- "stable"

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ The `decryptionCert` argument should be a public certificate matching the `decry

Passport-SAML uses the HTTP Redirect Binding for its `AuthnRequest`s (unless overridden with the `authnRequestBinding` parameter), and expects to receive the messages back via the HTTP POST binding.

Authentication requests sent by Passport-SAML can be signed using RSA-SHA1. To sign them you need to provide a private key in the PEM format via the `privateCert` configuration key. For example:
Authentication requests sent by Passport-SAML can be signed using RSA-SHA1. To sign them you need to provide a private key in the PEM format via the `privateCert` configuration key. The certificate
should start with `-----BEGIN PRIVATE KEY-----` on its own line and end with `-----END PRIVATE KEY-----` on its own line.

For example:

```javascript
privateCert: fs.readFileSync('./cert.pem', 'utf-8')
Expand Down
27 changes: 15 additions & 12 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ SAML.prototype.getCallbackUrl = function (req) {
};

SAML.prototype.generateUniqueID = function () {
var chars = "abcdef0123456789";
var uniqueID = "";
for (var i = 0; i < 20; i++) {
uniqueID += chars.substr(Math.floor((Math.random()*15)), 1);
}
return uniqueID;
return crypto.randomBytes(10).toString('hex');
};

SAML.prototype.generateInstant = function () {
Expand Down Expand Up @@ -512,15 +507,23 @@ SAML.prototype.validateSignature = function (fullXml, currentNode, cert) {

SAML.prototype.validatePostResponse = function (container, callback) {
var self = this;
var xml = new Buffer(container.SAMLResponse, 'base64').toString('utf8');
var doc = new xmldom.DOMParser().parseFromString(xml);

var inResponseTo = xpath(doc, "/*[local-name()='Response']/@InResponseTo");
if(inResponseTo){
inResponseTo = inResponseTo.length ? inResponseTo[0].nodeValue : null;
}
var xml, doc, inResponseTo;

Q.fcall(function(){
xml = new Buffer(container.SAMLResponse, 'base64').toString('utf8');
doc = new xmldom.DOMParser({
}).parseFromString(xml);

if (!doc.hasOwnProperty('documentElement'))
throw new Error('SAMLResponse is not valid base64-encoded XML');

inResponseTo = xpath(doc, "/*[local-name()='Response']/@InResponseTo");

if(inResponseTo){
inResponseTo = inResponseTo.length ? inResponseTo[0].nodeValue : null;
}

if(self.options.validateInResponseTo){
if (inResponseTo) {
return Q.ninvoke(self.cacheProvider, 'get', inResponseTo)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-saml",
"version": "0.20.1",
"version": "0.20.2",
"license" : "MIT",
"keywords": [
"saml",
Expand Down Expand Up @@ -45,7 +45,7 @@
"sinon": "^2.1.0"
},
"engines": {
"node": ">= 0.10.0"
"node": ">= 4"
},
"scripts": {
"test": "mocha",
Expand Down
17 changes: 17 additions & 0 deletions test/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f266c34

Please sign in to comment.