test_send_receive.html (2387B)
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_send_receive() { 16 17 const mls = new MLS(); 18 19 // Generate Signature KeyPairs for Alice and Bob 20 let alice = await mls.generateIdentity(); 21 let bob = await mls.generateIdentity(); 22 23 // Generate Credentials for Alice and Bob 24 let credential_alice = await mls.generateCredential("alice"); 25 let credential_bob = await mls.generateCredential("bob"); 26 27 // Generate a KeyPackage for Bob 28 let kp_bob = await mls.generateKeyPackage(bob, credential_bob); 29 30 // Creation of a Group by Alice 31 let group_alice = await mls.groupCreate(alice, credential_alice); 32 33 // Alice adds Bob to a group 34 let commit_output = await group_alice.add(kp_bob); 35 36 // Test: the returned commit output is not null 37 info("Commit Output 1:", JSON.stringify(commit_output)); 38 isnot(JSON.stringify(commit_output), "", "Commit Output != ''"); 39 40 // Alice receives the commit 41 let group_and_epoch_1_alice = await group_alice.receive(commit_output.commit); 42 43 // Info: the new group identifier and epoch are valid 44 info("Alice Group Identifier and Epoch:", JSON.stringify(group_and_epoch_1_alice)); 45 46 // Bob joins the group 47 let group_bob = await mls.groupJoin(bob, commit_output.welcome); 48 49 // Test: compare the group identifier after the join 50 is(byteArrayToHexString(group_alice.groupId), byteArrayToHexString(group_bob.groupId), "Alice GID == Bob GID"); 51 52 // Bob sends a message to Alice 53 const message = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 32, 33]); // "Hello World !" in ASCII 54 let ciphertext_bytes = await group_bob.send(message); 55 56 // Alice decrypts the message from Bob 57 let received_message = await group_alice.receive(ciphertext_bytes); 58 59 // Test: compare the generated group identifier to incorrect values 60 is(byteArrayToHexString(message), byteArrayToHexString(received_message.content), "Message Sent == Message Decrypted"); 61 62 SimpleTest.finish(); 63 } 64 65 SimpleTest.waitForExplicitFinish(); 66 test_send_receive(); 67 68 </script> 69 </pre> 70 </body> 71 </html>