Revert "Sync local profile key after rotating it."

This reverts commit ddbd20e706.
This commit is contained in:
Matthew Chen 2018-10-18 16:00:48 -04:00
parent ddbd20e706
commit 693b3e13a9
17 changed files with 178 additions and 120 deletions

View file

@ -295,6 +295,7 @@
450DF2051E0D74AC003D14BE /* Platform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450DF2041E0D74AC003D14BE /* Platform.swift */; };
450DF2091E0DD2C6003D14BE /* UserNotificationsAdaptee.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450DF2081E0DD2C6003D14BE /* UserNotificationsAdaptee.swift */; };
451166C01FD86B98000739BA /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451166BF1FD86B98000739BA /* AccountManager.swift */; };
451686AB1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451686AA1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift */; };
4517642B1DE939FD00EDB8B9 /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 451764291DE939FD00EDB8B9 /* ContactCell.swift */; };
45194F8F1FD71FF500333B2C /* ThreadUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129BE1FD2068600532771 /* ThreadUtil.m */; };
45194F901FD7200000333B2C /* ThreadUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129BD1FD2068600532771 /* ThreadUtil.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -978,6 +979,7 @@
450DF2041E0D74AC003D14BE /* Platform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Platform.swift; sourceTree = "<group>"; };
450DF2081E0DD2C6003D14BE /* UserNotificationsAdaptee.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = UserNotificationsAdaptee.swift; path = UserInterface/Notifications/UserNotificationsAdaptee.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
451166BF1FD86B98000739BA /* AccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountManager.swift; sourceTree = "<group>"; };
451686AA1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultiDeviceProfileKeyUpdateJob.swift; sourceTree = "<group>"; };
451764291DE939FD00EDB8B9 /* ContactCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactCell.swift; sourceTree = "<group>"; };
451777C71FD61554001225FF /* ConversationSearcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversationSearcher.swift; sourceTree = "<group>"; };
451A13B01E13DED2000A50FD /* CallNotificationsAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = CallNotificationsAdapter.swift; path = ../UserInterface/Notifications/CallNotificationsAdapter.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
@ -2099,6 +2101,7 @@
45D231761DC7E8F10034FA89 /* SessionResetJob.swift */,
45CD81EE1DC030E7004C9430 /* SyncPushTokensJob.swift */,
452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */,
451686AA1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift */,
4CC0B59B20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift */,
);
path = Jobs;
@ -3336,6 +3339,7 @@
34D1F0AE1F867BFC0066283D /* OWSMessageCell.m in Sources */,
4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */,
4CB5F26720F6E1E2004D1B42 /* MenuActionsViewController.swift in Sources */,
451686AB1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift in Sources */,
45D231771DC7E8F10034FA89 /* SessionResetJob.swift in Sources */,
340FC8A9204DAC8D007AEB0F /* NotificationSettingsOptionsViewController.m in Sources */,
452037D11EE84975004E4CDF /* DebugUISessionState.m in Sources */,

View file

@ -23,8 +23,12 @@ class ConversationConfigurationSyncOperation: OWSOperation {
return Environment.shared.contactsManager
}
private var syncManager: OWSSyncManagerProtocol {
return SSKEnvironment.shared.syncManager
private var profileManager: OWSProfileManager {
return OWSProfileManager.shared()
}
private var identityManager: OWSIdentityManager {
return OWSIdentityManager.shared()
}
private let thread: TSThread
@ -56,7 +60,25 @@ class ConversationConfigurationSyncOperation: OWSOperation {
return
}
syncManager.syncContacts(for: [signalAccount])
let syncMessage: OWSSyncContactsMessage = OWSSyncContactsMessage(signalAccounts: [signalAccount],
identityManager: self.identityManager,
profileManager: self.profileManager)
var dataSource: DataSource?
self.dbConnection.readWrite { transaction in
guard let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFailDebug("could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
}
guard let attachmentDataSource = dataSource else {
self.reportAssertionError(description: "unable to build attachment data source")
return
}
self.sendConfiguration(attachmentDataSource: attachmentDataSource, syncMessage: syncMessage)
}
private func sync(groupThread: TSGroupThread) {

View file

@ -0,0 +1,76 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
import PromiseKit
import SignalServiceKit
import SignalMessaging
/**
* Used to distribute our profile key to legacy linked devices, newly linked devices will have our profile key as part of provisioning.
* Syncing is accomplished via the existing contact syncing mechanism, except the only contact synced is ourself. It's incumbent on the linked device
* to treat this "self contact" record specially.
*/
@objc public class MultiDeviceProfileKeyUpdateJob: NSObject {
private let profileKey: OWSAES256Key
private let identityManager: OWSIdentityManager
private let messageSender: MessageSender
private let profileManager: OWSProfileManager
private var editingDatabaseConnection: YapDatabaseConnection {
return OWSPrimaryStorage.shared().dbReadWriteConnection
}
@objc public required init(profileKey: OWSAES256Key, identityManager: OWSIdentityManager, messageSender: MessageSender, profileManager: OWSProfileManager) {
self.profileKey = profileKey
self.identityManager = identityManager
self.messageSender = messageSender
self.profileManager = profileManager
}
@objc public class func run(profileKey: OWSAES256Key, identityManager: OWSIdentityManager, messageSender: MessageSender, profileManager: OWSProfileManager) {
return self.init(profileKey: profileKey, identityManager: identityManager, messageSender: messageSender, profileManager: profileManager).run()
}
func run(retryDelay: TimeInterval = 1) {
guard let localNumber = TSAccountManager.localNumber() else {
owsFailDebug("localNumber was unexpectedly nil")
return
}
let localSignalAccount = SignalAccount(recipientId: localNumber)
localSignalAccount.contact = Contact()
let syncContactsMessage = OWSSyncContactsMessage(signalAccounts: [localSignalAccount],
identityManager: self.identityManager,
profileManager: self.profileManager)
var dataSource: DataSource?
self.editingDatabaseConnection.readWrite { transaction in
guard let messageData: Data = syncContactsMessage.buildPlainTextAttachmentData(with: transaction) else {
owsFailDebug("could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
}
guard let attachmentDataSource = dataSource else {
owsFailDebug("dataSource was unexpectedly nil")
return
}
self.messageSender.enqueueTemporaryAttachment(attachmentDataSource,
contentType: OWSMimeTypeApplicationOctetStream,
in: syncContactsMessage,
success: {
Logger.info("Successfully synced profile key")
},
failure: { error in
Logger.error("failed with error: \(error) retrying in \(retryDelay)s.")
after(seconds: retryDelay).done {
self.run(retryDelay: retryDelay * 2)
}.retainUntilComplete()
})
}
}

View file

@ -104,6 +104,7 @@
#import <SignalServiceKit/OWSRecipientIdentity.h>
#import <SignalServiceKit/OWSRequestFactory.h>
#import <SignalServiceKit/OWSSignalService.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
#import <SignalServiceKit/PhoneNumber.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/SignalRecipient.h>

View file

@ -17,6 +17,7 @@
#import <SignalServiceKit/OWSPrimaryStorage+SessionStore.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/OWSReadReceiptManager.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
#import <SignalServiceKit/OWSSyncGroupsMessage.h>
#import <SignalServiceKit/OWSSyncGroupsRequestMessage.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
@ -90,14 +91,28 @@ NS_ASSUME_NONNULL_BEGIN
return [OWSPrimaryStorage.sharedManager newDatabaseConnection];
}
+ (id<OWSSyncManagerProtocol>)syncManager {
OWSAssertDebug(SSKEnvironment.shared.syncManager);
+ (void)sendContactsSyncMessage
{
OWSSyncContactsMessage *syncContactsMessage =
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
identityManager:self.identityManager
profileManager:self.profileManager];
__block DataSource *dataSource;
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncContactsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]];
}];
return SSKEnvironment.shared.syncManager;
}
+ (void)sendContactsSyncMessage {
[self.syncManager syncAllContacts];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage
success:^{
OWSLogInfo(@"Successfully sent Contacts response syncMessage.");
}
failure:^(NSError *error) {
OWSLogError(@"Failed to send Contacts response syncMessage with error: %@", error);
}];
}
+ (void)sendGroupSyncMessage

View file

@ -220,6 +220,16 @@ NS_ASSUME_NONNULL_BEGIN
}];
}
- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey
{
OWSAssertDebug(profileKey);
[MultiDeviceProfileKeyUpdateJob runWithProfileKey:profileKey
identityManager:OWSIdentityManager.sharedManager
messageSender:SSKEnvironment.shared.messageSender
profileManager:OWSProfileManager.sharedManager];
}
- (BOOL)isRunningTests
{
return getenv("runningTests_dontStartApp");

View file

@ -6,7 +6,6 @@
NS_ASSUME_NONNULL_BEGIN
@class AnyPromise;
@class OWSContactsManager;
@class OWSIdentityManager;
@class OWSMessageSender;

View file

@ -8,7 +8,6 @@
#import "OWSPreferences.h"
#import "OWSProfileManager.h"
#import "OWSReadReceiptManager.h"
#import <PromiseKit/AnyPromise.h>
#import <SignalServiceKit/AppReadiness.h>
#import <SignalServiceKit/DataSource.h>
#import <SignalServiceKit/MIMETypeUtil.h>
@ -17,8 +16,6 @@
#import <SignalServiceKit/OWSSyncConfigurationMessage.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
#import <SignalServiceKit/SSKEnvironment.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
@ -94,10 +91,6 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
return SSKEnvironment.shared.profileManager;
}
- (TSAccountManager *)tsAccountManager {
return TSAccountManager.sharedInstance;
}
#pragma mark - Notifications
- (void)signalAccountsDidChange:(id)notification {
@ -222,49 +215,6 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
}];
}
#pragma mark - Local Sync
- (AnyPromise *)syncLocalContact {
NSString *localNumber = self.tsAccountManager.localNumber;
SignalAccount *signalAccount = [[SignalAccount alloc] initWithRecipientId:localNumber];
signalAccount.contact = [Contact new];
return [self syncContactsForSignalAccounts:@[ signalAccount ]];
}
- (AnyPromise *)syncAllContacts {
return [self syncContactsForSignalAccounts:self.contactsManager.signalAccounts];
}
- (AnyPromise *)syncContactsForSignalAccounts:(NSArray<SignalAccount *> *)signalAccounts {
OWSSyncContactsMessage *syncContactsMessage =
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:signalAccounts
identityManager:self.identityManager
profileManager:self.profileManager];
__block DataSource *dataSource;
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
dataSource = [DataSourceValue
dataSourceWithSyncMessageData:[syncContactsMessage
buildPlainTextAttachmentDataWithTransaction:transaction]];
}];
AnyPromise *promise = [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage
success:^{
OWSLogInfo(@"Successfully sent contacts sync message.");
resolve(@(1));
}
failure:^(NSError *error) {
OWSLogError(@"Failed to send contacts sync message with error: %@", error);
resolve(error);
}];
}];
[promise retainUntilComplete];
return promise;
}
@end
NS_ASSUME_NONNULL_END

View file

@ -150,10 +150,6 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
return SSKEnvironment.shared.blockingManager;
}
- (id<OWSSyncManagerProtocol>)syncManager {
return SSKEnvironment.shared.syncManager;
}
#pragma mark - User Profile Accessor
- (void)ensureLocalProfileCached
@ -744,13 +740,8 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
// Fetch local profile.
promise = promise.then(^(id value) {
[self fetchLocalUsersProfile];
return @(1);
});
// Sync local profile key.
promise = promise.then(^(id value) {
return [self.syncManager syncLocalContact];
return @(1);
});
promise = promise.then(^(id value) {

View file

@ -10,7 +10,6 @@
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/SSKEnvironment.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <YapDatabase/YapDatabaseConnection.h>
#import <YapDatabase/YapDatabaseTransaction.h>
@ -98,15 +97,6 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
return self;
}
#pragma mark - Dependencies
- (id<OWSSyncManagerProtocol>)syncManager {
return SSKEnvironment.shared.syncManager;
}
#pragma mark -
- (nullable NSString *)avatarUrlPath
{
@synchronized(self)
@ -219,8 +209,8 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
// We populate an initial (empty) profile on launch of a new install, but until
// we have a registered account, syncing will fail (and there could not be any
// linked device to sync to at this point anyway).
if ([TSAccountManager isRegistered] && CurrentAppContext().isMainApp) {
[self.syncManager syncLocalContact];
if ([TSAccountManager isRegistered]) {
[CurrentAppContext() doMultiDeviceUpdateWithProfileKey:self.profileKey];
}
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_LocalProfileDidChange

View file

@ -27,6 +27,7 @@
#import "OWSPrimaryStorage.h"
#import "OWSReadReceiptManager.h"
#import "OWSRecordTranscriptJob.h"
#import "OWSSyncContactsMessage.h"
#import "OWSSyncGroupsMessage.h"
#import "OWSSyncGroupsRequestMessage.h"
#import "ProfileManagerProtocol.h"
@ -138,12 +139,6 @@ NS_ASSUME_NONNULL_BEGIN
return SSKEnvironment.shared.outgoingReceiptManager;
}
- (id<OWSSyncManagerProtocol>)syncManager {
OWSAssertDebug(SSKEnvironment.shared.syncManager);
return SSKEnvironment.shared.syncManager;
}
#pragma mark -
- (void)startObserving
@ -809,7 +804,28 @@ NS_ASSUME_NONNULL_BEGIN
// In rare cases this means we won't respond to the sync request, but that's
// acceptable.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.syncManager syncAllContacts];
OWSSyncContactsMessage *syncContactsMessage =
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
identityManager:self.identityManager
profileManager:self.profileManager];
__block NSData *_Nullable syncData;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
syncData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
}];
if (!syncData) {
OWSFailDebug(@"Failed to serialize contacts sync message.");
return;
}
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:syncData];
[self.messageSender enqueueTemporaryAttachment:dataSource
contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncContactsMessage
success:^{
OWSLogInfo(@"Successfully sent Contacts response syncMessage.");
}
failure:^(NSError *error) {
OWSLogError(@"Failed to send Contacts response syncMessage with error: %@", error);
}];
});
} else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeGroups) {
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];

View file

@ -2,8 +2,6 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSSyncManagerProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@class ContactDiscoveryService;
@ -30,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol OWSCallMessageHandler;
@protocol ProfileManagerProtocol;
@protocol OWSUDManager;
@protocol OWSSyncManagerProtocol;
@interface SSKEnvironment : NSObject

View file

@ -3,7 +3,6 @@
//
import Foundation
import PromiseKit
#if DEBUG
@ -13,24 +12,6 @@ public class OWSMockSyncManager: NSObject, OWSSyncManagerProtocol {
@objc public func sendConfigurationSyncMessage() {
Logger.info("")
}
@objc public func syncLocalContact() -> AnyPromise {
Logger.info("")
return AnyPromise()
}
@objc public func syncAllContacts() -> AnyPromise {
Logger.info("")
return AnyPromise()
}
@objc public func syncContacts(for signalAccounts: [SignalAccount]) -> AnyPromise {
Logger.info("")
return AnyPromise()
}
}
#endif

View file

@ -112,6 +112,10 @@ NS_ASSUME_NONNULL_BEGIN
return nil;
}
- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey
{
}
- (BOOL)isRunningTests
{
return YES;

View file

@ -87,6 +87,10 @@ NSString *NSStringForUIApplicationState(UIApplicationState value);
// Returns nil if isMainApp is NO
@property (nullable, nonatomic, readonly) UIAlertAction *openSystemSettingsAction;
// Should only be called if isMainApp is YES,
// but should only be necessary to call if isMainApp is YES.
- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey;
// Should be a NOOP if isMainApp is NO.
- (void)setNetworkActivityIndicatorVisible:(BOOL)value;

View file

@ -4,19 +4,10 @@
NS_ASSUME_NONNULL_BEGIN
@class AnyPromise;
@class SignalAccount;
@protocol OWSSyncManagerProtocol <NSObject>
- (void)sendConfigurationSyncMessage;
- (AnyPromise *)syncLocalContact;
- (AnyPromise *)syncAllContacts;
- (AnyPromise *)syncContactsForSignalAccounts:(NSArray<SignalAccount *> *)signalAccounts;
@end
NS_ASSUME_NONNULL_END

View file

@ -193,6 +193,11 @@ NS_ASSUME_NONNULL_BEGIN
return nil;
}
- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey
{
OWSFailDebug(@"");
}
- (BOOL)isRunningTests
{
// We don't need to distinguish this in the SAE.