Fix issues with GPG default key.

- Remove --no-options gpg option when using GPG key.
- Improve gpg default key tests

To use the default key, ~/.gnupg/gpg.conf needs:
  default-key <keyid>
  default-recipient-self
Or
  default-recipient <keyid>

Otherwise the first key in the keyring is used.
This commit is contained in:
Alexandre Pujol 2017-04-03 13:24:25 +01:00
parent d720e4b2ce
commit c303513be4
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
3 changed files with 17 additions and 7 deletions

View File

@ -0,0 +1,8 @@
# ~/.gnupg/gpg.conf
# Description of options can be found here:
# http://www.gnupg.org/documentation/manuals/gnupg-devel/GPG-Options.html
# GPG Configuration Options
default-key 0B2235E660753AB0475FB3E23DC836481F44B31E
default-recipient-self

View File

@ -196,7 +196,7 @@ test-tomb-recip() {
test-tomb-recip-default() { test-tomb-recip-default() {
notice "wiping all default.tomb* in /tmp" notice "wiping all default.tomb* in /tmp"
rm -f /tmp/default.tomb /tmp/default.tomb.key rm -f /tmp/default.tomb /tmp/default.tomb.key /tmp/default.tmp
notice "Testing tomb with the default recipient" notice "Testing tomb with the default recipient"
res=0 res=0
@ -207,6 +207,8 @@ test-tomb-recip-default() {
tt lock /tmp/default.tomb -k /tmp/default.tomb.key \ tt lock /tmp/default.tomb -k /tmp/default.tomb.key \
--ignore-swap --unsafe -g --ignore-swap --unsafe -g
{ test $? = 0 } || { res=1 } { test $? = 0 } || { res=1 }
gpg -d --status-fd 2 /tmp/default.tomb.key 1> /dev/null 2> /tmp/default.tmp
[[ -z "$(grep 'Tomb Test 2' /tmp/default.tmp)" ]] && { res=1 }
{ test $res = 0 } && { results+=(recip-default SUCCESS) } { test $res = 0 } && { results+=(recip-default SUCCESS) }
} }

12
tomb
View File

@ -995,7 +995,7 @@ gpg_decrypt() {
local gpgpass="$1\n$TOMBKEY" local gpgpass="$1\n$TOMBKEY"
local tmpres ret local tmpres ret
typeset -a gpgopt typeset -a gpgopt
gpgpopt=(--batch --no-tty --passphrase-fd 0) gpgpopt=(--batch --no-tty --passphrase-fd 0 --no-options)
{ option_is_set -g } && { { option_is_set -g } && {
gpgpass="$TOMBKEY" gpgpass="$TOMBKEY"
@ -1015,7 +1015,7 @@ gpg_decrypt() {
[[ $gpgver == "1.4.11" ]] && { [[ $gpgver == "1.4.11" ]] && {
_verbose "GnuPG is version 1.4.11 - adopting status fix." _verbose "GnuPG is version 1.4.11 - adopting status fix."
TOMBSECRET=`print - "$gpgpass" | \ TOMBSECRET=`print - "$gpgpass" | \
gpg --decrypt ${gpgpopt[@]} --no-options` gpg --decrypt ${gpgpopt[@]}`
ret=$? ret=$?
unset gpgpass unset gpgpass
return $ret return $ret
@ -1024,7 +1024,7 @@ gpg_decrypt() {
_tmp_create _tmp_create
tmpres=$TOMBTMP tmpres=$TOMBTMP
TOMBSECRET=`print - "$gpgpass" | \ TOMBSECRET=`print - "$gpgpass" | \
gpg --decrypt ${gpgpopt[@]} --no-options \ gpg --decrypt ${gpgpopt[@]} \
--status-fd 2 --no-mdc-warning --no-permission-warning \ --status-fd 2 --no-mdc-warning --no-permission-warning \
--no-secmem-warning 2> $tmpres` --no-secmem-warning 2> $tmpres`
unset gpgpass unset gpgpass
@ -1329,15 +1329,15 @@ gen_key() {
# Set gpg inputs and options # Set gpg inputs and options
gpgpass="${tombpass}\n$TOMBSECRET" gpgpass="${tombpass}\n$TOMBSECRET"
gpgopt=(--passphrase-fd 0 --symmetric) gpgopt=(--passphrase-fd 0 --symmetric --no-options)
opt='-n' opt='-n'
} }
_tmp_create _tmp_create
local tmpres=$TOMBTMP local tmpres=$TOMBTMP
print $opt - "$gpgpass" \ print $opt - "$gpgpass" \
| gpg --openpgp --force-mdc --cipher-algo ${algo} --batch \ | gpg --openpgp --force-mdc --cipher-algo ${algo} \
--no-options --no-tty ${gpgopt[@]} \ --batch --no-tty ${gpgopt[@]} \
--status-fd 2 -o - --armor 2> $tmpres --status-fd 2 -o - --armor 2> $tmpres
unset gpgpass unset gpgpass
# check result of gpg operation # check result of gpg operation