1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Merged with master and fixed conflicts

This commit is contained in:
gbubemismith
2023-05-08 12:16:25 -04:00
1131 changed files with 52396 additions and 51717 deletions

View File

@@ -1,5 +1,4 @@
import { FieldType } from "../../enums/fieldType";
import { LinkedIdType } from "../../enums/linkedIdType";
import { FieldType, LinkedIdType } from "../../enums";
import { BaseResponse } from "../response/base.response";
export class FieldApi extends BaseResponse {

View File

@@ -1,4 +1,4 @@
import { UriMatchType } from "../../enums/uriMatchType";
import { UriMatchType } from "../../enums";
import { BaseResponse } from "../response/base.response";
export class LoginUriApi extends BaseResponse {

View File

@@ -1,4 +1,4 @@
import { SecureNoteType } from "../../enums/secureNoteType";
import { SecureNoteType } from "../../enums";
import { BaseResponse } from "../response/base.response";
export class SecureNoteApi extends BaseResponse {

View File

@@ -1,4 +1,4 @@
import { EventType } from "../../enums/eventType";
import { EventType } from "../../enums";
export class EventData {
type: EventType;

View File

@@ -12,6 +12,7 @@ export class ServerConfigData {
server?: ThirdPartyServerConfigData;
environment?: EnvironmentServerConfigData;
utcDate: string;
featureStates: { [key: string]: string } = {};
constructor(serverConfigResponse: Partial<ServerConfigResponse>) {
this.version = serverConfigResponse?.version;
@@ -23,6 +24,7 @@ export class ServerConfigData {
this.environment = serverConfigResponse?.environment
? new EnvironmentServerConfigData(serverConfigResponse.environment)
: null;
this.featureStates = serverConfigResponse?.featureStates;
}
static fromJSON(obj: Jsonify<ServerConfigData>): ServerConfigData {

View File

@@ -9,8 +9,8 @@ import { Policy } from "../../admin-console/models/domain/policy";
import { CollectionView } from "../../admin-console/models/view/collection.view";
import { AuthenticationStatus } from "../../auth/enums/authentication-status";
import { EnvironmentUrls } from "../../auth/models/domain/environment-urls";
import { KdfType } from "../../enums/kdfType";
import { UriMatchType } from "../../enums/uriMatchType";
import { ForceResetPasswordReason } from "../../auth/models/domain/force-reset-password-reason";
import { KdfType, UriMatchType } from "../../enums";
import { Utils } from "../../misc/utils";
import { GeneratedPasswordHistory } from "../../tools/generator/password";
import { SendData } from "../../tools/send/models/data/send.data";
@@ -133,27 +133,20 @@ export class AccountKeys {
return null;
}
return Object.assign(
new AccountKeys(),
{ cryptoMasterKey: SymmetricCryptoKey.fromJSON(obj?.cryptoMasterKey) },
{
cryptoSymmetricKey: EncryptionPair.fromJSON(
obj?.cryptoSymmetricKey,
SymmetricCryptoKey.fromJSON
),
},
{ organizationKeys: AccountKeys.initRecordEncryptionPairsFromJSON(obj?.organizationKeys) },
{ providerKeys: AccountKeys.initRecordEncryptionPairsFromJSON(obj?.providerKeys) },
{
privateKey: EncryptionPair.fromJSON<string, ArrayBuffer>(
obj?.privateKey,
(decObj: string) => Utils.fromByteStringToArray(decObj).buffer
),
},
{
publicKey: Utils.fromByteStringToArray(obj?.publicKey)?.buffer,
}
);
return Object.assign(new AccountKeys(), {
cryptoMasterKey: SymmetricCryptoKey.fromJSON(obj?.cryptoMasterKey),
cryptoSymmetricKey: EncryptionPair.fromJSON(
obj?.cryptoSymmetricKey,
SymmetricCryptoKey.fromJSON
),
organizationKeys: AccountKeys.initRecordEncryptionPairsFromJSON(obj?.organizationKeys),
providerKeys: AccountKeys.initRecordEncryptionPairsFromJSON(obj?.providerKeys),
privateKey: EncryptionPair.fromJSON<string, ArrayBuffer>(
obj?.privateKey,
(decObj: string) => Utils.fromByteStringToArray(decObj).buffer
),
publicKey: Utils.fromByteStringToArray(obj?.publicKey)?.buffer,
});
}
static initRecordEncryptionPairsFromJSON(obj: any) {
@@ -181,7 +174,7 @@ export class AccountProfile {
entityId?: string;
entityType?: string;
everBeenUnlocked?: boolean;
forcePasswordReset?: boolean;
forcePasswordResetReason?: ForceResetPasswordReason;
hasPremiumPersonally?: boolean;
hasPremiumFromOrganization?: boolean;
lastSync?: string;

View File

@@ -1,4 +1,4 @@
import { EncryptionType } from "../../enums/encryptionType";
import { EncryptionType } from "../../enums";
import { IEncrypted } from "../../interfaces/IEncrypted";
import { Utils } from "../../misc/utils";

View File

@@ -1,6 +1,6 @@
import { Jsonify } from "type-fest";
import { EncryptionType } from "../../enums/encryptionType";
import { EncryptionType, EXPECTED_NUM_PARTS_BY_ENCRYPTION_TYPE } from "../../enums";
import { IEncrypted } from "../../interfaces/IEncrypted";
import { Utils } from "../../misc/utils";
@@ -75,34 +75,26 @@ export class EncString implements IEncrypted {
return;
}
const { encType, encPieces } = this.parseEncryptedString(this.encryptedString);
const { encType, encPieces } = EncString.parseEncryptedString(this.encryptedString);
this.encryptionType = encType;
if (encPieces.length !== EXPECTED_NUM_PARTS_BY_ENCRYPTION_TYPE[encType]) {
return;
}
switch (encType) {
case EncryptionType.AesCbc128_HmacSha256_B64:
case EncryptionType.AesCbc256_HmacSha256_B64:
if (encPieces.length !== 3) {
return;
}
this.iv = encPieces[0];
this.data = encPieces[1];
this.mac = encPieces[2];
break;
case EncryptionType.AesCbc256_B64:
if (encPieces.length !== 2) {
return;
}
this.iv = encPieces[0];
this.data = encPieces[1];
break;
case EncryptionType.Rsa2048_OaepSha256_B64:
case EncryptionType.Rsa2048_OaepSha1_B64:
if (encPieces.length !== 1) {
return;
}
this.data = encPieces[0];
break;
default:
@@ -110,7 +102,7 @@ export class EncString implements IEncrypted {
}
}
private parseEncryptedString(encryptedString: string): {
private static parseEncryptedString(encryptedString: string): {
encType: EncryptionType;
encPieces: string[];
} {
@@ -139,6 +131,12 @@ export class EncString implements IEncrypted {
};
}
static isSerializedEncString(s: string): boolean {
const { encType, encPieces } = this.parseEncryptedString(s);
return EXPECTED_NUM_PARTS_BY_ENCRYPTION_TYPE[encType] === encPieces.length;
}
async decrypt(orgId: string, key: SymmetricCryptoKey = null): Promise<string> {
if (this.decryptedValue != null) {
return this.decryptedValue;

View File

@@ -1,6 +1,5 @@
import { EnvironmentUrls } from "../../auth/models/domain/environment-urls";
import { StateVersion } from "../../enums/stateVersion";
import { ThemeType } from "../../enums/themeType";
import { StateVersion, ThemeType } from "../../enums";
import { WindowState } from "./window-state";
@@ -9,6 +8,7 @@ export class GlobalState {
installedVersion?: string;
locale?: string;
organizationInvitation?: any;
emergencyAccessInvitation?: any;
ssoCodeVerifier?: string;
ssoOrganizationIdentifier?: string;
ssoState?: string;
@@ -25,7 +25,6 @@ export class GlobalState {
mainWindowSize?: number;
enableBiometrics?: boolean;
biometricText?: string;
noAutoPromptBiometrics?: boolean;
noAutoPromptBiometricsText?: string;
stateVersion: StateVersion = StateVersion.One;
environmentUrls: EnvironmentUrls = new EnvironmentUrls();

View File

@@ -1,5 +1,4 @@
import { ProviderUserStatusType } from "../../admin-console/enums/provider-user-status-type";
import { ProviderUserType } from "../../admin-console/enums/provider-user-type";
import { ProviderUserStatusType, ProviderUserType } from "../../admin-console/enums";
import { ProviderData } from "../../admin-console/models/data/provider.data";
export class Provider {

View File

@@ -1,7 +1,6 @@
import { Jsonify } from "type-fest";
import { HtmlStorageLocation } from "../../enums/htmlStorageLocation";
import { StorageLocation } from "../../enums/storageLocation";
import { HtmlStorageLocation, StorageLocation } from "../../enums";
export type StorageOptions = {
storageLocation?: StorageLocation;

View File

@@ -1,6 +1,6 @@
import { Jsonify } from "type-fest";
import { EncryptionType } from "../../enums/encryptionType";
import { EncryptionType } from "../../enums";
import { Utils } from "../../misc/utils";
export class SymmetricCryptoKey {
@@ -62,12 +62,16 @@ export class SymmetricCryptoKey {
return { keyB64: this.keyB64 };
}
static fromJSON(obj: Jsonify<SymmetricCryptoKey>): SymmetricCryptoKey {
if (obj == null) {
static fromString(s: string): SymmetricCryptoKey {
if (s == null) {
return null;
}
const arrayBuffer = Utils.fromB64ToArray(obj.keyB64).buffer;
const arrayBuffer = Utils.fromB64ToArray(s).buffer;
return new SymmetricCryptoKey(arrayBuffer);
}
static fromJSON(obj: Jsonify<SymmetricCryptoKey>): SymmetricCryptoKey {
return SymmetricCryptoKey.fromString(obj?.keyB64);
}
}

View File

@@ -3,7 +3,7 @@ export class WindowState {
height?: number;
isMaximized?: boolean;
// TODO: displayBounds is an Electron.Rectangle.
// We need to establish some kind of client-specific global state, similiar to the way we already extend a base Account.
// We need to establish some kind of client-specific global state, similar to the way we already extend a base Account.
displayBounds: any;
x?: number;
y?: number;

View File

@@ -6,6 +6,16 @@ import { CollectionExport } from "./collection.export";
export class CollectionWithIdExport extends CollectionExport {
id: string;
static toView(req: CollectionWithIdExport, view = new CollectionView()) {
view.id = req.id;
return super.toView(req, view);
}
static toDomain(req: CollectionWithIdExport, domain = new CollectionDomain()) {
domain.id = req.id;
return super.toDomain(req, domain);
}
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CollectionView | CollectionDomain) {
this.id = o.id;

View File

@@ -1,28 +0,0 @@
import { EventType } from "../../enums/eventType";
import { EventView } from "../view/event.view";
export class EventExport {
message: string;
appIcon: string;
appName: string;
userId: string;
userName: string;
userEmail: string;
date: string;
ip: string;
type: string;
installationId: string;
constructor(event: EventView) {
this.message = event.humanReadableMessage;
this.appIcon = event.appIcon;
this.appName = event.appName;
this.userId = event.userId;
this.userName = event.userName;
this.userEmail = event.userEmail;
this.date = event.date;
this.ip = event.ip;
this.type = EventType[event.type];
this.installationId = event.installationId;
}
}

View File

@@ -1,5 +1,4 @@
import { FieldType } from "../../enums/fieldType";
import { LinkedIdType } from "../../enums/linkedIdType";
import { FieldType, LinkedIdType } from "../../enums";
import { Field as FieldDomain } from "../../vault/models/domain/field";
import { FieldView } from "../../vault/models/view/field.view";
import { EncString } from "../domain/enc-string";

View File

@@ -6,6 +6,16 @@ import { FolderExport } from "./folder.export";
export class FolderWithIdExport extends FolderExport {
id: string;
static toView(req: FolderWithIdExport, view = new FolderView()) {
view.id = req.id;
return super.toView(req, view);
}
static toDomain(req: FolderWithIdExport, domain = new FolderDomain()) {
domain.id = req.id;
return super.toDomain(req, domain);
}
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: FolderView | FolderDomain) {
this.id = o.id;

View File

@@ -0,0 +1,11 @@
export { CardExport } from "./card.export";
export { CipherWithIdExport } from "./cipher-with-ids.export";
export { CipherExport } from "./cipher.export";
export { CollectionWithIdExport } from "./collection-with-id.export";
export { CollectionExport } from "./collection.export";
export { FieldExport } from "./field.export";
export { FolderWithIdExport } from "./folder-with-id.export";
export { FolderExport } from "./folder.export";
export { IdentityExport } from "./identity.export";
export { LoginUriExport } from "./login-uri.export";
export { SecureNoteExport } from "./secure-note.export";

View File

@@ -1,4 +1,4 @@
import { UriMatchType } from "../../enums/uriMatchType";
import { UriMatchType } from "../../enums";
import { LoginUri as LoginUriDomain } from "../../vault/models/domain/login-uri";
import { LoginUriView } from "../../vault/models/view/login-uri.view";
import { EncString } from "../domain/enc-string";

View File

@@ -1,4 +1,4 @@
import { SecureNoteType } from "../../enums/secureNoteType";
import { SecureNoteType } from "../../enums";
import { SecureNote as SecureNoteDomain } from "../../vault/models/domain/secure-note";
import { SecureNoteView } from "../../vault/models/view/secure-note.view";

View File

@@ -1,4 +1,4 @@
import { EventType } from "../../enums/eventType";
import { EventType } from "../../enums";
export class EventRequest {
type: EventType;

View File

@@ -1,4 +1,4 @@
import { PaymentMethodType } from "../../billing/enums/payment-method-type";
import { PaymentMethodType } from "../../billing/enums";
export class IapCheckRequest {
paymentMethodType: PaymentMethodType;

View File

@@ -1,10 +1,10 @@
import { CipherRequest } from "../../vault/models/request/cipher.request";
import { FolderRequest } from "../../vault/models/request/folder.request";
import { FolderWithIdRequest } from "../../vault/models/request/folder-with-id.request";
import { KvpRequest } from "./kvp.request";
export class ImportCiphersRequest {
ciphers: CipherRequest[] = [];
folders: FolderRequest[] = [];
folders: FolderWithIdRequest[] = [];
folderRelationships: KvpRequest<number, number>[] = [];
}

View File

@@ -1,10 +1,10 @@
import { CollectionRequest } from "../../admin-console/models/request/collection.request";
import { CollectionWithIdRequest } from "../../admin-console/models/request/collection-with-id.request";
import { CipherRequest } from "../../vault/models/request/cipher.request";
import { KvpRequest } from "./kvp.request";
export class ImportOrganizationCiphersRequest {
ciphers: CipherRequest[] = [];
collections: CollectionRequest[] = [];
collections: CollectionWithIdRequest[] = [];
collectionRelationships: KvpRequest<number, number>[] = [];
}

View File

@@ -1,5 +1,5 @@
import { PasswordRequest } from "../../auth/models/request/password.request";
import { KdfType } from "../../enums/kdfType";
import { KdfType } from "../../enums";
export class KdfRequest extends PasswordRequest {
kdf: KdfType;

View File

@@ -1,5 +1,5 @@
import { CaptchaProtectedRequest } from "../../auth/models/request/captcha-protected.request";
import { KdfType } from "../../enums/kdfType";
import { KdfType } from "../../enums";
import { KeysRequest } from "./keys.request";
import { ReferenceEventRequest } from "./reference-event.request";

View File

@@ -1,6 +1,4 @@
import { DeviceType } from "../../enums/deviceType";
import { EventSystemUser } from "../../enums/event-system-user";
import { EventType } from "../../enums/eventType";
import { DeviceType, EventSystemUser, EventType } from "../../enums";
import { BaseResponse } from "./base.response";

View File

@@ -1,4 +1,4 @@
import { NotificationType } from "../../enums/notificationType";
import { NotificationType } from "../../enums";
import { BaseResponse } from "./base.response";

View File

@@ -5,6 +5,7 @@ export class ServerConfigResponse extends BaseResponse {
gitHash: string;
server: ThirdPartyServerConfigResponse;
environment: EnvironmentServerConfigResponse;
featureStates: { [key: string]: string } = {};
constructor(response: any) {
super(response);
@@ -17,6 +18,7 @@ export class ServerConfigResponse extends BaseResponse {
this.gitHash = this.getResponseProperty("GitHash");
this.server = new ThirdPartyServerConfigResponse(this.getResponseProperty("Server"));
this.environment = new EnvironmentServerConfigResponse(this.getResponseProperty("Environment"));
this.featureStates = this.getResponseProperty("FeatureStates");
}
}

View File

@@ -1,5 +1,4 @@
import { EventSystemUser } from "../../enums/event-system-user";
import { EventType } from "../../enums/eventType";
import { EventSystemUser, EventType } from "../../enums";
export class EventView {
message: string;