tor-browser

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

test_scenario.html (2540B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Messaging Layer Security</title>
      5  <!-- SimpleTest Helpers -->
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8  <!-- Local Helpers -->
      9  <script src="head_mls.js"></script>
     10 </head>
     11 <body>
     12 <pre id="test">
     13 <script class="testbody" type="text/javascript">
     14 
     15 async function test_scenario() {
     16 
     17  const mls = new MLS();
     18 
     19  // Alice: Create signature keypair and credential
     20  const alice = await mls.generateIdentity();
     21  const alice_credential = await mls.generateCredential("alice");
     22 
     23  // Bob: Create signature keypair and credential
     24  const bob = await mls.generateIdentity();
     25  const bob_credential = await mls.generateCredential("bob");
     26 
     27 
     28  // Bob: Generate a key package
     29  const bob_key_package = await mls.generateKeyPackage(bob, bob_credential);
     30 
     31  // Alice: Create a group
     32  let group_alice = await mls.groupCreate(alice, alice_credential);
     33 
     34  // Alice: Add Bob to the group
     35  let commit_output = await group_alice.add(bob_key_package);
     36 
     37  // Alice: process her Add commit
     38  await group_alice.receive(commit_output.commit);
     39 
     40  // Bob: Join the group
     41  let group_bob = await mls.groupJoin(bob, commit_output.welcome);
     42 
     43  // Test: compare group identifier from Alice and Bob
     44  is(byteArrayToHexString(group_alice.groupId), byteArrayToHexString(group_bob.groupId), "Alice GID == Bob GID");
     45 
     46  // Alice & Bob: Export a secret
     47  const context_bytes = new Uint8Array([99, 111, 110, 116, 101, 120, 116]); // "context" in ASCII
     48 
     49  const exportAlice = await group_alice.exportSecret("label", context_bytes, 15);
     50  const exportBob = await group_bob.exportSecret("label", context_bytes, 15);
     51 
     52  // Test: compare exporter from Alice and Bob
     53  is(byteArrayToHexString(exportAlice.exporter), byteArrayToHexString(exportBob.exporter), "Exporter Alice == Exporter Bob");
     54 
     55  // Bob: send a message to the group
     56  const message = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 32, 33]); // "Hello World !" in ASCII
     57  const ctx = await group_bob.send(message);
     58 
     59  // Alice: receive a message from the group
     60  const pt = await group_alice.receive(ctx);
     61  info("Alice received a message from Bob: " + JSON.stringify(pt));
     62 
     63  // Test: compare the message and the decrypted message
     64  is(byteArrayToHexString(message), byteArrayToHexString(pt.content), "Plaintext == Decrypted Message");
     65 
     66  SimpleTest.finish();
     67 }
     68 
     69 SimpleTest.waitForExplicitFinish();
     70 test_scenario();
     71 
     72 </script>
     73 </pre>
     74 </body>
     75 </html>