From 59fc23212897a5f822d29fea08f7a3fb3f26fe74 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Mar 2018 12:49:20 -0300 Subject: [PATCH] Backup export needs to verify that we have a valid account. --- Signal/src/util/OWSBackupExportJob.m | 53 +++++++++++----------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/Signal/src/util/OWSBackupExportJob.m b/Signal/src/util/OWSBackupExportJob.m index 59fd7438f..3a831c4cb 100644 --- a/Signal/src/util/OWSBackupExportJob.m +++ b/Signal/src/util/OWSBackupExportJob.m @@ -187,41 +187,28 @@ NSString *const kOWSBackup_ExportDatabaseKeySpec = @"kOWSBackup_ExportDatabaseKe OWSProdLogAndFail(@"%@ Could not create jobTempDirPath.", self.logTag); return completion(NO); } - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - completion(YES); - }); - // TSRequest *currentSignedPreKey = [OWSRequestFactory currentSignedPreKeyRequest]; - // [[TSNetworkManager sharedManager] makeRequest:currentSignedPreKey - // success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) { - // NSString *keyIdDictKey = @"keyId"; - // NSNumber *keyId = [responseObject objectForKey:keyIdDictKey]; - // OWSAssert(keyId); - // - // OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage - // sharedManager]; NSNumber *currentSignedPrekeyId = [primaryStorage - // currentSignedPrekeyId]; - // - // if (!keyId || !currentSignedPrekeyId || ![currentSignedPrekeyId - // isEqualToNumber:keyId]) { - // DDLogError( - // @"%@ Local and service 'current signed prekey ids' - // did not match. %@ == %@ == %d.", self.logTag, keyId, - // currentSignedPrekeyId, - // [currentSignedPrekeyId isEqualToNumber:keyId]); - // } - // } - // failure:^(NSURLSessionDataTask *task, NSError *error) { - // if (!IsNSErrorNetworkFailure(error)) { - // OWSProdError([OWSAnalyticsEvents - // errorPrekeysCurrentSignedPrekeyRequestFailed]); - // } - // DDLogWarn(@"%@ Could not retrieve current signed key from the - // service.", self.logTag); + // We need to verify that we have a valid account. + // Otherwise, if we re-register on another device, we + // continue to backup on our old device, overwriting + // backups from the new device. // - // // Mark the prekeys as _NOT_ checked on failure. - // [self markPreKeysAsNotChecked]; - // }]; + // We use an arbitrary request that requires authentication + // to verify our account state. + TSRequest *currentSignedPreKey = [OWSRequestFactory currentSignedPreKeyRequest]; + [[TSNetworkManager sharedManager] makeRequest:currentSignedPreKey + success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + completion(YES); + }); + } + failure:^(NSURLSessionDataTask *task, NSError *error) { + // TODO: We may want to surface this in the UI. + DDLogError(@"%@ could not verify account status: %@.", self.logTag, error); + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + completion(NO); + }); + }]; } - (void)exportDatabase:(OWSBackupJobBoolCompletion)completion