Skip to content

Instantly share code, notes, and snippets.

@SphinxKnight
Created March 18, 2019 17:29
Show Gist options
  • Save SphinxKnight/ce15fe08bb925d6359f4268746589827 to your computer and use it in GitHub Desktop.
Save SphinxKnight/ce15fe08bb925d6359f4268746589827 to your computer and use it in GitHub Desktop.
WebAuthn tests -WIP-
function pkCcreate(){
var publicKey = {
challenge: new Uint8Array([10,32,47,4,13,3,37,11,13,47,18,46,6,51,11,27,13,25,42,25,19,36,35,0,17,46]),
rp: {
name: "Example CORP",
id : "localhost"
},
user: {
id: new Uint8Array(26),
name: "jdoe@example.com",
displayName: "John Doe",
},
pubKeyCredParams: [
{
type: "public-key",
alg: -7
}
]
};
navigator.credentials.create({ publicKey })
.then(function (newCredentialInfo) {
// send attestation response and client extensions
// to the server to proceed with the registration
// of the credential
const txDecoder = new TextDecoder("utf-8");
console.log("cred properties");
console.log("type", newCredentialInfo.type);
console.log("id", newCredentialInfo.id);
console.log("rawId", newCredentialInfo.rawId);
const response = newCredentialInfo.response;
console.log("cred.response properties");
if(newCredentialInfo.response.getTransports){
console.log("getTransports() is there");
console.log("transports are:",response.getTransports());
}
console.log("attestationResponse.clientDataJSON", JSON.parse(txDecoder.decode(response.clientDataJSON)));
console.log("cred.response.attestationObject");
var attestationObject = CBOR.decode(response.attestationObject);
console.log("fmt", attestationObject.fmt);
console.log("attStmt", attestationObject.attStmt);
// flags
console.log("flags");
var offset = attestationObject.authData.byteOffset;
var currentOffset = 0;
var sizeHash = 32;
var rpIdHash = attestationObject.authData.slice(currentOffset,(currentOffset += sizeHash));
var shaHash = "".concat(...Array.from(rpIdHash).map(e => e.toString(16)));
console.log("rpIdHash is: ",shaHash);
var sizeFlag = 1;
var flagsNumber = attestationObject.authData.slice(currentOffset,(currentOffset += sizeFlag))[0];
var flagsArray = flagsNumber.toString(2).split("").reverse();
console.table(flagsArray);
var sizeCounter = 4;
var counter = (new DataView(attestationObject.authData.buffer, currentOffset + offset, sizeCounter)).getInt32();
currentOffset += sizeCounter;
console.log("signCount is:", counter);
var sizeAaguid = 16;
var aaguid = attestationObject.authData.slice(currentOffset,currentOffset += sizeAaguid);
var strAaguid = "".concat(...Array.from(aaguid).map(e => e.toString(16).padStart(2,"0")));
console.log("aaguid", strAaguid)
var sizeSizeCred = 2;
var sizeCred = (new DataView(attestationObject.authData.buffer, currentOffset + offset, sizeSizeCred)).getInt16();
currentOffset += sizeSizeCred;
console.log("credIdLength", sizeCred);
var credentialId = attestationObject.authData.slice(currentOffset, (currentOffset += sizeCred));
var strCredentialId = "".concat(...Array.from(credentialId).map(e => e.toString(16).padStart(2,"0")));
console.log("credentialId",strCredentialId);
var credPK = CBOR.decode(attestationObject.authData.buffer.slice(offset + currentOffset));
console.log(credPK);
// var cose =
// // Does Chrome support extensions ?
}).catch(function (err) {
console.error(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment