2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere authentication add-certifier subcommand
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
11 # They are Copyright 2008-2009, and are all released under the GPL,
14 # retrieve key from web of trust, import it into the host keyring, and
15 # ltsign the key in the host keyring so that it may certify other keys
27 # set default values for trust depth and domain
48 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
49 failure "Unknown option '$1'.
50 Type '$PGRM help' for usage."
58 if [ -z "$keyID" ] ; then
59 failure "You must specify the key ID of a key to add, or specify a file to read the key from."
61 if [ -f "$keyID" ] ; then
62 echo "Reading key from file '$keyID':"
63 importinfo=$(gpg_sphere "--import" < "$keyID" 2>&1) || failure "could not read key from '$keyID'"
64 # FIXME: if this is tried when the key database is not
65 # up-to-date, i got these errors (using set -x):
67 # ++ su -m monkeysphere -c '\''gpg --import'\''
68 # Warning: using insecure memory!
69 # gpg: key D21739E9: public key "Daniel Kahn Gillmor <dkg@fifthhorseman.net>" imported
70 # gpg: Total number processed: 1
71 # gpg: imported: 1 (RSA: 1)
72 # gpg: can'\''t create `/var/monkeysphere/gnupg-host/pubring.gpg.tmp'\'': Permission denied
73 # gpg: failed to rebuild keyring cache: Permission denied
74 # gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
75 # gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
76 # gpg: next trustdb check due at 2009-01-10'
77 # + failure 'could not read key from '\''/root/dkg.gpg'\'''
78 # + echo 'could not read key from '\''/root/dkg.gpg'\'''
80 keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ )
81 if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then
82 failure "Expected there to be a single gpg key in the file."
85 # get the key from the key server
86 gpg_sphere "--keyserver $KEYSERVER --recv-key '0x${keyID}!'" || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
91 # get the full fingerprint of a key ID
92 fingerprint=$(gpg_sphere "--list-key --with-colons --with-fingerprint 0x${keyID}!" | \
93 grep '^fpr:' | grep "$keyID" | cut -d: -f10)
95 if [ -z "$fingerprint" ] ; then
96 failure "Key '$keyID' not found."
101 gpg_sphere "--fingerprint 0x${fingerprint}!"
103 echo "Are you sure you want to add the above key as a"
104 read -p "certifier of users on this system? (y/N) " OK; OK=${OK:-N}
105 if [ "${OK/y/Y}" != 'Y' ] ; then
106 failure "Identity certifier not added."
109 # export the key to the host keyring
110 gpg_sphere "--export 0x${fingerprint}!" | gpg_core --import
112 if [ "$trust" = marginal ]; then
114 elif [ "$trust" = full ]; then
117 failure "Trust value requested ('$trust') was unclear (only 'marginal' or 'full' are supported)."
121 # NOTE: *all* user IDs will be ltsigned
122 ltsignCommand=$(cat <<EOF
134 if echo "$ltsignCommand" | \
135 gpg_core --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
137 # update the trustdb for the authentication keyring
138 gpg_sphere "--check-trustdb"
141 echo "Identity certifier added."
143 failure "Problem adding identify certifier."