2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere authentication diagnostics 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 # check on the status and validity of the key and public certificates
31 if ! id monkeysphere >/dev/null ; then
32 echo "! No monkeysphere user found! Please create a monkeysphere system user with bash as its shell."
33 problemsfound=$(($problemsfound+1))
36 if ! [ -d "$SYSDATADIR" ] ; then
37 echo "! no $SYSDATADIR directory found. Please create it."
38 problemsfound=$(($problemsfound+1))
41 echo "Checking for authentication directory..."
42 if ! [ -d "$MADATADIR" ] ; then
43 echo "! No authentication data directory found."
44 echo " - Recommendation: run 'monkeysphere-authentication setup'"
48 # FIXME: what's the correct, cross-platform answer?
49 seckey=$(gpg_core --list-secret-keys --fingerprint --with-colons --fixed-list-mode)
50 keysfound=$(echo "$seckey" | grep -c ^sec:)
52 # warn when anything is 2 months away from expiration
54 warndate=$(advance_date $warnwindow +%s)
56 echo "Checking core GPG key..."
57 if (( "$keysfound" < 1 )); then
58 echo "! No core key found."
59 echo " - Recommendation: run 'monkeysphere-authentication setup'"
60 problemsfound=$(($problemsfound+1))
61 elif (( "$keysfound" > 1 )); then
62 echo "! More than one core key found?"
63 # FIXME: recommend a way to resolve this
64 problemsfound=$(($problemsfound+1))
66 create=$(echo "$seckey" | grep ^sec: | cut -f6 -d:)
67 expire=$(echo "$seckey" | grep ^sec: | cut -f7 -d:)
68 fingerprint=$(echo "$seckey" | grep ^fpr: | head -n1 | cut -f10 -d:)
69 # check for key expiration:
70 if [ "$expire" ]; then
71 if (( "$expire" < "$curdate" )); then
72 echo "! Core key is expired."
73 echo " - Recommendation: ???"
74 problemsfound=$(($problemsfound+1))
75 elif (( "$expire" < "$warndate" )); then
76 echo "! Core key expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
77 echo " - Recommendation: ???"
78 problemsfound=$(($problemsfound+1))
83 if [ "$create" ] && (( "$create" > "$curdate" )); then
84 echo "! Core key was created in the future(?!). Is your clock correct?"
85 echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
86 problemsfound=$(($problemsfound+1))
91 # FIXME: look at the ownership/privileges of the various keyrings,
92 # directories housing them, etc (what should those values be? can
93 # we make them as minimal as possible?)
95 # FIXME: look to see that the ownertrust rules are set properly on the
98 # FIXME: make sure that at least one identity certifier exists
100 # FIXME: look at the timestamps on the monkeysphere-generated
101 # authorized_keys files -- warn if they seem out-of-date.
103 # FIXME: check for a cronjob that updates monkeysphere-generated
107 echo "Checking for Monkeysphere-enabled public-key authentication for users ..."
108 # Ensure that User ID authentication is enabled:
109 if ! grep -q "^AuthorizedKeysFile[[:space:]]\+${SYSDATADIR}/authorized_keys/%u$" "$sshd_config"; then
110 echo "! $sshd_config does not point to monkeysphere authorized keys."
111 echo " - Recommendation: add a line to $sshd_config: 'AuthorizedKeysFile ${SYSDATADIR}/authorized_keys/%u'"
112 problemsfound=$(($problemsfound+1))
114 if badauthorizedkeys=$(grep -i '^AuthorizedKeysFile' "$sshd_config" | grep -v "^AuthorizedKeysFile[[:space:]]\+${SYSDATADIR}/authorized_keys/%u$") ; then
115 echo "! $sshd_config refers to non-monkeysphere authorized_keys files:"
116 echo "$badauthorizedkeys"
117 echo " - Recommendation: remove the above AuthorizedKeysFile lines from $sshd_config"
118 problemsfound=$(($problemsfound+1))
121 if [ "$problemsfound" -gt 0 ]; then
122 echo "When the above $problemsfound issue"$(if [ "$problemsfound" -eq 1 ] ; then echo " is" ; else echo "s are" ; fi)" resolved, please re-run:"
123 echo " monkeysphere-authentication diagnostics"
125 echo "Everything seems to be in order!"