This commit is contained in:
nielsandriesse 2020-11-05 19:23:05 +11:00
parent 10582e0381
commit 74b104af45
10 changed files with 14 additions and 37 deletions

View File

@ -1,6 +1,6 @@
import SessionUtilities
public final class ClosedGroupRatchet : NSObject, NSCoding {
public final class ClosedGroupRatchet : NSObject, NSCoding { // Not a struct for YapDatabase compatibility
public let chainKey: String
public let keyIndex: UInt
public let messageKeys: [String]
@ -41,5 +41,5 @@ public final class ClosedGroupRatchet : NSObject, NSCoding {
}
// MARK: Description
override public var description: String { return "[ chainKey : \(chainKey), keyIndex : \(keyIndex), messageKeys : \(messageKeys.prettifiedDescription) ]" }
override public var description: String { "[ chainKey : \(chainKey), keyIndex : \(keyIndex), messageKeys : \(messageKeys.prettifiedDescription) ]" }
}

View File

@ -1,5 +1,5 @@
public final class ClosedGroupSenderKey : NSObject, NSCoding {
public final class ClosedGroupSenderKey : NSObject, NSCoding { // Not a struct for YapDatabase compatibility
public let chainKey: Data
public let keyIndex: UInt
public let publicKey: Data

View File

@ -2,6 +2,11 @@ import CryptoSwift
import PromiseKit
import SessionUtilities
public protocol SharedSenderKeysDelegate {
func requestSenderKey(for groupPublicKey: String, senderPublicKey: String, using transaction: Any)
}
public enum SharedSenderKeys {
private static let gcmTagSize: UInt = 16
private static let ivSize: UInt = 12
@ -100,8 +105,6 @@ public enum SharedSenderKeys {
do {
ratchet = try stepRatchetOnce(for: groupPublicKey, senderPublicKey: senderPublicKey, using: transaction)
} catch {
// FIXME: It'd be cleaner to handle this in OWSMessageDecrypter (where all the other decryption errors are handled), but this was a lot more
// convenient because there's an easy way to get the sender public key from here.
if case RatchetingError.loadingFailed(_, _) = error {
Configuration.shared.sharedSenderKeysDelegate.requestSenderKey(for: groupPublicKey, senderPublicKey: senderPublicKey, using: transaction)
}
@ -123,8 +126,6 @@ public enum SharedSenderKeys {
if !isRetry {
return try decrypt(ivAndCiphertext, for: groupPublicKey, senderPublicKey: senderPublicKey, keyIndex: keyIndex, using: transaction, isRetry: true)
} else {
// FIXME: It'd be cleaner to handle this in OWSMessageDecrypter (where all the other decryption errors are handled), but this was a lot more
// convenient because there's an easy way to get the sender public key from here.
if case RatchetingError.loadingFailed(_, _) = error {
Configuration.shared.sharedSenderKeysDelegate.requestSenderKey(for: groupPublicKey, senderPublicKey: senderPublicKey, using: transaction)
}
@ -160,13 +161,4 @@ public enum SharedSenderKeys {
throw error ?? RatchetingError.generic
}
}
public func isClosedGroup(_ publicKey: String) -> Bool {
return Configuration.shared.storage.getUserClosedGroupPublicKeys().contains(publicKey)
}
public func getKeyPair(forGroupWithPublicKey groupPublicKey: String) -> ECKeyPair {
let privateKey = Configuration.shared.storage.getClosedGroupPrivateKey(for: groupPublicKey)!
return ECKeyPair(publicKey: Data(hex: groupPublicKey.removing05PrefixIfNeeded()), privateKey: Data(hex: privateKey))
}
}

View File

@ -1,5 +0,0 @@
public protocol SharedSenderKeysDelegate {
func requestSenderKey(for groupPublicKey: String, senderPublicKey: String, using transaction: Any)
}

View File

@ -9,9 +9,4 @@ public protocol SessionProtocolKitStorageProtocol {
func getClosedGroupRatchet(for groupPublicKey: String, senderPublicKey: String, from collection: ClosedGroupRatchetCollectionType) -> ClosedGroupRatchet?
func setClosedGroupRatchet(for groupPublicKey: String, senderPublicKey: String, ratchet: ClosedGroupRatchet, in collection: ClosedGroupRatchetCollectionType, using transaction: Any)
func getAllClosedGroupRatchets(for groupPublicKey: String, from collection: ClosedGroupRatchetCollectionType) -> [(senderPublicKey: String, ratchet: ClosedGroupRatchet)]
func getAllClosedGroupSenderKeys(for groupPublicKey: String, from collection: ClosedGroupRatchetCollectionType) -> Set<ClosedGroupSenderKey>
func removeAllClosedGroupRatchets(for groupPublicKey: String, from collection: ClosedGroupRatchetCollectionType, using transaction: Any)
func getUserClosedGroupPublicKeys() -> Set<String>
func getClosedGroupPrivateKey(for publicKey: String) -> String?
}

View File

@ -6,7 +6,6 @@ public enum OnionRequestAPI {
private static var pathFailureCount: [Path:UInt] = [:]
private static var snodeFailureCount: [Snode:UInt] = [:]
public static var guardSnodes: Set<Snode> = []
// TODO: Just get/set paths from/in the database directly?
public static var paths: [Path] = [] // Not a set to ensure we consistently show the same path to the user
// MARK: Settings

View File

@ -5,9 +5,9 @@ public enum SnodeAPI {
/// - Note: Should only be accessed from `Threading.workQueue` to avoid race conditions.
internal static var snodeFailureCount: [Snode:UInt] = [:]
/// - Note: Should only be accessed from `Threading.workQueue` to avoid race conditions.
internal static var snodePool: Set<Snode> = [] // TODO: Just get/set the database values directly?
internal static var snodePool: Set<Snode> = []
/// - Note: Should only be accessed from `Threading.workQueue` to avoid race conditions.
internal static var swarmCache: [String:Set<Snode>] = [:] // TODO: Just get/set the database values directly?
internal static var swarmCache: [String:Set<Snode>] = [:]
// MARK: Settings
private static let maxRetryCount: UInt = 4

View File

@ -1,7 +1,7 @@
public extension Array where Element : CustomStringConvertible {
public var prettifiedDescription: String {
var prettifiedDescription: String {
return "[ " + map { $0.description }.joined(separator: ", ") + " ]"
}
}

View File

@ -1,7 +1,7 @@
public extension String {
public func removing05PrefixIfNeeded() -> String {
func removing05PrefixIfNeeded() -> String {
var result = self
if result.count == 66 && result.hasPrefix("05") { result.removeFirst(2) }
return result

View File

@ -600,6 +600,7 @@
C39DD28824F3318C008590FC /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C39DD28724F3318C008590FC /* Colors.xcassets */; };
C39DD28A24F3336E008590FC /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C39DD28724F3318C008590FC /* Colors.xcassets */; };
C39DD28B24F3336F008590FC /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C39DD28724F3318C008590FC /* Colors.xcassets */; };
C3AABDDF2553ECF00042FF4C /* Array+Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D12553860800C340D1 /* Array+Description.swift */; };
C3C2A5A3255385C100C340D1 /* SessionSnodeKit.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C2A5A1255385C100C340D1 /* SessionSnodeKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
C3C2A5A6255385C100C340D1 /* SessionSnodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3C2A59F255385C100C340D1 /* SessionSnodeKit.framework */; };
C3C2A5A7255385C100C340D1 /* SessionSnodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C3C2A59F255385C100C340D1 /* SessionSnodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@ -615,7 +616,6 @@
C3C2A5DA2553860B00C340D1 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5CE2553860700C340D1 /* Logging.swift */; };
C3C2A5DB2553860B00C340D1 /* Promise+Hashing.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5CF2553860700C340D1 /* Promise+Hashing.swift */; };
C3C2A5DC2553860B00C340D1 /* Promise+Threading.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D02553860800C340D1 /* Promise+Threading.swift */; };
C3C2A5DD2553860B00C340D1 /* Array+Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D12553860800C340D1 /* Array+Description.swift */; };
C3C2A5DE2553860B00C340D1 /* String+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D22553860900C340D1 /* String+Utilities.swift */; };
C3C2A5DF2553860B00C340D1 /* Promise+Delaying.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D32553860900C340D1 /* Promise+Delaying.swift */; };
C3C2A5E02553860B00C340D1 /* Threading.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D42553860A00C340D1 /* Threading.swift */; };
@ -738,7 +738,6 @@
C3C2ABEE2553C76900C340D1 /* ClosedGroupSenderKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2ABED2553C76900C340D1 /* ClosedGroupSenderKey.swift */; };
C3C2ABF82553C8A300C340D1 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2ABF72553C8A300C340D1 /* Storage.swift */; };
C3C2AC0A2553C9A100C340D1 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2AC092553C9A100C340D1 /* Configuration.swift */; };
C3C2AC1C2553CADF00C340D1 /* SharedSenderKeysDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2AC1B2553CADF00C340D1 /* SharedSenderKeysDelegate.swift */; };
C3C2AC2E2553CBEB00C340D1 /* String+Trimming.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2AC2D2553CBEB00C340D1 /* String+Trimming.swift */; };
C3C2AC372553CCE600C340D1 /* SessionUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3C2A679255388CC00C340D1 /* SessionUtilities.framework */; };
C3C3CF8924D8EED300E1CCE7 /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C3CF8824D8EED300E1CCE7 /* TextView.swift */; };
@ -1721,7 +1720,6 @@
C3C2ABED2553C76900C340D1 /* ClosedGroupSenderKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClosedGroupSenderKey.swift; sourceTree = "<group>"; };
C3C2ABF72553C8A300C340D1 /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = "<group>"; };
C3C2AC092553C9A100C340D1 /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
C3C2AC1B2553CADF00C340D1 /* SharedSenderKeysDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedSenderKeysDelegate.swift; sourceTree = "<group>"; };
C3C2AC2D2553CBEB00C340D1 /* String+Trimming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Trimming.swift"; sourceTree = "<group>"; };
C3C3CF8824D8EED300E1CCE7 /* TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
C3D0972A2510499C00F6E3E4 /* BackgroundPoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundPoller.swift; sourceTree = "<group>"; };
@ -3468,7 +3466,6 @@
C3C2ABE32553C74400C340D1 /* ClosedGroupRatchet.swift */,
C3C2ABED2553C76900C340D1 /* ClosedGroupSenderKey.swift */,
C3C2AB632553C5FF00C340D1 /* SharedSenderKeys.swift */,
C3C2AC1B2553CADF00C340D1 /* SharedSenderKeysDelegate.swift */,
C3C2ABF72553C8A300C340D1 /* Storage.swift */,
);
path = "Shared Sender Keys";
@ -4781,7 +4778,6 @@
C3C2A5DF2553860B00C340D1 /* Promise+Delaying.swift in Sources */,
C3C2A5DC2553860B00C340D1 /* Promise+Threading.swift in Sources */,
C3C2A5C4255385EE00C340D1 /* OnionRequestAPI+Encryption.swift in Sources */,
C3C2A5DD2553860B00C340D1 /* Array+Description.swift in Sources */,
C3C2A5E32553860B00C340D1 /* AESGCM.swift in Sources */,
C3C2A5DE2553860B00C340D1 /* String+Utilities.swift in Sources */,
C3C2A5E52553860B00C340D1 /* JSON.swift in Sources */,
@ -4797,6 +4793,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C3AABDDF2553ECF00042FF4C /* Array+Description.swift in Sources */,
C3C2ABD22553C6C900C340D1 /* Data+SecureRandom.swift in Sources */,
C3C2AC2E2553CBEB00C340D1 /* String+Trimming.swift in Sources */,
);
@ -4861,7 +4858,6 @@
C3C2AB642553C5FF00C340D1 /* SharedSenderKeys.swift in Sources */,
C3C2A9102553B5B200C340D1 /* AliceAxolotlParameters.m in Sources */,
C3C2A9FA2553B9C400C340D1 /* OWSSwiftUtils.swift in Sources */,
C3C2AC1C2553CADF00C340D1 /* SharedSenderKeysDelegate.swift in Sources */,
C3C2A92C2553B5BE00C340D1 /* SessionCipher.m in Sources */,
C3C2A8D42553B57C00C340D1 /* SignedPrekeyRecord.m in Sources */,
C3C2A8A12553B4F600C340D1 /* WhisperMessage.m in Sources */,