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" />
9 <script src=
"head_mls.js"></script>
13 <script class=
"testbody" type=
"text/javascript">
15 async function test_derive_exporter() {
17 const mls = new MLS();
19 // Generate Identity KeyPairs for Alice and Bob
20 let alice = await mls.generateIdentity();
21 let bob = await mls.generateIdentity();
23 info(
"Alice Client ID:", byteArrayToHexString(alice.content));
24 info(
"Bob Client ID:", byteArrayToHexString(bob.content));
27 // Generate Credentials for Alice and Bob
28 let credential_alice = await mls.generateCredential(
"alice");
29 let credential_bob = await mls.generateCredential(
"bob");
31 // Generate a KeyPackage for Bob
32 let kp_bob = await mls.generateKeyPackage(bob, credential_bob);
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));
38 // Get membership of the group
39 let members_alice_0 = await group_alice.details();
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");
48 // Alice adds Bob to a group
49 let commit_output = await group_alice.add(kp_bob);
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");
55 // Alice receives the commit
56 let group_and_epoch_1_alice = await group_alice.receive(commit_output.commit);
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");
63 // Get membership of the group
64 let members_alice_1 = await group_alice.details();
66 // Test that the returned group contain both Alice and Bob
67 info(
"Membership @ Epoch 1:", JSON.stringify(members_alice_1));
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");
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");
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");
78 // Bob joins the group
79 let group_bob = await mls.groupJoin(bob, commit_output.welcome);
81 // Test: compare the group identifier after the join
82 is(byteArrayToHexString(group_alice.groupId), byteArrayToHexString(group_bob.groupId),
"Alice GID == Bob GID");
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;
88 // Alice generates an Exporter
89 let exporter_alice = await group_alice.exportSecret(
90 "label", context_bytes, exporter_len);
92 // Bob generates an Exporter
93 let exporter_bob = await group_bob.exportSecret(
94 "label", context_bytes, exporter_len);
96 // Test that exporters are identical on both side
97 is(byteArrayToHexString(exporter_alice.exporter), byteArrayToHexString(exporter_bob.exporter),
"Exporter Alice == Exporter Bob");
102 SimpleTest.waitForExplicitFinish();
103 test_derive_exporter();