passbolt-browser-extension 5.16.1 → 5.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/CHANGELOG.md +105 -1
  2. package/RELEASE_NOTES.md +94 -4
  3. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager/AppDelegate.swift +3 -3
  4. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager/ViewController.swift +10 -10
  5. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/SafariWebExtensionHandler.swift +5 -5
  6. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/AbstractController.swift +5 -5
  7. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/ErrorController.swift +2 -2
  8. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/FetchController.swift +3 -3
  9. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/OpenSafariSettingsController.swift +1 -1
  10. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/SaveFileController.swift +2 -2
  11. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/controllers/WriteClipboardController.swift +3 -3
  12. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/services/fetch/SecureProfileSessionManager.swift +36 -30
  13. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/services/fetch/fetchService.swift +24 -24
  14. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/services/file/SaveFileService.swift +15 -15
  15. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/utils/ErrorSerializer.swift +13 -13
  16. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Extension/utils/LocatedError.swift +3 -3
  17. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/SafariWebExtensionHandlerTests.swift +3 -3
  18. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/AbstractControllerTests.swift +2 -2
  19. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/ErrorControllerTests.swift +1 -1
  20. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/FetchControllerTests.swift +1 -1
  21. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/OpenSafariSettingsControllerTests.swift +1 -1
  22. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/SaveFileControllerTests.swift +1 -1
  23. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/controllers/WriteClipboardControllerTests.swift +1 -1
  24. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/services/fetch/FetchServiceTests.swift +1 -1
  25. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/services/fetch/SecureProfileSessionManagerTests.swift +7 -7
  26. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/utils/ErrorSerializerTests.swift +17 -17
  27. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager Tests/utils/LocatedErrorTests.swift +12 -12
  28. package/build-safari-extension/Passbolt-Safari-Extension/Passbolt - password manager.xcodeproj/project.pbxproj +2 -4
  29. package/package.json +10 -7
  30. package/src/all/background_page/controller/accountRecovery/recoverAccountController.js +4 -0
  31. package/src/all/background_page/controller/accountRecovery/recoverAccountController.test.js +5 -1
  32. package/src/all/background_page/controller/informCallToActionController/informCallToActionController.js +4 -2
  33. package/src/all/background_page/controller/informCallToActionController/informCallToActionController.test.js +4 -2
  34. package/src/all/background_page/controller/mfaPolicy/mfaGetMfaSettingsController.test.js +13 -0
  35. package/src/all/background_page/controller/mfaSetup/MfaSetupAbortWebauthnCeremonyController.js +52 -0
  36. package/src/all/background_page/controller/mfaSetup/MfaSetupAbortWebauthnCeremonyController.test.js +54 -0
  37. package/src/all/background_page/controller/mfaSetup/MfaSetupBeginWebauthnCeremonyController.js +52 -0
  38. package/src/all/background_page/controller/mfaSetup/MfaSetupBeginWebauthnCeremonyController.test.js +54 -0
  39. package/src/all/background_page/controller/mfaSetup/MfaSetupDeleteWebauthnCredentialController.js +55 -0
  40. package/src/all/background_page/controller/mfaSetup/MfaSetupDeleteWebauthnCredentialController.test.js +55 -0
  41. package/src/all/background_page/controller/mfaSetup/MfaSetupFinishWebauthnCeremonyController.js +54 -0
  42. package/src/all/background_page/controller/mfaSetup/MfaSetupFinishWebauthnCeremonyController.test.js +54 -0
  43. package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnCredentialsController.js +54 -0
  44. package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnCredentialsController.test.js +61 -0
  45. package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnSettingsController.js +53 -0
  46. package/src/all/background_page/controller/mfaSetup/MfaSetupGetWebauthnSettingsController.test.js +57 -0
  47. package/src/all/background_page/controller/mfaSetup/MfaSetupHandleWebauthnCeremonyResultController.js +55 -0
  48. package/src/all/background_page/controller/mfaSetup/MfaSetupHandleWebauthnCeremonyResultController.test.js +52 -0
  49. package/src/all/background_page/controller/move/moveFolderController.js +12 -12
  50. package/src/all/background_page/controller/move/moveFolderController.test.js +31 -1
  51. package/src/all/background_page/controller/move/moveResourcesController.js +18 -5
  52. package/src/all/background_page/controller/move/moveResourcesController.test.js +68 -7
  53. package/src/all/background_page/controller/recover/completeRecoverController.js +4 -0
  54. package/src/all/background_page/controller/recover/completeRecoverController.test.js +5 -1
  55. package/src/all/background_page/controller/setup/completeSetupController.js +4 -0
  56. package/src/all/background_page/controller/setup/completeSetupController.test.js +5 -1
  57. package/src/all/background_page/error/webauthnAlreadyRunningCeremonyError.js +24 -0
  58. package/src/all/background_page/error/webauthnAuthenticatorAlreadyRegisteredError.js +26 -0
  59. package/src/all/background_page/error/webauthnCeremonyAbortedError.js +26 -0
  60. package/src/all/background_page/error/webauthnCeremonyCancelledError.js +26 -0
  61. package/src/all/background_page/error/webauthnCeremonyError.js +26 -0
  62. package/src/all/background_page/error/webauthnCeremonyNotFoundError.js +26 -0
  63. package/src/all/background_page/error/webauthnTLSCertificateError.js +24 -0
  64. package/src/all/background_page/event/appBootstrapEvents.js +32 -0
  65. package/src/all/background_page/event/appBootstrapEvents.test.js +31 -0
  66. package/src/all/background_page/event/folderEvents.js +5 -4
  67. package/src/all/background_page/event/informCallToActionEvents.js +3 -2
  68. package/src/all/background_page/event/mfaEvents.js +38 -1
  69. package/src/all/background_page/event/resourceEvents.js +9 -5
  70. package/src/all/background_page/index.js +16 -0
  71. package/src/all/background_page/model/entity/folder/foldersCollection.js +13 -9
  72. package/src/all/background_page/model/entity/folder/foldersCollection.test.data.js +35 -0
  73. package/src/all/background_page/model/entity/folder/foldersCollection.test.js +60 -0
  74. package/src/all/background_page/model/entity/mfa/mfaEnabledProviderEntity.js +11 -0
  75. package/src/all/background_page/model/entity/mfa/mfaEnabledProviderEntity.test.js +13 -0
  76. package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialEntity.js +126 -0
  77. package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialEntity.test.data.js +26 -0
  78. package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialEntity.test.js +105 -0
  79. package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialsCollection.js +52 -0
  80. package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialsCollection.test.data.js +22 -0
  81. package/src/all/background_page/model/entity/mfa/mfaWebauthnCredentialsCollection.test.js +60 -0
  82. package/src/all/background_page/model/entity/mfa/mfaWebauthnSettingsEntity.js +45 -0
  83. package/src/all/background_page/model/entity/mfa/mfaWebauthnSettingsEntity.test.data.js +17 -0
  84. package/src/all/background_page/model/entity/mfa/mfaWebauthnSettingsEntity.test.js +48 -0
  85. package/src/all/background_page/model/entity/mfa/webauthnCredentialCreationOptionsEntity.js +235 -0
  86. package/src/all/background_page/model/entity/mfa/webauthnCredentialCreationOptionsEntity.test.data.js +42 -0
  87. package/src/all/background_page/model/entity/mfa/webauthnCredentialCreationOptionsEntity.test.js +152 -0
  88. package/src/all/background_page/model/entity/mfa/webauthnRegistrationResponseEntity.js +72 -0
  89. package/src/all/background_page/model/entity/mfa/webauthnRegistrationResponseEntity.test.data.js +26 -0
  90. package/src/all/background_page/model/entity/mfa/webauthnRegistrationResponseEntity.test.js +83 -0
  91. package/src/all/background_page/model/entity/mfa/webauthnSetupCeremonyEntity.js +121 -0
  92. package/src/all/background_page/model/entity/mfa/webauthnSetupCeremonyEntity.test.data.js +36 -0
  93. package/src/all/background_page/model/entity/mfa/webauthnSetupCeremonyEntity.test.js +100 -0
  94. package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.js +0 -59
  95. package/src/all/background_page/model/entity/permission/change/permissionChangesCollection.test.js +0 -333
  96. package/src/all/background_page/model/entity/userAndGroupSearchResultEntity/userAndGroupSearchResultEntity.js +1 -1
  97. package/src/all/background_page/model/entity/userAndGroupSearchResultEntity/userAndGroupSearchResultEntity.test.js +19 -1
  98. package/src/all/background_page/pagemod/accountRecoveryBootstrapPagemod.test.js +1 -1
  99. package/src/all/background_page/pagemod/appBootstrapPagemod.js +2 -1
  100. package/src/all/background_page/pagemod/appBootstrapPagemod.test.js +8 -8
  101. package/src/all/background_page/pagemod/authBootstrapPagemod.test.js +1 -1
  102. package/src/all/background_page/pagemod/pagemod.js +3 -1
  103. package/src/all/background_page/pagemod/pagemod.test.js +1 -1
  104. package/src/all/background_page/pagemod/publicWebsiteSignInPagemod.test.js +1 -1
  105. package/src/all/background_page/pagemod/recoverBootstrapPagemod.test.js +1 -1
  106. package/src/all/background_page/pagemod/setupBootstrapPagemod.test.js +1 -1
  107. package/src/all/background_page/pagemod/webIntegrationPagemod.test.js +1 -1
  108. package/src/all/background_page/sdk/port/portManager.js +13 -1
  109. package/src/all/background_page/sdk/port/portManager.test.js +98 -0
  110. package/src/all/background_page/service/api/mfa/webauthnApiService.js +76 -0
  111. package/src/all/background_page/service/api/mfa/webauthnApiService.test.js +119 -0
  112. package/src/all/background_page/service/api/mfa/webauthnSettingsApiService.js +44 -0
  113. package/src/all/background_page/service/api/mfa/webauthnSettingsApiService.test.js +56 -0
  114. package/src/all/background_page/service/auth/postLoginService.js +2 -1
  115. package/src/all/background_page/service/auth/postLoginService.test.js +1 -1
  116. package/src/all/background_page/service/auth/postLogoutService.js +2 -1
  117. package/src/all/background_page/service/auth/postLogoutService.test.js +24 -1
  118. package/src/all/background_page/service/extension/onExtensionUpdateAvailableService.test.js +2 -6
  119. package/src/all/background_page/service/group/groupUpdateSecretsCryptoService.js +1 -1
  120. package/src/all/background_page/service/group/groupUpdateService.js +1 -1
  121. package/src/all/background_page/service/group/groupUpdateService.test.js +3 -3
  122. package/src/all/background_page/service/localStorage/localStorageService.js +2 -0
  123. package/src/all/background_page/service/localStorage/localStorageService.test.js +3 -2
  124. package/src/all/background_page/service/mfa/validateWebauthnCreationOptionsService.js +41 -0
  125. package/src/all/background_page/service/mfa/validateWebauthnCreationOptionsService.test.js +52 -0
  126. package/src/all/background_page/service/mfa/webauthnSetupCeremonyService.js +266 -0
  127. package/src/all/background_page/service/mfa/webauthnSetupCeremonyService.test.js +437 -0
  128. package/src/all/background_page/service/move/deserializeConfirmedMovePermissions.js +41 -0
  129. package/src/all/background_page/service/move/deserializeConfirmedMovePermissions.test.js +80 -0
  130. package/src/all/background_page/service/move/moveOneFolderService.js +88 -135
  131. package/src/all/background_page/service/move/moveOneFolderService.test.js +774 -5237
  132. package/src/all/background_page/service/move/moveResourcesService.js +68 -40
  133. package/src/all/background_page/service/move/moveResourcesService.test.data.js +53 -0
  134. package/src/all/background_page/service/move/moveResourcesService.test.js +559 -2090
  135. package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.js +2 -1
  136. package/src/all/background_page/service/offline/getOrFindOfflineSettingsService.test.js +23 -0
  137. package/src/all/background_page/service/permission/calculatePermissionsChangesService.js +172 -0
  138. package/src/all/background_page/service/permission/calculatePermissionsChangesService.test.js +370 -0
  139. package/src/all/background_page/service/rbac/getOrFindRbacService.js +2 -1
  140. package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.js +2 -1
  141. package/src/all/background_page/service/resourceType/getOrFindResourceTypesService.test.js +19 -0
  142. package/src/all/background_page/service/sessionStorage/webauthnSetupCeremonySessionStorageService.js +62 -0
  143. package/src/all/background_page/service/sessionStorage/webauthnSetupCeremonySessionStorageService.test.js +60 -0
  144. package/src/all/background_page/service/sessionStorage/workersSessionStorage.js +30 -0
  145. package/src/all/background_page/service/sessionStorage/workersSessionStorage.test.js +55 -0
  146. package/src/all/background_page/service/share/shareFoldersService.js +20 -36
  147. package/src/all/background_page/service/share/shareFoldersService.test.js +236 -0
  148. package/src/all/background_page/service/tab/tabService.js +3 -2
  149. package/src/all/background_page/service/toolbar/toolbarService.js +13 -5
  150. package/src/all/background_page/service/ui/browserTab.service.js +6 -4
  151. package/src/all/background_page/service/ui/browserTab.service.test.js +19 -6
  152. package/src/all/background_page/service/user/getOrFindMeService.js +2 -1
  153. package/src/all/background_page/service/user/getOrFindMeService.test.js +17 -0
  154. package/src/all/background_page/service/worker/workerService.js +42 -11
  155. package/src/all/background_page/service/worker/workerService.test.js +70 -2
  156. package/src/all/contentScripts/js/app/App.js +2 -0
  157. package/src/all/contentScripts/js/controller/abortWebauthnSetupCeremonyContentScriptController.js +62 -0
  158. package/src/all/contentScripts/js/controller/abortWebauthnSetupCeremonyContentScriptController.test.js +44 -0
  159. package/src/all/contentScripts/js/controller/runWebauthnSetupCeremonyContentScriptController.js +65 -0
  160. package/src/all/contentScripts/js/controller/runWebauthnSetupCeremonyContentScriptController.test.js +70 -0
  161. package/src/all/contentScripts/js/event/webauthnSetupCeremonyEvents.js +33 -0
  162. package/src/all/contentScripts/js/service/webauthnSetupCeremonyContentScriptService.js +154 -0
  163. package/src/all/contentScripts/js/service/webauthnSetupCeremonyContentScriptService.test.js +252 -0
  164. package/src/all/locales/en-UK/common.json +0 -1
  165. package/src/all/webAccessibleResources/js/lib/port.js +106 -10
  166. package/src/all/webAccessibleResources/js/lib/port.test.js +174 -1
  167. package/src/chrome/manifest.json +2 -3
  168. package/src/chrome-mv3/index.js +6 -0
  169. package/src/chrome-mv3/manifest.json +3 -4
  170. package/src/firefox/manifest.json +2 -3
  171. package/src/safari/background_page/index.js +2 -1
  172. package/src/safari/background_page/service/cookies/cookiesService.js +9 -3
  173. package/src/safari/background_page/service/cookies/cookiesService.test.js +28 -1
  174. package/src/safari/manifest.json +2 -3
  175. package/test/mocks/mockWebExtensionPolyfill.js +2 -4
  176. package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.js +0 -113
  177. package/src/all/background_page/service/move/calculatePermissionsChangesForMoveService.test.js +0 -158
  178. package/src/all/background_page/service/move/confirmMoveStrategyService.js +0 -42
  179. package/src/all/background_page/service/move/confirmMoveStrategyService.test.js +0 -67
  180. /package/src/all/background_page/service/{move/calculatePermissionsChangesForMoveService.test.data.js → permission/calculatePermissionsChangesService.test.data.js} +0 -0
@@ -55,7 +55,7 @@ describe("PostLoginService", () => {
55
55
  const informCtaPortWrapper = new Port(informCtaPort);
56
56
 
57
57
  // function mocked
58
- jest.spyOn(BrowserTabService, "sendMessage").mockImplementation(jest.fn());
58
+ jest.spyOn(BrowserTabService, "sendMessage").mockImplementation(async () => {});
59
59
  jest.spyOn(PortManager, "getPortById").mockImplementationOnce(() => informCtaPortWrapper);
60
60
  jest.spyOn(informCtaPortWrapper, "emit");
61
61
  jest.spyOn(toolbarService, "handleUserLoggedIn").mockImplementation(async () => {});
@@ -26,10 +26,11 @@ class PostLogoutService {
26
26
  * Sends a passbolt.auth.after-logout event on workers
27
27
  */
28
28
  static async exec() {
29
- await PostLogoutService.sendLogoutEventForWorkers();
29
+ // Flush the user data first, so it never depends on the workers' ability to answer.
30
30
  await LocalStorageService.flush();
31
31
  await new CopyToClipboardService().flushTemporaryContentIfAny();
32
32
  await StartLoopAuthSessionCheckService.clearAlarm();
33
+ await PostLogoutService.sendLogoutEventForWorkers();
33
34
  toolbarService.handleUserLoggedOut();
34
35
  resourceInProgressCacheService.reset();
35
36
  OnExtensionUpdateAvailableService.handleUserLoggedOut();
@@ -45,7 +45,7 @@ describe("PostLogoutService", () => {
45
45
  const appPortWrapper = new Port(appPort);
46
46
 
47
47
  // function mocked
48
- jest.spyOn(BrowserTabService, "sendMessage").mockImplementation(jest.fn());
48
+ jest.spyOn(BrowserTabService, "sendMessage").mockImplementation(async () => {});
49
49
  jest.spyOn(PortManager, "getPortById").mockImplementationOnce(() => appPortWrapper);
50
50
  jest.spyOn(appPortWrapper, "emit");
51
51
  jest.spyOn(LocalStorageService, "flush");
@@ -84,6 +84,29 @@ describe("PostLogoutService", () => {
84
84
  expect(LocalStorageService.flush).toHaveBeenCalled();
85
85
  });
86
86
 
87
+ it("Should flush the user data even if a worker never answers", async () => {
88
+ expect.assertions(3);
89
+ jest.useFakeTimers();
90
+ const worker = readWorker({ name: AppPagemod.appName });
91
+ await WorkersSessionStorage.addWorker(new WorkerEntity(worker));
92
+
93
+ jest.spyOn(PortManager, "isPortExist").mockImplementation(() => false);
94
+ // Simulate the Edge sleeping tab behavior: the message promise never settles.
95
+ jest.spyOn(BrowserTabService, "sendMessage").mockImplementation(() => new Promise(() => {}));
96
+ jest.spyOn(LocalStorageService, "flush");
97
+ jest.spyOn(StartLoopAuthSessionCheckService, "clearAlarm");
98
+ jest.spyOn(toolbarService, "handleUserLoggedOut");
99
+
100
+ const promise = PostLogoutService.exec();
101
+ await jest.advanceTimersByTimeAsync(1000);
102
+ await promise;
103
+
104
+ expect(LocalStorageService.flush).toHaveBeenCalledTimes(1);
105
+ expect(StartLoopAuthSessionCheckService.clearAlarm).toHaveBeenCalledTimes(1);
106
+ expect(toolbarService.handleUserLoggedOut).toHaveBeenCalledTimes(1);
107
+ jest.useRealTimers();
108
+ });
109
+
87
110
  it("Should call all services that needs to run processes on logout", async () => {
88
111
  expect.assertions(6);
89
112
  jest.spyOn(PortManager, "isPortExist").mockImplementation(() => false);
@@ -112,7 +112,7 @@ describe("OnExtensionUpdateAvailableService", () => {
112
112
  jest.spyOn(AuthenticationStatusService.prototype, "isAuthenticated").mockImplementation(() => true);
113
113
  jest
114
114
  .spyOn(BrowserTabService, "sendMessage")
115
- .mockImplementation(() => PortManager.registerPort(webIntegrationPortWrapper));
115
+ .mockImplementation(async () => PortManager.registerPort(webIntegrationPortWrapper));
116
116
  jest.spyOn(browser.runtime, "reload");
117
117
  jest.spyOn(webIntegrationPortWrapper, "emit");
118
118
  jest.spyOn(webIntegrationPortWrapper2, "emit");
@@ -123,11 +123,7 @@ describe("OnExtensionUpdateAvailableService", () => {
123
123
  expect(browser.runtime.reload).not.toHaveBeenCalled();
124
124
  await PostLogoutService.exec();
125
125
  // Waiting all promises has been finished
126
- await Promise.resolve();
127
- await Promise.resolve();
128
- await Promise.resolve();
129
- await Promise.resolve();
130
- await Promise.resolve();
126
+ await new Promise((resolve) => setTimeout(resolve, 0));
131
127
  // expectation
132
128
  expect(webIntegrationPortWrapper.emit).toHaveBeenCalledWith("passbolt.content-script.destroy");
133
129
  expect(webIntegrationPortWrapper.emit).toHaveBeenCalledTimes(1);
@@ -94,7 +94,7 @@ class GroupUpdateSecretsCryptoService {
94
94
  const secret = new SecretEntity({ resource_id, user_id, data });
95
95
  groupUpdateSecrets.push(secret);
96
96
 
97
- onProgress?.(i18n.t("Encrypting {{counter}}/{{total}}", { counter: i + 1, total: collectionLength }));
97
+ await onProgress?.(i18n.t("Encrypting {{counter}}/{{total}}", { counter: i + 1, total: collectionLength }));
98
98
  }
99
99
 
100
100
  return groupUpdateSecrets;
@@ -34,7 +34,7 @@ import { RequestAddUsersToGroupOffscreenService } from "../../../../chrome-mv3/s
34
34
  * - Updating group
35
35
  * - Done
36
36
  */
37
- const PROGRESS_GOAL = 6;
37
+ const PROGRESS_GOAL = 5;
38
38
 
39
39
  class GroupUpdateService {
40
40
  /**
@@ -100,7 +100,7 @@ describe("GroupUpdateService", () => {
100
100
 
101
101
  //Exepctation for the progressSerivce when there is no crypto involved
102
102
  expect(progressService.start).toHaveBeenCalledTimes(1);
103
- expect(progressService.start).toHaveBeenCalledWith(6, "Initialize");
103
+ expect(progressService.start).toHaveBeenCalledWith(5, "Initialize");
104
104
  expect(progressService.updateGoals).not.toHaveBeenCalled();
105
105
 
106
106
  expect(progressService.finishStep).toHaveBeenCalledTimes(3);
@@ -359,7 +359,7 @@ describe("GroupUpdateService", () => {
359
359
 
360
360
  //Exepctation for the progressSerivce when there is no crypto involved
361
361
  expect(progressService.start).toHaveBeenCalledTimes(1);
362
- expect(progressService.start).toHaveBeenCalledWith(6, "Initialize");
362
+ expect(progressService.start).toHaveBeenCalledWith(5, "Initialize");
363
363
  expect(progressService.updateGoals).not.toHaveBeenCalled();
364
364
 
365
365
  expect(progressService.finishStep).toHaveBeenCalledTimes(5);
@@ -494,7 +494,7 @@ describe("GroupUpdateService", () => {
494
494
 
495
495
  //Exepctation for the progressSerivce when there is no crypto involved
496
496
  expect(progressService.start).toHaveBeenCalledTimes(1);
497
- expect(progressService.start).toHaveBeenCalledWith(6, "Initialize");
497
+ expect(progressService.start).toHaveBeenCalledWith(5, "Initialize");
498
498
  expect(progressService.updateGoals).not.toHaveBeenCalled();
499
499
 
500
500
  expect(progressService.finishStep).toHaveBeenCalledTimes(5);
@@ -21,6 +21,7 @@ import PasswordGeneratorLocalStorage from "../local_storage/passwordGeneratorLoc
21
21
  import PostponeUserSettingInvitationService from "../invitation/postponeUserSettingInvitationService";
22
22
  import PassphraseStorageService from "../session_storage/passphraseStorageService";
23
23
  import SsoKitTemporaryStorageService from "../session_storage/ssoKitTemporaryStorageService";
24
+ import WebauthnSetupCeremonySessionStorageService from "../sessionStorage/webauthnSetupCeremonySessionStorageService";
24
25
  import GetLegacyAccountService from "../account/getLegacyAccountService";
25
26
  import RbacsLocalStorage from "../local_storage/rbacLocalStorage";
26
27
  import User from "../../model/user";
@@ -67,6 +68,7 @@ class LocalStorageService {
67
68
  PasswordGeneratorLocalStorage.flush(),
68
69
  PassphraseStorageService.flush(),
69
70
  SsoKitTemporaryStorageService.flush(),
71
+ WebauthnSetupCeremonySessionStorageService.flush(),
70
72
  KeepSessionAliveService.stop(),
71
73
  LocalStorageService.flushAccountBasedStorages(),
72
74
  ]).then(LocalStorageService.logFlushFailures);
@@ -48,7 +48,7 @@ beforeEach(() => {
48
48
  describe("LocalStorageService", () => {
49
49
  describe("LocalStorageService::flush", () => {
50
50
  it("Should flush all storage (with no account set)", async () => {
51
- expect.assertions(23);
51
+ expect.assertions(24);
52
52
  // spy on
53
53
  jest.spyOn(browser.storage.local, "remove");
54
54
  jest.spyOn(browser.storage.session, "remove");
@@ -68,7 +68,7 @@ describe("LocalStorageService", () => {
68
68
  await LocalStorageService.flush();
69
69
  // expectations
70
70
  expect(browser.storage.local.remove).toHaveBeenCalledTimes(5);
71
- expect(browser.storage.session.remove).toHaveBeenCalledTimes(2);
71
+ expect(browser.storage.session.remove).toHaveBeenCalledTimes(3);
72
72
  expect(browser.alarms.clear).toHaveBeenCalledTimes(2);
73
73
  expect(browser.storage.local.remove).toHaveBeenCalledWith("resources");
74
74
  expect(browser.storage.local.remove).toHaveBeenCalledWith("folders");
@@ -80,6 +80,7 @@ describe("LocalStorageService", () => {
80
80
  expect(browser.alarms.clear).toHaveBeenCalledWith("PassphraseStorageFlush");
81
81
  expect(browser.alarms.clear).toHaveBeenCalledWith("SessionKeepAlive");
82
82
  expect(browser.storage.session.remove).toHaveBeenCalledWith("temp_server_part_sso_kit");
83
+ expect(browser.storage.session.remove).toHaveBeenCalledWith("webauthn-setup-ceremony");
83
84
  expect(GetLegacyAccountService.get).not.toHaveBeenCalled();
84
85
  expect(UserMeLocalStorage.prototype.flush).not.toHaveBeenCalled();
85
86
  expect(MetadataTypesSettingsLocalStorage.prototype.flush).not.toHaveBeenCalled();
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.17.0
13
+ */
14
+ import WebauthnCeremonyError from "../../error/webauthnCeremonyError";
15
+ import WebauthnCredentialCreationOptionsEntity from "../../model/entity/mfa/webauthnCredentialCreationOptionsEntity";
16
+
17
+ /**
18
+ * Checks the creation options received from the API against the local account before they reach the browser.
19
+ * The shape of the options is guaranteed by WebauthnCredentialCreationOptionsEntity.
20
+ */
21
+ class ValidateWebauthnCreationOptionsService {
22
+ /**
23
+ * @param {WebauthnCredentialCreationOptionsEntity} options
24
+ * @param {AccountEntity} account
25
+ * @throws {WebauthnCeremonyError} on the first failing check
26
+ */
27
+ static validate(options, account) {
28
+ const expectedRpId = new URL(account.domain).hostname;
29
+ if (options.rp.id !== expectedRpId) {
30
+ throw new WebauthnCeremonyError(`The relying party id "${options.rp.id}" does not match the account domain.`);
31
+ }
32
+ if (options.user.name !== account.username) {
33
+ throw new WebauthnCeremonyError("The user name does not match the account username.");
34
+ }
35
+ if (WebauthnCredentialCreationOptionsEntity.decodeBase64Url(options.user.id) !== account.userId) {
36
+ throw new WebauthnCeremonyError("The user id does not match the account user id.");
37
+ }
38
+ }
39
+ }
40
+
41
+ export default ValidateWebauthnCreationOptionsService;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.17.0
13
+ */
14
+ import ValidateWebauthnCreationOptionsService from "./validateWebauthnCreationOptionsService";
15
+ import WebauthnCeremonyError from "../../error/webauthnCeremonyError";
16
+ import WebauthnCredentialCreationOptionsEntity from "../../model/entity/mfa/webauthnCredentialCreationOptionsEntity";
17
+ import { defaultWebauthnCredentialCreationOptionsDto } from "../../model/entity/mfa/webauthnCredentialCreationOptionsEntity.test.data";
18
+ import AccountEntity from "../../model/entity/account/accountEntity";
19
+ import { defaultAccountDto } from "../../model/entity/account/accountEntity.test.data";
20
+
21
+ describe("ValidateWebauthnCreationOptionsService", () => {
22
+ const account = new AccountEntity(defaultAccountDto());
23
+ const validate = (data) =>
24
+ ValidateWebauthnCreationOptionsService.validate(
25
+ new WebauthnCredentialCreationOptionsEntity(defaultWebauthnCredentialCreationOptionsDto(data)),
26
+ account,
27
+ );
28
+
29
+ describe("ValidateWebauthnCreationOptionsService::validate", () => {
30
+ it("accepts options matching the account", () => {
31
+ expect.assertions(1);
32
+ expect(() => validate()).not.toThrow();
33
+ });
34
+
35
+ it("rejects a relying party id different from the account domain hostname", () => {
36
+ expect.assertions(1);
37
+ expect(() => validate({ rp: { id: "evil.local", name: "Passbolt" } })).toThrow(WebauthnCeremonyError);
38
+ });
39
+
40
+ it("rejects a user name different from the account username", () => {
41
+ expect.assertions(1);
42
+ const user = { ...defaultWebauthnCredentialCreationOptionsDto().user, name: "betty@passbolt.com" };
43
+ expect(() => validate({ user })).toThrow("The user name does not match the account username.");
44
+ });
45
+
46
+ it("rejects a user id not decoding to the account user id", () => {
47
+ expect.assertions(1);
48
+ const user = { ...defaultWebauthnCredentialCreationOptionsDto().user, id: "bm90LXRoZS11c2VyLWlk" };
49
+ expect(() => validate({ user })).toThrow("The user id does not match the account user id.");
50
+ });
51
+ });
52
+ });
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Passbolt ~ Open source password manager for teams
3
+ * Copyright (c) Passbolt SA (https://www.passbolt.com)
4
+ *
5
+ * Licensed under GNU Affero General Public License version 3 of the or any later version.
6
+ * For full copyright and license information, please see the LICENSE.txt
7
+ * Redistributions of files must retain the above copyright notice.
8
+ *
9
+ * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com)
10
+ * @license https://opensource.org/licenses/AGPL-3.0 AGPL License
11
+ * @link https://www.passbolt.com Passbolt(tm)
12
+ * @since 5.17.0
13
+ */
14
+ import { v4 as uuidv4 } from "uuid";
15
+ import PassboltApiFetchError from "passbolt-styleguide/src/shared/lib/Error/PassboltApiFetchError";
16
+ import WebauthnApiService from "../api/mfa/webauthnApiService";
17
+ import WebauthnSetupCeremonySessionStorageService from "../sessionStorage/webauthnSetupCeremonySessionStorageService";
18
+ import WebauthnCredentialCreationOptionsEntity from "../../model/entity/mfa/webauthnCredentialCreationOptionsEntity";
19
+ import WebauthnRegistrationResponseEntity from "../../model/entity/mfa/webauthnRegistrationResponseEntity";
20
+ import WebauthnSetupCeremonyEntity from "../../model/entity/mfa/webauthnSetupCeremonyEntity";
21
+ import ValidateWebauthnCreationOptionsService from "./validateWebauthnCreationOptionsService";
22
+ import WorkerService from "../worker/workerService";
23
+ import WebauthnCeremonyNotFoundError from "../../error/webauthnCeremonyNotFoundError";
24
+ import WebauthnCeremonyAbortedError from "../../error/webauthnCeremonyAbortedError";
25
+
26
+ const APP_BOOTSTRAP_WORKER = "AppBootstrap";
27
+ const APP_WORKER = "App";
28
+
29
+ export const RUN_CEREMONY_EVENT = "passbolt.app-bootstrap.run-webauthn-ceremony";
30
+ export const ABORT_CEREMONY_EVENT = "passbolt.app-bootstrap.abort-webauthn-ceremony";
31
+ export const CEREMONY_DONE_EVENT = "passbolt.mfa-setup.webauthn-ceremony-done";
32
+
33
+ /**
34
+ * Runs the restartable WebAuthn setup ceremony: begin and finish against the API, create() delegated to the
35
+ * AppBootstrap content script, state kept in session storage so a service worker restart does not lose it.
36
+ * A single ceremony is pending at a time; beginning a new one aborts the previous one.
37
+ */
38
+ class WebauthnSetupCeremonyService {
39
+ /**
40
+ * @param {ApiClientOptions} apiClientOptions
41
+ * @param {AccountEntity} account
42
+ */
43
+ constructor(apiClientOptions, account) {
44
+ this.account = account;
45
+ this.webauthnApiService = new WebauthnApiService(apiClientOptions);
46
+ }
47
+
48
+ /**
49
+ * Begin a ceremony for a tab and hand the creation options to its content script.
50
+ * An unexpired ceremony pending on any tab is aborted and replaced.
51
+ * @param {number} tabId
52
+ * @throws {EntityValidationError} if the creation options are malformed
53
+ * @throws {WebauthnCeremonyError} if the creation options do not match the account
54
+ * @returns {Promise<void>}
55
+ */
56
+ async begin(tabId) {
57
+ const response = await this.webauthnApiService.begin();
58
+ const { handle, credentialCreationOptions } = response.body;
59
+ const options = new WebauthnCredentialCreationOptionsEntity(credentialCreationOptions);
60
+ ValidateWebauthnCreationOptionsService.validate(options, this.account);
61
+ const worker = await WorkerService.get(APP_BOOTSTRAP_WORKER, tabId);
62
+ const ceremony = new WebauthnSetupCeremonyEntity({
63
+ id: uuidv4(),
64
+ tab_id: tabId,
65
+ handle: handle,
66
+ started_at: new Date().toISOString(),
67
+ });
68
+ const previous = await WebauthnSetupCeremonySessionStorageService.get();
69
+ if (previous && !previous.isExpired) {
70
+ await this.emitAbort(previous);
71
+ if (previous.tabId !== tabId) {
72
+ await this.emitSuperseded(previous);
73
+ }
74
+ }
75
+ await WebauthnSetupCeremonySessionStorageService.set(ceremony);
76
+ try {
77
+ worker.port.emit(RUN_CEREMONY_EVENT, { id: ceremony.id, options: options.toDto() });
78
+ } catch (error) {
79
+ await WebauthnSetupCeremonySessionStorageService.flush();
80
+ throw error;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Handle the ceremony result sent by the content script and forward the outcome to the App worker.
86
+ * A result for an expired ceremony is reported to the App worker as an error.
87
+ * @param {number} tabId the tab the result came from
88
+ * @param {object} resultDto
89
+ * @param {boolean} resultDto.success true if the webauthn ceremony succeeded, false otherwise
90
+ * @param {{id: string, credential: object, aaguid: string|null}|{name: string, message: string}} [resultDto.result] the ceremony result details
91
+ * @throws {WebauthnCeremonyNotFoundError} if no ceremony is pending or the result does not match it (id or tab)
92
+ * @returns {Promise<void>}
93
+ */
94
+ async handleResult(tabId, resultDto) {
95
+ const ceremony = await WebauthnSetupCeremonySessionStorageService.get();
96
+ if (!ceremony) {
97
+ throw new WebauthnCeremonyNotFoundError();
98
+ }
99
+
100
+ const { success, result: webauthnCeremonyResult, result: webauthnCeremonyError } = resultDto;
101
+ if (ceremony.tabId !== tabId || (success && ceremony.id !== webauthnCeremonyResult.id)) {
102
+ throw new WebauthnCeremonyNotFoundError("The result does not match the pending passkey ceremony.");
103
+ }
104
+
105
+ if (ceremony.isExpired) {
106
+ const error = new WebauthnCeremonyNotFoundError("The pending passkey ceremony has expired.");
107
+ await this._emitCeremonyDoneResponse(tabId, error);
108
+ return;
109
+ }
110
+
111
+ if (!success) {
112
+ await this._emitCeremonyDoneResponse(tabId, webauthnCeremonyError);
113
+ return;
114
+ }
115
+
116
+ const credential = new WebauthnRegistrationResponseEntity(webauthnCeremonyResult.credential);
117
+ const completed = new WebauthnSetupCeremonyEntity({
118
+ ...ceremony.toDto(),
119
+ credential: credential.toDto(),
120
+ aaguid: webauthnCeremonyResult.aaguid ?? null,
121
+ });
122
+ await WebauthnSetupCeremonySessionStorageService.set(completed);
123
+ await this._emitCeremonyDoneResponse(tabId, { aaguid: completed.aaguid }, true);
124
+ }
125
+
126
+ /**
127
+ * Sends a `webauthn ceremony done` response back to the content script
128
+ * @param {number} tabId the tab id where to find the worker to answer to
129
+ * @param {object|error} result the data to send to the worker
130
+ * @param {boolean} success should the content script treat the response as a success or not
131
+ * @returns {Promise<void>}
132
+ */
133
+ async _emitCeremonyDoneResponse(tabId, result, success = false) {
134
+ if (!success) {
135
+ await WebauthnSetupCeremonySessionStorageService.flush();
136
+ }
137
+
138
+ const appWorker = await WorkerService.get(APP_WORKER, tabId);
139
+ const responseDto = { success, result };
140
+ await appWorker.port.emit(CEREMONY_DONE_EVENT, responseDto);
141
+ }
142
+
143
+ /**
144
+ * Finish the ceremony with the stored credential. The record is kept on a name error so the finish can be
145
+ * retried with another name; any other error ends the ceremony.
146
+ * @param {number} tabId
147
+ * @param {string} name the credential name chosen by the user
148
+ * @throws {WebauthnCeremonyNotFoundError} if no ceremony with a credential is pending for the tab, or if the API
149
+ * rejected the handle as expired
150
+ * @returns {Promise<{verified: string}>} the finish response body
151
+ */
152
+ async finish(tabId, name) {
153
+ const ceremony = await this.getPendingCeremony();
154
+ if (ceremony.tabId !== tabId || !ceremony.hasCredential) {
155
+ throw new WebauthnCeremonyNotFoundError();
156
+ }
157
+ let response;
158
+ try {
159
+ response = await this.webauthnApiService.finish({
160
+ handle: ceremony.handle,
161
+ credential: ceremony.credential,
162
+ name: name,
163
+ });
164
+ } catch (error) {
165
+ if (this.isNameError(error)) {
166
+ throw error;
167
+ }
168
+ await WebauthnSetupCeremonySessionStorageService.flush();
169
+ if (this.isExpiredHandleError(error)) {
170
+ throw new WebauthnCeremonyNotFoundError("The pending passkey ceremony has expired.");
171
+ }
172
+ throw error;
173
+ }
174
+ await WebauthnSetupCeremonySessionStorageService.flush();
175
+ return response.body;
176
+ }
177
+
178
+ /**
179
+ * Is the finish error a validation error on the credential name
180
+ * @private
181
+ * @param {Error} error
182
+ * @returns {boolean}
183
+ */
184
+ isNameError(error) {
185
+ return error instanceof PassboltApiFetchError && error.data?.code === 400 && Boolean(error.data.body?.name);
186
+ }
187
+
188
+ /**
189
+ * Is the finish error the API rejecting the ceremony handle as expired
190
+ * @private
191
+ * @param {Error} error
192
+ * @returns {boolean}
193
+ */
194
+ isExpiredHandleError(error) {
195
+ return (
196
+ error instanceof PassboltApiFetchError && error.data?.code === 400 && Boolean(error.data.body?.token?.expired)
197
+ );
198
+ }
199
+
200
+ /**
201
+ * Abort the ceremony pending on a tab: drop the record and close the prompt in the content script.
202
+ * @param {number} tabId
203
+ * @returns {Promise<void>}
204
+ */
205
+ async abort(tabId) {
206
+ const ceremony = await WebauthnSetupCeremonySessionStorageService.get();
207
+ if (ceremony?.tabId !== tabId) {
208
+ return;
209
+ }
210
+ await WebauthnSetupCeremonySessionStorageService.flush();
211
+ await this.emitAbort(ceremony);
212
+ }
213
+
214
+ /**
215
+ * Tell the app worker of a superseded ceremony's tab that its ceremony ended, since handleResult drops the
216
+ * abort result the content script reports for it; an unreachable worker is logged, not thrown.
217
+ * @private
218
+ * @param {WebauthnSetupCeremonyEntity} ceremony
219
+ * @returns {Promise<void>}
220
+ */
221
+ async emitSuperseded(ceremony) {
222
+ const error = new WebauthnCeremonyAbortedError("The passkey ceremony was superseded by a new one.");
223
+ try {
224
+ const appWorker = await WorkerService.get(APP_WORKER, ceremony.tabId);
225
+ appWorker.port.emit(CEREMONY_DONE_EVENT, { success: false, result: error });
226
+ } catch (error) {
227
+ console.warn("WebauthnSetupCeremonyService: could not reach the app worker of the superseded ceremony.", error);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Tell the content script of the ceremony's tab to abort the ceremony; an unreachable content script is logged,
233
+ * not thrown.
234
+ * @private
235
+ * @param {WebauthnSetupCeremonyEntity} ceremony
236
+ * @returns {Promise<void>}
237
+ */
238
+ async emitAbort(ceremony) {
239
+ try {
240
+ const worker = await WorkerService.get(APP_BOOTSTRAP_WORKER, ceremony.tabId);
241
+ worker.port.emit(ABORT_CEREMONY_EVENT, { id: ceremony.id });
242
+ } catch (error) {
243
+ console.warn("WebauthnSetupCeremonyService: could not reach the content script to abort the ceremony.", error);
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Load the pending ceremony, removing an expired one.
249
+ * @private
250
+ * @throws {WebauthnCeremonyNotFoundError} if there is no unexpired ceremony
251
+ * @returns {Promise<WebauthnSetupCeremonyEntity>}
252
+ */
253
+ async getPendingCeremony() {
254
+ const ceremony = await WebauthnSetupCeremonySessionStorageService.get();
255
+ if (!ceremony) {
256
+ throw new WebauthnCeremonyNotFoundError();
257
+ }
258
+ if (ceremony.isExpired) {
259
+ await WebauthnSetupCeremonySessionStorageService.flush();
260
+ throw new WebauthnCeremonyNotFoundError("The pending passkey ceremony has expired.");
261
+ }
262
+ return ceremony;
263
+ }
264
+ }
265
+
266
+ export default WebauthnSetupCeremonyService;