Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

E2EEncryption.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import browser from '../browser';
  2. import { ExternallyManagedKeyHandler } from './ExternallyManagedKeyHandler';
  3. import { ManagedKeyHandler } from './ManagedKeyHandler';
  4. import { OlmAdapter } from './OlmAdapter';
  5. /**
  6. * This module integrates {@link KeyHandler} with {@link JitsiConference} in order to enable E2E encryption.
  7. */
  8. export class E2EEncryption {
  9. /**
  10. * A constructor.
  11. * @param {JitsiConference} conference - The conference instance for which E2E encryption is to be enabled.
  12. */
  13. constructor(conference) {
  14. const { e2ee = {} } = conference.options.config;
  15. this._externallyManaged = e2ee.externallyManagedKey;
  16. if (this._externallyManaged) {
  17. this._keyHandler = new ExternallyManagedKeyHandler(conference);
  18. } else {
  19. this._keyHandler = new ManagedKeyHandler(conference);
  20. }
  21. }
  22. /**
  23. * Indicates if E2EE is supported in the current platform.
  24. *
  25. * @param {object} config - Global configuration.
  26. * @returns {boolean}
  27. */
  28. static isSupported(config) {
  29. const { e2ee = {} } = config;
  30. if (!e2ee.externallyManagedKey && !OlmAdapter.isSupported()) {
  31. return false;
  32. }
  33. return !(config.testing && config.testing.disableE2EE)
  34. && (browser.supportsInsertableStreams()
  35. || (config.enableEncodedTransformSupport && browser.supportsEncodedTransform()));
  36. }
  37. /**
  38. * Indicates whether E2EE is currently enabled or not.
  39. *
  40. * @returns {boolean}
  41. */
  42. isEnabled() {
  43. return this._keyHandler.isEnabled();
  44. }
  45. /**
  46. * Enables / disables End-To-End encryption.
  47. *
  48. * @param {boolean} enabled - whether E2EE should be enabled or not.
  49. * @returns {void}
  50. */
  51. async setEnabled(enabled) {
  52. await this._keyHandler.setEnabled(enabled);
  53. }
  54. /**
  55. * Sets the key and index for End-to-End encryption.
  56. *
  57. * @param {CryptoKey} [keyInfo.encryptionKey] - encryption key.
  58. * @param {Number} [keyInfo.index] - the index of the encryption key.
  59. * @returns {void}
  60. */
  61. setEncryptionKey(keyInfo) {
  62. this._keyHandler.setKey(keyInfo);
  63. }
  64. }