summaryrefslogtreecommitdiff
path: root/src/share/ma/setup
blob: 54ab5be186851c2194b7a38c1965860e59337dff (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere authentication setup 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 2009, and are all released under the GPL,
  11. # version 3 or later.
  12. setup() {
  13. # make all needed directories
  14. mkdir -p "${MADATADIR}"
  15. mkdir -p "${MATMPDIR}"
  16. mkdir -p "${GNUPGHOME_CORE}"
  17. chmod 700 "${GNUPGHOME_CORE}"
  18. mkdir -p "${GNUPGHOME_SPHERE}"
  19. chmod 700 "${GNUPGHOME_SPHERE}"
  20. mkdir -p "${SYSDATADIR}"/authorized_keys
  21. # deliberately replace the config files via truncation
  22. # FIXME: should we be dumping to tmp files and then moving atomically?
  23. log debug "writing core gpg.conf..."
  24. cat >"${GNUPGHOME_CORE}"/gpg.conf <<EOF
  25. # Monkeysphere trust core GnuPG configuration
  26. # This file is maintained by the Monkeysphere software.
  27. # Edits will be overwritten.
  28. no-greeting
  29. EOF
  30. log debug "writing sphere gpg.conf..."
  31. cat >"${GNUPGHOME_SPHERE}"/gpg.conf <<EOF
  32. # Monkeysphere trust sphere GnuPG configuration
  33. # This file is maintained by the Monkeysphere software.
  34. # Edits will be overwritten.
  35. no-greeting
  36. list-options show-uid-validity
  37. EOF
  38. # make sure the monkeysphere user owns everything in the sphere
  39. # gnupghome
  40. log debug "fixing sphere gnupg home ownership..."
  41. chown "$MONKEYSPHERE_USER:$MONKEYSPHERE_USER" "${GNUPGHOME_SPHERE}" "${GNUPGHOME_SPHERE}"/gpg.conf
  42. # get fingerprint of core key. this should be empty on unconfigured systems.
  43. local CORE_FPR=$(core_fingerprint)
  44. log debug "core fingerprint: $CORE_FPR"
  45. if [ -z "$CORE_FPR" ] ; then
  46. log info "setting up Monkeysphere authentication trust core..."
  47. local CORE_UID=$(printf "Monkeysphere authentication trust core UID (random string: %s)" $(head -c21 </dev/urandom | base64))
  48. log debug "generating monkeysphere authentication trust core key ($CORE_KEYLENGTH bits)..."
  49. PEM2OPENPGP_USAGE_FLAGS=certify \
  50. PEM2OPENPGP_NEWKEY=$CORE_KEYLENGTH pem2openpgp "$CORE_UID" \
  51. | gpg_core --import \
  52. || failure "Could not import new key for Monkeysphere authentication trust core"
  53. # get fingerprint of core key. should definitely not be empty at this point
  54. CORE_FPR=$(core_fingerprint)
  55. log debug "core fingerprint: $CORE_FPR"
  56. if [ -z "$CORE_FPR" ] ; then
  57. failure "Failed to create Monkeysphere authentication trust core!"
  58. fi
  59. else
  60. log verbose "Monkeysphere authentication trust core already exists."
  61. fi
  62. # export the core key to the sphere keyring
  63. log debug "exporting core pub key to sphere keyring..."
  64. gpg_core --export | gpg_sphere "--import"
  65. # ensure that the authentication sphere checker has absolute ownertrust on the expected key.
  66. log debug "setting ultimate owner trust on core key in gpg_sphere..."
  67. printf "%s:6:\n" "$CORE_FPR" | gpg_sphere "--import-ownertrust"
  68. gpg_sphere "--export-ownertrust" 2>&1 | log debug
  69. # check the owner trust
  70. log debug "checking gpg_sphere owner trust set properly..."
  71. local ORIG_TRUST
  72. if ORIG_TRUST=$(gpg_sphere "--export-ownertrust" | grep '^[^#]') ; then
  73. if [ "${CORE_FPR}:6:" != "$ORIG_TRUST" ] ; then
  74. failure "Monkeysphere authentication trust sphere should explicitly trust the core. It does not have proper ownertrust settings."
  75. fi
  76. else
  77. failure "Could not get monkeysphere-authentication trust guidelines."
  78. # FIXME: what does this mean? should we suggest how to fix?
  79. fi
  80. # ensure that we're using the extended trust model (1), and that
  81. # our preferences are reasonable (i.e. 3 marginal OR 1 fully
  82. # trusted certifications are sufficient to grant full validity.
  83. log debug "checking trust model for authentication ..."
  84. local TRUST_MODEL=$(gpg_sphere "--with-colons --fixed-list-mode --list-keys" \
  85. | head -n1 | grep "^tru:" | cut -d: -f3,6,7)
  86. log debug "sphere trust model: $TRUST_MODEL"
  87. if [ "$TRUST_MODEL" != '1:3:1' ] ; then
  88. failure "monkeysphere-authentication does not have the expected trust model settings."
  89. # FIXME: what does this mean? should we suggest how to fix?
  90. fi
  91. }