Given a recipient id, returns any unconfirmed identity

// FREEBIE
This commit is contained in:
Michael Kirk 2017-05-25 10:39:13 -07:00
parent 0201fa34ce
commit 09d7d8c027
2 changed files with 34 additions and 0 deletions

View file

@ -7,6 +7,8 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSRecipientIdentity;
extern NSString *const TSStorageManagerTrustedKeysCollection;
@interface TSStorageManager (IdentityKeyStore) <IdentityKeyStore>
@ -29,6 +31,15 @@ extern NSString *const TSStorageManagerTrustedKeysCollection;
approvedForBlockingUse:(BOOL)approvedForBlockingUse
approvedForNonBlockingUse:(BOOL)approvedForNonBlockingUse;
/**
* Check if a recipient identity corresponds to an untrusted identity
*
* @param recipientId unique stable identifier for the recipient, e.g. e164 phone number
* @returns nil if the identity doesn't exist or if it's trusted
* else returns the untrusted identity
*/
- (nullable OWSRecipientIdentity *)unconfirmedIdentityThatShouldBlockSendingForRecipientId:(NSString *)recipientId;
- (void)generateNewIdentityKey;
- (nullable NSData *)identityKeyForRecipientId:(NSString *)recipientId;
- (void)removeIdentityKeyForRecipient:(NSString *)receipientId;

View file

@ -175,6 +175,29 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0;
}
}
- (nullable OWSRecipientIdentity *)unconfirmedIdentityThatShouldBlockSendingForRecipientId:(NSString *)recipientId;
{
OWSAssert(recipientId != nil);
@synchronized([[self class] sharedIdentityKeyLock])
{
OWSRecipientIdentity *currentIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
if (currentIdentity == nil) {
// No preexisting key, Trust On First Use
return nil;
}
if ([self isTrustedIdentityKey:currentIdentity.identityKey
recipientId:currentIdentity.recipientId
direction:TSMessageDirectionOutgoing]) {
return nil;
}
// identity not yet trusted for sending
return currentIdentity;
}
}
- (BOOL)isTrustedKey:(NSData *)identityKey forSendingToIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
{
OWSAssert(identityKey != nil);