From 1800def4a716154c77065ec93233ee9b1d5a5edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Loegel?= Date: Fri, 17 May 2024 15:28:53 +0200 Subject: [PATCH] PB-33597 - As a user running an instance serving an invalid certificate I cannot install passbolt extension using an API < v3 --- .../background_page/model/setup/setupModel.js | 39 ++----- .../service/api/setup/setupService.js | 102 ------------------ 2 files changed, 10 insertions(+), 131 deletions(-) diff --git a/src/all/background_page/model/setup/setupModel.js b/src/all/background_page/model/setup/setupModel.js index 048d9716..87b3c65e 100644 --- a/src/all/background_page/model/setup/setupModel.js +++ b/src/all/background_page/model/setup/setupModel.js @@ -41,7 +41,7 @@ class SetupModel { * @throws {Error} if options are invalid or API error */ async startSetup(userId, authenticationTokenToken) { - let user, accountRecoveryOrganizationPolicy, userDto, accountRecoveryOrganizationPolicyDto, userPassphrasePoliciesDto, userPassphrasePolicies; + let user, accountRecoveryOrganizationPolicy, userPassphrasePolicies; if (!Validator.isUUID(userId)) { throw new TypeError("userId should be a valid uuid."); @@ -50,20 +50,10 @@ class SetupModel { throw new TypeError("authenticationTokenToken should be a valid uuid."); } - try { - const result = await this.setupService.findSetupInfo(userId, authenticationTokenToken); - userDto = result?.user; - accountRecoveryOrganizationPolicyDto = result?.account_recovery_organization_policy; - userPassphrasePoliciesDto = result?.user_passphrase_policy; - } catch (error) { - // If the entry point doesn't exist or return a 500, the API version is } */ async startRecover(userId, authenticationTokenToken) { - let user, userDto, userPassphrasePoliciesDto, userPassphrasePolicies; + let user, userPassphrasePolicies; if (!Validator.isUUID(userId)) { throw new TypeError("userId should be a valid uuid."); @@ -98,19 +88,10 @@ class SetupModel { throw new TypeError("authenticationTokenToken should be a valid uuid."); } - try { - const result = await this.setupService.findRecoverInfo(userId, authenticationTokenToken); - userDto = result?.user; - userPassphrasePoliciesDto = result?.user_passphrase_policy; - } catch (error) { - // If the entry point doesn't exist or return a 500, the API version is } response body - * @throws {Error} if options are invalid or API error - * @deprecated will be removed with v4 - */ - async findLegacySetupInfo(userId, token) { - this.assertValidId(userId); - this.assertValidId(token); - - const url = new URL(`${this.apiClient.baseUrl}/install/${userId}/${token}`); - let response, responseHtml, username, firstName, lastName; - try { - response = await fetch(url.toString()); - } catch (error) { - if (navigator.onLine) { - // Catch Network error such as bad certificate or server unreachable. - throw new PassboltServiceUnavailableError("Unable to reach the server, an unexpected error occurred"); - } else { - // Network connection lost. - throw new PassboltServiceUnavailableError("Unable to reach the server, you are not connected to the network"); - } - } - - try { - responseHtml = await response.text(); - const parser = new DOMParser(); - const parsedHtml = parser.parseFromString(responseHtml, 'text/html'); - username = parsedHtml.getElementById('js_setup_user_username').value; - firstName = parsedHtml.getElementById('js_setup_user_first_name').value; - lastName = parsedHtml.getElementById('js_setup_user_last_name').value; - } catch (error) { - /* - * If the response cannot be parsed, it's not a Passbolt API response. - * It can be a for example a proxy timeout error (504). - */ - throw new PassboltBadResponseError(); - } - - return { - username: username, - profile: { - first_name: firstName, - last_name: lastName - } - }; - } - - /** - * Find legacy recover info - * @param {string} userId the user id - * @param {string} token the token - * @returns {Promise<*>} response body - * @throws {Error} if options are invalid or API error - * @deprecated will be removed with v4 - */ - async findLegacyRecoverInfo(userId, token) { - this.assertValidId(userId); - this.assertValidId(token); - - const url = new URL(`${this.apiClient.baseUrl}/recover/${userId}/${token}`); - let response, responseHtml, username, firstName, lastName; - try { - response = await fetch(url.toString()); - } catch (error) { - if (navigator.onLine) { - // Catch Network error such as bad certificate or server unreachable. - throw new PassboltServiceUnavailableError("Unable to reach the server, an unexpected error occurred"); - } else { - // Network connection lost. - throw new PassboltServiceUnavailableError("Unable to reach the server, you are not connected to the network"); - } - } - - try { - responseHtml = await response.text(); - const parser = new DOMParser(); - const parsedHtml = parser.parseFromString(responseHtml, 'text/html'); - username = parsedHtml.getElementById('js_setup_user_username').value; - firstName = parsedHtml.getElementById('js_setup_user_first_name').value; - lastName = parsedHtml.getElementById('js_setup_user_last_name').value; - } catch (error) { - /* - * If the response cannot be parsed, it's not a Passbolt API response. - * It can be a for example a proxy timeout error (504). - */ - throw new PassboltBadResponseError(); - } - - return { - username: username, - profile: { - first_name: firstName, - last_name: lastName - } - }; - } } export default SetupService;