Skip to content

Commit 47dc3fb

Browse files
authored
Merge pull request #3 from ixoworld/fix/ssss-base64-detection
Fix: base64 backup key detection in BackupManager.decodeRecoveryKey
2 parents 6e7cfca + cedf64a commit 47dc3fb

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ixo/matrix-bot-sdk",
3-
"version": "0.8.0-ixo.5",
3+
"version": "0.8.0-ixo.6",
44
"description": "TypeScript/JavaScript SDK for Matrix bots and appservices (ixo fork)",
55
"repository": {
66
"type": "git",

src/e2ee/BackupManager.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,20 @@ export class BackupManager {
125125
* @returns The recovery key in Base64 format
126126
*/
127127
public static decodeRecoveryKey(recoveryKey: string): string {
128-
// Check if it looks like Base58 (contains spaces or matches Base58 pattern)
129-
const hasSpaces = recoveryKey.includes(" ");
130-
const looksLikeBase64 = recoveryKey.includes("=") || recoveryKey.includes("+") || recoveryKey.includes("/");
131-
132-
if (!hasSpaces && looksLikeBase64) {
133-
// Already Base64, return as-is
134-
return recoveryKey;
128+
// Try Base64 first: if it decodes to exactly 32 bytes, it's a raw backup key
129+
if (!recoveryKey.includes(" ")) {
130+
try {
131+
const decoded = Buffer.from(recoveryKey, "base64");
132+
if (decoded.length === KEY_SIZE) {
133+
// Verify it's actually base64 and not just coincidence by re-encoding
134+
const reencoded = decoded.toString("base64");
135+
if (reencoded === recoveryKey || reencoded.replace(/=+$/, "") === recoveryKey.replace(/=+$/, "")) {
136+
return recoveryKey;
137+
}
138+
}
139+
} catch {
140+
// Not valid base64, fall through to Base58
141+
}
135142
}
136143

137144
// Decode from Base58

0 commit comments

Comments
 (0)