Bläddra i källkod

Fixes #848 OTR doesn't start when `cache_otr_key` is set to `true`

JC Brand 8 år sedan
förälder
incheckning
39b3aa34d8
2 ändrade filer med 15 tillägg och 12 borttagningar
  1. 1 0
      docs/CHANGES.md
  2. 14 12
      src/converse-otr.js

+ 1 - 0
docs/CHANGES.md

@@ -13,6 +13,7 @@
 - Bugfix: OTR meta-messages were being shown in HTML5 notifications. [jcbrand]
 - CSS fix: Icon lock wasn't showing. [jcbrand]
 - #842 Persistent muc room creation not working [jcbrand]
+- #848 OTR doesn't start when `cache_otr_key` is set to `true`. [jcbrand]
 - #849 `TypeError: _converse.i18n.locale_data is undefined` when reconnecting. [jcbrand]
 
 ## 3.0.1 (2017-04-04)

+ 14 - 12
src/converse-otr.js

@@ -129,17 +129,20 @@
                 getSession: function (callback) {
                     var _converse = this.__super__._converse,
                         __ = _converse.__;
-                    var instance_tag, saved_key;
+                    var instance_tag, saved_key, encrypted_key;
                     if (_converse.cache_otr_key) {
-                        instance_tag = this.get('otr_instance_tag');
-                        saved_key = otr.DSA.parsePrivate(this.get('otr_priv_key'));
-                        if (saved_key && instance_tag) {
-                            this.trigger('showHelpMessages', [__('Re-establishing encrypted session')]);
-                            callback({
-                                'key': saved_key,
-                                'instance_tag': instance_tag
-                            });
-                            return; // Our work is done here
+                        encrypted_key = this.get('otr_priv_key');
+                        if (_.isString(encrypted_key)) {
+                            instance_tag = this.get('otr_instance_tag');
+                            saved_key = otr.DSA.parsePrivate(encrypted_key)
+                            if (saved_key && instance_tag) {
+                                this.trigger('showHelpMessages', [__('Re-establishing encrypted session')]);
+                                callback({
+                                    'key': saved_key,
+                                    'instance_tag': instance_tag
+                                });
+                                return; // Our work is done here
+                            }
                         }
                     }
                     // We need to generate a new key and instance tag
@@ -151,10 +154,9 @@
                     );
                     var that = this;
                     window.setTimeout(function () {
-                        var instance_tag = otr.OTR.makeInstanceTag();
                         callback({
                             'key': that.generatePrivateKey(instance_tag),
-                            'instance_tag': instance_tag
+                            'instance_tag': otr.OTR.makeInstanceTag()
                         });
                     }, 500);
                 },