2015-12-07 03:31:43 +01:00
|
|
|
//
|
2018-01-11 15:56:38 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2015-12-07 03:31:43 +01:00
|
|
|
//
|
|
|
|
|
2017-06-06 21:16:09 +02:00
|
|
|
#import "OWSRecipientIdentity.h"
|
2015-12-07 03:31:43 +01:00
|
|
|
#import <AxolotlKit/IdentityKeyStore.h>
|
|
|
|
|
2017-05-23 16:28:50 +02:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2018-03-05 15:30:58 +01:00
|
|
|
extern NSString *const OWSPrimaryStorageTrustedKeysCollection;
|
2017-06-06 20:12:50 +02:00
|
|
|
|
2017-06-06 21:16:09 +02:00
|
|
|
// This notification will be fired whenever identities are created
|
|
|
|
// or their verification state changes.
|
2017-06-06 21:01:11 +02:00
|
|
|
extern NSString *const kNSNotificationName_IdentityStateDidChange;
|
2017-06-06 20:12:50 +02:00
|
|
|
|
2017-06-08 05:21:25 +02:00
|
|
|
// number of bytes in a signal identity key, excluding the key-type byte.
|
|
|
|
extern const NSUInteger kIdentityKeyLength;
|
|
|
|
|
2017-05-25 19:39:13 +02:00
|
|
|
@class OWSRecipientIdentity;
|
2017-06-22 02:19:23 +02:00
|
|
|
@class OWSSignalServiceProtosVerified;
|
2018-01-11 15:56:38 +01:00
|
|
|
@class OWSStorage;
|
2018-02-02 20:07:13 +01:00
|
|
|
@class YapDatabaseReadWriteTransaction;
|
2017-05-25 19:39:13 +02:00
|
|
|
|
2017-06-06 20:12:50 +02:00
|
|
|
// This class can be safely accessed and used from any thread.
|
|
|
|
@interface OWSIdentityManager : NSObject <IdentityKeyStore>
|
|
|
|
|
|
|
|
- (instancetype)init NS_UNAVAILABLE;
|
2017-05-23 16:28:50 +02:00
|
|
|
|
2017-06-06 20:12:50 +02:00
|
|
|
+ (instancetype)sharedManager;
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
- (void)generateNewIdentityKey;
|
2017-06-06 21:32:43 +02:00
|
|
|
|
2018-01-30 22:41:25 +01:00
|
|
|
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId;
|
2018-01-30 21:05:04 +01:00
|
|
|
|
2018-02-02 20:21:35 +01:00
|
|
|
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId
|
|
|
|
transaction:(YapDatabaseReadTransaction *)transaction;
|
2017-06-06 21:16:09 +02:00
|
|
|
|
|
|
|
- (void)setVerificationState:(OWSVerificationState)verificationState
|
|
|
|
identityKey:(NSData *)identityKey
|
|
|
|
recipientId:(NSString *)recipientId
|
2018-01-23 19:58:45 +01:00
|
|
|
isUserInitiatedChange:(BOOL)isUserInitiatedChange
|
2018-02-02 20:21:35 +01:00
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
2017-06-06 21:16:09 +02:00
|
|
|
|
2018-01-30 22:41:25 +01:00
|
|
|
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId;
|
2018-01-30 21:49:36 +01:00
|
|
|
- (OWSVerificationState)verificationStateForRecipientId:(NSString *)recipientId
|
2018-02-02 18:56:55 +01:00
|
|
|
transaction:(YapDatabaseReadTransaction *)transaction;
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2018-02-02 20:07:13 +01:00
|
|
|
- (void)setVerificationState:(OWSVerificationState)verificationState
|
|
|
|
identityKey:(NSData *)identityKey
|
|
|
|
recipientId:(NSString *)recipientId
|
|
|
|
isUserInitiatedChange:(BOOL)isUserInitiatedChange;
|
|
|
|
|
2017-06-07 22:51:17 +02:00
|
|
|
- (nullable OWSRecipientIdentity *)recipientIdentityForRecipientId:(NSString *)recipientId;
|
|
|
|
|
2017-06-06 21:32:43 +02:00
|
|
|
/**
|
|
|
|
* @param recipientId unique stable identifier for the recipient, e.g. e164 phone number
|
2017-06-07 01:01:12 +02:00
|
|
|
* @returns nil if the recipient does not exist, or is trusted for sending
|
|
|
|
* else returns the untrusted recipient.
|
2017-06-06 21:32:43 +02:00
|
|
|
*/
|
2018-01-30 21:49:36 +01:00
|
|
|
- (nullable OWSRecipientIdentity *)untrustedIdentityForSendingToRecipientId:(NSString *)recipientId;
|
2017-06-06 21:32:43 +02:00
|
|
|
|
2017-09-21 17:55:25 +02:00
|
|
|
// This method can be called from any thread.
|
2018-02-02 20:52:45 +01:00
|
|
|
- (void)processIncomingSyncMessage:(OWSSignalServiceProtosVerified *)verified
|
|
|
|
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
2017-06-07 20:20:29 +02:00
|
|
|
|
2018-02-02 18:56:55 +01:00
|
|
|
- (BOOL)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId;
|
|
|
|
|
2018-01-10 16:40:48 +01:00
|
|
|
#pragma mark - Debug
|
|
|
|
|
2018-01-30 22:41:25 +01:00
|
|
|
- (nullable ECKeyPair *)identityKeyPair;
|
2018-01-22 23:09:50 +01:00
|
|
|
|
2018-01-10 16:40:48 +01:00
|
|
|
#if DEBUG
|
2018-01-12 22:49:51 +01:00
|
|
|
// Clears everything except the local identity key.
|
2018-02-02 20:07:13 +01:00
|
|
|
- (void)clearIdentityState:(YapDatabaseReadWriteTransaction *)transaction;
|
2018-01-12 22:49:51 +01:00
|
|
|
|
2018-02-02 20:07:13 +01:00
|
|
|
- (void)snapshotIdentityState:(YapDatabaseReadWriteTransaction *)transaction;
|
|
|
|
- (void)restoreIdentityState:(YapDatabaseReadWriteTransaction *)transaction;
|
2018-01-10 16:40:48 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
@end
|
2017-05-23 16:28:50 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|