support for attachment key on get

This commit is contained in:
Kyle Spearrin 2018-12-07 21:55:32 -05:00
parent 89dfa4e4f8
commit 2bc488b956
2 changed files with 15 additions and 6 deletions

2
jslib

@ -1 +1 @@
Subproject commit 739d308498ab68df3e37772265733c81b27f2cc2
Subproject commit 9283a29d35a18f058f3c84f8aaa919b911f1940a

View File

@ -84,7 +84,7 @@ export class GetCommand {
}
}
private async getCipher(id: string) {
private async getCipherView(id: string): Promise<CipherView | string[]> {
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);