Don't clear sessions since we're checking upon each encrypt/decrypt

Based on 7d94f31a99

// FREEBIE
This commit is contained in:
Michael Kirk 2017-06-01 18:11:22 -07:00
parent 9179d4e326
commit 4a43ec5e71
3 changed files with 6 additions and 29 deletions

View File

@ -124,9 +124,7 @@ static dispatch_queue_t _sessionCipherDispatchQueue;
userInfo:@{}];
}
if ([self.identityKeyStore saveRemoteIdentity:sessionState.remoteIdentityKey recipientId:self.recipientId]) {
[sessionRecord removePreviousSessionStates];
}
[self.identityKeyStore saveRemoteIdentity:sessionState.remoteIdentityKey recipientId:self.recipientId];
NSData *ciphertextBody = [AES_CBC encryptCBCMode:paddedMessage withKey:messageKeys.cipherKey withIV:messageKeys.iv];
@ -205,11 +203,8 @@ static dispatch_queue_t _sessionCipherDispatchQueue;
userInfo:@{}];
}
if ([self.identityKeyStore saveRemoteIdentity:sessionRecord.sessionState.remoteIdentityKey
recipientId:self.recipientId]) {
[sessionRecord removePreviousSessionStates];
}
[self.identityKeyStore saveRemoteIdentity:sessionRecord.sessionState.remoteIdentityKey
recipientId:self.recipientId];
[self.sessionStore storeSession:self.recipientId deviceId:self.deviceId session:sessionRecord];
return plaintext;

View File

@ -108,16 +108,8 @@ const int kPreKeyOfLastResortId = 0xFFFFFF;
[sessionRecord.sessionState setRemoteRegistrationId:preKeyBundle.registrationId];
[sessionRecord.sessionState setAliceBaseKey:ourBaseKey.publicKey];
// Saving invalidates any existing sessions, so be sure to save *before* storing the new session.
BOOL previousIdentityExisted =
[self.identityStore saveRemoteIdentity:theirIdentityKey recipientId:self.recipientId];
if (previousIdentityExisted) {
DDLogInfo(@"%@ PKBundle removing previous session states for changed identity for recipient:%@",
self.tag,
self.recipientId);
[sessionRecord removePreviousSessionStates];
}
[self.identityStore saveRemoteIdentity:theirIdentityKey recipientId:self.recipientId];
[self.sessionStore storeSession:self.recipientId deviceId:self.deviceId session:sessionRecord];
}
@ -141,14 +133,7 @@ const int kPreKeyOfLastResortId = 0xFFFFFF;
break;
}
BOOL previousIdentityExisted =
[self.identityStore saveRemoteIdentity:theirIdentityKey recipientId:self.recipientId];
if (previousIdentityExisted) {
DDLogInfo(@"%@ PKWM removing previous session states for changed identity for recipient:%@",
self.tag,
self.recipientId);
[sessionRecord removePreviousSessionStates];
}
[self.identityStore saveRemoteIdentity:theirIdentityKey recipientId:self.recipientId];
return unSignedPrekeyId;
}

View File

@ -24,11 +24,8 @@ typedef NS_ENUM(NSInteger, TSMessageDirection) {
*
* @param identityKey key data used to identify the recipient
* @param recipientId unique stable identifier for the recipient, e.g. e164 phone number
*
* @returns YES if we are replacing an existing known identity key for recipientId.
* NO if there was no previously stored identity key for the recipient.
*/
- (BOOL)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId;
- (void)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId;
/**
* @param identityKey key data used to identify the recipient