1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Direct download for send (#243)

* Remove Get file capability

This needs to be removed because the SendFileResponse no longer contains
a url to download the file from. Instead, a GetDownloadLink method
must be used. That method increments access count, which is not
desirable for the owner of the Send. The cleanest approach is to remove
the capability, which also matches Web client's behavior

* jslib updates

* Use GetDownloadData method to receive download Url

* Update jslib
This commit is contained in:
Matt Gibson
2021-03-02 10:05:20 -06:00
committed by GitHub
parent e77e1c94e8
commit fcd0c529ca
7 changed files with 15 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
import * as program from 'commander';
import { ApiService } from 'jslib/abstractions/api.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { SearchService } from 'jslib/abstractions/search.service';
@@ -40,12 +41,6 @@ export class SendGetCommand extends DownloadCommand {
return Response.success();
};
}
if (options.file != null) {
filter = s => {
return filter(s) && s.file != null && s.file.url != null;
};
selector = async s => await this.saveAttachmentToFile(s.file.url, s.cryptoKey, s.file.fileName, options.output);
}
if (Array.isArray(sends)) {
if (filter != null) {

View File

@@ -28,6 +28,7 @@ import { DownloadCommand } from '../download.command';
export class SendReceiveCommand extends DownloadCommand {
private canInteract: boolean;
private decKey: SymmetricCryptoKey;
private sendAccessRequest: SendAccessRequest;
constructor(private apiService: ApiService, cryptoService: CryptoService,
private cryptoFunctionService: CryptoFunctionService, private platformUtilsService: PlatformUtilsService,
@@ -53,7 +54,7 @@ export class SendReceiveCommand extends DownloadCommand {
}
const keyArray = Utils.fromUrlB64ToArray(key);
const request = new SendAccessRequest();
this.sendAccessRequest = new SendAccessRequest();
let password = options.password;
if (password == null || password === '') {
@@ -65,10 +66,10 @@ export class SendReceiveCommand extends DownloadCommand {
}
if (password != null && password !== '') {
request.password = await this.getUnlockedPassword(password, keyArray);
this.sendAccessRequest.password = await this.getUnlockedPassword(password, keyArray);
}
const response = await this.sendRequest(request, apiUrl, id, keyArray);
const response = await this.sendRequest(apiUrl, id, keyArray);
if (response instanceof Response) {
// Error scenario
@@ -85,7 +86,8 @@ export class SendReceiveCommand extends DownloadCommand {
process.stdout.write(response?.text?.text);
return Response.success();
case SendType.File:
return await this.saveAttachmentToFile(response?.file?.url, this.decKey, response?.file?.fileName, options.output);
const downloadData = await this.apiService.getSendFileDownloadData(response, this.sendAccessRequest);
return await this.saveAttachmentToFile(downloadData.url, this.decKey, response?.file?.fileName, options.output);
default:
return Response.success(new SendAccessResponse(response));
}
@@ -111,9 +113,9 @@ export class SendReceiveCommand extends DownloadCommand {
return Utils.fromBufferToB64(passwordHash);
}
private async sendRequest(request: SendAccessRequest, url: string, id: string, key: ArrayBuffer): Promise<Response | SendAccessView> {
private async sendRequest(url: string, id: string, key: ArrayBuffer): Promise<Response | SendAccessView> {
try {
const sendResponse = await this.apiService.postSendAccess(id, request, url);
const sendResponse = await this.apiService.postSendAccess(id, this.sendAccessRequest, url);
const sendAccess = new SendAccess(sendResponse);
this.decKey = await this.cryptoService.makeSendKey(key);
@@ -129,8 +131,8 @@ export class SendReceiveCommand extends DownloadCommand {
});
// reattempt with new password
request.password = await this.getUnlockedPassword(answer.password, key);
return await this.sendRequest(request, url, id, key);
this.sendAccessRequest.password = await this.getUnlockedPassword(answer.password, key);
return await this.sendRequest(url, id, key);
}
return Response.badRequest('Incorrect or missing password');