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 || {};
|
|
|
|
|
2017-06-09 22:22:39 +00:00
|
|
|
Whisper.KeyVerificationPanelView = Whisper.View.extend({
|
2017-06-09 01:08:41 +00:00
|
|
|
className: 'key-verification panel',
|
|
|
|
templateName: 'key-verification',
|
2017-06-10 19:18:24 +00:00
|
|
|
events: {
|
|
|
|
'click button.verify': 'toggleVerified',
|
|
|
|
},
|
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;
|
|
|
|
}
|
2017-06-10 19:18:24 +00:00
|
|
|
|
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))
|
2017-06-10 19:18:24 +00:00
|
|
|
.then(function() {
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
|
}.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() {
|
2017-06-10 19:18:24 +00:00
|
|
|
// Per Lilia: We can't turn this on until it generates a Latin1 string, as is
|
2017-06-09 01:08:41 +00:00
|
|
|
// required by the mobile clients.
|
2016-09-19 09:52:50 +00:00
|
|
|
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
|
|
|
},
|
2017-06-10 19:18:24 +00:00
|
|
|
toggleVerified: function() {
|
|
|
|
this.model.toggleVerified();
|
|
|
|
},
|
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));
|
|
|
|
}
|
2017-06-16 23:05:29 +00:00
|
|
|
var name = this.model.getTitle();
|
|
|
|
var yourSafetyNumberWith = i18n('yourSafetyNumberWith', name);
|
|
|
|
var isVerified = this.model.isVerified();
|
|
|
|
var verifyButton = isVerified ? i18n('markAsNotVerified') : i18n('verify');
|
|
|
|
var verifiedStatus = isVerified ? i18n('isVerified', name) : i18n('isNotVerified', name);
|
2017-06-10 19:18:24 +00:00
|
|
|
|
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()),
|
2017-06-10 19:18:24 +00:00
|
|
|
verifyHelp : i18n('verifyHelp', this.model.getTitle()),
|
|
|
|
verifyButton : verifyButton,
|
2016-09-18 22:16:39 +00:00
|
|
|
has_their_key : this.their_key !== undefined,
|
|
|
|
chunks : chunks,
|
2017-06-16 23:05:29 +00:00
|
|
|
isVerified : isVerified,
|
|
|
|
verifiedStatus : verifiedStatus
|
2015-03-05 23:25:49 +00:00
|
|
|
};
|
2015-02-27 02:10:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|