createcredential-getpublickey.https.html (1948B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>WebAuthn getPublicKey</title> 6 <meta name="timeout" content="long"> 7 <link rel="help" href="https://w3c.github.io/webauthn/#sctn-public-key-easy"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/resources/testdriver.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <script src="helpers.js"></script> 13 <script src="resources/utils.js"></script> 14 <script> 15 function testGetPublicKey() { 16 standardSetup(function() { 17 promise_test(async t => { 18 let cred = await createCredential(); 19 const response = cred.response; 20 assert_equals(response.getPublicKeyAlgorithm(), 21 cose_alg_ECDSA_w_SHA256); 22 23 const attestationObject = 24 new Cbor(response.attestationObject).getCBOR(); 25 const claimedAuthDataHex = uint8ArrayToHex( 26 new Uint8Array(response.getAuthenticatorData())); 27 const actualAuthDataHex = uint8ArrayToHex(attestationObject.authData); 28 assert_equals(actualAuthDataHex, claimedAuthDataHex); 29 30 // Check that the x and y coordinates of the public key appear in 31 // the claimed SPKI, at least. 32 const spkiHex = uint8ArrayToHex( 33 new Uint8Array(response.getPublicKey())); 34 const authData = parseAuthenticatorData(attestationObject.authData); 35 const pubKey = authData.attestedCredentialData.credentialPublicKey; 36 const xHex = uint8ArrayToHex(pubKey.x); 37 const yHex = uint8ArrayToHex(pubKey.y); 38 assert_not_equals(-1, spkiHex.indexOf(xHex)); 39 assert_not_equals(-1, spkiHex.indexOf(yHex)); 40 41 t.done(); 42 }); 43 }); 44 } 45 46 testGetPublicKey(); 47 /* JSHINT */ 48 /* globals standardSetup, createCredential */ 49 </script> 50 </head> 51 <body></body> 52 </html>