1

I'm looking at using Theodore T'so's pwgen (on linux/ubuntu) with its sha1 (-H) feature to generate passwords that I should be able to recreate later using the same file and seed.

I briefly looked to see what alternatives there might be if this particular app (pwgen in unix) is not available to me at any point. Is this a valid consideration? Is there an alternative application that will let me recreate the same password (given the same file and seed of course)?

Whilst this might to some extent be a unix/ubuntu app availability question, I want to hear from security folk on the pros and cons of this approach, hence this question on this forum.

  • What's wrong with a password manager? – Lucas Kauffman Jan 29 '14 at 18:54
2

It all depends on the context, which you do not specify. You want to be able to recreate the passwords for some reason; depending on that reason, inability to do it without a Linux machine at hand may or may not be a problem. In any case, the README file points at some ports to other systems, e.g. for Windows; moreover, chances are that the original "for Unix" pwgen could be compiled and executed without any change on a Windows machine with the help of cygwin. And you always have the option to run a VM (e.g. with Virtualbox), install a minimal Unix-like system in it, and run pwgen on that.

When you create passwords deterministically from a file and a seed (that's what the -H option does with pwgen), then the resulting passwords are no stronger than the file and seed are secret. Typically you would use the target server name as seed, and the file as a secret (that way, you can derive multiple passwords for many sites, from a master secret file); if you can keep a file secret, you might be able to keep a text file secret. That text file would simply contain your passwords so far, added with a text editor. This might be a simpler model, and it abstracts away all considerations about portability of a specific application to various platforms.

2

Implementing every option that pwgen supports is a bit of work. But you can start simulating the behavoiour of

pwgen -s -H asd -y

with a simple bash script like this

#!/bin/bash
pw_digits="0123456789";
pw_uppers="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
pw_lowers="abcdefghijklmnopqrstuvwxyz";
pw_symbols="!\"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~";
pw_ambiguous="B8G6I1l0OQDS5Z2";
pw_vowels="01aeiouyAEIOUY";

len="${1:-8}"
seed="${2:-pwgen}"
roundseed="$seed"
numpws=160

cset="${pw_digits}${pw_uppers}${pw_lowers}${pw_symbols}"
sum=""
rands=()

typeset -i idx

function reinit()
{
    sum="$( (dd if=asd bs=1 count=1024 2> /dev/null ; echo -n "$roundseed") | sha1sum | sed "s/ .*$//")"
    roundseed="$roundseed$seed"
    idx=0
    rands=($(echo $sum | sed "s/../0x& /g"))
}

reinit

for ((numpw = 0; numpw < "$numpws"; numpw++)) ; do
    valid=0
    while [[ $valid -eq 0 ]] ; do
        pw=""
        for ((char = 0; char < "$len"; char++)) ; do
            if [[ $idx -ge ${#rands[@]} ]] ; then
                reinit
            fi
            typeset -i randidx
            randidx=${rands[$idx]}
            randidx=$(( $randidx * ${#cset} / 256 ))
            pw="$pw${cset:$randidx:1}"
            idx=$(($idx+1))
        done
        if [[ "$pw" =~ [A-Z] ]] && [[ "$pw" =~ [0-9] ]] ; then
            for ((ckp = 0; ckp < ${#pw}; ckp++)) ; do
                for ((cks = 0; cks < ${#pw_symbols}; cks++)) ; do
                    [[ "${pw_symbols:$cks:1}" = "${pw:$ckp:1}" ]] && valid=1
                done
            done
        fi
    done
    echo -n "$pw "
    [[ $(($numpw % 8)) -eq 7 ]] && echo
done
[[ $(($numpw % 8)) -eq 0 ]] || echo

Of course this is way slower that in C...

You can give the number of characters per password as the first parameter and the seed as the second parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.