Removed usages of Box.KeyPair, removed a TODO

This commit is contained in:
Morgan Pretty 2023-03-10 09:42:36 +11:00
parent 8f39fe6972
commit 1334a64031
33 changed files with 92 additions and 97 deletions

View File

@ -739,7 +739,7 @@
FD8ECF7929340F7200C0D1BB /* libsession-util.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = FD8ECF7829340F7100C0D1BB /* libsession-util.xcframework */; };
FD8ECF7B29340FFD00C0D1BB /* SessionUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF7A29340FFD00C0D1BB /* SessionUtil.swift */; };
FD8ECF7D2934293A00C0D1BB /* _012_SessionUtilChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF7C2934293A00C0D1BB /* _012_SessionUtilChanges.swift */; };
FD8ECF7F2934298100C0D1BB /* SharedConfigDump.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF7E2934298100C0D1BB /* SharedConfigDump.swift */; };
FD8ECF7F2934298100C0D1BB /* ConfigDump.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF7E2934298100C0D1BB /* ConfigDump.swift */; };
FD8ECF822934387A00C0D1BB /* ConfigUserProfileSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF812934387A00C0D1BB /* ConfigUserProfileSpec.swift */; };
FD8ECF892935AB7200C0D1BB /* SessionUtilError.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF882935AB7200C0D1BB /* SessionUtilError.swift */; };
FD8ECF8B2935DB4B00C0D1BB /* SharedConfigMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8ECF8A2935DB4B00C0D1BB /* SharedConfigMessage.swift */; };
@ -1870,7 +1870,7 @@
FD8ECF7829340F7100C0D1BB /* libsession-util.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = "libsession-util.xcframework"; sourceTree = "<group>"; };
FD8ECF7A29340FFD00C0D1BB /* SessionUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionUtil.swift; sourceTree = "<group>"; };
FD8ECF7C2934293A00C0D1BB /* _012_SessionUtilChanges.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _012_SessionUtilChanges.swift; sourceTree = "<group>"; };
FD8ECF7E2934298100C0D1BB /* SharedConfigDump.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedConfigDump.swift; sourceTree = "<group>"; };
FD8ECF7E2934298100C0D1BB /* ConfigDump.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigDump.swift; sourceTree = "<group>"; };
FD8ECF812934387A00C0D1BB /* ConfigUserProfileSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigUserProfileSpec.swift; sourceTree = "<group>"; };
FD8ECF882935AB7200C0D1BB /* SessionUtilError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionUtilError.swift; sourceTree = "<group>"; };
FD8ECF8A2935DB4B00C0D1BB /* SharedConfigMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedConfigMessage.swift; sourceTree = "<group>"; };
@ -3612,7 +3612,7 @@
FDE77F6A280FEB28002CFC5D /* ControlMessageProcessRecord.swift */,
FD5C7308285007920029977D /* BlindedIdLookup.swift */,
FD09B7E6288670FD00ED0B66 /* Reaction.swift */,
FD8ECF7E2934298100C0D1BB /* SharedConfigDump.swift */,
FD8ECF7E2934298100C0D1BB /* ConfigDump.swift */,
FD432433299C6985008A0213 /* PendingReadReceipt.swift */,
);
path = Models;
@ -5800,7 +5800,7 @@
FD778B6429B189FF001BAC6B /* _013_GenerateInitialUserConfigDumps.swift in Sources */,
C32C598A256D0664003C73A2 /* SNProtoEnvelope+Conversion.swift in Sources */,
FDC438CB27BB7DB100C60D73 /* UpdateMessageRequest.swift in Sources */,
FD8ECF7F2934298100C0D1BB /* SharedConfigDump.swift in Sources */,
FD8ECF7F2934298100C0D1BB /* ConfigDump.swift in Sources */,
FDA1E83B29A5F2D500C5C3BD /* SessionUtil+Shared.swift in Sources */,
C352A2FF25574B6300338F3E /* MessageSendJob.swift in Sources */,
FDC438C327BB512200C60D73 /* SodiumProtocols.swift in Sources */,

View File

@ -501,7 +501,7 @@ public enum SMKLegacy {
return .new(
publicKey: publicKey,
name: name,
encryptionKeyPair: Box.KeyPair(
encryptionKeyPair: KeyPair(
publicKey: encryptionKeyPair.publicKey.bytes,
secretKey: encryptionKeyPair.privateKey.bytes
),

View File

@ -782,8 +782,8 @@ public extension Interaction {
let sodium: Sodium = Sodium()
if
let userEd25519KeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db),
let blindedKeyPair: Box.KeyPair = sodium.blindedKeyPair(
let userEd25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db),
let blindedKeyPair: KeyPair = sodium.blindedKeyPair(
serverPublicKey: openGroup.publicKey,
edKeyPair: userEd25519KeyPair,
genericHash: sodium.genericHash

View File

@ -383,7 +383,7 @@ public extension SessionThread {
) -> String? {
guard
threadVariant == .community,
let blindingInfo: (edkeyPair: Box.KeyPair?, publicKey: String?, capabilities: Set<Capability.Variant>) = Storage.shared.read({ db in
let blindingInfo: (edkeyPair: KeyPair?, publicKey: String?, capabilities: Set<Capability.Variant>) = Storage.shared.read({ db in
struct OpenGroupInfo: Decodable, FetchableRecord {
let publicKey: String?
let server: String?
@ -405,14 +405,14 @@ public extension SessionThread {
.defaulting(to: [])
)
}),
let userEdKeyPair: Box.KeyPair = blindingInfo.edkeyPair,
let userEdKeyPair: KeyPair = blindingInfo.edkeyPair,
let publicKey: String = blindingInfo.publicKey,
blindingInfo.capabilities.isEmpty || blindingInfo.capabilities.contains(.blind)
else { return nil }
let sodium: Sodium = Sodium()
let blindedKeyPair: Box.KeyPair? = sodium.blindedKeyPair(
let blindedKeyPair: KeyPair? = sodium.blindedKeyPair(
serverPublicKey: publicKey,
edKeyPair: userEdKeyPair,
genericHash: sodium.getGenericHash()

View File

@ -2,7 +2,6 @@
import Foundation
import GRDB
//import SignalCoreKit
import SessionUtilitiesKit
public enum FailedMessageSendsJob: JobExecutor {

View File

@ -205,7 +205,7 @@ internal extension SessionUtil {
db,
groupPublicKey: group.id,
name: name,
encryptionKeyPair: Box.KeyPair(
encryptionKeyPair: KeyPair(
publicKey: lastKeyPair.publicKey.bytes,
secretKey: lastKeyPair.secretKey.bytes
),

View File

@ -36,7 +36,7 @@ public final class ClosedGroupControlMessage: ControlMessage {
case wrappers
}
case new(publicKey: Data, name: String, encryptionKeyPair: Box.KeyPair, members: [Data], admins: [Data], expirationTimer: UInt32)
case new(publicKey: Data, name: String, encryptionKeyPair: KeyPair, members: [Data], admins: [Data], expirationTimer: UInt32)
/// An encryption key pair encrypted for each member individually.
///
@ -68,7 +68,7 @@ public final class ClosedGroupControlMessage: ControlMessage {
let newDescription: String = Kind.new(
publicKey: Data(),
name: "",
encryptionKeyPair: Box.KeyPair(publicKey: [], secretKey: []),
encryptionKeyPair: KeyPair(publicKey: [], secretKey: []),
members: [],
admins: [],
expirationTimer: 0
@ -79,7 +79,7 @@ public final class ClosedGroupControlMessage: ControlMessage {
self = .new(
publicKey: try container.decode(Data.self, forKey: .publicKey),
name: try container.decode(String.self, forKey: .name),
encryptionKeyPair: Box.KeyPair(
encryptionKeyPair: KeyPair(
publicKey: try container.decode([UInt8].self, forKey: .encryptionPublicKey),
secretKey: try container.decode([UInt8].self, forKey: .encryptionSecretKey)
),
@ -252,7 +252,7 @@ public final class ClosedGroupControlMessage: ControlMessage {
kind: .new(
publicKey: publicKey,
name: name,
encryptionKeyPair: Box.KeyPair(
encryptionKeyPair: KeyPair(
publicKey: encryptionKeyPairAsProto.publicKey.removingIdPrefixIfNeeded().bytes,
secretKey: encryptionKeyPairAsProto.privateKey.bytes
),

View File

@ -1349,7 +1349,7 @@ public enum OpenGroupAPI {
)
) -> (publicKey: String, signature: Bytes)? {
guard
let userEdKeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db),
let userEdKeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db),
let serverPublicKey: String = try? OpenGroup
.select(.publicKey)
.filter(OpenGroup.Columns.server == serverName.lowercased())
@ -1366,7 +1366,7 @@ public enum OpenGroupAPI {
// If we have no capabilities or if the server supports blinded keys then sign using the blinded key
if forceBlinded || capabilities.isEmpty || capabilities.contains(.blind) {
guard let blindedKeyPair: Box.KeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: serverPublicKey, edKeyPair: userEdKeyPair, genericHash: dependencies.genericHash) else {
guard let blindedKeyPair: KeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: serverPublicKey, edKeyPair: userEdKeyPair, genericHash: dependencies.genericHash) else {
return nil
}
@ -1394,7 +1394,7 @@ public enum OpenGroupAPI {
// Default to using the 'standard' key
default:
guard let userKeyPair: Box.KeyPair = Identity.fetchUserKeyPair(db) else { return nil }
guard let userKeyPair: KeyPair = Identity.fetchUserKeyPair(db) else { return nil }
guard let signatureResult: Bytes = try? dependencies.ed25519.sign(data: messageBytes, keyPair: userKeyPair) else {
return nil
}

View File

@ -945,7 +945,7 @@ public final class OpenGroupManager {
fallthrough
case .unblinded:
guard let userEdKeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
guard let userEdKeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
return false
}
guard sessionId.prefix != .unblinded || publicKey == SessionId(.unblinded, publicKey: userEdKeyPair.publicKey).hexString else {
@ -955,13 +955,13 @@ public final class OpenGroupManager {
case .blinded:
guard
let userEdKeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db),
let userEdKeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db),
let openGroupPublicKey: String = try? OpenGroup
.select(.publicKey)
.filter(id: groupId)
.asRequest(of: String.self)
.fetchOne(db),
let blindedKeyPair: Box.KeyPair = dependencies.sodium.blindedKeyPair(
let blindedKeyPair: KeyPair = dependencies.sodium.blindedKeyPair(
serverPublicKey: openGroupPublicKey,
edKeyPair: userEdKeyPair,
genericHash: dependencies.genericHash

View File

@ -3,6 +3,7 @@
import Foundation
import Sodium
import Curve25519Kit
import SessionUtilitiesKit
public protocol SodiumType {
func getBox() -> BoxType
@ -11,7 +12,7 @@ public protocol SodiumType {
func getAeadXChaCha20Poly1305Ietf() -> AeadXChaCha20Poly1305IetfType
func generateBlindingFactor(serverPublicKey: String, genericHash: GenericHashType) -> Bytes?
func blindedKeyPair(serverPublicKey: String, edKeyPair: Box.KeyPair, genericHash: GenericHashType) -> Box.KeyPair?
func blindedKeyPair(serverPublicKey: String, edKeyPair: KeyPair, genericHash: GenericHashType) -> KeyPair?
func sogsSignature(message: Bytes, secretKey: Bytes, blindedSecretKey ka: Bytes, blindedPublicKey kA: Bytes) -> Bytes?
func combineKeys(lhsKeyBytes: Bytes, rhsKeyBytes: Bytes) -> Bytes?
@ -29,7 +30,7 @@ public protocol AeadXChaCha20Poly1305IetfType {
}
public protocol Ed25519Type {
func sign(data: Bytes, keyPair: Box.KeyPair) throws -> Bytes?
func sign(data: Bytes, keyPair: KeyPair) throws -> Bytes?
func verifySignature(_ signature: Data, publicKey: Data, data: Data) throws -> Bool
}
@ -81,7 +82,7 @@ extension Sodium: SodiumType {
public func getSign() -> SignType { return sign }
public func getAeadXChaCha20Poly1305Ietf() -> AeadXChaCha20Poly1305IetfType { return aead.xchacha20poly1305ietf }
public func blindedKeyPair(serverPublicKey: String, edKeyPair: Box.KeyPair) -> Box.KeyPair? {
public func blindedKeyPair(serverPublicKey: String, edKeyPair: KeyPair) -> KeyPair? {
return blindedKeyPair(serverPublicKey: serverPublicKey, edKeyPair: edKeyPair, genericHash: getGenericHash())
}
}
@ -92,7 +93,7 @@ extension Sign: SignType {}
extension Aead.XChaCha20Poly1305Ietf: AeadXChaCha20Poly1305IetfType {}
struct Ed25519Wrapper: Ed25519Type {
func sign(data: Bytes, keyPair: Box.KeyPair) throws -> Bytes? {
func sign(data: Bytes, keyPair: KeyPair) throws -> Bytes? {
let ecKeyPair: ECKeyPair = try ECKeyPair(
publicKeyData: Data(keyPair.publicKey),
privateKeyData: Data(keyPair.secretKey)

View File

@ -88,7 +88,7 @@ extension MessageReceiver {
_ db: Database,
groupPublicKey: String,
name: String,
encryptionKeyPair: Box.KeyPair,
encryptionKeyPair: KeyPair,
members: [String],
admins: [String],
expirationTimer: UInt32,
@ -210,7 +210,7 @@ extension MessageReceiver {
let groupPublicKey: String = (explicitGroupPublicKey?.toHexString() ?? threadId)
guard let userKeyPair: Box.KeyPair = Identity.fetchUserKeyPair(db) else {
guard let userKeyPair: KeyPair = Identity.fetchUserKeyPair(db) else {
return SNLog("Couldn't find user X25519 key pair.")
}
guard let closedGroup: ClosedGroup = try? ClosedGroup.fetchOne(db, id: groupPublicKey) else {

View File

@ -177,7 +177,7 @@ extension MessageReceiver {
try message.closedGroups.forEach { closedGroup in
guard !existingClosedGroupsIds.contains(closedGroup.publicKey) else { return }
let keyPair: Box.KeyPair = Box.KeyPair(
let keyPair: KeyPair = KeyPair(
publicKey: closedGroup.encryptionKeyPublicKey.bytes,
secretKey: closedGroup.encryptionKeySecretKey.bytes
)

View File

@ -88,8 +88,8 @@ extension MessageReceiver {
let sodium: Sodium = Sodium()
guard
let userEdKeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db),
let blindedKeyPair: Box.KeyPair = sodium.blindedKeyPair(
let userEdKeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db),
let blindedKeyPair: KeyPair = sodium.blindedKeyPair(
serverPublicKey: openGroup.publicKey,
edKeyPair: userEdKeyPair,
genericHash: sodium.genericHash

View File

@ -93,7 +93,7 @@ extension MessageSender {
kind: .new(
publicKey: Data(hex: groupPublicKey),
name: name,
encryptionKeyPair: Box.KeyPair(
encryptionKeyPair: KeyPair(
publicKey: encryptionKeyPair.publicKey.bytes,
secretKey: encryptionKeyPair.privateKey.bytes
),
@ -442,7 +442,7 @@ extension MessageSender {
kind: .new(
publicKey: Data(hex: closedGroup.id),
name: closedGroup.name,
encryptionKeyPair: Box.KeyPair(
encryptionKeyPair: KeyPair(
publicKey: encryptionKeyPair.publicKey.bytes,
secretKey: encryptionKeyPair.secretKey.bytes
),

View File

@ -6,7 +6,7 @@ import Sodium
import SessionUtilitiesKit
extension MessageReceiver {
internal static func decryptWithSessionProtocol(ciphertext: Data, using x25519KeyPair: Box.KeyPair, dependencies: SMKDependencies = SMKDependencies()) throws -> (plaintext: Data, senderX25519PublicKey: String) {
internal static func decryptWithSessionProtocol(ciphertext: Data, using x25519KeyPair: KeyPair, dependencies: SMKDependencies = SMKDependencies()) throws -> (plaintext: Data, senderX25519PublicKey: String) {
let recipientX25519PrivateKey = x25519KeyPair.secretKey
let recipientX25519PublicKey = x25519KeyPair.publicKey
let signatureSize = dependencies.sign.Bytes
@ -44,7 +44,7 @@ extension MessageReceiver {
return (Data(plaintext), SessionId(.standard, publicKey: senderX25519PublicKey).hexString)
}
internal static func decryptWithSessionBlindingProtocol(data: Data, isOutgoing: Bool, otherBlindedPublicKey: String, with openGroupPublicKey: String, userEd25519KeyPair: Box.KeyPair, using dependencies: SMKDependencies = SMKDependencies()) throws -> (plaintext: Data, senderX25519PublicKey: String) {
internal static func decryptWithSessionBlindingProtocol(data: Data, isOutgoing: Bool, otherBlindedPublicKey: String, with openGroupPublicKey: String, userEd25519KeyPair: KeyPair, using dependencies: SMKDependencies = SMKDependencies()) throws -> (plaintext: Data, senderX25519PublicKey: String) {
/// Ensure the data is at least long enough to have the required components
guard
data.count > (dependencies.nonceGenerator24.NonceBytes + 2),

View File

@ -39,7 +39,7 @@ public enum MessageReceiver {
// Default to 'standard' as the old code didn't seem to require an `envelope.source`
switch (SessionId.Prefix(from: envelope.source) ?? .standard) {
case .standard, .unblinded:
guard let userX25519KeyPair: Box.KeyPair = Identity.fetchUserKeyPair(db) else {
guard let userX25519KeyPair: KeyPair = Identity.fetchUserKeyPair(db) else {
throw MessageReceiverError.noUserX25519KeyPair
}
@ -52,7 +52,7 @@ public enum MessageReceiver {
guard let openGroupServerPublicKey: String = openGroupServerPublicKey else {
throw MessageReceiverError.invalidGroupPublicKey
}
guard let userEd25519KeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
guard let userEd25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
throw MessageReceiverError.noUserED25519KeyPair
}
@ -93,7 +93,7 @@ public enum MessageReceiver {
do {
return try decryptWithSessionProtocol(
ciphertext: ciphertext,
using: Box.KeyPair(
using: KeyPair(
publicKey: keyPair.publicKey.bytes,
secretKey: keyPair.secretKey.bytes
)

View File

@ -12,7 +12,7 @@ extension MessageSender {
for recipientHexEncodedX25519PublicKey: String,
using dependencies: SMKDependencies = SMKDependencies()
) throws -> Data {
guard let userEd25519KeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
guard let userEd25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
throw MessageSenderError.noUserED25519KeyPair
}
@ -41,7 +41,7 @@ extension MessageSender {
guard SessionId.Prefix(from: recipientBlindedId) == .blinded else {
throw MessageSenderError.signingFailed
}
guard let userEd25519KeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
guard let userEd25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db) else {
throw MessageSenderError.noUserED25519KeyPair
}
guard let blindedKeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: openGroupPublicKey, edKeyPair: userEd25519KeyPair, genericHash: dependencies.genericHash) else {

View File

@ -388,7 +388,7 @@ public final class MessageSender {
// error in a non-retryable way
guard
let openGroup: OpenGroup = try? OpenGroup.fetchOne(db, id: threadId),
let userEdKeyPair: Box.KeyPair = Identity.fetchUserEd25519KeyPair(db),
let userEdKeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db),
case .openGroup(_, let server, _, _, _) = destination
else {
throw MessageSenderError.invalidMessage
@ -407,7 +407,7 @@ public final class MessageSender {
guard capabilities.isEmpty || capabilities.contains(.blind) else {
return SessionId(.unblinded, publicKey: userEdKeyPair.publicKey).hexString
}
guard let blindedKeyPair: Box.KeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: openGroup.publicKey, edKeyPair: userEdKeyPair, genericHash: dependencies.genericHash) else {
guard let blindedKeyPair: KeyPair = dependencies.sodium.blindedKeyPair(serverPublicKey: openGroup.publicKey, edKeyPair: userEdKeyPair, genericHash: dependencies.genericHash) else {
preconditionFailure()
}

View File

@ -68,7 +68,7 @@ extension Sodium {
}
/// Constructs a "blinded" key pair (`ka, kA`) based on an open group server `publicKey` and an ed25519 `keyPair`
public func blindedKeyPair(serverPublicKey: String, edKeyPair: Box.KeyPair, genericHash: GenericHashType) -> Box.KeyPair? {
public func blindedKeyPair(serverPublicKey: String, edKeyPair: KeyPair, genericHash: GenericHashType) -> KeyPair? {
guard edKeyPair.publicKey.count == Sodium.publicKeyLength && edKeyPair.secretKey.count == Sodium.secretKeyLength else {
return nil
}
@ -97,7 +97,7 @@ extension Sodium {
guard crypto_scalarmult_ed25519_base_noclamp(kAPtr, kaPtr) == 0 else { return nil }
return Box.KeyPair(
return KeyPair(
publicKey: Data(bytes: kAPtr, count: Sodium.publicKeyLength).bytes,
secretKey: Data(bytes: kaPtr, count: Sodium.secretKeyLength).bytes
)
@ -277,12 +277,3 @@ extension AeadXChaCha20Poly1305IetfType {
return authenticatedCipherText
}
}
extension Box.KeyPair: Equatable {
public static func == (lhs: Box.KeyPair, rhs: Box.KeyPair) -> Bool {
return (
lhs.publicKey == rhs.publicKey &&
lhs.secretKey == rhs.secretKey
)
}
}

View File

@ -89,7 +89,7 @@ class OpenGroupAPISpec: QuickSpec {
mockSodium
.when { $0.blindedKeyPair(serverPublicKey: any(), edKeyPair: any(), genericHash: mockGenericHash) }
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)

View File

@ -245,7 +245,7 @@ class OpenGroupManagerSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)
@ -2931,7 +2931,7 @@ class OpenGroupManagerSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: otherKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)
@ -3029,7 +3029,7 @@ class OpenGroupManagerSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: otherKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)
@ -3108,7 +3108,7 @@ class OpenGroupManagerSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: otherKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)
@ -3136,7 +3136,7 @@ class OpenGroupManagerSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)
@ -3175,7 +3175,7 @@ class OpenGroupManagerSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
)

View File

@ -69,7 +69,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
mockSodium
.when { $0.blindedKeyPair(serverPublicKey: any(), edKeyPair: any(), genericHash: mockGenericHash) }
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data(hex: TestConstants.blindedPublicKey).bytes,
secretKey: Data(hex: TestConstants.edSecretKey).bytes
)
@ -113,7 +113,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
"sFMhE5G4PbRtQFey1hsxLl221Qivc3ayaX2Mm/X89Dl8e45BC+Lb/KU9EdesxIK4pVgYXs9XrMtX3v8" +
"dt0eBaXneOBfr7qB8pHwwMZjtkOu1ED07T9nszgbWabBphUfWXe2U9K3PTRisSCI="
)!,
using: Box.KeyPair(
using: KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.privateKey)!.bytes
),
@ -139,7 +139,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
expect {
try MessageReceiver.decryptWithSessionProtocol(
ciphertext: "TestMessage".data(using: .utf8)!,
using: Box.KeyPair(
using: KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.privateKey)!.bytes
),
@ -163,7 +163,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
expect {
try MessageReceiver.decryptWithSessionProtocol(
ciphertext: "TestMessage".data(using: .utf8)!,
using: Box.KeyPair(
using: KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.privateKey)!.bytes
),
@ -181,7 +181,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
expect {
try MessageReceiver.decryptWithSessionProtocol(
ciphertext: "TestMessage".data(using: .utf8)!,
using: Box.KeyPair(
using: KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.privateKey)!.bytes
),
@ -197,7 +197,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
expect {
try MessageReceiver.decryptWithSessionProtocol(
ciphertext: "TestMessage".data(using: .utf8)!,
using: Box.KeyPair(
using: KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.privateKey)!.bytes
),
@ -219,7 +219,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -241,7 +241,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: false,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -260,7 +260,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -285,7 +285,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -318,7 +318,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -339,7 +339,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -364,7 +364,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -389,7 +389,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -414,7 +414,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -439,7 +439,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -464,7 +464,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),
@ -489,7 +489,7 @@ class MessageReceiverDecryptionSpec: QuickSpec {
isOutgoing: true,
otherBlindedPublicKey: "15\(TestConstants.blindedPublicKey)",
with: TestConstants.serverPublicKey,
userEd25519KeyPair: Box.KeyPair(
userEd25519KeyPair: KeyPair(
publicKey: Data.data(fromHex: TestConstants.edPublicKey)!.bytes,
secretKey: Data.data(fromHex: TestConstants.edSecretKey)!.bytes
),

View File

@ -264,7 +264,7 @@ class MessageSenderEncryptionSpec: QuickSpec {
)
}
.thenReturn(
Box.KeyPair(
KeyPair(
publicKey: Data(hex: TestConstants.edPublicKey).bytes,
secretKey: Data(hex: TestConstants.edSecretKey).bytes
)

View File

@ -2,6 +2,7 @@
import Foundation
import Sodium
import SessionUtilitiesKit
import Quick
import Nimble
@ -86,7 +87,7 @@ class SodiumUtilitiesSpec: QuickSpec {
it("successfully generates a blinded key pair") {
let result = sodium.blindedKeyPair(
serverPublicKey: TestConstants.serverPublicKey,
edKeyPair: Box.KeyPair(
edKeyPair: KeyPair(
publicKey: Data(hex: TestConstants.edPublicKey).bytes,
secretKey: Data(hex: TestConstants.edSecretKey).bytes
),
@ -102,7 +103,7 @@ class SodiumUtilitiesSpec: QuickSpec {
it("fails if the edKeyPair public key length wrong") {
let result = sodium.blindedKeyPair(
serverPublicKey: TestConstants.serverPublicKey,
edKeyPair: Box.KeyPair(
edKeyPair: KeyPair(
publicKey: Data(hex: String(TestConstants.edPublicKey.prefix(4))).bytes,
secretKey: Data(hex: TestConstants.edSecretKey).bytes
),
@ -115,7 +116,7 @@ class SodiumUtilitiesSpec: QuickSpec {
it("fails if the edKeyPair secret key length wrong") {
let result = sodium.blindedKeyPair(
serverPublicKey: TestConstants.serverPublicKey,
edKeyPair: Box.KeyPair(
edKeyPair: KeyPair(
publicKey: Data(hex: TestConstants.edPublicKey).bytes,
secretKey: Data(hex: String(TestConstants.edSecretKey.prefix(4))).bytes
),
@ -128,7 +129,7 @@ class SodiumUtilitiesSpec: QuickSpec {
it("fails if it cannot generate a blinding factor") {
let result = sodium.blindedKeyPair(
serverPublicKey: "Test",
edKeyPair: Box.KeyPair(
edKeyPair: KeyPair(
publicKey: Data(hex: TestConstants.edPublicKey).bytes,
secretKey: Data(hex: TestConstants.edSecretKey).bytes
),

View File

@ -2,11 +2,12 @@
import Foundation
import Sodium
import SessionUtilitiesKit
@testable import SessionMessagingKit
class MockEd25519: Mock<Ed25519Type>, Ed25519Type {
func sign(data: Bytes, keyPair: Box.KeyPair) throws -> Bytes? {
func sign(data: Bytes, keyPair: KeyPair) throws -> Bytes? {
return accept(args: [data, keyPair]) as? Bytes
}

View File

@ -2,6 +2,7 @@
import Foundation
import Sodium
import SessionUtilitiesKit
@testable import SessionMessagingKit
@ -15,8 +16,8 @@ class MockSodium: Mock<SodiumType>, SodiumType {
return accept(args: [serverPublicKey, genericHash]) as? Bytes
}
func blindedKeyPair(serverPublicKey: String, edKeyPair: Box.KeyPair, genericHash: GenericHashType) -> Box.KeyPair? {
return accept(args: [serverPublicKey, edKeyPair, genericHash]) as? Box.KeyPair
func blindedKeyPair(serverPublicKey: String, edKeyPair: KeyPair, genericHash: GenericHashType) -> KeyPair? {
return accept(args: [serverPublicKey, edKeyPair, genericHash]) as? KeyPair
}
func sogsSignature(message: Bytes, secretKey: Bytes, blindedSecretKey ka: Bytes, blindedPublicKey kA: Bytes) -> Bytes? {

View File

@ -494,7 +494,7 @@ public final class SnodeAPI {
.eraseToAnyPublisher()
}
guard let userED25519KeyPair: Box.KeyPair = Storage.shared.read({ db in Identity.fetchUserEd25519KeyPair(db) }) else {
guard let userED25519KeyPair: KeyPair = Storage.shared.read({ db in Identity.fetchUserEd25519KeyPair(db) }) else {
throw SnodeAPIError.noKeyPair
}
@ -573,7 +573,7 @@ public final class SnodeAPI {
.eraseToAnyPublisher()
}
guard let userED25519KeyPair: Box.KeyPair = Storage.shared.read({ db in Identity.fetchUserEd25519KeyPair(db) }) else {
guard let userED25519KeyPair: KeyPair = Storage.shared.read({ db in Identity.fetchUserEd25519KeyPair(db) }) else {
throw SnodeAPIError.noKeyPair
}

View File

@ -2,7 +2,7 @@
import Foundation
public struct KeyPair {
public struct KeyPair: Equatable {
public let publicKey: [UInt8]
public let secretKey: [UInt8]

View File

@ -94,7 +94,7 @@ public extension Identity {
return try? Identity.fetchOne(db, id: .x25519PrivateKey)?.data
}
static func fetchUserKeyPair(_ db: Database? = nil) -> Box.KeyPair? {
static func fetchUserKeyPair(_ db: Database? = nil) -> KeyPair? {
guard let db: Database = db else {
return Storage.shared.read { db in fetchUserKeyPair(db) }
}
@ -103,13 +103,13 @@ public extension Identity {
let privateKey: Data = fetchUserPrivateKey(db)
else { return nil }
return Box.KeyPair(
return KeyPair(
publicKey: publicKey.bytes,
secretKey: privateKey.bytes
)
}
static func fetchUserEd25519KeyPair(_ db: Database? = nil) -> Box.KeyPair? {
static func fetchUserEd25519KeyPair(_ db: Database? = nil) -> KeyPair? {
guard let db: Database = db else {
return Storage.shared.read { db in fetchUserEd25519KeyPair(db) }
}
@ -118,7 +118,7 @@ public extension Identity {
let secretKey: Data = try? Identity.fetchOne(db, id: .ed25519SecretKey)?.data
else { return nil }
return Box.KeyPair(
return KeyPair(
publicKey: publicKey.bytes,
secretKey: secretKey.bytes
)

View File

@ -6,5 +6,5 @@ public final class Features {
public static let useOnionRequests: Bool = true
public static let useTestnet: Bool = false
public static let useSharedUtilForUserConfig: Bool = true
public static let useSharedUtilForUserConfig: Bool = true // TODO: Base this off a timestamp
}

View File

@ -132,7 +132,7 @@ public final class ProfilePictureView: UIView {
additionalProfilePlaceholderImageView.pin(.right, to: .right, of: additionalImageContainerView)
additionalProfilePlaceholderImageView.pin(.bottom, to: .bottom, of: additionalImageContainerView, withInset: 5)
}
// TODO: Update this to be more explicit? (or add a helper method? current code requires duplicate logic around deciding what properties should be set in what cases)
private func prepareForReuse() {
imageView.contentMode = .scaleAspectFill
imageView.isHidden = true

View File

@ -3,9 +3,10 @@
import Foundation
import Sodium
import Curve25519Kit
import SessionUtilitiesKit
extension Box.KeyPair: Mocked {
static var mockValue: Box.KeyPair = Box.KeyPair(
extension KeyPair: Mocked {
static var mockValue: KeyPair = KeyPair(
publicKey: Data(hex: TestConstants.publicKey).bytes,
secretKey: Data(hex: TestConstants.edSecretKey).bytes
)