mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-08 19:18:02 +01:00
password is not needed for import
This commit is contained in:
parent
fdc116c957
commit
e3c2be9e84
2
jslib
2
jslib
@ -1 +1 @@
|
||||
Subproject commit d56c5ff4f157b346500ceb0c256e88daaf4c4684
|
||||
Subproject commit f16fc58d707b9ed55355e62440fb95185f972090
|
@ -1,6 +1,4 @@
|
||||
import * as program from 'commander';
|
||||
import * as inquirer from 'inquirer';
|
||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { ImportService } from 'jslib/abstractions/import.service';
|
||||
|
||||
import { Response } from '../models/response';
|
||||
@ -9,41 +7,23 @@ import { MessageResponse } from '../models/response/messageResponse';
|
||||
import { CliUtils } from '../utils';
|
||||
|
||||
export class ImportCommand {
|
||||
constructor(private cryptoService: CryptoService, private importService: ImportService) { }
|
||||
constructor(private importService: ImportService) { }
|
||||
|
||||
async run(format: string, filepath: string, password: string, cmd: program.Command): Promise<Response> {
|
||||
async run(format: string, filepath: string, cmd: program.Command): Promise<Response> {
|
||||
if (cmd.formats || false) {
|
||||
return this.list();
|
||||
} else {
|
||||
return this.import(format, filepath, password);
|
||||
return this.import(format, filepath);
|
||||
}
|
||||
}
|
||||
|
||||
private async import(format: string, filepath: string, password: string) {
|
||||
private async import(format: string, filepath: string) {
|
||||
if (format == null || format === '') {
|
||||
return Response.badRequest('`format` was not provided.');
|
||||
}
|
||||
if (filepath == null || filepath === '') {
|
||||
return Response.badRequest('`filepath` was not provided.');
|
||||
}
|
||||
if (password == null || password === '') {
|
||||
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
||||
type: 'password',
|
||||
name: 'password',
|
||||
message: 'Master password:',
|
||||
mask: '*',
|
||||
});
|
||||
password = answer.password;
|
||||
}
|
||||
if (password == null || password === '') {
|
||||
return Response.badRequest('Master password is required.');
|
||||
}
|
||||
|
||||
const keyHash = await this.cryptoService.hashPassword(password, null);
|
||||
const storedKeyHash = await this.cryptoService.getKeyHash();
|
||||
if (storedKeyHash == null || keyHash == null || storedKeyHash !== keyHash) {
|
||||
return Response.badRequest('Invalid master password.');
|
||||
}
|
||||
|
||||
const importer = await this.importService.getImporter(format, false);
|
||||
if (importer === null) {
|
||||
|
@ -371,7 +371,7 @@ export class Program {
|
||||
});
|
||||
|
||||
program
|
||||
.command('import [format] [input] [password]')
|
||||
.command('import [format] [input]')
|
||||
.description('Import vault data from a file.')
|
||||
.option('--formats', 'List formats')
|
||||
.on('--help', () => {
|
||||
@ -379,12 +379,12 @@ export class Program {
|
||||
writeLn('');
|
||||
writeLn(' bw import --formats');
|
||||
writeLn(' bw import bitwardencsv ./from/source.csv');
|
||||
writeLn(' bw import keepass2xml keepass_backup.xml myPassword123');
|
||||
writeLn(' bw import keepass2xml keepass_backup.xml');
|
||||
})
|
||||
.action(async (format, filepath, password, cmd) => {
|
||||
.action(async (format, filepath, cmd) => {
|
||||
await this.exitIfLocked();
|
||||
const command = new ImportCommand(this.main.cryptoService, this.main.importService);
|
||||
const response = await command.run(format, filepath, password, cmd);
|
||||
const command = new ImportCommand(this.main.importService);
|
||||
const response = await command.run(format, filepath, cmd);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user