2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-02-27 02:10:04 +00:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-03-05 23:25:49 +00:00
|
|
|
Whisper.KeyVerificationView = Whisper.View.extend({
|
2016-03-23 19:33:50 +00:00
|
|
|
className: 'key-verification',
|
|
|
|
templateName: 'key_verification',
|
2016-09-18 22:16:39 +00:00
|
|
|
initialize: function(options) {
|
|
|
|
this.our_number = textsecure.storage.user.getNumber();
|
|
|
|
if (options.newKey) {
|
|
|
|
this.their_key = options.newKey;
|
|
|
|
}
|
2016-09-18 01:59:22 +00:00
|
|
|
Promise.all([
|
|
|
|
this.loadTheirKey(),
|
|
|
|
this.loadOurKey(),
|
2016-09-18 22:16:39 +00:00
|
|
|
]).then(this.generateSecurityNumber.bind(this))
|
2016-10-21 17:22:17 +00:00
|
|
|
.then(this.render.bind(this));
|
|
|
|
//.then(this.makeQRCode.bind(this));
|
2016-09-19 09:52:50 +00:00
|
|
|
},
|
|
|
|
makeQRCode: function() {
|
|
|
|
new QRCode(this.$('.qr')[0]).makeCode(
|
|
|
|
dcodeIO.ByteBuffer.wrap(this.our_key).toString('base64')
|
|
|
|
);
|
2016-09-18 01:59:22 +00:00
|
|
|
},
|
|
|
|
loadTheirKey: function() {
|
2016-09-18 22:16:39 +00:00
|
|
|
if (this.their_key) {
|
|
|
|
return Promise.resolve(this.their_key);
|
2016-09-18 01:59:22 +00:00
|
|
|
} else {
|
|
|
|
return textsecure.storage.protocol.loadIdentityKey(
|
2016-09-18 22:16:39 +00:00
|
|
|
this.model.id
|
|
|
|
).then(function(their_key) {
|
|
|
|
this.their_key = their_key;
|
|
|
|
}.bind(this));
|
2016-09-18 01:59:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
loadOurKey: function() {
|
2016-09-18 22:16:39 +00:00
|
|
|
if (this.our_key) {
|
|
|
|
return Promise.resolve(this.our_key);
|
2016-09-18 01:59:22 +00:00
|
|
|
} else {
|
|
|
|
return textsecure.storage.protocol.loadIdentityKey(
|
2016-09-18 22:16:39 +00:00
|
|
|
this.our_number
|
|
|
|
).then(function(our_key) {
|
|
|
|
this.our_key = our_key;
|
|
|
|
}.bind(this));
|
2016-09-18 01:59:22 +00:00
|
|
|
}
|
2016-08-23 23:12:37 +00:00
|
|
|
},
|
2016-09-18 22:16:39 +00:00
|
|
|
generateSecurityNumber: function() {
|
|
|
|
return new libsignal.FingerprintGenerator(5200).createFor(
|
|
|
|
this.our_number, this.our_key, this.model.id, this.their_key
|
|
|
|
).then(function(securityNumber) {
|
|
|
|
this.securityNumber = securityNumber;
|
|
|
|
}.bind(this));
|
2015-02-27 02:10:04 +00:00
|
|
|
},
|
2015-03-07 01:05:36 +00:00
|
|
|
render_attributes: function() {
|
2016-09-18 22:16:39 +00:00
|
|
|
var s = this.securityNumber;
|
|
|
|
var chunks = [];
|
|
|
|
for (var i = 0; i < s.length; i += 5) {
|
|
|
|
chunks.push(s.substring(i, i+5));
|
|
|
|
}
|
|
|
|
var yourSafetyNumberWith = i18n(
|
|
|
|
'yourSafetyNumberWith', this.model.getTitle()
|
|
|
|
);
|
2016-01-20 03:01:47 +00:00
|
|
|
return {
|
2016-09-18 22:16:39 +00:00
|
|
|
learnMore : i18n('learnMore'),
|
|
|
|
their_key_unknown : i18n('theirIdentityUnknown'),
|
|
|
|
yourSafetyNumberWith : i18n('yourSafetyNumberWith', this.model.getTitle()),
|
|
|
|
has_their_key : this.their_key !== undefined,
|
|
|
|
chunks : chunks,
|
2015-03-05 23:25:49 +00:00
|
|
|
};
|
2015-02-27 02:10:04 +00:00
|
|
|
}
|
|
|
|
});
|
2016-03-23 19:33:50 +00:00
|
|
|
Whisper.KeyVerificationPanelView = Whisper.KeyVerificationView.extend({
|
|
|
|
className: 'key-verification panel',
|
|
|
|
templateName: 'key_verification_panel',
|
|
|
|
});
|
2015-02-27 02:10:04 +00:00
|
|
|
})();
|