Page MenuHomePhabricator

[web] Caclulate encrypted media sha256
ClosedPublic

Authored by bartek on Apr 29 2023, 9:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 6, 3:40 PM
Unknown Object (File)
Wed, Nov 6, 3:40 PM
Unknown Object (File)
Wed, Nov 6, 3:40 PM
Unknown Object (File)
Mon, Nov 4, 4:13 PM
Unknown Object (File)
Mon, Oct 28, 1:44 AM
Unknown Object (File)
Wed, Oct 23, 4:23 PM
Unknown Object (File)
Wed, Oct 23, 4:23 PM
Unknown Object (File)
Mon, Oct 21, 2:09 AM
Subscribers

Details

Summary

Web counterpart of D7647.
Sometimes encountered weird errors when creating the olm.Utility multiple times so decided to cache the instance and lazy-init Olm.


Due to ENG-3845 I decided to opt out of Olm here and used WebCrypto instead

Test Plan

Added console.log in encryptMedia() and sent encrypted photo. Verified that the hash is calculated

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Apr 29 2023, 9:25 AM

Please address inline comment before landing. If it doesn't make sense or you feel like I am missing something, feel free to re-request review

web/olm/olm-utils.js
17–24 ↗(On Diff #25937)

There is a risk here of a race that leads to two instantiations. We can avoid that

This revision is now accepted and ready to land.Apr 29 2023, 12:01 PM
web/olm/olm-utils.js
17–24 ↗(On Diff #25937)

Actually I missed a line here:

let olmUtilityInstance;
function olmUtility(): Promise<Utility> {
  if (!olmUtilityInstance) {
    olmUtilityInstance = (async () => {
      await initOlm();
      olmUtilityInstance = new olm.Utility();
      return olmUtilityInstance;
    })();
  }
  return Promise.resolve(olmUtilityInstance);
}

Apply suggestion - avoid race

During testing I encountered this issue: https://linear.app/comm/issue/ENG-3845/js-olm-sha256-fails

For now, used a WebCrypto fallback.

bartek retitled this revision from [web] Caclulate encrypted media sha256 using Olm to [web] Caclulate encrypted media sha256.May 8 2023, 4:52 AM
bartek edited the summary of this revision. (Show Details)
ashoat added inline comments.
web/media/encryption-utils.js
65

Looks like this is very well supported by modern browsers: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest

This revision was automatically updated to reflect the committed changes.