mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
add a bit of metrics to ie11 olm prototype
This commit is contained in:
parent
baa9879234
commit
08b12eace5
@ -41,45 +41,79 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
|
<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" src="../lib/olm/olm_legacy.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function main() {
|
function doit(log) {
|
||||||
if (window.msCrypto && !window.crypto) {
|
var alice = new Olm.Account();
|
||||||
window.crypto = window.msCrypto;
|
|
||||||
}
|
|
||||||
Olm.init( ).then(function() {
|
|
||||||
const alice = new Olm.Account();
|
|
||||||
alice.create();
|
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");
|
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
|
// generate OTK on receiver side
|
||||||
bob.generate_one_time_keys(1);
|
bob.generate_one_time_keys(1);
|
||||||
const bobOneTimeKeys = JSON.parse(bob.one_time_keys());
|
var bobOneTimeKeys = JSON.parse(bob.one_time_keys());
|
||||||
const otkName = Object.getOwnPropertyNames(bobOneTimeKeys.curve25519)[0];
|
var otkName = Object.getOwnPropertyNames(bobOneTimeKeys.curve25519)[0];
|
||||||
const bobOneTimeKey = bobOneTimeKeys.curve25519[otkName];
|
var bobOneTimeKey = bobOneTimeKeys.curve25519[otkName];
|
||||||
// encrypt
|
// encrypt
|
||||||
const aliceSession = new Olm.Session();
|
var aliceSession = new Olm.Session();
|
||||||
aliceSession.create_outbound(
|
aliceSession.create_outbound(
|
||||||
alice,
|
alice,
|
||||||
JSON.parse(bob.identity_keys()).curve25519,
|
JSON.parse(bob.identity_keys()).curve25519,
|
||||||
bobOneTimeKey
|
bobOneTimeKey
|
||||||
);
|
);
|
||||||
const message = aliceSession.encrypt("hello secret world");
|
var message = aliceSession.encrypt("hello secret world");
|
||||||
console.log("message", message);
|
log("message", message);
|
||||||
// decrypt
|
// decrypt
|
||||||
const bobSession = new Olm.Session();
|
var bobSession = new Olm.Session();
|
||||||
bobSession.create_inbound(bob, message.body);
|
bobSession.create_inbound(bob, message.body);
|
||||||
const plaintext = bobSession.decrypt(message.type, message.body);
|
var plaintext = bobSession.decrypt(message.type, message.body);
|
||||||
console.log("plaintext", plaintext);
|
log("plaintext", plaintext);
|
||||||
// remove Bob's OTK as it was used to start an olm session
|
// 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);
|
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();
|
main();
|
||||||
</script>
|
</script>
|
||||||
|
<pre id="log"></pre>
|
||||||
|
<button id="start">Loading...</button>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user