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) {
|
2017-07-11 22:54:46 +00:00
|
|
|
this.ourNumber = textsecure.storage.user.getNumber();
|
2016-09-18 22:16:39 +00:00
|
|
|
if (options.newKey) {
|
2017-07-11 22:54:46 +00:00
|
|
|
this.theirKey = options.newKey;
|
2016-09-18 22:16:39 +00:00
|
|
|
}
|
2017-06-10 19:18:24 +00:00
|
|
|
|
2017-07-11 22:54:46 +00:00
|
|
|
this.loadKeys().then(function() {
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
loadKeys: function() {
|
|
|
|
return Promise.all([
|
2016-09-18 01:59:22 +00:00
|
|
|
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() {
|
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(
|
2017-07-11 22:54:46 +00:00
|
|
|
dcodeIO.ByteBuffer.wrap(this.ourKey).toString('base64')
|
2016-09-19 09:52:50 +00:00
|
|
|
);
|
2016-09-18 01:59:22 +00:00
|
|
|
},
|
|
|
|
loadTheirKey: function() {
|
2017-07-11 22:54:46 +00:00
|
|
|
return textsecure.storage.protocol.loadIdentityKey(
|
|
|
|
this.model.id
|
|
|
|
).then(function(theirKey) {
|
|
|
|
this.theirKey = theirKey;
|
|
|
|
}.bind(this));
|
2016-09-18 01:59:22 +00:00
|
|
|
},
|
|
|
|
loadOurKey: function() {
|
2017-07-11 22:54:46 +00:00
|
|
|
return textsecure.storage.protocol.loadIdentityKey(
|
|
|
|
this.ourNumber
|
|
|
|
).then(function(ourKey) {
|
|
|
|
this.ourKey = ourKey;
|
|
|
|
}.bind(this));
|
2016-08-23 23:12:37 +00:00
|
|
|
},
|
2016-09-18 22:16:39 +00:00
|
|
|
generateSecurityNumber: function() {
|
|
|
|
return new libsignal.FingerprintGenerator(5200).createFor(
|
2017-07-11 22:54:46 +00:00
|
|
|
this.ourNumber, this.ourKey, this.model.id, this.theirKey
|
2016-09-18 22:16:39 +00:00
|
|
|
).then(function(securityNumber) {
|
|
|
|
this.securityNumber = securityNumber;
|
|
|
|
}.bind(this));
|
2015-02-27 02:10:04 +00:00
|
|
|
},
|
2017-07-11 22:54:46 +00:00
|
|
|
onSafetyNumberChanged: function() {
|
|
|
|
this.model.getProfiles().then(this.loadKeys.bind(this));
|
|
|
|
|
|
|
|
var dialog = new Whisper.ConfirmationDialogView({
|
2017-09-29 16:09:40 +00:00
|
|
|
message: i18n('changedRightAfterVerify', [this.model.getTitle(), this.model.getTitle()]),
|
2017-08-07 22:14:42 +00:00
|
|
|
hideCancel: true
|
2017-07-11 22:54:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
dialog.$el.insertBefore(this.el);
|
|
|
|
dialog.focusCancel();
|
|
|
|
},
|
2017-06-10 19:18:24 +00:00
|
|
|
toggleVerified: function() {
|
2017-07-11 22:54:46 +00:00
|
|
|
this.$('button.verify').attr('disabled', true);
|
|
|
|
this.model.toggleVerified().catch(function(result) {
|
|
|
|
if (result instanceof Error) {
|
|
|
|
if (result.name === 'OutgoingIdentityKeyError') {
|
|
|
|
this.onSafetyNumberChanged();
|
2017-07-12 22:51:04 +00:00
|
|
|
} else {
|
|
|
|
console.log('failed to toggle verified:', result.stack);
|
2017-07-11 22:54:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var keyError = _.some(result.errors, function(error) {
|
|
|
|
return error.name === 'OutgoingIdentityKeyError';
|
|
|
|
});
|
|
|
|
if (keyError) {
|
|
|
|
this.onSafetyNumberChanged();
|
2017-07-12 22:51:04 +00:00
|
|
|
} else {
|
|
|
|
_.forEach(result.errors, function(error) {
|
|
|
|
console.log('failed to toggle verified:', error.stack);
|
|
|
|
});
|
2017-07-11 22:54:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this)).then(function() {
|
|
|
|
this.$('button.verify').removeAttr('disabled');
|
|
|
|
}.bind(this));
|
2017-06-10 19:18:24 +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));
|
|
|
|
}
|
2017-06-16 23:05:29 +00:00
|
|
|
var name = this.model.getTitle();
|
|
|
|
var yourSafetyNumberWith = i18n('yourSafetyNumberWith', name);
|
|
|
|
var isVerified = this.model.isVerified();
|
2017-06-30 00:32:40 +00:00
|
|
|
var verifyButton = isVerified ? i18n('unverify') : i18n('verify');
|
2017-06-16 23:05:29 +00:00
|
|
|
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'),
|
2017-07-11 22:54:46 +00:00
|
|
|
theirKeyUnknown : i18n('theirIdentityUnknown'),
|
2016-09-18 22:16:39 +00:00
|
|
|
yourSafetyNumberWith : i18n('yourSafetyNumberWith', this.model.getTitle()),
|
2017-06-10 19:18:24 +00:00
|
|
|
verifyHelp : i18n('verifyHelp', this.model.getTitle()),
|
|
|
|
verifyButton : verifyButton,
|
2017-07-11 22:54:46 +00:00
|
|
|
hasTheirKey : this.theirKey !== undefined,
|
2016-09-18 22:16:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|