Skip to content

Commit

Permalink
temp debugger page
Browse files Browse the repository at this point in the history
  • Loading branch information
dagnelies committed Oct 11, 2024
1 parent 7ccda42 commit 5804ab2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 86 deletions.
14 changes: 9 additions & 5 deletions docs/demos/debugger.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<script defer src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<script defer src="https://unpkg.com/[email protected]/dist/buefy.min.js"></script>
<script defer type="module" src="js/playground.js"></script>
<script defer type="module" src="js/debugger.js"></script>
</head>
<body>

Expand Down Expand Up @@ -43,20 +43,24 @@ <h2 class="title">Signature validation</h2>
</b-field>

<b-field label="PublicKey" horizontal>
<b-input v-model="verification.publicKey" type="textarea"></b-input>
<div class="hint">The public key created during registration.</div>
<b-input v-model="verification.publicKey" type="textarea" @input="isKeyValid = null"></b-input>
<div class="hint">
<b-button @click="verifyKey()">Verify key</b-button>
<b-message type="is-success" v-if="isKeyValid === true">Valid {{verification.algorithm}} key</b-message>
<b-message type="is-danger" v-if="isKeyValid === false">Invalid {{verification.algorithm}} key</b-message>
</div>
</b-field>

<hr/>

<b-field label="AuthenticatorData" horizontal>
<b-input v-model="verification.authenticatorData" type="textarea"></b-input>
<div class="hint"><pre v-if="verification.authenticatorData">{{parseAuthData(verification.authenticatorData)}}</pre></div>
<div class="hint"><pre v-if="verification.authenticatorData">{{parsedAuthData}}</pre></div>
</b-field>

<b-field label="ClientData" horizontal>
<b-input v-model="verification.clientData" type="textarea"></b-input>
<div class="hint"><pre v-if="verification.clientData">{{parseClientData(verification.clientData)}}</pre></div>
<div class="hint"><pre v-if="verification.clientData">{{parsedClientData}}</pre></div>
</b-field>

<b-field label="Signature" horizontal>
Expand Down
112 changes: 31 additions & 81 deletions docs/demos/js/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,7 @@ const app = new Vue({
el: '#app',
data: {
origin: document.location.origin,
registration: {
options: {
user: "Arnaud",
challenge: webauthn.server.randomChallenge(),
hints: [],
userVerification: 'preferred',
discoverable: 'preferred',
timeout: 60000,
attestation: true
},
json: null,
result: null
},
authentication: {
credentialId: null,
options: {
challenge: webauthn.server.randomChallenge(),
hints: [],
authenticatorType: 'auto',
userVerification: 'required',
timeout: 60000,
allowCredentials: []
},
json: null,
result: null
},
isKeyValid: null,
verification: {
publicKey: "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWyyMt1l16_1rzDP63Ayw9EFpn1VbSt4NSJ7BOsDzqed5Z3aTfQSvzPBPHb4uYQuuckOKRbdoH9S0fEnSvNxpRg==", // null,
//"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzXUir6UgELFeM9il6id2vgZ1sWbZTk4C5JLIiMpg7lywwTRdp0i+lPP9rEdzcmwKwRLh5QT8DlPFQuKrUc8eXb9r+RPq/CvVOxVCqdK6A9fg0PDnvA3k7c5Ax5V5n/HcSw/uXVAzwstxQsbV5pOk0JDtys7rKiPjdO+XH5TbANNJE7PsS5j90zHLKNQaSybgF8V0v4Oz4I9u7IjVQKEz2V56E4Qfj/D7g0PCu63M5mNz5bGsmUzg5XwSRIaG3J3kDTuyTTGjPYhTnYFyWYXuMu1ZQ7JCe5FUv9m4oj3jH33VQEW3sorea7UOBjnSsLWp8MyE08M4tlY2xgyFL59obQIDAQAB",
Expand All @@ -43,86 +18,61 @@ const app = new Vue({
isValid: null
}
},
methods: {
newChallenge() {
return webauthn.utils.randomChallenge()
},
async register() {
computed: {
parsedAuthData() {
const authData = this.verification.authenticatorData
if(!authData)
return null
try {
const json = await webauthn.client.register(this.registration.options)
console.log(json)
this.$buefy.toast.open({
message: 'Registered!',
type: 'is-success'
})
this.registration.json = json

const result = await webauthn.server.verifyRegistration(json, {
challenge: this.registration.options.challenge,
origin: this.origin,
})
console.log(result)
this.registration.result = result
return webauthn.parsers.parseAuthenticator(authData)
}
catch(e) {
console.warn(e)
this.$buefy.toast.open({
message: e,
type: 'is-danger'
})
this.registration.result = {}
return "ERROR: failed to parse authenticator data. See console logs for more details."
}
},
async login() {
this.authentication.result = null
this.authentication.json = null
parsedClientData() {
const clientData = this.verification.clientData
if(!clientData)
return null
try {
const json = await webauthn.client.authenticate(this.authentication.options)
console.log(json)
this.$buefy.toast.open({
message: 'Authenticated!',
type: 'is-success'
})
this.authentication.json = json

const credential = this.registration?.result?.credential
if(credential) {
const result = await webauthn.server.verifyAuthentication(json, credential, {
challenge: this.authentication.options.challenge,
origin: this.origin,
userVerified: this.authentication.userVerification === 'required',
counter: -1 // Fixes #27 since counter is 0 on first auth with ios/macos
})
console.log(result)
this.authentication.result = result
}
return webauthn.parsers.parseClient(clientData)
}
catch(e) {
console.warn(e)
return "ERROR: failed to parse client data. See console logs for more details."
}
}
},
methods: {

async verifySignature() {
try {
this.verification.isValid = await webauthn.server.verifySignature(this.verification)
}
catch(e) {
console.warn(e)
this.$buefy.toast.open({
message: e,
type: 'is-danger'
})
this.verification.isValid = false
}
},
async verifySignature() {
async verifyKey() {
try {
this.verification.isValid = await webauthn.server.verifySignature(this.verification)
this.isKeyValid = null
const key = await webauthn.server.parseCryptoKey(this.verification.algorithm, this.verification.publicKey)
this.isKeyValid = true
}
catch(e) {
console.warn(e)
this.$buefy.toast.open({
message: e,
type: 'is-danger'
})
this.verification.isValid = false
this.isKeyValid = false
}
},
parseAuthData(authData) {
return webauthn.parsers.parseAuthenticator(authData)
},
parseClientData(clientData) {
return webauthn.parsers.parseClient(clientData)
}
}
})

0 comments on commit 5804ab2

Please sign in to comment.