Skip to content
Snippets Groups Projects
Commit 67abc395 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld
Browse files

tests: add key resolution functions

parent 6eafaf31
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,8 @@ fi ...@@ -29,6 +29,8 @@ fi
export GNUPGHOME=$(pwd)"/gnupg/" export GNUPGHOME=$(pwd)"/gnupg/"
chmod 700 "$GNUPGHOME" chmod 700 "$GNUPGHOME"
export PASSWORD_STORE_KEY="3DEEA12D" # "Password-store Test Key" 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 don't want to use any running agent.
# We want an agent to appear to pass to be running. # We want an agent to appear to pass to be running.
...@@ -164,5 +166,35 @@ verify_password() { ...@@ -164,5 +166,35 @@ verify_password() {
test_cmp "$expectedfile" "$actualfile" 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 # Initialize the test harness
. ./sharness.sh . ./sharness.sh
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment