Send any profile key in contact sync

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent f0a57edde0
commit 1f3d2d1ed6

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save