@ -104,7 +104,7 @@
return this . fetch ( { range : [ number + '.1' , number + '.' + ':' ] } ) ;
}
} ) ;
var Identity Key = Model . extend ( {
var Identity Record = Model . extend ( {
storeName : 'identityKeys' ,
validAttributes : [
'id' ,
@ -351,25 +351,25 @@
}
var number = textsecure . utils . unencodeNumber ( identifier ) [ 0 ] ;
var isOurNumber = number === textsecure . storage . user . getNumber ( ) ;
var identity Key = new IdentityKey ( { id : number } ) ;
var identity Record = new IdentityRecord ( { id : number } ) ;
return new Promise ( function ( resolve ) {
identity Key . fetch ( ) . always ( resolve ) ;
identity Record . fetch ( ) . always ( resolve ) ;
} ) . then ( function ( ) {
var existing = identity Key . get ( 'publicKey' ) ;
var existing = identity Record . get ( 'publicKey' ) ;
if ( isOurNumber ) {
return equalArrayBuffers ( existing , publicKey ) ;
}
switch ( direction ) {
case Direction . SENDING : return this . isTrustedForSending ( publicKey , identity Key ) ;
case Direction . SENDING : return this . isTrustedForSending ( publicKey , identity Record ) ;
case Direction . RECEIVING : return true ;
default : throw new Error ( "Unknown direction: " + direction ) ;
}
} . bind ( this ) ) ;
} ,
isTrustedForSending : function ( publicKey , identity Key ) {
var existing = identity Key . get ( 'publicKey' ) ;
isTrustedForSending : function ( publicKey , identity Record ) {
var existing = identity Record . get ( 'publicKey' ) ;
if ( ! existing ) {
console . log ( "isTrustedForSending: Nothing here, returning true..." ) ;
@ -379,11 +379,11 @@
console . log ( "isTrustedForSending: Identity keys don't match..." ) ;
return false ;
}
if ( identity Key . get ( 'verified' ) === VerifiedStatus . UNVERIFIED ) {
if ( identity Record . get ( 'verified' ) === VerifiedStatus . UNVERIFIED ) {
console . log ( "Needs unverified approval!" ) ;
return false ;
}
if ( this . isNonBlockingApprovalRequired ( identity Key ) ) {
if ( this . isNonBlockingApprovalRequired ( identity Record ) ) {
console . log ( "isTrustedForSending: Needs non-blocking approval!" ) ;
return false ;
}
@ -396,9 +396,9 @@
}
var number = textsecure . utils . unencodeNumber ( identifier ) [ 0 ] ;
return new Promise ( function ( resolve ) {
var identity Key = new IdentityKey ( { id : number } ) ;
identity Key . fetch ( ) . always ( function ( ) {
resolve ( identity Key . get ( 'publicKey' ) ) ;
var identity Record = new IdentityRecord ( { id : number } ) ;
identity Record . fetch ( ) . always ( function ( ) {
resolve ( identity Record . get ( 'publicKey' ) ) ;
} ) ;
} ) ;
} ,
@ -414,13 +414,13 @@
}
var number = textsecure . utils . unencodeNumber ( identifier ) [ 0 ] ;
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : number } ) ;
identity Key . fetch ( ) . always ( function ( ) {
var oldpublicKey = identity Key . get ( 'publicKey' ) ;
var identity Record = new IdentityRecord ( { id : number } ) ;
identity Record . fetch ( ) . always ( function ( ) {
var oldpublicKey = identity Record . get ( 'publicKey' ) ;
if ( ! oldpublicKey ) {
// Lookup failed, or the current key was removed, so save this one.
console . log ( "Saving new identity..." ) ;
identity Key . save ( {
identity Record . save ( {
publicKey : publicKey ,
firstUse : true ,
timestamp : Date . now ( ) ,
@ -431,7 +431,7 @@
} ) ;
} else if ( ! equalArrayBuffers ( oldpublicKey , publicKey ) ) {
console . log ( "Replacing existing identity..." ) ;
var previousStatus = identity Key . get ( 'verified' ) ;
var previousStatus = identity Record . get ( 'verified' ) ;
var verifiedStatus ;
if ( previousStatus === VerifiedStatus . VERIFIED
|| previousStatus === VerifiedStatus . UNVERIFIED ) {
@ -439,7 +439,7 @@
} else {
verifiedStatus = VerifiedStatus . DEFAULT ;
}
identity Key . save ( {
identity Record . save ( {
publicKey : publicKey ,
firstUse : false ,
timestamp : Date . now ( ) ,
@ -449,9 +449,9 @@
this . trigger ( 'keychange' , identifier ) ;
resolve ( true ) ;
} . bind ( this ) ) ;
} else if ( this . isNonBlockingApprovalRequired ( identity Key ) ) {
} else if ( this . isNonBlockingApprovalRequired ( identity Record ) ) {
console . log ( "Setting approval status..." ) ;
identity Key . save ( {
identity Record . save ( {
nonblockingApproval : nonblockingApproval ,
} ) . then ( function ( ) {
resolve ( false ) ;
@ -462,10 +462,10 @@
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} ,
isNonBlockingApprovalRequired : function ( identity Key ) {
return ( ! identity Key . get ( 'firstUse' )
&& Date . now ( ) - identity Key . get ( 'timestamp' ) < TIMESTAMP _THRESHOLD
&& ! identity Key . get ( 'nonblockingApproval' ) ) ;
isNonBlockingApprovalRequired : function ( identity Record ) {
return ( ! identity Record . get ( 'firstUse' )
&& Date . now ( ) - identity Record . get ( 'timestamp' ) < TIMESTAMP _THRESHOLD
&& ! identity Record . get ( 'nonblockingApproval' ) ) ;
} ,
saveIdentityWithAttributes : function ( identifier , attributes ) {
if ( identifier === null || identifier === undefined ) {
@ -473,12 +473,12 @@
}
var number = textsecure . utils . unencodeNumber ( identifier ) [ 0 ] ;
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : number } ) ;
identity Key . set ( attributes ) ;
if ( identity Key . isValid ( ) ) { // false if invalid attributes
identity Key . save ( ) . then ( resolve ) ;
var identity Record = new IdentityRecord ( { id : number } ) ;
identity Record . set ( attributes ) ;
if ( identity Record . isValid ( ) ) { // false if invalid attributes
identity Record . save ( ) . then ( resolve ) ;
} else {
reject ( identity Key . validationError ) ;
reject ( identity Record . validationError ) ;
}
} ) ;
} ,
@ -491,9 +491,9 @@
}
var number = textsecure . utils . unencodeNumber ( identifier ) [ 0 ] ;
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : number } ) ;
identity Key . fetch ( ) . then ( function ( ) {
identity Key . save ( {
var identity Record = new IdentityRecord ( { id : number } ) ;
identity Record . fetch ( ) . then ( function ( ) {
identity Record . save ( {
nonblockingApproval : nonblockingApproval
} ) . then ( function ( ) {
resolve ( ) ;
@ -511,9 +511,9 @@
throw new Error ( "Invalid verified status" ) ;
}
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : identifier } ) ;
identity Key . fetch ( ) . always ( function ( ) {
identity Key . save ( {
var identity Record = new IdentityRecord ( { id : identifier } ) ;
identity Record . fetch ( ) . always ( function ( ) {
identity Record . save ( {
verified : verifiedStatus
} ) . then ( function ( ) {
resolve ( ) ;
@ -528,9 +528,9 @@
throw new Error ( "Tried to set verified for undefined/null key" ) ;
}
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : identifier } ) ;
identity Key . fetch ( ) . then ( function ( ) {
var verifiedStatus = identity Key . get ( 'verified' ) ;
var identity Record = new IdentityRecord ( { id : identifier } ) ;
identity Record . fetch ( ) . then ( function ( ) {
var verifiedStatus = identity Record . get ( 'verified' ) ;
if ( validateVerifiedStatus ( verifiedStatus ) ) {
resolve ( verifiedStatus ) ;
}
@ -547,10 +547,10 @@
throw new Error ( "Tried to set verified for undefined/null key" ) ;
}
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : identifier } ) ;
identity Key . fetch ( ) . then ( function ( ) {
if ( Date . now ( ) - identity Key . get ( 'timestamp' ) < TIMESTAMP _THRESHOLD
&& ! identity Key . get ( 'nonblockingApproval' ) ) {
var identity Record = new IdentityRecord ( { id : identifier } ) ;
identity Record . fetch ( ) . then ( function ( ) {
if ( Date . now ( ) - identity Record . get ( 'timestamp' ) < TIMESTAMP _THRESHOLD
&& ! identity Record . get ( 'nonblockingApproval' ) ) {
resolve ( true ) ;
} else {
resolve ( false ) ;
@ -562,9 +562,9 @@
} ,
removeIdentityKey : function ( number ) {
return new Promise ( function ( resolve , reject ) {
var identity Key = new IdentityKey ( { id : number } ) ;
identity Key . fetch ( ) . then ( function ( ) {
identity Key . destroy ( ) ;
var identity Record = new IdentityRecord ( { id : number } ) ;
identity Record . fetch ( ) . then ( function ( ) {
identity Record . destroy ( ) ;
} ) . fail ( function ( ) {
reject ( new Error ( "Tried to remove identity for unknown number" ) ) ;
} ) ;