- elif [ "$MODE" = 'known_hosts' ] ; then
- host=$(echo "$userID" | sed -e "s|ssh://||")
- echo -n "$host "; gpgkey2ssh "$keyID" | sed -e "s/COMMENT/MonkeySphere${DATE}/"
+ echo -n "$host "
+ gpg2ssh "$keyID" | tr -d '\n'
+ echo " MonkeySphere${DATE}"
+}
+
+# convert key from gpg to ssh authorized_keys format
+gpg2authorized_keys() {
+ local userID
+ local keyID
+
+ userID="$1"
+ keyID="$2"
+
+ # NOTE: just in case, the COMMENT can be matched with the
+ # following regexp:
+ # '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
+ gpg2ssh "$keyID" | tr -d '\n'
+ echo " MonkeySphere${DATE} ${userID}"
+}
+
+### GPG UTILITIES
+
+# retrieve all keys with given user id from keyserver
+# FIXME: need to figure out how to retrieve all matching keys
+# (not just first N (5 in this case))
+gpg_fetch_userid() {
+ local userID
+ local returnCode
+
+ if [ "$CHECK_KEYSERVER" != 'true' ] ; then
+ return 0
+ fi
+
+ userID="$1"
+
+ log -n " checking keyserver $KEYSERVER... "
+ echo 1,2,3,4,5 | \
+ gpg --quiet --batch --with-colons \
+ --command-fd 0 --keyserver "$KEYSERVER" \
+ --search ="$userID" > /dev/null 2>&1
+ returnCode="$?"
+ loge "done."
+
+ # if the user is the monkeysphere user, then update the
+ # monkeysphere user's trustdb
+ if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
+ gpg_authentication "--check-trustdb" > /dev/null 2>&1