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>
<dict>
<key>CarthageVersion</key>
<string>0.33.0</string>
<string>0.34.0</string>
<key>OSXVersion</key>
<string>10.15.1</string>
<string>10.15.3</string>
<key>WebRTCCommit</key>
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
</dict>

@ -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)

@ -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> 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

Loading…
Cancel
Save