2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere authentication add-certifier subcommand
6 # This function adds a certifier whose signatures will be used to
7 # calculate validity of keys used to connect to user accounts on the
8 # server. The specified certifier key is first retrieved from the Web
9 # of Trust with the monkeysphere-user-controlled gpg_sphere keyring.
10 # Once then new key is retrieved, it is imported into the core
11 # keyring. The gpg_core then ltsigns the key with the desired trust
12 # level, and then the key is exported back to the gpg_sphere keyring.
13 # The gpg_sphere has ultimate owner trust of the core key, so the core
14 # ltsigs on the new certifier key can then be used by gpg_sphere
15 # calculate validity for keys inserted in the authorized_keys file.
17 # This is all to keep the monkeysphere user that connects to the
18 # keyservers from accessing the core secret key.
20 # The monkeysphere scripts are written by:
21 # Jameson Rollins <jrollins@finestructure.net>
22 # Jamie McClelland <jm@mayfirst.org>
23 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
25 # They are Copyright 2008-2009, and are all released under the GPL,
58 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
59 failure "Unknown option '$1'.
60 Type '$PGRM help' for usage."
69 # check that key ID or file is specified
70 if [ -z "$keyID" ] ; then
71 failure "You must specify the key ID of a key to add, or specify a file to read the key from."
74 # if file is specified
75 if [ -f "$keyID" -o "$keyID" = '-' ] ; then
76 # load the key from stdin
77 if [ "$keyID" = '-' ] ; then
78 local keyID=$(msmktempfile)
79 trap "rm -f $keyID" EXIT
80 log verbose "reading key from stdin..."
83 # load the key from the file
84 elif [ -f "$keyID" ] ; then
85 log verbose "reading key from file '$keyID'..."
88 # check the key is ok as monkeysphere user before loading
89 log debug "checking keys in file..."
90 fingerprint=$(su_monkeysphere_user \
91 ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
93 if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
94 failure "There was not exactly one gpg key in the file."
98 gpg_sphere "--import" <"$keyID" \
99 || failure "could not read key from '$keyID'"
103 # else, get the key from the keyserver
105 log verbose "searching keyserver $KEYSERVER for keyID $keyID..."
106 gpg_sphere "--keyserver $KEYSERVER --recv-key '0x${keyID}!'" \
107 || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
110 # get the full fingerprint of new certifier key
111 log debug "getting fingerprint of certifier key..."
112 fingerprint=$(gpg_sphere "--list-key --with-colons --with-fingerprint 0x${keyID}!" \
113 | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
115 if [ -z "$fingerprint" ] ; then
116 failure "Key '$keyID' not found."
119 log info "key found:"
120 gpg_sphere "--fingerprint 0x${fingerprint}!"
122 if [ "$PROMPT" = "true" ] ; then
123 echo "Are you sure you want to add the above key as a"
124 read -p "certifier of users on this system? (Y/n) " OK; OK=${OK:-Y}
125 if [ "${OK/y/Y}" != 'Y' ] ; then
126 failure "Identity certifier not added."
129 log debug "adding key without prompting."
132 # export the key to the core keyring so that the core can sign the
134 log debug "exporting retrieved certifier key to core keyring..."
135 gpg_sphere "--export 0x${fingerprint}!" | gpg_core --import
145 failure "Trust value requested ('$trust') was unclear (only 'marginal' or 'full' are supported)."
149 # edit-key script to ltsign key
150 # NOTE: *all* user IDs will be ltsigned
151 ltsignCommand=$(cat <<EOF
162 # core ltsigns the newly imported certifier key
163 log debug "executing core ltsign script..."
164 if echo "$ltsignCommand" | \
165 gpg_core --command-fd 0 --edit-key "0x${fingerprint}!" ; then
167 # transfer the new sigs back to the sphere keyring
168 gpg_core_sphere_sig_transfer
170 # update the sphere trustdb
171 log debug "updating sphere trustdb..."
172 gpg_sphere "--check-trustdb" 2>&1 | log debug
174 log info "Identity certifier added."
176 failure "Problem adding identify certifier."