From f51408e892c350bf8204b8180424b8d6f4bd0f0c Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 6 Jul 2014 14:28:34 -0300 Subject: Reset 'expiry' on keyringer_check_expiration (closes #62) --- lib/keyringer/functions | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index fdd8439..0360bb4 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -715,6 +715,7 @@ function keyringer_check_expiration { fi # Check the subkeys + expiry="" 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" -- cgit v1.2.3 From 20125ba1c35ee8bceb0e3ea1ab9c3b6017b11aa1 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 16 Aug 2014 20:10:22 -0300 Subject: New action 'cp' (2) --- lib/keyringer/actions/cp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 lib/keyringer/actions/cp (limited to 'lib') diff --git a/lib/keyringer/actions/cp b/lib/keyringer/actions/cp new file mode 100755 index 0000000..0629b61 --- /dev/null +++ b/lib/keyringer/actions/cp @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Copy secrets. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +# Aditional parameters +CWD="`pwd`" + +# 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 +cd "$KEYDIR" && cp -a "./$RELATIVE_PATH/$ORIG" "./$FILE" +keyringer_exec git "$BASEDIR" add "keys/$FILE" +cd "$CWD" -- cgit v1.2.3 From f63b965d14466197240a207509bddb9f204d64bc Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 16 Aug 2014 20:25:01 -0300 Subject: Removing trailing spaces --- lib/keyringer/functions | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 0360bb4..5dbb6b4 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -72,7 +72,7 @@ function keyringer_exec { action="$1" basedir="$2" shift 2 - + # Dispatch if keyringer_has_action "$action"; then "$ACTIONS/$action" "$basedir" $* @@ -171,7 +171,7 @@ function keyringer_set_tmpfile { else TMPWORK="$(mktemp "$template")" fi - + if [ "$?" != "0" ]; then printf "Error: can't set TMPWORK %s\n" "$TMPWORK" exit 1 @@ -250,7 +250,7 @@ function keyringer_git_ignore { function keyringer_set_env { if [ -z "$1" ]; then echo "Error: missing arguments for keyringer_set_env" - exit 1 + exit 1 fi ACTIONS="`dirname $0`" @@ -429,7 +429,7 @@ function keyringer_get_option { # Get a file argument function keyringer_get_file { FILE="$(keyringer_filename "$RELATIVE_PATH/$1")" - + if [ -z "$FILE" ]; then keyringer_action_usage exit 1 -- cgit v1.2.3 From df97a807e2c13a5d020d72f07058904b60f19cfd Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 16 Aug 2014 20:31:47 -0300 Subject: Edit: Unset RELATIVE_PATH before encrypting file --- ChangeLog | 2 ++ lib/keyringer/actions/edit | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index 87bf35f..e9be9aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2014-08-16 - Silvio Rhatto + Edit: Unset RELATIVE_PATH before encrypting file + New 'cp' action Reset 'expiry' on keyringer_check_expiration, reported and fixed diff --git a/lib/keyringer/actions/edit b/lib/keyringer/actions/edit index a5f14d4..c9f3f12 100755 --- a/lib/keyringer/actions/edit +++ b/lib/keyringer/actions/edit @@ -59,9 +59,9 @@ wait echo "Press any key when done using the file and you're sure that $APPNAME is closed." read -s -n 1 -# Encrypt again +# Encrypt again. Unset RELATIVE_PATH as it was already used to determine FILE path export KEYRINGER_ADD_EXTENSION=false -keyringer_exec encrypt "$BASEDIR" "$FILE" "$TMPWORK" +RELATIVE_PATH="" keyringer_exec encrypt "$BASEDIR" "$FILE" "$TMPWORK" # Check exit status errcrypt="$?" -- cgit v1.2.3 From bfd718703aac6fe706ee751f232b0e80601913d1 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 21 Aug 2014 15:04:52 -0300 Subject: Moving editors' files to shared folder --- Makefile | 4 ++-- keyringer | 24 +++++++++++++++++------- lib/keyringer/editors/vim | 5 ----- lib/keyringer/functions | 2 +- share/keyringer/editors/vim | 5 +++++ 5 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 lib/keyringer/editors/vim create mode 100644 share/keyringer/editors/vim (limited to 'lib') diff --git a/Makefile b/Makefile index c1e50e9..07513f2 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ install_lib: $(INSTALL) -D --mode=0755 lib/keyringer/functions $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/functions $(INSTALL) -D --mode=0755 -d lib/keyringer/actions $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/actions $(INSTALL) -D --mode=0755 lib/keyringer/actions/* $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/actions - $(INSTALL) -D --mode=0755 -d lib/keyringer/editors $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/editors - $(INSTALL) -D --mode=0644 lib/keyringer/editors/* $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/editors + $(INSTALL) -D --mode=0755 -d share/keyringer/editors $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/editors + $(INSTALL) -D --mode=0644 share/keyringer/editors/* $(DESTDIR)/$(PREFIX)/lib/$(PACKAGE)/editors install_bin: $(INSTALL) -D --mode=0755 keyringer $(DESTDIR)/$(PREFIX)/bin/keyringer diff --git a/keyringer b/keyringer index b8edc8e..a32f15b 100755 --- a/keyringer +++ b/keyringer @@ -149,13 +149,6 @@ ACTION="$2" # Turn off pathname expansion so expansion can work properly set -f -# 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 # Development or local installation layout @@ -165,6 +158,15 @@ else LIB="`dirname $(readlink -f $0)`/../lib/$NAME/functions" fi +# Set shared files location +if [ -e "`dirname $(readlink -f $0)`/share/$NAME" ]; then + # Development or local installation layout + SHARE="`dirname $(readlink -f $0)`/share/$NAME" +else + # System installation layout + SHARE="`dirname $(readlink -f $0)`/../share/$NAME" +fi + # Set actions location if [ -e "`dirname $(readlink -f $0)`/lib/$NAME/actions" ]; then # Development or local installation layout @@ -174,6 +176,14 @@ else ACTIONS="`dirname $(readlink -f $0)`/../lib/$NAME/actions" fi +# Export globals for other scripts +export PREFERENCES="`dirname $CONFIG`/$KEYRING" +export KEYRINGER_VERSION +export CONFIG_VERSION +export KEYRING +export CONFIG +export SHARE + # Load functions source "$LIB" || exit 1 diff --git a/lib/keyringer/editors/vim b/lib/keyringer/editors/vim deleted file mode 100644 index 0f877df..0000000 --- a/lib/keyringer/editors/vim +++ /dev/null @@ -1,5 +0,0 @@ -" Use sane defaults for VIM to avoid data leakage -" See https://keyringer.pw/trac/ticket/50 -set nowritebackup -set nobackup -set viminfo="NONE" diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 5dbb6b4..42c047d 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -287,7 +287,7 @@ function keyringer_set_env { # Avoid viminfo, see https://keyringer.pw/trac/ticket/50 if $EDITOR --help | grep -q -e "^VIM"; then if ! echo $EDITOR | grep -q -- "-i NONE"; then - EDITOR="$EDITOR -S `dirname $LIB`/editors/vim" + EDITOR="$EDITOR -S $SHARE/editors/vim" fi fi diff --git a/share/keyringer/editors/vim b/share/keyringer/editors/vim new file mode 100644 index 0000000..0f877df --- /dev/null +++ b/share/keyringer/editors/vim @@ -0,0 +1,5 @@ +" Use sane defaults for VIM to avoid data leakage +" See https://keyringer.pw/trac/ticket/50 +set nowritebackup +set nobackup +set viminfo="NONE" -- cgit v1.2.3 From 6ae4c3884701f31edbf84666a7b1b76dc01a1068 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 21 Aug 2014 15:37:06 -0300 Subject: Shell completions: fix handling of keyrings with '-' in their names --- ChangeLog | 4 +++- lib/keyringer/completions/bash/keyringer | 3 +-- lib/keyringer/completions/zsh/_keyringer | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index e9be9aa..0905d9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -2014-08-16 - Silvio Rhatto +2014-08-21 - Silvio Rhatto + + Shell completions: fix handling of keyrings with '-' in their names Edit: Unset RELATIVE_PATH before encrypting file diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index 0f2cb2b..b638418 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -69,7 +69,6 @@ _keyringer() { fi # Process config - source $config/config keyrings="`ls --color=never $config | sed -e '/^config$/d' | xargs`" # Available instances @@ -77,7 +76,7 @@ _keyringer() { # The current instance instance="${COMP_WORDS[1]}" - path="`eval echo '$'$instance`" + path="`grep -e "^$instance=" "$config/config" | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'`" # Command completions if [ "${#COMP_WORDS[@]}" == "2" ]; then diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index b4ccdd4..6142949 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -19,9 +19,8 @@ _keyringer() { fi # Process config - source $config/config local keyrings="`ls --color=never $config | sed -e '/^config$/d' | xargs`" - local keyring_path="`eval echo '$'$words[2]`" + local keyring_path="`grep -e "^$words[2]=" "$config/config" | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'`" local instances="`echo $keyrings | sed -e 's/ /$\\\|^/g' -e 's/^/^/' -e 's/$/$/'`" _arguments \ -- cgit v1.2.3 From b3c2760b06af98eb47db82dfdc9cc0f6d8075c86 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 21 Aug 2014 16:43:46 -0300 Subject: Minor zsh completion fixes --- ChangeLog | 1 + lib/keyringer/completions/zsh/_keyringer | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index 0905d9f..e741030 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2014-08-21 - Silvio Rhatto Shell completions: fix handling of keyrings with '-' in their names + and minor zsh fixes. Edit: Unset RELATIVE_PATH before encrypting file diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index 6142949..bd08a8c 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -70,7 +70,7 @@ _keyringer() { case "$words[3]" in recipients) words[5]="$(echo $words[5] | sed -e "s|^/||")" # TODO: avoid leading slash - compadd "$@" $(cd $keyring_path/config/recipients && ls --color=never -p $words[5]'*' 2> /dev/null) + compadd "$@" $(cd $keyring_path/config/recipients && ls --color=never -p $words[5]* 2> /dev/null) ;; genpair) words[5]="$(echo $words[5] | sed -e "s|^/||")" # TODO: avoid leading slash @@ -87,7 +87,7 @@ _keyringer() { esac ;; *) - if [ $words[3] == "git" ]; then + if [[ $words[3] == "git" ]]; then # TODO true fi -- cgit v1.2.3 From 50c8eac52ededab3bc52db3d0d03f0b8aeef8e86 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 21 Aug 2014 17:02:44 -0300 Subject: Shell completions: use KEYRINGER_CHECK_RECIPIENTS=false to avoid fatal errors --- ChangeLog | 6 +++++- lib/keyringer/completions/bash/keyringer | 6 +++--- lib/keyringer/completions/zsh/_keyringer | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/ChangeLog b/ChangeLog index e741030..9a2475a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,11 @@ 2014-08-21 - Silvio Rhatto + Shell completions: use KEYRINGER_CHECK_RECIPIENTS=false to avoid + fatal errors + + Shell completions: minor zsh fixes + Shell completions: fix handling of keyrings with '-' in their names - and minor zsh fixes. Edit: Unset RELATIVE_PATH before encrypting file diff --git a/lib/keyringer/completions/bash/keyringer b/lib/keyringer/completions/bash/keyringer index b638418..27cf919 100644 --- a/lib/keyringer/completions/bash/keyringer +++ b/lib/keyringer/completions/bash/keyringer @@ -82,7 +82,7 @@ _keyringer() { if [ "${#COMP_WORDS[@]}" == "2" ]; then opts="$keyrings" elif [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "$instances"; then - opts="`export KEYRINGER_CHECK_VERSION=false && keyringer $instance commands`" + opts="`export KEYRINGER_CHECK_RECIPIENTS=false && export KEYRINGER_CHECK_VERSION=false && keyringer $instance commands`" elif [ "${#COMP_WORDS[@]}" == "3" ]; then opts="init" elif [ "${#COMP_WORDS[@]}" == "4" ]; then @@ -95,7 +95,7 @@ _keyringer() { ;; ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip|find) 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)" + opts="$(bash -c "set -f && export KEYRINGER_CHECK_RECIPIENTS=false && export KEYRINGER_CHECK_VERSION=false && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; genpair) opts="gpg ssh ssl ssl-self" @@ -118,7 +118,7 @@ _keyringer() { ;; genpair) 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)" + opts="$(bash -c "set -f && export KEYRINGER_CHECK_RECIPIENTS=false && export KEYRINGER_CHECK_VERSION=false && keyringer $instance ls -p -d ${cur}*" 2> /dev/null)" ;; git) # TODO diff --git a/lib/keyringer/completions/zsh/_keyringer b/lib/keyringer/completions/zsh/_keyringer index bd08a8c..ab95c3d 100644 --- a/lib/keyringer/completions/zsh/_keyringer +++ b/lib/keyringer/completions/zsh/_keyringer @@ -36,7 +36,7 @@ _keyringer() { ;; action) if echo $words[2] | grep -qe "$instances"; then - compadd "$@" `KEYRINGER_CHECK_VERSION=false keyringer $words[2] commands` + compadd "$@" `KEYRINGER_CHECK_RECIPIENTS=false KEYRINGER_CHECK_VERSION=false keyringer $words[2] commands` else compadd "$@" "init" fi @@ -51,7 +51,7 @@ _keyringer() { ;; ls|tree|mkdir|encrypt|encrypt-batch|decrypt|edit|append|append-batch|del|rm|recrypt|open|clip|xclip|find) 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) + compadd "$@" $(KEYRINGER_CHECK_RECIPIENTS=false KEYRINGER_CHECK_VERSION=false keyringer $words[2] ls -p -d $words[4]'*' 2> /dev/null) ;; genpair) compadd "$@" gpg ssh ssl ssl-self @@ -74,7 +74,7 @@ _keyringer() { ;; genpair) words[5]="$(echo $words[5] | sed -e "s|^/||")" # TODO: avoid leading slash - compadd "$@" $(KEYRINGER_CHECK_VERSION=false keyringer $words[2] ls -p -d $words[5]'*' 2> /dev/null) + compadd "$@" $(KEYRINGER_CHECK_RECIPIENTS=false KEYRINGER_CHECK_VERSION=false keyringer $words[2] ls -p -d $words[5]'*' 2> /dev/null) ;; git) compadd "$@" $(_keyringer_git_complete $words[4] $words[5]) -- cgit v1.2.3