Created
August 15, 2018 06:12
-
-
Save goofmint/85966be41ed83c3897ce001ae206653d 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
let verifyAuthenticatorAttestationResponse = (webAuthnResponse) => { | |
let attestationBuffer = base64url.toBuffer(webAuthnResponse.response.attestationObject); | |
let ctapMakeCredResp = cbor.decodeAllSync(attestationBuffer)[0]; | |
let response = {'verified': false}; | |
if(ctapMakeCredResp.fmt === 'fido-u2f') { | |
let authrDataStruct = parseMakeCredAuthData(ctapMakeCredResp.authData); | |
if(!(authrDataStruct.flags & U2F_USER_PRESENTED)) | |
throw new Error('User was NOT presented durring authentication!'); | |
let clientDataHash = hash(base64url.toBuffer(webAuthnResponse.response.clientDataJSON)) | |
let reservedByte = Buffer.from([0x00]); | |
let publicKey = COSEECDHAtoPKCS(authrDataStruct.COSEPublicKey) | |
let signatureBase = Buffer.concat([reservedByte, authrDataStruct.rpIdHash, clientDataHash, authrDataStruct.credID, publicKey]); | |
let PEMCertificate = ASN1toPEM(ctapMakeCredResp.attStmt.x5c[0]); | |
let signature = ctapMakeCredResp.attStmt.sig; | |
response.verified = verifySignature(signature, signatureBase, PEMCertificate) | |
if(response.verified) { | |
response.authrInfo = { | |
fmt: 'fido-u2f', | |
publicKey: base64url.encode(publicKey), | |
counter: authrDataStruct.counter, | |
credID: base64url.encode(authrDataStruct.credID) | |
} | |
} | |
} | |
return response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment