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

MXCrypto: Key backup: Ignore all whitespaces in recovery key #621

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes in Matrix iOS SDK in 0.12.2 (2019-01-)
Improvements:
* MXRoom: Add a sendAudioFile API to send file using msgType "m.audio", thanks to N-Pex (PR #616).
* MXCrypto: Add key backup passphrase support (vector-im/riot-ios#2127).
* MXCrypto: Key backup: Ignore all whitespaces in recovery key (vector-im/riot-ios#2194).

Bug Fix:
* Crypto: Device deduplication method sometimes crashes (vector-im/riot-ios/issues/#2167).
Expand Down
6 changes: 5 additions & 1 deletion MatrixSDK/Crypto/KeyBackup/MXRecoveryKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ + (NSString *)encode:(NSData *)key

+ (NSData *)decode:(NSString *)recoveryKey error:(NSError **)error
{
NSString *recoveryKeyWithNoSpaces = [recoveryKey stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *recoveryKeyWithNoSpaces = [recoveryKey stringByReplacingOccurrencesOfString:@"\\s"
withString:@""
options:NSRegularExpressionSearch
range:NSMakeRange(0, recoveryKey.length)];

NSMutableData *result = [[self decodeBase58:recoveryKeyWithNoSpaces] mutableCopy];

if (!result)
Expand Down
8 changes: 6 additions & 2 deletions MatrixSDKTests/MXCryptoBackupTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,16 @@ - (void)testRecoveryKey

- (void)testIsValidRecoveryKey
{
NSString *recoveryKey = @"EsTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4d";
NSString *recoveryKey1 = @"EsTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4d";
NSString *recoveryKey2 = @"EsTcLW2KPGiFwKEA3As5g5c4BXwkqeeJZJV8Q9fugUMNUE4d";
NSString *recoveryKey3 = @"EsTc LW2K PGiF wKEA 3As5 g5c4\r\nBXwk qeeJ ZJV8 Q9fu gUMN UE4d";
NSString *invalidRecoveryKey1 = @"EsTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4e";
NSString *invalidRecoveryKey2 = @"EsTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4f";
NSString *invalidRecoveryKey3 = @"EqTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4d";

XCTAssertTrue([MXKeyBackup isValidRecoveryKey:recoveryKey]);
XCTAssertTrue([MXKeyBackup isValidRecoveryKey:recoveryKey1]);
XCTAssertTrue([MXKeyBackup isValidRecoveryKey:recoveryKey2]);
XCTAssertTrue([MXKeyBackup isValidRecoveryKey:recoveryKey3]);
XCTAssertFalse([MXKeyBackup isValidRecoveryKey:invalidRecoveryKey1]);
XCTAssertFalse([MXKeyBackup isValidRecoveryKey:invalidRecoveryKey2]);
XCTAssertFalse([MXKeyBackup isValidRecoveryKey:invalidRecoveryKey3]);
Expand Down