1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

update key api changes

This commit is contained in:
Kyle Spearrin 2018-07-17 17:22:45 -04:00
parent 3354f0b818
commit f35ecf0cd8
8 changed files with 39 additions and 6 deletions

View File

@ -35,6 +35,7 @@ import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
import { TwoFactorProviderRequest } from '../models/request/twoFactorProviderRequest';
import { TwoFactorRecoveryRequest } from '../models/request/twoFactorRecoveryRequest';
import { UpdateDomainsRequest } from '../models/request/updateDomainsRequest';
import { UpdateKeyRequest } from '../models/request/updateKeyRequest';
import { UpdateProfileRequest } from '../models/request/updateProfileRequest';
import { UpdateTwoFactorAuthenticatorRequest } from '../models/request/updateTwoFactorAuthenticatorRequest';
import { UpdateTwoFactorDuoRequest } from '../models/request/updateTwoFactorDuoRequest';
@ -106,6 +107,7 @@ export abstract class ApiService {
postAccountStorage: (request: StorageRequest) => Promise<any>;
postAccountPayment: (request: PaymentRequest) => Promise<any>;
postAccountLicense: (data: FormData) => Promise<any>;
postAccountKey: (request: UpdateKeyRequest) => Promise<any>;
postAccountKeys: (request: KeysRequest) => Promise<any>;
postAccountVerifyEmail: () => Promise<any>;
postAccountVerifyEmailToken: (request: VerifyEmailRequest) => Promise<any>;

View File

@ -14,7 +14,7 @@ export abstract class CipherService {
decryptedCipherCache: CipherView[];
clearCache: () => void;
encrypt: (model: CipherView) => Promise<Cipher>;
encrypt: (model: CipherView, key?: SymmetricCryptoKey) => Promise<Cipher>;
encryptFields: (fieldsModel: FieldView[], key: SymmetricCryptoKey) => Promise<Field[]>;
encryptField: (fieldModel: FieldView, key: SymmetricCryptoKey) => Promise<Field>;
get: (id: string) => Promise<Cipher>;

View File

@ -1,6 +1,7 @@
import { FolderData } from '../models/data/folderData';
import { Folder } from '../models/domain/folder';
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
import { FolderView } from '../models/view/folderView';
@ -8,7 +9,7 @@ export abstract class FolderService {
decryptedFolderCache: FolderView[];
clearCache: () => void;
encrypt: (model: FolderView) => Promise<Folder>;
encrypt: (model: FolderView, key?: SymmetricCryptoKey) => Promise<Folder>;
get: (id: string) => Promise<Folder>;
getAll: () => Promise<Folder[]>;
getAllDecrypted: () => Promise<FolderView[]>;

View File

@ -0,0 +1,12 @@
import { FolderRequest } from './folderRequest';
import { Folder } from '../domain/folder';
export class FolderWithIdRequest extends FolderRequest {
id: string;
constructor(folder: Folder) {
super(folder);
this.id = folder.id;
}
}

View File

@ -0,0 +1,10 @@
import { CipherWithIdRequest } from './cipherWithIdRequest';
import { FolderWithIdRequest } from './folderWithIdRequest';
export class UpdateKeyRequest {
ciphers: CipherWithIdRequest[] = [];
folders: FolderWithIdRequest[] = [];
masterPasswordHash: string;
privateKey: string;
key: string;
}

View File

@ -41,6 +41,7 @@ import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
import { TwoFactorProviderRequest } from '../models/request/twoFactorProviderRequest';
import { TwoFactorRecoveryRequest } from '../models/request/twoFactorRecoveryRequest';
import { UpdateDomainsRequest } from '../models/request/updateDomainsRequest';
import { UpdateKeyRequest } from '../models/request/updateKeyRequest';
import { UpdateProfileRequest } from '../models/request/updateProfileRequest';
import { UpdateTwoFactorAuthenticatorRequest } from '../models/request/updateTwoFactorAuthenticatorRequest';
import { UpdateTwoFactorDuoRequest } from '../models/request/updateTwoFactorDuoRequest';
@ -256,6 +257,10 @@ export class ApiService implements ApiServiceAbstraction {
return this.send('POST', '/accounts/keys', request, true, false);
}
postAccountKey(request: UpdateKeyRequest): Promise<any> {
return this.send('POST', '/accounts/key', request, true, false);
}
postAccountVerifyEmail(): Promise<any> {
return this.send('POST', '/accounts/verify-email', null, true, false);
}

View File

@ -60,7 +60,7 @@ export class CipherService implements CipherServiceAbstraction {
this.decryptedCipherCache = null;
}
async encrypt(model: CipherView): Promise<Cipher> {
async encrypt(model: CipherView, key?: SymmetricCryptoKey): Promise<Cipher> {
const cipher = new Cipher();
cipher.id = model.id;
cipher.folderId = model.folderId;
@ -69,7 +69,9 @@ export class CipherService implements CipherServiceAbstraction {
cipher.type = model.type;
cipher.collectionIds = model.collectionIds;
const key = await this.cryptoService.getOrgKey(cipher.organizationId);
if (key == null && cipher.organizationId != null) {
key = await this.cryptoService.getOrgKey(cipher.organizationId);
}
await Promise.all([
this.encryptObjProperty(model, cipher, {
name: null,

View File

@ -1,6 +1,7 @@
import { FolderData } from '../models/data/folderData';
import { Folder } from '../models/domain/folder';
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
import { FolderRequest } from '../models/request/folderRequest';
@ -35,10 +36,10 @@ export class FolderService implements FolderServiceAbstraction {
this.decryptedFolderCache = null;
}
async encrypt(model: FolderView): Promise<Folder> {
async encrypt(model: FolderView, key?: SymmetricCryptoKey): Promise<Folder> {
const folder = new Folder();
folder.id = model.id;
folder.name = await this.cryptoService.encrypt(model.name);
folder.name = await this.cryptoService.encrypt(model.name, key);
return folder;
}