Skip to content

Commit

Permalink
2019-11-07-webauthn.md: script
Browse files Browse the repository at this point in the history
  • Loading branch information
k committed Oct 22, 2024
1 parent 8aecdba commit 3b2d5d0
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions _posts/2019-11-07-webauthn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,50 @@ date: 2019-11-07
layout: post
---
<script>
var randomChallengeBuffer = new Uint8Array(32);
window.crypto.getRandomValues(randomChallengeBuffer);

var base64id = 'MIIBkzCCATigAwIBAjCCAZMwggE4oAMCAQIwggGTMII='
var idBuffer = Uint8Array.from(window.atob(base64id), c=>c.charCodeAt(0))

var publicKey = {
challenge: randomChallengeBuffer,

rp: { id: "scateu.me", name: "scateu.me" },

user: {
id: idBuffer,
name: "[email protected]",
displayName: "Alice von Wunderland"
},

attestation: 'none',

pubKeyCredParams: [
{ type: 'public-key', alg: -7 }, // ES256
{ type: 'public-key', alg: -257 } // RS256
]
function doFunction() {
var randomChallengeBuffer = new Uint8Array(32);
window.crypto.getRandomValues(randomChallengeBuffer);

var base64id = 'MIIBkzCCATigAwIBAjCCAZMwggE4oAMCAQIwggGTMII='
var idBuffer = Uint8Array.from(window.atob(base64id), c=>c.charCodeAt(0))

var publicKey = {
challenge: randomChallengeBuffer,

rp: { id: "scateu.me", name: "scateu.me" },

user: {
id: idBuffer,
name: "[email protected]",
displayName: "Alice von Wunderland"
},

attestation: 'none',

pubKeyCredParams: [
{ type: 'public-key', alg: -7 }, // ES256
{ type: 'public-key', alg: -257 } // RS256
]
}

navigator.credentials.create({ publicKey })
.then((newCredentialInfo) => {
console.log('SUCCESS', newCredentialInfo)
})
.catch((error) => {
console.log('FAIL', error)
})
}

navigator.credentials.create({ publicKey })
.then((newCredentialInfo) => {
console.log('SUCCESS', newCredentialInfo)
})
.catch((error) => {
console.log('FAIL', error)
})

</script>


在此页面(一定要有https,感兴趣的同学可以访问http的此页面观察对比现象)
随手打开Console,粘!

或者

<input id="clickMe" type="button" value="FIDO注册" onclick="doFunction();" />

注意:里面相关ID的scateu.me字样要与域名相匹配。


Expand Down

0 comments on commit 3b2d5d0

Please sign in to comment.