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 || {};
|
|
|
|
|
2016-08-23 23:12:37 +00:00
|
|
|
var SecurityNumberView = Whisper.View.extend({
|
|
|
|
className: 'securityNumber',
|
|
|
|
templateName: 'security_number',
|
|
|
|
initialize: function() {
|
|
|
|
this.generateSecurityNumber();
|
|
|
|
},
|
|
|
|
generateSecurityNumber: function() {
|
|
|
|
new libsignal.FingerprintGenerator(5200).createFor(
|
|
|
|
this.model.your_number,
|
|
|
|
this.model.your_key,
|
|
|
|
this.model.their_number,
|
|
|
|
this.model.their_key
|
|
|
|
).then(this.handleSecurityNumber.bind(this));
|
|
|
|
},
|
|
|
|
handleSecurityNumber: function(securityNumber) {
|
|
|
|
this.model.securityNumber = securityNumber;
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
render_attributes: function() {
|
|
|
|
var s = this.model.securityNumber;
|
|
|
|
var chunks = [];
|
|
|
|
for (var i = 0; i < s.length; i += 5) {
|
|
|
|
chunks.push(s.substring(i, i+5));
|
|
|
|
}
|
|
|
|
return { chunks: chunks };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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-08-23 23:12:37 +00:00
|
|
|
initialize: function() {
|
2016-09-18 01:59:22 +00:00
|
|
|
Promise.all([
|
|
|
|
this.loadTheirKey(),
|
|
|
|
this.loadOurKey(),
|
|
|
|
]).then(function() {
|
|
|
|
this.render();
|
|
|
|
/*
|
|
|
|
this.$('.securityNumber').append(
|
|
|
|
new SecurityNumberView({model: this.model}).el
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
setOurKey: function(our_key) {
|
|
|
|
this.model.your_key = our_key;
|
|
|
|
},
|
|
|
|
setTheirKey: function(their_key) {
|
|
|
|
this.model.their_key = their_key;
|
|
|
|
},
|
|
|
|
loadTheirKey: function() {
|
|
|
|
if (this.model.their_key) {
|
|
|
|
return Promise.resolve(this.model.their_key);
|
|
|
|
} else {
|
|
|
|
return textsecure.storage.protocol.loadIdentityKey(
|
|
|
|
this.model.their_number
|
|
|
|
).then(this.setTheirKey.bind(this));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadOurKey: function() {
|
|
|
|
if (this.model.your_key) {
|
|
|
|
return Promise.resolve(this.model.your_key);
|
|
|
|
} else {
|
|
|
|
return textsecure.storage.protocol.loadIdentityKey(
|
|
|
|
textsecure.storage.user.getNumber()
|
|
|
|
).then(this.setOurKey.bind(this));
|
|
|
|
}
|
2016-08-23 23:12:37 +00:00
|
|
|
},
|
2015-02-27 02:10:04 +00:00
|
|
|
splitKey: function(key) {
|
2015-07-16 18:06:05 +00:00
|
|
|
// key is an array buffer
|
|
|
|
var bytes = new Uint8Array(key);
|
|
|
|
var octets = [];
|
|
|
|
for (var i = 0; i < bytes.byteLength; ++i) {
|
|
|
|
octets.push(('0' + bytes[i].toString(16)).slice(-2));
|
|
|
|
}
|
2015-02-27 02:10:04 +00:00
|
|
|
|
2015-07-16 18:06:05 +00:00
|
|
|
return octets;
|
2015-02-27 02:10:04 +00:00
|
|
|
},
|
2015-03-07 01:05:36 +00:00
|
|
|
render_attributes: function() {
|
2016-01-20 03:01:47 +00:00
|
|
|
return {
|
2016-03-24 19:33:41 +00:00
|
|
|
learnMore : i18n('learnMore'),
|
2015-12-26 01:16:36 +00:00
|
|
|
verifyIdentity: i18n('verifyIdentity'),
|
2016-01-17 21:41:45 +00:00
|
|
|
yourIdentity: i18n('yourIdentity'),
|
|
|
|
theirIdentity: i18n('theirIdentity'),
|
2016-01-20 03:01:47 +00:00
|
|
|
their_key_unknown: i18n('theirIdentityUnknown'),
|
2015-02-27 02:10:04 +00:00
|
|
|
your_key: this.splitKey(this.model.your_key),
|
2016-03-22 01:18:10 +00:00
|
|
|
their_key: this.splitKey(this.model.their_key),
|
|
|
|
has_their_key: this.model.their_key !== undefined
|
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
|
|
|
})();
|