mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-24 11:56:18 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
36 lines
1.5 KiB
Swift
36 lines
1.5 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
import TelegramApi
|
|
import MtProtoKit
|
|
|
|
|
|
func validatedEncryptionConfig(postbox: Postbox, network: Network) -> Signal<SecretChatEncryptionConfig, NoError> {
|
|
return network.request(Api.functions.messages.getDhConfig(version: 0, randomLength: 0))
|
|
|> retryRequest
|
|
|> mapToSignal { result -> Signal<SecretChatEncryptionConfig, NoError> in
|
|
switch result {
|
|
case let .dhConfig(dhConfigData):
|
|
let (g, p, version) = (dhConfigData.g, dhConfigData.p, dhConfigData.version)
|
|
if !MTCheckIsSafeG(UInt32(g)) {
|
|
Logger.shared.log("SecretChatEncryptionConfig", "Invalid g")
|
|
return .complete()
|
|
}
|
|
|
|
if !MTCheckMod(network.encryptionProvider, p.makeData(), UInt32(g), network.context.keychain) {
|
|
Logger.shared.log("SecretChatEncryptionConfig", "Invalid p or g")
|
|
return .complete()
|
|
}
|
|
|
|
if !MTCheckIsSafePrime(network.encryptionProvider, p.makeData(), network.context.keychain) {
|
|
Logger.shared.log("SecretChatEncryptionConfig", "Invalid p")
|
|
return .never()
|
|
}
|
|
return .single(SecretChatEncryptionConfig(g: g, p: MemoryBuffer(p), version: version))
|
|
case .dhConfigNotModified:
|
|
assertionFailure()
|
|
return .never()
|
|
}
|
|
}
|
|
}
|