1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 22:33:35 +00:00

password is not needed for import

This commit is contained in:
Kyle Spearrin
2018-08-16 14:43:12 -04:00
parent fdc116c957
commit e3c2be9e84
3 changed files with 10 additions and 30 deletions

2
jslib

Submodule jslib updated: d56c5ff4f1...f16fc58d70

View File

@@ -1,6 +1,4 @@
import * as program from 'commander'; 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 { ImportService } from 'jslib/abstractions/import.service';
import { Response } from '../models/response'; import { Response } from '../models/response';
@@ -9,41 +7,23 @@ import { MessageResponse } from '../models/response/messageResponse';
import { CliUtils } from '../utils'; import { CliUtils } from '../utils';
export class ImportCommand { 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) { if (cmd.formats || false) {
return this.list(); return this.list();
} else { } 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 === '') { if (format == null || format === '') {
return Response.badRequest('`format` was not provided.'); return Response.badRequest('`format` was not provided.');
} }
if (filepath == null || filepath === '') { if (filepath == null || filepath === '') {
return Response.badRequest('`filepath` was not provided.'); 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); const importer = await this.importService.getImporter(format, false);
if (importer === null) { if (importer === null) {

View File

@@ -371,7 +371,7 @@ export class Program {
}); });
program program
.command('import [format] [input] [password]') .command('import [format] [input]')
.description('Import vault data from a file.') .description('Import vault data from a file.')
.option('--formats', 'List formats') .option('--formats', 'List formats')
.on('--help', () => { .on('--help', () => {
@@ -379,12 +379,12 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw import --formats'); writeLn(' bw import --formats');
writeLn(' bw import bitwardencsv ./from/source.csv'); 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(); await this.exitIfLocked();
const command = new ImportCommand(this.main.cryptoService, this.main.importService); const command = new ImportCommand(this.main.importService);
const response = await command.run(format, filepath, password, cmd); const response = await command.run(format, filepath, cmd);
this.processResponse(response); this.processResponse(response);
}); });