summaryrefslogtreecommitdiff
path: root/src/share/ma/diagnostics
blob: 8eca5862fe258a17e3a4dc2f700b0ebd208e2a43 (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere authentication diagnostics subcommand
  4. #
  5. # The monkeysphere scripts are written by:
  6. # Jameson Rollins <jrollins@finestructure.net>
  7. # Jamie McClelland <jm@mayfirst.org>
  8. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  9. #
  10. # They are Copyright 2008-2009, and are all released under the GPL,
  11. # version 3 or later.
  12. # check on the status and validity of the key and public certificates
  13. diagnostics() {
  14. local seckey
  15. local keysfound
  16. local curdate
  17. local warnwindow
  18. local warndate
  19. local create
  20. local expire
  21. local uid
  22. local fingerprint
  23. local badhostkeys
  24. local sshd_config
  25. local problemsfound=0
  26. report_cruft
  27. if ! id monkeysphere >/dev/null ; then
  28. echo "! No monkeysphere user found! Please create a monkeysphere system user with bash as its shell."
  29. problemsfound=$(($problemsfound+1))
  30. fi
  31. if ! [ -d "$SYSDATADIR" ] ; then
  32. echo "! no $SYSDATADIR directory found. Please create it."
  33. problemsfound=$(($problemsfound+1))
  34. fi
  35. echo "Checking for authentication directory..."
  36. if ! [ -d "$MADATADIR" ] ; then
  37. echo "! No authentication data directory found."
  38. echo " - Recommendation: run 'monkeysphere-authentication setup'"
  39. exit
  40. fi
  41. # FIXME: what's the correct, cross-platform way to determine where
  42. # sshd_config lives?
  43. sshd_config=/etc/ssh/sshd_config
  44. seckey=$(gpg_core --list-secret-keys --fingerprint --with-colons --fixed-list-mode)
  45. keysfound=$(echo "$seckey" | grep -c ^sec:)
  46. curdate=$(date +%s)
  47. # warn when anything is 2 months away from expiration
  48. warnwindow='2 months'
  49. warndate=$(advance_date $warnwindow +%s)
  50. echo "Checking core GPG key..."
  51. if (( "$keysfound" < 1 )); then
  52. echo "! No core key found."
  53. echo " - Recommendation: run 'monkeysphere-authentication setup'"
  54. problemsfound=$(($problemsfound+1))
  55. elif (( "$keysfound" > 1 )); then
  56. echo "! More than one core key found?"
  57. # FIXME: recommend a way to resolve this
  58. problemsfound=$(($problemsfound+1))
  59. else
  60. create=$(echo "$seckey" | grep ^sec: | cut -f6 -d:)
  61. expire=$(echo "$seckey" | grep ^sec: | cut -f7 -d:)
  62. fingerprint=$(echo "$seckey" | grep ^fpr: | head -n1 | cut -f10 -d:)
  63. # check for key expiration:
  64. if [ "$expire" ]; then
  65. if (( "$expire" < "$curdate" )); then
  66. echo "! Core key is expired."
  67. echo " - Recommendation: ???"
  68. problemsfound=$(($problemsfound+1))
  69. elif (( "$expire" < "$warndate" )); then
  70. echo "! Core key expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
  71. echo " - Recommendation: ???"
  72. problemsfound=$(($problemsfound+1))
  73. fi
  74. fi
  75. # and weirdnesses:
  76. if [ "$create" ] && (( "$create" > "$curdate" )); then
  77. echo "! Core key was created in the future(?!). Is your clock correct?"
  78. echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
  79. problemsfound=$(($problemsfound+1))
  80. fi
  81. fi
  82. # FIXME: look at the ownership/privileges of the various keyrings,
  83. # directories housing them, etc (what should those values be? can
  84. # we make them as minimal as possible?)
  85. # FIXME: look to see that the ownertrust rules are set properly on the
  86. # sphere keyring
  87. # make sure that at least one identity certifier exists
  88. echo
  89. echo "Checking for Identity Certifiers..."
  90. if ! ( monkeysphere-authentication list-identity-certifiers | egrep '^[A-F0-9]{40}:' >/dev/null ) ; then
  91. echo "! No Identity Certifiers found!"
  92. echo " - Recommendation: once you know who should be able to certify the identities of
  93. connecting users, you should add their key, with:
  94. monkeysphere-authentication add-identity-certifier"
  95. problemsfound=$(($problemsfound+1))
  96. fi
  97. # FIXME: look at the timestamps on the monkeysphere-generated
  98. # authorized_keys files -- warn if they seem out-of-date.
  99. # FIXME: check for a cronjob that updates monkeysphere-generated
  100. # authorized_keys?
  101. echo
  102. echo "Checking for Monkeysphere-enabled public-key authentication for users ..."
  103. # Ensure that User ID authentication is enabled:
  104. if ! grep -q "^AuthorizedKeysFile[[:space:]]\+${SYSDATADIR}/authorized_keys/%u$" "$sshd_config"; then
  105. echo "! $sshd_config does not point to monkeysphere authorized keys."
  106. echo " - Recommendation: add a line to $sshd_config: 'AuthorizedKeysFile ${SYSDATADIR}/authorized_keys/%u'"
  107. problemsfound=$(($problemsfound+1))
  108. fi
  109. if badauthorizedkeys=$(grep -i '^AuthorizedKeysFile' "$sshd_config" | grep -v "^AuthorizedKeysFile[[:space:]]\+${SYSDATADIR}/authorized_keys/%u$") ; then
  110. echo "! $sshd_config refers to non-monkeysphere authorized_keys files:"
  111. echo "$badauthorizedkeys"
  112. echo " - Recommendation: remove the above AuthorizedKeysFile lines from $sshd_config"
  113. problemsfound=$(($problemsfound+1))
  114. fi
  115. if [ "$problemsfound" -gt 0 ]; then
  116. echo "When the above $problemsfound issue"$(if [ "$problemsfound" -eq 1 ] ; then echo " is" ; else echo "s are" ; fi)" resolved, please re-run:"
  117. echo " monkeysphere-authentication diagnostics"
  118. else
  119. echo "Everything seems to be in order!"
  120. fi
  121. }