password-store

Simple password manager using gpg and ordinary unix directories
git clone https://git.zx2c4.com/password-store
Log | Files | Refs | README | LICENSE

commit 67abc395d981b9b4a5f71fc00a8807195e2865e3
parent 6eafaf31325dd18404e942f453130dd7a6e92f77
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date:   Wed, 23 Apr 2014 04:58:57 +0200

tests: add key resolution functions

Diffstat:
Mtests/setup.sh | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/tests/setup.sh b/tests/setup.sh @@ -29,6 +29,8 @@ fi export GNUPGHOME=$(pwd)"/gnupg/" chmod 700 "$GNUPGHOME" export PASSWORD_STORE_KEY="3DEEA12D" # "Password-store Test Key" +GPG="gpg" +which gpg2 &>/dev/null && GPG="gpg2" # We don't want to use any running agent. # We want an agent to appear to pass to be running. @@ -164,5 +166,35 @@ verify_password() { test_cmp "$expectedfile" "$actualfile" } +# canonicalize_gpg_keys() +# +# Resolves key names to key ids. +# +# Arguments: <key name>... +# Returns: 0, and echos keys on new lines +canonicalize_gpg_keys() { + $GPG --list-keys --keyid-format long "$@" | sed -n 's/sub *.*\/\([A-F0-9]\{16\}\) .*/\1/p' | sort -u +} + +# gpg_keys_from_encrypted_file() +# +# Finds keys used to encrypt a .gpg file. +# +# Arguments: <gpg file> +# Returns 0, and echos keys on new lines +gpg_keys_from_encrypted_file() { + $GPG -v --list-only --keyid-format long "$1" 2>&1 | cut -d ' ' -f 5 | sort -u +} + +# gpg_keys_from_group() +# +# Finds keys used in gpg.conf group +# +# Arguments: <group> +# Returns: 0, and echos keys on new lines, which might be non-canonical +gpg_keys_from_group() { + $GPG --list-config --with-colons | sed -n "s/^cfg:group:$1:\\(.*\\)/\\1/p" | tr ';' '\n' +} + # Initialize the test harness . ./sharness.sh