選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

E2EEncryption.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if (e2ee.disabled || config.testing?.disableE2EE) {
  34. return false;
  35. }
  36. return browser.supportsInsertableStreams()
  37. || (config.enableEncodedTransformSupport && browser.supportsEncodedTransform());
  38. }
  39. /**
  40. * Indicates whether E2EE is currently enabled or not.
  41. *
  42. * @returns {boolean}
  43. */
  44. isEnabled() {
  45. return this._keyHandler.isEnabled();
  46. }
  47. /**
  48. * Enables / disables End-To-End encryption.
  49. *
  50. * @param {boolean} enabled - whether E2EE should be enabled or not.
  51. * @returns {void}
  52. */
  53. async setEnabled(enabled) {
  54. await this._keyHandler.setEnabled(enabled);
  55. }
  56. /**
  57. * Sets the key and index for End-to-End encryption.
  58. *
  59. * @param {CryptoKey} [keyInfo.encryptionKey] - encryption key.
  60. * @param {Number} [keyInfo.index] - the index of the encryption key.
  61. * @returns {void}
  62. */
  63. setEncryptionKey(keyInfo) {
  64. this._keyHandler.setKey(keyInfo);
  65. }
  66. /**
  67. * Starts the verification process of the participant
  68. *
  69. * @param {Participant} - participant to be verified.
  70. * @returns {void}
  71. */
  72. startVerification(participant) {
  73. this._keyHandler.sasVerification?.startVerification(participant);
  74. }
  75. /**
  76. * Marks the channel as verified
  77. *
  78. * @param {Participant} - participant to be verified.
  79. * @param {boolean} isVerified - whether the verification was succesfull.
  80. * @returns {void}
  81. */
  82. markParticipantVerified(participant, isVerified) {
  83. this._keyHandler.sasVerification?.markParticipantVerified(participant, isVerified);
  84. }
  85. }