]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Adds pwgen action
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 19 Dec 2016 14:05:53 +0000 (12:05 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 19 Dec 2016 14:05:53 +0000 (12:05 -0200)
lib/keyringer/actions/pwgen [new file with mode: 0755]
lib/keyringer/completions/bash/keyringer
lib/keyringer/completions/zsh/_keyringer
share/man/keyringer.1.mdwn

diff --git a/lib/keyringer/actions/pwgen b/lib/keyringer/actions/pwgen
new file mode 100755 (executable)
index 0000000..45d2bf9
--- /dev/null
@@ -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"
index ccc8fb9e1f85976ebcca984bed32d86140200d4c..10b852eefe56323bd5a9b1fb9e62950e8a789fd6 100644 (file)
@@ -93,7 +93,7 @@ _keyringer() {
       recipients)
         opts="ls edit"
         ;;
-      ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip|sclip|find|mv|cp)
+      ls|tree|mkdir|encrypt|encrypt-batch|pwgen|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip|sclip|find|mv|cp)
         cur="`echo ${cur} | sed -e "s|^/*||"`" # avoid leading slash
         opts="$(bash -c "set -f && export KEYRINGER_CHECK_RECIPIENTS=false && export KEYRINGER_CHECK_VERSION=false && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)"
         ;;
@@ -128,7 +128,7 @@ _keyringer() {
         # TODO
         opts="$(_keyringer_git_complete ${prev} ${cur})"
         ;;
-      encrypt|encrypt-batch)
+      encrypt|encrypt-batch|pwgen)
         cur="$(_keyringer_path_complete ${cur})"
         opts="`compgen -o default "${cur}"`"
         ;;
index ff74933b4f6b8ac8deb3f0e414b85aac39ae41f5..756235238d7409aa5f0f62432e40cd24e1fbc5c1 100644 (file)
@@ -49,7 +49,7 @@ _keyringer() {
           recipients)
             compadd "$@" ls edit
             ;;
-          ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip|sclip|find|mv|cp)
+          ls|tree|mkdir|encrypt|encrypt-batch|pwgen|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip|sclip|find|mv|cp)
             words[4]="`echo $words[4] | sed -e "s|^/*||"`" # avoid leading slash
             compadd "$@" $(KEYRINGER_CHECK_RECIPIENTS=false KEYRINGER_CHECK_VERSION=false keyringer $words[2] ls -p -d $words[4]'*' 2> /dev/null)
             ;;
@@ -83,7 +83,7 @@ _keyringer() {
           git)
             compadd "$@" $(_keyringer_git_complete $words[4] $words[5])
             ;;
-          encrypt|encrypt-batch)
+          encrypt|encrypt-batch|pwgen)
             _files
             ;;
           *)
index 8f024d116f99e9d0e4ea21e40976ced8bc9d4216..afe7e99f8028e1c25b05ae67eff505dacc99d6b4 100644 (file)
@@ -163,6 +163,16 @@ open <*secret*>
     After the application exits, keyringer encrypts the temporary decrypted file
     again into the secret file and deletes the temporary file.
 
+pwgen <*secret*> [*size*]
+:    Generates a random passphrase and stores into *secret* pathname with optional
+     entropy size in bytes. Default size is 20.
+
+     Passphrases will be slightly bigger than size due to base64 conversion.
+
+     With this action you can generate and store a passphrase without need to see
+     it. Combined with clip or sclip action provides an hygienic way to handle
+     secrets.
+
 recrypt <*secret*>
 :   Re-encrypts a secret by decrypting it and encrypting it again. Useful when users are added
     into the recipient configuration. If no *secret* is given, all secrets in the repository