Fix backup address fetch keychain sharing

This commit is contained in:
Peter 2018-12-19 19:50:50 +03:00
parent cc97fc2fa2
commit a7e2581217
2 changed files with 28 additions and 28 deletions

View File

@ -145,7 +145,7 @@ static NSData *base64_decode(NSString *str) {
MTContext *context = [[MTContext alloc] initWithSerialization:currentContext.serialization apiEnvironment:apiEnvironment isTestingEnvironment:currentContext.isTestingEnvironment useTempAuthKeys:address.datacenterId != 0 ? currentContext.useTempAuthKeys : false]; MTContext *context = [[MTContext alloc] initWithSerialization:currentContext.serialization apiEnvironment:apiEnvironment isTestingEnvironment:currentContext.isTestingEnvironment useTempAuthKeys:address.datacenterId != 0 ? currentContext.useTempAuthKeys : false];
if (address.datacenterId != 0) { if (address.datacenterId != 0) {
context.keychain = currentContext.keychain; //context.keychain = currentContext.keychain;
} }
MTProto *mtProto = [[MTProto alloc] initWithContext:context datacenterId:address.datacenterId usageCalculationInfo:nil]; MTProto *mtProto = [[MTProto alloc] initWithContext:context datacenterId:address.datacenterId usageCalculationInfo:nil];

View File

@ -194,7 +194,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
if ((_mtState & MTProtoStatePaused) == 0) if ((_mtState & MTProtoStatePaused) == 0)
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p pause]", self); MTLog(@"[MTProto#%p@%p pause]", self, _context);
} }
_mtState |= MTProtoStatePaused; _mtState |= MTProtoStatePaused;
@ -212,7 +212,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
if (_mtState & MTProtoStatePaused) if (_mtState & MTProtoStatePaused)
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p resume]", self); MTLog(@"[MTProto#%p@%p resume]", self, _context);
} }
[self setMtState:_mtState & (~MTProtoStatePaused)]; [self setMtState:_mtState & (~MTProtoStatePaused)];
@ -265,7 +265,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
[[MTProto managerQueue] dispatchOnQueue:^ [[MTProto managerQueue] dispatchOnQueue:^
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p changing transport %@#%p to %@#%p]", self, [_transport class] == nil ? @"" : NSStringFromClass([_transport class]), _transport, [transport class] == nil ? @"" : NSStringFromClass([transport class]), transport); MTLog(@"[MTProto#%p@%p changing transport %@#%p to %@#%p]", self, _context, [_transport class] == nil ? @"" : NSStringFromClass([_transport class]), _transport, [transport class] == nil ? @"" : NSStringFromClass([transport class]), transport);
} }
[self allTransactionsMayHaveFailed]; [self allTransactionsMayHaveFailed];
@ -336,13 +336,13 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
} }
} else if (!_useUnauthorizedMode && [_context authInfoForDatacenterWithId:_datacenterId] == nil) { } else if (!_useUnauthorizedMode && [_context authInfoForDatacenterWithId:_datacenterId] == nil) {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p authInfoForDatacenterWithId:%d is nil]", self, _datacenterId); MTLog(@"[MTProto#%p@%p authInfoForDatacenterWithId:%d is nil]", self, _context, _datacenterId);
} }
if ((_mtState & MTProtoStateAwaitingDatacenterAuthorization) == 0) { if ((_mtState & MTProtoStateAwaitingDatacenterAuthorization) == 0) {
[self setMtState:_mtState | MTProtoStateAwaitingDatacenterAuthorization]; [self setMtState:_mtState | MTProtoStateAwaitingDatacenterAuthorization];
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p requesting authInfo for %d]", self, _datacenterId); MTLog(@"[MTProto#%p@%p requesting authInfo for %d]", self, _context, _datacenterId);
} }
[_context authInfoForDatacenterWithIdRequired:_datacenterId isCdn:_cdn]; [_context authInfoForDatacenterWithIdRequired:_datacenterId isCdn:_cdn];
} }
@ -375,7 +375,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
[[MTProto managerQueue] dispatchOnQueue:^ [[MTProto managerQueue] dispatchOnQueue:^
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p resetting session]", self); MTLog(@"[MTProto#%p@%p resetting session]", self, _context);
} }
if (_authInfo.authKeyId != 0 && !self.cdn) { if (_authInfo.authKeyId != 0 && !self.cdn) {
@ -424,7 +424,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
if (!alreadySyncing) if (!alreadySyncing)
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p begin time sync]", self); MTLog(@"[MTProto#%p@%p begin time sync]", self, _context);
} }
MTTimeSyncMessageService *timeSyncService = [[MTTimeSyncMessageService alloc] init]; MTTimeSyncMessageService *timeSyncService = [[MTTimeSyncMessageService alloc] init];
@ -456,7 +456,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
} }
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p service tasks state: %d, resend: %s]", self, _mtState, haveResendMessagesPending ? "yes" : "no"); MTLog(@"[MTProto#%p@%p service tasks state: %d, resend: %s]", self, _context, _mtState, haveResendMessagesPending ? "yes" : "no");
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -506,7 +506,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
if (notifyAboutServiceTask) if (notifyAboutServiceTask)
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p service tasks state: %d, resend: %s]", self, _mtState, "yes"); MTLog(@"[MTProto#%p@%p service tasks state: %d, resend: %s]", self, _context, _mtState, "yes");
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -558,7 +558,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
if (!performingServiceTasks) if (!performingServiceTasks)
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p service tasks state: %d, resend: %s]", self, _mtState, "no"); MTLog(@"[MTProto#%p@%p service tasks state: %d, resend: %s]", self, _context, _mtState, "no");
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -724,7 +724,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
return; return;
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p network state: %s]", self, isNetworkAvailable ? "available" : "waiting"); MTLog(@"[MTProto#%p@%p network state: %s]", self, _context, isNetworkAvailable ? "available" : "waiting");
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -755,7 +755,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
return; return;
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p transport #%p connection state: %s]", self, transport, isConnected ? "connected" : "connecting"); MTLog(@"[MTProto#%p@%p transport #%p connection state: %s]", self, _context, transport, isConnected ? "connected" : "connecting");
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -782,7 +782,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
return; return;
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p connection context update state: %s]", self, isUpdatingConnectionContext ? "updating" : "up to date"); MTLog(@"[MTProto#%p@%p connection context update state: %s]", self, _context, isUpdatingConnectionContext ? "updating" : "up to date");
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -1011,7 +1011,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
debugResetTransport = true; debugResetTransport = true;
} }
}*/ }*/
MTLog(@"[MTProto#%p preparing %@]", self, messageDescription); MTLog(@"[MTProto#%p@%p preparing %@]", self, _context, messageDescription);
} }
if (!monotonityViolated || _useUnauthorizedMode) if (!monotonityViolated || _useUnauthorizedMode)
@ -1055,7 +1055,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
if (monotonityViolated) if (monotonityViolated)
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p client message id monotonity violated]", self); MTLog(@"[MTProto#%p@%p client message id monotonity violated]", self, _context);
} }
[self resetSessionInfo]; [self resetSessionInfo];
@ -1242,7 +1242,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
} }
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p transport did not accept transactions with messages (%@)]", self, idsString); MTLog(@"[MTProto#%p@%p transport did not accept transactions with messages (%@)]", self, _context, idsString);
} }
} }
}]; }];
@ -1298,7 +1298,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
MTOutputStream *decryptedOs = [[MTOutputStream alloc] init]; MTOutputStream *decryptedOs = [[MTOutputStream alloc] init];
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%x sending time fix ping (%" PRId64 "/%" PRId32 ", %" PRId64 ")]", self, timeFixMessageId, timeFixSeqNo, _sessionInfo.sessionId); MTLog(@"[MTProto#%p@%p sending time fix ping (%" PRId64 "/%" PRId32 ", %" PRId64 ")]", self, _context, timeFixMessageId, timeFixSeqNo, _sessionInfo.sessionId);
} }
[decryptedOs writeInt64:[_authInfo authSaltForMessageId:timeFixMessageId]]; // salt [decryptedOs writeInt64:[_authInfo authSaltForMessageId:timeFixMessageId]]; // salt
@ -1423,7 +1423,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
MTOutputStream *decryptedOs = [[MTOutputStream alloc] init]; MTOutputStream *decryptedOs = [[MTOutputStream alloc] init];
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%llx sending temp key binding message (%" PRId64 "/%" PRId32 ") for %lld (%d)]", self, bindingMessageId, bindingSeqNo, effectiveTempAuthKey.authKeyId, (int)tempAuthKeyType); MTLog(@"[MTProto#%p@%p sending temp key binding message (%" PRId64 "/%" PRId32 ") for %lld (%d)]", self, _context, bindingMessageId, bindingSeqNo, effectiveTempAuthKey.authKeyId, (int)tempAuthKeyType);
} }
[decryptedOs writeInt64:[_authInfo authSaltForMessageId:bindingMessageId]]; [decryptedOs writeInt64:[_authInfo authSaltForMessageId:bindingMessageId]];
@ -2030,7 +2030,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
[data getBytes:&protocolErrorCode range:NSMakeRange(0, 4)]; [data getBytes:&protocolErrorCode range:NSMakeRange(0, 4)];
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p protocol error %" PRId32 "", self, protocolErrorCode); MTLog(@"[MTProto#%p@%p protocol error %" PRId32 "", self, _context, protocolErrorCode);
} }
if (decodeResult != nil) if (decodeResult != nil)
@ -2081,7 +2081,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
MTRpcError *rpcError = maybeInternalMessage; MTRpcError *rpcError = maybeInternalMessage;
if (rpcError.errorCode == 401 && [rpcError.errorDescription isEqualToString:@"AUTH_KEY_PERM_EMPTY"]) { if (rpcError.errorCode == 401 && [rpcError.errorDescription isEqualToString:@"AUTH_KEY_PERM_EMPTY"]) {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p received AUTH_KEY_PERM_EMPTY]", self); MTLog(@"[MTProto#%p@%p received AUTH_KEY_PERM_EMPTY]", self, _context);
} }
[self handleMissingKey:scheme.address]; [self handleMissingKey:scheme.address];
[self requestSecureTransportReset]; [self requestSecureTransportReset];
@ -2093,7 +2093,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
} }
if (parseError) { if (parseError) {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p incoming data parse error, header: %d:%@]", self, (int)decryptedData.length, dumpHexString(decryptedData, 128)); MTLog(@"[MTProto#%p@%p incoming data parse error, header: %d:%@]", self, _context, (int)decryptedData.length, dumpHexString(decryptedData, 128));
} }
[_context reportTransportSchemeFailureForDatacenterId:_datacenterId transportScheme:scheme]; [_context reportTransportSchemeFailureForDatacenterId:_datacenterId transportScheme:scheme];
@ -2114,7 +2114,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
} }
} else { } else {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p couldn't decrypt incoming data]", self); MTLog(@"[MTProto#%p@%p couldn't decrypt incoming data]", self, _context);
} }
if (decodeResult != nil) if (decodeResult != nil)
@ -2396,7 +2396,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
if ([_sessionInfo messageProcessed:incomingMessage.messageId]) if ([_sessionInfo messageProcessed:incomingMessage.messageId])
{ {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p received duplicate message %" PRId64 "]", self, incomingMessage.messageId); MTLog(@"[MTProto#%p@%p received duplicate message %" PRId64 "]", self, _context, incomingMessage.messageId);
} }
[_sessionInfo scheduleMessageConfirmation:incomingMessage.messageId size:incomingMessage.size]; [_sessionInfo scheduleMessageConfirmation:incomingMessage.messageId size:incomingMessage.size];
@ -2407,7 +2407,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
} }
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p [%d] received %@]", self, totalSize, [self incomingMessageDescription:incomingMessage]); MTLog(@"[MTProto#%p@%p [%d] received %@]", self, _context, totalSize, [self incomingMessageDescription:incomingMessage]);
} }
[_sessionInfo setMessageProcessed:incomingMessage.messageId]; [_sessionInfo setMessageProcessed:incomingMessage.messageId];
@ -2527,7 +2527,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
int64_t requestMessageId = ((MTMsgDetailedResponseInfoMessage *)detailedInfoMessage).requestMessageId; int64_t requestMessageId = ((MTMsgDetailedResponseInfoMessage *)detailedInfoMessage).requestMessageId;
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p detailed info %" PRId64 " is for %" PRId64 "", self, incomingMessage.messageId, requestMessageId); MTLog(@"[MTProto#%p@%p detailed info %" PRId64 " is for %" PRId64 "", self, _context, incomingMessage.messageId, requestMessageId);
} }
for (id<MTMessageService> messageService in _messageServices) for (id<MTMessageService> messageService in _messageServices)
@ -2549,7 +2549,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
{ {
[self requestMessageWithId:detailedInfoMessage.responseMessageId]; [self requestMessageWithId:detailedInfoMessage.responseMessageId];
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p will request message %" PRId64 "", self, detailedInfoMessage.responseMessageId); MTLog(@"[MTProto#%p@%p will request message %" PRId64 "", self, _context, detailedInfoMessage.responseMessageId);
} }
} }
else else
@ -2637,7 +2637,7 @@ static NSString *dumpHexString(NSData *data, int maxLength) {
} }
} else { } else {
if (MTLogEnabled()) { if (MTLogEnabled()) {
MTLog(@"[MTProto#%p bindTempAuthKey error %@]", self, rpcError); MTLog(@"[MTProto#%p@%p bindTempAuthKey error %@]", self, _context, rpcError);
} }
[self requestTransportTransaction]; [self requestTransportTransaction];