Skip to content

Commit

Permalink
Include participant identity in CryptoError errors (#1186)
Browse files Browse the repository at this point in the history
* Track participantIdentity for CryptorErrors

* Lint

* Add changeset

* Export E2EE error types

* Update .changeset/cryptor-error-participant-identity.md

Co-authored-by: lukasIO <[email protected]>

---------

Co-authored-by: lukasIO <[email protected]>
  • Loading branch information
hughns and lukasIO authored Jul 11, 2024
1 parent c3104bc commit b8a9d48
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/cryptor-error-participant-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Include participant identity in CryptoError errors
9 changes: 8 additions & 1 deletion src/e2ee/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ export enum CryptorErrorReason {
export class CryptorError extends LivekitError {
reason: CryptorErrorReason;

constructor(message?: string, reason: CryptorErrorReason = CryptorErrorReason.InternalError) {
participantIdentity?: string;

constructor(
message?: string,
reason: CryptorErrorReason = CryptorErrorReason.InternalError,
participantIdentity?: string,
) {
super(40, message);
this.reason = reason;
this.participantIdentity = participantIdentity;
}
}
1 change: 1 addition & 0 deletions src/e2ee/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './KeyProvider';
export * from './utils';
export * from './types';
export * from './events';
export * from './errors';
16 changes: 14 additions & 2 deletions src/e2ee/worker/FrameCryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ export class FrameCryptor extends BaseFrameCryptor {
.pipeTo(writable)
.catch((e) => {
workerLogger.warn(e);
this.emit(CryptorEvent.Error, e instanceof CryptorError ? e : new CryptorError(e.message));
this.emit(
CryptorEvent.Error,
e instanceof CryptorError
? e
: new CryptorError(e.message, undefined, this.participantIdentity),
);
});
this.trackId = trackId;
}
Expand Down Expand Up @@ -297,7 +302,11 @@ export class FrameCryptor extends BaseFrameCryptor {
workerLogger.debug('failed to decrypt, emitting error', this.logContext);
this.emit(
CryptorEvent.Error,
new CryptorError(`encryption key missing for encoding`, CryptorErrorReason.MissingKey),
new CryptorError(
`encryption key missing for encoding`,
CryptorErrorReason.MissingKey,
this.participantIdentity,
),
);
}
}
Expand Down Expand Up @@ -367,6 +376,7 @@ export class FrameCryptor extends BaseFrameCryptor {
new CryptorError(
`missing key at index ${keyIndex} for participant ${this.participantIdentity}`,
CryptorErrorReason.MissingKey,
this.participantIdentity,
),
);
}
Expand Down Expand Up @@ -487,12 +497,14 @@ export class FrameCryptor extends BaseFrameCryptor {
throw new CryptorError(
`valid key missing for participant ${this.participantIdentity}`,
CryptorErrorReason.InvalidKey,
this.participantIdentity,
);
}
} else {
throw new CryptorError(
`Decryption failed: ${error.message}`,
CryptorErrorReason.InvalidKey,
this.participantIdentity,
);
}
}
Expand Down

0 comments on commit b8a9d48

Please sign in to comment.