Rename model IdentityKey -> IdentityRecord
Reduce ambiguity in between the record itself, which now stores other information besides the public key, and its `publicKey` attribute, which contains an ArrayBuffer of key material. This model is internal to SignalProtocolStore. // FREEBIE
This commit is contained in:
parent
aa6dbb2e59
commit
0e0f14723e
1 changed files with 45 additions and 45 deletions
|
@ -104,7 +104,7 @@
|
||||||
return this.fetch({range: [number + '.1', number + '.' + ':']});
|
return this.fetch({range: [number + '.1', number + '.' + ':']});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var IdentityKey = Model.extend({
|
var IdentityRecord = Model.extend({
|
||||||
storeName: 'identityKeys',
|
storeName: 'identityKeys',
|
||||||
validAttributes: [
|
validAttributes: [
|
||||||
'id',
|
'id',
|
||||||
|
@ -351,25 +351,25 @@
|
||||||
}
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
var isOurNumber = number === textsecure.storage.user.getNumber();
|
var isOurNumber = number === textsecure.storage.user.getNumber();
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityRecord = new IdentityRecord({id: number});
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
identityKey.fetch().always(resolve);
|
identityRecord.fetch().always(resolve);
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
var existing = identityKey.get('publicKey');
|
var existing = identityRecord.get('publicKey');
|
||||||
|
|
||||||
if (isOurNumber) {
|
if (isOurNumber) {
|
||||||
return equalArrayBuffers(existing, publicKey);
|
return equalArrayBuffers(existing, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
case Direction.SENDING: return this.isTrustedForSending(publicKey, identityKey);
|
case Direction.SENDING: return this.isTrustedForSending(publicKey, identityRecord);
|
||||||
case Direction.RECEIVING: return true;
|
case Direction.RECEIVING: return true;
|
||||||
default: throw new Error("Unknown direction: " + direction);
|
default: throw new Error("Unknown direction: " + direction);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
isTrustedForSending: function(publicKey, identityKey) {
|
isTrustedForSending: function(publicKey, identityRecord) {
|
||||||
var existing = identityKey.get('publicKey');
|
var existing = identityRecord.get('publicKey');
|
||||||
|
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
console.log("isTrustedForSending: Nothing here, returning true...");
|
console.log("isTrustedForSending: Nothing here, returning true...");
|
||||||
|
@ -379,11 +379,11 @@
|
||||||
console.log("isTrustedForSending: Identity keys don't match...");
|
console.log("isTrustedForSending: Identity keys don't match...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (identityKey.get('verified') === VerifiedStatus.UNVERIFIED) {
|
if (identityRecord.get('verified') === VerifiedStatus.UNVERIFIED) {
|
||||||
console.log("Needs unverified approval!");
|
console.log("Needs unverified approval!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.isNonBlockingApprovalRequired(identityKey)) {
|
if (this.isNonBlockingApprovalRequired(identityRecord)) {
|
||||||
console.log("isTrustedForSending: Needs non-blocking approval!");
|
console.log("isTrustedForSending: Needs non-blocking approval!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -396,9 +396,9 @@
|
||||||
}
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityRecord = new IdentityRecord({id: number});
|
||||||
identityKey.fetch().always(function() {
|
identityRecord.fetch().always(function() {
|
||||||
resolve(identityKey.get('publicKey'));
|
resolve(identityRecord.get('publicKey'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -414,13 +414,13 @@
|
||||||
}
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityRecord = new IdentityRecord({id: number});
|
||||||
identityKey.fetch().always(function() {
|
identityRecord.fetch().always(function() {
|
||||||
var oldpublicKey = identityKey.get('publicKey');
|
var oldpublicKey = identityRecord.get('publicKey');
|
||||||
if (!oldpublicKey) {
|
if (!oldpublicKey) {
|
||||||
// Lookup failed, or the current key was removed, so save this one.
|
// Lookup failed, or the current key was removed, so save this one.
|
||||||
console.log("Saving new identity...");
|
console.log("Saving new identity...");
|
||||||
identityKey.save({
|
identityRecord.save({
|
||||||
publicKey : publicKey,
|
publicKey : publicKey,
|
||||||
firstUse : true,
|
firstUse : true,
|
||||||
timestamp : Date.now(),
|
timestamp : Date.now(),
|
||||||
|
@ -431,7 +431,7 @@
|
||||||
});
|
});
|
||||||
} else if (!equalArrayBuffers(oldpublicKey, publicKey)) {
|
} else if (!equalArrayBuffers(oldpublicKey, publicKey)) {
|
||||||
console.log("Replacing existing identity...");
|
console.log("Replacing existing identity...");
|
||||||
var previousStatus = identityKey.get('verified');
|
var previousStatus = identityRecord.get('verified');
|
||||||
var verifiedStatus;
|
var verifiedStatus;
|
||||||
if (previousStatus === VerifiedStatus.VERIFIED
|
if (previousStatus === VerifiedStatus.VERIFIED
|
||||||
|| previousStatus === VerifiedStatus.UNVERIFIED) {
|
|| previousStatus === VerifiedStatus.UNVERIFIED) {
|
||||||
|
@ -439,7 +439,7 @@
|
||||||
} else {
|
} else {
|
||||||
verifiedStatus = VerifiedStatus.DEFAULT;
|
verifiedStatus = VerifiedStatus.DEFAULT;
|
||||||
}
|
}
|
||||||
identityKey.save({
|
identityRecord.save({
|
||||||
publicKey : publicKey,
|
publicKey : publicKey,
|
||||||
firstUse : false,
|
firstUse : false,
|
||||||
timestamp : Date.now(),
|
timestamp : Date.now(),
|
||||||
|
@ -449,9 +449,9 @@
|
||||||
this.trigger('keychange', identifier);
|
this.trigger('keychange', identifier);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else if (this.isNonBlockingApprovalRequired(identityKey)) {
|
} else if (this.isNonBlockingApprovalRequired(identityRecord)) {
|
||||||
console.log("Setting approval status...");
|
console.log("Setting approval status...");
|
||||||
identityKey.save({
|
identityRecord.save({
|
||||||
nonblockingApproval : nonblockingApproval,
|
nonblockingApproval : nonblockingApproval,
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
|
@ -462,10 +462,10 @@
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
isNonBlockingApprovalRequired: function(identityKey) {
|
isNonBlockingApprovalRequired: function(identityRecord) {
|
||||||
return (!identityKey.get('firstUse')
|
return (!identityRecord.get('firstUse')
|
||||||
&& Date.now() - identityKey.get('timestamp') < TIMESTAMP_THRESHOLD
|
&& Date.now() - identityRecord.get('timestamp') < TIMESTAMP_THRESHOLD
|
||||||
&& !identityKey.get('nonblockingApproval'));
|
&& !identityRecord.get('nonblockingApproval'));
|
||||||
},
|
},
|
||||||
saveIdentityWithAttributes: function(identifier, attributes) {
|
saveIdentityWithAttributes: function(identifier, attributes) {
|
||||||
if (identifier === null || identifier === undefined) {
|
if (identifier === null || identifier === undefined) {
|
||||||
|
@ -473,12 +473,12 @@
|
||||||
}
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityRecord = new IdentityRecord({id: number});
|
||||||
identityKey.set(attributes);
|
identityRecord.set(attributes);
|
||||||
if (identityKey.isValid()) { // false if invalid attributes
|
if (identityRecord.isValid()) { // false if invalid attributes
|
||||||
identityKey.save().then(resolve);
|
identityRecord.save().then(resolve);
|
||||||
} else {
|
} else {
|
||||||
reject(identityKey.validationError);
|
reject(identityRecord.validationError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -491,9 +491,9 @@
|
||||||
}
|
}
|
||||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityRecord = new IdentityRecord({id: number});
|
||||||
identityKey.fetch().then(function() {
|
identityRecord.fetch().then(function() {
|
||||||
identityKey.save({
|
identityRecord.save({
|
||||||
nonblockingApproval: nonblockingApproval
|
nonblockingApproval: nonblockingApproval
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -511,9 +511,9 @@
|
||||||
throw new Error("Invalid verified status");
|
throw new Error("Invalid verified status");
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: identifier});
|
var identityRecord = new IdentityRecord({id: identifier});
|
||||||
identityKey.fetch().always(function() {
|
identityRecord.fetch().always(function() {
|
||||||
identityKey.save({
|
identityRecord.save({
|
||||||
verified: verifiedStatus
|
verified: verifiedStatus
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -528,9 +528,9 @@
|
||||||
throw new Error("Tried to set verified for undefined/null key");
|
throw new Error("Tried to set verified for undefined/null key");
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: identifier});
|
var identityRecord = new IdentityRecord({id: identifier});
|
||||||
identityKey.fetch().then(function() {
|
identityRecord.fetch().then(function() {
|
||||||
var verifiedStatus = identityKey.get('verified');
|
var verifiedStatus = identityRecord.get('verified');
|
||||||
if (validateVerifiedStatus(verifiedStatus)) {
|
if (validateVerifiedStatus(verifiedStatus)) {
|
||||||
resolve(verifiedStatus);
|
resolve(verifiedStatus);
|
||||||
}
|
}
|
||||||
|
@ -547,10 +547,10 @@
|
||||||
throw new Error("Tried to set verified for undefined/null key");
|
throw new Error("Tried to set verified for undefined/null key");
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: identifier});
|
var identityRecord = new IdentityRecord({id: identifier});
|
||||||
identityKey.fetch().then(function() {
|
identityRecord.fetch().then(function() {
|
||||||
if (Date.now() - identityKey.get('timestamp') < TIMESTAMP_THRESHOLD
|
if (Date.now() - identityRecord.get('timestamp') < TIMESTAMP_THRESHOLD
|
||||||
&& !identityKey.get('nonblockingApproval')) {
|
&& !identityRecord.get('nonblockingApproval')) {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
|
@ -562,9 +562,9 @@
|
||||||
},
|
},
|
||||||
removeIdentityKey: function(number) {
|
removeIdentityKey: function(number) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var identityKey = new IdentityKey({id: number});
|
var identityRecord = new IdentityRecord({id: number});
|
||||||
identityKey.fetch().then(function() {
|
identityRecord.fetch().then(function() {
|
||||||
identityKey.destroy();
|
identityRecord.destroy();
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
reject(new Error("Tried to remove identity for unknown number"));
|
reject(new Error("Tried to remove identity for unknown number"));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue