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