Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make KeyProvider and ParticipantKeyHandler work consistently for shared key and sender key scenarios (e2ee) #850

Merged
merged 7 commits into from
Aug 24, 2023

Conversation

lukasIO
Copy link
Contributor

@lukasIO lukasIO commented Aug 23, 2023

main motivation for these fixes was an inconsistency in setting the local participant's keys, which expected the participantId to be undefined. This caused a bug when trying to set individual sender keys instead of using a shared-key provider.
Initially this was done because when setKey on a KeyProvider was called, we had no way of figuring out whether or not that participant is actually the local participant, until we're connected to the server and have the participant identity info.

This PR

  • replaces strings with dedicated event enums in e2ee event emitters
  • introduces a enabledEncryptionMap that tracks whether or not encryption is enabled for a specific participant (previously this was handled as part of the ParticipantKeyHandler)
  • updates local participant encryption keys on SignalConnected (the earliest we know the identity without manually parsing the token)
  • introduces a dedicated initAck worker message in order not to have to mis-use the existing enable message for that purpose
  • uses a dedicated sharedKeyHandler that handles all key interactions when sharedKey is set to true. Previously an instance was created for each participant, but in the shared key scenario that makes less sense. the only downside is that ratcheting doesn't work independently now, but I don't really see a reason in the shared key scenario for ratcheting anyways.

@changeset-bot
Copy link

changeset-bot bot commented Aug 23, 2023

🦋 Changeset detected

Latest commit: ff4e6a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Aug 23, 2023

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 76.24 KB (0%)
dist/livekit-client.umd.js 81.69 KB (0%)

@lukasIO lukasIO marked this pull request as ready for review August 23, 2023 16:20
@lukasIO lukasIO changed the title e2ee fixes [e2ee] Make KeyProvider and ParticipantKeyHandler work consistently for shared key and sender key scenarios Aug 23, 2023
Copy link
Member

@davidzhao davidzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg!

this.e2eeManager.setParticipantCryptorEnabled(enabled),
]);
await Promise.all([this.localParticipant.setE2EEEnabled(enabled)]);
if (this.localParticipant.identity !== '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to be safe here. could this this be true?

Copy link
Contributor Author

@lukasIO lukasIO Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localParticipant.identity gets initialized with an empty string on room creation. As long as we don't know the actual identity, it doesn't make sense to enable the cryptor with a wrong/dummy identity. We do however use the most recent setting for localParticipant.isE2EEEnabled on SignalConnected now to enable the cryptor once we know the local participant's identity.

@lukasIO lukasIO changed the title [e2ee] Make KeyProvider and ParticipantKeyHandler work consistently for shared key and sender key scenarios Make KeyProvider and ParticipantKeyHandler work consistently for shared key and sender key scenarios (e2ee) Aug 24, 2023
@lukasIO lukasIO merged commit d399413 into main Aug 24, 2023
@lukasIO lukasIO deleted the lukas/e2ee-fixes branch August 24, 2023 14:00
@github-actions github-actions bot mentioned this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants