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

Add sanity check for duplicate cryptors and log more errors #1082

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-moose-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Add sanity check for duplicate cryptors and log more errors
12 changes: 12 additions & 0 deletions src/e2ee/worker/FrameCryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ export class FrameCryptor extends BaseFrameCryptor {
* @param keys
*/
setParticipant(id: string, keys: ParticipantKeyHandler) {
workerLogger.debug('setting new participant on cryptor', {
...this.logContext,
participant: id,
});
if (this.participantIdentity) {
workerLogger.error(
'cryptor has already a participant set, participant should have been unset before',
{
...this.logContext,
},
);
}
this.participantIdentity = id;
this.keys = keys;
this.sifGuard.reset();
Expand Down
27 changes: 24 additions & 3 deletions src/e2ee/worker/e2ee.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ onmessage = (ev) => {
break;
case 'enable':
setEncryptionEnabled(data.enabled, data.participantIdentity);
workerLogger.info('updated e2ee enabled status');
workerLogger.info(
`updated e2ee enabled status for ${data.participantIdentity} to ${data.enabled}`,
);
// acknowledge enable call successful
postMessage(ev.data);
break;
Expand Down Expand Up @@ -123,7 +125,19 @@ async function handleRatchetRequest(data: RatchetRequestMessage['data']) {
}

function getTrackCryptor(participantIdentity: string, trackId: string) {
let cryptor = participantCryptors.find((c) => c.getTrackId() === trackId);
let cryptors = participantCryptors.filter((c) => c.getTrackId() === trackId);
if (cryptors.length > 1) {
const debugInfo = cryptors
.map((c) => {
return { participant: c.getParticipantIdentity() };
})
.join(',');
workerLogger.error(
`Found multiple cryptors for the same trackID ${trackId}. target participant: ${participantIdentity} `,
{ participants: debugInfo },
);
}
let cryptor = cryptors[0];
if (!cryptor) {
workerLogger.info('creating new cryptor for', { participantIdentity });
if (!keyProviderOptions) {
Expand Down Expand Up @@ -168,9 +182,16 @@ function getSharedKeyHandler() {
}

function unsetCryptorParticipant(trackId: string, participantIdentity: string) {
const cryptor = participantCryptors.find(
const cryptors = participantCryptors.filter(
(c) => c.getParticipantIdentity() === participantIdentity && c.getTrackId() === trackId,
);
if (cryptors.length > 1) {
workerLogger.error('Found multiple cryptors for the same participant and trackID combination', {
trackId,
participantIdentity,
});
}
const cryptor = cryptors[0];
if (!cryptor) {
workerLogger.warn('Could not unset participant on cryptor', { trackId, participantIdentity });
} else {
Expand Down
Loading