Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-2582] Moved code to cipher service #5818

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions libs/angular/src/vault/components/attachments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,6 @@ export class AttachmentsComponent implements OnInit {
}

protected async saveCipherAttachment(file: File) {
//if cipher key encryption is disabled but the item has an individual key,
//then we rollback to using the user key as the main key of encryption of the item
//in order to keep item and it's attachments with the same encryption level
if (
this.cipherDomain.key != null &&
!(await this.cipherService.getCipherKeyEncryptionEnabled())
) {
const model = await this.cipherDomain.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(this.cipherDomain)
);
this.cipherDomain = await this.cipherService.encrypt(model);
await this.cipherService.updateWithServer(this.cipherDomain);
}

return this.cipherService.saveAttachmentWithServer(this.cipherDomain, file);
}

Expand Down
13 changes: 12 additions & 1 deletion libs/common/src/vault/services/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,22 @@ export class CipherService implements CipherServiceAbstraction {
admin = false
): Promise<Cipher> {
const key = await this.getKeyForCipherKeyDecryption(cipher);
const cipherKeyEncryptionEnabled = await this.getCipherKeyEncryptionEnabled();

const cipherEncKey =
(await this.getCipherKeyEncryptionEnabled()) && cipher.key != null
cipherKeyEncryptionEnabled && cipher.key != null
? new SymmetricCryptoKey(await this.encryptService.decryptToBytes(cipher.key, key))
: key;

//if cipher key encryption is disabled but the item has an individual key,
//then we rollback to using the user key as the main key of encryption of the item
//in order to keep item and it's attachments with the same encryption level
if (cipher.key != null && !cipherKeyEncryptionEnabled) {
const model = await cipher.decrypt(await this.getKeyForCipherKeyDecryption(cipher));
cipher = await this.encrypt(model);
await this.updateWithServer(cipher);
}

const encFileName = await this.cryptoService.encrypt(filename, cipherEncKey);

const dataEncKey = await this.cryptoService.makeEncKey(cipherEncKey);
Expand Down