test_derive_exporter.html (4335B)
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_derive_exporter() { 16 17 const mls = new MLS(); 18 19 // Generate Identity KeyPairs for Alice and Bob 20 let alice = await mls.generateIdentity(); 21 let bob = await mls.generateIdentity(); 22 23 info("Alice Client ID:", byteArrayToHexString(alice.content)); 24 info("Bob Client ID:", byteArrayToHexString(bob.content)); 25 26 27 // Generate Credentials for Alice and Bob 28 let credential_alice = await mls.generateCredential("alice"); 29 let credential_bob = await mls.generateCredential("bob"); 30 31 // Generate a KeyPackage for Bob 32 let kp_bob = await mls.generateKeyPackage(bob, credential_bob); 33 34 // Creation of a Group by Alice 35 let group_alice = await mls.groupCreate(alice, credential_alice); 36 info("Group Alice:", JSON.stringify(group_alice)); 37 38 // Get membership of the group 39 let members_alice_0 = await group_alice.details(); 40 41 // Test that the returned group membership is not null 42 info("Membership @ Epoch 0:", JSON.stringify(members_alice_0)); 43 is(members_alice_0.members.length, 1, "There should be exactly one member in the group"); 44 info("Member Client ID:", byteArrayToHexString(members_alice_0.members[0].clientId)); 45 info("Alice Client ID:", byteArrayToHexString(alice.content)); 46 is(byteArrayToHexString(members_alice_0.members[0].clientId), byteArrayToHexString(alice.content), "The client ID of the member should match Alice's client ID"); 47 48 // Alice adds Bob to a group 49 let commit_output = await group_alice.add(kp_bob); 50 51 // Test that the returned commit output is not null 52 info("Commit Output 1:", JSON.stringify(commit_output)); 53 isnot(byteArrayToHexString(commit_output.commit), "", "Commit Output commit should not be an empty string"); 54 55 // Alice receives the commit 56 let group_and_epoch_1_alice = await group_alice.receive(commit_output.commit); 57 58 // Test that the new group identifier and epoch are valid 59 info("Alice's Group Identifier and Epoch:", JSON.stringify(group_and_epoch_1_alice)); 60 isnot(byteArrayToHexString(group_and_epoch_1_alice.groupId), "", "Group ID should not be an empty string"); 61 isnot(byteArrayToHexString(group_and_epoch_1_alice.groupEpoch), "", "Group Epoch should not be an empty string"); 62 63 // Get membership of the group 64 let members_alice_1 = await group_alice.details(); 65 66 // Test that the returned group contain both Alice and Bob 67 info("Membership @ Epoch 1:", JSON.stringify(members_alice_1)); 68 69 // Test: the group should have exactly two members at epoch 1 70 is(members_alice_1.members.length, 2, "There should be exactly two members in the group"); 71 72 // Test: Bob should be in the group 73 is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(bob.content)), true, "Bob should be in the group"); 74 75 // Test: Alice should be in the group 76 is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be in the group"); 77 78 // Bob joins the group 79 let group_bob = await mls.groupJoin(bob, commit_output.welcome); 80 81 // Test: compare the group identifier after the join 82 is(byteArrayToHexString(group_alice.groupId), byteArrayToHexString(group_bob.groupId), "Alice GID == Bob GID"); 83 84 // Create exporter labels and context 85 const context_bytes = new Uint8Array([99, 111, 110, 116, 101, 120, 116]); // "context" in ASCII 86 const exporter_len = 32; 87 88 // Alice generates an Exporter 89 let exporter_alice = await group_alice.exportSecret( 90 "label", context_bytes, exporter_len); 91 92 // Bob generates an Exporter 93 let exporter_bob = await group_bob.exportSecret( 94 "label", context_bytes, exporter_len); 95 96 // Test that exporters are identical on both side 97 is(byteArrayToHexString(exporter_alice.exporter), byteArrayToHexString(exporter_bob.exporter), "Exporter Alice == Exporter Bob"); 98 99 SimpleTest.finish(); 100 } 101 102 SimpleTest.waitForExplicitFinish(); 103 test_derive_exporter(); 104 105 </script> 106 </pre> 107 </body> 108 </html>