signal-desktop/js/views/key_verification_view.js
Scott Nonnenberg 243cbd8123 Confirmaton on send, banner when 'unverified'
Not yet using the new APIs, but ready to. Still to do:
- Send sync messages on trust decisions
- Respond to received trust decision sync messages
- Show trust decisions in the conversation history
- In that rare situation where a sent message ends up with a key error
  make it easy to retry the send.

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

91 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()
);
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,
};
}
});
})();