1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-02 08:40:08 +01:00

Enable alternative ways for settings passwords (#101)

* Enable alternative ways for settings passwords:
* the environment variable BW_PASSWORD
* prefix the command line argument with "file:" and the password will read from the first line of that file
* prefix the command line argument with "env:" and the password will be read from that environment variable

* Appveyor fixes

* Switch to using command options for password file and password env

* Lowercase options
This commit is contained in:
Pasi Niemi 2020-05-08 17:38:28 +03:00 committed by GitHub
parent 0092aac275
commit fb7335b927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 7 deletions

View File

@ -14,6 +14,8 @@ import { Response } from '../models/response';
import { MessageResponse } from '../models/response/messageResponse';
import { NodeUtils } from '../../misc/nodeUtils';
export class LoginCommand {
protected validatedParams: () => Promise<any>;
protected success: () => Promise<MessageResponse>;
@ -38,14 +40,21 @@ export class LoginCommand {
return Response.badRequest('Email address is invalid.');
}
if ((password == null || password === '') && 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 === '') {
if (cmd.passwordfile) {
password = await NodeUtils.readFirstLine(cmd.passwordfile);
} else if (cmd.passwordenv && process.env[cmd.passwordenv]) {
password = process.env[cmd.passwordenv];
} else 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 === '') {
return Response.badRequest('Master password is required.');
}

View File

@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
export class NodeUtils {
static mkdirpSync(targetDir: string, mode = '700', relative = false, relativeDir: string = null) {
@ -13,4 +14,16 @@ export class NodeUtils {
return dir;
}, initialDir);
}
static readFirstLine(fileName: string) {
return new Promise<string>((resolve, reject) => {
const readStream = fs.createReadStream(fileName, {encoding: 'utf8'});
const readInterface = readline.createInterface(readStream);
readInterface
.on('line', (line) => {
readStream.close();
resolve(line);
})
.on('error', (err) => reject(err));
});
}
}