Commit 9967b955 authored by JC Brand's avatar JC Brand

Show an alert before generating private key

To make it clear to the user that the browser might freeze up while generating
the key.
parent 36c2a2ac
...@@ -316,31 +316,39 @@ ...@@ -316,31 +316,39 @@
} }
}, },
getSession: function (callback) { getSession: function () {
var saved_key = this.get('priv_key'); var saved_key = this.get('priv_key');
var cipher = crypto.lib.PasswordBasedCipher; var cipher = crypto.lib.PasswordBasedCipher;
var pass = converse.connection.pass; var pass = converse.connection.pass;
var result, key;
if (saved_key) { if (saved_key) {
var decrypted = cipher.decrypt(crypto.algo.AES, saved_key, pass); var decrypted = cipher.decrypt(crypto.algo.AES, saved_key, pass);
var key = otr.DSA.parsePrivate(decrypted.toString(crypto.enc.Latin1)); key = otr.DSA.parsePrivate(decrypted.toString(crypto.enc.Latin1));
if (cipher.decrypt(crypto.algo.AES, this.get('pass_check'), pass).toString(crypto.enc.Latin1) === 'match') { if (cipher.decrypt(crypto.algo.AES, this.get('pass_check'), pass).toString(crypto.enc.Latin1) === 'match') {
// Verified that the user's password is still the same // Verified that the user's password is still the same
return callback(key, this.get('instance_tag')); return {
'key': key,
'instance_tag': this.get('instance_tag')
};
} }
} }
this.trigger('showHelpMessages', [__('Please wait, generating private key...')]); // We need to generate a new key
setTimeout($.proxy(function () { result = alert(__(
// Couldn't get stored key, generate a new one. 'Your browser needs to generate a private key, which will be used '+
var key = new otr.DSA(); 'in your encrypted chat session. This can take up to 30 seconds and '+
var instance_tag = otr.OTR.makeInstanceTag(); 'your browser might freeze and become unresponsive.'));
this.trigger('showHelpMessages', [__('Private key generated.')]); key = new otr.DSA();
this.save({ var instance_tag = otr.OTR.makeInstanceTag();
'priv_key': cipher.encrypt(crypto.algo.AES, key.packPrivate(), pass).toString(), this.trigger('showHelpMessages', [__('Private key generated.')]);
'pass_check': cipher.encrypt(crypto.algo.AES, 'match', pass).toString(), this.save({
'instance_tag': instance_tag 'priv_key': cipher.encrypt(crypto.algo.AES, key.packPrivate(), pass).toString(),
}); 'pass_check': cipher.encrypt(crypto.algo.AES, 'match', pass).toString(),
return callback(key, instance_tag); 'instance_tag': instance_tag
}, this)); });
return {
'key': key,
'instance_tag': instance_tag
};
}, },
updateOTRStatus: function (state) { updateOTRStatus: function (state) {
...@@ -393,33 +401,32 @@ ...@@ -393,33 +401,32 @@
// If 'query_msg' is passed in, it means there is an alread incoming // If 'query_msg' is passed in, it means there is an alread incoming
// query message from our buddy. Otherwise, it is us who will // query message from our buddy. Otherwise, it is us who will
// send the query message to them. // send the query message to them.
this.getSession($.proxy(function (key, instance_tag) { session = this.getSession();
this.otr = new otr.OTR({ this.otr = new otr.OTR({
fragment_size: 140, fragment_size: 140,
send_interval: 200, send_interval: 200,
priv: key, priv: session.key,
instance_tag: instance_tag, instance_tag: session.instance_tag,
debug: this.debug debug: this.debug
}); });
this.otr.on('status', $.proxy(this.updateOTRStatus, this)); this.otr.on('status', $.proxy(this.updateOTRStatus, this));
this.otr.on('smp', $.proxy(this.onSMP, this)); this.otr.on('smp', $.proxy(this.onSMP, this));
this.otr.on('ui', $.proxy(function (msg) {
this.trigger('showReceivedOTRMessage', msg);
}, this));
this.otr.on('io', $.proxy(function (msg) {
this.trigger('sendMessageStanza', msg);
}, this));
this.otr.on('error', $.proxy(function (msg) {
this.trigger('showOTRError', msg);
}, this));
if (query_msg) { this.otr.on('ui', $.proxy(function (msg) {
this.otr.receiveMsg(query_msg); this.trigger('showReceivedOTRMessage', msg);
} else { }, this));
this.otr.sendQueryMsg(); this.otr.on('io', $.proxy(function (msg) {
} this.trigger('sendMessageStanza', msg);
}, this)); }, this));
this.otr.on('error', $.proxy(function (msg) {
this.trigger('showOTRError', msg);
}, this));
if (query_msg) {
this.otr.receiveMsg(query_msg);
} else {
this.otr.sendQueryMsg();
}
}, },
endOTR: function () { endOTR: function () {
......
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