mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-31 07:30:40 +00:00
Merge branch 'beta'
This commit is contained in:
commit
4ed47db191
2
Makefile
2
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)
|
||||
|
||||
|
@ -180,7 +180,6 @@
|
||||
- (void)cancel
|
||||
{
|
||||
[self cleanup];
|
||||
[self fail];
|
||||
}
|
||||
|
||||
- (void)complete {
|
||||
|
@ -109,9 +109,9 @@ static NSDictionary *selectPublicKey(NSArray *fingerprints, NSArray<NSDictionary
|
||||
{
|
||||
for (NSDictionary *keyDesc in publicKeys)
|
||||
{
|
||||
int64_t keyFingerprint = [[keyDesc objectForKey:@"fingerprint"] longLongValue];
|
||||
uint64_t keyFingerprint = [[keyDesc objectForKey:@"fingerprint"] unsignedLongLongValue];
|
||||
|
||||
if ([nFingerprint longLongValue] == keyFingerprint)
|
||||
if ([nFingerprint unsignedLongLongValue] == keyFingerprint)
|
||||
return keyDesc;
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,6 @@ typedef enum {
|
||||
id<EncryptionProvider> _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];
|
||||
|
@ -292,12 +292,13 @@ NSData *MTAesDecrypt(NSData *data, NSData *key, NSData *iv)
|
||||
NSData *MTRsaEncrypt(id<EncryptionProvider> 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
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
})
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user