add a bit of metrics to ie11 olm prototype

This commit is contained in:
Bruno Windels 2020-08-26 16:30:32 +01:00
parent baa9879234
commit 08b12eace5

View file

@ -41,45 +41,79 @@
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script type="text/javascript" src="../lib/olm/olm_legacy.js"></script>
<script type="text/javascript">
function main() {
if (window.msCrypto && !window.crypto) {
window.crypto = window.msCrypto;
}
Olm.init( ).then(function() {
const alice = new Olm.Account();
function doit(log) {
var alice = new Olm.Account();
alice.create();
console.log("alice", alice.identity_keys());
log("alice", alice.identity_keys());
const bob = new Olm.Account();
var bob = new Olm.Account();
bob.unpickle("secret", "EWfA87or4GgQ+wqVkyuFiW9gUk3FI6QSXgp8E2dS5RFLvXgy4oFvxwQ1gVnbMkdJz2Hy9ex9UmJ/ZyuRU0aRt0IwXpw/SUNq4IQeVJ7J/miXW7rV4Ep+4RSEf945KbDrokDCS2CoL5PIfv/NYyey32gA0hMi8wWIfIlOxFBV4SBJYSC+Qd54VjprwCg0Sn9vjQouKVrM/+5jzsv9+JK5OpWW0Vrb3qrXwyAOEAQ4WlOQcqZHAyPQIw");
console.log("bob", bob.identity_keys());
log("bob", bob.identity_keys());
// generate OTK on receiver side
bob.generate_one_time_keys(1);
const bobOneTimeKeys = JSON.parse(bob.one_time_keys());
const otkName = Object.getOwnPropertyNames(bobOneTimeKeys.curve25519)[0];
const bobOneTimeKey = bobOneTimeKeys.curve25519[otkName];
var bobOneTimeKeys = JSON.parse(bob.one_time_keys());
var otkName = Object.getOwnPropertyNames(bobOneTimeKeys.curve25519)[0];
var bobOneTimeKey = bobOneTimeKeys.curve25519[otkName];
// encrypt
const aliceSession = new Olm.Session();
var aliceSession = new Olm.Session();
aliceSession.create_outbound(
alice,
JSON.parse(bob.identity_keys()).curve25519,
bobOneTimeKey
);
const message = aliceSession.encrypt("hello secret world");
console.log("message", message);
var message = aliceSession.encrypt("hello secret world");
log("message", message);
// decrypt
const bobSession = new Olm.Session();
var bobSession = new Olm.Session();
bobSession.create_inbound(bob, message.body);
const plaintext = bobSession.decrypt(message.type, message.body);
console.log("plaintext", plaintext);
var plaintext = bobSession.decrypt(message.type, message.body);
log("plaintext", plaintext);
// remove Bob's OTK as it was used to start an olm session
console.log("bob OTK before removing", bob.one_time_keys());
log("bob OTK before removing", bob.one_time_keys());
bob.remove_one_time_keys(bobSession);
console.log("bob OTK after removing", bob.one_time_keys());
log("bob OTK after removing", bob.one_time_keys());
}
if (window.msCrypto && !window.crypto) {
window.crypto = window.msCrypto;
}
function doRun(e) {
e.target.setAttribute("disabled", "disabled");
var logEl = document.getElementById("log");
logEl.innerText = "";
var startTime = performance.now();
function log() {
var timeDiff = Math.round(performance.now() - startTime).toString();
while (timeDiff.length < 5) {
timeDiff = "0" + timeDiff;
}
logEl.appendChild(document.createTextNode(timeDiff + " "));
for (var i = 0; i < arguments.length; i += 1) {
var value = arguments[i];
if (typeof value !== "string") {
value = JSON.stringify(value);
}
logEl.appendChild(document.createTextNode(value + " "));
}
logEl.appendChild(document.createTextNode("\n"));
}
doit(log);
e.target.removeAttribute("disabled");
}
function main() {
Olm.init( ).then(function() {
var startButton = document.getElementById("start");
startButton.innerText = "Start";
startButton.addEventListener("click", doRun);
});
}
document.addEventListener("DOMContentLoaded", main);
main();
</script>
<pre id="log"></pre>
<button id="start">Loading...</button>
</body>
</html>