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,
57 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
58 failure "Unknown option '$1'.
59 Type '$PGRM help' for usage."
68 # check that key ID or file is specified
69 if [ -z "$keyID" ] ; then
70 failure "You must specify the key ID of a key to add, or specify a file to read the key from."
73 # check the trust value
82 failure "Trust value requested ('$trust') was unclear (only 'marginal' or 'full' are supported)."
86 # if file is specified
87 if [ -f "$keyID" -o "$keyID" = '-' ] ; then
88 # load the key from stdin
89 if [ "$keyID" = '-' ] ; then
90 # make a temporary file to hold the key from stdin
92 trap "rm -f $keyID" EXIT
93 log verbose "reading key from stdin..."
96 # load the key from the file
97 elif [ -f "$keyID" ] ; then
98 log verbose "reading key from file '$keyID'..."
101 # check the key is ok as monkeysphere user before loading
102 log debug "checking keys in file..."
103 fingerprint=$(su_monkeysphere_user \
104 ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
106 if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
107 failure "There was not exactly one gpg key in the file."
111 gpg_sphere "--import" <"$keyID" \
112 || failure "could not read key from '$keyID'"
114 # else, get the key from the keyserver
116 log verbose "searching keyserver $KEYSERVER for keyID $keyID..."
117 gpg_sphere "--keyserver $KEYSERVER --recv-key '0x${keyID}!'" \
118 || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
120 # get the full fingerprint of new certifier key
121 log debug "getting fingerprint of certifier key..."
122 fingerprint=$(gpg_sphere "--list-key --with-colons --with-fingerprint 0x${keyID}!" \
123 | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
125 log info "key found:"
126 gpg_sphere "--fingerprint 0x${fingerprint}!"
128 if [ "$PROMPT" = "true" ] ; then
129 echo "Are you sure you want to add the above key as a"
130 read -p "certifier of users on this system? (Y/n) " OK; OK=${OK:-Y}
131 if [ "${OK/y/Y}" != 'Y' ] ; then
132 failure "Identity certifier not added."
135 log debug "adding key without prompting."
139 # export the key to the core keyring so that the core can sign the
141 log debug "loading key into core keyring..."
142 gpg_sphere "--export 0x${fingerprint}!" | gpg_core --import
144 # edit-key script to ltsign key
145 # NOTE: *all* user IDs will be ltsigned
146 ltsignCommand=$(cat <<EOF
157 # core ltsigns the newly imported certifier key
158 log debug "executing core ltsign script..."
159 if echo "$ltsignCommand" | \
160 gpg_core --command-fd 0 --edit-key "0x${fingerprint}!" ; then
162 # transfer the new sigs back to the sphere keyring
163 gpg_core_sphere_sig_transfer
165 # update the sphere trustdb
166 log debug "updating sphere trustdb..."
167 gpg_sphere "--check-trustdb" 2>&1 | log debug
169 log info "Identity certifier added."
171 failure "Problem adding identify certifier."