This patch contains an experimental Web API for the Messaging Layer Security (RFC 9420) protocol. The API allows to securely generate cryptographic material and build large dynamic groups with state-of-the-art security. The state (both public and secret) is stored in the profile and isolated by origin within dedicated databases. No secret can be exfiltrated through the API, and privacy risks are minimized due to the selected isolation. Differential Revision: https://phabricator.services.mozilla.com/D210568
77 lines
2.7 KiB
HTML
77 lines
2.7 KiB
HTML
|
|
|
|
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test for Messaging Layer Security</title>
|
|
<!-- SimpleTest Helpers -->
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
<!-- Local Helpers -->
|
|
<script src="head_mls.js"></script>
|
|
</head>
|
|
<body>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
async function test_group_add() {
|
|
|
|
const mls = new MLS();
|
|
|
|
// Generate Signature KeyPairs for Alice and Bob
|
|
let alice = await mls.generateIdentity();
|
|
let bob = await mls.generateIdentity();
|
|
|
|
// Generate Credentials for Alice and Bob
|
|
let credential_alice = await mls.generateCredential("alice");
|
|
let credential_bob = await mls.generateCredential("bob");
|
|
|
|
// Generate a KeyPackage for Bob
|
|
let kp_bob = await mls.generateKeyPackage(bob, credential_bob);
|
|
|
|
// Creation of a Group by Alice
|
|
let group_alice = await mls.groupCreate(alice, credential_alice);
|
|
let members_alice_0 = await group_alice.details();
|
|
|
|
// Test: compare the group identifier to the invalid value
|
|
info("Group ID:", byteArrayToHexString(group_alice.groupId));
|
|
isnot(byteArrayToHexString(group_alice.groupId), "", "Group Identifier != ''");
|
|
|
|
// Alice adds Bob to a group
|
|
let commit_output = await group_alice.add(kp_bob);
|
|
|
|
// Test: compare the commit output to the invalid value
|
|
info("Commit Output:", byteArrayToHexString(commit_output.commit));
|
|
isnot(byteArrayToHexString(commit_output.commit), "", "Commit != ''");
|
|
|
|
// Alice receives the commit
|
|
let group_and_epoch_1_alice = await group_alice.receive(commit_output.commit);
|
|
|
|
// Test: make sure that the group epoch has been incremented by one
|
|
const expectedEpoch = new Uint8Array(new BigUint64Array([1n]).buffer);
|
|
is(byteArrayToHexString(group_and_epoch_1_alice.groupEpoch), byteArrayToHexString(expectedEpoch), "Group Epoch = 1");
|
|
|
|
// Get the group details
|
|
let members_alice_1 = await group_alice.details();
|
|
|
|
// Test: the group should have exactly one member at epoch 0
|
|
is(members_alice_0.members.length, 1, "There should be exactly one member in the group");
|
|
|
|
// Test: the group should have exactly two members at epoch 1
|
|
is(members_alice_1.members.length, 2, "There should be exactly two members in the group");
|
|
|
|
// Test: compare the group members to the expected value
|
|
is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(bob.content)), true, "Bob should be in the group");
|
|
is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be in the group");
|
|
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
test_group_add();
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|