pull/106/head
Niels Andriesse 5 years ago
parent a5b37a631d
commit 64dc3607d3

@ -1 +1 @@
Subproject commit 693c9ae5f51386e0570110a98541952bdfd62963 Subproject commit c171262c7dec75b47e89cde64b6ab2908b200c6b

@ -5,9 +5,9 @@
<key>BuildDetails</key> <key>BuildDetails</key>
<dict> <dict>
<key>CarthageVersion</key> <key>CarthageVersion</key>
<string>0.33.0</string> <string>0.34.0</string>
<key>OSXVersion</key> <key>OSXVersion</key>
<string>10.15.1</string> <string>10.15.3</string>
<key>WebRTCCommit</key> <key>WebRTCCommit</key>
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string> <string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
</dict> </dict>

@ -1,8 +1,8 @@
import Foundation import Foundation
import SignalMetadataKit import SignalMetadataKit
@objc(LKSessionReset) @objc(LKSessionResetImplementation)
public class LokiSessionReset: NSObject, SessionResetProtocol { public class LokiSessionResetImplementation : NSObject, SessionResetProtocol {
private let storage: OWSPrimaryStorage private let storage: OWSPrimaryStorage
@objc public init(storage: OWSPrimaryStorage) { @objc public init(storage: OWSPrimaryStorage) {
@ -11,58 +11,51 @@ public class LokiSessionReset: NSObject, SessionResetProtocol {
enum Errors : Error { enum Errors : Error {
case invalidPreKey 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 { 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 return
} }
guard let preKeyMessage = whisperMessage as? PreKeyWhisperMessage else { return } guard let preKeyMessage = whisperMessage as? PreKeyWhisperMessage else { return }
guard let storedPreKey = storage.getPreKey(forContact: recipientID, transaction: transaction) else {
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.")
Logger.error("Received a friend request from a public key for which no prekey bundle was created.")
throw Errors.invalidPreKey throw Errors.invalidPreKey
} }
guard storedPreKey.id == preKeyMessage.prekeyID else { guard storedPreKey.id == preKeyMessage.prekeyID else {
Logger.error("Received a PreKeyWhisperMessage (friend request accept) from an unknown source.") print("[Loki] Received a `PreKeyWhisperMessage` (friend request acceptance) from an unknown source.")
throw Errors.preKeyIdsDontMatch 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 { 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 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 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 { 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 return
} }
guard !recipientID.isEmpty else { return }
guard recipientId.count > 0 else { return } guard let thread = TSContactThread.getWithContactId(recipientID, transaction: transaction) else {
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).")
Logger.debug("[Loki] A new session was adopted but the thread couldn't be found for \(recipientId)")
return return
} }
// If the current user initiated the reset then send back an empty message to acknowledge the completion of the session reset // 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) let emptyMessage = EphemeralMessage(in: thread)
SSKEnvironment.shared.messageSender.sendPromise(message: emptyMessage).retainUntilComplete() SSKEnvironment.shared.messageSender.sendPromise(message: emptyMessage).retainUntilComplete()
} }
// Show session reset done message // Show session reset done message
TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageType: .typeLokiSessionResetDone).save(with: transaction) TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageType: .typeLokiSessionResetDone).save(with: transaction)
// Clear the session reset status // Clear the session reset status
thread.sessionResetStatus = .none thread.sessionResetStatus = .none
thread.save(with: transaction) thread.save(with: transaction)

@ -83,7 +83,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
@interface OWSMessageDecrypter () @interface OWSMessageDecrypter ()
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage; @property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
@property (nonatomic, readonly) LKSessionReset *sessionReset; @property (nonatomic, readonly) LKSessionResetImplementation *sessionResetImplementation;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@end @end
@ -101,7 +101,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
} }
_primaryStorage = primaryStorage; _primaryStorage = primaryStorage;
_sessionReset = [[LKSessionReset alloc] initWithStorage:primaryStorage]; _sessionResetImplementation = [[LKSessionResetImplementation alloc] initWithStorage:primaryStorage];
_dbConnection = primaryStorage.newDatabaseConnection; _dbConnection = primaryStorage.newDatabaseConnection;
OWSSingletonAssert(); OWSSingletonAssert();
@ -427,13 +427,13 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
@try { @try {
id<CipherMessage> cipherMessage = cipherMessageBlock(encryptedData); id<CipherMessage> cipherMessage = cipherMessageBlock(encryptedData);
LKSessionCipher *cipher = [[LKSessionCipher alloc] LKSessionCipher *cipher = [[LKSessionCipher alloc]
initWithSessionReset:self.sessionReset initWithSessionResetImplementation:self.sessionResetImplementation
sessionStore:self.primaryStorage sessionStore:self.primaryStorage
preKeyStore:self.primaryStorage preKeyStore:self.primaryStorage
signedPreKeyStore:self.primaryStorage signedPreKeyStore:self.primaryStorage
identityKeyStore:self.primaryStorage identityKeyStore:self.primaryStorage
recipientId:recipientId recipientID:recipientId
deviceId:deviceId]; deviceID:deviceId];
// plaintextData may be nil for some envelope types. // plaintextData may be nil for some envelope types.
NSError *error = nil; NSError *error = nil;
@ -489,7 +489,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSError *cipherError; NSError *cipherError;
SMKSecretSessionCipher *_Nullable cipher = SMKSecretSessionCipher *_Nullable cipher =
[[SMKSecretSessionCipher alloc] initWithSessionReset:self.sessionReset [[SMKSecretSessionCipher alloc] initWithSessionResetImplementation:self.sessionResetImplementation
sessionStore:self.primaryStorage sessionStore:self.primaryStorage
preKeyStore:self.primaryStorage preKeyStore:self.primaryStorage
signedPreKeyStore:self.primaryStorage signedPreKeyStore:self.primaryStorage

Loading…
Cancel
Save