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