Skip to content

Commit

Permalink
Handle case of missing InResponseTo when validation is on
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth authored and markstos committed Sep 25, 2018
1 parent f7aab5c commit e483496
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/xml-signing-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This will help generate signing info for test cases.
// Simply fill in the data and run it to get <DigestValue /> and <SignatureValue />.

const crypto = require('crypto')

const private_key = `-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
`

const cert = `-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
`

const saml_message = ``

const signed_info = `<SignedInfo...</SignedInfo>`

const signer = crypto.createSign('RSA-SHA1');
signer.update(signed_info);
signer.end();

const signature = signer.sign(private_key)
const signature_b64 = signature.toString('base64')

const verifier = crypto.createVerify('RSA-SHA1')
verifier.update(signed_info)
verifier.end()

const verified = verifier.verify(cert, signature)

const hash = crypto.createHash('RSA-SHA1')
hash.update(saml_message, 'utf8')
const digest_b64 = hash.digest('base64')

console.log(JSON.stringify({
signature: signature_b64,
digest: digest_b64,
verified: verified,
}, null, 2))
2 changes: 2 additions & 0 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ SAML.prototype.validatePostResponse = function (container, callback) {
throw new Error('InResponseTo is not valid');
return Q();
});
} else {
throw new Error('InResponseTo is missing from response');
}
} else {
return Q();
Expand Down
54 changes: 54 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 e483496

Please sign in to comment.