1
1
#! /usr/bin/env bash
2
2
3
- # Copyright (C) 2012 - 2014 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
3
+ # Copyright (C) 2012 - 2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4
4
# This file is licensed under the GPLv2+. Please see COPYING for more information.
5
5
6
6
umask " ${PASSWORD_STORE_UMASK:- 077} "
@@ -16,6 +16,8 @@ PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
16
16
X_SELECTION=" ${PASSWORD_STORE_X_SELECTION:- clipboard} "
17
17
CLIP_TIME=" ${PASSWORD_STORE_CLIP_TIME:- 45} "
18
18
GENERATED_LENGTH=" ${PASSWORD_STORE_GENERATED_LENGTH:- 25} "
19
+ CHARACTER_SET=" ${PASSWORD_STORE_CHARACTER_SET:- [:graph:]} "
20
+ CHARACTER_SET_NO_SYMBOLS=" ${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:- [:alnum:]} "
19
21
20
22
export GIT_DIR=" ${PASSWORD_STORE_GIT:- $PREFIX } /.git"
21
23
export GIT_WORK_TREE=" ${PASSWORD_STORE_GIT:- $PREFIX } "
@@ -431,12 +433,12 @@ cmd_edit() {
431
433
}
432
434
433
435
cmd_generate () {
434
- local opts clip=0 force=0 symbols= " -y " inplace=0
436
+ local opts clip=0 force=0 characters= " $CHARACTER_SET " inplace=0 pass
435
437
opts=" $( $GETOPT -o ncif -l no-symbols,clip,in-place,force -n " $PROGRAM " -- " $@ " ) "
436
438
local err=$?
437
439
eval set -- " $opts "
438
440
while true ; do case $1 in
439
- -n|--no-symbols) symbols= " " ; shift ;;
441
+ -n|--no-symbols) characters= " $CHARACTER_SET_NO_SYMBOLS " ; shift ;;
440
442
-c|--clip) clip=1; shift ;;
441
443
-f|--force) force=1; shift ;;
442
444
-i|--in-place) inplace=1; shift ;;
@@ -454,8 +456,8 @@ cmd_generate() {
454
456
455
457
[[ $inplace -eq 0 && $force -eq 0 && -e $passfile ]] && yesno " An entry already exists for $path . Overwrite it?"
456
458
457
- local pass= " $( pwgen -s $symbols $length 1 ) "
458
- [[ -n $pass ]] || exit 1
459
+ read -r -n $length pass < <( LC_ALL=C tr -dc " $characters " < /dev/urandom )
460
+ [[ ${ # pass} -eq $length ]] || die " Could not generate password from /dev/urandom. "
459
461
if [[ $inplace -eq 0 ]]; then
460
462
$GPG -e " ${GPG_RECIPIENT_ARGS[@]} " -o " $passfile " " ${GPG_OPTS[@]} " <<< " $pass" || die " Password encryption aborted."
461
463
else
0 commit comments