Skip to content

Commit

Permalink
Initial commit to support gpg2
Browse files Browse the repository at this point in the history
This is not tested yet but is being committed to separate branch to make testing on systems that use gpg2 easier.
  • Loading branch information
Ryan Harris committed Oct 9, 2017
1 parent db06991 commit 03e0176
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/keychain.spec
/keychain.txt
/keychain.1.orig
/.idea
11 changes: 11 additions & 0 deletions .idea/keychain.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions keychain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version=##VERSION##

PATH="${PATH:-/usr/bin:/bin:/sbin:/usr/sbin:/usr/ucb}"

maintainer="drobbins@funtoo.org"
maintainer="x48rph@gmail.com"
unset mesglog
unset myaction
unset agentsopt
Expand Down Expand Up @@ -54,6 +54,7 @@ absoluteopt=false
systemdopt=false
unset ssh_confirm
unset GREP_OPTIONS
gpg_prog_name="gpg"

BLUE=""
CYAN=""
Expand Down Expand Up @@ -376,7 +377,7 @@ inheritagents() {
inherit_gpg_agent_pid=$(echo "$GPG_AGENT_INFO" | cut -f2 -d:)
# GnuPG v.2.1+ removes $GPG_AGENT_INFO
elif [ -S "${GNUPGHOME:=$HOME/.gnupg}/S.gpg-agent" ]; then
inherit_gpg_agent_pid=$(findpids gpg)
inherit_gpg_agent_pid=$(findpids "${gpg_prog_name}")
inherit_gpg_agent_info="$GNUPGHOME/S.gpg-agent:${inherit_gpg_agent_pid}:1"
fi
fi
Expand Down Expand Up @@ -610,7 +611,7 @@ startagent() {
unset start_gpg_timeout
fi
# the 1.9.x series of gpg spews debug on stderr
start_out=$(gpg-agent --daemon --write-env-file $start_gpg_timeout 2>/dev/null)
start_out=$("${gpg_prog_name}"-agent --daemon --write-env-file $start_gpg_timeout 2>/dev/null)
else
error "I don't know how to start $start_prog-agent (2)"
return 1
Expand All @@ -635,7 +636,7 @@ SSH2_AGENT_PID=$inherit_ssh2_agent_pid; export SSH2_AGENT_PID;"
SSH2_AGENT_PID=$inherit_ssh2_agent_pid; export SSH2_AGENT_PID;"
fi

elif [ "$start_prog" = gpg -a -n "$inherit_gpg_agent_info" ]; then
elif [ "$start_prog" = "${gpg_prog_name}" -a -n "$inherit_gpg_agent_info" ]; then
start_out="GPG_AGENT_INFO=$inherit_gpg_agent_info; export GPG_AGENT_INFO;"

else
Expand Down Expand Up @@ -812,7 +813,7 @@ gpg_listmissing() {
for glm_k in "$@"; do
# Check if this key is known to the agent. Don't know another way...
if echo | env -i GPG_TTY="$GPG_TTY" PATH="$PATH" GPG_AGENT_INFO="$GPG_AGENT_INFO" \
gpg --no-options --use-agent --no-tty --sign --local-user "$glm_k" -o- >/dev/null 2>&1; then
"${gpg_prog_name}" --no-options --use-agent --no-tty --sign --local-user "$glm_k" -o- >/dev/null 2>&1; then
# already know about this key
mesg "Known gpg key: ${CYANN}${glm_k}${OFF}"
continue
Expand Down Expand Up @@ -915,7 +916,7 @@ parse_mykeys() {

# Check for gpg
if wantagent gpg; then
gpg --list-secret-keys "$pm_k" >/dev/null 2>&1
"${gpg_prog_name}" --list-secret-keys "$pm_k" >/dev/null 2>&1
if [ $? -eq 0 ]; then
add_gpgkey "$pm_k" ; continue
fi
Expand Down Expand Up @@ -1148,6 +1149,9 @@ while [ -n "$1" ]; do
--systemd)
systemdopt=true
;;
--gpg2)
gpg_prog_name="gpg2"
;;
--)
shift
IFS="
Expand Down Expand Up @@ -1274,7 +1278,7 @@ if $quickopt; then
elif [ $a = gpg ]; then
# not much way to be quick on this
if [ -n "$gpg_agent_pid" ]; then
case " $(findpids gpg) " in
case " $(findpids "${gpg_prog_name}") " in
*" $gpg_agent_pid "*)
mesg "Found existing gpg-agent: ${CYANN}$gpg_agent_pid${OFF}"
needstart=false ;;
Expand Down Expand Up @@ -1467,7 +1471,7 @@ if wantagent gpg; then

for k in "$@"; do
echo | env LC_ALL="$pinentry_lc_all" \
gpg --no-options --use-agent --no-tty --sign --local-user "$k" -o- >/dev/null 2>&1
"${gpg_prog_name}" --no-options --use-agent --no-tty --sign --local-user "$k" -o- >/dev/null 2>&1
[ $? != 0 ] && tryagain=true
done
$tryagain || break
Expand Down

0 comments on commit 03e0176

Please sign in to comment.