diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-18 17:52:06 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-18 17:52:06 -0700 |
commit | 6d086ecb8bbe6e382bf3960a3b0757489a38e78a (patch) | |
tree | c7502fa004b8dd78d16bd19cbb0a77d29a3af464 /src/helpers/parseAttestationAuthData.ts | |
parent | 3cd5df6f64f070c55190ecae4ba978ac4746dd10 (diff) |
Add more helpers and types
Diffstat (limited to 'src/helpers/parseAttestationAuthData.ts')
-rw-r--r-- | src/helpers/parseAttestationAuthData.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/helpers/parseAttestationAuthData.ts b/src/helpers/parseAttestationAuthData.ts new file mode 100644 index 0000000..951c0af --- /dev/null +++ b/src/helpers/parseAttestationAuthData.ts @@ -0,0 +1,63 @@ +import { ParsedAttestationAuthData } from "@lib/types"; + +/** + * Make sense of the authData buffer contained in an Attestation + */ +export default function parseAttestationAuthData(authData: Buffer): ParsedAttestationAuthData { + console.log('parsing attestation auth data'); + + let intBuffer = authData; + + const rpIdHash = intBuffer.slice(0, 32); + intBuffer = intBuffer.slice(32); + + const flagsBuf = intBuffer.slice(0, 1); + intBuffer = intBuffer.slice(1); + + const flagsInt = flagsBuf[0]; + + const flags = { + up: !!(flagsInt & 0x01), + uv: !!(flagsInt & 0x04), + at: !!(flagsInt & 0x40), + ed: !!(flagsInt & 0x80), + flagsInt, + }; + + console.debug('flags:', flags); + + const counterBuf = intBuffer.slice(0, 4); + intBuffer = intBuffer.slice(4); + + const counter = counterBuf.readUInt32BE(0); + + let aaguid: Buffer | undefined = undefined; + let credentialID: Buffer | undefined = undefined; + let COSEPublicKey: Buffer | undefined = undefined; + + if (flags.at) { + aaguid = intBuffer.slice(0, 16); + intBuffer = intBuffer.slice(16); + + const credIDLenBuf = intBuffer.slice(0, 2); + intBuffer = intBuffer.slice(2); + + const credIDLen = credIDLenBuf.readUInt16BE(0); + + credentialID = intBuffer.slice(0, credIDLen); + intBuffer = intBuffer.slice(credIDLen); + + COSEPublicKey = intBuffer; + } + + return { + rpIdHash, + flagsBuf, + flags, + counter, + counterBuf, + aaguid, + credentialID, + COSEPublicKey, + }; +} |