From 3bd00f09fdf94b6dc6260adceb3b3996019bee6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Mon, 11 Jan 2016 15:46:28 +0000 Subject: [PATCH] some fixes; asynchronous message decryption to keep browser responsive --- nodejs/public/javascripts/openpgp.js | 25 ++- nodejs/public/javascripts/openpgp.worker.js | 193 ++++++++++++++++++++ nodejs/public/javascripts/safechat.js | 57 ++++-- nodejs/public/stylesheets/safechat.css | 5 + nodejs/sockets/index.js | 2 +- nodejs/views/index.ejs | 11 +- 6 files changed, 264 insertions(+), 29 deletions(-) create mode 100644 nodejs/public/javascripts/openpgp.worker.js diff --git a/nodejs/public/javascripts/openpgp.js b/nodejs/public/javascripts/openpgp.js index 4ecef90..72df789 100644 --- a/nodejs/public/javascripts/openpgp.js +++ b/nodejs/public/javascripts/openpgp.js @@ -995,7 +995,7 @@ module.exports = { show_version: true, show_comment: true, - versionstring: "OpenPGP.js v1.2.0", + versionstring: "OpenPGP.js v1.3.0", commentstring: "http://openpgpjs.org", keyserver: "keyserver.linux.it", // "pgp.mit.edu:11371" @@ -5255,7 +5255,6 @@ function ii(a, b, c, d, x, s, t) { } function md51(s) { - txt = ''; var n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i; @@ -15922,6 +15921,10 @@ S2K.prototype.write = function () { bytes += this.salt; bytes += String.fromCharCode(this.c); break; + case 'gnu': + throw new Error("GNU s2k type not supported."); + default: + throw new Error("Unknown s2k type."); } return bytes; @@ -15950,8 +15953,8 @@ S2K.prototype.produce_key = function (passphrase, numBytes) { case 'iterated': var isp = [], - count = s2k.get_count(); - data = s2k.salt + passphrase; + count = s2k.get_count(), + data = s2k.salt + passphrase; while (isp.length * data.length < count) isp.push(data); @@ -15962,6 +15965,12 @@ S2K.prototype.produce_key = function (passphrase, numBytes) { isp = isp.substr(0, count); return crypto.hash.digest(algorithm, prefix + isp); + + case 'gnu': + throw new Error("GNU s2k type not supported."); + + default: + throw new Error("Unknown s2k type."); } } @@ -16655,8 +16664,8 @@ AsyncProxy.prototype.decryptKey = function(privateKey, password) { }); self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data); - data = new key.Key(packetlist); + var packetlist = packet.List.fromStructuredClone(data), + data = new key.Key(packetlist); resolve(data); }, reject:reject }); }); @@ -16683,8 +16692,8 @@ AsyncProxy.prototype.decryptKeyPacket = function(privateKey, keyIds, password) { }); self.tasks.push({ resolve:function(data) { - var packetlist = packet.List.fromStructuredClone(data); - data = new key.Key(packetlist); + var packetlist = packet.List.fromStructuredClone(data), + data = new key.Key(packetlist); resolve(data); }, reject:reject }); }); diff --git a/nodejs/public/javascripts/openpgp.worker.js b/nodejs/public/javascripts/openpgp.worker.js new file mode 100644 index 0000000..6cd2c12 --- /dev/null +++ b/nodejs/public/javascripts/openpgp.worker.js @@ -0,0 +1,193 @@ +;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o').text(html).html(); +} + +function htmldec(data) { + return $('
').html(data).text(); +} + /// Alert user /** Alert user, e.g. that a new message has arrived. */ function beep(user) { - success("message from "+user+" received"); + if (user) success("message from "+htmlenc(user)+" received"); navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { @@ -313,9 +320,11 @@ function userid() { /// Clear Message Text And Attachments /** Does not remove the receiver's name */ function clearmessage() { + $("#message").prop(":disabled", true); filecontent = new Array(); $('#preview').empty(); $("#msg").val(""); + $("#message").prop(":disabled", false); } /// Display Image Attachments @@ -392,8 +401,11 @@ var userMap = null; function users(userlist) { console.log("rcv-> users"); userMap = new Array(); + $("#allusers").empty(); userlist.forEach(function(usr) { userMap[usr.name] = usr.pubkey; + $("#allusers").append('