Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MXRecoveryService: Expose checkPrivateKey to validate a private key #1129

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changes to be released in next version
* MXRoomLastMessage: Use MXKeyProvider methods to encrypt/decrypt last message dictionary.
* VoIP: Change hold direction to send-only.
* Encrypted Media: Remove redundant and undocumented mimetype fields from encrypted attachments (vector-im/element-ios/issues/4303).
* MXRecoveryService: Expose checkPrivateKey to validate a private key (vector-im/element-ios/issues/4430).

🐛 Bugfix
* MXSession: Fix app that can fail to resume (vector-im/element-ios/issues/4417).
Expand Down
8 changes: 8 additions & 0 deletions MatrixSDK/Crypto/Recovery/MXRecoveryService.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ typedef NS_ENUM(NSInteger, MXRecoveryServiceErrorCode)
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;

/**
Check whether a private key corresponds to the current recovery.

@param privateKey the private key.
@param complete called with a boolean that indicates whether or not the key matches
*/
- (void)checkPrivateKey:(NSData*)privateKey complete:(void (^)(BOOL match))complete;


#pragma mark - Secrets in the recovery

Expand Down
13 changes: 13 additions & 0 deletions MatrixSDK/Crypto/Recovery/MXRecoveryService.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ - (void)deleteKeyBackupWithSuccess:(void (^)(void))success
} failure:failure];
}

- (void)checkPrivateKey:(NSData*)privateKey complete:(void (^)(BOOL match))complete
{
MXSecretStorageKeyContent *keyContent = [_secretStorage keyWithKeyId:self.recoveryId];
if (!keyContent)
{
complete(NO);
return;
}

[_secretStorage checkPrivateKey:privateKey withKey:keyContent complete:complete];
}


#pragma mark - Secrets in the recovery

Expand Down Expand Up @@ -310,6 +322,7 @@ - (void)createRecoveryForSecrets:(nullable NSArray<NSString*>*)secrets
// Set this recovery as the default SSSS key id
[self.secretStorage setAsDefaultKeyWithKeyId:keyCreationInfo.keyId success:^{

// ####
manuroe marked this conversation as resolved.
Show resolved Hide resolved
[self updateRecoveryForSecrets:secrets withPrivateKey:keyCreationInfo.privateKey success:^{
success(keyCreationInfo);
} failure:failure];
Expand Down