Files
Desktop/js/views/key_verification_view.js
Scott Nonnenberg bedf10056b Support for group-member verifications via second-level panel
Also:
- All the necessary wire-up to update things in real time. If you have
a safety number page up via a group member view as well as via a 1:1
conversation with that contact, they'll both be updated as the
underlying model changes. Similarly, the overall group will update
in real-time as members change.
- A bit of special-casing for yourself in a group conversation - you're
shown as 'me' and are not clickable, where normally that would take you
to the Safety Number screen for that contact. You are also not included
in the trust calculations for a given group.

FREEBIE
2017-08-04 12:03:25 -07:00

93 lines
3.4 KiB
JavaScript

/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
Whisper.KeyVerificationPanelView = Whisper.View.extend({
className: 'key-verification panel',
templateName: 'key-verification',
events: {
'click button.verify': 'toggleVerified',
},
initialize: function(options) {
this.our_number = textsecure.storage.user.getNumber();
if (options.newKey) {
this.their_key = options.newKey;
}
Promise.all([
this.loadTheirKey(),
this.loadOurKey(),
]).then(this.generateSecurityNumber.bind(this))
.then(function() {
this.listenTo(this.model, 'change', this.render);
}.bind(this))
.then(this.render.bind(this));
//.then(this.makeQRCode.bind(this));
},
makeQRCode: function() {
// Per Lilia: We can't turn this on until it generates a Latin1 string, as is
// required by the mobile clients.
new QRCode(this.$('.qr')[0]).makeCode(
dcodeIO.ByteBuffer.wrap(this.our_key).toString('base64')
);
},
loadTheirKey: function() {
if (this.their_key) {
return Promise.resolve(this.their_key);
} else {
return textsecure.storage.protocol.loadIdentityKey(
this.model.id
).then(function(their_key) {
this.their_key = their_key;
}.bind(this));
}
},
loadOurKey: function() {
if (this.our_key) {
return Promise.resolve(this.our_key);
} else {
return textsecure.storage.protocol.loadIdentityKey(
this.our_number
).then(function(our_key) {
this.our_key = our_key;
}.bind(this));
}
},
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));
},
toggleVerified: function() {
this.model.toggleVerified();
},
render_attributes: function() {
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()
);
console.log('this.model',this.model);
var verifyButton = this.model.isVerified() ? i18n('markAsNotVerified') : i18n('verify');
return {
learnMore : i18n('learnMore'),
their_key_unknown : i18n('theirIdentityUnknown'),
yourSafetyNumberWith : i18n('yourSafetyNumberWith', this.model.getTitle()),
verifyHelp : i18n('verifyHelp', this.model.getTitle()),
verifyButton : verifyButton,
has_their_key : this.their_key !== undefined,
chunks : chunks,
};
}
});
})();