Commit a2aeec84 authored by JC Brand's avatar JC Brand

Add initial OTR code.

- /otr will generate a new private key (or fetch it from storage).
parent 57fc8b98
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
"dependencies": { "dependencies": {
"requirejs": "2.1.8", "requirejs": "2.1.8",
"jquery": "1.8.3", "jquery": "1.8.3",
"sjcl": "git://github.com/bitwiseshiftleft/sjcl.git",
"jed": "0.5.4", "jed": "0.5.4",
"tinysort": "git://github.com/Sjeiti/TinySort.git", "tinysort": "git://github.com/Sjeiti/TinySort.git",
"underscore": "1.5.1", "underscore": "1.5.1",
...@@ -18,7 +17,8 @@ ...@@ -18,7 +17,8 @@
"strophe.vcard": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/vcard/strophe.vcard.js", "strophe.vcard": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/vcard/strophe.vcard.js",
"strophe.disco": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/disco/strophe.disco.js", "strophe.disco": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/disco/strophe.disco.js",
"strophe.muc": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/muc/strophe.muc.js", "strophe.muc": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/muc/strophe.muc.js",
"otr": "~0.2.1" "otr": "~0.2.1",
"crypto-js": "~3.1.2"
}, },
"exportsOverride": {} "exportsOverride": {}
} }
...@@ -14,22 +14,22 @@ ...@@ -14,22 +14,22 @@
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define("converse", [ define("converse", [
"components/otr/build/otr", "components/otr/build/otr",
"crypto.aes",
"locales", "locales",
"localstorage", "localstorage",
"tinysort", "tinysort",
"sjcl",
"strophe", "strophe",
"strophe.muc", "strophe.muc",
"strophe.roster", "strophe.roster",
"strophe.vcard", "strophe.vcard",
"strophe.disco" "strophe.disco"
], function(otr) { ], function(otr, crypto) {
// Use Mustache style syntax for variable interpolation // Use Mustache style syntax for variable interpolation
_.templateSettings = { _.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g, evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g interpolate : /\{\{([\s\S]+?)\}\}/g
}; };
return factory(jQuery, _, otr, console); return factory(jQuery, _, crypto, otr, console);
} }
); );
} else { } else {
...@@ -38,9 +38,9 @@ ...@@ -38,9 +38,9 @@
evaluate : /\{\[([\s\S]+?)\]\}/g, evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g interpolate : /\{\{([\s\S]+?)\}\}/g
}; };
root.converse = factory(jQuery, _, otr, console || {log: function(){}}); root.converse = factory(jQuery, _, crypto, otr, console || {log: function(){}});
} }
}(this, function ($, _, otr, console) { }(this, function ($, _, crypto, otr, console) {
var converse = {}; var converse = {};
converse.initialize = function (settings) { converse.initialize = function (settings) {
// Default values // Default values
...@@ -206,6 +206,40 @@ ...@@ -206,6 +206,40 @@
} }
}, },
getPrivateKey: function () {
var savedKey = this.get('priv_key');
var myKey, decrypted, ciphertextParams;
if (savedKey) {
decrypted = crypto.lib.PasswordBasedCipher.decrypt(crypto.algo.AES, savedKey, converse.connection.pass);
myKey = otr.DSA.parsePrivate(decrypted.toString(crypto.enc.Latin1));
} else {
myKey = new otr.DSA();
ciphertextParams = crypto.lib.PasswordBasedCipher.encrypt(crypto.algo.AES, myKey.packPrivate(), converse.connection.pass);
this.save({'priv_key': ciphertextParams.toString()});
}
return myKey;
},
initiateOTR: function (myKey) {
var options = {
fragment_size: 140,
send_interval: 200,
priv: myKey,
debug: true
};
var contact = new otr.OTR(options);
contact.on('ui', function (msg) {
console.log("message to display to the user:"+msg);
});
contact.on('io', function (msg) {
console.log("message to display to the user:"+msg);
});
contact.on('error', function (msg) {
console.log("message to display to the user:"+msg);
});
},
messageReceived: function (message) { messageReceived: function (message) {
var $message = $(message), var $message = $(message),
body = converse.autoLink($message.children('body').text()), body = converse.autoLink($message.children('body').text()),
...@@ -382,6 +416,21 @@ ...@@ -382,6 +416,21 @@
this.addHelpMessages(msgs); this.addHelpMessages(msgs);
return; return;
} }
else if (match[1] === "otr") {
msgs = [
__('Initializing OTR.'),
__('Generating private key'),
__('...this might take a few seconds.')
];
this.addHelpMessages(msgs);
var privKey = this.model.getPrivateKey();
msgs = [
__('Private key generated.')
];
this.addHelpMessages(msgs);
this.model.initiateOTR(privKey);
return;
}
} }
var message = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: timestamp}) var message = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: timestamp})
.c('body').t(text).up() .c('body').t(text).up()
......
...@@ -11,7 +11,8 @@ require.config({ ...@@ -11,7 +11,8 @@ require.config({
"strophe.muc": "components/strophe.muc/index", "strophe.muc": "components/strophe.muc/index",
"strophe.roster": "components/strophe.roster/index", "strophe.roster": "components/strophe.roster/index",
"strophe.vcard": "components/strophe.vcard/index", "strophe.vcard": "components/strophe.vcard/index",
"strophe.disco": "components/strophe.disco/index" "strophe.disco": "components/strophe.disco/index",
"crypto.aes": "components/crypto-js/build/rollups/aes"
}, },
// define module dependencies for modules not using define // define module dependencies for modules not using define
...@@ -27,6 +28,9 @@ require.config({ ...@@ -27,6 +28,9 @@ require.config({
//module value. //module value.
exports: 'Backbone' exports: 'Backbone'
}, },
'crypto.aes': {
exports: 'CryptoJS'
},
'tinysort': { deps: ['jquery'] }, 'tinysort': { deps: ['jquery'] },
'strophe': { deps: ['jquery'] }, 'strophe': { deps: ['jquery'] },
'underscore': { exports: '_' }, 'underscore': { exports: '_' },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment