Browse Source

Remove the Signal protocol

pull/325/head
Niels Andriesse 2 years ago
parent
commit
71758b0c00
  1. 3
      Session/Meta/Signal-Bridging-Header.h
  2. 13
      Session/Signal/AppDelegate.m
  3. 4
      Session/Signal/AppEnvironment.swift
  4. 24
      Session/Signal/ConversationView/ConversationViewController.m
  5. 8
      Session/Signal/PrivacySettingsTableViewController.m
  6. 194
      Session/Signal/SessionResetJob.swift
  7. 32
      SessionMessagingKit/Configuration.swift
  8. 1
      SessionMessagingKit/Database/OWSPrimaryStorage.m
  9. 10
      SessionMessagingKit/Database/Storage+Messaging.swift
  10. 2
      SessionMessagingKit/Database/TSDatabaseView.h
  11. 28
      SessionMessagingKit/Database/TSDatabaseView.m
  12. 39
      SessionMessagingKit/Messages/Control Messages/Unused/NullMessage.swift
  13. 80
      SessionMessagingKit/Messages/Control Messages/Unused/SessionRequest.swift
  14. 17
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyErrorMessage.h
  15. 29
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyErrorMessage.m
  16. 22
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.h
  17. 141
      SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m
  18. 5
      SessionMessagingKit/Messages/Signal/TSMessage.h
  19. 2
      SessionMessagingKit/Meta/SessionMessagingKit.h
  20. 46
      SessionMessagingKit/Sending & Receiving/MessageReceiver+Decryption.swift
  21. 1
      SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift
  22. 23
      SessionMessagingKit/Sending & Receiving/MessageSender+Encryption.swift
  23. 1
      SessionMessagingKit/Storage.swift
  24. 2
      SessionMessagingKit/Threads/TSContactThread.m
  25. 8
      SessionMessagingKit/Threads/TSThread.h
  26. 22
      SessionMessagingKit/Threads/TSThread.m
  27. 71
      SessionMessagingKit/To Do/OWSUDManager.swift
  28. 5
      SessionMessagingKit/To Do/SignalRecipient.m
  29. 4
      SessionMessagingKit/Utilities/OWSIdentityManager.h
  30. 4
      SessionMessagingKit/Utilities/OWSIdentityManager.m
  31. 2
      SessionMessagingKit/Utilities/SSKEnvironment.h
  32. 3
      SessionMessagingKit/Utilities/SSKEnvironment.m
  33. 3
      SessionMessagingKit/Utilities/YapDatabaseConnection+OWS.h
  34. 15
      SessionMessagingKit/Utilities/YapDatabaseConnection+OWS.m
  35. 3
      SessionMessagingKit/Utilities/YapDatabaseTransaction+OWS.h
  36. 15
      SessionMessagingKit/Utilities/YapDatabaseTransaction+OWS.m
  37. 0
      SessionProtocolKit/ClosedGroupRatchet.swift
  38. 1
      SessionProtocolKit/ClosedGroupSenderKey.swift
  39. 10
      SessionProtocolKit/Meta/SessionProtocolKit.h
  40. 0
      SessionProtocolKit/NSData+messagePadding.h
  41. 0
      SessionProtocolKit/NSData+messagePadding.m
  42. 0
      SessionProtocolKit/SharedSenderKeys.swift
  43. 72
      SessionProtocolKit/Signal/AxolotlExceptions.h
  44. 24
      SessionProtocolKit/Signal/CipherMessage/CipherMessage.h
  45. 18
      SessionProtocolKit/Signal/CipherMessage/ClosedGroupCiphertextMessage.h
  46. 60
      SessionProtocolKit/Signal/CipherMessage/ClosedGroupCiphertextMessage.m
  47. 13
      SessionProtocolKit/Signal/CipherMessage/FallbackMessage.h
  48. 18
      SessionProtocolKit/Signal/CipherMessage/FallbackMessage.m
  49. 32
      SessionProtocolKit/Signal/CipherMessage/PreKeyWhisperMessage.h
  50. 149
      SessionProtocolKit/Signal/CipherMessage/PreKeyWhisperMessage.m
  51. 40
      SessionProtocolKit/Signal/CipherMessage/WhisperMessage.h
  52. 202
      SessionProtocolKit/Signal/CipherMessage/WhisperMessage.m
  53. 15
      SessionProtocolKit/Signal/Constants.h
  54. 41
      SessionProtocolKit/Signal/Crypto/AES-CBC.h
  55. 105
      SessionProtocolKit/Signal/Crypto/AES-CBC.m
  56. 51
      SessionProtocolKit/Signal/FallbackSessionCipher.swift
  57. 104
      SessionProtocolKit/Signal/LokiSessionCipher.swift
  58. 31
      SessionProtocolKit/Signal/Prekeys/PreKeyBundle.h
  59. 106
      SessionProtocolKit/Signal/Prekeys/PreKeyBundle.m
  60. 16
      SessionProtocolKit/Signal/Prekeys/PreKeyRecord.h
  61. 45
      SessionProtocolKit/Signal/Prekeys/PreKeyRecord.m
  62. 21
      SessionProtocolKit/Signal/Prekeys/SignedPrekeyRecord.h
  63. 78
      SessionProtocolKit/Signal/Prekeys/SignedPrekeyRecord.m
  64. 571
      SessionProtocolKit/Signal/Protos/OWSUnidentifiedDelivery.pb.swift
  65. 782
      SessionProtocolKit/Signal/Protos/SMKProto.swift
  66. 873
      SessionProtocolKit/Signal/Protos/SPKProto.swift
  67. 642
      SessionProtocolKit/Signal/Protos/WhisperTextProtocol.pb.swift
  68. 22
      SessionProtocolKit/Signal/Ratchet/AliceAxolotlParameters.h
  69. 39
      SessionProtocolKit/Signal/Ratchet/AliceAxolotlParameters.m
  70. 13
      SessionProtocolKit/Signal/Ratchet/AxolotlParameters.h
  71. 22
      SessionProtocolKit/Signal/Ratchet/BobAxolotlParameters.h
  72. 37
      SessionProtocolKit/Signal/Ratchet/BobAxolotlParameters.m
  73. 17
      SessionProtocolKit/Signal/Ratchet/Chain.h
  74. 17
      SessionProtocolKit/Signal/Ratchet/ChainAndIndex.h
  75. 13
      SessionProtocolKit/Signal/Ratchet/ChainAndIndex.m
  76. 25
      SessionProtocolKit/Signal/Ratchet/ChainKey.h
  77. 96
      SessionProtocolKit/Signal/Ratchet/ChainKey.m
  78. 20
      SessionProtocolKit/Signal/Ratchet/MessageKeys.h
  79. 62
      SessionProtocolKit/Signal/Ratchet/MessageKeys.m
  80. 19
      SessionProtocolKit/Signal/Ratchet/RKCK.h
  81. 22
      SessionProtocolKit/Signal/Ratchet/RKCK.m
  82. 41
      SessionProtocolKit/Signal/Ratchet/RatchetingSession.h
  83. 188
      SessionProtocolKit/Signal/Ratchet/RatchetingSession.m
  84. 16
      SessionProtocolKit/Signal/Ratchet/ReceivingChain.h
  85. 57
      SessionProtocolKit/Signal/Ratchet/ReceivingChain.m
  86. 18
      SessionProtocolKit/Signal/Ratchet/RootKey.h
  87. 64
      SessionProtocolKit/Signal/Ratchet/RootKey.m
  88. 16
      SessionProtocolKit/Signal/Ratchet/SendingChain.h
  89. 54
      SessionProtocolKit/Signal/Ratchet/SendingChain.m
  90. 20
      SessionProtocolKit/Signal/Ratchet/TSDerivedSecrets.h
  91. 67
      SessionProtocolKit/Signal/Ratchet/TSDerivedSecrets.m
  92. 107
      SessionProtocolKit/Signal/SMKCertificateValidator.swift
  93. 9
      SessionProtocolKit/Signal/SMKError.swift
  94. 563
      SessionProtocolKit/Signal/SMKSecretSessionCipher.swift
  95. 53
      SessionProtocolKit/Signal/SMKSenderCertificate.swift
  96. 64
      SessionProtocolKit/Signal/SMKServerCertificate.swift
  97. 51
      SessionProtocolKit/Signal/SMKUDAccessKey.swift
  98. 95
      SessionProtocolKit/Signal/SMKUnidentifiedSenderMessage.swift
  99. 71
      SessionProtocolKit/Signal/SMKUnidentifiedSenderMessageContent.swift
  100. 44
      SessionProtocolKit/Signal/SessionCipher.h
  101. Some files were not shown because too many files have changed in this diff Show More

3
Session/Meta/Signal-Bridging-Header.h

@ -38,7 +38,6 @@
#import "OWSQRCodeScanningViewController.h"
#import "SignalApp.h"
#import "UIViewController+Permissions.h"
#import <SessionProtocolKit/NSData+keyVersionByte.h>
#import <PureLayout/PureLayout.h>
#import <Reachability/Reachability.h>
#import <SignalCoreKit/Cryptography.h>
@ -74,7 +73,6 @@
#import <SessionUtilitiesKit/OWSFileSystem.h>
#import <SessionMessagingKit/OWSIdentityManager.h>
#import <SessionMessagingKit/OWSMediaGalleryFinder.h>
#import <SignalUtilitiesKit/OWSPrimaryStorage+SessionStore.h>
#import <SessionMessagingKit/OWSRecipientIdentity.h>
#import <SignalUtilitiesKit/SignalAccount.h>
#import <SessionMessagingKit/SignalRecipient.h>
@ -88,7 +86,6 @@
#import <SessionMessagingKit/TSIncomingMessage.h>
#import <SessionMessagingKit/TSInfoMessage.h>
#import <SessionMessagingKit/TSOutgoingMessage.h>
#import <SignalUtilitiesKit/TSPreKeyManager.h>
#import <SessionMessagingKit/TSThread.h>
#import <SessionUtilitiesKit/LKGroupUtilities.h>
#import <SessionUtilitiesKit/UIImage+OWS.h>

13
Session/Signal/AppDelegate.m

@ -29,7 +29,6 @@
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SessionMessagingKit/TSAccountManager.h>
#import <SessionMessagingKit/TSDatabaseView.h>
#import <SignalUtilitiesKit/TSPreKeyManager.h>
#import <YapDatabase/YapDatabaseCryptoUtils.h>
#import <sys/utsname.h>
@ -72,13 +71,6 @@ static NSTimeInterval launchStartedAt;
return [OWSReadReceiptManager sharedManager];
}
- (id<OWSUDManager>)udManager
{
OWSAssertDebug(SSKEnvironment.shared.udManager);
return SSKEnvironment.shared.udManager;
}
- (OWSPrimaryStorage *)primaryStorage
{
OWSAssertDebug(SSKEnvironment.shared.primaryStorage);
@ -377,9 +369,6 @@ static NSTimeInterval launchStartedAt;
{
OWSAssertIsOnMainThread();
// Always check prekeys after app launches, and sometimes check on app activation.
[TSPreKeyManager checkPreKeysIfNecessary];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
RTCInitializeSSL();
@ -525,8 +514,6 @@ static NSTimeInterval launchStartedAt;
[self ensureRootViewController];
[self.udManager setup];
[self preheatDatabaseViews];
[self.primaryStorage touchDbAsync];

4
Session/Signal/AppEnvironment.swift

@ -34,9 +34,6 @@ import SignalUtilitiesKit
@objc
public var pushRegistrationManager: PushRegistrationManager
@objc
public var sessionResetJobQueue: SessionResetJobQueue
@objc
public var backup: OWSBackup
@ -71,7 +68,6 @@ import SignalUtilitiesKit
self.accountManager = AccountManager()
self.notificationPresenter = NotificationPresenter()
self.pushRegistrationManager = PushRegistrationManager()
self.sessionResetJobQueue = SessionResetJobQueue()
self.backup = OWSBackup()
self.backupLazyRestore = BackupLazyRestore()
if #available(iOS 10.0, *) {

24
Session/Signal/ConversationView/ConversationViewController.m

@ -32,7 +32,6 @@
#import "TSGroupThread.h"
#import "TSIncomingMessage.h"
#import "TSInfoMessage.h"
#import <SessionMessagingKit/TSInvalidIdentityKeyErrorMessage.h>
#import "UIFont+OWS.h"
#import "UIViewController+Permissions.h"
#import <AVFoundation/AVFoundation.h>
@ -63,7 +62,6 @@
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
#import <SessionMessagingKit/TSAccountManager.h>
#import <SessionMessagingKit/TSGroupModel.h>
#import <SessionMessagingKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SessionMessagingKit/TSQuotedMessage.h>
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
#import <YapDatabase/YapDatabase.h>
@ -247,11 +245,6 @@ typedef enum : NSUInteger {
#pragma mark - Dependencies
- (OWSSessionResetJobQueue *)sessionResetJobQueue
{
return AppEnvironment.shared.sessionResetJobQueue;
}
- (OWSAudioSession *)audioSession
{
return Environment.shared.audioSession;
@ -1525,23 +1518,6 @@ typedef enum : NSUInteger {
[alert addAction:[OWSAlerts cancelAction]];
UIAlertAction *resetSessionAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON", @"")
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"reset_session")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
if (![self.thread isKindOfClass:[TSContactThread class]]) {
// Corrupt Message errors only appear in contact threads.
OWSLogError(@"Unexpected request to reset session in group thread. Refusing");
return;
}
TSContactThread *contactThread = (TSContactThread *)self.thread;
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self.sessionResetJobQueue addContactThread:contactThread transaction:transaction];
}];
}];
[alert addAction:resetSessionAction];
[self dismissKeyBoard];
[self presentAlert:alert];
}

8
Session/Signal/PrivacySettingsTableViewController.m

@ -56,11 +56,6 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
#pragma mark - Dependencies
- (id<OWSUDManager>)udManager
{
return SSKEnvironment.shared.udManager;
}
- (OWSPreferences *)preferences
{
return Environment.shared.preferences;
@ -291,8 +286,7 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s
- (void)didToggleUDUnrestrictedAccessSwitch:(UISwitch *)sender
{
OWSLogInfo(@"toggled to: %@", (sender.isOn ? @"ON" : @"OFF"));
[self.udManager setShouldAllowUnrestrictedAccessLocal:sender.isOn];
}
- (void)didToggleUDShowIndicatorsSwitch:(UISwitch *)sender

194
Session/Signal/SessionResetJob.swift

@ -1,194 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
import PromiseKit
import SignalUtilitiesKit
@objc(OWSSessionResetJobQueue)
public class SessionResetJobQueue: NSObject, SignalUtilitiesKit.JobQueue {
@objc(addContactThread:transaction:)
public func add(contactThread: TSContactThread, transaction: YapDatabaseReadWriteTransaction) {
let jobRecord = OWSSessionResetJobRecord(contactThread: contactThread, label: self.jobRecordLabel)
self.add(jobRecord: jobRecord, transaction: transaction)
}
// MARK: JobQueue
public typealias DurableOperationType = SessionResetOperation
public let jobRecordLabel: String = "SessionReset"
public static let maxRetries: UInt = 10
public let requiresInternet: Bool = true
public var runningOperations: [SessionResetOperation] = []
@objc
public override init() {
super.init()
AppReadiness.runNowOrWhenAppWillBecomeReady {
self.setup()
}
}
@objc
public func setup() {
defaultSetup()
}
public var isSetup: Bool = false
public func didMarkAsReady(oldJobRecord: JobRecordType, transaction: YapDatabaseReadWriteTransaction) {
// no special handling
}
let operationQueue: OperationQueue = {
// no need to serialize the operation queuing, since sending will ultimately be serialized by MessageSender
let operationQueue = OperationQueue()
operationQueue.name = "SessionReset.OperationQueue"
return operationQueue
}()
public func operationQueue(jobRecord: OWSSessionResetJobRecord) -> OperationQueue {
return self.operationQueue
}
public func buildOperation(jobRecord: OWSSessionResetJobRecord, transaction: YapDatabaseReadTransaction) throws -> SessionResetOperation {
guard let contactThread = TSThread.fetch(uniqueId: jobRecord.contactThreadId, transaction: transaction) as? TSContactThread else {
throw JobError.obsolete(description: "thread for session reset no longer exists")
}
return SessionResetOperation(contactThread: contactThread, jobRecord: jobRecord)
}
}
public class SessionResetOperation: OWSOperation, DurableOperation {
// MARK: DurableOperation
public let jobRecord: OWSSessionResetJobRecord
weak public var durableOperationDelegate: SessionResetJobQueue?
public var operation: OWSOperation {
return self
}
// MARK:
let contactThread: TSContactThread
var recipientId: String {
return contactThread.contactIdentifier()
}
@objc public required init(contactThread: TSContactThread, jobRecord: OWSSessionResetJobRecord) {
self.contactThread = contactThread
self.jobRecord = jobRecord
}
// MARK: Dependencies
var dbConnection: YapDatabaseConnection {
return SSKEnvironment.shared.primaryStorage.dbReadWriteConnection
}
var primaryStorage: OWSPrimaryStorage {
return SSKEnvironment.shared.primaryStorage
}
// MARK:
var firstAttempt = true
override public func run() {
assert(self.durableOperationDelegate != nil)
/*
let endSessionMessage = EndSessionMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: self.contactThread)
firstly {
return self.messageSender.sendPromise(message: endSessionMessage)
}.done {
Logger.info("successfully sent EndSessionMessage.")
Storage.writeSync { transaction in
// Archive the just-created session since the recipient should delete their corresponding
// session upon receiving and decrypting our EndSession message.
// Otherwise if we send another message before them, they wont have the session to decrypt it.
self.primaryStorage.archiveAllSessions(forContact: self.recipientId, protocolContext: transaction)
/* Loki: Original code
* ================
let message = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(),
in: self.contactThread,
messageType: TSInfoMessageType.typeSessionDidEnd)
message.save(with: transaction)
* ================
*/
if (self.contactThread.sessionResetStatus != .requestReceived) {
let message = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: self.contactThread, messageType: .typeLokiSessionResetInProgress)
message.save(with: transaction)
// Loki: We have initiated a session reset
SNLog("Session reset initiated.")
self.contactThread.sessionResetStatus = .initiated
self.contactThread.save(with: transaction)
}
}
self.reportSuccess()
}.catch { error in
Logger.error("sending error: \(error.localizedDescription)")
self.reportError(error)
}.retainUntilComplete()
*/
}
override public func didSucceed() {
Storage.writeSync { transaction in
self.durableOperationDelegate?.durableOperationDidSucceed(self, transaction: transaction)
}
}
override public func didReportError(_ error: Error) {
Logger.debug("remainingRetries: \(self.remainingRetries)")
Storage.writeSync { transaction in
self.durableOperationDelegate?.durableOperation(self, didReportError: error, transaction: transaction)
}
}
override public func retryInterval() -> TimeInterval {
// Arbitrary backoff factor...
// With backOffFactor of 1.9
// try 1 delay: 0.00s
// try 2 delay: 0.19s
// ...
// try 5 delay: 1.30s
// ...
// try 11 delay: 61.31s
let backoffFactor = 1.9
let maxBackoff = kHourInterval
let seconds = 0.1 * min(maxBackoff, pow(backoffFactor, Double(self.jobRecord.failureCount)))
return seconds
}
override public func didFail(error: Error) {
Logger.error("failed to send EndSessionMessage with error: \(error.localizedDescription)")
Storage.writeSync { transaction in
self.durableOperationDelegate?.durableOperation(self, didFailWithError: error, transaction: transaction)
// Even though this is the failure handler - which means probably the recipient didn't receive the message
// there's a chance that our send did succeed and the server just timed out our repsonse or something.
// Since the cost of sending a future message using a session the recipient doesn't have is so high,
// we archive the session just in case.
//
// Archive the just-created session since the recipient should delete their corresponding
// session upon receiving and decrypting our EndSession message.
// Otherwise if we send another message before them, they wont have the session to decrypt it.
self.primaryStorage.archiveAllSessions(forContact: self.recipientId, protocolContext: transaction)
}
}
}

32
SessionMessagingKit/Configuration.swift

@ -3,43 +3,17 @@ import SessionProtocolKit
@objc
public final class SNMessagingKitConfiguration : NSObject {
public let storage: SessionMessagingKitStorageProtocol
@objc public let signalStorage: SessionStore & PreKeyStore & SignedPreKeyStore
public let identityKeyStore: IdentityKeyStore
public let sessionRestorationImplementation: SessionRestorationProtocol
public let certificateValidator: SMKCertificateValidator
@objc public static var shared: SNMessagingKitConfiguration!
fileprivate init(
storage: SessionMessagingKitStorageProtocol,
signalStorage: SessionStore & PreKeyStore & SignedPreKeyStore,
identityKeyStore: IdentityKeyStore,
sessionRestorationImplementation: SessionRestorationProtocol,
certificateValidator: SMKCertificateValidator
) {
fileprivate init(storage: SessionMessagingKitStorageProtocol) {
self.storage = storage
self.signalStorage = signalStorage
self.identityKeyStore = identityKeyStore
self.sessionRestorationImplementation = sessionRestorationImplementation
self.certificateValidator = certificateValidator
}
}
public enum SNMessagingKit { // Just to make the external API nice
public static func configure(
storage: SessionMessagingKitStorageProtocol,
signalStorage: SessionStore & PreKeyStore & SignedPreKeyStore,
identityKeyStore: IdentityKeyStore,
sessionRestorationImplementation: SessionRestorationProtocol,
certificateValidator: SMKCertificateValidator
) {
SNMessagingKitConfiguration.shared = SNMessagingKitConfiguration(
storage: storage,
signalStorage: signalStorage,
identityKeyStore: identityKeyStore,
sessionRestorationImplementation: sessionRestorationImplementation,
certificateValidator: certificateValidator
)
public static func configure(storage: SessionMessagingKitStorageProtocol) {
SNMessagingKitConfiguration.shared = SNMessagingKitConfiguration(storage: storage)
}
}

1
SessionMessagingKit/Database/OWSPrimaryStorage.m

@ -173,7 +173,6 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
[TSDatabaseView asyncRegisterUnseenDatabaseView:self];
[TSDatabaseView asyncRegisterThreadOutgoingMessagesDatabaseView:self];
[TSDatabaseView asyncRegisterThreadSpecialMessagesDatabaseView:self];
[FullTextSearchFinder asyncRegisterDatabaseExtensionWithStorage:self];
[OWSIncomingMessageFinder asyncRegisterExtensionWithPrimaryStorage:self];

10
SessionMessagingKit/Database/Storage+Messaging.swift

@ -6,16 +6,6 @@ extension Storage {
SSKEnvironment.shared.tsAccountManager.getOrGenerateRegistrationId(transaction as! YapDatabaseReadWriteTransaction)
}
public func getSenderCertificate(for publicKey: String) -> SMKSenderCertificate {
let (promise, seal) = Promise<SMKSenderCertificate>.pending()
SSKEnvironment.shared.udManager.ensureSenderCertificate { senderCertificate in
seal.fulfill(senderCertificate)
} failure: { error in
// Should never fail
}
return try! promise.wait()
}
/// Returns the ID of the thread.
public func getOrCreateThread(for publicKey: String, groupPublicKey: String?, openGroupID: String?, using transaction: Any) -> String? {
let transaction = transaction as! YapDatabaseReadWriteTransaction

2
SessionMessagingKit/Database/TSDatabaseView.h

@ -63,8 +63,6 @@ extern NSString *const TSLazyRestoreAttachmentsDatabaseViewExtensionName;
// Instances of OWSReadTracking for wasRead is NO.
+ (void)asyncRegisterUnseenDatabaseView:(OWSStorage *)storage;
+ (void)asyncRegisterThreadSpecialMessagesDatabaseView:(OWSStorage *)storage;
+ (void)asyncRegisterLazyRestoreAttachmentsDatabaseView:(OWSStorage *)storage;
@end

28
SessionMessagingKit/Database/TSDatabaseView.m

@ -7,7 +7,6 @@
#import "TSAttachment.h"
#import "TSAttachmentPointer.h"
#import "TSIncomingMessage.h"
#import "TSInvalidIdentityKeyErrorMessage.h"
#import "TSOutgoingMessage.h"
#import "TSThread.h"
#import <YapDatabase/YapDatabaseAutoView.h>
@ -128,33 +127,6 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
storage:storage];
}
+ (void)asyncRegisterThreadSpecialMessagesDatabaseView:(OWSStorage *)storage
{
YapDatabaseViewGrouping *viewGrouping = [YapDatabaseViewGrouping withObjectBlock:^NSString *(
YapDatabaseReadTransaction *transaction, NSString *collection, NSString *key, id object) {
if (![object isKindOfClass:[TSInteraction class]]) {
return nil;
}
TSInteraction *interaction = (TSInteraction *)object;
if ([interaction isDynamicInteraction]) {
return interaction.uniqueThreadId;
} else if ([object isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]) {
return interaction.uniqueThreadId;
} else if ([object isKindOfClass:[TSErrorMessage class]]) {
TSErrorMessage *errorMessage = (TSErrorMessage *)object;
if (errorMessage.errorType == TSErrorMessageNonBlockingIdentityChange) {
return errorMessage.uniqueThreadId;
}
}
return nil;
}];
[self registerMessageDatabaseViewWithName:TSThreadSpecialMessagesDatabaseViewExtensionName
viewGrouping:viewGrouping
version:@"2"
storage:storage];
}
+ (void)asyncRegisterLegacyThreadInteractionsDatabaseView:(OWSStorage *)storage
{
YapDatabaseView *existingView = [storage registeredExtension:TSMessageDatabaseViewExtensionName_Legacy];

39
SessionMessagingKit/Messages/Control Messages/Unused/NullMessage.swift

@ -1,39 +0,0 @@
import SessionProtocolKit
import SessionUtilitiesKit
@objc(SNNullMessage)
public final class NullMessage : ControlMessage {
// MARK: Initialization
public override init() { super.init() }
// MARK: Coding
public required init?(coder: NSCoder) {
super.init(coder: coder)
}
public override func encode(with coder: NSCoder) {
super.encode(with: coder)
}
// MARK: Proto Conversion
public override class func fromProto(_ proto: SNProtoContent) -> NullMessage? {
guard proto.nullMessage != nil else { return nil }
return NullMessage()
}
public override func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? {
let nullMessageProto = SNProtoNullMessage.builder()
let paddingSize = UInt.random(in: 0..<512) // random(in:) uses the system's default random generator, which is cryptographically secure
let padding = Data.getSecureRandomData(ofSize: paddingSize)!
nullMessageProto.setPadding(padding)
let contentProto = SNProtoContent.builder()
do {
contentProto.setNullMessage(try nullMessageProto.build())
return try contentProto.build()
} catch {
SNLog("Couldn't construct null message proto from: \(self).")
return nil
}
}
}

80
SessionMessagingKit/Messages/Control Messages/Unused/SessionRequest.swift

@ -1,80 +0,0 @@
import SessionProtocolKit
import SessionUtilitiesKit
@objc(SNSessionRequest)
public final class SessionRequest : ControlMessage {
public var preKeyBundle: PreKeyBundle?
// MARK: Initialization
public override init() { super.init() }
internal init(preKeyBundle: PreKeyBundle) {
super.init()
self.preKeyBundle = preKeyBundle
}
// MARK: Validation
public override var isValid: Bool {
guard super.isValid else { return false }
return preKeyBundle != nil
}
// MARK: Coding
public required init?(coder: NSCoder) {
super.init(coder: coder)
if let preKeyBundle = coder.decodeObject(forKey: "preKeyBundle") as! PreKeyBundle? { self.preKeyBundle = preKeyBundle }
}
public override func encode(with coder: NSCoder) {
super.encode(with: coder)
coder.encode(preKeyBundle, forKey: "preKeyBundle")
}
// MARK: Proto Conversion
public override class func fromProto(_ proto: SNProtoContent) -> SessionRequest? {
guard proto.nullMessage != nil, let preKeyBundleProto = proto.prekeyBundleMessage else { return nil }
var registrationID: UInt32 = 0
SNMessagingKitConfiguration.shared.storage.writeSync { transaction in
registrationID = SNMessagingKitConfiguration.shared.storage.getOrGenerateRegistrationID(using: transaction)
}
guard let preKeyBundle = PreKeyBundle(
registrationId: Int32(registrationID),
deviceId: 1,
preKeyId: Int32(preKeyBundleProto.prekeyID),
preKeyPublic: preKeyBundleProto.prekey,
signedPreKeyPublic: preKeyBundleProto.signedKey,
signedPreKeyId: Int32(preKeyBundleProto.signedKeyID),
signedPreKeySignature: preKeyBundleProto.signature,
identityKey: preKeyBundleProto.identityKey
) else { return nil }
return SessionRequest(preKeyBundle: preKeyBundle)
}
public override func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? {
guard let preKeyBundle = preKeyBundle else {
SNLog("Couldn't construct session request proto from: \(self).")
return nil
}
let nullMessageProto = SNProtoNullMessage.builder()
let paddingSize = UInt.random(in: 0..<512) // random(in:) uses the system's default random generator, which is cryptographically secure
let padding = Data.getSecureRandomData(ofSize: paddingSize)!
nullMessageProto.setPadding(padding)
let preKeyBundleProto = SNProtoPrekeyBundleMessage.builder()
preKeyBundleProto.setIdentityKey(preKeyBundle.identityKey)
preKeyBundleProto.setDeviceID(UInt32(preKeyBundle.deviceId))
preKeyBundleProto.setPrekeyID(UInt32(preKeyBundle.preKeyId))
preKeyBundleProto.setPrekey(preKeyBundle.preKeyPublic)
preKeyBundleProto.setSignedKeyID(UInt32(preKeyBundle.signedPreKeyId))
preKeyBundleProto.setSignedKey(preKeyBundle.signedPreKeyPublic)
preKeyBundleProto.setSignature(preKeyBundle.signedPreKeySignature)
let contentProto = SNProtoContent.builder()
do {
contentProto.setNullMessage(try nullMessageProto.build())
contentProto.setPrekeyBundleMessage(try preKeyBundleProto.build())
return try contentProto.build()
} catch {
SNLog("Couldn't construct session request proto from: \(self).")
return nil
}
}
}

17
SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyErrorMessage.h

@ -1,17 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <SessionMessagingKit/TSErrorMessage.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSInvalidIdentityKeyErrorMessage : TSErrorMessage
- (void)throws_acceptNewIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions");
- (nullable NSData *)throws_newIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions");
- (NSString *)theirSignalId;
@end
NS_ASSUME_NONNULL_END

29
SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyErrorMessage.m

@ -1,29 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSInvalidIdentityKeyErrorMessage.h"
#import <SessionProtocolKit/SessionProtocolKit.h>
NS_ASSUME_NONNULL_BEGIN
@implementation TSInvalidIdentityKeyErrorMessage
- (void)throws_acceptNewIdentityKey
{
}
- (nullable NSData *)throws_newIdentityKey
{
return nil;
}
- (NSString *)theirSignalId
{
return nil;
}
@end
NS_ASSUME_NONNULL_END

22
SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.h

@ -1,22 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <SessionMessagingKit/TSInvalidIdentityKeyErrorMessage.h>
NS_ASSUME_NONNULL_BEGIN
@class SNProtoEnvelope;
// DEPRECATED - we no longer create new instances of this class (as of mid-2017); However, existing instances may
// exist, so we should keep this class around to honor their old behavior.
__attribute__((deprecated)) @interface TSInvalidIdentityKeyReceivingErrorMessage : TSInvalidIdentityKeyErrorMessage
#ifdef DEBUG
+ (nullable instancetype)untrustedKeyWithEnvelope:(SNProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
#endif
@end
NS_ASSUME_NONNULL_END

141
SessionMessagingKit/Messages/Signal/TSInvalidIdentityKeyReceivingErrorMessage.m

@ -1,141 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSInvalidIdentityKeyReceivingErrorMessage.h"
#import "OWSIdentityManager.h"
#import "OWSPrimaryStorage.h"
#import "SSKEnvironment.h"
#import "TSContactThread.h"
#import "TSDatabaseView.h"
#import "TSErrorMessage_privateConstructor.h"
#import <SessionProtocolKit/NSData+keyVersionByte.h>
#import <SessionProtocolKit/PreKeyWhisperMessage.h>
#import <YapDatabase/YapDatabaseTransaction.h>
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
__attribute__((deprecated)) @interface TSInvalidIdentityKeyReceivingErrorMessage()
@property (nonatomic, readonly, copy) NSString *authorId;
@end
@implementation TSInvalidIdentityKeyReceivingErrorMessage {
// Not using a property declaration in order to exclude from DB serialization
SNProtoEnvelope *_Nullable _envelope;
}
@synthesize envelopeData = _envelopeData;
#ifdef DEBUG
// We no longer create these messages, but they might exist on legacy clients so it's useful to be able to
// create them with the debug UI
+ (nullable instancetype)untrustedKeyWithEnvelope:(SNProtoEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
// Legit usage of senderTimestamp, references message which failed to decrypt
TSInvalidIdentityKeyReceivingErrorMessage *errorMessage =
[[self alloc] initForUnknownIdentityKeyWithTimestamp:envelope.timestamp
inThread:contactThread
incomingEnvelope:envelope];
return errorMessage;
}
- (nullable instancetype)initForUnknownIdentityKeyWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
incomingEnvelope:(SNProtoEnvelope *)envelope
{
self = [self initWithTimestamp:timestamp inThread:thread failedMessageType:TSErrorMessageWrongTrustedIdentityKey];
if (!self) {
return self;
}
NSError *error;
_envelopeData = [envelope serializedDataAndReturnError:&error];
if (!_envelopeData || error != nil) {
return nil;
}
_authorId = envelope.source;
return self;
}
#endif
- (nullable SNProtoEnvelope *)envelope
{
if (!_envelope) {
NSError *error;
SNProtoEnvelope *_Nullable envelope = [SNProtoEnvelope parseData:self.envelopeData error:&error];
if (error || envelope == nil) {
} else {
_envelope = envelope;
}
}
return _envelope;
}
- (void)throws_acceptNewIdentityKey
{
if (self.errorType != TSErrorMessageWrongTrustedIdentityKey) {
return;
}
NSData *_Nullable newKey = [self throws_newIdentityKey];
if (!newKey) {
return;
}
[[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey recipientId:self.envelope.source];
// Decrypt this and any old messages for the newly accepted key
NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *messagesToDecrypt =
[self.thread receivedMessagesForInvalidKey:newKey];
for (TSInvalidIdentityKeyReceivingErrorMessage *errorMessage in messagesToDecrypt) {
// Here we remove the existing error message because handleReceivedEnvelope will either
// 1.) succeed and create a new successful message in the thread or...
// 2.) fail and create a new identical error message in the thread.
[errorMessage remove];
}
}
- (nullable NSData *)throws_newIdentityKey
{
if (!self.envelope) {
return nil;
}
if (self.envelope.type != SNProtoEnvelopeTypePrekeyBundle) {
return nil;
}
NSData *pkwmData = self.envelope.content;
if (!pkwmData) {
return nil;
}
PreKeyWhisperMessage *message = [[PreKeyWhisperMessage alloc] init_throws_withData:pkwmData];
return [message.identityKey throws_removeKeyType];
}
- (NSString *)theirSignalId
{
if (self.authorId) {
return self.authorId;
} else {
// for existing messages before we were storing author id.
return self.envelope.source;
}
}
@end
NS_ASSUME_NONNULL_END

5
SessionMessagingKit/Messages/Signal/TSMessage.h

@ -6,6 +6,11 @@
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, TSMessageDirection) {
TSMessageDirectionIncoming,
TSMessageDirectionOutgoing
};
/**
* Abstract message class.
*/

2
SessionMessagingKit/Meta/SessionMessagingKit.h

@ -48,8 +48,6 @@ FOUNDATION_EXPORT const unsigned char SessionMessagingKitVersionString[];
#import <SessionMessagingKit/TSIncomingMessage.h>
#import <SessionMessagingKit/TSInfoMessage.h>
#import <SessionMessagingKit/TSInteraction.h>
#import <SessionMessagingKit/TSInvalidIdentityKeyErrorMessage.h>
#import <SessionMessagingKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SessionMessagingKit/TSOutgoingMessage.h>
#import <SessionMessagingKit/TSQuotedMessage.h>
#import <SessionMessagingKit/TSThread.h>

46
SessionMessagingKit/Sending & Receiving/MessageReceiver+Decryption.swift

@ -5,18 +5,6 @@ import Sodium
internal extension MessageReceiver {
static func decryptWithSignalProtocol(envelope: SNProtoEnvelope, using transaction: Any) throws -> (plaintext: Data, senderPublicKey: String) {
let storage = SNMessagingKitConfiguration.shared.signalStorage
let certificateValidator = SNMessagingKitConfiguration.shared.certificateValidator
guard let data = envelope.content else { throw Error.noData }
guard let userPublicKey = SNMessagingKitConfiguration.shared.storage.getUserPublicKey() else { throw Error.noUserX25519KeyPair }
let cipher = try SMKSecretSessionCipher(sessionResetImplementation: SNMessagingKitConfiguration.shared.sessionRestorationImplementation,
sessionStore: storage, preKeyStore: storage, signedPreKeyStore: storage, identityStore: SNMessagingKitConfiguration.shared.identityKeyStore)
let result = try cipher.throwswrapped_decryptMessage(certificateValidator: certificateValidator, cipherTextData: data,
timestamp: envelope.timestamp, localRecipientId: userPublicKey, localDeviceId: 1, protocolContext: transaction)
return (result.paddedPayload, result.senderRecipientId)
}
static func decryptWithSessionProtocol(envelope: SNProtoEnvelope) throws -> (plaintext: Data, senderX25519PublicKey: String) {
guard let ciphertext = envelope.content else { throw Error.noData }
let recipientX25519PrivateKey: Data
@ -53,38 +41,4 @@ internal extension MessageReceiver {
return (Data(plaintext), "05" + senderX25519PublicKey.toHexString())
}
static func decryptWithSharedSenderKeys(envelope: SNProtoEnvelope, using transaction: Any) throws -> (plaintext: Data, senderPublicKey: String) {
// 1. ) Check preconditions
guard let groupPublicKey = envelope.source, SNMessagingKitConfiguration.shared.storage.isClosedGroup(groupPublicKey) else {
throw Error.invalidGroupPublicKey
}
guard let data = envelope.content else {
throw Error.noData
}
guard let hexEncodedGroupPrivateKey = SNMessagingKitConfiguration.shared.storage.getClosedGroupPrivateKey(for: groupPublicKey) else {
throw Error.noGroupPrivateKey
}
let groupPrivateKey = Data(hex: hexEncodedGroupPrivateKey)
// 2. ) Parse the wrapper
let wrapper = try SNProtoClosedGroupCiphertextMessageWrapper.parseData(data)
let ivAndCiphertext = wrapper.ciphertext
let ephemeralPublicKey = wrapper.ephemeralPublicKey
// 3. ) Decrypt the data inside
guard let ephemeralSharedSecret = try? Curve25519.generateSharedSecret(fromPublicKey: ephemeralPublicKey, privateKey: groupPrivateKey) else {
throw Error.sharedSecretGenerationFailed
}
let salt = "LOKI".data(using: String.Encoding.utf8, allowLossyConversion: true)!.bytes
let symmetricKey = try HMAC(key: salt, variant: .sha256).authenticate(ephemeralSharedSecret.bytes)
let closedGroupCiphertextMessageAsData = try AESGCM.decrypt(ivAndCiphertext, with: Data(symmetricKey))
// 4. ) Parse the closed group ciphertext message
let closedGroupCiphertextMessage = ClosedGroupCiphertextMessage(_throws_with: closedGroupCiphertextMessageAsData)
let senderPublicKey = closedGroupCiphertextMessage.senderPublicKey.toHexString()
guard senderPublicKey != SNMessagingKitConfiguration.shared.storage.getUserPublicKey() else { throw Error.selfSend }
// 5. ) Use the info inside the closed group ciphertext message to decrypt the actual message content
let plaintext = try SharedSenderKeys.decrypt(closedGroupCiphertextMessage.ivAndCiphertext, for: groupPublicKey,
senderPublicKey: senderPublicKey, keyIndex: UInt(closedGroupCiphertextMessage.keyIndex), using: transaction)
// 6. ) Return
return (plaintext, senderPublicKey)
}
}

1
SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift

@ -1,4 +1,5 @@
import PromiseKit
import SessionProtocolKit
extension MessageSender : SharedSenderKeysDelegate {

23
SessionMessagingKit/Sending & Receiving/MessageSender+Encryption.swift

@ -4,15 +4,6 @@ import Sodium
internal extension MessageSender {
static func encryptWithSignalProtocol(_ plaintext: Data, associatedWith message: Message, for publicKey: String, using transaction: Any) throws -> Data {
let storage = SNMessagingKitConfiguration.shared.signalStorage
let cipher = try SMKSecretSessionCipher(sessionResetImplementation: SNMessagingKitConfiguration.shared.sessionRestorationImplementation,
sessionStore: storage, preKeyStore: storage, signedPreKeyStore: storage, identityStore: SNMessagingKitConfiguration.shared.identityKeyStore)
let certificate = SMKSenderCertificate(senderDeviceId: 1, senderRecipientId: SNMessagingKitConfiguration.shared.storage.getUserPublicKey()!)
return try cipher.throwswrapped_encryptMessage(recipientPublicKey: publicKey, deviceID: 1, paddedPlaintext: (plaintext as NSData).paddedMessageBody(),
senderCertificate: certificate, protocolContext: transaction, useFallbackSessionCipher: true)
}
static func encryptWithSessionProtocol(_ plaintext: Data, for recipientHexEncodedX25519PublicKey: String) throws -> Data {
guard let userED25519KeyPair = SNMessagingKitConfiguration.shared.storage.getUserED25519KeyPair() else { throw Error.noUserED25519KeyPair }
let recipientX25519PublicKey = Data(hex: recipientHexEncodedX25519PublicKey.removing05PrefixIfNeeded())
@ -25,18 +16,4 @@ internal extension MessageSender {
return Data(ciphertext)
}
static func encryptWithSharedSenderKeys(_ plaintext: Data, for groupPublicKey: String, using transaction: Any) throws -> Data {
// 1. ) Encrypt the data with the user's sender key
guard let userPublicKey = SNMessagingKitConfiguration.shared.storage.getUserPublicKey() else {
SNLog("Couldn't find user key pair.")
throw Error.noUserX25519KeyPair
}
let (ivAndCiphertext, keyIndex) = try SharedSenderKeys.encrypt((plaintext as NSData).paddedMessageBody(), for: groupPublicKey, senderPublicKey: userPublicKey, using: transaction)
let encryptedMessage = ClosedGroupCiphertextMessage(_throws_withIVAndCiphertext: ivAndCiphertext, senderPublicKey: Data(hex: userPublicKey), keyIndex: UInt32(keyIndex))
// 2. ) Encrypt the result for the group's public key to hide the sender public key and key index
let intermediate = try AESGCM.encrypt(encryptedMessage.serialized, for: groupPublicKey.removing05PrefixIfNeeded())
// 3. ) Wrap the result
return try SNProtoClosedGroupCiphertextMessageWrapper.builder(ciphertext: intermediate.ciphertext, ephemeralPublicKey: intermediate.ephemeralPublicKey).build().serializedData()
}
}

1
SessionMessagingKit/Storage.swift

@ -24,7 +24,6 @@ public protocol SessionMessagingKitStorageProtocol {
// MARK: - Signal Protocol
func getOrGenerateRegistrationID(using transaction: Any) -> UInt32
func getSenderCertificate(for publicKey: String) -> SMKSenderCertificate
// MARK: - Shared Sender Keys

2
SessionMessagingKit/Threads/TSContactThread.m

@ -64,7 +64,7 @@ NSString *const TSContactThreadPrefix = @"c";
- (BOOL)hasSafetyNumbers
{
return !![[OWSIdentityManager sharedManager] identityKeyForRecipientId:self.contactIdentifier];
return NO;
}
- (NSString *)name

8
SessionMessagingKit/Threads/TSThread.h

@ -60,14 +60,6 @@ BOOL IsNoteToSelfEnabled(void);
*/
- (NSUInteger)numberOfInteractions;
/**
* Get all messages in the thread we weren't able to decrypt
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *)receivedMessagesForInvalidKey:(NSData *)key;
#pragma clang diagnostic pop
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(unreadMessageCount(transaction:));

22
SessionMessagingKit/Threads/TSThread.m

@ -224,28 +224,6 @@ BOOL IsNoteToSelfEnabled(void)
return [interactions copy];
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *)receivedMessagesForInvalidKey:(NSData *)key
{
NSMutableArray *errorMessages = [NSMutableArray new];
[self enumerateInteractionsUsingBlock:^(TSInteraction *interaction) {
if ([interaction isKindOfClass:[TSInvalidIdentityKeyReceivingErrorMessage class]]) {
TSInvalidIdentityKeyReceivingErrorMessage *error = (TSInvalidIdentityKeyReceivingErrorMessage *)interaction;
@try {
if ([[error throws_newIdentityKey] isEqualToData:key]) {
[errorMessages addObject:(TSInvalidIdentityKeyReceivingErrorMessage *)interaction];
}
} @catch (NSException *exception) {
}
}
}];
return [errorMessages copy];
}
#pragma clang diagnostic pop
- (NSUInteger)numberOfInteractions
{
__block NSUInteger count;

71
SessionMessagingKit/To Do/OWSUDManager.swift

@ -1,71 +0,0 @@
@objc
public enum UnidentifiedAccessMode: Int {
case unknown
case enabled
case disabled
case unrestricted
}
@objc
public class OWSUDAccess: NSObject {
@objc
public let udAccessKey: SMKUDAccessKey
@objc
public let udAccessMode: UnidentifiedAccessMode
@objc
public let isRandomKey: Bool
@objc
public required init(udAccessKey: SMKUDAccessKey,
udAccessMode: UnidentifiedAccessMode,
isRandomKey: Bool) {
self.udAccessKey = udAccessKey
self.udAccessMode = udAccessMode
self.isRandomKey = isRandomKey
}
}
@objc public protocol OWSUDManager: class {
@objc func setup()
@objc func trustRoot() -> ECPublicKey
@objc func isUDVerboseLoggingEnabled() -> Bool
// MARK: - Recipient State
@objc
func setUnidentifiedAccessMode(_ mode: UnidentifiedAccessMode, recipientId: String)
@objc
func unidentifiedAccessMode(forRecipientId recipientId: String) -> UnidentifiedAccessMode
@objc
func udAccessKey(forRecipientId recipientId: String) -> SMKUDAccessKey?
@objc
func udAccess(forRecipientId recipientId: String,
requireSyncAccess: Bool) -> OWSUDAccess?
// MARK: Sender Certificate
// We use completion handlers instead of a promise so that message sending
// logic can access the strongly typed certificate data.
@objc
func ensureSenderCertificate(success:@escaping (SMKSenderCertificate) -> Void,
failure:@escaping (Error) -> Void)
// MARK: Unrestricted Access
@objc
func shouldAllowUnrestrictedAccessLocal() -> Bool
@objc
func setShouldAllowUnrestrictedAccessLocal(_ value: Bool)
@objc
func getSenderCertificate() -> SMKSenderCertificate?
}

5
SessionMessagingKit/To Do/SignalRecipient.m

@ -27,11 +27,6 @@ NS_ASSUME_NONNULL_BEGIN
return SSKEnvironment.shared.profileManager;
}
- (id<OWSUDManager>)udManager
{
return SSKEnvironment.shared.udManager;
}
- (TSAccountManager *)tsAccountManager
{
return SSKEnvironment.shared.tsAccountManager;

4
SessionMessagingKit/Utilities/OWSIdentityManager.h

@ -2,7 +2,7 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <SessionProtocolKit/IdentityKeyStore.h>
#import <Curve25519Kit/Curve25519.h>
#import <YapDatabase/YapDatabase.h>
@class OWSPrimaryStorage;
@ -34,7 +34,7 @@ extern const NSUInteger kStoredIdentityKeyLength;
@class YapDatabaseReadWriteTransaction;
// This class can be safely accessed and used from any thread.
@interface OWSIdentityManager : NSObject <IdentityKeyStore>
@interface OWSIdentityManager : NSObject
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;

4
SessionMessagingKit/Utilities/OWSIdentityManager.m

@ -16,10 +16,10 @@
#import "TSContactThread.h"
#import "TSErrorMessage.h"
#import "TSGroupThread.h"
#import "TSMessage.h"
#import <SessionProtocolKit/SessionProtocolKit.h>
#import "YapDatabaseConnection+OWS.h"
#import "YapDatabaseTransaction+OWS.h"
#import <SessionProtocolKit/NSData+keyVersionByte.h>
#import <Curve25519Kit/Curve25519.h>
#import <SignalCoreKit/NSDate+OWS.h>
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>