Page MenuHomePhabricator

D9000.id30479.diff
No OneTemporary

D9000.id30479.diff

diff --git a/native/backup/conversion-utils.js b/native/backup/conversion-utils.js
--- a/native/backup/conversion-utils.js
+++ b/native/backup/conversion-utils.js
@@ -16,4 +16,9 @@
return new Uint8Array(objBuffer);
}
-export { getBackupBytesFromBlob, convertObjToBytes };
+function convertBytesToObj<T>(bytes: Uint8Array): T {
+ const str = commUtilsModule.decodeUTF8ArrayBufferToString(bytes.buffer);
+ return JSON.parse(str);
+}
+
+export { getBackupBytesFromBlob, convertObjToBytes, convertBytesToObj };
diff --git a/native/backup/encryption.js b/native/backup/encryption.js
--- a/native/backup/encryption.js
+++ b/native/backup/encryption.js
@@ -1,9 +1,14 @@
// @flow
import { hexToUintArray } from 'lib/media/data-utils.js';
-import type { Backup, BackupEncrypted } from 'lib/types/backup-types.js';
+import type {
+ Backup,
+ BackupEncrypted,
+ UserData,
+ UserKeys,
+} from 'lib/types/backup-types.js';
-import { convertObjToBytes } from './conversion-utils.js';
+import { convertBytesToObj, convertObjToBytes } from './conversion-utils.js';
import { fetchNativeKeychainCredentials } from '../account/native-credentials.js';
import { commCoreModule } from '../native-modules.js';
import * as AES from '../utils/aes-crypto-module.js';
@@ -31,4 +36,27 @@
return { backupID, userKeys: ct1, userData: ct2 };
}
-export { getBackupKey, encryptBackup };
+async function decryptUserKeys(
+ backupID: string,
+ userKeysBytes: ArrayBuffer,
+): Promise<UserKeys> {
+ const backupKey = await getBackupKey(backupID);
+ const decryptedUserKeys = AES.decrypt(
+ backupKey,
+ new Uint8Array(userKeysBytes),
+ );
+ return convertBytesToObj<UserKeys>(decryptedUserKeys);
+}
+
+async function decryptUserData(
+ backupDataKey: string,
+ userDataBytes: ArrayBuffer,
+): Promise<UserData> {
+ const decryptedUserData = AES.decrypt(
+ hexToUintArray(backupDataKey),
+ new Uint8Array(userDataBytes),
+ );
+ return convertBytesToObj<UserData>(decryptedUserData);
+}
+
+export { getBackupKey, encryptBackup, decryptUserKeys, decryptUserData };

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 1:23 AM (16 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2696964
Default Alt Text
D9000.id30479.diff (2 KB)

Event Timeline