Patch bad mac issues

This commit is contained in:
nielsandriesse 2020-08-21 09:35:41 +10:00
parent a51fcc0c04
commit 54988eeecf
3 changed files with 20 additions and 1 deletions

View file

@ -20,7 +20,7 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol {
guard let preKeyMessage = whisperMessage as? PreKeyWhisperMessage else { return }
guard let storedPreKey = storage.getPreKeyRecord(forContact: recipientID, transaction: transaction) else {
print("[Loki] Missing pre key bundle.")
return
throw Error.invalidPreKey
}
guard storedPreKey.id == preKeyMessage.prekeyID else {
print("[Loki] Received a `PreKeyWhisperMessage` from an unknown source.")

View file

@ -141,6 +141,7 @@ public final class SessionManagementProtocol : NSObject {
guard let thread = thread as? TSContactThread else {
return print("[Loki] Can't restore session for non contact thread.")
}
guard thread.sessionResetStatus == .none else { return }
// Send end session messages to the devices requiring session restoration
let devices = thread.sessionRestoreDevices // TODO: Rename this to something that reads better
for device in devices {

View file

@ -581,6 +581,24 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
return;
}
// FIXME: This is a temporary patch for bad mac issues. At least with this people will be able to message again. We have to figure out the root cause of the issue though.
if ([decryptError userInfo][NSUnderlyingErrorKey] != nil) {
NSDictionary *underlyingErrorUserInfo = [[decryptError userInfo][NSUnderlyingErrorKey] userInfo];
if (underlyingErrorUserInfo[SCKExceptionWrapperUnderlyingExceptionKey] != nil) {
NSException *underlyingUnderlyingError = underlyingErrorUserInfo[SCKExceptionWrapperUnderlyingExceptionKey];
if ([[underlyingUnderlyingError reason] hasPrefix:@"Bad Mac!"]) {
if ([underlyingError userInfo][@"kSenderRecipientIdKey"] != nil) {
NSString *senderPublicKey = [underlyingError userInfo][@"kSenderRecipientIdKey"];
TSContactThread *thread = [TSContactThread getThreadWithContactId:senderPublicKey transaction:transaction];
if (thread != nil) {
[thread addSessionRestoreDevice:senderPublicKey transaction:transaction];
[LKSessionManagementProtocol startSessionResetInThread:thread transaction:transaction];
}
}
}
}
}
failureBlock(underlyingError);
return;
}