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