mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.1 KiB
Swift
59 lines
2.1 KiB
Swift
1 year ago
|
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
import Combine
|
||
|
import GRDB
|
||
|
import Sodium
|
||
|
import SessionSnodeKit
|
||
|
import SessionUtilitiesKit
|
||
|
|
||
|
extension MessageReceiver {
|
||
|
/// Some messages are encrypted with `libSession` and don't use Protobuf, this function decrypts those messages and
|
||
|
/// routes them accordingly
|
||
|
public static func handleLibSessionMessage(
|
||
|
_ db: Database,
|
||
|
threadId: String,
|
||
|
threadVariant: SessionThread.Variant,
|
||
|
message: LibSessionMessage,
|
||
|
using dependencies: Dependencies
|
||
|
) throws {
|
||
|
guard
|
||
|
let sender: String = message.sender,
|
||
|
let senderSessionId: SessionId = try? SessionId(from: sender),
|
||
|
let userEd25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db, using: dependencies)
|
||
|
else { throw MessageReceiverError.decryptionFailed }
|
||
|
|
||
|
let supportedEncryptionDomains: [SessionUtil.Crypto.Domain] = [
|
||
|
.kickedMessage
|
||
|
]
|
||
|
|
||
|
try supportedEncryptionDomains
|
||
|
.map { domain -> (domain: SessionUtil.Crypto.Domain, plaintext: Data) in
|
||
|
(
|
||
|
domain,
|
||
|
try SessionUtil.decrypt(
|
||
|
ciphertext: message.ciphertext,
|
||
|
senderSessionId: senderSessionId,
|
||
|
ed25519KeyPair: userEd25519KeyPair,
|
||
|
domain: domain,
|
||
|
using: dependencies
|
||
|
)
|
||
|
)
|
||
|
}
|
||
|
.forEach { domain, plaintext in
|
||
|
switch domain {
|
||
|
case SessionUtil.Crypto.Domain.kickedMessage:
|
||
|
try handleGroupDelete(
|
||
|
db,
|
||
|
groupSessionId: senderSessionId,
|
||
|
plaintext: plaintext,
|
||
|
using: dependencies
|
||
|
)
|
||
|
|
||
|
default: SNLog("[MessageReceiver] Received libSession encrypted message with unsupported domain: \(domain)")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|