aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'javascript')
-rw-r--r--javascript/.gitignore7
-rw-r--r--javascript/README.md46
-rw-r--r--javascript/demo/demo.css8
-rw-r--r--javascript/demo/group_demo.html112
-rw-r--r--javascript/demo/group_demo.js506
-rw-r--r--javascript/demo/one_to_one_demo.html147
-rw-r--r--javascript/externs.js4
-rw-r--r--javascript/index.d.ts129
-rw-r--r--javascript/olm_inbound_group_session.js180
-rw-r--r--javascript/olm_outbound_group_session.js147
-rw-r--r--javascript/olm_pk.js362
-rw-r--r--javascript/olm_post.js587
-rw-r--r--javascript/olm_pre.js49
-rw-r--r--javascript/olm_prefix.js4
-rw-r--r--javascript/olm_sas.js99
-rw-r--r--javascript/olm_suffix.js36
-rw-r--r--javascript/package.json33
-rw-r--r--javascript/test/megolm.spec.js73
-rw-r--r--javascript/test/olm.spec.js101
-rw-r--r--javascript/test/pk.spec.js122
-rw-r--r--javascript/test/sas.spec.js62
21 files changed, 0 insertions, 2814 deletions
diff --git a/javascript/.gitignore b/javascript/.gitignore
deleted file mode 100644
index 1533e1b..0000000
--- a/javascript/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-/exported_functions.json
-/node_modules
-/npm-debug.log
-/olm.js
-/olm_legacy.js
-/olm.wasm
-/reports
diff --git a/javascript/README.md b/javascript/README.md
deleted file mode 100644
index bdf0224..0000000
--- a/javascript/README.md
+++ /dev/null
@@ -1,46 +0,0 @@
-Olm
-===
-
-Note: before using any of the olm functions, you must call `Olm.init()`, and
-wait for the promise to resolve, otherwise you will get errors like:
-`Uncaught TypeError: Olm.Account is not a constructor`
-
-Example:
-
- var alice = new Olm.Account();
- var bob = new Olm.Account();
- alice.create();
- bob.create();
- bob.generate_one_time_keys(1);
-
- var bobs_id_keys = JSON.parse(bob.identity_keys());
- var bobs_id_key = bobs_id_keys.curve25519;
- var bobs_ot_keys = JSON.parse(bob.one_time_keys());
- for (key in bobs_ot_keys.curve25519) {
- var bobs_ot_key = bobs_ot_keys.curve25519[key];
- }
-
- alice_session = new Olm.Session();
- alice_session.create_outbound(alice, bobs_id_key, bobs_ot_key);
- alice_message = a_session.encrypt("Hello");
-
- bob_session.create_inbound(bob, bob_message);
- var plaintext = bob_session.decrypt(message_1.type, bob_message);
- bob.remove_one_time_keys(bob_session);
-
-
-Group chat:
-
- var outbound_session = new Olm.OutboundGroupSession();
- outbound_session.create();
-
- // exchange these over a secure channel
- var session_id = group_session.session_id();
- var session_key = group_session.session_key();
- var message_index = group_session.message_index();
-
- var inbound_session = new Olm.InboundGroupSession();
- inbound_session.create(message_index, session_key);
-
- var ciphertext = outbound_session.encrypt("Hello");
- var plaintext = inbound_session.decrypt(ciphertext);
diff --git a/javascript/demo/demo.css b/javascript/demo/demo.css
deleted file mode 100644
index bf07df1..0000000
--- a/javascript/demo/demo.css
+++ /dev/null
@@ -1,8 +0,0 @@
-div.user {
- width: 500px;
- float: left;
- overflow: scroll;
- margin: 0px 20px 0px 0px;
- border: 1px solid black;
- padding: 5px;
-} \ No newline at end of file
diff --git a/javascript/demo/group_demo.html b/javascript/demo/group_demo.html
deleted file mode 100644
index d93a7cd..0000000
--- a/javascript/demo/group_demo.html
+++ /dev/null
@@ -1,112 +0,0 @@
-<html>
- <head>
- <link rel="stylesheet" type="text/css" href="demo.css"/>
- <script src="../olm.js"></script>
- <script src="group_demo.js"></script>
- </head>
-<body>
-<div id="user1" class="user">
- <h1>User1</h1>
-
- <textarea class="user_plain_input"></textarea>
- <button class="user_encrypt">Encrypt</button>
-
- <h2>Outgoing</h2>
-
- <h3>One-to-one output</h3>
- <div class="user_cipher_output"></div>
-
- <h3>Group output</h3>
- <div class="group_output"></div>
-
- <h2>Incoming</h2>
-
- <h3>One-to-one Received</h3>
- <div class="user_cipher_input"></div>
-
- <h3>Group received</h3>
- <div class="group_input"></div>
-
- <h2>Tasks</h2>
- <div class="user_progress"></div>
-</div>
-
-<div id="user2" class="user">
- <h1>User 2</h1>
-
- <textarea class="user_plain_input"></textarea>
- <button class="user_encrypt">Encrypt</button>
-
- <h2>Outgoing</h2>
-
- <h3>One-to-one output</h3>
- <div class="user_cipher_output"></div>
-
- <h3>Group output</h3>
- <div class="group_output"></div>
-
- <h2>Incoming</h2>
-
- <h3>One-to-one Received</h3>
- <div class="user_cipher_input"></div>
-
- <h3>Group received</h3>
- <div class="group_input"></div>
-
- <h2>Tasks</h2>
- <div class="user_progress"></div>
-</div>
-
-<div id="user3" class="user">
- <h1>User 3</h1>
-
- <textarea class="user_plain_input"></textarea>
- <button class="user_encrypt">Encrypt</button>
-
- <h2>Outgoing</h2>
-
- <h3>One-to-one output</h3>
- <div class="user_cipher_output"></div>
-
- <h3>Group output</h3>
- <div class="group_output"></div>
-
- <h2>Incoming</h2>
-
- <h3>One-to-one Received</h3>
- <div class="user_cipher_input"></div>
-
- <h3>Group received</h3>
- <div class="group_input"></div>
-
- <h2>Tasks</h2>
- <div class="user_progress"></div>
-</div>
-
-<div id="user4" class="user">
- <h1>User 4</h1>
-
- <textarea class="user_plain_input"></textarea>
- <button class="user_encrypt">Encrypt</button>
-
- <h2>Outgoing</h2>
-
- <h3>One-to-one output</h3>
- <div class="user_cipher_output"></div>
-
- <h3>Group output</h3>
- <div class="group_output"></div>
-
- <h2>Incoming</h2>
-
- <h3>One-to-one Received</h3>
- <div class="user_cipher_input"></div>
-
- <h3>Group received</h3>
- <div class="group_input"></div>
-
- <h2>Tasks</h2>
- <div class="user_progress"></div>
-</div>
-</body>
-</html>
diff --git a/javascript/demo/group_demo.js b/javascript/demo/group_demo.js
deleted file mode 100644
index 44b8166..0000000
--- a/javascript/demo/group_demo.js
+++ /dev/null
@@ -1,506 +0,0 @@
-/* Javascript parts of the group demo. To use, load group_demo.html in your
- * browser.
- */
-
-function buttonElement(buttonLabel, clickHandler) {
- var button = document.createElement("button");
- button.appendChild(document.createTextNode(buttonLabel));
- button.addEventListener("click", clickHandler, false);
- return button;
-}
-
-function buttonsAndText(textContent, buttonLabelToHandlerMap) {
- var el = document.createElement("div");
- for (var label in buttonLabelToHandlerMap) {
- if (!buttonLabelToHandlerMap.hasOwnProperty(label)) {
- continue;
- }
- var handler = buttonLabelToHandlerMap[label];
- var button = buttonElement(label, handler);
- el.appendChild(button);
- }
-
- var message_element = document.createElement("tt");
- el.appendChild(message_element);
-
- var content = document.createTextNode(textContent);
- message_element.appendChild(content);
-
- return el;
-}
-
-function buttonAndTextElement(buttonLabel, textContent, clickHandler) {
- var buttonMap = {};
- buttonMap[buttonLabel] = clickHandler;
- return buttonsAndText(textContent, buttonMap);
-}
-
-function DemoUser(name) {
- this.name = name;
- this.olmAccount = new Olm.Account();
- this.olmAccount.create();
-
- this.idKey = this.getIdKeys()["curve25519"];
-
- /* the people in our chat, indexed by their Curve25519 identity key.
- */
- this.peers = {};
-
- /* the Ed25519 signing key for each peer, indexed by their Curve25519 id key
- */
- this.peerSigningKeys = {};
-
- /* for each peer, a one-to-one session - indexed by id key and created on
- * demand */
- this.peerSessions = {};
-
- /* for each peer, info on their sender session - indexed by id key and
- * session id */
- this.peerGroupSessions = {};
-
- /* our outbound group session */
- this.groupSession = undefined;
-
- /* a list of pending tasks */
- this.tasks = [];
- this.taskWorker = undefined;
-
- /* the operations our peers are allowed to do on us */
- var publicOps = [
- "getIdKeys", "getOneTimeKey",
- "receiveOneToOne", "receiveGroup",
- ];
-
- this.remoteOps = {};
- for (var i=0; i<publicOps.length; i++) {
- var op = publicOps[i];
- this.remoteOps[op] = this[op].bind(this);
- }
-}
-
-DemoUser.prototype._progress = function(message) {
- var progress = this.progressElement;
-
- var message_element = document.createElement("pre");
- var start_content = document.createTextNode(message + "...");
- function start() {
- message_element.appendChild(start_content);
- progress.appendChild(message_element);
- }
- function done(res) {
- var done_content = document.createTextNode(message + "..." + res);
- message_element.replaceChild(done_content, start_content);
- }
- return {start:start, done:done};
-};
-
-DemoUser.prototype._do_tasks = function() {
- var self = this;
- var task = self.tasks.shift();
- var desc = task[0];
- var func = task[1];
- var callback = task[2];
-
- var p = self._progress(desc);
- p.start();
-
- function done() {
- p.done("Done");
-
- if (callback) {
- try {
- callback.apply(undefined, arguments)
- } catch (e) {
- console.error("Uncaught exception in callback", e.stack || e);
- }
- }
-
- start_tasks();
- }
-
- // sleep 50ms before actually doing the task
- self.taskWorker = window.setTimeout(function() {
- try {
- task[1](done);
- } catch (e) {
- console.error("Uncaught exception in task", e.stack || e);
- p.done("Failed: "+e);
- start_tasks();
- }
- }, 50);
-
-
- function start_tasks() {
- if (self.tasks.length == 0) {
- self.taskWorker = undefined;
- return;
- }
-
- self.taskWorker = window.setTimeout(self._do_tasks.bind(self), 50);
- }
-}
-
-/**
- * add a function "task" to this user's queue of things to do.
- *
- * task is called with a single argument 'done' which is a function to call
- * once the task is complete.
- *
- * 'callback' is called once the task is complete, with any arguments that
- * were passed to 'done'.
- */
-DemoUser.prototype.addTask = function(description, task, callback) {
- this.tasks.push([description, task, callback]);
- if(!this.taskWorker) {
- this._do_tasks();
- }
-};
-
-DemoUser.prototype.addPeer = function(peerOps) {
- var keys = peerOps.getIdKeys();
- var id = keys["curve25519"];
- this.peers[id] = peerOps;
- this.peerSigningKeys[id] = keys["ed25519"];
-};
-
-DemoUser.prototype.getIdKeys = function() {
- return JSON.parse(this.olmAccount.identity_keys());
-};
-
-DemoUser.prototype.getOneTimeKey = function() {
- var self = this;
- self.olmAccount.generate_one_time_keys(1);
- var keys = JSON.parse(self.olmAccount.one_time_keys()).curve25519;
- for (key_id in keys) {
- if (keys.hasOwnProperty(key_id)) {
- self.olmAccount.mark_keys_as_published();
- return keys[key_id];
- }
- }
- throw new Error("No one-time-keys generated");
-};
-
-/* ************************************************************************
- *
- * one-to-one messaging
- */
-
-/**
- * retrieve, or initiate, a one-to-one session to a given peer
- */
-DemoUser.prototype.getPeerSession = function(peerId, callback) {
- var self = this;
-
- if (this.peerSessions[peerId]) {
- callback(this.peerSessions[peerId]);
- return;
- }
-
- var peer = this.peers[peerId];
- this.addTask("get peer keys", function(done) {
- key = peer.getOneTimeKey();
- done(key);
- }, function(ot_key) {
- self.addTask("create peer session", function(done) {
- var session = new Olm.Session();
- session.create_outbound(self.olmAccount, peerId, ot_key);
- self.peerSessions[peerId] = session;
- done(session);
- }, callback);
- });
-};
-
-/**
- * encrypt a one-to-one message and prepare it for sending to a peer
- */
-DemoUser.prototype.sendToPeer = function(peerId, message, callback) {
- var self = this;
- this.getPeerSession(peerId, function(session) {
- self.addTask("encrypt one-to-one message", function(done) {
- var encrypted = session.encrypt(message);
- var packet = {
- sender_key: self.idKey,
- ciphertext: encrypted,
- };
- var json = JSON.stringify(packet);
-
- var el = buttonAndTextElement("send", json, function(ev) {
- self.peers[peerId].receiveOneToOne(json);
- });
- self.cipherOutputDiv.appendChild(el);
- done();
- }, callback);
- });
-};
-
-/**
- * handler for receiving a one-to-one message
- */
-DemoUser.prototype.receiveOneToOne = function(jsonpacket) {
- var self = this;
- var el = buttonAndTextElement("decrypt", jsonpacket, function(ev) {
- var sender = JSON.parse(jsonpacket).sender_key;
- self.decryptOneToOne(jsonpacket, function(result) {
-
- var el2 = document.createElement("tt");
- el.appendChild(el2);
-
- var content = document.createTextNode(" -> "+result);
- el2.appendChild(content);
-
- var body = JSON.parse(result);
-
- // create a new inbound session if we don't yet have one
- if (!self.peerGroupSessions[sender] ||
- !self.peerGroupSessions[sender][body.session_id]) {
- self.createInboundSession(
- sender, body.session_id, body.session_key
- );
- }
- });
- });
- this.cipherInputDiv.appendChild(el);
-};
-
-/**
- * add a task to decrypt a one-to-one message. Calls the callback with the
- * decrypted plaintext
- */
-DemoUser.prototype.decryptOneToOne = function(jsonpacket, callback) {
- var self = this;
- self.addTask("decrypt one-to-one message", function(done) {
- var packet = JSON.parse(jsonpacket);
- var peerId = packet.sender_key;
-
- var session = self.peerSessions[peerId];
- var plaintext;
- if (session) {
- plaintext = session.decrypt(packet.ciphertext.type, packet.ciphertext.body);
- done(plaintext);
- return;
- }
-
- if (packet.ciphertext.type != 0) {
- throw new Error("Unknown one-to-one session");
- }
-
- session = new Olm.Session();
- session.create_inbound(self.olmAccount, packet.ciphertext.body);
- self.peerSessions[peerId] = session;
- plaintext = session.decrypt(packet.ciphertext.type, packet.ciphertext.body);
- done(plaintext);
- }, callback)
-};
-
-/* ************************************************************************
- *
- * group messaging
- */
-
-
-/**
- * retrieve, or initiate, an outbound group session
- */
-DemoUser.prototype.getGroupSession = function() {
- if (this.groupSession) {
- return this.groupSession;
- }
-
- this.groupSession = new Olm.OutboundGroupSession();
- this.groupSession.create();
-
- var keymsg = {
- "session_id": this.groupSession.session_id(),
- "session_key": this.groupSession.session_key(),
- "message_index": this.groupSession.message_index(),
- };
- var jsonmsg = JSON.stringify(keymsg);
-
- for (var peer in this.peers) {
- if (!this.peers.hasOwnProperty(peer)) {
- continue;
- }
- this.sendToPeer(peer, jsonmsg);
- }
-
- return this.groupSession;
-};
-
-/**
- * add a task to create an inbound group session
- */
-DemoUser.prototype.createInboundSession = function(
- peer_id, session_id, session_key, callback
-) {
- var self = this;
- this.addTask("init inbound session", function(done) {
- session = new Olm.InboundGroupSession();
- session.create(session_key);
- if (!self.peerGroupSessions[peer_id]) {
- self.peerGroupSessions[peer_id] = {};
- }
- if (session_id != session.session_id()) {
- throw new Error("Mismatched session_ids");
- }
- self.peerGroupSessions[peer_id][session_id] = session;
- done(session);
- }, callback);
-};
-
-/**
- * handler for receiving a group message
- */
-DemoUser.prototype.receiveGroup = function(jsonpacket) {
- var self = this;
- var el = buttonAndTextElement("decrypt", jsonpacket, function(ev) {
- self.decryptGroup(jsonpacket, function(result) {
- var el2 = document.createElement("tt");
- el.appendChild(el2);
-
- var content = document.createTextNode(" -> "+result);
- el2.appendChild(content);
- });
- });
- this.groupInputDiv.appendChild(el);
-};
-
-/**
- * add a task to decrypt a received group message. Calls the callback with the
- * decrypted plaintext
- */
-DemoUser.prototype.decryptGroup = function(jsonpacket, callback) {
- var self = this;
- this.addTask("decrypt group message", function(done) {
- var packet = JSON.parse(jsonpacket);
-
- var sender = packet.sender_key;
- var session_id = packet.session_id;
-
- var sender_signing_key = self.peerSigningKeys[sender];
- if (!sender_signing_key) {
- throw new Error("No known signing key for sender "+sender);
- }
-
- var olmUtility = new Olm.Utility();
- olmUtility.ed25519_verify(
- sender_signing_key, packet.body, packet.signature
- );
-
- var peer_sessions = self.peerGroupSessions[sender];
- if (!peer_sessions) {
- throw new Error("No sessions for sender "+sender);
- }
-
- var session = peer_sessions[session_id];
- if (!session) {
- throw new Error("Unknown session id " + session_id);
- }
-
- var result = session.decrypt(packet.body);
- done(result.plaintext);
- }, callback);
-};
-
-
-
-/**
- * add a task to encrypt, and prepare for sending, a group message.
- *
- * Will create a group session if necessary
- */
-DemoUser.prototype.encrypt = function(message) {
- var self = this;
- var session = this.getGroupSession();
-
- function sendJsonToPeers(json) {
- for (var peer in self.peers) {
- if (!self.peers.hasOwnProperty(peer)) {
- continue;
- }
- self.peers[peer].receiveGroup(json);
- }
- }
-
-
- self.addTask("encrypt group message", function(done) {
- var encrypted = session.encrypt(message);
- var signature = self.olmAccount.sign(encrypted);
-
- var packet = {
- sender_key: self.idKey,
- session_id: session.session_id(),
- body: encrypted,
- signature: signature,
- };
- var json = JSON.stringify(packet);
-
- var el = buttonsAndText(json, {
- send: function(ev) {
- sendJsonToPeers(json);
- },
- "send corrupted": function(ev) {
- var p = JSON.parse(json);
- p.body += " ";
- sendJsonToPeers(JSON.stringify(p));
- },
- });
- self.groupOutputDiv.appendChild(el);
- done();
- });
-};
-
-
-/* ************************************************************************** */
-
-function initUserDiv(demoUser, div) {
- demoUser.progressElement = div.getElementsByClassName("user_progress")[0];
- demoUser.cipherOutputDiv = div.getElementsByClassName("user_cipher_output")[0];
- demoUser.cipherInputDiv = div.getElementsByClassName("user_cipher_input")[0];
- demoUser.groupOutputDiv = div.getElementsByClassName("group_output")[0];
- demoUser.groupInputDiv = div.getElementsByClassName("group_input")[0];
-
- var plain_input = div.getElementsByClassName("user_plain_input")[0];
- var encrypt = div.getElementsByClassName("user_encrypt")[0];
-
- encrypt.addEventListener("click", function() {
- demoUser.encrypt(plain_input.value);
- }, false);
-
-}
-
-function startDemo() {
- var user1 = new DemoUser();
- initUserDiv(user1, document.getElementById("user1"));
-
- var user2 = new DemoUser();
- initUserDiv(user2, document.getElementById("user2"));
-
- var user3 = new DemoUser();
- initUserDiv(user3, document.getElementById("user3"));
-
- var user4 = new DemoUser();
- initUserDiv(user4, document.getElementById("user4"));
-
- user1.addPeer(user2.remoteOps);
- user1.addPeer(user3.remoteOps);
- user1.addPeer(user4.remoteOps);
-
- user2.addPeer(user1.remoteOps);
- user2.addPeer(user3.remoteOps);
- user2.addPeer(user4.remoteOps);
-
- user3.addPeer(user1.remoteOps);
- user3.addPeer(user2.remoteOps);
- user3.addPeer(user4.remoteOps);
-
- user4.addPeer(user1.remoteOps);
- user4.addPeer(user2.remoteOps);
- user4.addPeer(user3.remoteOps);
-}
-
-
-document.addEventListener("DOMContentLoaded", function() {
- Olm.init().then(function() {
- startDemo();
- });
-}, false);
diff --git a/javascript/demo/one_to_one_demo.html b/javascript/demo/one_to_one_demo.html
deleted file mode 100644
index a225e4a..0000000
--- a/javascript/demo/one_to_one_demo.html
+++ /dev/null
@@ -1,147 +0,0 @@
-<html>
-<head>
-<script src="../olm.js"></script>
-<script>
-document.addEventListener("DOMContentLoaded", function() {
- Olm.init().then(function() {
- demo();
- });
-}, false);
-
-function demo() {
- function progress(who, message) {
- var message_element = document.createElement("pre");
- var progress = document.getElementById(who + "_progress");
- var start_content = document.createTextNode(message + "...");
- var done_content = document.createTextNode(message + "... Done");
- function start() {
- message_element.appendChild(start_content);
- progress.appendChild(message_element);
- }
- function done() {
- message_element.replaceChild(done_content, start_content);
- }
- return {start:start, done:done};
- }
-
- window.alice = new Olm.Account();
- window.bob = new Olm.Account();
- var a_session = new Olm.Session();
- var b_session = new Olm.Session();
- var message_1;
- var tasks = [];
-
- tasks.push(["alice", "Creating account", function() { alice.create() }]);
- tasks.push(["bob", "Creating account", function() { bob.create() }]);
- tasks.push(["bob", "Generate one time keys", function() {
- bob.generate_one_time_keys(1);
- }]);
- tasks.push(["alice", "Create outbound session", function() {
- var bobs_id_keys = JSON.parse(bob.identity_keys());
- var bobs_id_key = bobs_id_keys.curve25519;
- var bobs_ot_keys = JSON.parse(bob.one_time_keys());
- var bobs_ot_key;
- for (key in bobs_ot_keys.curve25519) {
- bobs_ot_key = bobs_ot_keys.curve25519[key];
- }
- a_session.create_outbound(alice, bobs_id_key, bobs_ot_key);
- }]);
- tasks.push(["alice", "Encrypt first message", function() {
- message_1 = a_session.encrypt("");
- }]);
- tasks.push(["bob", "Create inbound session", function() {
- b_session.create_inbound(bob, message_1.body);
- }]);
- tasks.push(["bob", "Decrypt first message", function() {
- b_session.decrypt(message_1.type, message_1.body);
- }]);
-
- function glue_encrypt(from, to, from_session) {
- var plain_input = document.getElementById(from + "_plain_input");
- var cipher_output = document.getElementById(from + "_cipher_output");
- var cipher_input = document.getElementById(to + "_cipher_input");
- var encrypt = document.getElementById(from + "_encrypt");
-
- encrypt.addEventListener("click", function() {
- var message = from_session.encrypt(plain_input.value);
- var message_element = document.createElement("pre");
- var content = document.createTextNode(JSON.stringify(message));
- message_element.appendChild(content);
- cipher_output.appendChild(message_element);
- message_element.addEventListener("click", function() {
- cipher_input.value = JSON.stringify(message);
- }, false);
- }, false);
- }
-
- function glue_decrypt(to, to_session) {
- var cipher_input = document.getElementById(to + "_cipher_input");
- var plain_output = document.getElementById(to + "_plain_output");
- var decrypt = document.getElementById(to + "_decrypt");
-
- decrypt.addEventListener("click", function() {
- var message = JSON.parse(cipher_input.value);
- try {
- var plaintext = to_session.decrypt(message.type, message.body);
- } catch (e) {
- var plaintext = "ERROR: " + e.message;
- }
- var message_element = document.createElement("pre");
- var message_content = document.createTextNode(plaintext);
- message_element.appendChild(message_content);
- plain_output.appendChild(message_element);
- }, false);
- }
-
- function do_tasks(next) {
- if (tasks.length > 0) {
- var task = tasks.shift();
- var p = progress(task[0], task[1])
- p.start();
- window.setTimeout(function() {
- task[2]();
- p.done();
- window.setTimeout(do_tasks, 50, next);
- }, 50)
- } else {
- next();
- }
- }
-
- do_tasks(function() {
- glue_encrypt("alice", "bob", a_session);
- glue_decrypt("bob", b_session);
-
- glue_encrypt("bob", "alice", b_session);
- glue_decrypt("alice", a_session);
- });
-}
-
-</script>
-<body>
-<div id="alice">
- <h1>Alice</h1>
- <div id="alice_progress"></div>
- <h2>Encryption</h2>
- <textarea id="alice_plain_input"></textarea>
- <button id="alice_encrypt">Encrypt</button>
- <div id="alice_cipher_output"></div>
- <h2>Decryption</h2>
- <textarea id="alice_cipher_input"></textarea>
- <button id="alice_decrypt">Decrypt</button>
- <div id="alice_plain_output"></div>
-</div>
-<div id="bob">
- <h1>Bob</h1>
- <div id="bob_progress"></div>
- <h2>Encryption</h2>
- <textarea id="bob_plain_input"></textarea>
- <button id="bob_encrypt">Encrypt</button>
- <div id="bob_cipher_output"></div>
- <h2>Decryption</h2>
- <textarea id="bob_cipher_input"></textarea>
- <button id="bob_decrypt">Decrypt</button>
- <div id="bob_plain_output"></div>
-</div>
-</body>
-</html>
diff --git a/javascript/externs.js b/javascript/externs.js
deleted file mode 100644
index 752e937..0000000
--- a/javascript/externs.js
+++ /dev/null
@@ -1,4 +0,0 @@
-var OLM_OPTIONS;
-var olm_exports;
-var onInitSuccess;
-var onInitFail;
diff --git a/javascript/index.d.ts b/javascript/index.d.ts
deleted file mode 100644
index 141f695..0000000
--- a/javascript/index.d.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
-Copyright 2020 The Matrix.org Foundation C.I.C.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-export as namespace Olm;
-
-declare class Account {
- constructor();
- free();
- create();
- identity_keys(): string;
- sign(message: string | Uint8Array): string;
- one_time_keys(): string;
- mark_keys_as_published();
- max_number_of_one_time_keys(): number;
- generate_one_time_keys(number_of_keys: number);
- remove_one_time_keys(session: Session);
- generate_fallback_key();
- fallback_key(): string;
- pickle(key: string | Uint8Array): string;
- unpickle(key: string | Uint8Array, pickle: string);
-}
-
-declare class Session {
- constructor();
- free(): void;
- pickle(key: string | Uint8Array): string;
- unpickle(key: string | Uint8Array, pickle: string);
- create_outbound(
- account: Account, their_identity_key: string, their_one_time_key: string,
- ): void;
- create_inbound(account: Account, one_time_key_message: string): void;
- create_inbound_from(
- account: Account, identity_key: string, one_time_key_message: string,
- ): void;
- session_id(): string;
- has_received_message(): boolean;
- matches_inbound(one_time_key_message: string): boolean;
- matches_inbound_from(identity_key: string, one_time_key_message: string): boolean;
- encrypt(plaintext: string): object;
- decrypt(message_type: number, message: string): string;
- describe(): string;
-}
-
-declare class Utility {
- constructor();
- free(): void;
- sha256(input: string | Uint8Array): string;
- ed25519_verify(key: string, message: string | Uint8Array, signature: string): void;
-}
-
-declare class InboundGroupSession {
- constructor();
- free(): void;
- pickle(key: string | Uint8Array): string;
- unpickle(key: string | Uint8Array, pickle: string);
- create(session_key: string): string;
- import_session(session_key: string): string;
- decrypt(message: string): object;
- session_id(): string;
- first_known_index(): number;
- export_session(message_index: number): string;
-}
-
-declare class OutboundGroupSession {
- constructor();
- free(): void;
- pickle(key: string | Uint8Array): string;
- unpickle(key: string | Uint8Array, pickle: string);
- create(): void;
- encrypt(plaintext: string): string;
- session_id(): string;
- session_key(): string;
- message_index(): number;
-}
-
-declare class PkEncryption {
- constructor();
- free(): void;
- set_recipient_key(key: string): void;
- encrypt(plaintext: string): object;
-}
-
-declare class PkDecryption {
- constructor();
- free(): void;
- init_with_private_key(key: Uint8Array): string;
- generate_key(): string;
- get_private_key(): Uint8Array;
- pickle(key: string | Uint8Array): string;
- unpickle(key: string | Uint8Array, pickle: string): string;
- decrypt(ephemeral_key: string, mac: string, ciphertext: string): string;
-}
-
-declare class PkSigning {
- constructor();
- free(): void;
- init_with_seed(seed: Uint8Array): string;
- generate_seed(): Uint8Array;
- sign(message: string): string;
-}
-
-declare class SAS {
- constructor();
- free(): void;
- get_pubkey(): string;
- set_their_key(their_key: string): void;
- generate_bytes(info: string, length: number): Uint8Array;
- calculate_mac(input: string, info: string): string;
- calculate_mac_long_kdf(input: string, info: string): string;
-}
-
-export function init(opts?: object): Promise<void>;
-
-export function get_library_version(): [number, number, number];
-
-export const PRIVATE_KEY_LENGTH: number;
diff --git a/javascript/olm_inbound_group_session.js b/javascript/olm_inbound_group_session.js
deleted file mode 100644
index 423d2b1..0000000
--- a/javascript/olm_inbound_group_session.js
+++ /dev/null
@@ -1,180 +0,0 @@
-function InboundGroupSession() {
- var size = Module['_olm_inbound_group_session_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_inbound_group_session'](this.buf);
-}
-
-function inbound_group_session_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_inbound_group_session_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-InboundGroupSession.prototype['free'] = function() {
- Module['_olm_clear_inbound_group_session'](this.ptr);
- free(this.ptr);
-}
-
-InboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
- var key_array = array_from_string(key);
- var pickle_length = inbound_group_session_method(
- Module['_olm_pickle_inbound_group_session_length']
- )(this.ptr);
- var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
- try {
- inbound_group_session_method(Module['_olm_pickle_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
- return UTF8ToString(pickle_buffer, pickle_length);
-});
-
-InboundGroupSession.prototype['unpickle'] = restore_stack(function(key, pickle) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- var pickle_array = array_from_string(pickle);
- var pickle_buffer = stack(pickle_array);
- try {
- inbound_group_session_method(Module['_olm_unpickle_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer,
- pickle_array.length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
-});
-
-InboundGroupSession.prototype['create'] = restore_stack(function(session_key) {
- var key_array = array_from_string(session_key);
- var key_buffer = stack(key_array);
-
- try {
- inbound_group_session_method(Module['_olm_init_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length
- );
- } finally {
- // clear out copies of the key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
-});
-
-InboundGroupSession.prototype['import_session'] = restore_stack(function(session_key) {
- var key_array = array_from_string(session_key);
- var key_buffer = stack(key_array);
-
- try {
- inbound_group_session_method(Module['_olm_import_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length
- );
- } finally {
- // clear out copies of the key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
-});
-
-InboundGroupSession.prototype['decrypt'] = restore_stack(function(
- message
-) {
- var message_buffer, plaintext_buffer, plaintext_length;
-
- try {
- message_buffer = malloc(message.length);
- writeAsciiToMemory(message, message_buffer, true);
-
- var max_plaintext_length = inbound_group_session_method(
- Module['_olm_group_decrypt_max_plaintext_length']
- )(this.ptr, message_buffer, message.length);
-
- // caculating the length destroys the input buffer, so we need to re-copy it.
- writeAsciiToMemory(message, message_buffer, true);
-
- plaintext_buffer = malloc(max_plaintext_length + NULL_BYTE_PADDING_LENGTH);
- var message_index = stack(4);
-
- plaintext_length = inbound_group_session_method(
- Module["_olm_group_decrypt"]
- )(
- this.ptr,
- message_buffer, message.length,
- plaintext_buffer, max_plaintext_length,
- message_index
- );
-
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- plaintext_buffer+plaintext_length,
- 0, "i8"
- );
-
- return {
- "plaintext": UTF8ToString(plaintext_buffer, plaintext_length),
- "message_index": getValue(message_index, "i32")
- }
- } finally {
- if (message_buffer !== undefined) {
- free(message_buffer);
- }
- if (plaintext_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, plaintext_length);
- free(plaintext_buffer);
- }
- }
-});
-
-InboundGroupSession.prototype['session_id'] = restore_stack(function() {
- var length = inbound_group_session_method(
- Module['_olm_inbound_group_session_id_length']
- )(this.ptr);
- var session_id = stack(length + NULL_BYTE_PADDING_LENGTH);
- inbound_group_session_method(Module['_olm_inbound_group_session_id'])(
- this.ptr, session_id, length
- );
- return UTF8ToString(session_id, length);
-});
-
-InboundGroupSession.prototype['first_known_index'] = restore_stack(function() {
- return inbound_group_session_method(
- Module['_olm_inbound_group_session_first_known_index']
- )(this.ptr);
-});
-
-InboundGroupSession.prototype['export_session'] = restore_stack(function(message_index) {
- var key_length = inbound_group_session_method(
- Module['_olm_export_inbound_group_session_length']
- )(this.ptr);
- var key = stack(key_length + NULL_BYTE_PADDING_LENGTH);
- outbound_group_session_method(Module['_olm_export_inbound_group_session'])(
- this.ptr, key, key_length, message_index
- );
- var key_str = UTF8ToString(key, key_length);
- bzero(key, key_length); // clear out a copy of the key
- return key_str;
-});
-
-olm_exports['InboundGroupSession'] = InboundGroupSession;
diff --git a/javascript/olm_outbound_group_session.js b/javascript/olm_outbound_group_session.js
deleted file mode 100644
index e4852c1..0000000
--- a/javascript/olm_outbound_group_session.js
+++ /dev/null
@@ -1,147 +0,0 @@
-function OutboundGroupSession() {
- var size = Module['_olm_outbound_group_session_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_outbound_group_session'](this.buf);
-}
-
-function outbound_group_session_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_outbound_group_session_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-OutboundGroupSession.prototype['free'] = function() {
- Module['_olm_clear_outbound_group_session'](this.ptr);
- free(this.ptr);
-}
-
-OutboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
- var key_array = array_from_string(key);
- var pickle_length = outbound_group_session_method(
- Module['_olm_pickle_outbound_group_session_length']
- )(this.ptr);
- var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
- try {
- outbound_group_session_method(Module['_olm_pickle_outbound_group_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
- return UTF8ToString(pickle_buffer, pickle_length);
-});
-
-OutboundGroupSession.prototype['unpickle'] = restore_stack(function(key, pickle) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- var pickle_array = array_from_string(pickle);
- var pickle_buffer = stack(pickle_array);
- try {
- outbound_group_session_method(Module['_olm_unpickle_outbound_group_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer,
- pickle_array.length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
-});
-
-OutboundGroupSession.prototype['create'] = restore_stack(function() {
- var random_length = outbound_group_session_method(
- Module['_olm_init_outbound_group_session_random_length']
- )(this.ptr);
- var random = random_stack(random_length);
- outbound_group_session_method(Module['_olm_init_outbound_group_session'])(
- this.ptr, random, random_length
- );
-});
-
-OutboundGroupSession.prototype['encrypt'] = function(plaintext) {
- var plaintext_buffer, message_buffer, plaintext_length;
- try {
- plaintext_length = lengthBytesUTF8(plaintext);
-
- var message_length = outbound_group_session_method(
- Module['_olm_group_encrypt_message_length']
- )(this.ptr, plaintext_length);
-
- // need to allow space for the terminator (which stringToUTF8 always
- // writes), hence + 1.
- plaintext_buffer = malloc(plaintext_length + 1);
- stringToUTF8(plaintext, plaintext_buffer, plaintext_length + 1);
-
- message_buffer = malloc(message_length + NULL_BYTE_PADDING_LENGTH);
- outbound_group_session_method(Module['_olm_group_encrypt'])(
- this.ptr,
- plaintext_buffer, plaintext_length,
- message_buffer, message_length
- );
-
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- message_buffer+message_length,
- 0, "i8"
- );
-
- return UTF8ToString(message_buffer, message_length);
- } finally {
- if (plaintext_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, plaintext_length + 1);
- free(plaintext_buffer);
- }
- if (message_buffer !== undefined) {
- free(message_buffer);
- }
- }
-};
-
-OutboundGroupSession.prototype['session_id'] = restore_stack(function() {
- var length = outbound_group_session_method(
- Module['_olm_outbound_group_session_id_length']
- )(this.ptr);
- var session_id = stack(length + NULL_BYTE_PADDING_LENGTH);
- outbound_group_session_method(Module['_olm_outbound_group_session_id'])(
- this.ptr, session_id, length
- );
- return UTF8ToString(session_id, length);
-});
-
-OutboundGroupSession.prototype['session_key'] = restore_stack(function() {
- var key_length = outbound_group_session_method(
- Module['_olm_outbound_group_session_key_length']
- )(this.ptr);
- var key = stack(key_length + NULL_BYTE_PADDING_LENGTH);
- outbound_group_session_method(Module['_olm_outbound_group_session_key'])(
- this.ptr, key, key_length
- );
- var key_str = UTF8ToString(key, key_length);
- bzero(key, key_length); // clear out our copy of the key
- return key_str;
-});
-
-OutboundGroupSession.prototype['message_index'] = function() {
- var idx = outbound_group_session_method(
- Module['_olm_outbound_group_session_message_index']
- )(this.ptr);
- return idx;
-};
-
-olm_exports['OutboundGroupSession'] = OutboundGroupSession;
diff --git a/javascript/olm_pk.js b/javascript/olm_pk.js
deleted file mode 100644
index 4690b90..0000000
--- a/javascript/olm_pk.js
+++ /dev/null
@@ -1,362 +0,0 @@
-function PkEncryption() {
- var size = Module['_olm_pk_encryption_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_pk_encryption'](this.buf);
-}
-
-function pk_encryption_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_pk_encryption_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-PkEncryption.prototype['free'] = function() {
- Module['_olm_clear_pk_encryption'](this.ptr);
- free(this.ptr);
-}
-
-PkEncryption.prototype['set_recipient_key'] = restore_stack(function(key) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- pk_encryption_method(Module['_olm_pk_encryption_set_recipient_key'])(
- this.ptr, key_buffer, key_array.length
- );
-});
-
-PkEncryption.prototype['encrypt'] = restore_stack(function(
- plaintext
-) {
- var plaintext_buffer, ciphertext_buffer, plaintext_length, random, random_length;
- try {
- plaintext_length = lengthBytesUTF8(plaintext)
- plaintext_buffer = malloc(plaintext_length + 1);
- stringToUTF8(plaintext, plaintext_buffer, plaintext_length + 1);
- random_length = pk_encryption_method(
- Module['_olm_pk_encrypt_random_length']
- )();
- random = random_stack(random_length);
- var ciphertext_length = pk_encryption_method(
- Module['_olm_pk_ciphertext_length']
- )(this.ptr, plaintext_length);
- ciphertext_buffer = malloc(ciphertext_length + NULL_BYTE_PADDING_LENGTH);
- var mac_length = pk_encryption_method(
- Module['_olm_pk_mac_length']
- )(this.ptr);
- var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH);
- setValue(
- mac_buffer + mac_length,
- 0, "i8"
- );
- var ephemeral_length = pk_encryption_method(
- Module['_olm_pk_key_length']
- )();
- var ephemeral_buffer = stack(ephemeral_length + NULL_BYTE_PADDING_LENGTH);
- setValue(
- ephemeral_buffer + ephemeral_length,
- 0, "i8"
- );
- pk_encryption_method(Module['_olm_pk_encrypt'])(
- this.ptr,
- plaintext_buffer, plaintext_length,
- ciphertext_buffer, ciphertext_length,
- mac_buffer, mac_length,
- ephemeral_buffer, ephemeral_length,
- random, random_length
- );
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- ciphertext_buffer + ciphertext_length,
- 0, "i8"
- );
- return {
- "ciphertext": UTF8ToString(ciphertext_buffer, ciphertext_length),
- "mac": UTF8ToString(mac_buffer, mac_length),
- "ephemeral": UTF8ToString(ephemeral_buffer, ephemeral_length)
- };
- } finally {
- if (random !== undefined) {
- // clear out the random buffer, since it is key data
- bzero(random, random_length);
- }
- if (plaintext_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, plaintext_length + 1);
- free(plaintext_buffer);
- }
- if (ciphertext_buffer !== undefined) {
- free(ciphertext_buffer);
- }
- }
-});
-
-
-function PkDecryption() {
- var size = Module['_olm_pk_decryption_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_pk_decryption'](this.buf);
-}
-
-function pk_decryption_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_pk_decryption_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-PkDecryption.prototype['free'] = function() {
- Module['_olm_clear_pk_decryption'](this.ptr);
- free(this.ptr);
-}
-
-PkDecryption.prototype['init_with_private_key'] = restore_stack(function (private_key) {
- var private_key_buffer = stack(private_key.length);
- Module['HEAPU8'].set(private_key, private_key_buffer);
-
- var pubkey_length = pk_decryption_method(
- Module['_olm_pk_key_length']
- )();
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
- try {
- pk_decryption_method(Module['_olm_pk_key_from_private'])(
- this.ptr,
- pubkey_buffer, pubkey_length,
- private_key_buffer, private_key.length
- );
- } finally {
- // clear out our copy of the private key
- bzero(private_key_buffer, private_key.length);
- }
- return UTF8ToString(pubkey_buffer, pubkey_length);
-});
-
-PkDecryption.prototype['generate_key'] = restore_stack(function () {
- var random_length = pk_decryption_method(
- Module['_olm_pk_private_key_length']
- )();
- var random_buffer = random_stack(random_length);
- var pubkey_length = pk_decryption_method(
- Module['_olm_pk_key_length']
- )();
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
- try {
- pk_decryption_method(Module['_olm_pk_key_from_private'])(
- this.ptr,
- pubkey_buffer, pubkey_length,
- random_buffer, random_length
- );
- } finally {
- // clear out the random buffer (= private key)
- bzero(random_buffer, random_length);
- }
- return UTF8ToString(pubkey_buffer, pubkey_length);
-});
-
-PkDecryption.prototype['get_private_key'] = restore_stack(function () {
- var privkey_length = pk_encryption_method(
- Module['_olm_pk_private_key_length']
- )();
- var privkey_buffer = stack(privkey_length);
- pk_decryption_method(Module['_olm_pk_get_private_key'])(
- this.ptr,
- privkey_buffer, privkey_length
- );
- // The inner Uint8Array creates a view of the buffer. The outer Uint8Array
- // copies it to a new array to return, since the original buffer will get
- // deallocated from the stack and could get overwritten.
- var key_arr = new Uint8Array(
- new Uint8Array(Module['HEAPU8'].buffer, privkey_buffer, privkey_length)
- );
- bzero(privkey_buffer, privkey_length); // clear out our copy of the key
- return key_arr;
-});
-
-PkDecryption.prototype['pickle'] = restore_stack(function (key) {
- var key_array = array_from_string(key);
- var pickle_length = pk_decryption_method(
- Module['_olm_pickle_pk_decryption_length']
- )(this.ptr);
- var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
- try {
- pk_decryption_method(Module['_olm_pickle_pk_decryption'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
- return UTF8ToString(pickle_buffer, pickle_length);
-});
-
-PkDecryption.prototype['unpickle'] = restore_stack(function (key, pickle) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- var pickle_array = array_from_string(pickle);
- var pickle_buffer = stack(pickle_array);
- var ephemeral_length = pk_decryption_method(
- Module["_olm_pk_key_length"]
- )();
- var ephemeral_buffer = stack(ephemeral_length + NULL_BYTE_PADDING_LENGTH);
- try {
- pk_decryption_method(Module['_olm_unpickle_pk_decryption'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer,
- pickle_array.length, ephemeral_buffer, ephemeral_length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
- return UTF8ToString(ephemeral_buffer, ephemeral_length);
-});
-
-PkDecryption.prototype['decrypt'] = restore_stack(function (
- ephemeral_key, mac, ciphertext
-) {
- var plaintext_buffer, ciphertext_buffer, plaintext_max_length;
- try {
- var ciphertext_length = lengthBytesUTF8(ciphertext)
- ciphertext_buffer = malloc(ciphertext_length + 1);
- stringToUTF8(ciphertext, ciphertext_buffer, ciphertext_length + 1);
- var ephemeralkey_array = array_from_string(ephemeral_key);
- var ephemeralkey_buffer = stack(ephemeralkey_array);
- var mac_array = array_from_string(mac);
- var mac_buffer = stack(mac_array);
- plaintext_max_length = pk_decryption_method(Module['_olm_pk_max_plaintext_length'])(
- this.ptr,
- ciphertext_length
- );
- plaintext_buffer = malloc(plaintext_max_length + NULL_BYTE_PADDING_LENGTH);
- var plaintext_length = pk_decryption_method(Module['_olm_pk_decrypt'])(
- this.ptr,
- ephemeralkey_buffer, ephemeralkey_array.length,
- mac_buffer, mac_array.length,
- ciphertext_buffer, ciphertext_length,
- plaintext_buffer, plaintext_max_length
- );
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- plaintext_buffer + plaintext_length,
- 0, "i8"
- );
- return UTF8ToString(plaintext_buffer, plaintext_length);
- } finally {
- if (plaintext_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, plaintext_length + 1);
- free(plaintext_buffer);
- }
- if (ciphertext_buffer !== undefined) {
- free(ciphertext_buffer);
- }
- }
-})
-
-
-function PkSigning() {
- var size = Module['_olm_pk_signing_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_pk_signing'](this.buf);
-}
-
-function pk_signing_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_pk_signing_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-PkSigning.prototype['free'] = function() {
- Module['_olm_clear_pk_signing'](this.ptr);
- free(this.ptr);
-}
-
-PkSigning.prototype['init_with_seed'] = restore_stack(function (seed) {
- var seed_buffer = stack(seed.length);
- Module['HEAPU8'].set(seed, seed_buffer);
-
- var pubkey_length = pk_signing_method(
- Module['_olm_pk_signing_public_key_length']
- )();
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
- try {
- pk_signing_method(Module['_olm_pk_signing_key_from_seed'])(
- this.ptr,
- pubkey_buffer, pubkey_length,
- seed_buffer, seed.length
- );
- } finally {
- // clear out our copy of the seed
- bzero(seed_buffer, seed.length);
- }
- return UTF8ToString(pubkey_buffer, pubkey_length);
-});
-
-PkSigning.prototype['generate_seed'] = restore_stack(function () {
- var random_length = pk_signing_method(
- Module['_olm_pk_signing_seed_length']
- )();
- var random_buffer = random_stack(random_length);
- var key_arr = new Uint8Array(
- new Uint8Array(Module['HEAPU8'].buffer, random_buffer, random_length)
- );
- bzero(random_buffer, random_length);
- return key_arr;
-});
-
-PkSigning.prototype['sign'] = restore_stack(function (message) {
- // XXX: Should be able to sign any bytes rather than just strings,
- // but this is consistent with encrypt for now.
- //var message_buffer = stack(message.length);
- //Module['HEAPU8'].set(message, message_buffer);
- var message_buffer, message_length;
-
- try {
- message_length = lengthBytesUTF8(message)
- message_buffer = malloc(message_length + 1);
- stringToUTF8(message, message_buffer, message_length + 1);
-
- var sig_length = pk_signing_method(
- Module['_olm_pk_signature_length']
- )();
- var sig_buffer = stack(sig_length + NULL_BYTE_PADDING_LENGTH);
- pk_signing_method(Module['_olm_pk_sign'])(
- this.ptr,
- message_buffer, message_length,
- sig_buffer, sig_length
- );
- return UTF8ToString(sig_buffer, sig_length);
- } finally {
- if (message_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(message_buffer, message_length + 1);
- free(message_buffer);
- }
- }
-});
diff --git a/javascript/olm_post.js b/javascript/olm_post.js
deleted file mode 100644
index 450861a..0000000
--- a/javascript/olm_post.js
+++ /dev/null
@@ -1,587 +0,0 @@
-var malloc = Module['_malloc'];
-var free = Module['_free'];
-var OLM_ERROR;
-
-function filled_stack(size, filler) {
- var ptr = stackAlloc(size);
- filler(new Uint8Array(Module['HEAPU8'].buffer, ptr, size));
- return ptr;
-}
-
-/* allocate a number of bytes of storage on the stack.
- *
- * If size_or_array is a Number, allocates that number of zero-initialised bytes.
- */
-function stack(size_or_array) {
- return (typeof size_or_array == 'number')
- ? filled_stack(size_or_array, function(x) { x.fill(0) })
- : filled_stack(size_or_array.length, function(x) { x.set(size_or_array) });
-}
-
-function array_from_string(string) {
- return string instanceof Uint8Array ? string : intArrayFromString(string, true);
-}
-
-function random_stack(size) {
- return filled_stack(size, get_random_values);
-}
-
-function restore_stack(wrapped) {
- return function() {
- var sp = stackSave();
- try {
- return wrapped.apply(this, arguments);
- } finally {
- stackRestore(sp);
- }
- }
-}
-
-/* set a memory area to zero */
-function bzero(ptr, n) {
- while(n-- > 0) {
- Module['HEAP8'][ptr++] = 0;
- }
-}
-
-function Account() {
- var size = Module['_olm_account_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_account'](this.buf);
-}
-
-function account_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_account_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-Account.prototype['free'] = function() {
- Module['_olm_clear_account'](this.ptr);
- free(this.ptr);
-}
-
-Account.prototype['create'] = restore_stack(function() {
- var random_length = account_method(
- Module['_olm_create_account_random_length']
- )(this.ptr);
- var random = random_stack(random_length);
- account_method(Module['_olm_create_account'])(
- this.ptr, random, random_length
- );
-});
-
-Account.prototype['identity_keys'] = restore_stack(function() {
- var keys_length = account_method(
- Module['_olm_account_identity_keys_length']
- )(this.ptr);
- var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH);
- account_method(Module['_olm_account_identity_keys'])(
- this.ptr, keys, keys_length
- );
- return UTF8ToString(keys, keys_length);
-});
-
-Account.prototype['sign'] = restore_stack(function(message) {
- var signature_length = account_method(
- Module['_olm_account_signature_length']
- )(this.ptr);
- var message_array = array_from_string(message);
- var message_buffer = stack(message_array);
- var signature_buffer = stack(signature_length + NULL_BYTE_PADDING_LENGTH);
- try {
- account_method(Module['_olm_account_sign'])(
- this.ptr,
- message_buffer, message_array.length,
- signature_buffer, signature_length
- );
- } finally {
- // clear out copies of the message, which may be plaintext
- bzero(message_buffer, message_array.length);
- for (var i = 0; i < message_array.length; i++) {
- message_array[i] = 0;
- }
- }
- return UTF8ToString(signature_buffer, signature_length);
-});
-
-Account.prototype['one_time_keys'] = restore_stack(function() {
- var keys_length = account_method(
- Module['_olm_account_one_time_keys_length']
- )(this.ptr);
- var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH);
- account_method(Module['_olm_account_one_time_keys'])(
- this.ptr, keys, keys_length
- );
- return UTF8ToString(keys, keys_length);
-});
-
-Account.prototype['mark_keys_as_published'] = restore_stack(function() {
- account_method(Module['_olm_account_mark_keys_as_published'])(this.ptr);
-});
-
-Account.prototype['max_number_of_one_time_keys'] = restore_stack(function() {
- return account_method(Module['_olm_account_max_number_of_one_time_keys'])(
- this.ptr
- );
-});
-
-Account.prototype['generate_one_time_keys'] = restore_stack(function(
- number_of_keys
-) {
- var random_length = account_method(
- Module['_olm_account_generate_one_time_keys_random_length']
- )(this.ptr, number_of_keys);
- var random = random_stack(random_length);
- account_method(Module['_olm_account_generate_one_time_keys'])(
- this.ptr, number_of_keys, random, random_length
- );
-});
-
-Account.prototype['remove_one_time_keys'] = restore_stack(function(session) {
- account_method(Module['_olm_remove_one_time_keys'])(
- this.ptr, session.ptr
- );
-});
-
-Account.prototype['generate_fallback_key'] = restore_stack(function() {
- var random_length = account_method(
- Module['_olm_account_generate_fallback_key_random_length']
- )(this.ptr);
- var random = random_stack(random_length);
- account_method(Module['_olm_account_generate_fallback_key'])(
- this.ptr, random, random_length
- );
-});
-
-Account.prototype['fallback_key'] = restore_stack(function() {
- var keys_length = account_method(
- Module['_olm_account_fallback_key_length']
- )(this.ptr);
- var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH);
- account_method(Module['_olm_account_fallback_key'])(
- this.ptr, keys, keys_length
- );
- return UTF8ToString(keys, keys_length);
-});
-
-Account.prototype['pickle'] = restore_stack(function(key) {
- var key_array = array_from_string(key);
- var pickle_length = account_method(
- Module['_olm_pickle_account_length']
- )(this.ptr);
- var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
- try {
- account_method(Module['_olm_pickle_account'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
- return UTF8ToString(pickle_buffer, pickle_length);
-});
-
-Account.prototype['unpickle'] = restore_stack(function(key, pickle) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- var pickle_array = array_from_string(pickle);
- var pickle_buffer = stack(pickle_array);
- try {
- account_method(Module['_olm_unpickle_account'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer,
- pickle_array.length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
-});
-
-function Session() {
- var size = Module['_olm_session_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_session'](this.buf);
-}
-
-function session_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_session_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-Session.prototype['free'] = function() {
- Module['_olm_clear_session'](this.ptr);
- free(this.ptr);
-}
-
-Session.prototype['pickle'] = restore_stack(function(key) {
- var key_array = array_from_string(key);
- var pickle_length = session_method(
- Module['_olm_pickle_session_length']
- )(this.ptr);
- var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
- try {
- session_method(Module['_olm_pickle_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
- return UTF8ToString(pickle_buffer, pickle_length);
-});
-
-Session.prototype['unpickle'] = restore_stack(function(key, pickle) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- var pickle_array = array_from_string(pickle);
- var pickle_buffer = stack(pickle_array);
- try {
- session_method(Module['_olm_unpickle_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer,
- pickle_array.length
- );
- } finally {
- // clear out copies of the pickle key
- bzero(key_buffer, key_array.length)
- for (var i = 0; i < key_array.length; i++) {
- key_array[i] = 0;
- }
- }
-});
-
-Session.prototype['create_outbound'] = restore_stack(function(
- account, their_identity_key, their_one_time_key
-) {
- var random_length = session_method(
- Module['_olm_create_outbound_session_random_length']
- )(this.ptr);
- var random = random_stack(random_length);
- var identity_key_array = array_from_string(their_identity_key);
- var one_time_key_array = array_from_string(their_one_time_key);
- var identity_key_buffer = stack(identity_key_array);
- var one_time_key_buffer = stack(one_time_key_array);
- try {
- session_method(Module['_olm_create_outbound_session'])(
- this.ptr, account.ptr,
- identity_key_buffer, identity_key_array.length,
- one_time_key_buffer, one_time_key_array.length,
- random, random_length
- );
- } finally {
- // clear the random buffer, which is key data
- bzero(random, random_length);
- }
-});
-
-Session.prototype['create_inbound'] = restore_stack(function(
- account, one_time_key_message
-) {
- var message_array = array_from_string(one_time_key_message);
- var message_buffer = stack(message_array);
- try {
- session_method(Module['_olm_create_inbound_session'])(
- this.ptr, account.ptr, message_buffer, message_array.length
- );
- } finally {
- // clear out copies of the key
- bzero(message_buffer, message_array.length);
- for (var i = 0; i < message_array.length; i++) {
- message_array[i] = 0;
- }
- }
-});
-
-Session.prototype['create_inbound_from'] = restore_stack(function(
- account, identity_key, one_time_key_message
-) {
- var identity_key_array = array_from_string(identity_key);
- var identity_key_buffer = stack(identity_key_array);
- var message_array = array_from_string(one_time_key_message);
- var message_buffer = stack(message_array);
- try {
- session_method(Module['_olm_create_inbound_session_from'])(
- this.ptr, account.ptr,
- identity_key_buffer, identity_key_array.length,
- message_buffer, message_array.length
- );
- } finally {
- // clear out copies of the key
- bzero(message_buffer, message_array.length);
- for (var i = 0; i < message_array.length; i++) {
- message_array[i] = 0;
- }
- }
-});
-
-Session.prototype['session_id'] = restore_stack(function() {
- var id_length = session_method(Module['_olm_session_id_length'])(this.ptr);
- var id_buffer = stack(id_length + NULL_BYTE_PADDING_LENGTH);
- session_method(Module['_olm_session_id'])(
- this.ptr, id_buffer, id_length
- );
- return UTF8ToString(id_buffer, id_length);
-});
-
-Session.prototype['has_received_message'] = function() {
- return session_method(Module['_olm_session_has_received_message'])(
- this.ptr
- ) ? true : false;
-};
-
-
-Session.prototype['matches_inbound'] = restore_stack(function(
- one_time_key_message
-) {
- var message_array = array_from_string(one_time_key_message);
- var message_buffer = stack(message_array);
- return session_method(Module['_olm_matches_inbound_session'])(
- this.ptr, message_buffer, message_array.length
- ) ? true : false;
-});
-
-Session.prototype['matches_inbound_from'] = restore_stack(function(
- identity_key, one_time_key_message
-) {
- var identity_key_array = array_from_string(identity_key);
- var identity_key_buffer = stack(identity_key_array);
- var message_array = array_from_string(one_time_key_message);
- var message_buffer = stack(message_array);
- return session_method(Module['_olm_matches_inbound_session_from'])(
- this.ptr,
- identity_key_buffer, identity_key_array.length,
- message_buffer, message_array.length
- ) ? true : false;
-});
-
-Session.prototype['encrypt'] = restore_stack(function(
- plaintext
-) {
- var plaintext_buffer, message_buffer, plaintext_length, random, random_length;
- try {
- random_length = session_method(
- Module['_olm_encrypt_random_length']
- )(this.ptr);
- var message_type = session_method(
- Module['_olm_encrypt_message_type']
- )(this.ptr);
-
- plaintext_length = lengthBytesUTF8(plaintext);
- var message_length = session_method(
- Module['_olm_encrypt_message_length']
- )(this.ptr, plaintext_length);
-
- random = random_stack(random_length);
-
- // need to allow space for the terminator (which stringToUTF8 always
- // writes), hence + 1.
- plaintext_buffer = malloc(plaintext_length + 1);
- stringToUTF8(plaintext, plaintext_buffer, plaintext_length + 1);
-
- message_buffer = malloc(message_length + NULL_BYTE_PADDING_LENGTH);
-
- session_method(Module['_olm_encrypt'])(
- this.ptr,
- plaintext_buffer, plaintext_length,
- random, random_length,
- message_buffer, message_length
- );
-
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- message_buffer+message_length,
- 0, "i8"
- );
-
- return {
- "type": message_type,
- "body": UTF8ToString(message_buffer, message_length),
- };
- } finally {
- if (random !== undefined) {
- // clear out the random buffer, since it is the private key
- bzero(random, random_length);
- }
- if (plaintext_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, plaintext_length + 1);
- free(plaintext_buffer);
- }
- if (message_buffer !== undefined) {
- free(message_buffer);
- }
- }
-});
-
-Session.prototype['decrypt'] = restore_stack(function(
- message_type, message
-) {
- var message_buffer, plaintext_buffer, max_plaintext_length;
-
- try {
- message_buffer = malloc(message.length);
- writeAsciiToMemory(message, message_buffer, true);
-
- max_plaintext_length = session_method(
- Module['_olm_decrypt_max_plaintext_length']
- )(this.ptr, message_type, message_buffer, message.length);
-
- // caculating the length destroys the input buffer, so we need to re-copy it.
- writeAsciiToMemory(message, message_buffer, true);
-
- plaintext_buffer = malloc(max_plaintext_length + NULL_BYTE_PADDING_LENGTH);
-
- var plaintext_length = session_method(Module["_olm_decrypt"])(
- this.ptr, message_type,
- message_buffer, message.length,
- plaintext_buffer, max_plaintext_length
- );
-
- // UTF8ToString requires a null-terminated argument, so add the
- // null terminator.
- setValue(
- plaintext_buffer+plaintext_length,
- 0, "i8"
- );
-
- return UTF8ToString(plaintext_buffer, plaintext_length);
- } finally {
- if (message_buffer !== undefined) {
- free(message_buffer);
- }
- if (plaintext_buffer !== undefined) {
- // don't leave a copy of the plaintext in the heap.
- bzero(plaintext_buffer, max_plaintext_length);
- free(plaintext_buffer);
- }
- }
-
-});
-
-Session.prototype['describe'] = restore_stack(function() {
- var description_buf;
- try {
- description_buf = malloc(256);
- session_method(Module['_olm_session_describe'])(
- this.ptr, description_buf, 256
- );
- return UTF8ToString(description_buf);
- } finally {
- if (description_buf !== undefined) free(description_buf);
- }
-});
-
-function Utility() {
- var size = Module['_olm_utility_size']();
- this.buf = malloc(size);
- this.ptr = Module['_olm_utility'](this.buf);
-}
-
-function utility_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_utility_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-Utility.prototype['free'] = function() {
- Module['_olm_clear_utility'](this.ptr);
- free(this.ptr);
-}
-
-Utility.prototype['sha256'] = restore_stack(function(input) {
- var output_length = utility_method(Module['_olm_sha256_length'])(this.ptr);
- var input_array = array_from_string(input);
- var input_buffer = stack(input_array);
- var output_buffer = stack(output_length + NULL_BYTE_PADDING_LENGTH);
- try {
- utility_method(Module['_olm_sha256'])(
- this.ptr,
- input_buffer, input_array.length,
- output_buffer, output_length
- );
- } finally {
- // clear out copies of the input buffer, which may be plaintext
- bzero(input_buffer, input_array.length);
- for (var i = 0; i < input_array.length; i++) {
- input_array[i] = 0;
- }
- }
- return UTF8ToString(output_buffer, output_length);
-});
-
-Utility.prototype['ed25519_verify'] = restore_stack(function(
- key, message, signature
-) {
- var key_array = array_from_string(key);
- var key_buffer = stack(key_array);
- var message_array = array_from_string(message);
- var message_buffer = stack(message_array);
- var signature_array = array_from_string(signature);
- var signature_buffer = stack(signature_array);
- try {
- utility_method(Module['_olm_ed25519_verify'])(
- this.ptr,
- key_buffer, key_array.length,
- message_buffer, message_array.length,
- signature_buffer, signature_array.length
- );
- } finally {
- // clear out copies of the input buffer, which may be plaintext
- bzero(message_buffer, message_array.length);
- for (var i = 0; i < message_array.length; i++) {
- message_array[i] = 0;
- }
- }
-});
-
-olm_exports["Account"] = Account;
-olm_exports["Session"] = Session;
-olm_exports["Utility"] = Utility;
-olm_exports["PkEncryption"] = PkEncryption;
-olm_exports["PkDecryption"] = PkDecryption;
-olm_exports["PkSigning"] = PkSigning;
-olm_exports["SAS"] = SAS;
-
-olm_exports["get_library_version"] = restore_stack(function() {
- var buf = stack(3);
- Module['_olm_get_library_version'](buf, buf+1, buf+2);
- return [
- getValue(buf, 'i8'),
- getValue(buf+1, 'i8'),
- getValue(buf+2, 'i8'),
- ];
-});
diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js
deleted file mode 100644
index 314d7da..0000000
--- a/javascript/olm_pre.js
+++ /dev/null
@@ -1,49 +0,0 @@
-var get_random_values;
-
-if (typeof(window) !== 'undefined') {
- // We're in a browser (directly, via browserify, or via webpack).
- get_random_values = function(buf) {
- window.crypto.getRandomValues(buf);
- };
-} else if (module["exports"]) {
- // We're running in node.
- var nodeCrypto = require("crypto");
- get_random_values = function(buf) {
- // [''] syntax needed here rather than '.' to prevent
- // closure compiler from mangling the import(!)
- var bytes = nodeCrypto['randomBytes'](buf.length);
- buf.set(bytes);
- };
- process = global["process"];
-} else {
- throw new Error("Cannot find global to attach library to");
-}
-
-/* applications should define OLM_OPTIONS in the environment to override
- * emscripten module settings
- */
-if (typeof(OLM_OPTIONS) !== 'undefined') {
- for (var olm_option_key in OLM_OPTIONS) {
- if (OLM_OPTIONS.hasOwnProperty(olm_option_key)) {
- Module[olm_option_key] = OLM_OPTIONS[olm_option_key];
- }
- }
-}
-
-/* The 'length' argument to Pointer_stringify doesn't work if the input
- * includes characters >= 128, which makes Pointer_stringify unreliable. We
- * could use it on strings which are known to be ascii, but that seems
- * dangerous. Instead we add a NULL character to all of our strings and just
- * use UTF8ToString.
- */
-var NULL_BYTE_PADDING_LENGTH = 1;
-
-Module['onRuntimeInitialized'] = function() {
- OLM_ERROR = Module['_olm_error']();
- olm_exports["PRIVATE_KEY_LENGTH"] = Module['_olm_pk_private_key_length']();
- if (onInitSuccess) onInitSuccess();
-};
-
-Module['onAbort'] = function(err) {
- if (onInitFail) onInitFail(err);
-};
diff --git a/javascript/olm_prefix.js b/javascript/olm_prefix.js
deleted file mode 100644
index ae2d9f9..0000000
--- a/javascript/olm_prefix.js
+++ /dev/null
@@ -1,4 +0,0 @@
-var Olm = (function() {
-var olm_exports = {};
-var onInitSuccess;
-var onInitFail;
diff --git a/javascript/olm_sas.js b/javascript/olm_sas.js
deleted file mode 100644
index 38535d5..0000000
--- a/javascript/olm_sas.js
+++ /dev/null
@@ -1,99 +0,0 @@
-function SAS() {
- var size = Module['_olm_sas_size']();
- var random_length = Module['_olm_create_sas_random_length']();
- var random = random_stack(random_length);
- this.buf = malloc(size);
- this.ptr = Module['_olm_sas'](this.buf);
- Module['_olm_create_sas'](this.ptr, random, random_length);
- bzero(random, random_length);
-}
-
-function sas_method(wrapped) {
- return function() {
- var result = wrapped.apply(this, arguments);
- if (result === OLM_ERROR) {
- var message = UTF8ToString(
- Module['_olm_sas_last_error'](arguments[0])
- );
- throw new Error("OLM." + message);
- }
- return result;
- }
-}
-
-SAS.prototype['free'] = function() {
- Module['_olm_clear_sas'](this.ptr);
- free(this.ptr);
-};
-
-SAS.prototype['get_pubkey'] = restore_stack(function() {
- var pubkey_length = sas_method(Module['_olm_sas_pubkey_length'])(this.ptr);
- var pubkey_buffer = stack(pubkey_length + NULL_BYTE_PADDING_LENGTH);
- sas_method(Module['_olm_sas_get_pubkey'])(this.ptr, pubkey_buffer, pubkey_length);
- return UTF8ToString(pubkey_buffer, pubkey_length);
-});
-
-SAS.prototype['set_their_key'] = restore_stack(function(their_key) {
- var their_key_array = array_from_string(their_key);
- var their_key_buffer = stack(their_key_array);
- sas_method(Module['_olm_sas_set_their_key'])(
- this.ptr,
- their_key_buffer, their_key_array.length
- );
-});
-
-SAS.prototype['is_their_key_set'] = restore_stack(function() {
- return sas_method(Module['_olm_sas_is_their_key_set'])(
- this.ptr
- ) ? true : false;
-});
-
-SAS.prototype['generate_bytes'] = restore_stack(function(info, length) {
- var info_array = array_from_string(info);
- var info_buffer = stack(info_array);
- var output_buffer = stack(length);
- sas_method(Module['_olm_sas_generate_bytes'])(
- this.ptr,
- info_buffer, info_array.length,
- output_buffer, length
- );
- // The inner Uint8Array creates a view of the buffer. The outer Uint8Array
- // copies it to a new array to return, since the original buffer will get
- // deallocated from the stack and could get overwritten.
- var output_arr = new Uint8Array(
- new Uint8Array(Module['HEAPU8'].buffer, output_buffer, length)
- );
- return output_arr;
-});
-
-SAS.prototype['calculate_mac'] = restore_stack(function(input, info) {
- var input_array = array_from_string(input);
- var input_buffer = stack(input_array);
- var info_array = array_from_string(info);
- var info_buffer = stack(info_array);
- var mac_length = sas_method(Module['_olm_sas_mac_length'])(this.ptr);
- var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH);
- sas_method(Module['_olm_sas_calculate_mac'])(
- this.ptr,
- input_buffer, input_array.length,
- info_buffer, info_array.length,
- mac_buffer, mac_length
- );
- return UTF8ToString(mac_buffer, mac_length);
-});
-
-SAS.prototype['calculate_mac_long_kdf'] = restore_stack(function(input, info) {
- var input_array = array_from_string(input);
- var input_buffer = stack(input_array);
- var info_array = array_from_string(info);
- var info_buffer = stack(info_array);
- var mac_length = sas_method(Module['_olm_sas_mac_length'])(this.ptr);
- var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH);
- sas_method(Module['_olm_sas_calculate_mac_long_kdf'])(
- this.ptr,
- input_buffer, input_array.length,
- info_buffer, info_array.length,
- mac_buffer, mac_length
- );
- return UTF8ToString(mac_buffer, mac_length);
-});
diff --git a/javascript/olm_suffix.js b/javascript/olm_suffix.js
deleted file mode 100644
index d6f72b7..0000000
--- a/javascript/olm_suffix.js
+++ /dev/null
@@ -1,36 +0,0 @@
-var olmInitPromise;
-
-olm_exports['init'] = function(opts) {
- if (olmInitPromise) return olmInitPromise;
-
- if (opts) OLM_OPTIONS = opts;
-
- olmInitPromise = new Promise(function(resolve, reject) {
- onInitSuccess = function() {
- resolve();
- };
- onInitFail = function(err) {
- reject(err);
- };
- Module();
- });
- return olmInitPromise;
-};
-
-return olm_exports;
-
-})();
-
-if (typeof(window) !== 'undefined') {
- // We've been imported directly into a browser. Define the global 'Olm' object.
- // (we do this even if module.exports was defined, because it's useful to have
- // Olm in the global scope for browserified and webpacked apps.)
- window["Olm"] = Olm;
-}
-
-if (typeof module === 'object') {
- // Emscripten sets the module exports to be its module
- // with wrapped c functions. Clobber it with our higher
- // level wrapper class.
- module.exports = Olm;
-}
diff --git a/javascript/package.json b/javascript/package.json
deleted file mode 100644
index c479a98..0000000
--- a/javascript/package.json
+++ /dev/null
@@ -1,33 +0,0 @@
-{
- "name": "olm",
- "version": "3.2.1",
- "description": "An implementation of the Double Ratchet cryptographic ratchet",
- "main": "olm.js",
- "files": [
- "olm.js",
- "olm.wasm",
- "olm_legacy.js",
- "index.d.ts",
- "README.md"
- ],
- "scripts": {
- "build": "make -C .. js",
- "test": "jasmine-node test --verbose --junitreport --captureExceptions"
- },
- "repository": {
- "type": "git",
- "url": "git+https://github.com/matrix-org/olm.git"
- },
- "keywords": [
- "matrix-org"
- ],
- "author": "matrix.org",
- "license": "Apache-2.0",
- "bugs": {
- "url": "https://github.com/matrix-org/olm/issues"
- },
- "homepage": "https://github.com/matrix-org/olm#readme",
- "devDependencies": {
- "jasmine-node": "^1.14.5"
- }
-}
diff --git a/javascript/test/megolm.spec.js b/javascript/test/megolm.spec.js
deleted file mode 100644
index 241d4bd..0000000
--- a/javascript/test/megolm.spec.js
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-Copyright 2016 OpenMarket Ltd
-Copyright 2018 New Vector Ltd
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-"use strict";
-
-var Olm = require('../olm');
-
-describe("megolm", function() {
- var aliceSession, bobSession;
-
- beforeEach(function(done) {
- Olm.init().then(function() {
- aliceSession = new Olm.OutboundGroupSession();
- bobSession = new Olm.InboundGroupSession();
-
- done();
- });
- });
-
- afterEach(function() {
- if (aliceSession !== undefined) {
- aliceSession.free();
- aliceSession = undefined;
- }
-
- if (bobSession !== undefined) {
- bobSession.free();
- bobSession = undefined;
- }
- });
-
- it("should encrypt and decrypt", function() {
- aliceSession.create();
- expect(aliceSession.message_index()).toEqual(0);
- bobSession.create(aliceSession.session_key());
-
- var TEST_TEXT='têst1';
- var encrypted = aliceSession.encrypt(TEST_TEXT);
- var decrypted = bobSession.decrypt(encrypted);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted.plaintext).toEqual(TEST_TEXT);
- expect(decrypted.message_index).toEqual(0);
-
- TEST_TEXT='hot beverage: ☕';
- encrypted = aliceSession.encrypt(TEST_TEXT);
- decrypted = bobSession.decrypt(encrypted);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted.plaintext).toEqual(TEST_TEXT);
- expect(decrypted.message_index).toEqual(1);
-
- // shorter text, to spot buffer overruns
- TEST_TEXT='☕';
- encrypted = aliceSession.encrypt(TEST_TEXT);
- decrypted = bobSession.decrypt(encrypted);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted.plaintext).toEqual(TEST_TEXT);
- expect(decrypted.message_index).toEqual(2);
- });
-});
diff --git a/javascript/test/olm.spec.js b/javascript/test/olm.spec.js
deleted file mode 100644
index a698314..0000000
--- a/javascript/test/olm.spec.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
-Copyright 2016 OpenMarket Ltd
-Copyright 2018 New Vector Ltd
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-"use strict";
-
-var Olm = require('../olm');
-
-if (!Object.keys) {
- Object.keys = function(o) {
- var k=[], p;
- for (p in o) if (Object.prototype.hasOwnProperty.call(o,p)) k.push(p);
- return k;
- }
-}
-
-describe("olm", function() {
- var aliceAccount, bobAccount;
- var aliceSession, bobSession;
-
- beforeEach(function(done) {
- // This should really be in a beforeAll, but jasmine-node
- // doesn't support that
- Olm.init().then(function() {
- aliceAccount = new Olm.Account();
- bobAccount = new Olm.Account();
- aliceSession = new Olm.Session();
- bobSession = new Olm.Session();
-
- done();
- });
- });
-
- afterEach(function() {
- if (aliceAccount !== undefined) {
- aliceAccount.free();
- aliceAccount = undefined;
- }
-
- if (bobAccount !== undefined) {
- bobAccount.free();
- bobAccount = undefined;
- }
-
- if (aliceSession !== undefined) {
- aliceSession.free();
- aliceSession = undefined;
- }
-
- if (bobSession !== undefined) {
- bobSession.free();
- bobSession = undefined;
- }
- });
-
- it('should encrypt and decrypt', function() {
- aliceAccount.create();
- bobAccount.create();
-
- bobAccount.generate_one_time_keys(1);
- var bobOneTimeKeys = JSON.parse(bobAccount.one_time_keys()).curve25519;
- bobAccount.mark_keys_as_published();
-
- var bobIdKey = JSON.parse(bobAccount.identity_keys()).curve25519;
-
- var otk_id = Object.keys(bobOneTimeKeys)[0];
-
- aliceSession.create_outbound(
- aliceAccount, bobIdKey, bobOneTimeKeys[otk_id]
- );
-
- var TEST_TEXT='têst1';
- var encrypted = aliceSession.encrypt(TEST_TEXT);
- expect(encrypted.type).toEqual(0);
- bobSession.create_inbound(bobAccount, encrypted.body);
- bobAccount.remove_one_time_keys(bobSession);
- var decrypted = bobSession.decrypt(encrypted.type, encrypted.body);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted).toEqual(TEST_TEXT);
-
- TEST_TEXT='hot beverage: ☕';
- encrypted = bobSession.encrypt(TEST_TEXT);
- expect(encrypted.type).toEqual(1);
- decrypted = aliceSession.decrypt(encrypted.type, encrypted.body);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted).toEqual(TEST_TEXT);
- });
-});
diff --git a/javascript/test/pk.spec.js b/javascript/test/pk.spec.js
deleted file mode 100644
index f212b96..0000000
--- a/javascript/test/pk.spec.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
-Copyright 2018, 2019 New Vector Ltd
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-"use strict";
-
-var Olm = require('../olm');
-
-describe("pk", function() {
- var encryption, decryption, signing;
-
- beforeEach(function(done) {
- Olm.init().then(function() {
- encryption = new Olm.PkEncryption();
- decryption = new Olm.PkDecryption();
- signing = new Olm.PkSigning();
-
- done();
- });
- });
-
- afterEach(function () {
- if (encryption !== undefined) {
- encryption.free();
- encryption = undefined;
- }
- if (decryption !== undefined) {
- decryption.free();
- decryption = undefined;
- }
- if (signing !== undefined) {
- signing.free();
- signing = undefined;
- }
- });
-
- it('should import & export keys from private parts', function () {
- var alice_private = new Uint8Array([
- 0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
- 0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
- 0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
- 0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
- ]);
- var alice_public = decryption.init_with_private_key(alice_private);
- expect(alice_public).toEqual("hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmo");
-
- var alice_private_out = decryption.get_private_key();
- expect(alice_private_out).toEqual(alice_private);
- });
-
- it('should encrypt and decrypt', function () {
- var TEST_TEXT='têst1';
- var pubkey = decryption.generate_key();
- encryption.set_recipient_key(pubkey);
- var encrypted = encryption.encrypt(TEST_TEXT);
- var decrypted = decryption.decrypt(encrypted.ephemeral, encrypted.mac, encrypted.ciphertext);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted).toEqual(TEST_TEXT);
-
- TEST_TEXT='hot beverage: ☕';
- encryption.set_recipient_key(pubkey);
- encrypted = encryption.encrypt(TEST_TEXT);
- decrypted = decryption.decrypt(encrypted.ephemeral, encrypted.mac, encrypted.ciphertext);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted).toEqual(TEST_TEXT);
- });
-
- it('should pickle and unpickle', function () {
- var TEST_TEXT = 'têst1';
- var pubkey = decryption.generate_key();
- encryption.set_recipient_key(pubkey);
- var encrypted = encryption.encrypt(TEST_TEXT);
-
- var PICKLE_KEY = 'secret_key';
- var pickle = decryption.pickle(PICKLE_KEY);
-
- var new_decryption = new Olm.PkDecryption();
- var new_pubkey = new_decryption.unpickle(PICKLE_KEY, pickle);
- expect(new_pubkey).toEqual(pubkey);
- var decrypted = new_decryption.decrypt(encrypted.ephemeral, encrypted.mac, encrypted.ciphertext);
- console.log(TEST_TEXT, "->", decrypted);
- expect(decrypted).toEqual(TEST_TEXT);
- new_decryption.free();
- });
-
- it('should sign and verify', function () {
- var seed = new Uint8Array([
- 0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
- 0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
- 0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
- 0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
- ]);
-
- var TEST_TEXT = "We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.";
- //var seed = signing.generate_seed();
- var pubkey = signing.init_with_seed(seed);
- var sig = signing.sign(TEST_TEXT);
-
- var util = new Olm.Utility();
- util.ed25519_verify(pubkey, TEST_TEXT, sig);
- var verifyFailure;
- try {
- util.ed25519_verify(pubkey, TEST_TEXT, 'p' + sig.slice(1));
- } catch (e) {
- verifyFailure = e;
- }
- expect(verifyFailure).not.toBeNull();
- util.free();
- });
-});
diff --git a/javascript/test/sas.spec.js b/javascript/test/sas.spec.js
deleted file mode 100644
index 4ab4120..0000000
--- a/javascript/test/sas.spec.js
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-Copyright 2018 New Vector Ltd
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-var Olm = require('../olm');
-
-describe("sas", function() {
- var alice, bob;
-
- beforeEach(async function(done) {
- Olm.init().then(function() {
- alice = new Olm.SAS();
- bob = new Olm.SAS();
-
- done();
- });
- });
-
- afterEach(function () {
- if (alice !== undefined) {
- alice.free();
- alice = undefined;
- }
- if (bob !== undefined) {
- bob.free();
- bob = undefined;
- }
- });
-
- it('should create matching SAS bytes', function () {
- alice.set_their_key(bob.get_pubkey());
- bob.set_their_key(alice.get_pubkey());
- expect(alice.generate_bytes("SAS", 5).toString()).toEqual(bob.generate_bytes("SAS", 5).toString());
- });
-
- it('should create matching MACs', function () {
- alice.set_their_key(bob.get_pubkey());
- bob.set_their_key(alice.get_pubkey());
- expect(alice.calculate_mac("test", "MAC").toString()).toEqual(bob.calculate_mac("test", "MAC").toString());
- });
-
- it('should fail to generate bytes if their key is not set', function () {
- expect(alice.is_their_key_set()).toBeFalsy();
- expect(() => {
- alice.generate_bytes("SAS", 5);
- }).toThrow();
- alice.set_their_key(bob.get_pubkey());
- expect(alice.is_their_key_set()).toBeTruthy();
- });
-});