diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-12-19 12:05:53 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-12-19 12:05:53 -0200 |
commit | e3273d8ead6ee0da307097febeb27a38e8cc3593 (patch) | |
tree | 44d4677fc051daa7a3c41cdf2026651de9d8b61b /lib/keyringer/actions | |
parent | 85c61ed6857676f4ca259ff73845f3d3c6dab7d2 (diff) | |
download | keyringer-e3273d8ead6ee0da307097febeb27a38e8cc3593.tar.gz keyringer-e3273d8ead6ee0da307097febeb27a38e8cc3593.tar.bz2 |
Adds pwgen action
Diffstat (limited to 'lib/keyringer/actions')
-rwxr-xr-x | lib/keyringer/actions/pwgen | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/keyringer/actions/pwgen b/lib/keyringer/actions/pwgen new file mode 100755 index 0000000..45d2bf9 --- /dev/null +++ b/lib/keyringer/actions/pwgen @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Generates passphrases. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Parameters +SIZE="$3" +FILE="$2" + +# Generates a random passphrase +function keyringer_pwgen { + ENTROPY_BYTES=${1:-20} # in bytes + ENTROPY_SOURCE="${ENTROPY_SOURCE:-/dev/urandom}" + + # Strip possible newlines if output is wrapped. + # Also strip trailing = signs as they add nothing to the password's entropy. + head -c $ENTROPY_BYTES $ENTROPY_SOURCE | base64 | tr -d '\n=' + echo +} + +# Check +if [ -z "$FILE" ]; then + echo "Usage: keyringer <keyring> $BASENAME <secret> [size]" + exit 1 +elif [ ! -z "$SIZE" ] && ! echo $SIZE | egrep -q '^[0-9]+$'; then + echo "$SIZE is not a number" + exit 1 +fi + +# Encrypt and store a randomly-generated secret +keyringer_pwgen $SIZE | keyringer_exec encrypt "$BASEDIR" "$FILE" |