From 872bc04674ad06fab4b9f4951239a11ee14e65cb Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 5 Dec 2021 12:19:22 +0100 Subject: [PATCH] fix(ssss): Strip all whitespace characters from recovery keys upon decode Previously we stripped all spaces off of the recovery when decoding it, so that we could format the recovery key nicely. It turns out, however, that some element flavours also format with linebreaks, leading to the user having to manually remove them. We fix this by just stripping *all* whitespace off of the recovery key. --- lib/encryption/ssss.dart | 2 +- test/encryption/ssss_test.dart | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index 3a8a380f..fc591522 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -121,7 +121,7 @@ class SSSS { } static Uint8List decodeRecoveryKey(String recoveryKey) { - final result = base58.decode(recoveryKey.replaceAll(' ', '')); + final result = base58.decode(recoveryKey.replaceAll(RegExp(r'\s'), '')); final parity = result.fold(0, (a, b) => a ^ b); if (parity != 0) { diff --git a/test/encryption/ssss_test.dart b/test/encryption/ssss_test.dart index 13de3af8..093f8ca4 100644 --- a/test/encryption/ssss_test.dart +++ b/test/encryption/ssss_test.dart @@ -126,7 +126,10 @@ void main() { if (!olmEnabled) return; final key = Uint8List.fromList(secureRandomBytes(32)); final encoded = SSSS.encodeRecoveryKey(key); - final decoded = SSSS.decodeRecoveryKey(encoded); + var decoded = SSSS.decodeRecoveryKey(encoded); + expect(key, decoded); + + decoded = SSSS.decodeRecoveryKey(encoded + ' \n\t'); expect(key, decoded); final handle = client.encryption!.ssss.open();