mirror of
https://github.com/bitwarden/browser
synced 2026-01-03 09:03:32 +00:00
Add send to cli (#253)
* Upgrade commander to 7.0.0 * Add url to Api call This is needed to allow access to sends that are available from a different Bitwarden server than configured for the CLI * Allow upload of send files from CLI * Allow send search by accessId * Utils methods used in Send CLI implementation * Revert adding string type to encrypted file data * linter fixes * Add Buffer to ArrayBuffer used in CLI send implementation
This commit is contained in:
@@ -73,6 +73,7 @@ import { VerifyBankRequest } from '../models/request/verifyBankRequest';
|
||||
import { VerifyDeleteRecoverRequest } from '../models/request/verifyDeleteRecoverRequest';
|
||||
import { VerifyEmailRequest } from '../models/request/verifyEmailRequest';
|
||||
|
||||
import { Utils } from '../misc/utils';
|
||||
import { ApiKeyResponse } from '../models/response/apiKeyResponse';
|
||||
import { BillingResponse } from '../models/response/billingResponse';
|
||||
import { BreachAccountResponse } from '../models/response/breachAccountResponse';
|
||||
@@ -410,8 +411,8 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
return new SendResponse(r);
|
||||
}
|
||||
|
||||
async postSendAccess(id: string, request: SendAccessRequest): Promise<SendAccessResponse> {
|
||||
const r = await this.send('POST', '/sends/access/' + id, request, false, true);
|
||||
async postSendAccess(id: string, request: SendAccessRequest, apiUrl?: string): Promise<SendAccessResponse> {
|
||||
const r = await this.send('POST', '/sends/access/' + id, request, false, true, apiUrl);
|
||||
return new SendAccessResponse(r);
|
||||
}
|
||||
|
||||
@@ -1210,7 +1211,8 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
}
|
||||
|
||||
private async send(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body: any,
|
||||
authed: boolean, hasResponse: boolean): Promise<any> {
|
||||
authed: boolean, hasResponse: boolean, apiUrl?: string): Promise<any> {
|
||||
apiUrl = Utils.isNullOrWhitespace(apiUrl) ? this.apiBaseUrl : apiUrl;
|
||||
const headers = new Headers({
|
||||
'Device-Type': this.deviceType,
|
||||
});
|
||||
@@ -1246,7 +1248,7 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
}
|
||||
|
||||
requestInit.headers = headers;
|
||||
const response = await this.fetch(new Request(this.apiBaseUrl + path, requestInit));
|
||||
const response = await this.fetch(new Request(apiUrl + path, requestInit));
|
||||
|
||||
if (hasResponse && response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
|
||||
@@ -169,7 +169,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
if (s.name != null && s.name.toLowerCase().indexOf(query) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (query.length >= 8 && (s.id.startsWith(query) || (s.file?.id != null && s.file.id.startsWith(query)))) {
|
||||
if (query.length >= 8 && (s.id.startsWith(query) || s.accessId.toLocaleLowerCase().startsWith(query) || (s.file?.id != null && s.file.id.startsWith(query)))) {
|
||||
return true;
|
||||
}
|
||||
if (s.notes != null && s.notes.toLowerCase().indexOf(query) > -1) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import { StorageService } from '../abstractions/storage.service';
|
||||
import { UserService } from '../abstractions/user.service';
|
||||
|
||||
import { Utils } from '../misc/utils';
|
||||
import { CipherString } from '../models/domain';
|
||||
|
||||
const Keys = {
|
||||
sendsPrefix: 'sends_',
|
||||
@@ -38,7 +39,7 @@ export class SendService implements SendServiceAbstraction {
|
||||
this.decryptedSendCache = null;
|
||||
}
|
||||
|
||||
async encrypt(model: SendView, file: File, password: string,
|
||||
async encrypt(model: SendView, file: File | ArrayBuffer, password: string,
|
||||
key?: SymmetricCryptoKey): Promise<[Send, ArrayBuffer]> {
|
||||
let fileData: ArrayBuffer = null;
|
||||
const send = new Send();
|
||||
@@ -64,7 +65,13 @@ export class SendService implements SendServiceAbstraction {
|
||||
} else if (send.type === SendType.File) {
|
||||
send.file = new SendFile();
|
||||
if (file != null) {
|
||||
fileData = await this.parseFile(send, file, model.cryptoKey);
|
||||
if (file instanceof ArrayBuffer) {
|
||||
const [name, data] = await this.encryptFileData(model.file.fileName, file, model.cryptoKey);
|
||||
send.file.fileName = name;
|
||||
fileData = data;
|
||||
} else {
|
||||
fileData = await this.parseFile(send, file, model.cryptoKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,9 +234,9 @@ export class SendService implements SendServiceAbstraction {
|
||||
reader.readAsArrayBuffer(file);
|
||||
reader.onload = async (evt) => {
|
||||
try {
|
||||
send.file.fileName = await this.cryptoService.encrypt(file.name, key);
|
||||
const fileData = await this.cryptoService.encryptToBytes(evt.target.result as ArrayBuffer, key);
|
||||
resolve(fileData);
|
||||
const [name, data] = await this.encryptFileData(file.name, evt.target.result as ArrayBuffer, key);
|
||||
send.file.fileName = name;
|
||||
resolve(data);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
@@ -239,4 +246,11 @@ export class SendService implements SendServiceAbstraction {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private async encryptFileData(fileName: string, data: ArrayBuffer,
|
||||
key: SymmetricCryptoKey): Promise<[CipherString, ArrayBuffer]> {
|
||||
const encFileName = await this.cryptoService.encrypt(fileName, key);
|
||||
const encFileData = await this.cryptoService.encryptToBytes(data, key);
|
||||
return [encFileName, encFileData];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user