From 2bc488b95604adf9dc524cb68b9bb2609684f976 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 7 Dec 2018 21:55:32 -0500 Subject: [PATCH] support for attachment key on get --- jslib | 2 +- src/commands/get.command.ts | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/jslib b/jslib index 739d308498..9283a29d35 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 739d308498ab68df3e37772265733c81b27f2cc2 +Subproject commit 9283a29d35a18f058f3c84f8aaa919b911f1940a diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index b4c67ae403..b1cc778999 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -84,7 +84,7 @@ export class GetCommand { } } - private async getCipher(id: string) { + private async getCipherView(id: string): Promise { let decCipher: CipherView = null; if (this.isGuid(id)) { const cipher = await this.cipherService.get(id); @@ -95,16 +95,24 @@ export class GetCommand { let ciphers = await this.cipherService.getAllDecrypted(); ciphers = this.searchService.searchCiphersBasic(ciphers, id); if (ciphers.length > 1) { - return Response.multipleResults(ciphers.map((c) => c.id)); + return ciphers.map((c) => c.id); } if (ciphers.length > 0) { decCipher = ciphers[0]; } } + return decCipher; + } + + private async getCipher(id: string) { + const decCipher = await this.getCipherView(id); if (decCipher == null) { return Response.notFound(); } + if (Array.isArray(decCipher)) { + return Response.multipleResults(decCipher); + } const res = new CipherResponse(decCipher); return Response.success(res); } @@ -221,8 +229,8 @@ export class GetCommand { return cipherResponse; } - const cipher = cipherResponse.data as CipherResponse; - if (cipher.attachments == null || cipher.attachments.length === 0) { + const cipher = await this.getCipherView(itemId); + if (cipher == null || Array.isArray(cipher) || cipher.attachments.length === 0) { return Response.error('No attachments available for this item.'); } @@ -249,7 +257,8 @@ export class GetCommand { try { const buf = await response.arrayBuffer(); - const key = await this.cryptoService.getOrgKey(cipher.organizationId); + const key = attachments[0].key != null ? attachments[0].key : + await this.cryptoService.getOrgKey(cipher.organizationId); const decBuf = await this.cryptoService.decryptFromBytes(buf, key); const filePath = await CliUtils.saveFile(Buffer.from(decBuf), cmd.output, attachments[0].fileName); const res = new MessageResponse('Saved ' + filePath, null);