From 64dc3607d3581c30d9dca9fbd336fef694376381 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 17 Feb 2020 14:18:01 +1100 Subject: [PATCH] Clean --- Pods | 2 +- Signal/Signal-Info.plist | 4 +- ...t => LokiSessionResetImplementation.swift} | 43 ++++++++----------- .../src/Messages/OWSMessageDecrypter.m | 12 +++--- 4 files changed, 27 insertions(+), 34 deletions(-) rename SignalServiceKit/src/Loki/Database/{LokiSessionReset.swift => LokiSessionResetImplementation.swift} (59%) diff --git a/Pods b/Pods index 693c9ae5f..c171262c7 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 693c9ae5f51386e0570110a98541952bdfd62963 +Subproject commit c171262c7dec75b47e89cde64b6ab2908b200c6b diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 92e102579..342d37adb 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -5,9 +5,9 @@ BuildDetails CarthageVersion - 0.33.0 + 0.34.0 OSXVersion - 10.15.1 + 10.15.3 WebRTCCommit 1445d719bf05280270e9f77576f80f973fd847f8 M73 diff --git a/SignalServiceKit/src/Loki/Database/LokiSessionReset.swift b/SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift similarity index 59% rename from SignalServiceKit/src/Loki/Database/LokiSessionReset.swift rename to SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift index 53b3e4cf1..bf6307bd1 100644 --- a/SignalServiceKit/src/Loki/Database/LokiSessionReset.swift +++ b/SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift @@ -1,8 +1,8 @@ import Foundation import SignalMetadataKit -@objc(LKSessionReset) -public class LokiSessionReset: NSObject, SessionResetProtocol { +@objc(LKSessionResetImplementation) +public class LokiSessionResetImplementation : NSObject, SessionResetProtocol { private let storage: OWSPrimaryStorage @objc public init(storage: OWSPrimaryStorage) { @@ -11,58 +11,51 @@ public class LokiSessionReset: NSObject, SessionResetProtocol { enum Errors : Error { case invalidPreKey - case preKeyIdsDontMatch + case preKeyIDsDontMatch } - public func verifyFriendRequestAcceptPreKey(for recipientId: String, whisperMessage: CipherMessage, protocolContext: Any?) throws { + public func validatePreKeyForFriendRequestAcceptance(for recipientID: String, whisperMessage: CipherMessage, protocolContext: Any?) throws { guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else { - owsFailDebug("Could not verify friend request accept prekey because invalid transaction was passed") + print("[Loki] Could not verify friend request acceptance pre key because an invalid transaction was provided.") return } - guard let preKeyMessage = whisperMessage as? PreKeyWhisperMessage else { return } - - guard let storedPreKey = storage.getPreKey(forContact: recipientId, transaction: transaction) else { - Logger.error("Received a friend request from a public key for which no prekey bundle was created.") + guard let storedPreKey = storage.getPreKey(forContact: recipientID, transaction: transaction) else { + print("[Loki] Received a friend request from a public key for which no pre key bundle was created.") throw Errors.invalidPreKey } - guard storedPreKey.id == preKeyMessage.prekeyID else { - Logger.error("Received a PreKeyWhisperMessage (friend request accept) from an unknown source.") - throw Errors.preKeyIdsDontMatch + print("[Loki] Received a `PreKeyWhisperMessage` (friend request acceptance) from an unknown source.") + throw Errors.preKeyIDsDontMatch } } - public func getSessionResetStatus(for recipientId: String, protocolContext: Any?) -> SessionResetStatus { + public func getSessionResetStatus(for recipientID: String, protocolContext: Any?) -> SessionResetStatus { guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else { - Logger.warn("Could not get session reset status for \(recipientId) because invalid transaction was passed") + print("[Loki] Could not get session reset status for \(recipientID) because an invalid transaction was provided.") return .none } - guard let thread = TSContactThread.getWithContactId(recipientId, transaction: transaction) else { return .none } + guard let thread = TSContactThread.getWithContactId(recipientID, transaction: transaction) else { return .none } return thread.sessionResetStatus } - public func onNewSessionAdopted(for recipientId: String, protocolContext: Any?) { + public func onNewSessionAdopted(for recipientID: String, protocolContext: Any?) { guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else { - Logger.warn("[Loki] Cannot handle new session adoption because invalid transaction was passed") + Logger.warn("[Loki] Cannot handle new session adoption because an invalid transaction was provided.") return } - - guard recipientId.count > 0 else { return } - guard let thread = TSContactThread.getWithContactId(recipientId, transaction: transaction) else { - Logger.debug("[Loki] A new session was adopted but the thread couldn't be found for \(recipientId)") + guard !recipientID.isEmpty else { return } + guard let thread = TSContactThread.getWithContactId(recipientID, transaction: transaction) else { + Logger.debug("[Loki] A new session was adopted but the thread couldn't be found for: \(recipientID).") return } - // If the current user initiated the reset then send back an empty message to acknowledge the completion of the session reset - if (thread.sessionResetStatus == .initiated) { + if thread.sessionResetStatus == .initiated { let emptyMessage = EphemeralMessage(in: thread) SSKEnvironment.shared.messageSender.sendPromise(message: emptyMessage).retainUntilComplete() } - // Show session reset done message TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageType: .typeLokiSessionResetDone).save(with: transaction) - // Clear the session reset status thread.sessionResetStatus = .none thread.save(with: transaction) diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index dd553da2e..24b45947a 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -83,7 +83,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes @interface OWSMessageDecrypter () @property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage; -@property (nonatomic, readonly) LKSessionReset *sessionReset; +@property (nonatomic, readonly) LKSessionResetImplementation *sessionResetImplementation; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @end @@ -101,7 +101,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes } _primaryStorage = primaryStorage; - _sessionReset = [[LKSessionReset alloc] initWithStorage:primaryStorage]; + _sessionResetImplementation = [[LKSessionResetImplementation alloc] initWithStorage:primaryStorage]; _dbConnection = primaryStorage.newDatabaseConnection; OWSSingletonAssert(); @@ -427,13 +427,13 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes @try { id cipherMessage = cipherMessageBlock(encryptedData); LKSessionCipher *cipher = [[LKSessionCipher alloc] - initWithSessionReset:self.sessionReset + initWithSessionResetImplementation:self.sessionResetImplementation sessionStore:self.primaryStorage preKeyStore:self.primaryStorage signedPreKeyStore:self.primaryStorage identityKeyStore:self.primaryStorage - recipientId:recipientId - deviceId:deviceId]; + recipientID:recipientId + deviceID:deviceId]; // plaintextData may be nil for some envelope types. NSError *error = nil; @@ -489,7 +489,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes [self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { NSError *cipherError; SMKSecretSessionCipher *_Nullable cipher = - [[SMKSecretSessionCipher alloc] initWithSessionReset:self.sessionReset + [[SMKSecretSessionCipher alloc] initWithSessionResetImplementation:self.sessionResetImplementation sessionStore:self.primaryStorage preKeyStore:self.primaryStorage signedPreKeyStore:self.primaryStorage