From 60603e9479414a67f96849f99851ef2749693f49 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 12:52:56 -0200 Subject: Initial implementation for keyringer shell (#34) --- lib/keyringer/actions/shell | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 lib/keyringer/actions/shell (limited to 'lib') diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell new file mode 100755 index 0000000..c70d6bb --- /dev/null +++ b/lib/keyringer/actions/shell @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Interactive shell. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# While a "quit" command isn't entered, read STDIN +while read -rep "keyringer:/> " STDIN; do + if [ "$STDIN" == "quit" ]; then + break + # If line is not empty or commented, process command + elif [[ -n "$STDIN" && "$STDIN" != "#"* ]]; then + keyringer "$KEYRING" $STDIN + fi +done -- cgit v1.2.3 From cd69cba65cdb39135f44d83537869086ed2330b0 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 13:23:06 -0200 Subject: Initial code for 'cd' shell command (#34) --- lib/keyringer/actions/shell | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell index c70d6bb..d8a0ef7 100755 --- a/lib/keyringer/actions/shell +++ b/lib/keyringer/actions/shell @@ -7,12 +7,38 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Basic parameters +SHELLPATH="/" + # While a "quit" command isn't entered, read STDIN -while read -rep "keyringer:/> " STDIN; do +while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do if [ "$STDIN" == "quit" ]; then break - # If line is not empty or commented, process command + elif [[ "$STDIN" == "cd"* ]]; then + + # Update current path + OLDPATH="$SHELLPATH" + SHELLPATH="/`echo $STDIN | sed -e 's/^cd//' | cut -d ' ' -f 2`" + + # Fix current path + if [ "$SHELLPATH" == "/" ]; then + SHELLPATH="/" + elif [[ "$SHELLPATH" == "/.."* ]]; then + ARGS="$SHELLPATH" + SHELLPATH="$OLDPATH" + for colons in `echo $ARGS | sed -e 's|/| |g'`; do + SHELLPATH="`dirname $SHELLPATH`" + done + fi + + # Check if path exists + if [ ! -d "$KEYDIR/$SHELLPATH" ]; then + echo "No such folder $SHELLPATH" + SHELLPATH="$OLDPATH" + fi + elif [[ -n "$STDIN" && "$STDIN" != "#"* ]]; then - keyringer "$KEYRING" $STDIN + # If line is not empty or commented, process command + RELATIVE_PATH="$SHELLPATH" keyringer "$KEYRING" $STDIN fi done -- cgit v1.2.3 From f695f7810ac91d9cd3f576dcb58f41e75e720129 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 13:38:46 -0200 Subject: Enhanced 'cd' behavior (#34) --- lib/keyringer/actions/shell | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell index d8a0ef7..d9a3e07 100755 --- a/lib/keyringer/actions/shell +++ b/lib/keyringer/actions/shell @@ -18,19 +18,27 @@ while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do # Update current path OLDPATH="$SHELLPATH" - SHELLPATH="/`echo $STDIN | sed -e 's/^cd//' | cut -d ' ' -f 2`" + SHELLPATH="`echo $STDIN | sed -e 's/^cd//' | cut -d ' ' -f 2`" # Fix current path - if [ "$SHELLPATH" == "/" ]; then + if [ "$SHELLPATH" == "/" ] || [ "$SHELLPATH" == "" ]; then SHELLPATH="/" - elif [[ "$SHELLPATH" == "/.."* ]]; then + elif [[ "$SHELLPATH" == ".."* ]]; then ARGS="$SHELLPATH" SHELLPATH="$OLDPATH" for colons in `echo $ARGS | sed -e 's|/| |g'`; do - SHELLPATH="`dirname $SHELLPATH`" + SHELLPATH="`dirname $SHELLPATH | sed -e 's|^\.||'`" done fi + # Ensure path is absolute + if echo "$SHELLPATH" | grep -v -q -e "^/"; then + SHELLPATH="/$OLDPATH/$SHELLPATH" + fi + + # Removing multiple slashes + SHELLPATH="`echo $SHELLPATH | sed -e 's/\/\+/\//g'`" + # Check if path exists if [ ! -d "$KEYDIR/$SHELLPATH" ]; then echo "No such folder $SHELLPATH" -- cgit v1.2.3 From a8c1608fee73578358c3c17f76b44f0857c38ac0 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 14:15:51 -0200 Subject: Integrating shell with all commands (#34) --- keyringer | 3 ++- lib/keyringer/actions/append | 4 ++-- lib/keyringer/actions/decrypt | 2 +- lib/keyringer/actions/del | 2 +- lib/keyringer/actions/edit | 2 +- lib/keyringer/actions/encrypt | 4 ++-- lib/keyringer/actions/genpair | 2 +- lib/keyringer/actions/help | 1 + lib/keyringer/actions/ls | 2 +- lib/keyringer/actions/recrypt | 2 +- lib/keyringer/actions/shell | 4 +++- lib/keyringer/actions/tree | 2 +- lib/keyringer/actions/usage | 2 +- lib/keyringer/functions | 5 +++-- 14 files changed, 21 insertions(+), 16 deletions(-) create mode 120000 lib/keyringer/actions/help (limited to 'lib') diff --git a/keyringer b/keyringer index e65bef0..33d19ff 100755 --- a/keyringer +++ b/keyringer @@ -131,11 +131,12 @@ ACTION="$2" # Turn off pathname expansion so expansion can work properly set -f -# Export preferences and version for other scripts +# Export globals for other scripts export PREFERENCES="`dirname $CONFIG`/$KEYRING" export KEYRINGER_VERSION export CONFIG_VERSION export KEYRING +export CONFIG # Set functions location if [ -e "`dirname $(readlink -f $0)`/lib/$NAME/functions" ]; then diff --git a/lib/keyringer/actions/append b/lib/keyringer/actions/append index e307056..818a7ac 100755 --- a/lib/keyringer/actions/append +++ b/lib/keyringer/actions/append @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$2" +keyringer_get_file "$RELATIVE_PATH/$2" # Only display directions if we're running append, not append-batch if [ "$BASENAME" == "append" ]; then @@ -17,4 +17,4 @@ fi # Append content to an existing secret ( keyringer_exec decrypt "$BASEDIR" "$FILE" && cat ) | \ - keyringer_exec encrypt-batch $BASEDIR $FILE + keyringer_exec encrypt-batch "$BASEDIR" "$FILE" diff --git a/lib/keyringer/actions/decrypt b/lib/keyringer/actions/decrypt index 2b1401c..aab7881 100755 --- a/lib/keyringer/actions/decrypt +++ b/lib/keyringer/actions/decrypt @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$2" +keyringer_get_file "$RELATIVE_PATH/$2" # Decrypt $GPG --quiet --use-agent -d "$KEYDIR/$FILE" diff --git a/lib/keyringer/actions/del b/lib/keyringer/actions/del index d160ac4..a2514d7 100755 --- a/lib/keyringer/actions/del +++ b/lib/keyringer/actions/del @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$2" +keyringer_get_file "$RELATIVE_PATH/$2" # Set options if [ ! -z "$3" ]; then diff --git a/lib/keyringer/actions/edit b/lib/keyringer/actions/edit index 9a3e488..d303bd5 100755 --- a/lib/keyringer/actions/edit +++ b/lib/keyringer/actions/edit @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$2" +keyringer_get_file "$RELATIVE_PATH/$2" # Set recipients file keyringer_set_recipients "$FILE" diff --git a/lib/keyringer/actions/encrypt b/lib/keyringer/actions/encrypt index 0a40bc1..526eaa1 100755 --- a/lib/keyringer/actions/encrypt +++ b/lib/keyringer/actions/encrypt @@ -65,7 +65,7 @@ if [ ! -z "$3" ]; then FILE="$BASEPATH" fi - keyringer_get_new_file $FILE + keyringer_get_new_file $RELATIVE_PATH/$FILE if [ ! -e "$UNENCRYPTED_FILE" ]; then echo "Error: cannot encrypt $UNENCRYPTED_FILE: path not found." @@ -74,7 +74,7 @@ if [ ! -z "$3" ]; then else UNENCRYPTED_FILE="-" shift - keyringer_get_new_file $* + keyringer_get_new_file $RELATIVE_PATH/$* fi # Set recipients file diff --git a/lib/keyringer/actions/genpair b/lib/keyringer/actions/genpair index f048bc7..6898b0f 100755 --- a/lib/keyringer/actions/genpair +++ b/lib/keyringer/actions/genpair @@ -184,7 +184,7 @@ source "$LIB" || exit 1 # Aditional parameters KEYTYPE="$2" -FILE="$3" +FILE="$RELATIVE_PATH/$3" NODE="$4" OUTFILE="$5" CWD="`pwd`" diff --git a/lib/keyringer/actions/help b/lib/keyringer/actions/help new file mode 120000 index 0000000..ae18295 --- /dev/null +++ b/lib/keyringer/actions/help @@ -0,0 +1 @@ +usage \ No newline at end of file diff --git a/lib/keyringer/actions/ls b/lib/keyringer/actions/ls index bb66263..93f5f75 100755 --- a/lib/keyringer/actions/ls +++ b/lib/keyringer/actions/ls @@ -15,5 +15,5 @@ shift ARGS="`echo "$*" | sed -e "s|^/*||"`" # Run list command -cd "$KEYDIR" && ls $ARGS +cd "$KEYDIR/$RELATIVE_PATH" && ls $ARGS cd "$CWD" diff --git a/lib/keyringer/actions/recrypt b/lib/keyringer/actions/recrypt index 014fef7..7d5c6ae 100755 --- a/lib/keyringer/actions/recrypt +++ b/lib/keyringer/actions/recrypt @@ -9,7 +9,7 @@ source "$LIB" || exit 1 function keyringer_recrypt { # Get file - keyringer_get_file "$1" + keyringer_get_file "$RELATIVE_PATH/$1" # Set recipients file keyringer_set_recipients "$FILE" diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell index d9a3e07..955dfe8 100755 --- a/lib/keyringer/actions/shell +++ b/lib/keyringer/actions/shell @@ -12,8 +12,10 @@ SHELLPATH="/" # While a "quit" command isn't entered, read STDIN while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do - if [ "$STDIN" == "quit" ]; then + if [ "$STDIN" == "quit" ] || [ "$STDIN" == "exit" ] || [ "$STDIN" == "bye" ]; then break + elif [ "$STDIN" == "shell" ]; then + echo "Why you need nesting?" elif [[ "$STDIN" == "cd"* ]]; then # Update current path diff --git a/lib/keyringer/actions/tree b/lib/keyringer/actions/tree index 8e94cb0..a2e272d 100755 --- a/lib/keyringer/actions/tree +++ b/lib/keyringer/actions/tree @@ -27,5 +27,5 @@ else fi # Run list command -cd "$KEYDIR" && $TREE $ARGS +cd "$KEYDIR/$RELATIVE_PATH" && $TREE $ARGS cd "$CWD" diff --git a/lib/keyringer/actions/usage b/lib/keyringer/actions/usage index f4ac0fa..e3369cc 100755 --- a/lib/keyringer/actions/usage +++ b/lib/keyringer/actions/usage @@ -7,4 +7,4 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 -keyringer_usage +keyringer_usage $KEYRING diff --git a/lib/keyringer/functions b/lib/keyringer/functions index bef00d9..f387c46 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -474,9 +474,10 @@ function keyringer_usage { printf "Usage: %s [arguments]\n\n" "$BASENAME" printf "Available commands: \n\n" keyringer_show_actions | sed -e 's/^/\t/' - printf "\tinit [remote]\n\n" $BASENAME - if [ ! -z "$keyrings" ]; then + # Display only when not in a keyring context + if [ ! -z "$keyrings" ] && [ -z "$1" ]; then + printf "\tinit [remote]\n\n" $BASENAME printf "Available keyrings: %s \n" "$keyrings" fi } -- cgit v1.2.3 From 47ea7016dc8e5cd8dff3603243aa95fa5f31dbff Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 17:25:07 -0200 Subject: Using RELATIVE_PATH directly at keyringer_get_file and keyringer_get_new_file --- lib/keyringer/actions/append | 2 +- lib/keyringer/actions/decrypt | 2 +- lib/keyringer/actions/del | 2 +- lib/keyringer/actions/edit | 2 +- lib/keyringer/actions/encrypt | 4 ++-- lib/keyringer/actions/recrypt | 2 +- lib/keyringer/functions | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/append b/lib/keyringer/actions/append index 818a7ac..fbb6c1c 100755 --- a/lib/keyringer/actions/append +++ b/lib/keyringer/actions/append @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$RELATIVE_PATH/$2" +keyringer_get_file "$2" # Only display directions if we're running append, not append-batch if [ "$BASENAME" == "append" ]; then diff --git a/lib/keyringer/actions/decrypt b/lib/keyringer/actions/decrypt index aab7881..2b1401c 100755 --- a/lib/keyringer/actions/decrypt +++ b/lib/keyringer/actions/decrypt @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$RELATIVE_PATH/$2" +keyringer_get_file "$2" # Decrypt $GPG --quiet --use-agent -d "$KEYDIR/$FILE" diff --git a/lib/keyringer/actions/del b/lib/keyringer/actions/del index a2514d7..d160ac4 100755 --- a/lib/keyringer/actions/del +++ b/lib/keyringer/actions/del @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$RELATIVE_PATH/$2" +keyringer_get_file "$2" # Set options if [ ! -z "$3" ]; then diff --git a/lib/keyringer/actions/edit b/lib/keyringer/actions/edit index d303bd5..9a3e488 100755 --- a/lib/keyringer/actions/edit +++ b/lib/keyringer/actions/edit @@ -8,7 +8,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 # Get file -keyringer_get_file "$RELATIVE_PATH/$2" +keyringer_get_file "$2" # Set recipients file keyringer_set_recipients "$FILE" diff --git a/lib/keyringer/actions/encrypt b/lib/keyringer/actions/encrypt index 526eaa1..0a40bc1 100755 --- a/lib/keyringer/actions/encrypt +++ b/lib/keyringer/actions/encrypt @@ -65,7 +65,7 @@ if [ ! -z "$3" ]; then FILE="$BASEPATH" fi - keyringer_get_new_file $RELATIVE_PATH/$FILE + keyringer_get_new_file $FILE if [ ! -e "$UNENCRYPTED_FILE" ]; then echo "Error: cannot encrypt $UNENCRYPTED_FILE: path not found." @@ -74,7 +74,7 @@ if [ ! -z "$3" ]; then else UNENCRYPTED_FILE="-" shift - keyringer_get_new_file $RELATIVE_PATH/$* + keyringer_get_new_file $* fi # Set recipients file diff --git a/lib/keyringer/actions/recrypt b/lib/keyringer/actions/recrypt index 7d5c6ae..014fef7 100755 --- a/lib/keyringer/actions/recrypt +++ b/lib/keyringer/actions/recrypt @@ -9,7 +9,7 @@ source "$LIB" || exit 1 function keyringer_recrypt { # Get file - keyringer_get_file "$RELATIVE_PATH/$1" + keyringer_get_file "$1" # Set recipients file keyringer_set_recipients "$FILE" diff --git a/lib/keyringer/functions b/lib/keyringer/functions index f387c46..872dac9 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -398,7 +398,7 @@ function keyringer_upgrade { # Get a file argument function keyringer_get_file { - FILE="$(keyringer_filename "$1")" + FILE="$(keyringer_filename "$RELATIVE_PATH/$1")" if [ -z "$FILE" ]; then keyringer_action_usage @@ -427,7 +427,7 @@ function keyringer_get_new_file { fi # Complete file name - FILE="$(keyringer_filename "$FILE")" + FILE="$RELATIVE_PATH/$(keyringer_filename "$FILE")" if [ -z "$*" ]; then keyringer_action_usage -- cgit v1.2.3 From f58aac98a069c694d2a5791eb96a7554af6b798f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 17:36:04 -0200 Subject: Run shell by default (#34) --- keyringer | 10 ++++++---- lib/keyringer/actions/shell | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/keyringer b/keyringer index 33d19ff..9c45d97 100755 --- a/keyringer +++ b/keyringer @@ -162,12 +162,14 @@ source "$LIB" || exit 1 # Setup main configuration and load preferences keyringer_config_load -if [ -z "$ACTION" ]; then +# Dispatch +if [ -z "$KEYRING" ]; then keyringer_usage exit 1 -fi - -if [ "$ACTION" == "init" ]; then +elif [ -z "$ACTION" ]; then + # Run shell if no action were given + keyringer $KEYRING shell +elif [ "$ACTION" == "init" ]; then keyringer_init $* elif keyringer_has_action "$ACTION"; then keyringer_dispatch $* diff --git a/lib/keyringer/actions/shell b/lib/keyringer/actions/shell index 955dfe8..ab170b1 100755 --- a/lib/keyringer/actions/shell +++ b/lib/keyringer/actions/shell @@ -10,6 +10,9 @@ source "$LIB" || exit 1 # Basic parameters SHELLPATH="/" +# Show usage +keyringer_usage $KEYRING + # While a "quit" command isn't entered, read STDIN while read -rep "keyringer:/${KEYRING}${SHELLPATH}> " STDIN; do if [ "$STDIN" == "quit" ] || [ "$STDIN" == "exit" ] || [ "$STDIN" == "bye" ]; then -- cgit v1.2.3 From d3c34db2f307d86209235832db8b9c04a2942405 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 18:48:53 -0200 Subject: Adding mkdir action (#34) --- lib/keyringer/actions/mkdir | 19 +++++++++++++++++++ share/man/keyringer.1.mdwn | 3 +++ 2 files changed, 22 insertions(+) create mode 100755 lib/keyringer/actions/mkdir (limited to 'lib') diff --git a/lib/keyringer/actions/mkdir b/lib/keyringer/actions/mkdir new file mode 100755 index 0000000..b31eb0b --- /dev/null +++ b/lib/keyringer/actions/mkdir @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Create folders. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Aditional parameters +CWD="`pwd`" + +# Avoid leading slash +shift +ARGS="`echo "$*" | sed -e "s|^/*||"`" + +# Run mkdir command +cd "$KEYDIR/$RELATIVE_PATH" && mkdir -p $ARGS +cd "$CWD" diff --git a/share/man/keyringer.1.mdwn b/share/man/keyringer.1.mdwn index b383507..f8d243e 100644 --- a/share/man/keyringer.1.mdwn +++ b/share/man/keyringer.1.mdwn @@ -56,6 +56,9 @@ ls <*path*> if *path* is specified. Like the git wrapper, this is a wrapper around the *LS(1)* command. +mkdir <*path*> +: Create a directory inside the repository *keys* folder. + tree <*path*> : List contents from the toplevel repository *keys* folder or from relative paths if *path* is specified using a tree-like format. Like the ls wrapper, this is a -- cgit v1.2.3 From b2b3a02e33c9efbbfce46a658360189ecc8dda2a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 18:51:38 -0200 Subject: Adding shell completions for 'mkdir' action (#34) --- lib/keyringer/completions/bash/keyringer | 2 +- lib/keyringer/completions/zsh/_keyringer | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index eeda27f..5474c67 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -94,7 +94,7 @@ _keyringer() { recipients) opts="ls edit" ;; - ls|tree|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open) + ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open) cur="`echo ${cur} | sed -e "s|^/*||"`" # avoid leading slash opts="$(bash -c "set -f && export KEYRINGER_CHECK_VERSION=false && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index 5717b00..0eba079 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -50,7 +50,7 @@ _keyringer() { recipients) compadd "$@" ls edit ;; - ls|tree|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open) + ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open) words[4]="`echo $words[4] | sed -e "s|^/*||"`" # avoid leading slash compadd "$@" $(KEYRINGER_CHECK_VERSION=false keyringer $words[2] ls -p -d $words[4]'*' 2> /dev/null) ;; -- cgit v1.2.3 From 21e393464645c76c949d74180ce04b7507e0d738 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 22:13:25 -0200 Subject: Adding 'teardown' action --- development.mdwn | 4 +--- lib/keyringer/actions/teardown | 27 +++++++++++++++++++++++++++ lib/keyringer/functions | 13 ++++++++++--- share/man/keyringer.1.mdwn | 4 ++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100755 lib/keyringer/actions/teardown (limited to 'lib') diff --git a/development.mdwn b/development.mdwn index 1f475b6..8366b59 100644 --- a/development.mdwn +++ b/development.mdwn @@ -102,9 +102,7 @@ Setup: Teardown: - rm -rf ~/code/tests/keyringer - rm ~/.keyringer/test - sed -i -e '/^test=/d' ~/.keyringer/config + keyringer test teardown -y Translation ----------- diff --git a/lib/keyringer/actions/teardown b/lib/keyringer/actions/teardown new file mode 100755 index 0000000..3d33da4 --- /dev/null +++ b/lib/keyringer/actions/teardown @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Remove a keyring. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Options +CONFIRM="$2" + +if [ -z "$CONFIRM" ] || [ "$CONFIRM" != "-y" ]; then + echo "WARNING: about to remove the LOCAL copy of $KEYRING" + echo "WARNING: This will irrevocably destroy $KEYDIR" + echo "WARNING: the action cannot be undone!" + + read -rep "Are you sure to WIPE keyring $KEYRING (type YES to confirm)? " key + if [ "$key" != "YES" ]; then + exit 1 + fi +fi + +# Teardown +keyringer_shred `dirname $KEYDIR` +keyringer_shred $HOME/.keyringer/$KEYRING +sed -i -e "/^$KEYRING=/d" $HOME/.keyringer/config diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 872dac9..0e795ee 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -206,10 +206,17 @@ function keyringer_shred { echo "$message $path using $tool..." if [ -d "$path" ]; then - find $path -exec $tool -f {} \; - rmdir $path + if [ "$tool" == "wipe" ] || [ "$tool" == "rm" ]; then + $tool -rf $path + else + find $path -exec $tool -uf {} \; + fi else - $tool -f "$path" + if [ "$tool" == "wipe" ] || [ "$tool" == "rm" ]; then + $tool -f "$path" + else + $tool -uf "$path" + fi fi } diff --git a/share/man/keyringer.1.mdwn b/share/man/keyringer.1.mdwn index f8d243e..ad9569b 100644 --- a/share/man/keyringer.1.mdwn +++ b/share/man/keyringer.1.mdwn @@ -74,6 +74,10 @@ shell All <*secret*> parameters from actions invoked from the shell are called relatively from the current selected directory. +teardown +: Remove permanently a local copy of a repository, very dangerous if you + have just a single copy. + # SECRET MANIPULATION ACTIONS All secret manipulation actions operate upon a *secret* which is the pathname -- cgit v1.2.3 From 7aac0eea6ab0690e040ffe2ed2eab4adde8d5ead Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 22:32:59 -0200 Subject: Fix instance list at shell completions --- lib/keyringer/completions/bash/keyringer | 4 ++-- lib/keyringer/completions/zsh/_keyringer | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index 5474c67..eb8fabd 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -70,10 +70,10 @@ _keyringer() { # Process config source $config/config - keyrings="`ls --color=never $config | sed -e 's/config//' | xargs`" + keyrings="`ls --color=never $config | sed -e '/^config$/d' | xargs`" # Available instances - instances="`echo $keyrings | sed -e 's/ /\\\|/g'`" + instances="`echo $keyrings | sed -e 's/ /$\\\|^/g' -e 's/^/^/' -e 's/$/$/'`" # The current instance instance="${COMP_WORDS[1]}" diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index 0eba079..e889fd8 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -20,9 +20,9 @@ _keyringer() { # Process config source $config/config - local keyrings="`ls --color=never $config | sed -e 's/config//' | xargs`" + local keyrings="`ls --color=never $config | sed -e '/^config$/d' | xargs`" local keyring_path="`eval echo '$'$words[2]`" - local instances="`echo $keyrings | sed -e 's/ /\\\|/g'`" + local instances="`echo $keyrings | sed -e 's/ /$\\\|^/g' -e 's/^/^/' -e 's/$/$/'`" _arguments \ '1: :->keyring' \ -- cgit v1.2.3 From b4bdeafcf666b6f7a6f3f33e9f4cf1fb0a7cebbf Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 10 Dec 2013 22:43:14 -0200 Subject: Comments --- lib/keyringer/actions/commands | 1 + lib/keyringer/actions/edit | 1 + lib/keyringer/actions/encrypt | 4 +++- lib/keyringer/actions/options | 1 + lib/keyringer/actions/preferences | 3 +++ lib/keyringer/actions/recipients | 1 + lib/keyringer/actions/recrypt | 2 ++ lib/keyringer/actions/teardown | 1 + lib/keyringer/actions/tree | 2 +- lib/keyringer/actions/usage | 1 + 10 files changed, 15 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/commands b/lib/keyringer/actions/commands index 2605666..cb49c02 100755 --- a/lib/keyringer/actions/commands +++ b/lib/keyringer/actions/commands @@ -7,4 +7,5 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Dispatch keyringer_show_actions diff --git a/lib/keyringer/actions/edit b/lib/keyringer/actions/edit index 9a3e488..5f31aa0 100755 --- a/lib/keyringer/actions/edit +++ b/lib/keyringer/actions/edit @@ -24,6 +24,7 @@ keyringer_set_tmpfile $BASENAME.$EXTENSION # Decrypt the information to the file $GPG --yes -o "$TMPWORK" --use-agent -d "$KEYDIR/$FILE" +# Action check if [ "$BASENAME" == "edit" ]; then APP="$EDITOR" elif [ "$BASENAME" == "open" ]; then diff --git a/lib/keyringer/actions/encrypt b/lib/keyringer/actions/encrypt index 0a40bc1..e9bf453 100755 --- a/lib/keyringer/actions/encrypt +++ b/lib/keyringer/actions/encrypt @@ -106,12 +106,13 @@ else keyringer_encrypt $FILE $UNENCRYPTED_FILE fi +# Check exit status err="$?" - if [ "$err" != "0" ]; then exit "$err" fi +# Wipe information if [ "$UNENCRYPTED_FILE" != "-" ]; then echo "Done. PLEASE WIPE the non-encrypted $UNENCRYPTED_FILE." fi @@ -121,4 +122,5 @@ if [ -d "$BASEDIR/.git" ]; then keyringer_exec git "$BASEDIR" add "keys/$FILE" fi +# Done exit "$?" diff --git a/lib/keyringer/actions/options b/lib/keyringer/actions/options index 8508aea..3bf0e43 100755 --- a/lib/keyringer/actions/options +++ b/lib/keyringer/actions/options @@ -17,6 +17,7 @@ if [ ! -e "$OPTIONS" ]; then keyringer_exec git "$BASEDIR" add config/options fi +# Dispatch if [ "$COMMAND" == "ls" ]; then cat "$OPTIONS" elif [ "$COMMAND" == "edit" ]; then diff --git a/lib/keyringer/actions/preferences b/lib/keyringer/actions/preferences index e82848d..f7507a7 100755 --- a/lib/keyringer/actions/preferences +++ b/lib/keyringer/actions/preferences @@ -7,8 +7,10 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Options COMMAND="$2" +# Syntax check if [ -z "$COMMAND" ]; then echo "Usage: keyringer preferences [arguments]" echo "Available commands:" @@ -24,6 +26,7 @@ if [ ! -e "$PREFERENCES" ]; then touch "$PREFERENCES" fi +# Dispatch if [ "$COMMAND" == "ls" ]; then cat "$PREFERENCES" elif [ "$COMMAND" == "edit" ]; then diff --git a/lib/keyringer/actions/recipients b/lib/keyringer/actions/recipients index 7093a6b..4149786 100755 --- a/lib/keyringer/actions/recipients +++ b/lib/keyringer/actions/recipients @@ -13,6 +13,7 @@ keyringer_get_command "$2" # Set recipients file keyringer_set_new_recipients "$3" +# Syntax check and dispatcher if [ "$COMMAND" == "ls" ]; then if [ ! -z "$3" ]; then if [ -e "$RECIPIENTS_FILE" ]; then diff --git a/lib/keyringer/actions/recrypt b/lib/keyringer/actions/recrypt index 014fef7..696399b 100755 --- a/lib/keyringer/actions/recrypt +++ b/lib/keyringer/actions/recrypt @@ -7,6 +7,7 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Recrypt a single secret function keyringer_recrypt { # Get file keyringer_get_file "$1" @@ -34,6 +35,7 @@ function keyringer_recrypt { echo "$recrypted" > "$KEYDIR/$FILE" } +# Syntax check and dispatcher if [ ! -z "$2" ]; then keyringer_recrypt $2 else diff --git a/lib/keyringer/actions/teardown b/lib/keyringer/actions/teardown index 3d33da4..64da740 100755 --- a/lib/keyringer/actions/teardown +++ b/lib/keyringer/actions/teardown @@ -10,6 +10,7 @@ source "$LIB" || exit 1 # Options CONFIRM="$2" +# Confirmation if [ -z "$CONFIRM" ] || [ "$CONFIRM" != "-y" ]; then echo "WARNING: about to remove the LOCAL copy of $KEYRING" echo "WARNING: This will irrevocably destroy $KEYDIR" diff --git a/lib/keyringer/actions/tree b/lib/keyringer/actions/tree index a2e272d..8f9d7cd 100755 --- a/lib/keyringer/actions/tree +++ b/lib/keyringer/actions/tree @@ -1,6 +1,6 @@ #!/bin/bash # -# List keys. +# List keys, tree version. # # Thanks http://www.centerkey.com/tree/ diff --git a/lib/keyringer/actions/usage b/lib/keyringer/actions/usage index e3369cc..2ca7639 100755 --- a/lib/keyringer/actions/usage +++ b/lib/keyringer/actions/usage @@ -7,4 +7,5 @@ LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Dispatch keyringer_usage $KEYRING -- cgit v1.2.3 From 4a19a5a2db0e49846249bf4b7ce02a2c6e143626 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 22 Dec 2013 13:22:00 -0200 Subject: Add missing '/.' test at keyringer_set_recipients --- lib/keyringer/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 0e795ee..de7516f 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -554,7 +554,7 @@ function keyringer_set_recipients { candidate_no_extension="`echo $1 | sed -e 's/.asc$//'`" # Find the first matching recipient - while [ ! -z "$candidate" ] && [ "$candidate" != "." ] && [ "$candidate" != "/" ]; do + while [ ! -z "$candidate" ] && [ "$candidate" != "." ] && [ "$candidate" != "/" ] && [ "$candidate" != "/." ]; do if [ -e "$RECIPIENTS/$candidate" ]; then RECIPIENTS_FILE="$RECIPIENTS/$candidate" RECIPIENTS_FILE_BASE="$RECIPIENTS_BASE/$candidate" -- cgit v1.2.3 From b95155761a1789557ea1569491d149e3c90d295b Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 26 Dec 2013 21:56:04 -0200 Subject: Adding 'find' action --- ChangeLog | 4 ++++ lib/keyringer/actions/find | 19 +++++++++++++++++++ share/man/keyringer.1.mdwn | 3 +++ 3 files changed, 26 insertions(+) create mode 100755 lib/keyringer/actions/find (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index 2de87c4..eb6b543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-12-26 - Silvio Rhatto + + New action: find. + 2013-12-10 - Silvio Rhatto New actions: shell (#34), help, mkdir, teardown. diff --git a/lib/keyringer/actions/find b/lib/keyringer/actions/find new file mode 100755 index 0000000..92bec25 --- /dev/null +++ b/lib/keyringer/actions/find @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Find secrets. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Aditional parameters +CWD="`pwd`" + +# Avoid leading slash +shift +ARGS="`echo "$*" | sed -e "s|^/*||"`" + +# Run find command +cd "$KEYDIR/$RELATIVE_PATH" && find -iname "*$ARGS*" +cd "$CWD" diff --git a/share/man/keyringer.1.mdwn b/share/man/keyringer.1.mdwn index ad9569b..c3a8a7c 100644 --- a/share/man/keyringer.1.mdwn +++ b/share/man/keyringer.1.mdwn @@ -37,6 +37,9 @@ Keyringer has three types of actions: # REPOSITORY LOOKUP AND MANIPULATION ACTIONS +find <*expression*> +: Find secrets in the repository. + init <*path*> [*remote*] : Initialize a new keyringer repository. If a *remote* URL is specified, keyringer will clone an existing repository. -- cgit v1.2.3 From 7468b6ec0df6aa6c594640154eecb02b12cca5e5 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 26 Dec 2013 23:20:09 -0200 Subject: Support for RELATIVE_FOLDER at git action --- lib/keyringer/actions/git | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/actions/git b/lib/keyringer/actions/git index 3c4f435..108ccea 100755 --- a/lib/keyringer/actions/git +++ b/lib/keyringer/actions/git @@ -12,5 +12,13 @@ CWD="`pwd`" # Run git command shift -mkdir -p "$BASEDIR" && cd "$BASEDIR" && git $* + +# Set working folder +if [ ! -z "$RELATIVE_PATH" ]; then + WORK="$KEYDIR/$RELATIVE_PATH" +else + WORK="$BASEDIR" +fi + +mkdir -p "$WORK" && cd "$WORK" && git $* cd "$CWD" -- cgit v1.2.3 From 6e077ce5604f8de1eec8e953248674423254246d Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 26 Dec 2013 23:56:30 -0200 Subject: Adding mv and rmdir actions --- ChangeLog | 6 ++++-- lib/keyringer/actions/mv | 28 ++++++++++++++++++++++++++++ lib/keyringer/actions/rmdir | 19 +++++++++++++++++++ share/man/keyringer.1.mdwn | 6 ++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100755 lib/keyringer/actions/mv create mode 100755 lib/keyringer/actions/rmdir (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index eb6b543..401fc64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,12 @@ 2013-12-26 - Silvio Rhatto - New action: find. + New actions: find, mv, rmdir + + Support for RELATIVE_FOLDER at git action 2013-12-10 - Silvio Rhatto - New actions: shell (#34), help, mkdir, teardown. + New actions: shell (#34), help, mkdir, teardown 2013-11-26 - 0.2.9 Silvio Rhatto diff --git a/lib/keyringer/actions/mv b/lib/keyringer/actions/mv new file mode 100755 index 0000000..aaf6772 --- /dev/null +++ b/lib/keyringer/actions/mv @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Move secrets. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Avoid leading slash +ORIG="$(keyringer_filename `echo "$2" | sed -e "s|^/*||"`)" +DEST="`echo "$3" | sed -e "s|^/*||"`" + +# Set destination +if [ ! -d "$KEYDIR/$RELATIVE_PATH/$DEST" ]; then + keyringer_get_new_file $DEST +else + FILE="$DEST" +fi + +# Check if secret exists +if ! echo "$ORIG" | grep -q '*' && [ ! -e "$KEYDIR/$RELATIVE_PATH/$ORIG" ]; then + echo "Secret not found: $ORIG" + exit 1 +fi + +# Run move command +keyringer_exec git "$BASEDIR" mv $ORIG $FILE diff --git a/lib/keyringer/actions/rmdir b/lib/keyringer/actions/rmdir new file mode 100755 index 0000000..398cf11 --- /dev/null +++ b/lib/keyringer/actions/rmdir @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Remove folders. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Aditional parameters +CWD="`pwd`" + +# Avoid leading slash +shift +ARGS="`echo "$*" | sed -e "s|^/*||"`" + +# Run rmdir command +cd "$KEYDIR/$RELATIVE_PATH" && rmdir $ARGS +cd "$CWD" diff --git a/share/man/keyringer.1.mdwn b/share/man/keyringer.1.mdwn index c3a8a7c..1cd7a45 100644 --- a/share/man/keyringer.1.mdwn +++ b/share/man/keyringer.1.mdwn @@ -62,6 +62,9 @@ ls <*path*> mkdir <*path*> : Create a directory inside the repository *keys* folder. +:rmdir <*path*> +: Remove an empty folder inside the repository *keys* folder. + tree <*path*> : List contents from the toplevel repository *keys* folder or from relative paths if *path* is specified using a tree-like format. Like the ls wrapper, this is a @@ -116,6 +119,9 @@ del <*secret*> rm <*secret*> : Alias for *del* action. +mv <*secret*> <*dest*> +: Rename a secret. + edit <*secret*> : Edit a secret by temporarily decrypting it, opening the decrypted copy into the text editor defined by the *$EDITOR* environment variable and then re-encrypting it. -- cgit v1.2.3 From 05c979445a142de0b9a66995728d984ab2247856 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 31 Dec 2013 17:58:30 -0200 Subject: Use 'gpg --quiet' by default --- lib/keyringer/actions/decrypt | 2 +- lib/keyringer/functions | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/decrypt b/lib/keyringer/actions/decrypt index 2b1401c..b63b74e 100755 --- a/lib/keyringer/actions/decrypt +++ b/lib/keyringer/actions/decrypt @@ -11,7 +11,7 @@ source "$LIB" || exit 1 keyringer_get_file "$2" # Decrypt -$GPG --quiet --use-agent -d "$KEYDIR/$FILE" +$GPG --use-agent -d "$KEYDIR/$FILE" # Exit exit "$?" diff --git a/lib/keyringer/functions b/lib/keyringer/functions index de7516f..9eb832f 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -290,9 +290,9 @@ function keyringer_set_env { fi if [ ! -z "$KEYID" ]; then - GPG="gpg -u $KEYID" + GPG="gpg --quiet -u $KEYID" else - GPG="gpg" + GPG="gpg --quiet" fi # Check keyring config version -- cgit v1.2.3 From 0471007d92b837d8d5df2c6d3a80fffd1048c3a4 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 12 Feb 2014 12:13:27 -0200 Subject: Proper error handling at edit action --- lib/keyringer/actions/edit | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/actions/edit b/lib/keyringer/actions/edit index 5f31aa0..03ccdab 100755 --- a/lib/keyringer/actions/edit +++ b/lib/keyringer/actions/edit @@ -44,5 +44,18 @@ $APP "$TMPWORK" # Encrypt again $GPG --yes -o "$KEYDIR/$FILE" --use-agent --armor -e -s $(keyringer_recipients "$RECIPIENTS_FILE") "$TMPWORK" +# Check exit status +errcrypt="$?" + # Remove temp file keyringer_unset_tmpfile "$TMPWORK" + +# Check exit status again +errwipe="$?" + +# Error handling must be done after temp file removal +if [ "$errcrypt" != "0" ]; then + exit "$errcrypt" +elif [ "$errwipe" != "0" ]; then + exit $errwipe +fi -- cgit v1.2.3 From 36b74ae7fad92c8f03a6f00ff2d0fe2f70ea7899 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 12 Feb 2014 13:31:16 -0200 Subject: Check key expirations (#37) --- lib/keyringer/functions | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 9eb832f..810effe 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -541,6 +541,31 @@ EOF echo "Please check for this key or fix the recipient file." exit 1 fi + + # Current date + seconds="`date +%s`" + + # Check the main key + expiry="`gpg --with-colons --fixed-list-mode --list-keys "$recipient" | grep ^pub | cut -d : -f 7`" + + # Check if key is expired + if [[ "$seconds" -gt "$expiry" ]]; then + echo "Fatal: primary key for $recipient expired on `date --date="@$expiry"`" + exit 1 + else + # Check the subkeys + for expiry in `gpg --with-colons --fixed-list-mode --list-keys "$recipient" | grep ^sub | cut -d : -f 7`; do + if [[ "$seconds" -lt "$expiry" ]]; then + not_expired="1" + fi + + if [ "$not_expired" != "1" ]; then + echo "Fatal: key $recipient has no keys suitable for encryption: all subkeys expired." + exit 1 + fi + done + fi + fi done } -- cgit v1.2.3 From 2842331046ee4b31d13a210a6d69a87363fa20e1 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 13 Feb 2014 11:54:45 -0200 Subject: Expiration check should handle keys without expiry dates --- lib/keyringer/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 810effe..5cc92b1 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -549,7 +549,7 @@ EOF expiry="`gpg --with-colons --fixed-list-mode --list-keys "$recipient" | grep ^pub | cut -d : -f 7`" # Check if key is expired - if [[ "$seconds" -gt "$expiry" ]]; then + if [ ! -z "$expiry" ] && [[ "$seconds" -gt "$expiry" ]]; then echo "Fatal: primary key for $recipient expired on `date --date="@$expiry"`" exit 1 else -- cgit v1.2.3 From 9b26f57a726ccb582f41c19c7c3bbcef3225c12d Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 19 Feb 2014 23:38:36 -0300 Subject: Adding xclip action thanks to password-store --- ChangeLog | 4 +++- lib/keyringer/actions/clip | 1 + lib/keyringer/actions/xclip | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 120000 lib/keyringer/actions/clip create mode 100755 lib/keyringer/actions/xclip (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index 17f343e..f94fb74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -2014-02-12 - Silvio Rhatto +2014-02-19 - Silvio Rhatto + + Added xclip action (#33) Check key expirations (#37) diff --git a/lib/keyringer/actions/clip b/lib/keyringer/actions/clip new file mode 120000 index 0000000..8b8c16c --- /dev/null +++ b/lib/keyringer/actions/clip @@ -0,0 +1 @@ +xclip \ No newline at end of file diff --git a/lib/keyringer/actions/xclip b/lib/keyringer/actions/xclip new file mode 100755 index 0000000..414013b --- /dev/null +++ b/lib/keyringer/actions/xclip @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Decrypt secret header to clipboard. +# + +# Copy contents to clipboard. +# Function thanks to Password Store by Jason A. Donenfeld +# distributed under GPLv2+: http://www.zx2c4.com/projects/password-store/ +clip() { + # This base64 business is a disgusting hack to deal with newline inconsistancies + # in shell. There must be a better way to deal with this, but because I'm a dolt, + # we're going with this for now. + + before="$(xclip -o -selection clipboard | base64)" + echo -n "$1" | xclip -selection clipboard + ( + sleep 45 + now="$(xclip -o -selection clipboard | base64)" + if [[ $now != $(echo -n "$1" | base64) ]]; then + before="$now" + fi + + # It might be nice to programatically check to see if klipper exists, + # as well as checking for other common clipboard managers. But for now, + # this works fine -- if qdbus isn't there or if klipper isn't running, + # this essentially becomes a no-op. + # + # Clipboard managers frequently write their history out in plaintext, + # so we axe it here: + qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory &>/dev/null + + echo "$before" | base64 -d | xclip -selection clipboard + ) & disown + echo "Copied $2 to clipboard. Will clear in 45 seconds." +} + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Get file +keyringer_get_file "$2" + +# Decrypt +pass="$($GPG --use-agent -d "$KEYDIR/$FILE" | head -n 1)" + +# Copy to clipboard +if [ ! -z "$pass" ]; then + clip "$pass" "$2" +fi + +# Exit +exit "$?" -- cgit v1.2.3 From 04b03dd14a0abe02f436f86e3d647f97b3e5522b Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 19 Feb 2014 23:42:29 -0300 Subject: Adding xclip action thanks to password-store (2) --- lib/keyringer/actions/xclip | 6 ++++++ lib/keyringer/completions/bash/keyringer | 2 +- lib/keyringer/completions/zsh/_keyringer | 2 +- share/man/keyringer.1.mdwn | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/xclip b/lib/keyringer/actions/xclip index 414013b..b28984f 100755 --- a/lib/keyringer/actions/xclip +++ b/lib/keyringer/actions/xclip @@ -38,6 +38,12 @@ clip() { LIB="`dirname $0`/../functions" source "$LIB" || exit 1 +# Check for xclip +if ! which xclip; then + echo "fatal: xclip not found" + exit 1 +fi + # Get file keyringer_get_file "$2" diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index eb8fabd..a640583 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -94,7 +94,7 @@ _keyringer() { recipients) opts="ls edit" ;; - ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open) + ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip) cur="`echo ${cur} | sed -e "s|^/*||"`" # avoid leading slash opts="$(bash -c "set -f && export KEYRINGER_CHECK_VERSION=false && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index e889fd8..1a6d8c6 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -50,7 +50,7 @@ _keyringer() { recipients) compadd "$@" ls edit ;; - ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open) + ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip) words[4]="`echo $words[4] | sed -e "s|^/*||"`" # avoid leading slash compadd "$@" $(KEYRINGER_CHECK_VERSION=false keyringer $words[2] ls -p -d $words[4]'*' 2> /dev/null) ;; diff --git a/share/man/keyringer.1.mdwn b/share/man/keyringer.1.mdwn index 1cd7a45..ccaabdf 100644 --- a/share/man/keyringer.1.mdwn +++ b/share/man/keyringer.1.mdwn @@ -150,6 +150,9 @@ recrypt <*secret*> into the recipient configuration. If no *secret* is given, all secrets in the repository are re-encrypted. +clip <*secret*>, xclip <*secret*> +: Copy the first line of a secret to the clipboard, following password-store convention. + # CONFIGURATION ACTIONS commands -- cgit v1.2.3 From 0fba4b17d2c76784f99de0182d175b2d37f07638 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 20 Feb 2014 00:22:03 -0300 Subject: Try to find a similar file at keyringer_get_file() --- lib/keyringer/actions/find | 2 +- lib/keyringer/functions | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/actions/find b/lib/keyringer/actions/find index 92bec25..21afc7a 100755 --- a/lib/keyringer/actions/find +++ b/lib/keyringer/actions/find @@ -15,5 +15,5 @@ shift ARGS="`echo "$*" | sed -e "s|^/*||"`" # Run find command -cd "$KEYDIR/$RELATIVE_PATH" && find -iname "*$ARGS*" +cd "$KEYDIR/$RELATIVE_PATH" && find -iname "*$ARGS*" | sed -e 's|^./||g' cd "$CWD" diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 5cc92b1..014c2c9 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -411,8 +411,33 @@ function keyringer_get_file { keyringer_action_usage exit 1 elif [ ! -f "$KEYDIR/$FILE" ]; then - echo "File not found: $KEYDIR/$FILE" - exit 1 + # Try to find a similar file + count=0 + candidates=(`keyringer_exec find "$BASEDIR" "$1" | grep -e '.asc$'`) + + if [ ! -z "$candidates" ]; then + echo "Could not find exact match \"$1\", please chose one" + echo "of the following secrets:" + echo "" + + for candidate in ${candidates[@]}; do + echo -e "\t[$count] $candidate" + let count++ + done + + echo "" + read -p "Enter option: " option + + if [[ "$option" =~ ^[0-9]+$ ]] && [ ! -z "${candidates[$option]}" ]; then + FILE="$(keyringer_filename "$RELATIVE_PATH/${candidates[$option]}")" + else + echo "Invalid option" + exit 1 + fi + else + echo "File not found: $KEYDIR/$FILE" + exit 1 + fi fi } -- cgit v1.2.3