Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33470673
D9000.1769037651.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D9000.1769037651.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 21, 11:20 PM (7 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5965416
Default Alt Text
D9000.1769037651.diff (2 KB)
Attached To
Mode
D9000: [client-backup] implement functions to decrypt backup
Attached
Detach File
Event Timeline
Log In to Comment