Merge branch 'dev' into light-mode

pull/249/head
nielsandriesse 5 years ago
commit 7e603f96f5

@ -94,6 +94,12 @@ public final class SessionMetaProtocol : NSObject {
}
// MARK: - Receiving
@objc(isErrorMessageFromBeforeRestoration:)
public static func isErrorMessageFromBeforeRestoration(_ errorMessage: TSErrorMessage) -> Bool {
let restorationTimeInMs = UInt64(storage.getRestorationTime() * 1000)
return errorMessage.timestamp < restorationTimeInMs
}
@objc(shouldSkipMessageDecryptResult:wrappedIn:)
public static func shouldSkipMessageDecryptResult(_ result: OWSMessageDecryptResult, wrappedIn envelope: SSKProtoEnvelope) -> Bool {

@ -164,15 +164,21 @@ public final class SessionManagementProtocol : NSObject {
// MARK: - Receiving
@objc(handleDecryptionError:forPublicKey:transaction:)
public static func handleDecryptionError(_ rawValue: Int32, for publicKey: String, using transaction: YapDatabaseReadWriteTransaction) {
let type = TSErrorMessageType(rawValue: rawValue)
public static func handleDecryptionError(_ errorMessage: TSErrorMessage, for publicKey: String, using transaction: YapDatabaseReadWriteTransaction) {
let type = errorMessage.errorType
let masterPublicKey = storage.getMasterHexEncodedPublicKey(for: publicKey, in: transaction) ?? publicKey
let thread = TSContactThread.getOrCreateThread(withContactId: masterPublicKey, transaction: transaction)
let restorationTimeInMs = UInt64(storage.getRestorationTime() * 1000)
// Show the session reset prompt upon certain errors
switch type {
case .noSession, .invalidMessage, .invalidKeyException:
// Store the source device's public key in case it was a secondary device
thread.addSessionRestoreDevice(publicKey, transaction: transaction)
if restorationTimeInMs > errorMessage.timestamp {
// Automatically rebuild session after restoration
sendSessionRequestIfNeeded(to: publicKey, using: transaction)
} else {
// Store the source device's public key in case it was a secondary device
thread.addSessionRestoreDevice(publicKey, transaction: transaction)
}
default: break
}
}
@ -180,7 +186,8 @@ public final class SessionManagementProtocol : NSObject {
private static func shouldProcessSessionRequest(from publicKey: String, at timestamp: UInt64) -> Bool {
let sentTimestamp = Storage.getSessionRequestSentTimestamp(for: publicKey)
let processedTimestamp = Storage.getSessionRequestProcessedTimestamp(for: publicKey)
return timestamp > sentTimestamp && timestamp > processedTimestamp
let restorationTimestamp = UInt64(storage.getRestorationTime() * 1000)
return timestamp > sentTimestamp && timestamp > processedTimestamp && timestamp > restorationTimestamp
}
@objc(handlePreKeyBundleMessageIfNeeded:wrappedIn:transaction:)

@ -5,6 +5,7 @@
#import "OWSEndSessionMessage.h"
#import "OWSPrimaryStorage+Loki.h"
#import "SignalRecipient.h"
#import <SessionCoreKit/NSDate+OWS.h>
#import <SessionServiceKit/SessionServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN

@ -526,7 +526,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
NSError *_Nullable underlyingError;
SSKProtoEnvelope *_Nullable identifiedEnvelope;
if (![decryptError.domain isEqualToString:@"SignalMetadataKit.SecretSessionKnownSenderError"]) {
if (![decryptError.domain isEqualToString:@"SessionMetadataKit.SecretSessionKnownSenderError"]) {
underlyingError = decryptError;
identifiedEnvelope = envelope;
} else {
@ -574,7 +574,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
return;
}
if ([underlyingError.domain isEqualToString:@"SignalMetadataKit.SMKSecretSessionCipherError"]
if ([underlyingError.domain isEqualToString:@"SessionMetadataKit.SMKSecretSessionCipherError"]
&& underlyingError.code == SMKSecretSessionCipherErrorSelfSentMessage) {
// Self-sent messages can be safely discarded.
failureBlock(underlyingError);
@ -690,9 +690,17 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
OWSAssertDebug(errorMessage);
if (errorMessage != nil) {
[errorMessage saveWithTransaction:transaction];
[LKSessionManagementProtocol handleDecryptionError:errorMessage.errorType forPublicKey:envelope.source transaction:transaction];
[self notifyUserForErrorMessage:errorMessage envelope:envelope transaction:transaction];
[LKSessionManagementProtocol handleDecryptionError:errorMessage forPublicKey:envelope.source transaction:transaction];
if (![LKSessionMetaProtocol isErrorMessageFromBeforeRestoration:errorMessage]) {
[errorMessage saveWithTransaction:transaction];
[self notifyUserForErrorMessage:errorMessage envelope:envelope transaction:transaction];
} else {
// Show the thread if it exists before restoration
NSString *masterPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source;
TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:masterPublicKey transaction:transaction];
contactThread.shouldThreadBeVisible = true;
[contactThread saveWithTransaction:transaction];
}
}
} error:nil];
}

@ -1450,13 +1450,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSPrimaryStorage *storage = self.primaryStorage;
SignalRecipient *recipient = messageSend.recipient;
OWSAssertDebug(recipientID.length > 0);
__block BOOL hasSession;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
hasSession = [storage containsSession:recipientID deviceId:[deviceId intValue] protocolContext:transaction];
} error:nil];
if (hasSession) { return YES; }
// Discard "typing indicator" messages if there is no existing session with the user.
BOOL canSafelyBeDiscarded = messageSend.message.isOnline;
if (canSafelyBeDiscarded) {
@ -1467,6 +1461,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
__block NSException *exception;
if (!bundle) {
__block BOOL hasSession;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
hasSession = [storage containsSession:recipientID deviceId:[deviceId intValue] protocolContext:transaction];
} error:nil];
if (hasSession) { return YES; }
TSOutgoingMessage *message = messageSend.message;
// Loki: Remove this when we have shared sender keys
// ========

Loading…
Cancel
Save