diff --git a/Makefile b/Makefile index 625c56dc0f..db4f5cdcf8 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include Utils.makefile -APP_VERSION="7.1" +APP_VERSION="7.1.1" CORE_COUNT=$(shell sysctl -n hw.logicalcpu) CORE_COUNT_MINUS_ONE=$(shell expr ${CORE_COUNT} \- 1) diff --git a/submodules/MtProtoKit/Sources/MTDatacenterAuthAction.m b/submodules/MtProtoKit/Sources/MTDatacenterAuthAction.m index 736b69f546..1a36bbeecc 100644 --- a/submodules/MtProtoKit/Sources/MTDatacenterAuthAction.m +++ b/submodules/MtProtoKit/Sources/MTDatacenterAuthAction.m @@ -180,7 +180,6 @@ - (void)cancel { [self cleanup]; - [self fail]; } - (void)complete { diff --git a/submodules/MtProtoKit/Sources/MTDatacenterAuthMessageService.m b/submodules/MtProtoKit/Sources/MTDatacenterAuthMessageService.m index 22aaf5d07d..da1ca4e98a 100644 --- a/submodules/MtProtoKit/Sources/MTDatacenterAuthMessageService.m +++ b/submodules/MtProtoKit/Sources/MTDatacenterAuthMessageService.m @@ -109,9 +109,9 @@ static NSDictionary *selectPublicKey(NSArray *fingerprints, NSArray _encryptionProvider; bool _tempAuth; - MTSessionInfo *_sessionInfo; MTDatacenterAuthStage _stage; int64_t _currentStageMessageId; @@ -165,7 +164,6 @@ typedef enum { { _encryptionProvider = context.encryptionProvider; _tempAuth = tempAuth; - _sessionInfo = [[MTSessionInfo alloc] initWithRandomSessionIdAndContext:context]; } return self; } @@ -267,7 +265,7 @@ typedef enum { [reqDhBuffer appendInt64:_dhPublicKeyFingerprint]; [reqDhBuffer appendTLBytes:_dhEncryptedData]; - NSString *messageDescription = [NSString stringWithFormat:@"reqDh nonce:%@ serverNonce:%@ p:%@ q:%@ fingerprint:%llx", _nonce, _serverNonce, _dhP, _dhQ, _dhPublicKeyFingerprint]; + NSString *messageDescription = [NSString stringWithFormat:@"reqDh nonce:%@ serverNonce:%@ p:%@ q:%@ fingerprint:%llx dhEncryptedData:%d bytes", _nonce, _serverNonce, _dhP, _dhQ, _dhPublicKeyFingerprint, (int)_dhEncryptedData.length]; MTOutgoingMessage *message = [[MTOutgoingMessage alloc] initWithData:reqDhBuffer.data metadata:messageDescription additionalDebugDescription:nil shortMetadata:messageDescription messageId:_currentStageMessageId messageSeqNo:_currentStageMessageSeqNo]; return [[MTMessageTransaction alloc] initWithMessagePayload:@[message] prepared:nil failed:nil completion:^(NSDictionary *messageInternalIdToTransactionId, NSDictionary *messageInternalIdToPreparedMessage, __unused NSDictionary *messageInternalIdToQuickAckId) { @@ -402,12 +400,10 @@ typedef enum { arc4random_buf(&random, 1); [dataWithHash appendBytes:&random length:1]; } - #if DEBUG - assert(dataWithHash.length == 255); - #endif + NSData *encryptedData = MTRsaEncrypt(_encryptionProvider, [publicKey objectForKey:@"key"], dataWithHash); if (MTLogEnabled()) { - MTLog(@"[MTDatacenterAuthMessageService#%p encryptedData.length = %d]", self, encryptedData.length); + MTLog(@"[MTDatacenterAuthMessageService#%p encryptedData length %d dataWithHash length %d]", self, (int)encryptedData.length, (int)dataWithHash.length); } if (encryptedData.length < 256) { @@ -447,8 +443,11 @@ typedef enum { arc4random_buf(&random, 1); [dataWithHash appendBytes:&random length:1]; } - + NSData *encryptedData = MTRsaEncrypt(_encryptionProvider, [publicKey objectForKey:@"key"], dataWithHash); + if (MTLogEnabled()) { + MTLog(@"[MTDatacenterAuthMessageService#%p encryptedData length %d dataWithHash length %d]", self, (int)encryptedData.length, (int)dataWithHash.length); + } if (encryptedData.length < 256) { NSMutableData *newEncryptedData = [[NSMutableData alloc] init]; diff --git a/submodules/MtProtoKit/Sources/MTEncryption.m b/submodules/MtProtoKit/Sources/MTEncryption.m index 4df030344c..348e3065a3 100644 --- a/submodules/MtProtoKit/Sources/MTEncryption.m +++ b/submodules/MtProtoKit/Sources/MTEncryption.m @@ -292,12 +292,13 @@ NSData *MTAesDecrypt(NSData *data, NSData *key, NSData *iv) NSData *MTRsaEncrypt(id provider, NSString *publicKey, NSData *data) { #if TARGET_OS_IOS - NSMutableData *updatedData = [[NSMutableData alloc] initWithData:data]; + return [provider rsaEncryptWithPublicKey:publicKey data:data]; + /*NSMutableData *updatedData = [[NSMutableData alloc] initWithData:data]; while (updatedData.length < 256) { uint8_t zero = 0; [updatedData replaceBytesInRange:NSMakeRange(0, 0) withBytes:&zero length:1]; } - return [MTRsa encryptData:updatedData publicKey:publicKey]; + return [MTRsa encryptData:updatedData publicKey:publicKey];*/ #else return [provider macosRSAEncrypt:publicKey data:data]; #endif diff --git a/submodules/MtProtoKit/Sources/MTProto.m b/submodules/MtProtoKit/Sources/MTProto.m index 62e23fff8b..c0c1d8177b 100644 --- a/submodules/MtProtoKit/Sources/MTProto.m +++ b/submodules/MtProtoKit/Sources/MTProto.m @@ -1726,8 +1726,13 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64; { [[MTProto managerQueue] dispatchOnQueue:^ { - if (transport != _transport || completion == nil) + if (transport != _transport || completion == nil) { return; + } + + if (_useUnauthorizedMode) { + return; + } MTDatacenterAuthKey *authKey = [self getAuthKeyForCurrentScheme:scheme createIfNeeded:false authInfoSelector:nil]; if (authKey == nil) { @@ -2038,11 +2043,18 @@ static NSString *dumpHexString(NSData *data, int maxLength) { - (void)handleMissingKey:(MTTransportScheme *)scheme { NSAssert([[MTProto managerQueue] isCurrentQueue], @"invalid queue"); + if (_useUnauthorizedMode) { + if (MTLogEnabled()) { + MTLog(@"[MTProto#%p@%p don't handleMissingKey when useUnauthorizedMode]", self, _context); + } + return; + } + MTDatacenterAuthInfoSelector authInfoSelector; [self getAuthKeyForCurrentScheme:scheme createIfNeeded:false authInfoSelector:&authInfoSelector]; if (MTLogEnabled()) { - MTLog(@"[MTProto#%p@%p missing key %lld selector]", self, _context, _validAuthInfo.authInfo.authKeyId, authInfoSelector); + MTLog(@"[MTProto#%p@%p missing key %lld selector %d]", self, _context, _validAuthInfo.authInfo.authKeyId, authInfoSelector); } if (_useExplicitAuthKey != nil) { @@ -2618,7 +2630,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) { { [_context setGlobalTimeDifference:timeDifference]; - if (saltList != nil) + if (!_useUnauthorizedMode && saltList != nil) { if (_useExplicitAuthKey) { if (_validAuthInfo != nil && _validAuthInfo.selector == authInfoSelector) { diff --git a/submodules/SyncCore/Sources/NetworkSettings.swift b/submodules/SyncCore/Sources/NetworkSettings.swift index b8341c79fb..94d17222eb 100644 --- a/submodules/SyncCore/Sources/NetworkSettings.swift +++ b/submodules/SyncCore/Sources/NetworkSettings.swift @@ -4,21 +4,27 @@ public struct NetworkSettings: PreferencesEntry, Equatable { public var reducedBackupDiscoveryTimeout: Bool public var applicationUpdateUrlPrefix: String? public var backupHostOverride: String? + public var defaultEnableTempKeys: Bool + public var userEnableTempKeys: Bool? public static var defaultSettings: NetworkSettings { - return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil) + return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil, defaultEnableTempKeys: false, userEnableTempKeys: nil) } - public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?) { + public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?, defaultEnableTempKeys: Bool, userEnableTempKeys: Bool?) { self.reducedBackupDiscoveryTimeout = reducedBackupDiscoveryTimeout self.applicationUpdateUrlPrefix = applicationUpdateUrlPrefix self.backupHostOverride = backupHostOverride + self.defaultEnableTempKeys = defaultEnableTempKeys + self.userEnableTempKeys = userEnableTempKeys } public init(decoder: PostboxDecoder) { self.reducedBackupDiscoveryTimeout = decoder.decodeInt32ForKey("reducedBackupDiscoveryTimeout", orElse: 0) != 0 self.applicationUpdateUrlPrefix = decoder.decodeOptionalStringForKey("applicationUpdateUrlPrefix") self.backupHostOverride = decoder.decodeOptionalStringForKey("backupHostOverride") + self.defaultEnableTempKeys = decoder.decodeBoolForKey("defaultEnableTempKeys", orElse: false) + self.userEnableTempKeys = decoder.decodeOptionalBoolForKey("userEnableTempKeys") } public func encode(_ encoder: PostboxEncoder) { @@ -33,6 +39,12 @@ public struct NetworkSettings: PreferencesEntry, Equatable { } else { encoder.encodeNil(forKey: "backupHostOverride") } + encoder.encodeBool(self.defaultEnableTempKeys, forKey: "defaultEnableTempKeys") + if let userEnableTempKeys = self.userEnableTempKeys { + encoder.encodeBool(userEnableTempKeys, forKey: "userEnableTempKeys") + } else { + encoder.encodeNil(forKey: "userEnableTempKeys") + } } public func isEqual(to: PreferencesEntry) -> Bool { diff --git a/submodules/TelegramCore/Sources/ManagedConfigurationUpdates.swift b/submodules/TelegramCore/Sources/ManagedConfigurationUpdates.swift index 99512d4bf1..39de484df8 100644 --- a/submodules/TelegramCore/Sources/ManagedConfigurationUpdates.swift +++ b/submodules/TelegramCore/Sources/ManagedConfigurationUpdates.swift @@ -35,10 +35,14 @@ func managedConfigurationUpdates(accountManager: AccountManager, postbox: Postbo } let blockedMode = (config.flags & 8) != 0 + + let defaultEnableTempKeys = (config.flags & (1 << 13)) != 0 + updateNetworkSettingsInteractively(transaction: transaction, network: network, { settings in var settings = settings settings.reducedBackupDiscoveryTimeout = blockedMode settings.applicationUpdateUrlPrefix = config.autoupdateUrlPrefix + settings.defaultEnableTempKeys = defaultEnableTempKeys return settings }) diff --git a/submodules/TelegramCore/Sources/Network.swift b/submodules/TelegramCore/Sources/Network.swift index 07355983ed..eebda144d0 100644 --- a/submodules/TelegramCore/Sources/Network.swift +++ b/submodules/TelegramCore/Sources/Network.swift @@ -474,6 +474,17 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa } } + let useTempAuthKeys: Bool + if let networkSettings = networkSettings { + if let userEnableTempKeys = networkSettings.userEnableTempKeys { + useTempAuthKeys = userEnableTempKeys + } else { + useTempAuthKeys = networkSettings.defaultEnableTempKeys + } + } else { + useTempAuthKeys = true + } + var contextValue: MTContext? sharedContexts.with { store in let key = SharedContextStore.Key(accountId: accountId) @@ -483,7 +494,7 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa context = current context.updateApiEnvironment({ _ in return apiEnvironment}) } else { - context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: true)! + context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: useTempAuthKeys)! store.contexts[key] = context } contextValue = context diff --git a/submodules/TelegramCore/Sources/NetworkSettings.swift b/submodules/TelegramCore/Sources/NetworkSettings.swift index 39d2f071c0..8e5f9b27d6 100644 --- a/submodules/TelegramCore/Sources/NetworkSettings.swift +++ b/submodules/TelegramCore/Sources/NetworkSettings.swift @@ -17,7 +17,7 @@ extension NetworkSettings { } } -public func updateNetworkSettingsInteractively(transaction: Transaction, network: Network, _ f: @escaping (NetworkSettings) -> NetworkSettings) { +public func updateNetworkSettingsInteractively(transaction: Transaction, network: Network?, _ f: @escaping (NetworkSettings) -> NetworkSettings) { var updateNetwork = false var updatedSettings: NetworkSettings? transaction.updatePreferencesEntry(key: PreferencesKeys.networkSettings, { current in @@ -33,7 +33,7 @@ public func updateNetworkSettingsInteractively(transaction: Transaction, network return updated }) - if updateNetwork, let updatedSettings = updatedSettings { + if let network = network, updateNetwork, let updatedSettings = updatedSettings { network.context.updateApiEnvironment { current in return current?.withUpdatedNetworkSettings(updatedSettings.mtNetworkSettings) } diff --git a/submodules/TelegramCore/Sources/UpdateMessageService.swift b/submodules/TelegramCore/Sources/UpdateMessageService.swift index bca8a5a76e..32e797fb71 100644 --- a/submodules/TelegramCore/Sources/UpdateMessageService.swift +++ b/submodules/TelegramCore/Sources/UpdateMessageService.swift @@ -58,7 +58,7 @@ class UpdateMessageService: NSObject, MTMessageService { self.putNext(groups) } case let .updateShortChatMessage(flags, id, fromId, chatId, message, pts, ptsCount, date, fwdFrom, viaBotId, replyHeader, entities): - let generatedMessage = Api.Message.message(flags: flags, id: id, fromId: .peerChat(chatId: fromId), peerId: Api.Peer.peerChat(chatId: chatId), fwdFrom: fwdFrom, viaBotId: viaBotId, replyTo: replyHeader, date: date, message: message, media: Api.MessageMedia.messageMediaEmpty, replyMarkup: nil, entities: entities, views: nil, forwards: nil, replies: nil, editDate: nil, postAuthor: nil, groupedId: nil, restrictionReason: nil) + let generatedMessage = Api.Message.message(flags: flags, id: id, fromId: .peerUser(userId: fromId), peerId: Api.Peer.peerChat(chatId: chatId), fwdFrom: fwdFrom, viaBotId: viaBotId, replyTo: replyHeader, date: date, message: message, media: Api.MessageMedia.messageMediaEmpty, replyMarkup: nil, entities: entities, views: nil, forwards: nil, replies: nil, editDate: nil, postAuthor: nil, groupedId: nil, restrictionReason: nil) let update = Api.Update.updateNewMessage(message: generatedMessage, pts: pts, ptsCount: ptsCount) let groups = groupUpdates([update], users: [], chats: [], date: date, seqRange: nil) if groups.count != 0 {