-
-
Save kypflug/36d380f47d54196edf26cea6a829de9f to your computer and use it in GitHub Desktop.
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
var jwkToPem = require('jwk-to-pem') | |
var crypto = require('crypto'); | |
var webAuthAuthenticator = { | |
validateSignature: function (publicKey, clientData, authnrData, signature, challenge) { | |
// Make sure the challenge in the client data | |
// matches the expected challenge | |
var c = new Buffer(clientData, 'base64'); | |
var cc = JSON.parse(c.toString().replace(/\0/g,'')); | |
if(cc.challenge != challenge) return false; | |
// Hash data with sha256 | |
const hash = crypto.createHash('sha256'); | |
hash.update(c); | |
var h = hash.digest(); | |
// Verify signature is correct for authnrData + hash | |
var verify = crypto.createVerify('RSA-SHA256'); | |
verify.update(new Buffer(authnrData,'base64')); | |
verify.update(h); | |
return verify.verify(jwkToPem(JSON.parse(publicKey)), signature, 'base64'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment