1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00

--passwordenv doesn't work for for unlock (#347)

* - Add passwordenv parameter to unlock command
- Add passwordfile parameter to unlock command
- Adapt help message

* Remove newline

* Add warning if passwordenv var not found

* Appease the linter

* Refactor

* Undo last commit
This commit is contained in:
Philip Kaiser 2021-07-02 22:04:07 +02:00 committed by GitHub
parent 4656b6e383
commit 47308ef240
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 12 deletions

View File

@ -14,24 +14,44 @@ import { PasswordVerificationRequest } from 'jslib-common/models/request/passwor
import { Utils } from 'jslib-common/misc/utils';
import { HashPurpose } from 'jslib-common/enums/hashPurpose';
import { NodeUtils } from 'jslib-common/misc/nodeUtils';
import { ConsoleLogService } from 'jslib-common/services/consoleLog.service';
export class UnlockCommand {
constructor(private cryptoService: CryptoService, private userService: UserService,
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) { }
private logService: ConsoleLogService;
async run(password: string, cmd: program.Command) {
constructor(private cryptoService: CryptoService, private userService: UserService,
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) {
this.logService = new ConsoleLogService(false);
}
async run(password: string, options: program.OptionValues) {
const canInteract = process.env.BW_NOINTERACTION !== 'true';
if ((password == null || password === '') && canInteract) {
if (password == null || password === '') {
if (options.passwordfile) {
password = await NodeUtils.readFirstLine(options.passwordfile);
} else if (options.passwordenv) {
if (process.env[options.passwordenv]) {
password = process.env[options.passwordenv];
} else {
this.logService.warning(`Warning: Provided passwordenv ${options.passwordenv} is not set`);
}
}
}
if (password == null || password === '') {
if (canInteract) {
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
type: 'password',
name: 'password',
message: 'Master password:',
});
password = answer.password;
}
if (password == null || password === '') {
} else {
return Response.badRequest('Master password is required.');
}
}
this.setNewSessionKey();
const email = await this.userService.getEmail();

View File

@ -202,6 +202,8 @@ export class Program extends BaseProgram {
}
this.processResponse(Response.error('Vault is locked.'), true);
})
.option('--passwordenv <passwordenv>', 'Environment variable storing your password')
.option('--passwordfile <passwordfile>', 'Path to a file containing your password as its first line')
.action(async (password, cmd) => {
if (!cmd.check) {
await this.exitIfNotAuthed();