mirror of
https://github.com/bitwarden/browser
synced 2026-02-06 19:53:59 +00:00
* Created mappings for client domain object to SDK * Add abstract decrypt observable * Added todo for future consideration * Added implementation to cipher service * Added adapter and unit tests * Created cipher encryption abstraction and service * Register cipher encryption service * Added tests for the cipher encryption service * changed signature * Updated feature flag name * added new function to be used for decrypting ciphers * Added new encryptedKey field * added new function to be used for decrypting ciphers * Manually set fields * Added encrypted key in attachment view * Fixed test * Updated references to use decrypt with feature flag * Added dependency * updated package.json * lint fix * fixed tests * Fixed small mapping issues * Fixed test * Added function to decrypt fido2 key value * Added function to decrypt fido2 key value and updated test * updated to use sdk function without prociding the key * updated localdata sdk type change * decrypt attachment content using sdk * Fixed dependency issues * updated package.json * Refactored service to handle getting decrypted buffer using the legacy and sdk implementations * updated services and component to use refactored version * Updated decryptCiphersWithSdk to use decryptManyLegacy for batch decryption, ensuring the SDK is only called once per batch * Fixed merge conflicts * Fixed merge conflicts * Fixed merge conflicts * Fixed lint issues * Moved getDecryptedAttachmentBuffer to cipher service * Moved getDecryptedAttachmentBuffer to cipher service * ensure CipherView properties are null instead of undefined * Fixed test * ensure AttachmentView properties are null instead of undefined * Linked ticket in comment * removed unused orgKey
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { firstValueFrom } from "rxjs";
|
|
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
|
|
import { Response } from "../../models/response";
|
|
import { CliUtils } from "../../utils";
|
|
import { CipherResponse } from "../../vault/models/cipher.response";
|
|
|
|
export class ShareCommand {
|
|
constructor(
|
|
private cipherService: CipherService,
|
|
private accountService: AccountService,
|
|
) {}
|
|
|
|
async run(id: string, organizationId: string, requestJson: string): Promise<Response> {
|
|
if (process.env.BW_SERVE !== "true" && (requestJson == null || requestJson === "")) {
|
|
requestJson = await CliUtils.readStdin();
|
|
}
|
|
|
|
if (requestJson == null || requestJson === "") {
|
|
return Response.badRequest("`requestJson` was not provided.");
|
|
}
|
|
|
|
let req: string[] = [];
|
|
if (typeof requestJson !== "string") {
|
|
req = requestJson;
|
|
} else {
|
|
try {
|
|
const reqJson = Buffer.from(requestJson, "base64").toString();
|
|
req = JSON.parse(reqJson);
|
|
if (req == null || req.length === 0) {
|
|
return Response.badRequest("You must provide at least one collection id for this item.");
|
|
}
|
|
// FIXME: Remove when updating file. Eslint update
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
} catch (e) {
|
|
return Response.badRequest("Error parsing the encoded request data.");
|
|
}
|
|
}
|
|
|
|
if (id != null) {
|
|
id = id.toLowerCase();
|
|
}
|
|
if (organizationId != null) {
|
|
organizationId = organizationId.toLowerCase();
|
|
}
|
|
|
|
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
|
|
|
const cipher = await this.cipherService.get(id, activeUserId);
|
|
if (cipher == null) {
|
|
return Response.notFound();
|
|
}
|
|
if (cipher.organizationId != null) {
|
|
return Response.badRequest("This item already belongs to an organization.");
|
|
}
|
|
|
|
const cipherView = await this.cipherService.decrypt(cipher, activeUserId);
|
|
try {
|
|
await this.cipherService.shareWithServer(cipherView, organizationId, req, activeUserId);
|
|
const updatedCipher = await this.cipherService.get(cipher.id, activeUserId);
|
|
const decCipher = await this.cipherService.decrypt(updatedCipher, activeUserId);
|
|
const res = new CipherResponse(decCipher);
|
|
return Response.success(res);
|
|
} catch (e) {
|
|
return Response.error(e);
|
|
}
|
|
}
|
|
}
|