Send any profile key in contact sync

// FREEBIE
This commit is contained in:
Michael Kirk 2017-08-25 17:16:49 -04:00
parent f0a57edde0
commit 1f3d2d1ed6
10 changed files with 50 additions and 14 deletions

View File

@ -152,7 +152,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment getCurrent].contactsManager
identityManager:[OWSIdentityManager sharedManager]
messageSender:[Environment getCurrent].messageSender];
messageSender:[Environment getCurrent].messageSender
profileManager:[OWSProfileManager sharedManager]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(databaseViewRegistrationComplete)

View File

@ -919,6 +919,11 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
});
}
- (nullable NSData *)profileKeyDataForRecipientId:(NSString *)recipientId
{
return [self profileKeyForRecipientId:recipientId].keyData;
}
- (nullable OWSAES256Key *)profileKeyForRecipientId:(NSString *)recipientId
{
OWSAssert(recipientId.length > 0);

View File

@ -9,12 +9,14 @@ NS_ASSUME_NONNULL_BEGIN
@class OWSContactsManager;
@class OWSMessageSender;
@class OWSIdentityManager;
@class OWSProfileManager;
@interface OWSContactsSyncing : NSObject
- (instancetype)initWithContactsManager:(OWSContactsManager *)contactsManager
identityManager:(OWSIdentityManager *)identityManager
messageSender:(OWSMessageSender *)messageSender;
messageSender:(OWSMessageSender *)messageSender
profileManager:(OWSProfileManager *)profileManager;
@end

View File

@ -4,6 +4,7 @@
#import "OWSContactsSyncing.h"
#import "OWSContactsManager.h"
#import "OWSProfileManager.h"
#import "TSAccountManager.h"
#import <SignalServiceKit/MIMETypeUtil.h>
#import <SignalServiceKit/OWSMessageSender.h>
@ -24,6 +25,7 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) OWSProfileManager *profileManager;
@property (nonatomic) BOOL isRequestInFlight;
@ -34,6 +36,7 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
- (instancetype)initWithContactsManager:(OWSContactsManager *)contactsManager
identityManager:(OWSIdentityManager *)identityManager
messageSender:(OWSMessageSender *)messageSender
profileManager:(OWSProfileManager *)profileManager
{
self = [super init];
@ -48,6 +51,7 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
_contactsManager = contactsManager;
_identityManager = identityManager;
_messageSender = messageSender;
_profileManager = profileManager;
OWSSingletonAssert();
@ -91,7 +95,8 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
}
OWSSyncContactsMessage *syncContactsMessage = [[OWSSyncContactsMessage alloc] initWithContactsManager:self.contactsManager
identityManager:self.identityManager];
identityManager:self.identityManager
profileManager:self.profileManager];
NSData *messageData = [syncContactsMessage buildPlainTextAttachmentData];

View File

@ -12,7 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSContactsOutputStream : OWSChunkedOutputStream
- (void)writeSignalAccount:(SignalAccount *)signalAccount
recipientIdentity:(nullable OWSRecipientIdentity *)recipientIdentity;
recipientIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
profileKeyData:(nullable NSData *)profileKeyData;
@end

View File

@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)writeSignalAccount:(SignalAccount *)signalAccount
recipientIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
profileKeyData:(nullable NSData *)profileKeyData
{
OWSAssert(signalAccount);
OWSAssert(signalAccount.contact);
@ -44,6 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
[contactBuilder setAvatarBuilder:avatarBuilder];
}
if (profileKeyData) {
[contactBuilder setProfileKey:profileKeyData];
}
NSData *contactData = [[contactBuilder build] data];
uint32_t contactDataLength = (uint32_t)contactData.length;

View File

@ -6,14 +6,15 @@
NS_ASSUME_NONNULL_BEGIN
@class YapDatabaseReadWriteTransaction;
@protocol ContactsManagerProtocol;
@protocol ProfileManagerProtocol;
@class OWSIdentityManager;
@interface OWSSyncContactsMessage : OWSOutgoingSyncMessage
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager
identityManager:(OWSIdentityManager *)identityManager;
identityManager:(OWSIdentityManager *)identityManager
profileManager:(id<ProfileManagerProtocol>)profileManager;
- (NSData *)buildPlainTextAttachmentData;

View File

@ -12,6 +12,7 @@
#import "SignalAccount.h"
#import "TSAttachment.h"
#import "TSAttachmentStream.h"
#import "ProfileManagerProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@ -19,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
@property (nonatomic, readonly) id<ProfileManagerProtocol> profileManager;
@end
@ -26,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager
identityManager:(OWSIdentityManager *)identityManager
profileManager:(id<ProfileManagerProtocol>)profileManager
{
self = [super initWithTimestamp:[NSDate ows_millisecondTimeStamp]];
if (!self) {
@ -34,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
_contactsManager = contactsManager;
_identityManager = identityManager;
_profileManager = profileManager;
return self;
}
@ -71,8 +75,11 @@ NS_ASSUME_NONNULL_BEGIN
for (SignalAccount *signalAccount in self.contactsManager.signalAccounts) {
OWSRecipientIdentity *recipientIdentity = [self.identityManager recipientIdentityForRecipientId:signalAccount.recipientId];
NSData *_Nullable profileKeyData = [self.profileManager profileKeyDataForRecipientId:signalAccount.recipientId];
[contactsOutputStream writeSignalAccount:signalAccount recipientIdentity:recipientIdentity];
[contactsOutputStream writeSignalAccount:signalAccount
recipientIdentity:recipientIdentity
profileKeyData:profileKeyData];
}
[contactsOutputStream flush];

View File

@ -515,8 +515,7 @@ NS_ASSUME_NONNULL_BEGIN
if ([dataMessage hasProfileKey]) {
NSData *profileKey = [dataMessage profileKey];
NSString *recipientId = incomingEnvelope.source;
id<ProfileManagerProtocol> profileManager = [TextSecureKitEnv sharedEnv].profileManager;
[profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
[self.profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
}
if (dataMessage.hasGroup) {
@ -580,6 +579,12 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (id<ProfileManagerProtocol>)profileManager
{
// TODO inject at init?
return [TextSecureKitEnv sharedEnv].profileManager;
}
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)incomingEnvelope
withCallMessage:(OWSSignalServiceProtosCallMessage *)callMessage
{
@ -589,8 +594,7 @@ NS_ASSUME_NONNULL_BEGIN
if ([callMessage hasProfileKey]) {
NSData *profileKey = [callMessage profileKey];
NSString *recipientId = incomingEnvelope.source;
id<ProfileManagerProtocol> profileManager = [TextSecureKitEnv sharedEnv].profileManager;
[profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
[self.profileManager setProfileKeyData:profileKey forRecipientId:recipientId];
}
if (callMessage.hasOffer) {
@ -707,8 +711,7 @@ NS_ASSUME_NONNULL_BEGIN
if (dataMessage && destination.length > 0 && [dataMessage hasProfileKey]) {
// If we observe a linked device sending our profile key to another
// user, we can infer that that user belongs in our profile whitelist.
id<ProfileManagerProtocol> profileManager = [TextSecureKitEnv sharedEnv].profileManager;
[profileManager addUserToProfileWhitelist:destination];
[self.profileManager addUserToProfileWhitelist:destination];
// TODO: Can we also infer when groups are added to the whitelist
// from sent messages to groups?
@ -729,7 +732,8 @@ NS_ASSUME_NONNULL_BEGIN
if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeContacts) {
OWSSyncContactsMessage *syncContactsMessage =
[[OWSSyncContactsMessage alloc] initWithContactsManager:self.contactsManager
identityManager:self.identityManager];
identityManager:self.identityManager
profileManager:self.profileManager];
[self.messageSender sendTemporaryAttachmentData:[syncContactsMessage buildPlainTextAttachmentData]
contentType:OWSMimeTypeApplicationOctetStream

View File

@ -5,10 +5,13 @@
@class TSThread;
@class OWSAES256Key;
NS_ASSUME_NONNULL_BEGIN
@protocol ProfileManagerProtocol <NSObject>
- (OWSAES256Key *)localProfileKey;
- (nullable NSData *)profileKeyDataForRecipientId:(NSString *)recipientId;
- (void)setProfileKeyData:(NSData *)profileKeyData forRecipientId:(NSString *)recipientId;
- (BOOL)isUserInProfileWhitelist:(NSString *)recipientId;
@ -18,3 +21,5 @@
- (void)addUserToProfileWhitelist:(NSString *)recipientId;
@end
NS_ASSUME_NONNULL_END