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
@@ -0,0 +1,235 @@
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 EntityV2 from "passbolt-styleguide/src/shared/models/entity/abstract/entityV2";
15
+ import EntityValidationError from "passbolt-styleguide/src/shared/models/entity/abstract/entityValidationError";
16
+
17
+ // COSE algorithm identifiers ES256 and RS256, https://www.iana.org/assignments/cose#algorithms
18
+ const ALLOWED_ALGORITHMS = [-7, -257];
19
+ // WebAuthn recommends at least 16 bytes, https://www.w3.org/TR/webauthn-3/#sctn-cryptographic-challenges
20
+ const CHALLENGE_MIN_BYTES = 16;
21
+
22
+ /**
23
+ * PublicKeyCredentialCreationOptionsJSON as returned by the API begin endpoint.
24
+ * The build rules check the nested content; ValidateWebauthnCreationOptionsService checks it against the account.
25
+ */
26
+ class WebauthnCredentialCreationOptionsEntity extends EntityV2 {
27
+ /**
28
+ * Get the entity schema
29
+ * @returns {Object} schema
30
+ */
31
+ static getSchema() {
32
+ return {
33
+ type: "object",
34
+ required: ["rp", "user", "challenge", "pubKeyCredParams", "attestation"],
35
+ properties: {
36
+ rp: {
37
+ type: "object",
38
+ properties: {
39
+ id: {
40
+ type: "string",
41
+ minLength: 1,
42
+ },
43
+ name: {
44
+ type: "string",
45
+ minLength: 1,
46
+ },
47
+ },
48
+ },
49
+ user: {
50
+ type: "object",
51
+ properties: {
52
+ id: {
53
+ type: "string",
54
+ minLength: 1,
55
+ // format: "x-base64", // "x-" prefixed format are non JSON Schema standards
56
+ },
57
+ name: {
58
+ type: "string",
59
+ minLength: 1,
60
+ },
61
+ displayName: {
62
+ type: "string",
63
+ minLength: 1,
64
+ },
65
+ },
66
+ },
67
+ challenge: {
68
+ type: "string",
69
+ minLength: 1,
70
+ // format: "x-base64",
71
+ },
72
+ pubKeyCredParams: {
73
+ type: "array",
74
+ minItems: 1,
75
+ items: {
76
+ type: "object",
77
+ properties: {
78
+ type: {
79
+ type: "string",
80
+ enum: ["public-key"],
81
+ },
82
+ alg: {
83
+ type: "number",
84
+ enum: ALLOWED_ALGORITHMS,
85
+ },
86
+ },
87
+ },
88
+ },
89
+ timeout: {
90
+ type: "integer",
91
+ },
92
+ excludeCredentials: {
93
+ type: "array",
94
+ },
95
+ authenticatorSelection: {
96
+ type: "object",
97
+ },
98
+ attestation: {
99
+ type: "string",
100
+ enum: ["none"],
101
+ },
102
+ hints: {
103
+ type: "array",
104
+ },
105
+ extensions: {
106
+ type: "object",
107
+ },
108
+ },
109
+ };
110
+ }
111
+
112
+ /**
113
+ * @inheritDoc
114
+ * @throws {EntityValidationError} If a relying party or user field is missing or empty.
115
+ * @throws {EntityValidationError} If the user id is not base64url.
116
+ * @throws {EntityValidationError} If the challenge is not base64url of at least 16 bytes.
117
+ * @throws {EntityValidationError} If a public key credential parameter is not ES256 or RS256.
118
+ */
119
+ validateBuildRules() {
120
+ const { rp, user, challenge, pubKeyCredParams } = this._props;
121
+ this.assertNonEmptyString("rp.id", rp.id);
122
+ this.assertNonEmptyString("rp.name", rp.name);
123
+ this.assertNonEmptyString("user.id", user.id);
124
+ this.assertNonEmptyString("user.name", user.name);
125
+ this.assertNonEmptyString("user.displayName", user.displayName);
126
+ this.assertBase64Url("user.id", user.id);
127
+ this.assertChallengeLength(challenge);
128
+ this.assertSupportedAlgorithms(pubKeyCredParams);
129
+ }
130
+
131
+ /**
132
+ * Assert that the challenge is base64url of at least the WebAuthn minimum length.
133
+ *
134
+ * @param {string} challenge The base64url challenge
135
+ * @throws {EntityValidationError} If the challenge is not decodable or too short.
136
+ */
137
+ assertChallengeLength(challenge) {
138
+ if (this.assertBase64Url("challenge", challenge).length < CHALLENGE_MIN_BYTES) {
139
+ const error = new EntityValidationError();
140
+ error.addError("challenge", "min_bytes", `The challenge should be at least ${CHALLENGE_MIN_BYTES} bytes.`);
141
+ throw error;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Assert that the credential parameters offer only supported public key algorithms.
147
+ *
148
+ * @param {Array<object>} pubKeyCredParams The [{type, alg}] list
149
+ * @throws {EntityValidationError} If the list is empty or contains an unsupported type or algorithm.
150
+ */
151
+ assertSupportedAlgorithms(pubKeyCredParams) {
152
+ const paramsAreValid =
153
+ pubKeyCredParams.length > 0 &&
154
+ pubKeyCredParams.every((p) => p?.type === "public-key" && ALLOWED_ALGORITHMS.includes(p?.alg));
155
+ if (!paramsAreValid) {
156
+ const error = new EntityValidationError();
157
+ error.addError(
158
+ "pubKeyCredParams",
159
+ "unsupported_alg",
160
+ "The pubKeyCredParams should only contain supported public key algorithms.",
161
+ );
162
+ throw error;
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Assert that the given nested prop is a non empty string.
168
+ *
169
+ * @param {string} propName The dotted property path, example: rp.id
170
+ * @param {*} propValue The property value
171
+ * @throws {EntityValidationError} If the value is not a non empty string.
172
+ */
173
+ assertNonEmptyString(propName, propValue) {
174
+ if (typeof propValue !== "string" || propValue.length === 0) {
175
+ const error = new EntityValidationError();
176
+ error.addError(propName, "required", `The ${propName} should be a non empty string.`);
177
+ throw error;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Assert that the given prop is base64url and return its decoded value.
183
+ *
184
+ * @param {string} propName The property path, example: user.id
185
+ * @param {string} propValue The property value
186
+ * @returns {string} The decoded binary string
187
+ * @throws {EntityValidationError} If the value is not decodable.
188
+ */
189
+ assertBase64Url(propName, propValue) {
190
+ try {
191
+ return WebauthnCredentialCreationOptionsEntity.decodeBase64Url(propValue);
192
+ } catch {
193
+ const error = new EntityValidationError();
194
+ error.addError(propName, "base64url", `The ${propName} should be base64url.`);
195
+ throw error;
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Decode a base64url string to a binary string.
201
+ * @param {string} value
202
+ * @returns {string}
203
+ * @throws {DOMException} If the value is not decodable.
204
+ */
205
+ static decodeBase64Url(value) {
206
+ const base64 = value.replace(/-/g, "+").replace(/_/g, "/");
207
+ return atob(base64 + "=".repeat((4 - (base64.length % 4)) % 4));
208
+ }
209
+
210
+ /**
211
+ * The relying party {id, name}
212
+ * @returns {object}
213
+ */
214
+ get rp() {
215
+ return this._props.rp;
216
+ }
217
+
218
+ /**
219
+ * The user {id, name, displayName}
220
+ * @returns {object}
221
+ */
222
+ get user() {
223
+ return this._props.user;
224
+ }
225
+
226
+ /**
227
+ * The accepted credential parameters [{type, alg}]
228
+ * @returns {Array<object>}
229
+ */
230
+ get pubKeyCredParams() {
231
+ return this._props.pubKeyCredParams;
232
+ }
233
+ }
234
+
235
+ export default WebauthnCredentialCreationOptionsEntity;
@@ -0,0 +1,42 @@
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
+
15
+ /**
16
+ * Mirrors the API begin response body for the default account (domain https://passbolt.local, user ada).
17
+ * user.id is the base64url encoding of the account user id string.
18
+ */
19
+ export const defaultWebauthnCredentialCreationOptionsDto = (data = {}) => ({
20
+ rp: {
21
+ id: "passbolt.local",
22
+ name: "Passbolt",
23
+ },
24
+ user: {
25
+ id: "Zjg0ODI3N2MtNTM5OC01OGY4LWE4MmEtNzIzOTdhZjJkNDUw",
26
+ name: "ada@passbolt.com",
27
+ displayName: "Ada Lovelace",
28
+ },
29
+ challenge: "dGhpcy1pcy1hLWNoYWxsZW5nZS1vZi0zMi1ieXRlcw",
30
+ pubKeyCredParams: [
31
+ { type: "public-key", alg: -7 },
32
+ { type: "public-key", alg: -257 },
33
+ ],
34
+ timeout: 300000,
35
+ excludeCredentials: [],
36
+ authenticatorSelection: {
37
+ residentKey: "discouraged",
38
+ userVerification: "preferred",
39
+ },
40
+ attestation: "none",
41
+ ...data,
42
+ });
@@ -0,0 +1,152 @@
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 EntityValidationError from "passbolt-styleguide/src/shared/models/entity/abstract/entityValidationError";
15
+ import EntitySchema from "passbolt-styleguide/src/shared/models/entity/abstract/entitySchema";
16
+ import * as assertEntityProperty from "passbolt-styleguide/test/assert/assertEntityProperty";
17
+ import WebauthnCredentialCreationOptionsEntity from "./webauthnCredentialCreationOptionsEntity";
18
+ import { defaultWebauthnCredentialCreationOptionsDto } from "./webauthnCredentialCreationOptionsEntity.test.data";
19
+
20
+ describe("WebauthnCredentialCreationOptionsEntity", () => {
21
+ describe("WebauthnCredentialCreationOptionsEntity::getSchema", () => {
22
+ it("schema must validate", () => {
23
+ EntitySchema.validateSchema(
24
+ WebauthnCredentialCreationOptionsEntity.name,
25
+ WebauthnCredentialCreationOptionsEntity.getSchema(),
26
+ );
27
+ });
28
+
29
+ it("validates rp property", () => {
30
+ assertEntityProperty.required(WebauthnCredentialCreationOptionsEntity, "rp");
31
+ });
32
+
33
+ it("validates user property", () => {
34
+ assertEntityProperty.required(WebauthnCredentialCreationOptionsEntity, "user");
35
+ });
36
+
37
+ it("validates challenge property", () => {
38
+ assertEntityProperty.string(WebauthnCredentialCreationOptionsEntity, "challenge");
39
+ assertEntityProperty.minLength(WebauthnCredentialCreationOptionsEntity, "challenge", 1);
40
+ assertEntityProperty.required(WebauthnCredentialCreationOptionsEntity, "challenge");
41
+ });
42
+
43
+ it("validates pubKeyCredParams property", () => {
44
+ assertEntityProperty.array(WebauthnCredentialCreationOptionsEntity, "pubKeyCredParams");
45
+ assertEntityProperty.required(WebauthnCredentialCreationOptionsEntity, "pubKeyCredParams");
46
+ });
47
+
48
+ it("validates timeout property", () => {
49
+ assertEntityProperty.integer(WebauthnCredentialCreationOptionsEntity, "timeout");
50
+ assertEntityProperty.notRequired(WebauthnCredentialCreationOptionsEntity, "timeout");
51
+ });
52
+
53
+ it("validates attestation property", () => {
54
+ assertEntityProperty.enumeration(WebauthnCredentialCreationOptionsEntity, "attestation", ["none"], ["direct"]);
55
+ assertEntityProperty.required(WebauthnCredentialCreationOptionsEntity, "attestation");
56
+ });
57
+ });
58
+
59
+ describe("WebauthnCredentialCreationOptionsEntity::constructor", () => {
60
+ it("works if valid DTO is provided", () => {
61
+ expect.assertions(4);
62
+ const dto = defaultWebauthnCredentialCreationOptionsDto();
63
+ const entity = new WebauthnCredentialCreationOptionsEntity(dto);
64
+ expect(entity.toDto()).toEqual(dto);
65
+ expect(entity.rp).toEqual(dto.rp);
66
+ expect(entity.user).toEqual(dto.user);
67
+ expect(entity.pubKeyCredParams).toEqual(dto.pubKeyCredParams);
68
+ });
69
+
70
+ it.each([
71
+ ["rp", "id"],
72
+ ["rp", "name"],
73
+ ["user", "id"],
74
+ ["user", "name"],
75
+ ["user", "displayName"],
76
+ ])("throws if %s.%s is not a non empty string", (prop, field) => {
77
+ expect.assertions(2);
78
+ const dto = defaultWebauthnCredentialCreationOptionsDto();
79
+ dto[prop][field] = "";
80
+ try {
81
+ new WebauthnCredentialCreationOptionsEntity(dto);
82
+ } catch (error) {
83
+ expect(error).toBeInstanceOf(EntityValidationError);
84
+ expect(error.hasError(`${prop}.${field}`, "required")).toBe(true);
85
+ }
86
+ });
87
+
88
+ it.each([
89
+ [[]],
90
+ [[{ type: "password", alg: -7 }]],
91
+ [[{ type: "public-key", alg: -8 }]],
92
+ [
93
+ [
94
+ { type: "public-key", alg: -7 },
95
+ { type: "public-key", alg: -8 },
96
+ ],
97
+ ],
98
+ ])("throws on unsupported public key credential parameters %j", (pubKeyCredParams) => {
99
+ expect.assertions(2);
100
+ try {
101
+ new WebauthnCredentialCreationOptionsEntity(defaultWebauthnCredentialCreationOptionsDto({ pubKeyCredParams }));
102
+ } catch (error) {
103
+ expect(error).toBeInstanceOf(EntityValidationError);
104
+ expect(error.hasError("pubKeyCredParams", "unsupported_alg")).toBe(true);
105
+ }
106
+ });
107
+
108
+ it("throws if user.id is not base64url", () => {
109
+ expect.assertions(2);
110
+ const user = { ...defaultWebauthnCredentialCreationOptionsDto().user, id: "%%%" };
111
+ try {
112
+ new WebauthnCredentialCreationOptionsEntity(defaultWebauthnCredentialCreationOptionsDto({ user }));
113
+ } catch (error) {
114
+ expect(error).toBeInstanceOf(EntityValidationError);
115
+ expect(error.hasError("user.id", "base64url")).toBe(true);
116
+ }
117
+ });
118
+
119
+ it("throws if the challenge is not base64url", () => {
120
+ expect.assertions(2);
121
+ try {
122
+ new WebauthnCredentialCreationOptionsEntity(defaultWebauthnCredentialCreationOptionsDto({ challenge: "%%%" }));
123
+ } catch (error) {
124
+ expect(error).toBeInstanceOf(EntityValidationError);
125
+ expect(error.hasError("challenge", "base64url")).toBe(true);
126
+ }
127
+ });
128
+
129
+ it("throws if the challenge is shorter than 16 bytes", () => {
130
+ expect.assertions(2);
131
+ const challenge = "dGhpcy1pcy1zaG9ydA";
132
+ try {
133
+ new WebauthnCredentialCreationOptionsEntity(defaultWebauthnCredentialCreationOptionsDto({ challenge }));
134
+ } catch (error) {
135
+ expect(error).toBeInstanceOf(EntityValidationError);
136
+ expect(error.hasError("challenge", "min_bytes")).toBe(true);
137
+ }
138
+ });
139
+ });
140
+
141
+ describe("WebauthnCredentialCreationOptionsEntity::decodeBase64Url", () => {
142
+ it("decodes a base64url string without padding", () => {
143
+ expect.assertions(1);
144
+ expect(WebauthnCredentialCreationOptionsEntity.decodeBase64Url("YWRhLT4_Xz4")).toBe("ada->?_>");
145
+ });
146
+
147
+ it("throws when the string is not decodable", () => {
148
+ expect.assertions(1);
149
+ expect(() => WebauthnCredentialCreationOptionsEntity.decodeBase64Url("%%%")).toThrow(DOMException);
150
+ });
151
+ });
152
+ });
@@ -0,0 +1,72 @@
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 EntityV2 from "passbolt-styleguide/src/shared/models/entity/abstract/entityV2";
15
+ import EntityValidationError from "passbolt-styleguide/src/shared/models/entity/abstract/entityValidationError";
16
+
17
+ /**
18
+ * RegistrationResponseJSON as produced by PublicKeyCredential.toJSON() after a create() ceremony.
19
+ */
20
+ class WebauthnRegistrationResponseEntity extends EntityV2 {
21
+ /**
22
+ * Get the entity schema
23
+ * @returns {Object} schema
24
+ */
25
+ static getSchema() {
26
+ return {
27
+ type: "object",
28
+ required: ["id", "rawId", "type", "response"],
29
+ properties: {
30
+ id: {
31
+ type: "string",
32
+ minLength: 1,
33
+ },
34
+ rawId: {
35
+ type: "string",
36
+ minLength: 1,
37
+ },
38
+ type: {
39
+ type: "string",
40
+ enum: ["public-key"],
41
+ },
42
+ response: {
43
+ type: "object",
44
+ },
45
+ authenticatorAttachment: {
46
+ type: "string",
47
+ nullable: true,
48
+ },
49
+ clientExtensionResults: {
50
+ type: "object",
51
+ },
52
+ },
53
+ };
54
+ }
55
+
56
+ /**
57
+ * @inheritDoc
58
+ * @throws {EntityValidationError} If response.clientDataJSON or response.attestationObject is missing or empty.
59
+ */
60
+ validateBuildRules() {
61
+ const response = this._props.response;
62
+ for (const field of ["clientDataJSON", "attestationObject"]) {
63
+ if (typeof response[field] !== "string" || response[field].length === 0) {
64
+ const error = new EntityValidationError();
65
+ error.addError(`response.${field}`, "required", `The response.${field} should be a non empty string.`);
66
+ throw error;
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ export default WebauthnRegistrationResponseEntity;
@@ -0,0 +1,26 @@
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
+ export const defaultWebauthnRegistrationResponseDto = (data = {}) => ({
15
+ id: "AQIDBAUGBwgJCgsMDQ4PEA",
16
+ rawId: "AQIDBAUGBwgJCgsMDQ4PEA",
17
+ type: "public-key",
18
+ response: {
19
+ clientDataJSON: "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIn0",
20
+ attestationObject: "o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVg",
21
+ transports: ["internal"],
22
+ },
23
+ authenticatorAttachment: "platform",
24
+ clientExtensionResults: {},
25
+ ...data,
26
+ });
@@ -0,0 +1,83 @@
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 EntitySchema from "passbolt-styleguide/src/shared/models/entity/abstract/entitySchema";
15
+ import EntityValidationError from "passbolt-styleguide/src/shared/models/entity/abstract/entityValidationError";
16
+ import * as assertEntityProperty from "passbolt-styleguide/test/assert/assertEntityProperty";
17
+ import WebauthnRegistrationResponseEntity from "./webauthnRegistrationResponseEntity";
18
+ import { defaultWebauthnRegistrationResponseDto } from "./webauthnRegistrationResponseEntity.test.data";
19
+
20
+ describe("WebauthnRegistrationResponseEntity", () => {
21
+ describe("WebauthnRegistrationResponseEntity::getSchema", () => {
22
+ it("schema must validate", () => {
23
+ EntitySchema.validateSchema(
24
+ WebauthnRegistrationResponseEntity.name,
25
+ WebauthnRegistrationResponseEntity.getSchema(),
26
+ );
27
+ });
28
+
29
+ it("validates id property", () => {
30
+ assertEntityProperty.string(WebauthnRegistrationResponseEntity, "id");
31
+ assertEntityProperty.minLength(WebauthnRegistrationResponseEntity, "id", 1);
32
+ assertEntityProperty.required(WebauthnRegistrationResponseEntity, "id");
33
+ });
34
+
35
+ it("validates rawId property", () => {
36
+ assertEntityProperty.string(WebauthnRegistrationResponseEntity, "rawId");
37
+ assertEntityProperty.required(WebauthnRegistrationResponseEntity, "rawId");
38
+ });
39
+
40
+ it("validates type property", () => {
41
+ assertEntityProperty.enumeration(WebauthnRegistrationResponseEntity, "type", ["public-key"], ["password"]);
42
+ assertEntityProperty.required(WebauthnRegistrationResponseEntity, "type");
43
+ });
44
+
45
+ it("validates response property", () => {
46
+ assertEntityProperty.required(WebauthnRegistrationResponseEntity, "response");
47
+ });
48
+
49
+ it("validates authenticatorAttachment property", () => {
50
+ assertEntityProperty.string(WebauthnRegistrationResponseEntity, "authenticatorAttachment");
51
+ assertEntityProperty.nullable(WebauthnRegistrationResponseEntity, "authenticatorAttachment");
52
+ assertEntityProperty.notRequired(WebauthnRegistrationResponseEntity, "authenticatorAttachment");
53
+ });
54
+ });
55
+
56
+ describe("WebauthnRegistrationResponseEntity::constructor", () => {
57
+ it("works if valid DTO is provided", () => {
58
+ expect.assertions(1);
59
+ const dto = defaultWebauthnRegistrationResponseDto();
60
+ const entity = new WebauthnRegistrationResponseEntity(dto);
61
+ expect(entity.toDto()).toEqual(dto);
62
+ });
63
+
64
+ it.each(["clientDataJSON", "attestationObject"])("throws if response.%s is missing", (field) => {
65
+ expect.assertions(2);
66
+ const dto = defaultWebauthnRegistrationResponseDto();
67
+ delete dto.response[field];
68
+ try {
69
+ new WebauthnRegistrationResponseEntity(dto);
70
+ } catch (error) {
71
+ expect(error).toBeInstanceOf(EntityValidationError);
72
+ expect(error.hasError(`response.${field}`, "required")).toBe(true);
73
+ }
74
+ });
75
+
76
+ it("throws if response.clientDataJSON is empty", () => {
77
+ expect.assertions(1);
78
+ const dto = defaultWebauthnRegistrationResponseDto();
79
+ dto.response.clientDataJSON = "";
80
+ expect(() => new WebauthnRegistrationResponseEntity(dto)).toThrow(EntityValidationError);
81
+ });
82
+ });
83
+ });