Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32528954
D8999.1767147333.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D8999.1767147333.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
@@ -10,4 +10,10 @@
return new Uint8Array(decodedBuffer);
}
-export { getBackupBytesFromBlob };
+function convertObjToBytes<T>(obj: T): Uint8Array {
+ const objStr = JSON.stringify(obj);
+ const objBuffer = commUtilsModule.encodeStringToUTF8ArrayBuffer(objStr ?? '');
+ return new Uint8Array(objBuffer);
+}
+
+export { getBackupBytesFromBlob, convertObjToBytes };
diff --git a/native/backup/encryption.js b/native/backup/encryption.js
--- a/native/backup/encryption.js
+++ b/native/backup/encryption.js
@@ -1,7 +1,12 @@
// @flow
+import { hexToUintArray } from 'lib/media/data-utils.js';
+import type { Backup, BackupEncrypted } from 'lib/types/backup-types.js';
+
+import { 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';
async function getBackupKey(backupID: string): Promise<Uint8Array> {
const nativeCredentials = await fetchNativeKeychainCredentials();
@@ -13,4 +18,17 @@
return new Uint8Array(backupKey);
}
-export { getBackupKey };
+async function encryptBackup(backup: Backup): Promise<BackupEncrypted> {
+ const { backupID, userKeys, userData } = backup;
+ const userKeysBytes = convertObjToBytes(userKeys);
+ const backupKey = await getBackupKey(backupID);
+ const ct1 = AES.encrypt(backupKey, userKeysBytes);
+
+ const userDataBytes = convertObjToBytes(userData);
+ const backupDataKey = hexToUintArray(userKeys.backupDataKey);
+ const ct2 = AES.encrypt(backupDataKey, userDataBytes);
+
+ return { backupID, userKeys: ct1, userData: ct2 };
+}
+
+export { getBackupKey, encryptBackup };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 31, 2:15 AM (5 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5871420
Default Alt Text
D8999.1767147333.diff (1 KB)
Attached To
Mode
D8999: [client-backup] implement function to encrypt backup
Attached
Detach File
Event Timeline
Log In to Comment