tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

virtual_authenticator.html (3479B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>TestDriver virtual authenticator methods</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script>
      9 "use strict";
     10 
     11 // Encodes |data| into a base64url string. There is no '=' padding, and the
     12 // characters '-' and '_' must be used instead of '+' and '/', respectively.
     13 function base64urlEncode(data) {
     14  let result = btoa(data);
     15  return result.replaceAll("=", "").replaceAll("+", "-").replaceAll("/", "_");
     16 }
     17 
     18 // The example attestation private key from the U2F spec at
     19 // https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.html#registration-example
     20 // PKCS.8 encoded without encryption, as a base64url string.
     21 const private_key =
     22    "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg8_zMDQDYAxlU-Q"
     23  + "hk1Dwkf0v18GZca1DMF3SaJ9HPdmShRANCAASNYX5lyVCOZLzFZzrIKmeZ2jwU"
     24  + "RmgsJYxGP__fWN_S-j5sN4tT15XEpN_7QZnt14YvI6uvAgO0uJEboFaZlOEB";
     25 let credential_id = base64urlEncode("cred-1");
     26 let credential = {
     27  credentialId: credential_id,
     28  rpId: window.location.hostname,
     29  privateKey: private_key,
     30  signCount: 0,
     31  isResidentCredential: false,
     32 };
     33 
     34 let authenticator_id = null;
     35 
     36 promise_test(async t => {
     37  authenticator_id = await test_driver.add_virtual_authenticator({
     38    protocol: "ctap1/u2f",
     39    transport: "usb",
     40  });
     41 }, "Can create an authenticator");
     42 
     43 promise_test(async t => {
     44  return test_driver.add_credential(authenticator_id, credential);
     45 }, "Can add a credential");
     46 
     47 promise_test(async t => {
     48  let credentials = await test_driver.get_credentials(authenticator_id);
     49  assert_equals(credentials.length, 1);
     50  // The U2F REGISTER operation stores the hash of the rpId, so the rpId
     51  // itself may not be available on the returned credential.
     52  assert_equals(credentials[0].credentialId, credential.credentialId);
     53  assert_equals(credentials[0].privateKey, credential.privateKey);
     54  assert_equals(credentials[0].signCount, credential.signCount);
     55  assert_equals(credentials[0].isResidentCredential,
     56                credential.isResidentCredential);
     57 }, "Can get the credentials");
     58 
     59 promise_test(async t => {
     60  await test_driver.remove_credential(authenticator_id, credential_id);
     61  let credentials = await test_driver.get_credentials(authenticator_id);
     62  assert_equals(credentials.length, 0);
     63 }, "Can remove a credential");
     64 
     65 promise_test(async t => {
     66  let credential1 = credential;
     67  let credential2 =
     68    Object.assign({}, credential, {credentialId: base64urlEncode("cred-2")});
     69  await test_driver.add_credential(authenticator_id, credential1);
     70  await test_driver.add_credential(authenticator_id, credential2);
     71 
     72  let credentials = await test_driver.get_credentials(authenticator_id);
     73  assert_equals(credentials.length, 2);
     74 
     75  await test_driver.remove_all_credentials(authenticator_id);
     76  credentials = await test_driver.get_credentials(authenticator_id);
     77  assert_equals(credentials.length, 0);
     78 }, "Can remove all credentials");
     79 
     80 promise_test(async t => {
     81  await test_driver.set_user_verified(authenticator_id, {isUserVerified: true});
     82  await test_driver.set_user_verified(authenticator_id, {isUserVerified: false});
     83 }, "Can set user verified");
     84 
     85 promise_test(async t => {
     86  await test_driver.remove_virtual_authenticator(authenticator_id);
     87 }, "Can remove a virtual authenticator");
     88 </script>