Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32417800
D7688.1765349168.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
D7688.1765349168.diff
View Options
diff --git a/web/media/encryption-utils.js b/web/media/encryption-utils.js
--- a/web/media/encryption-utils.js
+++ b/web/media/encryption-utils.js
@@ -21,6 +21,7 @@
+file: File,
+uri: string,
+encryptionKey: string,
+ +sha256Hash: string,
};
async function encryptFile(input: File): Promise<{
@@ -55,11 +56,14 @@
const startEncrypt = Date.now();
const paddedLength = calculatePaddedLength(data.length);
const shouldPad = paddedLength <= PADDING_THRESHOLD;
- let key, encryptedData;
+ let key, encryptedData, sha256;
try {
const plaintextData = shouldPad ? pad(data) : data;
key = await AES.generateKey();
encryptedData = await AES.encrypt(key, plaintextData);
+
+ const hashBytes = await crypto.subtle.digest('SHA-256', encryptedData);
+ sha256 = btoa(String.fromCharCode(...new Uint8Array(hashBytes)));
} catch (e) {
success = false;
exceptionMessage = getMessageForException(e);
@@ -69,11 +73,14 @@
dataSize: encryptedData?.byteLength ?? -1,
isPadded: shouldPad,
time: Date.now() - startEncrypt,
- sha256: null,
+ sha256,
success,
exceptionMessage,
});
- if (!success || !encryptedData || !key) {
+ if (encryptedData && !sha256) {
+ return { steps, result: { success: false, reason: 'digest_failed' } };
+ }
+ if (!success || !encryptedData || !key || !sha256) {
return { steps, result: { success: false, reason: 'encryption_failed' } };
}
@@ -86,6 +93,7 @@
file: output,
uri: URL.createObjectURL(output),
encryptionKey: uintArrayToHexString(key),
+ sha256Hash: sha256,
},
};
}
diff --git a/web/olm/olm-utils.js b/web/olm/olm-utils.js
--- a/web/olm/olm-utils.js
+++ b/web/olm/olm-utils.js
@@ -1,5 +1,6 @@
// @flow
+import type { Utility } from '@commapp/olm';
import olm from '@commapp/olm';
declare var olmFilename: string;
@@ -13,4 +14,16 @@
return await olm.init({ locateFile });
}
-export { initOlm };
+let olmUtilityInstance;
+function olmUtility(): Promise<Utility> {
+ if (!olmUtilityInstance) {
+ olmUtilityInstance = (async () => {
+ await initOlm();
+ olmUtilityInstance = new olm.Utility();
+ return olmUtilityInstance;
+ })();
+ }
+ return Promise.resolve(olmUtilityInstance);
+}
+
+export { initOlm, olmUtility };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 6:46 AM (16 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5861783
Default Alt Text
D7688.1765349168.diff (2 KB)
Attached To
Mode
D7688: [web] Caclulate encrypted media sha256
Attached
Detach File
Event Timeline
Log In to Comment