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