Delete session *before* sending EndSession message

Typically we're sending an EndSession message because our session has
diverged from the remote party's session. So if we send an EndSession
message, but decrypt it with our old out-of-sync session, how can we
expect them to be able to decrypt it?

Instead, by deleting the existing sessions, we'll fetch a new PreKey,
and start fresh with the remote side.

// FREEBIE
This commit is contained in:
Michael Kirk 2017-04-06 20:38:12 -04:00
parent 9d0c76ca56
commit d8ae941736
1 changed files with 18 additions and 12 deletions

View File

@ -25,20 +25,26 @@ class SessionResetJob: NSObject {
func run() {
Logger.info("\(TAG) Local user reset session.")
let endSessionMessage = EndSessionMessage(timestamp:NSDate.ows_millisecondTimeStamp(), in: thread)
self.messageSender.send(endSessionMessage, success: {
Logger.info("\(self.TAG) successfully sent EndSession<essage.")
Logger.info("\(self.TAG) deleting sessions for recipient: \(self.recipientId)")
OWSDispatch.sessionStoreQueue().async {
self.storageManager.deleteAllSessions(forContact: self.recipientId)
let message = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(),
in: self.thread,
messageType: TSInfoMessageType.typeSessionDidEnd)
message.save()
}, failure: {error in
Logger.error("\(self.TAG) failed to send EndSesionMessage with error: \(error.localizedDescription)")
})
DispatchQueue.main.async {
let endSessionMessage = EndSessionMessage(timestamp:NSDate.ows_millisecondTimeStamp(), in: self.thread)
self.messageSender.send(endSessionMessage, success: {
Logger.info("\(self.TAG) successfully sent EndSession<essage.")
Logger.info("\(self.TAG) deleting sessions for recipient: \(self.recipientId)")
let message = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(),
in: self.thread,
messageType: TSInfoMessageType.typeSessionDidEnd)
message.save()
}, failure: {error in
Logger.error("\(self.TAG) failed to send EndSesionMessage with error: \(error.localizedDescription)")
})
}
}
}
class func run(contactThread: TSContactThread, messageSender: MessageSender, storageManager: TSStorageManager) {