Skip to content

Commit

Permalink
Merge pull request #621 from matrix-org/riot_2194
Browse files Browse the repository at this point in the history
MXCrypto: Key backup: Ignore all whitespaces in recovery key
  • Loading branch information
manuroe committed Jan 24, 2019
2 parents f389fa0 + 1f3bbdd commit 0134fe3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
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

0 comments on commit 0134fe3

Please sign in to comment.