@bitwarden/cli 2023.8.2 → 2023.9.1

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.
package/build/bw.js CHANGED
@@ -20,7 +20,7 @@ module.exports = require("url");
20
20
  /***/ 147:
21
21
  /***/ ((module) => {
22
22
 
23
- module.exports = JSON.parse('{"name":"@bitwarden/cli","description":"A secure and free password manager for all of your devices.","version":"2023.8.2","keywords":["bitwarden","password","vault","password manager","cli"],"author":"Bitwarden Inc. <hello@bitwarden.com> (https://bitwarden.com)","homepage":"https://bitwarden.com","repository":{"type":"git","url":"https://github.com/bitwarden/clients"},"license":"GPL-3.0-only","scripts":{"clean":"rimraf dist","build":"webpack","build:debug":"npm run build && node --inspect ./build/bw.js","build:watch":"webpack --watch","build:prod":"cross-env NODE_ENV=production webpack","build:prod:watch":"cross-env NODE_ENV=production webpack --watch","package":"npm run package:win && npm run package:mac && npm run package:lin","package:win":"pkg . --targets win-x64 --output ./dist/windows/bw.exe","package:mac":"pkg . --targets macos-x64 --output ./dist/macos/bw","package:lin":"pkg . --targets linux-x64 --output ./dist/linux/bw","debug":"node --inspect ./build/bw.js","dist":"npm run build:prod && npm run clean && npm run package","dist:win":"npm run build:prod && npm run clean && npm run package:win","dist:mac":"npm run build:prod && npm run clean && npm run package:mac","dist:lin":"npm run build:prod && npm run clean && npm run package:lin","publish:npm":"npm run build:prod && npm publish --access public","test":"jest","test:watch":"jest --watch","test:watch:all":"jest --watchAll"},"bin":{"bw":"build/bw.js"},"pkg":{"assets":["./build/**/*","../../node_modules/argon2/**/*"]},"dependencies":{"@koa/multer":"3.0.2","@koa/router":"12.0.0","argon2":"0.30.3","big-integer":"1.6.51","browser-hrtime":"1.1.8","chalk":"4.1.2","commander":"7.2.0","form-data":"4.0.0","https-proxy-agent":"5.0.1","inquirer":"8.2.5","jsdom":"22.1.0","jszip":"3.10.1","koa":"2.14.2","koa-bodyparser":"4.4.0","koa-json":"2.0.2","lowdb":"1.0.0","lunr":"2.3.9","multer":"1.4.5-lts.1","node-fetch":"2.6.11","node-forge":"1.3.1","open":"8.4.2","papaparse":"5.4.1","proper-lockfile":"4.1.2","rxjs":"7.8.1","tldts":"6.0.5","zxcvbn":"4.4.2"}}');
23
+ module.exports = JSON.parse('{"name":"@bitwarden/cli","description":"A secure and free password manager for all of your devices.","version":"2023.9.1","keywords":["bitwarden","password","vault","password manager","cli"],"author":"Bitwarden Inc. <hello@bitwarden.com> (https://bitwarden.com)","homepage":"https://bitwarden.com","repository":{"type":"git","url":"https://github.com/bitwarden/clients"},"license":"GPL-3.0-only","scripts":{"clean":"rimraf dist","build":"webpack","build:debug":"npm run build && node --inspect ./build/bw.js","build:watch":"webpack --watch","build:prod":"cross-env NODE_ENV=production webpack","build:prod:watch":"cross-env NODE_ENV=production webpack --watch","package":"npm run package:win && npm run package:mac && npm run package:lin","package:win":"pkg . --targets win-x64 --output ./dist/windows/bw.exe","package:mac":"pkg . --targets macos-x64 --output ./dist/macos/bw","package:lin":"pkg . --targets linux-x64 --output ./dist/linux/bw","debug":"node --inspect ./build/bw.js","dist":"npm run build:prod && npm run clean && npm run package","dist:win":"npm run build:prod && npm run clean && npm run package:win","dist:mac":"npm run build:prod && npm run clean && npm run package:mac","dist:lin":"npm run build:prod && npm run clean && npm run package:lin","publish:npm":"npm run build:prod && npm publish --access public","test":"jest","test:watch":"jest --watch","test:watch:all":"jest --watchAll"},"bin":{"bw":"build/bw.js"},"pkg":{"assets":["./build/**/*","../../node_modules/argon2/**/*"]},"dependencies":{"@koa/multer":"3.0.2","@koa/router":"12.0.0","argon2":"0.31.0","big-integer":"1.6.51","browser-hrtime":"1.1.8","chalk":"4.1.2","commander":"7.2.0","form-data":"4.0.0","https-proxy-agent":"5.0.1","inquirer":"8.2.6","jsdom":"22.1.0","jszip":"3.10.1","koa":"2.14.2","koa-bodyparser":"4.4.1","koa-json":"2.0.2","lowdb":"1.0.0","lunr":"2.3.9","multer":"1.4.5-lts.1","node-fetch":"2.6.12","node-forge":"1.3.1","open":"8.4.2","papaparse":"5.4.1","proper-lockfile":"4.1.2","rxjs":"7.8.1","tldts":"6.0.14","zxcvbn":"4.4.2"}}');
24
24
 
25
25
  /***/ })
26
26
 
@@ -1462,6 +1462,7 @@ utils_Utils.global = null;
1462
1462
  // Transpiled version of /\p{Emoji_Presentation}/gu using https://mothereff.in/regexpu. Used for compatability in older browsers.
1463
1463
  utils_Utils.regexpEmojiPresentation = /(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])/g;
1464
1464
  utils_Utils.validHosts = ["localhost"];
1465
+ utils_Utils.originalMinimumPasswordLength = 8;
1465
1466
  utils_Utils.minimumPasswordLength = 12;
1466
1467
  utils_Utils.DomainMatchBlacklist = new Map([
1467
1468
  ["google.com", new Set(["script.google.com"])],
@@ -1472,7 +1473,7 @@ utils_Utils.init();
1472
1473
 
1473
1474
 
1474
1475
  function canAccessVaultTab(org) {
1475
- return org.canViewAssignedCollections || org.canViewAllCollections || org.canManageGroups;
1476
+ return org.canViewAssignedCollections || org.canViewAllCollections;
1476
1477
  }
1477
1478
  function canAccessSettingsTab(org) {
1478
1479
  return (org.isOwner ||
@@ -2202,19 +2203,6 @@ var SecureNoteType;
2202
2203
  SecureNoteType[SecureNoteType["Generic"] = 0] = "Generic";
2203
2204
  })(SecureNoteType || (SecureNoteType = {}));
2204
2205
 
2205
- ;// CONCATENATED MODULE: ../../libs/common/src/enums/state-version.enum.ts
2206
- var StateVersion;
2207
- (function (StateVersion) {
2208
- StateVersion[StateVersion["One"] = 1] = "One";
2209
- StateVersion[StateVersion["Two"] = 2] = "Two";
2210
- StateVersion[StateVersion["Three"] = 3] = "Three";
2211
- StateVersion[StateVersion["Four"] = 4] = "Four";
2212
- StateVersion[StateVersion["Five"] = 5] = "Five";
2213
- StateVersion[StateVersion["Six"] = 6] = "Six";
2214
- StateVersion[StateVersion["Seven"] = 7] = "Seven";
2215
- StateVersion[StateVersion["Latest"] = 7] = "Latest";
2216
- })(StateVersion || (StateVersion = {}));
2217
-
2218
2206
  ;// CONCATENATED MODULE: ../../libs/common/src/enums/storage-location.enum.ts
2219
2207
  var StorageLocation;
2220
2208
  (function (StorageLocation) {
@@ -2266,7 +2254,6 @@ var UriMatchType;
2266
2254
 
2267
2255
 
2268
2256
 
2269
-
2270
2257
 
2271
2258
 
2272
2259
 
@@ -2459,7 +2446,7 @@ class Organization {
2459
2446
  return this.isAdmin || this.permissions.deleteAnyCollection;
2460
2447
  }
2461
2448
  get canViewAllCollections() {
2462
- return this.canCreateNewCollections || this.canEditAnyCollection || this.canDeleteAnyCollection;
2449
+ return this.canEditAnyCollection || this.canDeleteAnyCollection;
2463
2450
  }
2464
2451
  get canEditAssignedCollections() {
2465
2452
  return this.isManager || this.permissions.editAssignedCollections;
@@ -3893,12 +3880,29 @@ class AccountDecryptionOptions {
3893
3880
  return null;
3894
3881
  }
3895
3882
  const accountDecryptionOptions = new AccountDecryptionOptions();
3896
- accountDecryptionOptions.hasMasterPassword = response.hasMasterPassword;
3897
- if (response.trustedDeviceOption) {
3898
- accountDecryptionOptions.trustedDeviceOption = new TrustedDeviceUserDecryptionOption(response.trustedDeviceOption.hasAdminApproval, response.trustedDeviceOption.hasLoginApprovingDevice, response.trustedDeviceOption.hasManageResetPasswordPermission);
3883
+ if (response.userDecryptionOptions) {
3884
+ // If the response has userDecryptionOptions, this means it's on a post-TDE server version and can interrogate
3885
+ // the new decryption options.
3886
+ const responseOptions = response.userDecryptionOptions;
3887
+ accountDecryptionOptions.hasMasterPassword = responseOptions.hasMasterPassword;
3888
+ if (responseOptions.trustedDeviceOption) {
3889
+ accountDecryptionOptions.trustedDeviceOption = new TrustedDeviceUserDecryptionOption(responseOptions.trustedDeviceOption.hasAdminApproval, responseOptions.trustedDeviceOption.hasLoginApprovingDevice, responseOptions.trustedDeviceOption.hasManageResetPasswordPermission);
3890
+ }
3891
+ if (responseOptions.keyConnectorOption) {
3892
+ accountDecryptionOptions.keyConnectorOption = new KeyConnectorUserDecryptionOption(responseOptions.keyConnectorOption.keyConnectorUrl);
3893
+ }
3899
3894
  }
3900
- if (response.keyConnectorOption) {
3901
- accountDecryptionOptions.keyConnectorOption = new KeyConnectorUserDecryptionOption(response.keyConnectorOption.keyConnectorUrl);
3895
+ else {
3896
+ // If the response does not have userDecryptionOptions, this means it's on a pre-TDE server version and so
3897
+ // we must base our decryption options on the presence of the keyConnectorUrl.
3898
+ // Note that the presence of keyConnectorUrl implies that the user does not have a master password, as in pre-TDE
3899
+ // server versions, a master password short-circuited the addition of the keyConnectorUrl to the response.
3900
+ // TODO: remove this check after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
3901
+ const usingKeyConnector = response.keyConnectorUrl != null;
3902
+ accountDecryptionOptions.hasMasterPassword = !usingKeyConnector;
3903
+ if (usingKeyConnector) {
3904
+ accountDecryptionOptions.keyConnectorOption = new KeyConnectorUserDecryptionOption(response.keyConnectorUrl);
3905
+ }
3902
3906
  }
3903
3907
  return accountDecryptionOptions;
3904
3908
  }
@@ -4240,7 +4244,7 @@ class LogInStrategy {
4240
4244
  refreshToken: tokenResponse.refreshToken,
4241
4245
  }),
4242
4246
  keys: accountKeys,
4243
- decryptionOptions: AccountDecryptionOptions.fromResponse(tokenResponse.userDecryptionOptions),
4247
+ decryptionOptions: AccountDecryptionOptions.fromResponse(tokenResponse),
4244
4248
  adminAuthRequest: adminAuthRequest === null || adminAuthRequest === void 0 ? void 0 : adminAuthRequest.toJSON(),
4245
4249
  }));
4246
4250
  });
@@ -4552,23 +4556,56 @@ class SsoLogInStrategy extends LogInStrategy {
4552
4556
  }
4553
4557
  setMasterKey(tokenResponse) {
4554
4558
  return sso_login_strategy_awaiter(this, void 0, void 0, function* () {
4555
- // TODO: discuss how this is no longer true with TDE
4556
- // eventually we’ll need to support migration of existing TDE users to Key Connector
4557
- const newSsoUser = tokenResponse.key == null;
4558
- if (tokenResponse.keyConnectorUrl != null) {
4559
- if (!newSsoUser) {
4560
- yield this.keyConnectorService.setMasterKeyFromUrl(tokenResponse.keyConnectorUrl);
4559
+ // The only way we can be setting a master key at this point is if we are using Key Connector.
4560
+ // First, check to make sure that we should do so based on the token response.
4561
+ if (this.shouldSetMasterKeyFromKeyConnector(tokenResponse)) {
4562
+ // If we're here, we know that the user should use Key Connector (they have a KeyConnectorUrl) and does not have a master password.
4563
+ // We can now check the key on the token response to see whether they are a brand new user or an existing user.
4564
+ // The presence of a masterKeyEncryptedUserKey indicates that the user has already been provisioned in Key Connector.
4565
+ const newSsoUser = tokenResponse.key == null;
4566
+ if (newSsoUser) {
4567
+ yield this.keyConnectorService.convertNewSsoUserToKeyConnector(tokenResponse, this.orgId);
4561
4568
  }
4562
4569
  else {
4563
- yield this.keyConnectorService.convertNewSsoUserToKeyConnector(tokenResponse, this.orgId);
4570
+ const keyConnectorUrl = this.getKeyConnectorUrl(tokenResponse);
4571
+ yield this.keyConnectorService.setMasterKeyFromUrl(keyConnectorUrl);
4564
4572
  }
4565
4573
  }
4566
4574
  });
4567
4575
  }
4576
+ /**
4577
+ * Determines if it is possible set the `masterKey` from Key Connector.
4578
+ * @param tokenResponse
4579
+ * @returns `true` if the master key can be set from Key Connector, `false` otherwise
4580
+ */
4581
+ shouldSetMasterKeyFromKeyConnector(tokenResponse) {
4582
+ var _a;
4583
+ const userDecryptionOptions = tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.userDecryptionOptions;
4584
+ if (userDecryptionOptions != null) {
4585
+ const userHasMasterPassword = userDecryptionOptions.hasMasterPassword;
4586
+ const userHasKeyConnectorUrl = ((_a = userDecryptionOptions.keyConnectorOption) === null || _a === void 0 ? void 0 : _a.keyConnectorUrl) != null;
4587
+ // In order for us to set the master key from Key Connector, we need to have a Key Connector URL
4588
+ // and the user must not have a master password.
4589
+ return userHasKeyConnectorUrl && !userHasMasterPassword;
4590
+ }
4591
+ else {
4592
+ // In pre-TDE versions of the server, the userDecryptionOptions will not be present.
4593
+ // In this case, we can determine if the user has a master password and has a Key Connector URL by
4594
+ // just checking the keyConnectorUrl property. This is because the server short-circuits on the response
4595
+ // and will not pass back the URL in the response if the user has a master password.
4596
+ // TODO: remove compatibility check after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
4597
+ return tokenResponse.keyConnectorUrl != null;
4598
+ }
4599
+ }
4600
+ getKeyConnectorUrl(tokenResponse) {
4601
+ var _a, _b;
4602
+ // TODO: remove tokenResponse.keyConnectorUrl reference after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
4603
+ const userDecryptionOptions = tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.userDecryptionOptions;
4604
+ return ((_a = tokenResponse.keyConnectorUrl) !== null && _a !== void 0 ? _a : (_b = userDecryptionOptions === null || userDecryptionOptions === void 0 ? void 0 : userDecryptionOptions.keyConnectorOption) === null || _b === void 0 ? void 0 : _b.keyConnectorUrl);
4605
+ }
4568
4606
  // TODO: future passkey login strategy will need to support setting user key (decrypting via TDE or admin approval request)
4569
4607
  // so might be worth moving this logic to a common place (base login strategy or a separate service?)
4570
4608
  setUserKey(tokenResponse) {
4571
- var _a;
4572
4609
  return sso_login_strategy_awaiter(this, void 0, void 0, function* () {
4573
4610
  const masterKeyEncryptedUserKey = tokenResponse.key;
4574
4611
  // Note: masterKeyEncryptedUserKey is undefined for SSO JIT provisioned users
@@ -4588,13 +4625,13 @@ class SsoLogInStrategy extends LogInStrategy {
4588
4625
  yield this.trySetUserKeyWithDeviceKey(tokenResponse);
4589
4626
  }
4590
4627
  }
4591
- else if (
4592
- // TODO: remove tokenResponse.keyConnectorUrl when it's deprecated
4593
- masterKeyEncryptedUserKey != null &&
4594
- (tokenResponse.keyConnectorUrl || ((_a = userDecryptionOptions === null || userDecryptionOptions === void 0 ? void 0 : userDecryptionOptions.keyConnectorOption) === null || _a === void 0 ? void 0 : _a.keyConnectorUrl))) {
4628
+ else if (masterKeyEncryptedUserKey != null &&
4629
+ this.getKeyConnectorUrl(tokenResponse) != null) {
4595
4630
  // Key connector enabled for user
4596
4631
  yield this.trySetUserKeyWithMasterKey();
4597
4632
  }
4633
+ // Note: In the traditional SSO flow with MP without key connector, the lock component
4634
+ // is responsible for deriving master key from MP entry and then decrypting the user key
4598
4635
  });
4599
4636
  }
4600
4637
  trySetUserKeyWithApprovedAdminRequestIfExists() {
@@ -4659,8 +4696,12 @@ class SsoLogInStrategy extends LogInStrategy {
4659
4696
  trySetUserKeyWithMasterKey() {
4660
4697
  return sso_login_strategy_awaiter(this, void 0, void 0, function* () {
4661
4698
  const masterKey = yield this.cryptoService.getMasterKey();
4699
+ // There is a scenario in which the master key is not set here. That will occur if the user
4700
+ // has a master password and is using Key Connector. In that case, we cannot set the master key
4701
+ // because the user hasn't entered their master password yet.
4702
+ // Instead, we'll return here and let the migration to Key Connector handle setting the master key.
4662
4703
  if (!masterKey) {
4663
- throw new Error("Master key not found");
4704
+ return;
4664
4705
  }
4665
4706
  const userKey = yield this.cryptoService.decryptUserKeyWithMasterKey(masterKey);
4666
4707
  yield this.cryptoService.setUserKey(userKey);
@@ -5138,7 +5179,7 @@ class DeviceTrustCryptoService {
5138
5179
  makeDeviceKey() {
5139
5180
  return device_trust_crypto_service_implementation_awaiter(this, void 0, void 0, function* () {
5140
5181
  // Create 512-bit device key
5141
- const randomBytes = yield this.cryptoFunctionService.randomBytes(64);
5182
+ const randomBytes = yield this.cryptoFunctionService.aesGenerateKey(512);
5142
5183
  const deviceKey = new SymmetricCryptoKey(randomBytes);
5143
5184
  return deviceKey;
5144
5185
  });
@@ -5383,9 +5424,11 @@ class KeyConnectorService {
5383
5424
  });
5384
5425
  }
5385
5426
  convertNewSsoUserToKeyConnector(tokenResponse, orgId) {
5427
+ var _a;
5386
5428
  return key_connector_service_awaiter(this, void 0, void 0, function* () {
5387
- const { kdf, kdfIterations, kdfMemory, kdfParallelism, keyConnectorUrl } = tokenResponse;
5388
- const password = yield this.cryptoFunctionService.randomBytes(64);
5429
+ // TODO: Remove after tokenResponse.keyConnectorUrl is deprecated in 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
5430
+ const { kdf, kdfIterations, kdfMemory, kdfParallelism, keyConnectorUrl: legacyKeyConnectorUrl, userDecryptionOptions, } = tokenResponse;
5431
+ const password = yield this.cryptoFunctionService.aesGenerateKey(512);
5389
5432
  const kdfConfig = new KdfConfig(kdfIterations, kdfMemory, kdfParallelism);
5390
5433
  const masterKey = yield this.cryptoService.makeMasterKey(utils_Utils.fromBufferToB64(password), yield this.tokenService.getEmail(), kdf, kdfConfig);
5391
5434
  const keyConnectorRequest = new KeyConnectorUserKeyRequest(masterKey.encKeyB64);
@@ -5395,6 +5438,7 @@ class KeyConnectorService {
5395
5438
  yield this.cryptoService.setMasterKeyEncryptedUserKey(userKey[1].encryptedString);
5396
5439
  const [pubKey, privKey] = yield this.cryptoService.makeKeyPair();
5397
5440
  try {
5441
+ const keyConnectorUrl = legacyKeyConnectorUrl !== null && legacyKeyConnectorUrl !== void 0 ? legacyKeyConnectorUrl : (_a = userDecryptionOptions === null || userDecryptionOptions === void 0 ? void 0 : userDecryptionOptions.keyConnectorOption) === null || _a === void 0 ? void 0 : _a.keyConnectorUrl;
5398
5442
  yield this.apiService.postUserKeyToKeyConnector(keyConnectorUrl, keyConnectorRequest);
5399
5443
  }
5400
5444
  catch (e) {
@@ -5677,7 +5721,7 @@ const TwoFactorProviders = {
5677
5721
  description: null,
5678
5722
  priority: 4,
5679
5723
  sort: 5,
5680
- premium: true,
5724
+ premium: false,
5681
5725
  },
5682
5726
  };
5683
5727
  class TwoFactorService {
@@ -5977,7 +6021,6 @@ class GlobalState {
5977
6021
  constructor() {
5978
6022
  this.theme = ThemeType.System;
5979
6023
  this.window = new WindowState();
5980
- this.stateVersion = StateVersion.One;
5981
6024
  this.environmentUrls = new EnvironmentUrls();
5982
6025
  }
5983
6026
  }
@@ -6047,6 +6090,73 @@ class BroadcasterService {
6047
6090
  }
6048
6091
  }
6049
6092
 
6093
+ ;// CONCATENATED MODULE: ../../libs/common/src/platform/models/response/server-config.response.ts
6094
+
6095
+ class ServerConfigResponse extends BaseResponse {
6096
+ constructor(response) {
6097
+ super(response);
6098
+ this.featureStates = {};
6099
+ if (response == null) {
6100
+ return;
6101
+ }
6102
+ this.version = this.getResponseProperty("Version");
6103
+ this.gitHash = this.getResponseProperty("GitHash");
6104
+ this.server = new ThirdPartyServerConfigResponse(this.getResponseProperty("Server"));
6105
+ this.environment = new EnvironmentServerConfigResponse(this.getResponseProperty("Environment"));
6106
+ this.featureStates = this.getResponseProperty("FeatureStates");
6107
+ }
6108
+ }
6109
+ class EnvironmentServerConfigResponse extends BaseResponse {
6110
+ constructor(data = null) {
6111
+ super(data);
6112
+ if (data == null) {
6113
+ return;
6114
+ }
6115
+ this.cloudRegion = this.getResponseProperty("CloudRegion");
6116
+ this.vault = this.getResponseProperty("Vault");
6117
+ this.api = this.getResponseProperty("Api");
6118
+ this.identity = this.getResponseProperty("Identity");
6119
+ this.notifications = this.getResponseProperty("Notifications");
6120
+ this.sso = this.getResponseProperty("Sso");
6121
+ }
6122
+ }
6123
+ class ThirdPartyServerConfigResponse extends BaseResponse {
6124
+ constructor(data = null) {
6125
+ super(data);
6126
+ if (data == null) {
6127
+ return;
6128
+ }
6129
+ this.name = this.getResponseProperty("Name");
6130
+ this.url = this.getResponseProperty("Url");
6131
+ }
6132
+ }
6133
+
6134
+ ;// CONCATENATED MODULE: ../../libs/common/src/platform/services/config/config-api.service.ts
6135
+ var config_api_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6136
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6137
+ return new (P || (P = Promise))(function (resolve, reject) {
6138
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6139
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6140
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6141
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
6142
+ });
6143
+ };
6144
+
6145
+
6146
+ class ConfigApiService {
6147
+ constructor(apiService, authService) {
6148
+ this.apiService = apiService;
6149
+ this.authService = authService;
6150
+ }
6151
+ get() {
6152
+ return config_api_service_awaiter(this, void 0, void 0, function* () {
6153
+ const authed = (yield this.authService.getAuthStatus()) !== AuthenticationStatus.LoggedOut;
6154
+ const r = yield this.apiService.send("GET", "/config", null, authed, true);
6155
+ return new ServerConfigResponse(r);
6156
+ });
6157
+ }
6158
+ }
6159
+
6050
6160
  ;// CONCATENATED MODULE: ../../libs/common/src/platform/services/container.service.ts
6051
6161
  class ContainerService {
6052
6162
  constructor(cryptoService, encryptService) {
@@ -14093,7 +14203,7 @@ class CryptoService {
14093
14203
  if (masterKey == null) {
14094
14204
  throw new Error("No Master Key found.");
14095
14205
  }
14096
- const newUserKey = yield this.cryptoFunctionService.randomBytes(64);
14206
+ const newUserKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14097
14207
  return this.buildProtectedSymmetricKey(masterKey, newUserKey);
14098
14208
  });
14099
14209
  }
@@ -14305,7 +14415,7 @@ class CryptoService {
14305
14415
  if (key == null) {
14306
14416
  throw new Error("No key provided");
14307
14417
  }
14308
- const newSymKey = yield this.cryptoFunctionService.randomBytes(64);
14418
+ const newSymKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14309
14419
  return this.buildProtectedSymmetricKey(key, newSymKey);
14310
14420
  });
14311
14421
  }
@@ -14391,7 +14501,7 @@ class CryptoService {
14391
14501
  }
14392
14502
  makeOrgKey() {
14393
14503
  return crypto_service_awaiter(this, void 0, void 0, function* () {
14394
- const shareKey = yield this.cryptoFunctionService.randomBytes(64);
14504
+ const shareKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14395
14505
  const publicKey = yield this.getPublicKey();
14396
14506
  const encShareKey = yield this.rsaEncrypt(shareKey, publicKey);
14397
14507
  return [encShareKey, new SymmetricCryptoKey(shareKey)];
@@ -14502,6 +14612,12 @@ class CryptoService {
14502
14612
  return new SymmetricCryptoKey(sendKey);
14503
14613
  });
14504
14614
  }
14615
+ makeCipherKey() {
14616
+ return crypto_service_awaiter(this, void 0, void 0, function* () {
14617
+ const randomBytes = yield this.cryptoFunctionService.aesGenerateKey(512);
14618
+ return new SymmetricCryptoKey(randomBytes);
14619
+ });
14620
+ }
14505
14621
  clearKeys(userId) {
14506
14622
  return crypto_service_awaiter(this, void 0, void 0, function* () {
14507
14623
  yield this.clearUserKey(true, userId);
@@ -14630,8 +14746,8 @@ class CryptoService {
14630
14746
  */
14631
14747
  initAccount() {
14632
14748
  return crypto_service_awaiter(this, void 0, void 0, function* () {
14633
- const randomBytes = yield this.cryptoFunctionService.randomBytes(64);
14634
- const userKey = new SymmetricCryptoKey(randomBytes);
14749
+ const rawKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14750
+ const userKey = new SymmetricCryptoKey(rawKey);
14635
14751
  const [publicKey, privateKey] = yield this.makeKeyPair(userKey);
14636
14752
  yield this.setUserKey(userKey);
14637
14753
  yield this.stateService.setEncryptedPrivateKey(privateKey.encryptedString);
@@ -15215,7 +15331,7 @@ var environment_service_awaiter = (undefined && undefined.__awaiter) || function
15215
15331
  class environment_service_EnvironmentService {
15216
15332
  constructor(stateService) {
15217
15333
  this.stateService = stateService;
15218
- this.urlsSubject = new external_rxjs_namespaceObject.Subject();
15334
+ this.urlsSubject = new external_rxjs_namespaceObject.ReplaySubject(1);
15219
15335
  this.urls = this.urlsSubject.asObservable();
15220
15336
  this.initialized = false;
15221
15337
  this.scimUrl = null;
@@ -15835,8 +15951,32 @@ class NoopMessagingService {
15835
15951
  }
15836
15952
  }
15837
15953
 
15838
- ;// CONCATENATED MODULE: ../../libs/common/src/platform/services/state-migration.service.ts
15839
- var state_migration_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
15954
+ ;// CONCATENATED MODULE: ../../libs/common/src/admin-console/models/data/provider.data.ts
15955
+ class ProviderData {
15956
+ constructor(response) {
15957
+ this.id = response.id;
15958
+ this.name = response.name;
15959
+ this.status = response.status;
15960
+ this.type = response.type;
15961
+ this.enabled = response.enabled;
15962
+ this.userId = response.userId;
15963
+ this.useEvents = response.useEvents;
15964
+ }
15965
+ }
15966
+
15967
+ ;// CONCATENATED MODULE: ../../libs/common/src/enums/vault-timeout-action.enum.ts
15968
+ var VaultTimeoutAction;
15969
+ (function (VaultTimeoutAction) {
15970
+ VaultTimeoutAction["Lock"] = "lock";
15971
+ VaultTimeoutAction["LogOut"] = "logOut";
15972
+ })(VaultTimeoutAction || (VaultTimeoutAction = {}));
15973
+
15974
+ ;// CONCATENATED MODULE: ../../libs/common/src/models/data/event.data.ts
15975
+ class EventData {
15976
+ }
15977
+
15978
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migration-builder.ts
15979
+ var migration_builder_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
15840
15980
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15841
15981
  return new (P || (P = Promise))(function (resolve, reject) {
15842
15982
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -15845,514 +15985,558 @@ var state_migration_service_awaiter = (undefined && undefined.__awaiter) || func
15845
15985
  step((generator = generator.apply(thisArg, _arguments || [])).next());
15846
15986
  });
15847
15987
  };
15848
-
15849
-
15850
-
15851
- // Originally (before January 2022) storage was handled as a flat key/value pair store.
15852
- // With the move to a typed object for state storage these keys should no longer be in use anywhere outside of this migration.
15853
- const v1Keys = {
15854
- accessToken: "accessToken",
15855
- alwaysShowDock: "alwaysShowDock",
15856
- autoConfirmFingerprints: "autoConfirmFingerprints",
15857
- autoFillOnPageLoadDefault: "autoFillOnPageLoadDefault",
15858
- biometricAwaitingAcceptance: "biometricAwaitingAcceptance",
15859
- biometricFingerprintValidated: "biometricFingerprintValidated",
15860
- biometricText: "biometricText",
15861
- biometricUnlock: "biometric",
15862
- clearClipboard: "clearClipboardKey",
15863
- clientId: "apikey_clientId",
15864
- clientSecret: "apikey_clientSecret",
15865
- collapsedGroupings: "collapsedGroupings",
15866
- convertAccountToKeyConnector: "convertAccountToKeyConnector",
15867
- defaultUriMatch: "defaultUriMatch",
15868
- disableAddLoginNotification: "disableAddLoginNotification",
15869
- disableAutoBiometricsPrompt: "noAutoPromptBiometrics",
15870
- disableAutoTotpCopy: "disableAutoTotpCopy",
15871
- disableBadgeCounter: "disableBadgeCounter",
15872
- disableChangedPasswordNotification: "disableChangedPasswordNotification",
15873
- disableContextMenuItem: "disableContextMenuItem",
15874
- disableFavicon: "disableFavicon",
15875
- disableGa: "disableGa",
15876
- dontShowCardsCurrentTab: "dontShowCardsCurrentTab",
15877
- dontShowIdentitiesCurrentTab: "dontShowIdentitiesCurrentTab",
15878
- emailVerified: "emailVerified",
15879
- enableAlwaysOnTop: "enableAlwaysOnTopKey",
15880
- enableAutoFillOnPageLoad: "enableAutoFillOnPageLoad",
15881
- enableBiometric: "enabledBiometric",
15882
- enableBrowserIntegration: "enableBrowserIntegration",
15883
- enableBrowserIntegrationFingerprint: "enableBrowserIntegrationFingerprint",
15884
- enableCloseToTray: "enableCloseToTray",
15885
- enableFullWidth: "enableFullWidth",
15886
- enableMinimizeToTray: "enableMinimizeToTray",
15887
- enableStartToTray: "enableStartToTrayKey",
15888
- enableTray: "enableTray",
15889
- encKey: "encKey",
15890
- encOrgKeys: "encOrgKeys",
15891
- encPrivate: "encPrivateKey",
15892
- encProviderKeys: "encProviderKeys",
15893
- entityId: "entityId",
15894
- entityType: "entityType",
15895
- environmentUrls: "environmentUrls",
15896
- equivalentDomains: "equivalentDomains",
15897
- eventCollection: "eventCollection",
15898
- forcePasswordReset: "forcePasswordReset",
15899
- history: "generatedPasswordHistory",
15900
- installedVersion: "installedVersion",
15901
- kdf: "kdf",
15902
- kdfIterations: "kdfIterations",
15903
- key: "key",
15904
- keyHash: "keyHash",
15905
- lastActive: "lastActive",
15906
- localData: "sitesLocalData",
15907
- locale: "locale",
15908
- mainWindowSize: "mainWindowSize",
15909
- minimizeOnCopyToClipboard: "minimizeOnCopyToClipboardKey",
15910
- neverDomains: "neverDomains",
15911
- noAutoPromptBiometricsText: "noAutoPromptBiometricsText",
15912
- openAtLogin: "openAtLogin",
15913
- passwordGenerationOptions: "passwordGenerationOptions",
15914
- pinProtected: "pinProtectedKey",
15915
- protectedPin: "protectedPin",
15916
- refreshToken: "refreshToken",
15917
- ssoCodeVerifier: "ssoCodeVerifier",
15918
- ssoIdentifier: "ssoOrgIdentifier",
15919
- ssoState: "ssoState",
15920
- stamp: "securityStamp",
15921
- theme: "theme",
15922
- userEmail: "userEmail",
15923
- userId: "userId",
15924
- usesConnector: "usesKeyConnector",
15925
- vaultTimeoutAction: "vaultTimeoutAction",
15926
- vaultTimeout: "lockOption",
15927
- rememberedEmail: "rememberedEmail",
15928
- };
15929
- const v1KeyPrefixes = {
15930
- ciphers: "ciphers_",
15931
- collections: "collections_",
15932
- folders: "folders_",
15933
- lastSync: "lastSync_",
15934
- policies: "policies_",
15935
- twoFactorToken: "twoFactorToken_",
15936
- organizations: "organizations_",
15937
- providers: "providers_",
15938
- sends: "sends_",
15939
- settings: "settings_",
15940
- };
15941
- const keys = {
15942
- global: "global",
15943
- authenticatedAccounts: "authenticatedAccounts",
15944
- activeUserId: "activeUserId",
15945
- tempAccountSettings: "tempAccountSettings",
15946
- accountActivity: "accountActivity",
15947
- };
15948
- const partialKeys = {
15949
- autoKey: "_masterkey_auto",
15950
- biometricKey: "_masterkey_biometric",
15951
- masterKey: "_masterkey",
15988
+ class MigrationBuilder {
15989
+ /** Create a new MigrationBuilder with an empty buffer of migrations to perform.
15990
+ *
15991
+ * Add migrations to the buffer with {@link with} and {@link rollback}.
15992
+ * @returns A new MigrationBuilder.
15993
+ */
15994
+ static create() {
15995
+ return new MigrationBuilder([]);
15996
+ }
15997
+ constructor(migrations) {
15998
+ this.migrations = migrations;
15999
+ }
16000
+ /** Add a migrator to the MigrationBuilder. Types are updated such that the chained MigrationBuilder must currently be
16001
+ * at state version equal to the from version of the migrator. Return as MigrationBuilder<TTo> where TTo is the to
16002
+ * version of the migrator, so that the next migrator can be chained.
16003
+ *
16004
+ * @param migrate A migrator class or a tuple of a migrator class, the from version, and the to version. A tuple is
16005
+ * required to instantiate version numbers unless a default constructor is defined.
16006
+ * @returns A new MigrationBuilder with the to version of the migrator as the current version.
16007
+ */
16008
+ with(...migrate) {
16009
+ return this.addMigrator(migrate, "up");
16010
+ }
16011
+ /** Add a migrator to rollback on the MigrationBuilder's list of migrations. As with {@link with}, types of
16012
+ * MigrationBuilder and Migrator must align. However, this time the migration is reversed so TCurrent of the
16013
+ * MigrationBuilder must be equal to the to version of the migrator. Return as MigrationBuilder<TFrom> where TFrom
16014
+ * is the from version of the migrator, so that the next migrator can be chained.
16015
+ *
16016
+ * @param migrate A migrator class or a tuple of a migrator class, the from version, and the to version. A tuple is
16017
+ * required to instantiate version numbers unless a default constructor is defined.
16018
+ * @returns A new MigrationBuilder with the from version of the migrator as the current version.
16019
+ */
16020
+ rollback(...migrate) {
16021
+ if (migrate.length === 3) {
16022
+ migrate = [migrate[0], migrate[2], migrate[1]];
16023
+ }
16024
+ return this.addMigrator(migrate, "down");
16025
+ }
16026
+ /** Execute the migrations as defined in the MigrationBuilder's migrator buffer */
16027
+ migrate(helper) {
16028
+ return this.migrations.reduce((promise, migrator) => promise.then(() => migration_builder_awaiter(this, void 0, void 0, function* () {
16029
+ yield this.runMigrator(migrator.migrator, helper, migrator.direction);
16030
+ })), Promise.resolve());
16031
+ }
16032
+ addMigrator(migrate, direction = "up") {
16033
+ const newMigration = migrate.length === 1
16034
+ ? { migrator: new migrate[0](), direction }
16035
+ : { migrator: new migrate[0](migrate[1], migrate[2]), direction };
16036
+ return new MigrationBuilder([...this.migrations, newMigration]);
16037
+ }
16038
+ runMigrator(migrator, helper, direction) {
16039
+ return migration_builder_awaiter(this, void 0, void 0, function* () {
16040
+ const shouldMigrate = yield migrator.shouldMigrate(helper, direction);
16041
+ helper.info(`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) should migrate: ${shouldMigrate} - ${direction}`);
16042
+ if (shouldMigrate) {
16043
+ const method = direction === "up" ? migrator.migrate : migrator.rollback;
16044
+ yield method(helper);
16045
+ helper.info(`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) migrated - ${direction}`);
16046
+ yield migrator.updateVersion(helper, direction);
16047
+ helper.info(`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) updated version - ${direction}`);
16048
+ }
16049
+ });
16050
+ }
16051
+ }
16052
+
16053
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migration-helper.ts
16054
+ var migration_helper_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16055
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16056
+ return new (P || (P = Promise))(function (resolve, reject) {
16057
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16058
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16059
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16060
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16061
+ });
15952
16062
  };
15953
- class StateMigrationService {
15954
- constructor(storageService, secureStorageService, stateFactory) {
16063
+ class MigrationHelper {
16064
+ constructor(currentVersion, storageService, logService) {
16065
+ this.currentVersion = currentVersion;
15955
16066
  this.storageService = storageService;
15956
- this.secureStorageService = secureStorageService;
15957
- this.stateFactory = stateFactory;
16067
+ this.logService = logService;
16068
+ }
16069
+ get(key) {
16070
+ return this.storageService.get(key);
15958
16071
  }
15959
- needsMigration() {
15960
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
15961
- const currentStateVersion = yield this.getCurrentStateVersion();
15962
- return currentStateVersion == null || currentStateVersion < StateVersion.Latest;
16072
+ set(key, value) {
16073
+ this.logService.info(`Setting ${key}`);
16074
+ return this.storageService.save(key, value);
16075
+ }
16076
+ info(message) {
16077
+ this.logService.info(message);
16078
+ }
16079
+ getAccounts() {
16080
+ var _a;
16081
+ return migration_helper_awaiter(this, void 0, void 0, function* () {
16082
+ const userIds = (_a = (yield this.get("authenticatedAccounts"))) !== null && _a !== void 0 ? _a : [];
16083
+ return Promise.all(userIds.map((userId) => migration_helper_awaiter(this, void 0, void 0, function* () {
16084
+ return ({
16085
+ userId,
16086
+ account: yield this.get(userId),
16087
+ });
16088
+ })));
15963
16089
  });
15964
16090
  }
15965
- migrate() {
15966
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
15967
- let currentStateVersion = yield this.getCurrentStateVersion();
15968
- while (currentStateVersion < StateVersion.Latest) {
15969
- switch (currentStateVersion) {
15970
- case StateVersion.One:
15971
- yield this.migrateStateFrom1To2();
15972
- break;
15973
- case StateVersion.Two:
15974
- yield this.migrateStateFrom2To3();
15975
- break;
15976
- case StateVersion.Three:
15977
- yield this.migrateStateFrom3To4();
15978
- break;
15979
- case StateVersion.Four: {
15980
- const authenticatedAccounts = yield this.getAuthenticatedAccounts();
15981
- for (const account of authenticatedAccounts) {
15982
- const migratedAccount = yield this.migrateAccountFrom4To5(account);
15983
- yield this.set(account.profile.userId, migratedAccount);
15984
- }
15985
- yield this.setCurrentStateVersion(StateVersion.Five);
15986
- break;
15987
- }
15988
- case StateVersion.Five: {
15989
- const authenticatedAccounts = yield this.getAuthenticatedAccounts();
15990
- for (const account of authenticatedAccounts) {
15991
- const migratedAccount = yield this.migrateAccountFrom5To6(account);
15992
- yield this.set(account.profile.userId, migratedAccount);
16091
+ }
16092
+
16093
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrator.ts
16094
+ var migrator_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16095
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16096
+ return new (P || (P = Promise))(function (resolve, reject) {
16097
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16098
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16099
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16100
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16101
+ });
16102
+ };
16103
+ const IRREVERSIBLE = new Error("Irreversible migration");
16104
+ class Migrator {
16105
+ constructor(fromVersion, toVersion) {
16106
+ this.fromVersion = fromVersion;
16107
+ this.toVersion = toVersion;
16108
+ if (fromVersion == null || toVersion == null) {
16109
+ throw new Error("Invalid migration");
16110
+ }
16111
+ if (fromVersion > toVersion) {
16112
+ throw new Error("Invalid migration");
16113
+ }
16114
+ }
16115
+ shouldMigrate(helper, direction) {
16116
+ const startVersion = direction === "up" ? this.fromVersion : this.toVersion;
16117
+ return Promise.resolve(helper.currentVersion === startVersion);
16118
+ }
16119
+ updateVersion(helper, direction) {
16120
+ return migrator_awaiter(this, void 0, void 0, function* () {
16121
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16122
+ helper.currentVersion = endVersion;
16123
+ yield helper.set("stateVersion", endVersion);
16124
+ });
16125
+ }
16126
+ }
16127
+
16128
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/3-fix-premium.ts
16129
+ var _3_fix_premium_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16130
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16131
+ return new (P || (P = Promise))(function (resolve, reject) {
16132
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16133
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16134
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16135
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16136
+ });
16137
+ };
16138
+ // eslint-disable-next-line import/no-restricted-paths -- Used for token decoding, which are valid for days. We want the latest
16139
+
16140
+
16141
+ class FixPremiumMigrator extends Migrator {
16142
+ migrate(helper) {
16143
+ return _3_fix_premium_awaiter(this, void 0, void 0, function* () {
16144
+ const accounts = yield helper.getAccounts();
16145
+ function fixPremium(userId, account) {
16146
+ var _a, _b;
16147
+ return _3_fix_premium_awaiter(this, void 0, void 0, function* () {
16148
+ if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.hasPremiumPersonally) === null && ((_b = account.tokens) === null || _b === void 0 ? void 0 : _b.accessToken) != null) {
16149
+ let decodedToken;
16150
+ try {
16151
+ decodedToken = yield TokenService.decodeToken(account.tokens.accessToken);
15993
16152
  }
15994
- yield this.setCurrentStateVersion(StateVersion.Six);
15995
- break;
15996
- }
15997
- case StateVersion.Six: {
15998
- const authenticatedAccounts = yield this.getAuthenticatedAccounts();
15999
- const globals = (yield this.getGlobals());
16000
- for (const account of authenticatedAccounts) {
16001
- const migratedAccount = yield this.migrateAccountFrom6To7(globals === null || globals === void 0 ? void 0 : globals.noAutoPromptBiometrics, account);
16002
- yield this.set(account.profile.userId, migratedAccount);
16153
+ catch (_c) {
16154
+ return;
16003
16155
  }
16004
- if (globals) {
16005
- delete globals.noAutoPromptBiometrics;
16156
+ if ((decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.premium) == null) {
16157
+ return;
16006
16158
  }
16007
- yield this.set(keys.global, globals);
16008
- yield this.setCurrentStateVersion(StateVersion.Seven);
16159
+ account.profile.hasPremiumPersonally = decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.premium;
16160
+ return helper.set(userId, account);
16009
16161
  }
16010
- }
16011
- currentStateVersion += 1;
16162
+ });
16012
16163
  }
16164
+ yield Promise.all(accounts.map(({ userId, account }) => fixPremium(userId, account)));
16013
16165
  });
16014
16166
  }
16015
- migrateStateFrom1To2() {
16016
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22;
16017
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16018
- const clearV1Keys = (clearingUserId) => state_migration_service_awaiter(this, void 0, void 0, function* () {
16019
- for (const key in v1Keys) {
16020
- if (key == null) {
16021
- continue;
16022
- }
16023
- yield this.set(v1Keys[key], null);
16024
- }
16025
- if (clearingUserId != null) {
16026
- for (const keyPrefix in v1KeyPrefixes) {
16027
- if (keyPrefix == null) {
16028
- continue;
16029
- }
16030
- yield this.set(v1KeyPrefixes[keyPrefix] + userId, null);
16167
+ rollback(helper) {
16168
+ throw IRREVERSIBLE;
16169
+ }
16170
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16171
+ // it is nested inside a global object.
16172
+ updateVersion(helper, direction) {
16173
+ return _3_fix_premium_awaiter(this, void 0, void 0, function* () {
16174
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16175
+ helper.currentVersion = endVersion;
16176
+ const global = (yield helper.get("global")) || {};
16177
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16178
+ });
16179
+ }
16180
+ }
16181
+
16182
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/4-remove-ever-been-unlocked.ts
16183
+ var _4_remove_ever_been_unlocked_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16184
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16185
+ return new (P || (P = Promise))(function (resolve, reject) {
16186
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16187
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16188
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16189
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16190
+ });
16191
+ };
16192
+
16193
+ class RemoveEverBeenUnlockedMigrator extends Migrator {
16194
+ migrate(helper) {
16195
+ return _4_remove_ever_been_unlocked_awaiter(this, void 0, void 0, function* () {
16196
+ const accounts = yield helper.getAccounts();
16197
+ function removeEverBeenUnlocked(userId, account) {
16198
+ var _a;
16199
+ return _4_remove_ever_been_unlocked_awaiter(this, void 0, void 0, function* () {
16200
+ if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.everBeenUnlocked) != null) {
16201
+ delete account.profile.everBeenUnlocked;
16202
+ return helper.set(userId, account);
16031
16203
  }
16032
- }
16033
- });
16034
- // Some processes, like biometrics, may have already defined a value before migrations are run.
16035
- // We don't want to null out those values if they don't exist in the old storage scheme (like for new installs)
16036
- // So, the OOO for migration is that we:
16037
- // 1. Check for an existing storage value from the old storage structure OR
16038
- // 2. Check for a value already set by processes that run before migration OR
16039
- // 3. Assign the default value
16040
- const globals = (_a = (yield this.get(keys.global))) !== null && _a !== void 0 ? _a : this.stateFactory.createGlobal(null);
16041
- globals.stateVersion = StateVersion.Two;
16042
- globals.environmentUrls =
16043
- (_b = (yield this.get(v1Keys.environmentUrls))) !== null && _b !== void 0 ? _b : globals.environmentUrls;
16044
- globals.locale = (_c = (yield this.get(v1Keys.locale))) !== null && _c !== void 0 ? _c : globals.locale;
16045
- globals.noAutoPromptBiometrics =
16046
- (_d = (yield this.get(v1Keys.disableAutoBiometricsPrompt))) !== null && _d !== void 0 ? _d : globals.noAutoPromptBiometrics;
16047
- globals.noAutoPromptBiometricsText =
16048
- (_e = (yield this.get(v1Keys.noAutoPromptBiometricsText))) !== null && _e !== void 0 ? _e : globals.noAutoPromptBiometricsText;
16049
- globals.ssoCodeVerifier =
16050
- (_f = (yield this.get(v1Keys.ssoCodeVerifier))) !== null && _f !== void 0 ? _f : globals.ssoCodeVerifier;
16051
- globals.ssoOrganizationIdentifier =
16052
- (_g = (yield this.get(v1Keys.ssoIdentifier))) !== null && _g !== void 0 ? _g : globals.ssoOrganizationIdentifier;
16053
- globals.ssoState = (_h = (yield this.get(v1Keys.ssoState))) !== null && _h !== void 0 ? _h : globals.ssoState;
16054
- globals.rememberedEmail =
16055
- (_j = (yield this.get(v1Keys.rememberedEmail))) !== null && _j !== void 0 ? _j : globals.rememberedEmail;
16056
- globals.theme = (_k = (yield this.get(v1Keys.theme))) !== null && _k !== void 0 ? _k : globals.theme;
16057
- globals.vaultTimeout = (_l = (yield this.get(v1Keys.vaultTimeout))) !== null && _l !== void 0 ? _l : globals.vaultTimeout;
16058
- globals.vaultTimeoutAction =
16059
- (_m = (yield this.get(v1Keys.vaultTimeoutAction))) !== null && _m !== void 0 ? _m : globals.vaultTimeoutAction;
16060
- globals.window = (_o = (yield this.get(v1Keys.mainWindowSize))) !== null && _o !== void 0 ? _o : globals.window;
16061
- globals.enableTray = (_p = (yield this.get(v1Keys.enableTray))) !== null && _p !== void 0 ? _p : globals.enableTray;
16062
- globals.enableMinimizeToTray =
16063
- (_q = (yield this.get(v1Keys.enableMinimizeToTray))) !== null && _q !== void 0 ? _q : globals.enableMinimizeToTray;
16064
- globals.enableCloseToTray =
16065
- (_r = (yield this.get(v1Keys.enableCloseToTray))) !== null && _r !== void 0 ? _r : globals.enableCloseToTray;
16066
- globals.enableStartToTray =
16067
- (_s = (yield this.get(v1Keys.enableStartToTray))) !== null && _s !== void 0 ? _s : globals.enableStartToTray;
16068
- globals.openAtLogin = (_t = (yield this.get(v1Keys.openAtLogin))) !== null && _t !== void 0 ? _t : globals.openAtLogin;
16069
- globals.alwaysShowDock =
16070
- (_u = (yield this.get(v1Keys.alwaysShowDock))) !== null && _u !== void 0 ? _u : globals.alwaysShowDock;
16071
- globals.enableBrowserIntegration =
16072
- (_v = (yield this.get(v1Keys.enableBrowserIntegration))) !== null && _v !== void 0 ? _v : globals.enableBrowserIntegration;
16073
- globals.enableBrowserIntegrationFingerprint =
16074
- (_w = (yield this.get(v1Keys.enableBrowserIntegrationFingerprint))) !== null && _w !== void 0 ? _w : globals.enableBrowserIntegrationFingerprint;
16075
- const userId = (_x = (yield this.get(v1Keys.userId))) !== null && _x !== void 0 ? _x : (yield this.get(v1Keys.entityId));
16076
- const defaultAccount = this.stateFactory.createAccount(null);
16077
- const accountSettings = {
16078
- autoConfirmFingerPrints: (_y = (yield this.get(v1Keys.autoConfirmFingerprints))) !== null && _y !== void 0 ? _y : defaultAccount.settings.autoConfirmFingerPrints,
16079
- autoFillOnPageLoadDefault: (_z = (yield this.get(v1Keys.autoFillOnPageLoadDefault))) !== null && _z !== void 0 ? _z : defaultAccount.settings.autoFillOnPageLoadDefault,
16080
- biometricUnlock: (_0 = (yield this.get(v1Keys.biometricUnlock))) !== null && _0 !== void 0 ? _0 : defaultAccount.settings.biometricUnlock,
16081
- clearClipboard: (_1 = (yield this.get(v1Keys.clearClipboard))) !== null && _1 !== void 0 ? _1 : defaultAccount.settings.clearClipboard,
16082
- defaultUriMatch: (_2 = (yield this.get(v1Keys.defaultUriMatch))) !== null && _2 !== void 0 ? _2 : defaultAccount.settings.defaultUriMatch,
16083
- disableAddLoginNotification: (_3 = (yield this.get(v1Keys.disableAddLoginNotification))) !== null && _3 !== void 0 ? _3 : defaultAccount.settings.disableAddLoginNotification,
16084
- disableAutoBiometricsPrompt: (_4 = (yield this.get(v1Keys.disableAutoBiometricsPrompt))) !== null && _4 !== void 0 ? _4 : defaultAccount.settings.disableAutoBiometricsPrompt,
16085
- disableAutoTotpCopy: (_5 = (yield this.get(v1Keys.disableAutoTotpCopy))) !== null && _5 !== void 0 ? _5 : defaultAccount.settings.disableAutoTotpCopy,
16086
- disableBadgeCounter: (_6 = (yield this.get(v1Keys.disableBadgeCounter))) !== null && _6 !== void 0 ? _6 : defaultAccount.settings.disableBadgeCounter,
16087
- disableChangedPasswordNotification: (_7 = (yield this.get(v1Keys.disableChangedPasswordNotification))) !== null && _7 !== void 0 ? _7 : defaultAccount.settings.disableChangedPasswordNotification,
16088
- disableContextMenuItem: (_8 = (yield this.get(v1Keys.disableContextMenuItem))) !== null && _8 !== void 0 ? _8 : defaultAccount.settings.disableContextMenuItem,
16089
- disableGa: (_9 = (yield this.get(v1Keys.disableGa))) !== null && _9 !== void 0 ? _9 : defaultAccount.settings.disableGa,
16090
- dontShowCardsCurrentTab: (_10 = (yield this.get(v1Keys.dontShowCardsCurrentTab))) !== null && _10 !== void 0 ? _10 : defaultAccount.settings.dontShowCardsCurrentTab,
16091
- dontShowIdentitiesCurrentTab: (_11 = (yield this.get(v1Keys.dontShowIdentitiesCurrentTab))) !== null && _11 !== void 0 ? _11 : defaultAccount.settings.dontShowIdentitiesCurrentTab,
16092
- enableAlwaysOnTop: (_12 = (yield this.get(v1Keys.enableAlwaysOnTop))) !== null && _12 !== void 0 ? _12 : defaultAccount.settings.enableAlwaysOnTop,
16093
- enableAutoFillOnPageLoad: (_13 = (yield this.get(v1Keys.enableAutoFillOnPageLoad))) !== null && _13 !== void 0 ? _13 : defaultAccount.settings.enableAutoFillOnPageLoad,
16094
- enableBiometric: (_14 = (yield this.get(v1Keys.enableBiometric))) !== null && _14 !== void 0 ? _14 : defaultAccount.settings.enableBiometric,
16095
- enableFullWidth: (_15 = (yield this.get(v1Keys.enableFullWidth))) !== null && _15 !== void 0 ? _15 : defaultAccount.settings.enableFullWidth,
16096
- environmentUrls: (_16 = globals.environmentUrls) !== null && _16 !== void 0 ? _16 : defaultAccount.settings.environmentUrls,
16097
- equivalentDomains: (_17 = (yield this.get(v1Keys.equivalentDomains))) !== null && _17 !== void 0 ? _17 : defaultAccount.settings.equivalentDomains,
16098
- minimizeOnCopyToClipboard: (_18 = (yield this.get(v1Keys.minimizeOnCopyToClipboard))) !== null && _18 !== void 0 ? _18 : defaultAccount.settings.minimizeOnCopyToClipboard,
16099
- neverDomains: (_19 = (yield this.get(v1Keys.neverDomains))) !== null && _19 !== void 0 ? _19 : defaultAccount.settings.neverDomains,
16100
- passwordGenerationOptions: (_20 = (yield this.get(v1Keys.passwordGenerationOptions))) !== null && _20 !== void 0 ? _20 : defaultAccount.settings.passwordGenerationOptions,
16101
- pinProtected: Object.assign(new EncryptionPair(), {
16102
- decrypted: null,
16103
- encrypted: yield this.get(v1Keys.pinProtected),
16104
- }),
16105
- protectedPin: yield this.get(v1Keys.protectedPin),
16106
- settings: userId == null
16107
- ? null
16108
- : yield this.get(v1KeyPrefixes.settings + userId),
16109
- vaultTimeout: (_21 = (yield this.get(v1Keys.vaultTimeout))) !== null && _21 !== void 0 ? _21 : defaultAccount.settings.vaultTimeout,
16110
- vaultTimeoutAction: (_22 = (yield this.get(v1Keys.vaultTimeoutAction))) !== null && _22 !== void 0 ? _22 : defaultAccount.settings.vaultTimeoutAction,
16111
- };
16112
- // (userId == null) = no logged in user (so no known userId) and we need to temporarily store account specific settings in state to migrate on first auth
16113
- // (userId != null) = we have a currently authed user (so known userId) with encrypted data and other key settings we can move, no need to temporarily store account settings
16114
- if (userId == null) {
16115
- yield this.set(keys.tempAccountSettings, accountSettings);
16116
- yield this.set(keys.global, globals);
16117
- yield this.set(keys.authenticatedAccounts, []);
16118
- yield this.set(keys.activeUserId, null);
16119
- yield clearV1Keys();
16120
- return;
16121
- }
16122
- globals.twoFactorToken = yield this.get(v1KeyPrefixes.twoFactorToken + userId);
16123
- yield this.set(keys.global, globals);
16124
- yield this.set(userId, {
16125
- data: {
16126
- addEditCipherInfo: null,
16127
- ciphers: {
16128
- decrypted: null,
16129
- encrypted: yield this.get(v1KeyPrefixes.ciphers + userId),
16130
- },
16131
- collapsedGroupings: null,
16132
- collections: {
16133
- decrypted: null,
16134
- encrypted: yield this.get(v1KeyPrefixes.collections + userId),
16135
- },
16136
- eventCollection: yield this.get(v1Keys.eventCollection),
16137
- folders: {
16138
- decrypted: null,
16139
- encrypted: yield this.get(v1KeyPrefixes.folders + userId),
16140
- },
16141
- localData: null,
16142
- organizations: yield this.get(v1KeyPrefixes.organizations + userId),
16143
- passwordGenerationHistory: {
16144
- decrypted: null,
16145
- encrypted: yield this.get(v1Keys.history),
16146
- },
16147
- policies: {
16148
- decrypted: null,
16149
- encrypted: yield this.get(v1KeyPrefixes.policies + userId),
16150
- },
16151
- providers: yield this.get(v1KeyPrefixes.providers + userId),
16152
- sends: {
16153
- decrypted: null,
16154
- encrypted: yield this.get(v1KeyPrefixes.sends + userId),
16155
- },
16156
- },
16157
- keys: {
16158
- apiKeyClientSecret: yield this.get(v1Keys.clientSecret),
16159
- cryptoMasterKey: null,
16160
- cryptoMasterKeyAuto: null,
16161
- cryptoMasterKeyB64: null,
16162
- cryptoMasterKeyBiometric: null,
16163
- cryptoSymmetricKey: {
16164
- encrypted: yield this.get(v1Keys.encKey),
16165
- decrypted: null,
16166
- },
16167
- legacyEtmKey: null,
16168
- organizationKeys: {
16169
- decrypted: null,
16170
- encrypted: yield this.get(v1Keys.encOrgKeys),
16171
- },
16172
- privateKey: {
16173
- decrypted: null,
16174
- encrypted: yield this.get(v1Keys.encPrivate),
16175
- },
16176
- providerKeys: {
16177
- decrypted: null,
16178
- encrypted: yield this.get(v1Keys.encProviderKeys),
16179
- },
16180
- publicKey: null,
16181
- },
16182
- profile: {
16183
- apiKeyClientId: yield this.get(v1Keys.clientId),
16184
- authenticationStatus: null,
16185
- convertAccountToKeyConnector: yield this.get(v1Keys.convertAccountToKeyConnector),
16186
- email: yield this.get(v1Keys.userEmail),
16187
- emailVerified: yield this.get(v1Keys.emailVerified),
16188
- entityId: null,
16189
- entityType: null,
16190
- everBeenUnlocked: null,
16191
- forcePasswordReset: null,
16192
- hasPremiumPersonally: null,
16193
- kdfIterations: yield this.get(v1Keys.kdfIterations),
16194
- kdfType: yield this.get(v1Keys.kdf),
16195
- keyHash: yield this.get(v1Keys.keyHash),
16196
- lastSync: null,
16197
- userId: userId,
16198
- usesKeyConnector: null,
16199
- },
16200
- settings: accountSettings,
16201
- tokens: {
16202
- accessToken: yield this.get(v1Keys.accessToken),
16203
- decodedToken: null,
16204
- refreshToken: yield this.get(v1Keys.refreshToken),
16205
- securityStamp: null,
16206
- },
16207
- });
16208
- yield this.set(keys.authenticatedAccounts, [userId]);
16209
- yield this.set(keys.activeUserId, userId);
16210
- const accountActivity = {
16211
- [userId]: yield this.get(v1Keys.lastActive),
16212
- };
16213
- accountActivity[userId] = yield this.get(v1Keys.lastActive);
16214
- yield this.set(keys.accountActivity, accountActivity);
16215
- yield clearV1Keys(userId);
16216
- if (yield this.secureStorageService.has(v1Keys.key, { keySuffix: "biometric" })) {
16217
- yield this.secureStorageService.save(`${userId}${partialKeys.biometricKey}`, yield this.secureStorageService.get(v1Keys.key, { keySuffix: "biometric" }), { keySuffix: "biometric" });
16218
- yield this.secureStorageService.remove(v1Keys.key, { keySuffix: "biometric" });
16219
- }
16220
- if (yield this.secureStorageService.has(v1Keys.key, { keySuffix: "auto" })) {
16221
- yield this.secureStorageService.save(`${userId}${partialKeys.autoKey}`, yield this.secureStorageService.get(v1Keys.key, { keySuffix: "auto" }), { keySuffix: "auto" });
16222
- yield this.secureStorageService.remove(v1Keys.key, { keySuffix: "auto" });
16223
- }
16224
- if (yield this.secureStorageService.has(v1Keys.key)) {
16225
- yield this.secureStorageService.save(`${userId}${partialKeys.masterKey}`, yield this.secureStorageService.get(v1Keys.key));
16226
- yield this.secureStorageService.remove(v1Keys.key);
16204
+ });
16227
16205
  }
16206
+ Promise.all(accounts.map(({ userId, account }) => removeEverBeenUnlocked(userId, account)));
16228
16207
  });
16229
16208
  }
16230
- migrateStateFrom2To3() {
16231
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16232
- const authenticatedUserIds = yield this.get(keys.authenticatedAccounts);
16233
- yield Promise.all(authenticatedUserIds.map((userId) => state_migration_service_awaiter(this, void 0, void 0, function* () {
16234
- var _a, _b;
16235
- const account = yield this.get(userId);
16236
- if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.hasPremiumPersonally) === null &&
16237
- ((_b = account.tokens) === null || _b === void 0 ? void 0 : _b.accessToken) != null) {
16238
- const decodedToken = yield TokenService.decodeToken(account.tokens.accessToken);
16239
- account.profile.hasPremiumPersonally = decodedToken.premium;
16240
- yield this.set(userId, account);
16241
- }
16242
- })));
16243
- const globals = yield this.getGlobals();
16244
- globals.stateVersion = StateVersion.Three;
16245
- yield this.set(keys.global, globals);
16209
+ rollback(helper) {
16210
+ throw IRREVERSIBLE;
16211
+ }
16212
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16213
+ // it is nested inside a global object.
16214
+ updateVersion(helper, direction) {
16215
+ return _4_remove_ever_been_unlocked_awaiter(this, void 0, void 0, function* () {
16216
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16217
+ helper.currentVersion = endVersion;
16218
+ const global = (yield helper.get("global")) || {};
16219
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16246
16220
  });
16247
16221
  }
16248
- migrateStateFrom3To4() {
16249
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16250
- const authenticatedUserIds = yield this.get(keys.authenticatedAccounts);
16251
- yield Promise.all(authenticatedUserIds.map((userId) => state_migration_service_awaiter(this, void 0, void 0, function* () {
16252
- var _a;
16253
- const account = yield this.get(userId);
16254
- if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.everBeenUnlocked) != null) {
16255
- delete account.profile.everBeenUnlocked;
16256
- return this.set(userId, account);
16257
- }
16258
- })));
16259
- const globals = yield this.getGlobals();
16260
- globals.stateVersion = StateVersion.Four;
16261
- yield this.set(keys.global, globals);
16222
+ }
16223
+
16224
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/5-add-key-type-to-org-keys.ts
16225
+ var _5_add_key_type_to_org_keys_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16226
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16227
+ return new (P || (P = Promise))(function (resolve, reject) {
16228
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16229
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16230
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16231
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16232
+ });
16233
+ };
16234
+
16235
+ class AddKeyTypeToOrgKeysMigrator extends Migrator {
16236
+ migrate(helper) {
16237
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16238
+ const accounts = yield helper.getAccounts();
16239
+ function updateOrgKey(userId, account) {
16240
+ var _a, _b;
16241
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16242
+ const encryptedOrgKeys = (_b = (_a = account === null || account === void 0 ? void 0 : account.keys) === null || _a === void 0 ? void 0 : _a.organizationKeys) === null || _b === void 0 ? void 0 : _b.encrypted;
16243
+ if (encryptedOrgKeys == null) {
16244
+ return;
16245
+ }
16246
+ const newOrgKeys = {};
16247
+ Object.entries(encryptedOrgKeys).forEach(([orgId, encKey]) => {
16248
+ newOrgKeys[orgId] = {
16249
+ type: "organization",
16250
+ key: encKey,
16251
+ };
16252
+ });
16253
+ account.keys.organizationKeys.encrypted = newOrgKeys;
16254
+ yield helper.set(userId, account);
16255
+ });
16256
+ }
16257
+ Promise.all(accounts.map(({ userId, account }) => updateOrgKey(userId, account)));
16262
16258
  });
16263
16259
  }
16264
- migrateAccountFrom4To5(account) {
16265
- var _a, _b;
16266
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16267
- const encryptedOrgKeys = (_b = (_a = account.keys) === null || _a === void 0 ? void 0 : _a.organizationKeys) === null || _b === void 0 ? void 0 : _b.encrypted;
16268
- if (encryptedOrgKeys != null) {
16269
- for (const [orgId, encKey] of Object.entries(encryptedOrgKeys)) {
16270
- encryptedOrgKeys[orgId] = {
16271
- type: "organization",
16272
- key: encKey, // Account v4 does not reflect the current account model so we have to cast
16273
- };
16274
- }
16260
+ rollback(helper) {
16261
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16262
+ const accounts = yield helper.getAccounts();
16263
+ function updateOrgKey(userId, account) {
16264
+ var _a, _b;
16265
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16266
+ const encryptedOrgKeys = (_b = (_a = account === null || account === void 0 ? void 0 : account.keys) === null || _a === void 0 ? void 0 : _a.organizationKeys) === null || _b === void 0 ? void 0 : _b.encrypted;
16267
+ if (encryptedOrgKeys == null) {
16268
+ return;
16269
+ }
16270
+ const newOrgKeys = {};
16271
+ Object.entries(encryptedOrgKeys).forEach(([orgId, encKey]) => {
16272
+ newOrgKeys[orgId] = encKey.key;
16273
+ });
16274
+ account.keys.organizationKeys.encrypted = newOrgKeys;
16275
+ yield helper.set(userId, account);
16276
+ });
16275
16277
  }
16276
- return account;
16278
+ Promise.all(accounts.map(({ userId, account }) => _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () { return updateOrgKey(userId, account); })));
16277
16279
  });
16278
16280
  }
16279
- migrateAccountFrom5To6(account) {
16280
- var _a;
16281
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16282
- (_a = account.keys) === null || _a === void 0 ? true : delete _a.legacyEtmKey;
16283
- return account;
16281
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16282
+ // it is nested inside a global object.
16283
+ updateVersion(helper, direction) {
16284
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16285
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16286
+ helper.currentVersion = endVersion;
16287
+ const global = (yield helper.get("global")) || {};
16288
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16284
16289
  });
16285
16290
  }
16286
- migrateAccountFrom6To7(globalSetting, account) {
16287
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16288
- if (globalSetting) {
16289
- account.settings = Object.assign({}, account.settings, { disableAutoBiometricsPrompt: true });
16291
+ }
16292
+
16293
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/6-remove-legacy-etm-key.ts
16294
+ var _6_remove_legacy_etm_key_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16295
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16296
+ return new (P || (P = Promise))(function (resolve, reject) {
16297
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16298
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16299
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16300
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16301
+ });
16302
+ };
16303
+
16304
+ class RemoveLegacyEtmKeyMigrator extends Migrator {
16305
+ migrate(helper) {
16306
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16307
+ const accounts = yield helper.getAccounts();
16308
+ function updateAccount(userId, account) {
16309
+ var _a;
16310
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16311
+ if ((_a = account === null || account === void 0 ? void 0 : account.keys) === null || _a === void 0 ? void 0 : _a.legacyEtmKey) {
16312
+ delete account.keys.legacyEtmKey;
16313
+ yield helper.set(userId, account);
16314
+ }
16315
+ });
16290
16316
  }
16291
- return account;
16317
+ yield Promise.all(accounts.map(({ userId, account }) => updateAccount(userId, account)));
16292
16318
  });
16293
16319
  }
16294
- get options() {
16295
- return { htmlStorageLocation: HtmlStorageLocation.Local };
16320
+ rollback(helper) {
16321
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16322
+ throw IRREVERSIBLE;
16323
+ });
16296
16324
  }
16297
- get(key) {
16298
- return this.storageService.get(key, this.options);
16325
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16326
+ // it is nested inside a global object.
16327
+ updateVersion(helper, direction) {
16328
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16329
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16330
+ helper.currentVersion = endVersion;
16331
+ const global = (yield helper.get("global")) || {};
16332
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16333
+ });
16299
16334
  }
16300
- set(key, value) {
16301
- if (value == null) {
16302
- return this.storageService.remove(key, this.options);
16303
- }
16304
- return this.storageService.save(key, value, this.options);
16335
+ }
16336
+
16337
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/7-move-biometric-auto-prompt-to-account.ts
16338
+ var _7_move_biometric_auto_prompt_to_account_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16339
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16340
+ return new (P || (P = Promise))(function (resolve, reject) {
16341
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16342
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16343
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16344
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16345
+ });
16346
+ };
16347
+
16348
+ class MoveBiometricAutoPromptToAccount extends Migrator {
16349
+ migrate(helper) {
16350
+ var _a;
16351
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16352
+ const global = yield helper.get("global");
16353
+ const noAutoPromptBiometrics = (_a = global === null || global === void 0 ? void 0 : global.noAutoPromptBiometrics) !== null && _a !== void 0 ? _a : false;
16354
+ const accounts = yield helper.getAccounts();
16355
+ function updateAccount(userId, account) {
16356
+ var _a;
16357
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16358
+ if (account == null) {
16359
+ return;
16360
+ }
16361
+ if (noAutoPromptBiometrics) {
16362
+ account.settings = Object.assign((_a = account === null || account === void 0 ? void 0 : account.settings) !== null && _a !== void 0 ? _a : {}, {
16363
+ disableAutoBiometricsPrompt: true,
16364
+ });
16365
+ yield helper.set(userId, account);
16366
+ }
16367
+ });
16368
+ }
16369
+ delete global.noAutoPromptBiometrics;
16370
+ yield Promise.all([
16371
+ ...accounts.map(({ userId, account }) => updateAccount(userId, account)),
16372
+ helper.set("global", global),
16373
+ ]);
16374
+ });
16305
16375
  }
16306
- getGlobals() {
16307
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16308
- return yield this.get(keys.global);
16376
+ rollback(helper) {
16377
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16378
+ throw IRREVERSIBLE;
16309
16379
  });
16310
16380
  }
16311
- getCurrentStateVersion() {
16312
- var _a, _b;
16313
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16314
- return (_b = (_a = (yield this.getGlobals())) === null || _a === void 0 ? void 0 : _a.stateVersion) !== null && _b !== void 0 ? _b : StateVersion.One;
16381
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16382
+ // it is nested inside a global object.
16383
+ updateVersion(helper, direction) {
16384
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16385
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16386
+ helper.currentVersion = endVersion;
16387
+ const global = (yield helper.get("global")) || {};
16388
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16315
16389
  });
16316
16390
  }
16317
- setCurrentStateVersion(newVersion) {
16318
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16319
- const globals = yield this.getGlobals();
16320
- globals.stateVersion = newVersion;
16321
- yield this.set(keys.global, globals);
16391
+ }
16392
+
16393
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/8-move-state-version.ts
16394
+ var _8_move_state_version_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16395
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16396
+ return new (P || (P = Promise))(function (resolve, reject) {
16397
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16398
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16399
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16400
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16401
+ });
16402
+ };
16403
+
16404
+ class MoveStateVersionMigrator extends Migrator {
16405
+ migrate(helper) {
16406
+ return _8_move_state_version_awaiter(this, void 0, void 0, function* () {
16407
+ const global = yield helper.get("global");
16408
+ if (global.stateVersion) {
16409
+ yield helper.set("stateVersion", global.stateVersion);
16410
+ delete global.stateVersion;
16411
+ yield helper.set("global", global);
16412
+ }
16413
+ else {
16414
+ throw new Error("Migration failed, state version not found");
16415
+ }
16322
16416
  });
16323
16417
  }
16324
- getAuthenticatedAccounts() {
16325
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16326
- const authenticatedUserIds = yield this.get(keys.authenticatedAccounts);
16327
- return Promise.all(authenticatedUserIds.map((id) => this.get(id)));
16418
+ rollback(helper) {
16419
+ return _8_move_state_version_awaiter(this, void 0, void 0, function* () {
16420
+ const version = yield helper.get("stateVersion");
16421
+ const global = yield helper.get("global");
16422
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: version }));
16423
+ yield helper.set("stateVersion", undefined);
16424
+ });
16425
+ }
16426
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but this migration moves
16427
+ // it from a `global` object to root.This makes for unique rollback versioning.
16428
+ updateVersion(helper, direction) {
16429
+ return _8_move_state_version_awaiter(this, void 0, void 0, function* () {
16430
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16431
+ helper.currentVersion = endVersion;
16432
+ if (direction === "up") {
16433
+ yield helper.set("stateVersion", endVersion);
16434
+ }
16435
+ else {
16436
+ const global = (yield helper.get("global")) || {};
16437
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16438
+ }
16328
16439
  });
16329
16440
  }
16330
16441
  }
16331
16442
 
16332
- ;// CONCATENATED MODULE: ../../libs/common/src/admin-console/models/data/provider.data.ts
16333
- class ProviderData {
16334
- constructor(response) {
16335
- this.id = response.id;
16336
- this.name = response.name;
16337
- this.status = response.status;
16338
- this.type = response.type;
16339
- this.enabled = response.enabled;
16340
- this.userId = response.userId;
16341
- this.useEvents = response.useEvents;
16443
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/min-version.ts
16444
+ var min_version_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16445
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16446
+ return new (P || (P = Promise))(function (resolve, reject) {
16447
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16448
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16449
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16450
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16451
+ });
16452
+ };
16453
+
16454
+
16455
+ function minVersionError(current) {
16456
+ return `Your local data is too old to be migrated. Your current state version is ${current}, but minimum version is ${MIN_VERSION}.`;
16457
+ }
16458
+ class MinVersionMigrator extends Migrator {
16459
+ constructor() {
16460
+ super(0, MIN_VERSION);
16461
+ }
16462
+ // Overrides the default implementation to catch any version that may be passed in.
16463
+ shouldMigrate(helper) {
16464
+ return Promise.resolve(helper.currentVersion < MIN_VERSION);
16465
+ }
16466
+ migrate(helper) {
16467
+ return min_version_awaiter(this, void 0, void 0, function* () {
16468
+ if (helper.currentVersion < MIN_VERSION) {
16469
+ throw new Error(minVersionError(helper.currentVersion));
16470
+ }
16471
+ });
16472
+ }
16473
+ rollback(helper) {
16474
+ return min_version_awaiter(this, void 0, void 0, function* () {
16475
+ throw IRREVERSIBLE;
16476
+ });
16342
16477
  }
16343
16478
  }
16344
16479
 
16345
- ;// CONCATENATED MODULE: ../../libs/common/src/enums/vault-timeout-action.enum.ts
16346
- var VaultTimeoutAction;
16347
- (function (VaultTimeoutAction) {
16348
- VaultTimeoutAction["Lock"] = "lock";
16349
- VaultTimeoutAction["LogOut"] = "logOut";
16350
- })(VaultTimeoutAction || (VaultTimeoutAction = {}));
16351
-
16352
- ;// CONCATENATED MODULE: ../../libs/common/src/models/data/event.data.ts
16353
- class EventData {
16480
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrate.ts
16481
+ var migrate_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16482
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16483
+ return new (P || (P = Promise))(function (resolve, reject) {
16484
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16485
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16486
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16487
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16488
+ });
16489
+ };
16490
+
16491
+
16492
+
16493
+
16494
+
16495
+
16496
+
16497
+
16498
+
16499
+ const MIN_VERSION = 2;
16500
+ const CURRENT_VERSION = 8;
16501
+ function migrate(storageService, logService) {
16502
+ return migrate_awaiter(this, void 0, void 0, function* () {
16503
+ const migrationHelper = new MigrationHelper(yield currentVersion(storageService, logService), storageService, logService);
16504
+ if (migrationHelper.currentVersion < 0) {
16505
+ // Cannot determine state, assuming empty so we don't repeatedly apply a migration.
16506
+ yield storageService.save("stateVersion", CURRENT_VERSION);
16507
+ return;
16508
+ }
16509
+ MigrationBuilder.create()
16510
+ .with(MinVersionMigrator)
16511
+ .with(FixPremiumMigrator, 2, 3)
16512
+ .with(RemoveEverBeenUnlockedMigrator, 3, 4)
16513
+ .with(AddKeyTypeToOrgKeysMigrator, 4, 5)
16514
+ .with(RemoveLegacyEtmKeyMigrator, 5, 6)
16515
+ .with(MoveBiometricAutoPromptToAccount, 6, 7)
16516
+ .with(MoveStateVersionMigrator, 7, CURRENT_VERSION)
16517
+ .migrate(migrationHelper);
16518
+ });
16519
+ }
16520
+ function currentVersion(storageService, logService) {
16521
+ var _a;
16522
+ return migrate_awaiter(this, void 0, void 0, function* () {
16523
+ let state = yield storageService.get("stateVersion");
16524
+ if (state == null) {
16525
+ // Pre v8
16526
+ state = (_a = (yield storageService.get("global"))) === null || _a === void 0 ? void 0 : _a.stateVersion;
16527
+ }
16528
+ if (state == null) {
16529
+ logService.info("No state version found, assuming empty state.");
16530
+ return -1;
16531
+ }
16532
+ logService.info(`State version: ${state}`);
16533
+ return state;
16534
+ });
16354
16535
  }
16355
16536
 
16537
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/index.ts
16538
+
16539
+
16356
16540
  ;// CONCATENATED MODULE: ../../libs/common/src/admin-console/models/domain/password-generator-policy-options.ts
16357
16541
 
16358
16542
  class PasswordGeneratorPolicyOptions extends Domain {
@@ -17244,6 +17428,7 @@ class CipherData {
17244
17428
  this.creationDate = response.creationDate;
17245
17429
  this.deletedDate = response.deletedDate;
17246
17430
  this.reprompt = response.reprompt;
17431
+ this.key = response.key;
17247
17432
  switch (this.type) {
17248
17433
  case CipherType.Login:
17249
17434
  this.login = new LoginData(response.login);
@@ -18301,15 +18486,17 @@ var state_service_awaiter = (undefined && undefined.__awaiter) || function (this
18301
18486
 
18302
18487
 
18303
18488
 
18304
- const state_service_keys = {
18489
+
18490
+ const keys = {
18305
18491
  state: "state",
18492
+ stateVersion: "stateVersion",
18306
18493
  global: "global",
18307
18494
  authenticatedAccounts: "authenticatedAccounts",
18308
18495
  activeUserId: "activeUserId",
18309
18496
  tempAccountSettings: "tempAccountSettings",
18310
18497
  accountActivity: "accountActivity",
18311
18498
  };
18312
- const state_service_partialKeys = {
18499
+ const partialKeys = {
18313
18500
  userAutoKey: "_user_auto",
18314
18501
  userBiometricKey: "_user_biometric",
18315
18502
  autoKey: "_masterkey_auto",
@@ -18318,12 +18505,11 @@ const state_service_partialKeys = {
18318
18505
  };
18319
18506
  const DDG_SHARED_KEY = "DuckDuckGoSharedKey";
18320
18507
  class StateService {
18321
- constructor(storageService, secureStorageService, memoryStorageService, logService, stateMigrationService, stateFactory, useAccountCache = true) {
18508
+ constructor(storageService, secureStorageService, memoryStorageService, logService, stateFactory, useAccountCache = true) {
18322
18509
  this.storageService = storageService;
18323
18510
  this.secureStorageService = secureStorageService;
18324
18511
  this.memoryStorageService = memoryStorageService;
18325
18512
  this.logService = logService;
18326
- this.stateMigrationService = stateMigrationService;
18327
18513
  this.stateFactory = stateFactory;
18328
18514
  this.useAccountCache = useAccountCache;
18329
18515
  this.accountsSubject = new external_rxjs_namespaceObject.BehaviorSubject({});
@@ -18358,9 +18544,7 @@ class StateService {
18358
18544
  if (this.hasBeenInited) {
18359
18545
  return;
18360
18546
  }
18361
- if (yield this.stateMigrationService.needsMigration()) {
18362
- yield this.stateMigrationService.migrate();
18363
- }
18547
+ yield migrate(this.storageService, this.logService);
18364
18548
  yield this.state().then((state) => state_service_awaiter(this, void 0, void 0, function* () {
18365
18549
  if (state == null) {
18366
18550
  yield this.setState(new State(this.createGlobals()));
@@ -18381,13 +18565,13 @@ class StateService {
18381
18565
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
18382
18566
  var _a;
18383
18567
  state.authenticatedAccounts =
18384
- (_a = (yield this.storageService.get(state_service_keys.authenticatedAccounts))) !== null && _a !== void 0 ? _a : [];
18568
+ (_a = (yield this.storageService.get(keys.authenticatedAccounts))) !== null && _a !== void 0 ? _a : [];
18385
18569
  for (const i in state.authenticatedAccounts) {
18386
18570
  if (i != null) {
18387
18571
  yield this.syncAccountFromDisk(state.authenticatedAccounts[i]);
18388
18572
  }
18389
18573
  }
18390
- const storedActiveUser = yield this.storageService.get(state_service_keys.activeUserId);
18574
+ const storedActiveUser = yield this.storageService.get(keys.activeUserId);
18391
18575
  if (storedActiveUser != null) {
18392
18576
  state.activeUserId = storedActiveUser;
18393
18577
  }
@@ -18418,7 +18602,7 @@ class StateService {
18418
18602
  account = yield this.setAccountEnvironment(account);
18419
18603
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
18420
18604
  state.authenticatedAccounts.push(account.profile.userId);
18421
- yield this.storageService.save(state_service_keys.authenticatedAccounts, state.authenticatedAccounts);
18605
+ yield this.storageService.save(keys.authenticatedAccounts, state.authenticatedAccounts);
18422
18606
  state.accounts[account.profile.userId] = account;
18423
18607
  return state;
18424
18608
  }));
@@ -18433,7 +18617,7 @@ class StateService {
18433
18617
  this.clearDecryptedDataForActiveUser();
18434
18618
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
18435
18619
  state.activeUserId = userId;
18436
- yield this.storageService.save(state_service_keys.activeUserId, userId);
18620
+ yield this.storageService.save(keys.activeUserId, userId);
18437
18621
  this.activeAccountSubject.next(state.activeUserId);
18438
18622
  return state;
18439
18623
  }));
@@ -18797,7 +18981,7 @@ class StateService {
18797
18981
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18798
18982
  return null;
18799
18983
  }
18800
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.userAutoKey}`, options);
18984
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.userAutoKey}`, options);
18801
18985
  });
18802
18986
  }
18803
18987
  /**
@@ -18809,7 +18993,7 @@ class StateService {
18809
18993
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18810
18994
  return;
18811
18995
  }
18812
- yield this.saveSecureStorageKey(state_service_partialKeys.userAutoKey, value, options);
18996
+ yield this.saveSecureStorageKey(partialKeys.userAutoKey, value, options);
18813
18997
  });
18814
18998
  }
18815
18999
  /**
@@ -18821,7 +19005,7 @@ class StateService {
18821
19005
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18822
19006
  return null;
18823
19007
  }
18824
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.userBiometricKey}`, options);
19008
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.userBiometricKey}`, options);
18825
19009
  });
18826
19010
  }
18827
19011
  hasUserKeyBiometric(options) {
@@ -18830,7 +19014,7 @@ class StateService {
18830
19014
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18831
19015
  return false;
18832
19016
  }
18833
- return yield this.secureStorageService.has(`${options.userId}${state_service_partialKeys.userBiometricKey}`, options);
19017
+ return yield this.secureStorageService.has(`${options.userId}${partialKeys.userBiometricKey}`, options);
18834
19018
  });
18835
19019
  }
18836
19020
  setUserKeyBiometric(value, options) {
@@ -18839,7 +19023,7 @@ class StateService {
18839
19023
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18840
19024
  return;
18841
19025
  }
18842
- yield this.saveSecureStorageKey(state_service_partialKeys.userBiometricKey, value, options);
19026
+ yield this.saveSecureStorageKey(partialKeys.userBiometricKey, value, options);
18843
19027
  });
18844
19028
  }
18845
19029
  getPinKeyEncryptedUserKey(options) {
@@ -18877,7 +19061,7 @@ class StateService {
18877
19061
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18878
19062
  return null;
18879
19063
  }
18880
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.autoKey}`, options);
19064
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.autoKey}`, options);
18881
19065
  });
18882
19066
  }
18883
19067
  /**
@@ -18889,7 +19073,7 @@ class StateService {
18889
19073
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18890
19074
  return;
18891
19075
  }
18892
- yield this.saveSecureStorageKey(state_service_partialKeys.autoKey, value, options);
19076
+ yield this.saveSecureStorageKey(partialKeys.autoKey, value, options);
18893
19077
  });
18894
19078
  }
18895
19079
  /**
@@ -18901,7 +19085,7 @@ class StateService {
18901
19085
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18902
19086
  return null;
18903
19087
  }
18904
- return yield this.secureStorageService.get(`${options === null || options === void 0 ? void 0 : options.userId}${state_service_partialKeys.masterKey}`, options);
19088
+ return yield this.secureStorageService.get(`${options === null || options === void 0 ? void 0 : options.userId}${partialKeys.masterKey}`, options);
18905
19089
  });
18906
19090
  }
18907
19091
  /**
@@ -18913,7 +19097,7 @@ class StateService {
18913
19097
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18914
19098
  return;
18915
19099
  }
18916
- yield this.saveSecureStorageKey(state_service_partialKeys.masterKey, value, options);
19100
+ yield this.saveSecureStorageKey(partialKeys.masterKey, value, options);
18917
19101
  });
18918
19102
  }
18919
19103
  /**
@@ -18925,7 +19109,7 @@ class StateService {
18925
19109
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18926
19110
  return null;
18927
19111
  }
18928
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.biometricKey}`, options);
19112
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.biometricKey}`, options);
18929
19113
  });
18930
19114
  }
18931
19115
  /**
@@ -18937,7 +19121,7 @@ class StateService {
18937
19121
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18938
19122
  return false;
18939
19123
  }
18940
- return yield this.secureStorageService.has(`${options.userId}${state_service_partialKeys.biometricKey}`, options);
19124
+ return yield this.secureStorageService.has(`${options.userId}${partialKeys.biometricKey}`, options);
18941
19125
  });
18942
19126
  }
18943
19127
  /**
@@ -18949,7 +19133,7 @@ class StateService {
18949
19133
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18950
19134
  return;
18951
19135
  }
18952
- yield this.saveSecureStorageKey(state_service_partialKeys.biometricKey, value, options);
19136
+ yield this.saveSecureStorageKey(partialKeys.biometricKey, value, options);
18953
19137
  });
18954
19138
  }
18955
19139
  getDecryptedCiphers(options) {
@@ -19875,7 +20059,7 @@ class StateService {
19875
20059
  getLastActive(options) {
19876
20060
  return state_service_awaiter(this, void 0, void 0, function* () {
19877
20061
  options = this.reconcileOptions(options, yield this.defaultOnDiskOptions());
19878
- const accountActivity = yield this.storageService.get(state_service_keys.accountActivity, options);
20062
+ const accountActivity = yield this.storageService.get(keys.accountActivity, options);
19879
20063
  if (accountActivity == null || Object.keys(accountActivity).length < 1) {
19880
20064
  return null;
19881
20065
  }
@@ -19889,9 +20073,9 @@ class StateService {
19889
20073
  if (options.userId == null) {
19890
20074
  return;
19891
20075
  }
19892
- const accountActivity = (_a = (yield this.storageService.get(state_service_keys.accountActivity, options))) !== null && _a !== void 0 ? _a : {};
20076
+ const accountActivity = (_a = (yield this.storageService.get(keys.accountActivity, options))) !== null && _a !== void 0 ? _a : {};
19893
20077
  accountActivity[options.userId] = value;
19894
- yield this.storageService.save(state_service_keys.accountActivity, accountActivity, options);
20078
+ yield this.storageService.save(keys.accountActivity, accountActivity, options);
19895
20079
  });
19896
20080
  }
19897
20081
  getLastSync(options) {
@@ -20316,19 +20500,6 @@ class StateService {
20316
20500
  yield this.saveAccount(account, this.reconcileOptions(options, yield this.defaultOnDiskLocalOptions()));
20317
20501
  });
20318
20502
  }
20319
- getStateVersion() {
20320
- var _a;
20321
- return state_service_awaiter(this, void 0, void 0, function* () {
20322
- return (_a = (yield this.getGlobals(yield this.defaultOnDiskLocalOptions())).stateVersion) !== null && _a !== void 0 ? _a : 1;
20323
- });
20324
- }
20325
- setStateVersion(value) {
20326
- return state_service_awaiter(this, void 0, void 0, function* () {
20327
- const globals = yield this.getGlobals(yield this.defaultOnDiskOptions());
20328
- globals.stateVersion = value;
20329
- yield this.saveGlobals(globals, yield this.defaultOnDiskOptions());
20330
- });
20331
- }
20332
20503
  getWindow() {
20333
20504
  return state_service_awaiter(this, void 0, void 0, function* () {
20334
20505
  const globals = yield this.getGlobals(yield this.defaultOnDiskOptions());
@@ -20405,7 +20576,10 @@ class StateService {
20405
20576
  if (this.useDisk && globals == null) {
20406
20577
  globals = yield this.getGlobalsFromDisk(options);
20407
20578
  }
20408
- return globals !== null && globals !== void 0 ? globals : this.createGlobals();
20579
+ if (globals == null) {
20580
+ globals = this.createGlobals();
20581
+ }
20582
+ return globals;
20409
20583
  });
20410
20584
  }
20411
20585
  saveGlobals(globals, options) {
@@ -20422,7 +20596,7 @@ class StateService {
20422
20596
  }
20423
20597
  getGlobalsFromDisk(options) {
20424
20598
  return state_service_awaiter(this, void 0, void 0, function* () {
20425
- return yield this.storageService.get(state_service_keys.global, options);
20599
+ return yield this.storageService.get(keys.global, options);
20426
20600
  });
20427
20601
  }
20428
20602
  saveGlobalsToMemory(globals) {
@@ -20436,10 +20610,10 @@ class StateService {
20436
20610
  saveGlobalsToDisk(globals, options) {
20437
20611
  return state_service_awaiter(this, void 0, void 0, function* () {
20438
20612
  if (options.useSecureStorage) {
20439
- yield this.secureStorageService.save(state_service_keys.global, globals, options);
20613
+ yield this.secureStorageService.save(keys.global, globals, options);
20440
20614
  }
20441
20615
  else {
20442
- yield this.storageService.save(state_service_keys.global, globals, options);
20616
+ yield this.storageService.save(keys.global, globals, options);
20443
20617
  }
20444
20618
  });
20445
20619
  }
@@ -20557,9 +20731,9 @@ class StateService {
20557
20731
  if ((storedAccount === null || storedAccount === void 0 ? void 0 : storedAccount.settings) != null) {
20558
20732
  account.settings = storedAccount.settings;
20559
20733
  }
20560
- else if (yield this.storageService.has(state_service_keys.tempAccountSettings)) {
20561
- account.settings = yield this.storageService.get(state_service_keys.tempAccountSettings);
20562
- yield this.storageService.remove(state_service_keys.tempAccountSettings);
20734
+ else if (yield this.storageService.has(keys.tempAccountSettings)) {
20735
+ account.settings = yield this.storageService.get(keys.tempAccountSettings);
20736
+ yield this.storageService.remove(keys.tempAccountSettings);
20563
20737
  }
20564
20738
  account.settings.environmentUrls = environmentUrls;
20565
20739
  account.settings.region = region;
@@ -20678,7 +20852,7 @@ class StateService {
20678
20852
  }
20679
20853
  getActiveUserIdFromStorage() {
20680
20854
  return state_service_awaiter(this, void 0, void 0, function* () {
20681
- return yield this.storageService.get(state_service_keys.activeUserId);
20855
+ return yield this.storageService.get(keys.activeUserId);
20682
20856
  });
20683
20857
  }
20684
20858
  removeAccountFromLocalStorage(userId = null) {
@@ -20784,7 +20958,7 @@ class StateService {
20784
20958
  yield this.setLastActive(null, { userId: userId });
20785
20959
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
20786
20960
  state.authenticatedAccounts = state.authenticatedAccounts.filter((id) => id !== userId);
20787
- yield this.storageService.save(state_service_keys.authenticatedAccounts, state.authenticatedAccounts);
20961
+ yield this.storageService.save(keys.authenticatedAccounts, state.authenticatedAccounts);
20788
20962
  return state;
20789
20963
  }));
20790
20964
  });
@@ -20835,7 +21009,7 @@ class StateService {
20835
21009
  }
20836
21010
  state() {
20837
21011
  return state_service_awaiter(this, void 0, void 0, function* () {
20838
- const state = yield this.memoryStorageService.get(state_service_keys.state, {
21012
+ const state = yield this.memoryStorageService.get(keys.state, {
20839
21013
  deserializer: (s) => State.fromJSON(s, this.accountDeserializer),
20840
21014
  });
20841
21015
  return state;
@@ -20843,7 +21017,7 @@ class StateService {
20843
21017
  }
20844
21018
  setState(state) {
20845
21019
  return state_service_awaiter(this, void 0, void 0, function* () {
20846
- yield this.memoryStorageService.save(state_service_keys.state, state);
21020
+ yield this.memoryStorageService.save(keys.state, state);
20847
21021
  });
20848
21022
  }
20849
21023
  updateState(stateUpdater) {
@@ -22821,7 +22995,7 @@ class SendService {
22821
22995
  send.hideEmail = model.hideEmail;
22822
22996
  send.maxAccessCount = model.maxAccessCount;
22823
22997
  if (model.key == null) {
22824
- model.key = yield this.cryptoFunctionService.randomBytes(16);
22998
+ model.key = yield this.cryptoFunctionService.aesGenerateKey(128);
22825
22999
  model.cryptoKey = yield this.cryptoService.makeSendKey(model.key);
22826
23000
  }
22827
23001
  if (password != null) {
@@ -23000,6 +23174,57 @@ class SendService {
23000
23174
  }
23001
23175
  }
23002
23176
 
23177
+ ;// CONCATENATED MODULE: external "semver"
23178
+ const external_semver_namespaceObject = require("semver");
23179
+ ;// CONCATENATED MODULE: ../../libs/common/src/platform/misc/flags.ts
23180
+ function getFlags(envFlags) {
23181
+ if (typeof envFlags === "string") {
23182
+ return JSON.parse(envFlags);
23183
+ }
23184
+ else {
23185
+ return envFlags;
23186
+ }
23187
+ }
23188
+ /**
23189
+ * Gets the value of a feature flag from environment.
23190
+ * All flags default to "on" (true).
23191
+ * Only use for shared code in `libs`, otherwise use the client-specific function.
23192
+ * @param flag The name of the feature flag to check
23193
+ * @returns The value of the flag
23194
+ */
23195
+ function flagEnabled(flag) {
23196
+ const flags = getFlags({"enableCipherKeyEncryption":false});
23197
+ return flags[flag] == null || !!flags[flag];
23198
+ }
23199
+ /**
23200
+ * Gets the value of a dev flag from environment.
23201
+ * Will always return false unless in development.
23202
+ * Only use for shared code in `libs`, otherwise use the client-specific function.
23203
+ * @param flag The name of the dev flag to check
23204
+ * @returns The value of the flag
23205
+ */
23206
+ function devFlagEnabled(flag) {
23207
+ if (process.env.ENV !== "development") {
23208
+ return false;
23209
+ }
23210
+ const devFlags = getFlags(process.env.DEV_FLAGS);
23211
+ return devFlags[flag] == null || !!devFlags[flag];
23212
+ }
23213
+ /**
23214
+ * Gets the value of a dev flag from environment.
23215
+ * Will always return false unless in development.
23216
+ * @param flag The name of the dev flag to check
23217
+ * @returns The value of the flag
23218
+ * @throws Error if the flag is not enabled
23219
+ */
23220
+ function devFlagValue(flag) {
23221
+ if (!devFlagEnabled(flag)) {
23222
+ throw new Error(`This method should not be called, it is protected by a disabled dev flag.`);
23223
+ }
23224
+ const devFlags = getFlags(process.env.DEV_FLAGS);
23225
+ return devFlags[flag];
23226
+ }
23227
+
23003
23228
  ;// CONCATENATED MODULE: ../../libs/common/src/vault/models/domain/attachment.ts
23004
23229
  var attachment_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
23005
23230
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -23547,6 +23772,8 @@ var cipher_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _a
23547
23772
 
23548
23773
 
23549
23774
 
23775
+
23776
+
23550
23777
  class Cipher extends Domain {
23551
23778
  constructor(obj, localData = null) {
23552
23779
  super();
@@ -23560,6 +23787,7 @@ class Cipher extends Domain {
23560
23787
  folderId: null,
23561
23788
  name: null,
23562
23789
  notes: null,
23790
+ key: null,
23563
23791
  }, ["id", "organizationId", "folderId"]);
23564
23792
  this.type = obj.type;
23565
23793
  this.favorite = obj.favorite;
@@ -23612,9 +23840,16 @@ class Cipher extends Domain {
23612
23840
  this.passwordHistory = null;
23613
23841
  }
23614
23842
  }
23843
+ // We are passing the organizationId into the EncString.decrypt() method here, but because the encKey will always be
23844
+ // present and so the organizationId will not be used.
23845
+ // We will refactor the EncString.decrypt() in https://bitwarden.atlassian.net/browse/PM-3762 to remove the dependency on the organizationId.
23615
23846
  decrypt(encKey) {
23616
23847
  return cipher_awaiter(this, void 0, void 0, function* () {
23617
23848
  const model = new CipherView(this);
23849
+ if (this.key != null) {
23850
+ const encryptService = utils_Utils.getContainerService().getEncryptService();
23851
+ encKey = new SymmetricCryptoKey(yield encryptService.decryptToBytes(this.key, encKey));
23852
+ }
23618
23853
  yield this.decryptObj(model, {
23619
23854
  name: null,
23620
23855
  notes: null,
@@ -23635,13 +23870,12 @@ class Cipher extends Domain {
23635
23870
  default:
23636
23871
  break;
23637
23872
  }
23638
- const orgId = this.organizationId;
23639
23873
  if (this.attachments != null && this.attachments.length > 0) {
23640
23874
  const attachments = [];
23641
23875
  yield this.attachments.reduce((promise, attachment) => {
23642
23876
  return promise
23643
23877
  .then(() => {
23644
- return attachment.decrypt(orgId, encKey);
23878
+ return attachment.decrypt(this.organizationId, encKey);
23645
23879
  })
23646
23880
  .then((decAttachment) => {
23647
23881
  attachments.push(decAttachment);
@@ -23654,7 +23888,7 @@ class Cipher extends Domain {
23654
23888
  yield this.fields.reduce((promise, field) => {
23655
23889
  return promise
23656
23890
  .then(() => {
23657
- return field.decrypt(orgId, encKey);
23891
+ return field.decrypt(this.organizationId, encKey);
23658
23892
  })
23659
23893
  .then((decField) => {
23660
23894
  fields.push(decField);
@@ -23667,7 +23901,7 @@ class Cipher extends Domain {
23667
23901
  yield this.passwordHistory.reduce((promise, ph) => {
23668
23902
  return promise
23669
23903
  .then(() => {
23670
- return ph.decrypt(orgId, encKey);
23904
+ return ph.decrypt(this.organizationId, encKey);
23671
23905
  })
23672
23906
  .then((decPh) => {
23673
23907
  passwordHistory.push(decPh);
@@ -23679,6 +23913,7 @@ class Cipher extends Domain {
23679
23913
  });
23680
23914
  }
23681
23915
  toCipherData() {
23916
+ var _a;
23682
23917
  const c = new CipherData();
23683
23918
  c.id = this.id;
23684
23919
  c.organizationId = this.organizationId;
@@ -23693,6 +23928,7 @@ class Cipher extends Domain {
23693
23928
  c.creationDate = this.creationDate != null ? this.creationDate.toISOString() : null;
23694
23929
  c.deletedDate = this.deletedDate != null ? this.deletedDate.toISOString() : null;
23695
23930
  c.reprompt = this.reprompt;
23931
+ c.key = (_a = this.key) === null || _a === void 0 ? void 0 : _a.encryptedString;
23696
23932
  this.buildDataModel(this, c, {
23697
23933
  name: null,
23698
23934
  notes: null,
@@ -23737,6 +23973,7 @@ class Cipher extends Domain {
23737
23973
  const attachments = (_a = obj.attachments) === null || _a === void 0 ? void 0 : _a.map((a) => Attachment.fromJSON(a));
23738
23974
  const fields = (_b = obj.fields) === null || _b === void 0 ? void 0 : _b.map((f) => Field.fromJSON(f));
23739
23975
  const passwordHistory = (_c = obj.passwordHistory) === null || _c === void 0 ? void 0 : _c.map((ph) => Password.fromJSON(ph));
23976
+ const key = EncString.fromJSON(obj.key);
23740
23977
  Object.assign(domain, obj, {
23741
23978
  name,
23742
23979
  notes,
@@ -23745,6 +23982,7 @@ class Cipher extends Domain {
23745
23982
  attachments,
23746
23983
  fields,
23747
23984
  passwordHistory,
23985
+ key,
23748
23986
  });
23749
23987
  switch (obj.type) {
23750
23988
  case CipherType.Card:
@@ -23983,6 +24221,7 @@ class AttachmentRequest {
23983
24221
 
23984
24222
  class CipherRequest {
23985
24223
  constructor(cipher) {
24224
+ var _a;
23986
24225
  this.type = cipher.type;
23987
24226
  this.folderId = cipher.folderId;
23988
24227
  this.organizationId = cipher.organizationId;
@@ -23991,6 +24230,7 @@ class CipherRequest {
23991
24230
  this.favorite = cipher.favorite;
23992
24231
  this.lastKnownRevisionDate = cipher.revisionDate;
23993
24232
  this.reprompt = cipher.reprompt;
24233
+ this.key = (_a = cipher.key) === null || _a === void 0 ? void 0 : _a.encryptedString;
23994
24234
  switch (this.type) {
23995
24235
  case CipherType.Login:
23996
24236
  this.login = new LoginApi();
@@ -24211,8 +24451,13 @@ var cipher_service_awaiter = (undefined && undefined.__awaiter) || function (thi
24211
24451
 
24212
24452
 
24213
24453
 
24454
+
24455
+
24456
+
24457
+
24458
+ const CIPHER_KEY_ENC_MIN_SERVER_VER = new external_semver_namespaceObject.SemVer("2023.9.1");
24214
24459
  class CipherService {
24215
- constructor(cryptoService, settingsService, apiService, i18nService, searchService, stateService, encryptService, cipherFileUploadService) {
24460
+ constructor(cryptoService, settingsService, apiService, i18nService, searchService, stateService, encryptService, cipherFileUploadService, configService) {
24216
24461
  this.cryptoService = cryptoService;
24217
24462
  this.settingsService = settingsService;
24218
24463
  this.apiService = apiService;
@@ -24221,6 +24466,7 @@ class CipherService {
24221
24466
  this.stateService = stateService;
24222
24467
  this.encryptService = encryptService;
24223
24468
  this.cipherFileUploadService = cipherFileUploadService;
24469
+ this.configService = configService;
24224
24470
  this.sortedCiphersCache = new SortedCiphersCache(this.sortCiphersByLastUsed);
24225
24471
  }
24226
24472
  getDecryptedCipherCache() {
@@ -24247,56 +24493,17 @@ class CipherService {
24247
24493
  yield this.clearDecryptedCiphersState(userId);
24248
24494
  });
24249
24495
  }
24250
- encrypt(model, key, originalCipher = null) {
24496
+ encrypt(model, keyForEncryption, keyForCipherKeyDecryption, originalCipher = null) {
24497
+ var _a;
24251
24498
  return cipher_service_awaiter(this, void 0, void 0, function* () {
24252
- // Adjust password history
24253
24499
  if (model.id != null) {
24254
24500
  if (originalCipher == null) {
24255
24501
  originalCipher = yield this.get(model.id);
24256
24502
  }
24257
24503
  if (originalCipher != null) {
24258
- const existingCipher = yield originalCipher.decrypt();
24259
- model.passwordHistory = existingCipher.passwordHistory || [];
24260
- if (model.type === CipherType.Login && existingCipher.type === CipherType.Login) {
24261
- if (existingCipher.login.password != null &&
24262
- existingCipher.login.password !== "" &&
24263
- existingCipher.login.password !== model.login.password) {
24264
- const ph = new PasswordHistoryView();
24265
- ph.password = existingCipher.login.password;
24266
- ph.lastUsedDate = model.login.passwordRevisionDate = new Date();
24267
- model.passwordHistory.splice(0, 0, ph);
24268
- }
24269
- else {
24270
- model.login.passwordRevisionDate = existingCipher.login.passwordRevisionDate;
24271
- }
24272
- }
24273
- if (existingCipher.hasFields) {
24274
- const existingHiddenFields = existingCipher.fields.filter((f) => f.type === FieldType.Hidden &&
24275
- f.name != null &&
24276
- f.name !== "" &&
24277
- f.value != null &&
24278
- f.value !== "");
24279
- const hiddenFields = model.fields == null
24280
- ? []
24281
- : model.fields.filter((f) => f.type === FieldType.Hidden && f.name != null && f.name !== "");
24282
- existingHiddenFields.forEach((ef) => {
24283
- const matchedField = hiddenFields.find((f) => f.name === ef.name);
24284
- if (matchedField == null || matchedField.value !== ef.value) {
24285
- const ph = new PasswordHistoryView();
24286
- ph.password = ef.name + ": " + ef.value;
24287
- ph.lastUsedDate = new Date();
24288
- model.passwordHistory.splice(0, 0, ph);
24289
- }
24290
- });
24291
- }
24292
- }
24293
- if (model.passwordHistory != null && model.passwordHistory.length === 0) {
24294
- model.passwordHistory = null;
24295
- }
24296
- else if (model.passwordHistory != null && model.passwordHistory.length > 5) {
24297
- // only save last 5 history
24298
- model.passwordHistory = model.passwordHistory.slice(0, 5);
24504
+ yield this.updateModelfromExistingCipher(model, originalCipher);
24299
24505
  }
24506
+ this.adjustPasswordHistoryLength(model);
24300
24507
  }
24301
24508
  const cipher = new Cipher();
24302
24509
  cipher.id = model.id;
@@ -24308,29 +24515,28 @@ class CipherService {
24308
24515
  cipher.revisionDate = model.revisionDate;
24309
24516
  cipher.reprompt = model.reprompt;
24310
24517
  cipher.edit = model.edit;
24311
- if (key == null && cipher.organizationId != null) {
24312
- key = yield this.cryptoService.getOrgKey(cipher.organizationId);
24313
- if (key == null) {
24314
- throw new Error("Cannot encrypt cipher for organization. No key.");
24518
+ if (yield this.getCipherKeyEncryptionEnabled()) {
24519
+ cipher.key = (_a = originalCipher === null || originalCipher === void 0 ? void 0 : originalCipher.key) !== null && _a !== void 0 ? _a : null;
24520
+ const userOrOrgKey = yield this.getKeyForCipherKeyDecryption(cipher);
24521
+ // The keyForEncryption is only used for encrypting the cipher key, not the cipher itself, since cipher key encryption is enabled.
24522
+ // If the caller has provided a key for cipher key encryption, use it. Otherwise, use the user or org key.
24523
+ keyForEncryption || (keyForEncryption = userOrOrgKey);
24524
+ // If the caller has provided a key for cipher key decryption, use it. Otherwise, use the user or org key.
24525
+ keyForCipherKeyDecryption || (keyForCipherKeyDecryption = userOrOrgKey);
24526
+ return this.encryptCipherWithCipherKey(model, cipher, keyForEncryption, keyForCipherKeyDecryption);
24527
+ }
24528
+ else {
24529
+ if (keyForEncryption == null && cipher.organizationId != null) {
24530
+ keyForEncryption = yield this.cryptoService.getOrgKey(cipher.organizationId);
24531
+ if (keyForEncryption == null) {
24532
+ throw new Error("Cannot encrypt cipher for organization. No key.");
24533
+ }
24315
24534
  }
24535
+ // We want to ensure that the cipher key is null if cipher key encryption is disabled
24536
+ // so that decryption uses the proper key.
24537
+ cipher.key = null;
24538
+ return this.encryptCipher(model, cipher, keyForEncryption);
24316
24539
  }
24317
- yield Promise.all([
24318
- this.encryptObjProperty(model, cipher, {
24319
- name: null,
24320
- notes: null,
24321
- }, key),
24322
- this.encryptCipherData(cipher, model, key),
24323
- this.encryptFields(model.fields, key).then((fields) => {
24324
- cipher.fields = fields;
24325
- }),
24326
- this.encryptPasswordHistories(model.passwordHistory, key).then((ph) => {
24327
- cipher.passwordHistory = ph;
24328
- }),
24329
- this.encryptAttachments(model.attachments, key).then((attachments) => {
24330
- cipher.attachments = attachments;
24331
- }),
24332
- ]);
24333
- return cipher;
24334
24540
  });
24335
24541
  }
24336
24542
  encryptAttachments(attachmentsModel, key) {
@@ -24625,7 +24831,7 @@ class CipherService {
24625
24831
  createWithServer(cipher, orgAdmin) {
24626
24832
  return cipher_service_awaiter(this, void 0, void 0, function* () {
24627
24833
  let response;
24628
- if (orgAdmin) {
24834
+ if (orgAdmin && cipher.organizationId != null) {
24629
24835
  const request = new CipherCreateRequest(cipher);
24630
24836
  response = yield this.apiService.postCipherAdmin(request);
24631
24837
  }
@@ -24674,7 +24880,7 @@ class CipherService {
24674
24880
  yield Promise.all(attachmentPromises);
24675
24881
  cipher.organizationId = organizationId;
24676
24882
  cipher.collectionIds = collectionIds;
24677
- const encCipher = yield this.encrypt(cipher);
24883
+ const encCipher = yield this.encryptSharedCipher(cipher);
24678
24884
  const request = new CipherShareRequest(encCipher);
24679
24885
  const response = yield this.apiService.putShareCipher(cipher.id, request);
24680
24886
  const data = new CipherData(response, collectionIds);
@@ -24688,7 +24894,7 @@ class CipherService {
24688
24894
  for (const cipher of ciphers) {
24689
24895
  cipher.organizationId = organizationId;
24690
24896
  cipher.collectionIds = collectionIds;
24691
- promises.push(this.encrypt(cipher).then((c) => {
24897
+ promises.push(this.encryptSharedCipher(cipher).then((c) => {
24692
24898
  encCiphers.push(c);
24693
24899
  }));
24694
24900
  }
@@ -24727,12 +24933,22 @@ class CipherService {
24727
24933
  }
24728
24934
  saveAttachmentRawWithServer(cipher, filename, data, admin = false) {
24729
24935
  return cipher_service_awaiter(this, void 0, void 0, function* () {
24730
- let encKey;
24731
- encKey = yield this.cryptoService.getOrgKey(cipher.organizationId);
24732
- encKey || (encKey = yield this.cryptoService.getUserKeyWithLegacySupport());
24733
- const dataEncKey = yield this.cryptoService.makeDataEncKey(encKey);
24734
- const encFileName = yield this.encryptService.encrypt(filename, encKey);
24735
- const encData = yield this.encryptService.encryptToBytes(data, dataEncKey[0]);
24936
+ const encKey = yield this.getKeyForCipherKeyDecryption(cipher);
24937
+ const cipherKeyEncryptionEnabled = yield this.getCipherKeyEncryptionEnabled();
24938
+ const cipherEncKey = cipherKeyEncryptionEnabled && cipher.key != null
24939
+ ? new SymmetricCryptoKey(yield this.encryptService.decryptToBytes(cipher.key, encKey))
24940
+ : encKey;
24941
+ //if cipher key encryption is disabled but the item has an individual key,
24942
+ //then we rollback to using the user key as the main key of encryption of the item
24943
+ //in order to keep item and it's attachments with the same encryption level
24944
+ if (cipher.key != null && !cipherKeyEncryptionEnabled) {
24945
+ const model = yield cipher.decrypt(yield this.getKeyForCipherKeyDecryption(cipher));
24946
+ cipher = yield this.encrypt(model);
24947
+ yield this.updateWithServer(cipher);
24948
+ }
24949
+ const encFileName = yield this.encryptService.encrypt(filename, cipherEncKey);
24950
+ const dataEncKey = yield this.cryptoService.makeDataEncKey(cipherEncKey);
24951
+ const encData = yield this.encryptService.encryptToBytes(new Uint8Array(data), dataEncKey[0]);
24736
24952
  const response = yield this.cipherFileUploadService.upload(cipher, encFileName, encData, admin, dataEncKey);
24737
24953
  const cData = new CipherData(response, cipher.collectionIds);
24738
24954
  if (!admin) {
@@ -25020,7 +25236,68 @@ class CipherService {
25020
25236
  yield this.restore(restores);
25021
25237
  });
25022
25238
  }
25239
+ getKeyForCipherKeyDecryption(cipher) {
25240
+ return cipher_service_awaiter(this, void 0, void 0, function* () {
25241
+ return ((yield this.cryptoService.getOrgKey(cipher.organizationId)) ||
25242
+ (yield this.cryptoService.getUserKeyWithLegacySupport()));
25243
+ });
25244
+ }
25023
25245
  // Helpers
25246
+ // In the case of a cipher that is being shared with an organization, we want to decrypt the
25247
+ // cipher key with the user's key and then re-encrypt it with the organization's key.
25248
+ encryptSharedCipher(model) {
25249
+ return cipher_service_awaiter(this, void 0, void 0, function* () {
25250
+ const keyForCipherKeyDecryption = yield this.cryptoService.getUserKeyWithLegacySupport();
25251
+ return yield this.encrypt(model, null, keyForCipherKeyDecryption);
25252
+ });
25253
+ }
25254
+ updateModelfromExistingCipher(model, originalCipher) {
25255
+ return cipher_service_awaiter(this, void 0, void 0, function* () {
25256
+ const existingCipher = yield originalCipher.decrypt(yield this.getKeyForCipherKeyDecryption(originalCipher));
25257
+ model.passwordHistory = existingCipher.passwordHistory || [];
25258
+ if (model.type === CipherType.Login && existingCipher.type === CipherType.Login) {
25259
+ if (existingCipher.login.password != null &&
25260
+ existingCipher.login.password !== "" &&
25261
+ existingCipher.login.password !== model.login.password) {
25262
+ const ph = new PasswordHistoryView();
25263
+ ph.password = existingCipher.login.password;
25264
+ ph.lastUsedDate = model.login.passwordRevisionDate = new Date();
25265
+ model.passwordHistory.splice(0, 0, ph);
25266
+ }
25267
+ else {
25268
+ model.login.passwordRevisionDate = existingCipher.login.passwordRevisionDate;
25269
+ }
25270
+ }
25271
+ if (existingCipher.hasFields) {
25272
+ const existingHiddenFields = existingCipher.fields.filter((f) => f.type === FieldType.Hidden &&
25273
+ f.name != null &&
25274
+ f.name !== "" &&
25275
+ f.value != null &&
25276
+ f.value !== "");
25277
+ const hiddenFields = model.fields == null
25278
+ ? []
25279
+ : model.fields.filter((f) => f.type === FieldType.Hidden && f.name != null && f.name !== "");
25280
+ existingHiddenFields.forEach((ef) => {
25281
+ const matchedField = hiddenFields.find((f) => f.name === ef.name);
25282
+ if (matchedField == null || matchedField.value !== ef.value) {
25283
+ const ph = new PasswordHistoryView();
25284
+ ph.password = ef.name + ": " + ef.value;
25285
+ ph.lastUsedDate = new Date();
25286
+ model.passwordHistory.splice(0, 0, ph);
25287
+ }
25288
+ });
25289
+ }
25290
+ });
25291
+ }
25292
+ adjustPasswordHistoryLength(model) {
25293
+ if (model.passwordHistory != null && model.passwordHistory.length === 0) {
25294
+ model.passwordHistory = null;
25295
+ }
25296
+ else if (model.passwordHistory != null && model.passwordHistory.length > 5) {
25297
+ // only save last 5 history
25298
+ model.passwordHistory = model.passwordHistory.slice(0, 5);
25299
+ }
25300
+ }
25024
25301
  shareAttachmentWithServer(attachmentView, cipherId, organizationId) {
25025
25302
  return cipher_service_awaiter(this, void 0, void 0, function* () {
25026
25303
  const attachmentResponse = yield this.apiService.nativeFetch(new Request(attachmentView.url, { cache: "no-store" }));
@@ -25198,6 +25475,49 @@ class CipherService {
25198
25475
  clearSortedCiphers() {
25199
25476
  this.sortedCiphersCache.clear();
25200
25477
  }
25478
+ encryptCipher(model, cipher, key) {
25479
+ return cipher_service_awaiter(this, void 0, void 0, function* () {
25480
+ yield Promise.all([
25481
+ this.encryptObjProperty(model, cipher, {
25482
+ name: null,
25483
+ notes: null,
25484
+ }, key),
25485
+ this.encryptCipherData(cipher, model, key),
25486
+ this.encryptFields(model.fields, key).then((fields) => {
25487
+ cipher.fields = fields;
25488
+ }),
25489
+ this.encryptPasswordHistories(model.passwordHistory, key).then((ph) => {
25490
+ cipher.passwordHistory = ph;
25491
+ }),
25492
+ this.encryptAttachments(model.attachments, key).then((attachments) => {
25493
+ cipher.attachments = attachments;
25494
+ }),
25495
+ ]);
25496
+ return cipher;
25497
+ });
25498
+ }
25499
+ encryptCipherWithCipherKey(model, cipher, keyForCipherKeyEncryption, keyForCipherKeyDecryption) {
25500
+ return cipher_service_awaiter(this, void 0, void 0, function* () {
25501
+ // First, we get the key for cipher key encryption, in its decrypted form
25502
+ let decryptedCipherKey;
25503
+ if (cipher.key == null) {
25504
+ decryptedCipherKey = yield this.cryptoService.makeCipherKey();
25505
+ }
25506
+ else {
25507
+ decryptedCipherKey = new SymmetricCryptoKey(yield this.encryptService.decryptToBytes(cipher.key, keyForCipherKeyDecryption));
25508
+ }
25509
+ // Then, we have to encrypt the cipher key with the proper key.
25510
+ cipher.key = yield this.encryptService.encrypt(decryptedCipherKey.key, keyForCipherKeyEncryption);
25511
+ // Finally, we can encrypt the cipher with the decrypted cipher key.
25512
+ return this.encryptCipher(model, cipher, decryptedCipherKey);
25513
+ });
25514
+ }
25515
+ getCipherKeyEncryptionEnabled() {
25516
+ return cipher_service_awaiter(this, void 0, void 0, function* () {
25517
+ return (flagEnabled("enableCipherKeyEncryption") &&
25518
+ (yield (0,external_rxjs_namespaceObject.firstValueFrom)(this.configService.checkServerMeetsVersionRequirement$(CIPHER_KEY_ENC_MIN_SERVER_VER))));
25519
+ });
25520
+ }
25201
25521
  }
25202
25522
  cipher_service_decorate([
25203
25523
  sequentialize(() => "getAllDecrypted"),
@@ -26707,6 +27027,43 @@ class LoginExport {
26707
27027
  }
26708
27028
  }
26709
27029
 
27030
+ ;// CONCATENATED MODULE: ../../libs/common/src/models/export/password-history.export.ts
27031
+
27032
+
27033
+
27034
+ class PasswordHistoryExport {
27035
+ static template() {
27036
+ const req = new PasswordHistoryExport();
27037
+ req.password = null;
27038
+ req.lastUsedDate = null;
27039
+ return req;
27040
+ }
27041
+ static toView(req, view = new PasswordHistoryView()) {
27042
+ view.password = req.password;
27043
+ view.lastUsedDate = req.lastUsedDate;
27044
+ return view;
27045
+ }
27046
+ static toDomain(req, domain = new Password()) {
27047
+ domain.password = req.password != null ? new EncString(req.password) : null;
27048
+ domain.lastUsedDate = req.lastUsedDate;
27049
+ return domain;
27050
+ }
27051
+ constructor(o) {
27052
+ var _a;
27053
+ this.lastUsedDate = null;
27054
+ if (o == null) {
27055
+ return;
27056
+ }
27057
+ if (o instanceof PasswordHistoryView) {
27058
+ this.password = o.password;
27059
+ }
27060
+ else {
27061
+ this.password = (_a = o.password) === null || _a === void 0 ? void 0 : _a.encryptedString;
27062
+ }
27063
+ this.lastUsedDate = o.lastUsedDate;
27064
+ }
27065
+ }
27066
+
26710
27067
  ;// CONCATENATED MODULE: ../../libs/common/src/models/export/secure-note.export.ts
26711
27068
 
26712
27069
 
@@ -26744,7 +27101,14 @@ class SecureNoteExport {
26744
27101
 
26745
27102
 
26746
27103
 
27104
+
26747
27105
  class CipherExport {
27106
+ constructor() {
27107
+ this.passwordHistory = null;
27108
+ this.revisionDate = null;
27109
+ this.creationDate = null;
27110
+ this.deletedDate = null;
27111
+ }
26748
27112
  static template() {
26749
27113
  const req = new CipherExport();
26750
27114
  req.organizationId = null;
@@ -26760,6 +27124,10 @@ class CipherExport {
26760
27124
  req.card = null;
26761
27125
  req.identity = null;
26762
27126
  req.reprompt = CipherRepromptType.None;
27127
+ req.passwordHistory = [];
27128
+ req.creationDate = null;
27129
+ req.revisionDate = null;
27130
+ req.deletedDate = null;
26763
27131
  return req;
26764
27132
  }
26765
27133
  static toView(req, view = new CipherView()) {
@@ -26794,6 +27162,12 @@ class CipherExport {
26794
27162
  view.identity = IdentityExport.toView(req.identity);
26795
27163
  break;
26796
27164
  }
27165
+ if (req.passwordHistory != null) {
27166
+ view.passwordHistory = req.passwordHistory.map((ph) => PasswordHistoryExport.toView(ph));
27167
+ }
27168
+ view.creationDate = req.creationDate;
27169
+ view.revisionDate = req.revisionDate;
27170
+ view.deletedDate = req.deletedDate;
26797
27171
  return view;
26798
27172
  }
26799
27173
  static toDomain(req, domain = new Cipher()) {
@@ -26807,6 +27181,7 @@ class CipherExport {
26807
27181
  domain.notes = req.notes != null ? new EncString(req.notes) : null;
26808
27182
  domain.favorite = req.favorite;
26809
27183
  domain.reprompt = (_a = req.reprompt) !== null && _a !== void 0 ? _a : CipherRepromptType.None;
27184
+ domain.key = req.key != null ? new EncString(req.key) : null;
26810
27185
  if (req.fields != null) {
26811
27186
  domain.fields = req.fields.map((f) => FieldExport.toDomain(f));
26812
27187
  }
@@ -26824,11 +27199,17 @@ class CipherExport {
26824
27199
  domain.identity = IdentityExport.toDomain(req.identity);
26825
27200
  break;
26826
27201
  }
27202
+ if (req.passwordHistory != null) {
27203
+ domain.passwordHistory = req.passwordHistory.map((ph) => PasswordHistoryExport.toDomain(ph));
27204
+ }
27205
+ domain.creationDate = req.creationDate;
27206
+ domain.revisionDate = req.revisionDate;
27207
+ domain.deletedDate = req.deletedDate;
26827
27208
  return domain;
26828
27209
  }
26829
27210
  // Use build method instead of ctor so that we can control order of JSON stringify for pretty print
26830
27211
  build(o) {
26831
- var _a, _b;
27212
+ var _a, _b, _c;
26832
27213
  this.organizationId = o.organizationId;
26833
27214
  this.folderId = o.folderId;
26834
27215
  this.type = o.type;
@@ -26840,6 +27221,7 @@ class CipherExport {
26840
27221
  else {
26841
27222
  this.name = (_a = o.name) === null || _a === void 0 ? void 0 : _a.encryptedString;
26842
27223
  this.notes = (_b = o.notes) === null || _b === void 0 ? void 0 : _b.encryptedString;
27224
+ this.key = (_c = o.key) === null || _c === void 0 ? void 0 : _c.encryptedString;
26843
27225
  }
26844
27226
  this.favorite = o.favorite;
26845
27227
  if (o.fields != null) {
@@ -26864,6 +27246,17 @@ class CipherExport {
26864
27246
  this.identity = new IdentityExport(o.identity);
26865
27247
  break;
26866
27248
  }
27249
+ if (o.passwordHistory != null) {
27250
+ if (o instanceof CipherView) {
27251
+ this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
27252
+ }
27253
+ else {
27254
+ this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
27255
+ }
27256
+ }
27257
+ this.creationDate = o.creationDate;
27258
+ this.revisionDate = o.revisionDate;
27259
+ this.deletedDate = o.deletedDate;
26867
27260
  }
26868
27261
  }
26869
27262
 
@@ -27227,12 +27620,15 @@ class VaultExportService {
27227
27620
  if (exportData.ciphers != null && exportData.ciphers.length > 0) {
27228
27621
  exportData.ciphers
27229
27622
  .filter((c) => c.deletedDate === null)
27230
- .forEach((c) => {
27623
+ .forEach((c) => vault_export_service_awaiter(this, void 0, void 0, function* () {
27231
27624
  const cipher = new Cipher(new CipherData(c));
27232
- exportPromises.push(cipher.decrypt().then((decCipher) => {
27625
+ exportPromises.push(this.cipherService
27626
+ .getKeyForCipherKeyDecryption(cipher)
27627
+ .then((key) => cipher.decrypt(key))
27628
+ .then((decCipher) => {
27233
27629
  decCiphers.push(decCipher);
27234
27630
  }));
27235
- });
27631
+ }));
27236
27632
  }
27237
27633
  }
27238
27634
  return Promise.all(exportPromises);
@@ -27287,17 +27683,14 @@ class VaultExportService {
27287
27683
  const ciphers = [];
27288
27684
  const promises = [];
27289
27685
  promises.push(this.apiService.getCollections(organizationId).then((c) => {
27290
- const collectionPromises = [];
27291
27686
  if (c != null && c.data != null && c.data.length > 0) {
27292
27687
  c.data.forEach((r) => {
27293
27688
  const collection = new Collection(new CollectionData(r));
27294
27689
  collections.push(collection);
27295
27690
  });
27296
27691
  }
27297
- return Promise.all(collectionPromises);
27298
27692
  }));
27299
27693
  promises.push(this.apiService.getCiphersOrganization(organizationId).then((c) => {
27300
- const cipherPromises = [];
27301
27694
  if (c != null && c.data != null && c.data.length > 0) {
27302
27695
  c.data
27303
27696
  .filter((item) => item.deletedDate === null)
@@ -27306,7 +27699,6 @@ class VaultExportService {
27306
27699
  ciphers.push(cipher);
27307
27700
  });
27308
27701
  }
27309
- return Promise.all(cipherPromises);
27310
27702
  }));
27311
27703
  yield Promise.all(promises);
27312
27704
  const orgKey = yield this.cryptoService.getOrgKey(organizationId);
@@ -27802,6 +28194,9 @@ class base_importer_BaseImporter {
27802
28194
  if (cipher.fields != null && cipher.fields.length === 0) {
27803
28195
  cipher.fields = null;
27804
28196
  }
28197
+ if (cipher.passwordHistory != null && cipher.passwordHistory.length === 0) {
28198
+ cipher.passwordHistory = null;
28199
+ }
27805
28200
  }
27806
28201
  processKvp(cipher, key, value, type = FieldType.Text) {
27807
28202
  if (this.isNullOrWhitespace(value)) {
@@ -28239,33 +28634,34 @@ var bitwarden_json_importer_awaiter = (undefined && undefined.__awaiter) || func
28239
28634
 
28240
28635
 
28241
28636
  class BitwardenJsonImporter extends base_importer_BaseImporter {
28242
- constructor(cryptoService, i18nService) {
28637
+ constructor(cryptoService, i18nService, cipherService) {
28243
28638
  super();
28244
28639
  this.cryptoService = cryptoService;
28245
28640
  this.i18nService = i18nService;
28641
+ this.cipherService = cipherService;
28246
28642
  }
28247
28643
  parse(data) {
28248
28644
  return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28249
28645
  this.result = new import_result_ImportResult();
28250
- this.results = JSON.parse(data);
28251
- if (this.results == null || this.results.items == null) {
28646
+ const results = JSON.parse(data);
28647
+ if (results == null || results.items == null) {
28252
28648
  this.result.success = false;
28253
28649
  return this.result;
28254
28650
  }
28255
- if (this.results.encrypted) {
28256
- yield this.parseEncrypted();
28651
+ if (results.encrypted) {
28652
+ yield this.parseEncrypted(results);
28257
28653
  }
28258
28654
  else {
28259
- this.parseDecrypted();
28655
+ yield this.parseDecrypted(results);
28260
28656
  }
28261
28657
  return this.result;
28262
28658
  });
28263
28659
  }
28264
- parseEncrypted() {
28660
+ parseEncrypted(results) {
28265
28661
  return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28266
- if (this.results.encKeyValidation_DO_NOT_EDIT != null) {
28662
+ if (results.encKeyValidation_DO_NOT_EDIT != null) {
28267
28663
  const orgKey = yield this.cryptoService.getOrgKey(this.organizationId);
28268
- const encKeyValidation = new EncString(this.results.encKeyValidation_DO_NOT_EDIT);
28664
+ const encKeyValidation = new EncString(results.encKeyValidation_DO_NOT_EDIT);
28269
28665
  const encKeyValidationDecrypt = yield this.cryptoService.decryptToUtf8(encKeyValidation, orgKey);
28270
28666
  if (encKeyValidationDecrypt === null) {
28271
28667
  this.result.success = false;
@@ -28273,29 +28669,10 @@ class BitwardenJsonImporter extends base_importer_BaseImporter {
28273
28669
  return;
28274
28670
  }
28275
28671
  }
28276
- const groupingsMap = new Map();
28277
- if (this.organization && this.results.collections != null) {
28278
- for (const c of this.results.collections) {
28279
- const collection = CollectionWithIdExport.toDomain(c);
28280
- if (collection != null) {
28281
- collection.organizationId = this.organizationId;
28282
- const view = yield collection.decrypt();
28283
- groupingsMap.set(c.id, this.result.collections.length);
28284
- this.result.collections.push(view);
28285
- }
28286
- }
28287
- }
28288
- else if (!this.organization && this.results.folders != null) {
28289
- for (const f of this.results.folders) {
28290
- const folder = FolderWithIdExport.toDomain(f);
28291
- if (folder != null) {
28292
- const view = yield folder.decrypt();
28293
- groupingsMap.set(f.id, this.result.folders.length);
28294
- this.result.folders.push(view);
28295
- }
28296
- }
28297
- }
28298
- for (const c of this.results.items) {
28672
+ const groupingsMap = this.organization
28673
+ ? yield this.parseCollections(results)
28674
+ : yield this.parseFolders(results);
28675
+ for (const c of results.items) {
28299
28676
  const cipher = CipherWithIdExport.toDomain(c);
28300
28677
  // reset ids incase they were set for some reason
28301
28678
  cipher.id = null;
@@ -28321,64 +28698,99 @@ class BitwardenJsonImporter extends base_importer_BaseImporter {
28321
28698
  }
28322
28699
  });
28323
28700
  }
28324
- const view = yield cipher.decrypt();
28701
+ const view = yield cipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(cipher));
28325
28702
  this.cleanupCipher(view);
28326
28703
  this.result.ciphers.push(view);
28327
28704
  }
28328
28705
  this.result.success = true;
28329
28706
  });
28330
28707
  }
28331
- parseDecrypted() {
28332
- const groupingsMap = new Map();
28333
- if (this.organization && this.results.collections != null) {
28334
- this.results.collections.forEach((c) => {
28335
- const collection = CollectionWithIdExport.toView(c);
28336
- if (collection != null) {
28337
- collection.organizationId = null;
28338
- groupingsMap.set(c.id, this.result.collections.length);
28339
- this.result.collections.push(collection);
28708
+ parseDecrypted(results) {
28709
+ return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28710
+ const groupingsMap = this.organization
28711
+ ? yield this.parseCollections(results)
28712
+ : yield this.parseFolders(results);
28713
+ results.items.forEach((c) => {
28714
+ const cipher = CipherWithIdExport.toView(c);
28715
+ // reset ids incase they were set for some reason
28716
+ cipher.id = null;
28717
+ cipher.organizationId = null;
28718
+ cipher.collectionIds = null;
28719
+ // make sure password history is limited
28720
+ if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) {
28721
+ cipher.passwordHistory = cipher.passwordHistory.slice(0, 5);
28340
28722
  }
28341
- });
28342
- }
28343
- else if (!this.organization && this.results.folders != null) {
28344
- this.results.folders.forEach((f) => {
28345
- const folder = FolderWithIdExport.toView(f);
28346
- if (folder != null) {
28347
- groupingsMap.set(f.id, this.result.folders.length);
28348
- this.result.folders.push(folder);
28723
+ if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) {
28724
+ this.result.folderRelationships.push([
28725
+ this.result.ciphers.length,
28726
+ groupingsMap.get(c.folderId),
28727
+ ]);
28349
28728
  }
28729
+ else if (this.organization && c.collectionIds != null) {
28730
+ c.collectionIds.forEach((cId) => {
28731
+ if (groupingsMap.has(cId)) {
28732
+ this.result.collectionRelationships.push([
28733
+ this.result.ciphers.length,
28734
+ groupingsMap.get(cId),
28735
+ ]);
28736
+ }
28737
+ });
28738
+ }
28739
+ this.cleanupCipher(cipher);
28740
+ this.result.ciphers.push(cipher);
28350
28741
  });
28351
- }
28352
- this.results.items.forEach((c) => {
28353
- const cipher = CipherWithIdExport.toView(c);
28354
- // reset ids incase they were set for some reason
28355
- cipher.id = null;
28356
- cipher.organizationId = null;
28357
- cipher.collectionIds = null;
28358
- // make sure password history is limited
28359
- if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) {
28360
- cipher.passwordHistory = cipher.passwordHistory.slice(0, 5);
28361
- }
28362
- if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) {
28363
- this.result.folderRelationships.push([
28364
- this.result.ciphers.length,
28365
- groupingsMap.get(c.folderId),
28366
- ]);
28742
+ this.result.success = true;
28743
+ });
28744
+ }
28745
+ parseFolders(data) {
28746
+ return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28747
+ if (data.folders == null) {
28748
+ return null;
28367
28749
  }
28368
- else if (this.organization && c.collectionIds != null) {
28369
- c.collectionIds.forEach((cId) => {
28370
- if (groupingsMap.has(cId)) {
28371
- this.result.collectionRelationships.push([
28372
- this.result.ciphers.length,
28373
- groupingsMap.get(cId),
28374
- ]);
28750
+ const groupingsMap = new Map();
28751
+ for (const f of data.folders) {
28752
+ let folderView;
28753
+ if (data.encrypted) {
28754
+ const folder = FolderWithIdExport.toDomain(f);
28755
+ if (folder != null) {
28756
+ folderView = yield folder.decrypt();
28375
28757
  }
28376
- });
28758
+ }
28759
+ else {
28760
+ folderView = FolderWithIdExport.toView(f);
28761
+ }
28762
+ if (folderView != null) {
28763
+ groupingsMap.set(f.id, this.result.folders.length);
28764
+ this.result.folders.push(folderView);
28765
+ }
28377
28766
  }
28378
- this.cleanupCipher(cipher);
28379
- this.result.ciphers.push(cipher);
28767
+ return groupingsMap;
28768
+ });
28769
+ }
28770
+ parseCollections(data) {
28771
+ return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28772
+ if (data.collections == null) {
28773
+ return null;
28774
+ }
28775
+ const groupingsMap = new Map();
28776
+ for (const c of data.collections) {
28777
+ let collectionView;
28778
+ if (data.encrypted) {
28779
+ const collection = CollectionWithIdExport.toDomain(c);
28780
+ collection.organizationId = this.organizationId;
28781
+ collectionView = yield collection.decrypt();
28782
+ }
28783
+ else {
28784
+ collectionView = CollectionWithIdExport.toView(c);
28785
+ collectionView.organizationId = null;
28786
+ }
28787
+ if (collectionView != null) {
28788
+ groupingsMap.set(c.id, this.result.collections.length);
28789
+ this.result.collections.push(collectionView);
28790
+ }
28791
+ }
28792
+ return groupingsMap;
28380
28793
  });
28381
- this.result.success = true;
28382
28794
  }
28383
28795
  }
28384
28796
 
@@ -28398,8 +28810,8 @@ var bitwarden_password_protected_importer_awaiter = (undefined && undefined.__aw
28398
28810
 
28399
28811
 
28400
28812
  class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter {
28401
- constructor(cryptoService, i18nService, promptForPassword_callback) {
28402
- super(cryptoService, i18nService);
28813
+ constructor(cryptoService, i18nService, cipherService, promptForPassword_callback) {
28814
+ super(cryptoService, i18nService, cipherService);
28403
28815
  this.promptForPassword_callback = promptForPassword_callback;
28404
28816
  }
28405
28817
  parse(data) {
@@ -32366,6 +32778,97 @@ class PasswordWalletTxtImporter extends base_importer_BaseImporter {
32366
32778
  }
32367
32779
  }
32368
32780
 
32781
+ ;// CONCATENATED MODULE: ../../libs/importer/src/importers/protonpass/types/protonpass-json-type.ts
32782
+ var ProtonPassItemState;
32783
+ (function (ProtonPassItemState) {
32784
+ ProtonPassItemState[ProtonPassItemState["ACTIVE"] = 1] = "ACTIVE";
32785
+ ProtonPassItemState[ProtonPassItemState["TRASHED"] = 2] = "TRASHED";
32786
+ })(ProtonPassItemState || (ProtonPassItemState = {}));
32787
+
32788
+ ;// CONCATENATED MODULE: ../../libs/importer/src/importers/protonpass/protonpass-json-importer.ts
32789
+
32790
+
32791
+
32792
+
32793
+
32794
+
32795
+
32796
+ class ProtonPassJsonImporter extends base_importer_BaseImporter {
32797
+ constructor(i18nService) {
32798
+ super();
32799
+ this.i18nService = i18nService;
32800
+ }
32801
+ parse(data) {
32802
+ const result = new import_result_ImportResult();
32803
+ const results = JSON.parse(data);
32804
+ if (results == null || results.vaults == null) {
32805
+ result.success = false;
32806
+ return Promise.resolve(result);
32807
+ }
32808
+ if (results.encrypted) {
32809
+ result.success = false;
32810
+ result.errorMessage = this.i18nService.t("unsupportedEncryptedImport");
32811
+ return Promise.resolve(result);
32812
+ }
32813
+ for (const [, vault] of Object.entries(results.vaults)) {
32814
+ for (const item of vault.items) {
32815
+ if (item.state == ProtonPassItemState.TRASHED) {
32816
+ continue;
32817
+ }
32818
+ this.processFolder(result, vault.name);
32819
+ const cipher = this.initLoginCipher();
32820
+ cipher.name = item.data.metadata.name;
32821
+ cipher.notes = item.data.metadata.note;
32822
+ switch (item.data.type) {
32823
+ case "login": {
32824
+ const loginContent = item.data.content;
32825
+ cipher.login.uris = this.makeUriArray(loginContent.urls);
32826
+ cipher.login.username = loginContent.username;
32827
+ cipher.login.password = loginContent.password;
32828
+ if (loginContent.totpUri != "") {
32829
+ cipher.login.totp = new URL(loginContent.totpUri).searchParams.get("secret");
32830
+ }
32831
+ for (const extraField of item.data.extraFields) {
32832
+ this.processKvp(cipher, extraField.fieldName, extraField.type == "totp" ? extraField.data.totpUri : extraField.data.content, extraField.type == "text" ? FieldType.Text : FieldType.Hidden);
32833
+ }
32834
+ break;
32835
+ }
32836
+ case "note":
32837
+ cipher.type = CipherType.SecureNote;
32838
+ cipher.secureNote = new SecureNoteView();
32839
+ cipher.secureNote.type = SecureNoteType.Generic;
32840
+ break;
32841
+ case "creditCard": {
32842
+ const creditCardContent = item.data.content;
32843
+ cipher.type = CipherType.Card;
32844
+ cipher.card = new CardView();
32845
+ cipher.card.cardholderName = creditCardContent.cardholderName;
32846
+ cipher.card.number = creditCardContent.number;
32847
+ cipher.card.brand = CardView.getCardBrandByPatterns(creditCardContent.number);
32848
+ cipher.card.code = creditCardContent.verificationNumber;
32849
+ if (!this.isNullOrWhitespace(creditCardContent.expirationDate)) {
32850
+ cipher.card.expMonth = creditCardContent.expirationDate.substring(0, 2);
32851
+ cipher.card.expMonth = cipher.card.expMonth.replace(/^0+/, "");
32852
+ cipher.card.expYear = creditCardContent.expirationDate.substring(2, 6);
32853
+ }
32854
+ if (!this.isNullOrWhitespace(creditCardContent.pin)) {
32855
+ this.processKvp(cipher, "PIN", creditCardContent.pin, FieldType.Hidden);
32856
+ }
32857
+ break;
32858
+ }
32859
+ }
32860
+ this.cleanupCipher(cipher);
32861
+ result.ciphers.push(cipher);
32862
+ }
32863
+ }
32864
+ if (this.organization) {
32865
+ this.moveFoldersToCollections(result);
32866
+ }
32867
+ result.success = true;
32868
+ return Promise.resolve(result);
32869
+ }
32870
+ }
32871
+
32369
32872
  ;// CONCATENATED MODULE: ../../libs/importer/src/importers/psono/psono-json-importer.ts
32370
32873
 
32371
32874
 
@@ -32490,6 +32993,7 @@ class PsonoJsonImporter extends base_importer_BaseImporter {
32490
32993
  return cipher;
32491
32994
  }
32492
32995
  parseWebsiteLogins(entry, cipher) {
32996
+ var _a;
32493
32997
  if (entry == null || entry.type != "website_password") {
32494
32998
  return;
32495
32999
  }
@@ -32498,7 +33002,7 @@ class PsonoJsonImporter extends base_importer_BaseImporter {
32498
33002
  cipher.login.username = entry.website_password_username;
32499
33003
  cipher.login.password = entry.website_password_password;
32500
33004
  cipher.login.uris = this.makeUriArray(entry.website_password_url);
32501
- this.processKvp(cipher, "website_password_auto_submit", entry.website_password_auto_submit.toString(), FieldType.Boolean);
33005
+ this.processKvp(cipher, "website_password_auto_submit", (_a = entry.website_password_auto_submit) === null || _a === void 0 ? void 0 : _a.toString(), FieldType.Boolean);
32502
33006
  this.processKvp(cipher, "website_password_url_filter", entry.website_password_url_filter);
32503
33007
  this.importUnmappedFields(cipher, entry, this.WEBSITE_mappedValues);
32504
33008
  }
@@ -33276,6 +33780,7 @@ class ZohoVaultCsvImporter extends base_importer_BaseImporter {
33276
33780
 
33277
33781
 
33278
33782
 
33783
+
33279
33784
 
33280
33785
 
33281
33786
 
@@ -33303,6 +33808,7 @@ const regularImportOptions = [
33303
33808
  // { id: "keeperjson", name: "Keeper (json)" },
33304
33809
  { id: "enpasscsv", name: "Enpass (csv)" },
33305
33810
  { id: "enpassjson", name: "Enpass (json)" },
33811
+ { id: "protonpass", name: "ProtonPass (zip/json)" },
33306
33812
  { id: "safeincloudxml", name: "SafeInCloud (xml)" },
33307
33813
  { id: "pwsafexml", name: "Password Safe (xml)" },
33308
33814
  { id: "stickypasswordxml", name: "Sticky Password (xml)" },
@@ -33456,7 +33962,7 @@ class ImportService {
33456
33962
  return new BitwardenCsvImporter();
33457
33963
  case "bitwardenjson":
33458
33964
  case "bitwardenpasswordprotected":
33459
- return new BitwardenPasswordProtectedImporter(this.cryptoService, this.i18nService, promptForPassword_callback);
33965
+ return new BitwardenPasswordProtectedImporter(this.cryptoService, this.i18nService, this.cipherService, promptForPassword_callback);
33460
33966
  case "lastpasscsv":
33461
33967
  case "passboltcsv":
33462
33968
  return new LastPassCsvImporter();
@@ -33572,6 +34078,8 @@ class ImportService {
33572
34078
  return new PsonoJsonImporter();
33573
34079
  case "passkyjson":
33574
34080
  return new PasskyJsonImporter();
34081
+ case "protonpass":
34082
+ return new ProtonPassJsonImporter(this.i18nService);
33575
34083
  default:
33576
34084
  return null;
33577
34085
  }
@@ -33942,6 +34450,9 @@ class NodeCryptoFunctionService {
33942
34450
  });
33943
34451
  });
33944
34452
  }
34453
+ aesGenerateKey(bitLength) {
34454
+ return this.randomBytes(bitLength / 8);
34455
+ }
33945
34456
  randomBytes(length) {
33946
34457
  return new Promise((resolve, reject) => {
33947
34458
  external_crypto_namespaceObject.randomBytes(length, (error, bytes) => {
@@ -33993,6 +34504,147 @@ class NodeCryptoFunctionService {
33993
34504
  }
33994
34505
  }
33995
34506
 
34507
+ ;// CONCATENATED MODULE: ../../libs/common/src/platform/abstractions/config/server-config.ts
34508
+ const dayInMilliseconds = 24 * 3600 * 1000;
34509
+ const eighteenHoursInMilliseconds = 18 * 3600 * 1000;
34510
+ class ServerConfig {
34511
+ constructor(serverConfigData) {
34512
+ var _a, _b;
34513
+ this.featureStates = {};
34514
+ this.version = serverConfigData.version;
34515
+ this.gitHash = serverConfigData.gitHash;
34516
+ this.server = serverConfigData.server;
34517
+ this.utcDate = new Date(serverConfigData.utcDate);
34518
+ this.environment = serverConfigData.environment;
34519
+ this.featureStates = serverConfigData.featureStates;
34520
+ if (((_a = this.server) === null || _a === void 0 ? void 0 : _a.name) == null && ((_b = this.server) === null || _b === void 0 ? void 0 : _b.url) == null) {
34521
+ this.server = null;
34522
+ }
34523
+ }
34524
+ getAgeInMilliseconds() {
34525
+ var _a;
34526
+ return new Date().getTime() - ((_a = this.utcDate) === null || _a === void 0 ? void 0 : _a.getTime());
34527
+ }
34528
+ isValid() {
34529
+ return this.getAgeInMilliseconds() <= dayInMilliseconds;
34530
+ }
34531
+ expiresSoon() {
34532
+ return this.getAgeInMilliseconds() >= eighteenHoursInMilliseconds;
34533
+ }
34534
+ static fromJSON(obj) {
34535
+ if (obj == null) {
34536
+ return null;
34537
+ }
34538
+ return new ServerConfig(obj);
34539
+ }
34540
+ }
34541
+
34542
+ ;// CONCATENATED MODULE: ../../libs/common/src/platform/services/config/config.service.ts
34543
+ var config_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
34544
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34545
+ return new (P || (P = Promise))(function (resolve, reject) {
34546
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34547
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34548
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34549
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34550
+ });
34551
+ };
34552
+
34553
+
34554
+
34555
+
34556
+
34557
+
34558
+ const ONE_HOUR_IN_MILLISECONDS = 1000 * 3600;
34559
+ class ConfigService {
34560
+ constructor(stateService, configApiService, authService, environmentService, logService,
34561
+ // Used to avoid duplicate subscriptions, e.g. in browser between the background and popup
34562
+ subscribe = true) {
34563
+ this.stateService = stateService;
34564
+ this.configApiService = configApiService;
34565
+ this.authService = authService;
34566
+ this.environmentService = environmentService;
34567
+ this.logService = logService;
34568
+ this.subscribe = subscribe;
34569
+ this.inited = false;
34570
+ this._serverConfig = new external_rxjs_namespaceObject.ReplaySubject(1);
34571
+ this.serverConfig$ = this._serverConfig.asObservable();
34572
+ this._forceFetchConfig = new external_rxjs_namespaceObject.Subject();
34573
+ this.refreshTimer$ = (0,external_rxjs_namespaceObject.timer)(ONE_HOUR_IN_MILLISECONDS, ONE_HOUR_IN_MILLISECONDS); // after 1 hour, then every hour
34574
+ this.cloudRegion$ = this.serverConfig$.pipe((0,external_rxjs_namespaceObject.map)((config) => { var _a, _b; return (_b = (_a = config === null || config === void 0 ? void 0 : config.environment) === null || _a === void 0 ? void 0 : _a.cloudRegion) !== null && _b !== void 0 ? _b : Region.US; }));
34575
+ }
34576
+ init() {
34577
+ if (!this.subscribe || this.inited) {
34578
+ return;
34579
+ }
34580
+ const latestServerConfig$ = (0,external_rxjs_namespaceObject.defer)(() => this.configApiService.get()).pipe((0,external_rxjs_namespaceObject.map)((response) => new ServerConfigData(response)), (0,external_rxjs_namespaceObject.delayWhen)((data) => this.saveConfig(data)), (0,external_rxjs_namespaceObject.catchError)((e) => {
34581
+ // fall back to stored ServerConfig (if any)
34582
+ this.logService.error("Unable to fetch ServerConfig: " + (e === null || e === void 0 ? void 0 : e.message));
34583
+ return this.stateService.getServerConfig();
34584
+ }));
34585
+ // If you need to fetch a new config when an event occurs, add an observable that emits on that event here
34586
+ (0,external_rxjs_namespaceObject.merge)(this.refreshTimer$, // an overridable interval
34587
+ this.environmentService.urls, // when environment URLs change (including when app is started)
34588
+ this._forceFetchConfig // manual
34589
+ )
34590
+ .pipe((0,external_rxjs_namespaceObject.concatMap)(() => latestServerConfig$), (0,external_rxjs_namespaceObject.map)((data) => (data == null ? null : new ServerConfig(data))))
34591
+ .subscribe((config) => this._serverConfig.next(config));
34592
+ this.inited = true;
34593
+ }
34594
+ getFeatureFlag$(key, defaultValue) {
34595
+ return this.serverConfig$.pipe((0,external_rxjs_namespaceObject.map)((serverConfig) => {
34596
+ if ((serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.featureStates) == null || serverConfig.featureStates[key] == null) {
34597
+ return defaultValue;
34598
+ }
34599
+ return serverConfig.featureStates[key];
34600
+ }));
34601
+ }
34602
+ getFeatureFlag(key, defaultValue) {
34603
+ return config_service_awaiter(this, void 0, void 0, function* () {
34604
+ return yield (0,external_rxjs_namespaceObject.firstValueFrom)(this.getFeatureFlag$(key, defaultValue));
34605
+ });
34606
+ }
34607
+ triggerServerConfigFetch() {
34608
+ this._forceFetchConfig.next();
34609
+ }
34610
+ saveConfig(data) {
34611
+ var _a;
34612
+ return config_service_awaiter(this, void 0, void 0, function* () {
34613
+ if ((yield this.authService.getAuthStatus()) === AuthenticationStatus.LoggedOut) {
34614
+ return;
34615
+ }
34616
+ yield this.stateService.setServerConfig(data);
34617
+ this.environmentService.setCloudWebVaultUrl((_a = data.environment) === null || _a === void 0 ? void 0 : _a.cloudRegion);
34618
+ });
34619
+ }
34620
+ /**
34621
+ * Verifies whether the server version meets the minimum required version
34622
+ * @param minimumRequiredServerVersion The minimum version required
34623
+ * @returns True if the server version is greater than or equal to the minimum required version
34624
+ */
34625
+ checkServerMeetsVersionRequirement$(minimumRequiredServerVersion) {
34626
+ return this.serverConfig$.pipe((0,external_rxjs_namespaceObject.map)((serverConfig) => {
34627
+ if (serverConfig == null) {
34628
+ return false;
34629
+ }
34630
+ const serverVersion = new external_semver_namespaceObject.SemVer(serverConfig.version);
34631
+ return serverVersion.compare(minimumRequiredServerVersion) >= 0;
34632
+ }));
34633
+ }
34634
+ }
34635
+
34636
+ ;// CONCATENATED MODULE: ./src/platform/services/cli-config.service.ts
34637
+
34638
+
34639
+ class CliConfigService extends ConfigService {
34640
+ constructor() {
34641
+ super(...arguments);
34642
+ // The rxjs timer uses setTimeout/setInterval under the hood, which prevents the node process from exiting
34643
+ // when the command is finished. Cli should never be alive long enough to use the timer, so we disable it.
34644
+ this.refreshTimer$ = external_rxjs_namespaceObject.NEVER;
34645
+ }
34646
+ }
34647
+
33996
34648
  ;// CONCATENATED MODULE: external "child_process"
33997
34649
  const external_child_process_namespaceObject = require("child_process");
33998
34650
  ;// CONCATENATED MODULE: ./src/platform/services/cli-platform-utils.service.ts
@@ -34673,6 +35325,7 @@ class CipherResponse extends BaseResponse {
34673
35325
  this.passwordHistory = passwordHistory.map((h) => new PasswordHistoryResponse(h));
34674
35326
  }
34675
35327
  this.reprompt = this.getResponseProperty("Reprompt") || CipherRepromptType.None;
35328
+ this.key = this.getResponseProperty("Key") || null;
34676
35329
  }
34677
35330
  }
34678
35331
 
@@ -37729,7 +38382,7 @@ class CliUtils {
37729
38382
  });
37730
38383
  });
37731
38384
  }
37732
- static extract1PuxContent(input) {
38385
+ static extractZipContent(input, filepath) {
37733
38386
  return new Promise((resolve, reject) => {
37734
38387
  let p = null;
37735
38388
  if (input != null && input !== "") {
@@ -37749,7 +38402,7 @@ class CliUtils {
37749
38402
  reject(err);
37750
38403
  }
37751
38404
  external_jszip_namespaceObject.loadAsync(data).then((zip) => {
37752
- resolve(zip.file("export.data").async("string"));
38405
+ resolve(zip.file(filepath).async("string"));
37753
38406
  }, (reason) => {
37754
38407
  reject(reason);
37755
38408
  });
@@ -37923,6 +38576,21 @@ class CliUtils {
37923
38576
  static convertBooleanOption(optionValue) {
37924
38577
  return optionValue || optionValue === "" ? true : false;
37925
38578
  }
38579
+ static convertNumberOption(optionValue, defaultValue) {
38580
+ try {
38581
+ if (optionValue != null) {
38582
+ const numVal = parseInt(optionValue);
38583
+ return !Number.isNaN(numVal) ? numVal : defaultValue;
38584
+ }
38585
+ return defaultValue;
38586
+ }
38587
+ catch (_a) {
38588
+ return defaultValue;
38589
+ }
38590
+ }
38591
+ static convertStringOption(optionValue, defaultValue) {
38592
+ return optionValue != null ? String(optionValue) : defaultValue;
38593
+ }
37926
38594
  }
37927
38595
 
37928
38596
  ;// CONCATENATED MODULE: ./src/auth/commands/unlock.command.ts
@@ -38424,11 +39092,11 @@ class ShareCommand {
38424
39092
  if (cipher.organizationId != null) {
38425
39093
  return Response.badRequest("This item already belongs to an organization.");
38426
39094
  }
38427
- const cipherView = yield cipher.decrypt();
39095
+ const cipherView = yield cipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(cipher));
38428
39096
  try {
38429
39097
  yield this.cipherService.shareWithServer(cipherView, organizationId, req);
38430
39098
  const updatedCipher = yield this.cipherService.get(cipher.id);
38431
- const decCipher = yield updatedCipher.decrypt();
39099
+ const decCipher = yield updatedCipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(updatedCipher));
38432
39100
  const res = new cipher_response_CipherResponse(decCipher);
38433
39101
  return Response.success(res);
38434
39102
  }
@@ -38480,6 +39148,9 @@ class GenerateCommand {
38480
39148
  numWords: normalizedOptions.words,
38481
39149
  capitalize: normalizedOptions.capitalize,
38482
39150
  includeNumber: normalizedOptions.includeNumber,
39151
+ minNumber: normalizedOptions.minNumber,
39152
+ minSpecial: normalizedOptions.minSpecial,
39153
+ ambiguous: normalizedOptions.ambiguous,
38483
39154
  };
38484
39155
  const enforcedOptions = (yield this.stateService.getIsAuthenticated())
38485
39156
  ? (yield this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options))[0]
@@ -38498,10 +39169,13 @@ class generate_command_Options {
38498
39169
  this.special = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.special);
38499
39170
  this.capitalize = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.capitalize);
38500
39171
  this.includeNumber = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.includeNumber);
38501
- this.length = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.length) != null ? parseInt(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.length, null) : 14;
39172
+ this.ambiguous = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.ambiguous);
39173
+ this.length = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.length, 14);
38502
39174
  this.type = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.passphrase) ? "passphrase" : "password";
38503
- this.separator = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.separator) == null ? "-" : passedOptions.separator + "";
38504
- this.words = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.words) != null ? parseInt(passedOptions.words, null) : 3;
39175
+ this.separator = CliUtils.convertStringOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.separator, "-");
39176
+ this.words = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.words, 3);
39177
+ this.minNumber = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.minNumber, 1);
39178
+ this.minSpecial = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.minSpecial, 1);
38505
39179
  if (!this.uppercase && !this.lowercase && !this.special && !this.number) {
38506
39180
  this.lowercase = true;
38507
39181
  this.uppercase = true;
@@ -39518,7 +40192,7 @@ class CreateCommand {
39518
40192
  try {
39519
40193
  yield this.cipherService.createWithServer(cipher);
39520
40194
  const newCipher = yield this.cipherService.get(cipher.id);
39521
- const decCipher = yield newCipher.decrypt();
40195
+ const decCipher = yield newCipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(newCipher));
39522
40196
  const res = new cipher_response_CipherResponse(decCipher);
39523
40197
  return Response.success(res);
39524
40198
  }
@@ -39571,7 +40245,7 @@ class CreateCommand {
39571
40245
  try {
39572
40246
  yield this.cipherService.saveAttachmentRawWithServer(cipher, fileName, new Uint8Array(fileBuf).buffer);
39573
40247
  const updatedCipher = yield this.cipherService.get(cipher.id);
39574
- const decCipher = yield updatedCipher.decrypt();
40248
+ const decCipher = yield updatedCipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(updatedCipher));
39575
40249
  return Response.success(new cipher_response_CipherResponse(decCipher));
39576
40250
  }
39577
40251
  catch (e) {
@@ -39894,7 +40568,7 @@ class EditCommand {
39894
40568
  if (cipher == null) {
39895
40569
  return Response.notFound();
39896
40570
  }
39897
- let cipherView = yield cipher.decrypt();
40571
+ let cipherView = yield cipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(cipher));
39898
40572
  if (cipherView.isDeleted) {
39899
40573
  return Response.badRequest("You may not edit a deleted item. Use the restore command first.");
39900
40574
  }
@@ -39903,7 +40577,7 @@ class EditCommand {
39903
40577
  try {
39904
40578
  yield this.cipherService.updateWithServer(encCipher);
39905
40579
  const updatedCipher = yield this.cipherService.get(cipher.id);
39906
- const decCipher = yield updatedCipher.decrypt();
40580
+ const decCipher = yield updatedCipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(updatedCipher));
39907
40581
  const res = new cipher_response_CipherResponse(decCipher);
39908
40582
  return Response.success(res);
39909
40583
  }
@@ -39925,7 +40599,7 @@ class EditCommand {
39925
40599
  try {
39926
40600
  yield this.cipherService.saveCollectionsWithServer(cipher);
39927
40601
  const updatedCipher = yield this.cipherService.get(cipher.id);
39928
- const decCipher = yield updatedCipher.decrypt();
40602
+ const decCipher = yield updatedCipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(updatedCipher));
39929
40603
  const res = new cipher_response_CipherResponse(decCipher);
39930
40604
  return Response.success(res);
39931
40605
  }
@@ -40142,7 +40816,7 @@ class GetCommand extends DownloadCommand {
40142
40816
  if (utils_Utils.isGuid(id)) {
40143
40817
  const cipher = yield this.cipherService.get(id);
40144
40818
  if (cipher != null) {
40145
- decCipher = yield cipher.decrypt();
40819
+ decCipher = yield cipher.decrypt(yield this.cipherService.getKeyForCipherKeyDecryption(cipher));
40146
40820
  }
40147
40821
  }
40148
40822
  else if (id.trim() !== "") {
@@ -41490,9 +42164,12 @@ class Program {
41490
42164
  .option("-p, --passphrase", "Generate a passphrase.")
41491
42165
  .option("--length <length>", "Length of the password.")
41492
42166
  .option("--words <words>", "Number of words.")
42167
+ .option("--minNumber <count>", "Minimum number of numeric characters.")
42168
+ .option("--minSpecial <count>", "Minimum number of special characters.")
41493
42169
  .option("--separator <separator>", "Word separator.")
41494
42170
  .option("-c, --capitalize", "Title case passphrase.")
41495
42171
  .option("--includeNumber", "Passphrase includes number.")
42172
+ .option("--ambiguous", "Avoid ambiguous characters.")
41496
42173
  .on("--help", () => {
41497
42174
  writeLn("\n Notes:");
41498
42175
  writeLn("");
@@ -42206,7 +42883,10 @@ class ImportCommand {
42206
42883
  try {
42207
42884
  let contents;
42208
42885
  if (format === "1password1pux") {
42209
- contents = yield CliUtils.extract1PuxContent(filepath);
42886
+ contents = yield CliUtils.extractZipContent(filepath, "export.data");
42887
+ }
42888
+ else if (format === "protonpass" && filepath.endsWith(".zip")) {
42889
+ contents = yield CliUtils.extractZipContent(filepath, "Proton Pass/data.json");
42210
42890
  }
42211
42891
  else {
42212
42892
  contents = yield CliUtils.readFile(filepath);
@@ -42721,6 +43401,7 @@ var bw_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argum
42721
43401
 
42722
43402
 
42723
43403
 
43404
+
42724
43405
 
42725
43406
 
42726
43407
  // Polyfills
@@ -42757,8 +43438,7 @@ class Main {
42757
43438
  this.storageService = new LowdbStorageService(this.logService, null, p, false, true);
42758
43439
  this.secureStorageService = new NodeEnvSecureStorageService(this.storageService, this.logService, () => this.cryptoService);
42759
43440
  this.memoryStorageService = new MemoryStorageService();
42760
- this.stateMigrationService = new StateMigrationService(this.storageService, this.secureStorageService, new StateFactory(GlobalState, Account));
42761
- this.stateService = new StateService(this.storageService, this.secureStorageService, this.memoryStorageService, this.logService, this.stateMigrationService, new StateFactory(GlobalState, Account));
43441
+ this.stateService = new StateService(this.storageService, this.secureStorageService, this.memoryStorageService, this.logService, new StateFactory(GlobalState, Account));
42762
43442
  this.cryptoService = new CryptoService(this.cryptoFunctionService, this.encryptService, this.platformUtilsService, this.logService, this.stateService);
42763
43443
  this.appIdService = new AppIdService(this.storageService);
42764
43444
  this.tokenService = new TokenService(this.stateService);
@@ -42779,10 +43459,7 @@ class Main {
42779
43459
  this.cipherFileUploadService = new CipherFileUploadService(this.apiService, this.fileUploadService);
42780
43460
  this.sendApiService = this.sendApiService = new SendApiService(this.apiService, this.fileUploadService, this.sendService);
42781
43461
  this.searchService = new SearchService(this.logService, this.i18nService);
42782
- this.cipherService = new CipherService(this.cryptoService, this.settingsService, this.apiService, this.i18nService, this.searchService, this.stateService, this.encryptService, this.cipherFileUploadService);
42783
43462
  this.broadcasterService = new BroadcasterService();
42784
- this.folderService = new FolderService(this.cryptoService, this.i18nService, this.cipherService, this.stateService);
42785
- this.folderApiService = new FolderApiService(this.folderService, this.apiService);
42786
43463
  this.collectionService = new CollectionService(this.cryptoService, this.i18nService, this.stateService);
42787
43464
  this.providerService = new ProviderService(this.stateService);
42788
43465
  this.organizationService = new organization_service_OrganizationService(this.stateService);
@@ -42797,6 +43474,11 @@ class Main {
42797
43474
  this.deviceTrustCryptoService = new DeviceTrustCryptoService(this.cryptoFunctionService, this.cryptoService, this.encryptService, this.stateService, this.appIdService, this.devicesApiService, this.i18nService, this.platformUtilsService);
42798
43475
  this.authRequestCryptoService = new AuthRequestCryptoServiceImplementation(this.cryptoService);
42799
43476
  this.authService = new AuthService(this.cryptoService, this.apiService, this.tokenService, this.appIdService, this.platformUtilsService, this.messagingService, this.logService, this.keyConnectorService, this.environmentService, this.stateService, this.twoFactorService, this.i18nService, this.encryptService, this.passwordStrengthService, this.policyService, this.deviceTrustCryptoService, this.authRequestCryptoService);
43477
+ this.configApiService = new ConfigApiService(this.apiService, this.authService);
43478
+ this.configService = new CliConfigService(this.stateService, this.configApiService, this.authService, this.environmentService, this.logService, true);
43479
+ this.cipherService = new CipherService(this.cryptoService, this.settingsService, this.apiService, this.i18nService, this.searchService, this.stateService, this.encryptService, this.cipherFileUploadService, this.configService);
43480
+ this.folderService = new FolderService(this.cryptoService, this.i18nService, this.cipherService, this.stateService);
43481
+ this.folderApiService = new FolderApiService(this.folderService, this.apiService);
42800
43482
  const lockedCallback = (userId) => bw_awaiter(this, void 0, void 0, function* () { return yield this.cryptoService.clearStoredUserKey(KeySuffixOptions.Auto); });
42801
43483
  this.userVerificationService = new UserVerificationService(this.stateService, this.cryptoService, this.i18nService, this.userVerificationApiService);
42802
43484
  this.vaultTimeoutSettingsService = new VaultTimeoutSettingsService(this.cryptoService, this.tokenService, this.policyService, this.stateService, this.userVerificationService);
@@ -42853,6 +43535,7 @@ class Main {
42853
43535
  const locale = yield this.stateService.getLocale();
42854
43536
  yield this.i18nService.init(locale);
42855
43537
  this.twoFactorService.init();
43538
+ this.configService.init();
42856
43539
  const installedVersion = yield this.stateService.getInstalledVersion();
42857
43540
  const currentVersion = yield this.platformUtilsService.getApplicationVersion();
42858
43541
  if (installedVersion == null || installedVersion !== currentVersion) {