summaryrefslogtreecommitdiff
path: root/src/monkeysphere-authentication
blob: 6d2e72cbe34d62aa82843f9121b9a8fa7e5e2297 (plain)
  1. #!/usr/bin/env bash
  2. # monkeysphere-authentication: Monkeysphere authentication admin tool
  3. #
  4. # The monkeysphere scripts are written by:
  5. # Jameson Rollins <jrollins@finestructure.net>
  6. # Jamie McClelland <jm@mayfirst.org>
  7. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  8. # Micah Anderson <micah@riseup.net>
  9. #
  10. # They are Copyright 2008-2009, and are all released under the GPL,
  11. # version 3 or later.
  12. ########################################################################
  13. set -e
  14. PGRM=$(basename $0)
  15. SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
  16. export SYSSHAREDIR
  17. . "${SYSSHAREDIR}/common" || exit 1
  18. SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
  19. export SYSDATADIR
  20. # sharedir for authentication functions
  21. MASHAREDIR="${SYSSHAREDIR}/ma"
  22. # datadir for authentication functions
  23. MADATADIR="${SYSDATADIR}/authentication"
  24. # temp directory to enable atomic moves of authorized_keys files
  25. MATMPDIR="${MADATADIR}/tmp"
  26. export MSTMPDIR
  27. # UTC date in ISO 8601 format if needed
  28. DATE=$(date -u '+%FT%T')
  29. # unset some environment variables that could screw things up
  30. unset GREP_OPTIONS
  31. # default return code
  32. RETURN=0
  33. ########################################################################
  34. # FUNCTIONS
  35. ########################################################################
  36. usage() {
  37. cat <<EOF >&2
  38. usage: $PGRM <subcommand> [options] [args]
  39. Monkeysphere authentication admin tool.
  40. subcommands:
  41. setup (s) setup monkeysphere user authentication
  42. update-users (u) [USER]... update user authorized_keys files
  43. add-id-certifier (c+) KEYID import and tsign a certification key
  44. --domain (-n) DOMAIN limit ID certifications to DOMAIN
  45. --trust (-t) TRUST trust level of certifier (full)
  46. --depth (-d) DEPTH trust depth for certifier (1)
  47. remove-id-certifier (c-) KEYID remove a certification key
  48. list-id-certifiers (c) list certification keys
  49. expert <expert-subcommand> run expert command
  50. expert help expert command help
  51. version (v) show version number
  52. help (h,?) this help
  53. EOF
  54. }
  55. # function to interact with the gpg core keyring
  56. gpg_core() {
  57. GNUPGHOME="$GNUPGHOME_CORE"
  58. export GNUPGHOME
  59. # NOTE: we supress this warning because we need the monkeysphere
  60. # user to be able to read the host pubring. we realize this might
  61. # be problematic, but it's the simplest solution, without too much
  62. # loss of security.
  63. gpg "$@"
  64. }
  65. # function to interact with the gpg sphere keyring
  66. # FIXME: this function requires basically accepts only a single
  67. # argument because of problems with quote expansion. this needs to be
  68. # fixed/improved.
  69. gpg_sphere() {
  70. GNUPGHOME="$GNUPGHOME_SPHERE"
  71. export GNUPGHOME
  72. su_monkeysphere_user "gpg $@"
  73. }
  74. # export signatures from core to sphere
  75. gpg_core_sphere_sig_transfer() {
  76. gpg_core --export-options export-local-sigs --export | \
  77. gpg_sphere --import-options import-local-sigs --import
  78. }
  79. ########################################################################
  80. # MAIN
  81. ########################################################################
  82. # unset variables that should be defined only in config file
  83. unset KEYSERVER
  84. unset AUTHORIZED_USER_IDS
  85. unset RAW_AUTHORIZED_KEYS
  86. unset MONKEYSPHERE_USER
  87. # load configuration file
  88. [ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG"
  89. # set empty config variable with ones from the environment, or with
  90. # defaults
  91. LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
  92. KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
  93. AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
  94. RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
  95. MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
  96. # other variables
  97. CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
  98. REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
  99. GNUPGHOME_CORE=${MONKEYSPHERE_GNUPGHOME_CORE:="${MADATADIR}/core"}
  100. GNUPGHOME_SPHERE=${MONKEYSPHERE_GNUPGHOME_SPHERE:="${MADATADIR}/sphere"}
  101. CORE_KEYLENGTH=${MONKEYSPHERE_CORE_KEYLENGTH:="2048"}
  102. # export variables needed in su invocation
  103. export DATE
  104. export MODE
  105. export LOG_LEVEL
  106. export MONKEYSPHERE_USER
  107. export KEYSERVER
  108. export CHECK_KEYSERVER
  109. export REQUIRED_USER_KEY_CAPABILITY
  110. export GNUPGHOME_CORE
  111. export GNUPGHOME_SPHERE
  112. export GNUPGHOME
  113. export CORE_KEYLENGTH
  114. # get subcommand
  115. COMMAND="$1"
  116. [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
  117. shift
  118. case $COMMAND in
  119. 'setup'|'setup'|'s')
  120. source "${MASHAREDIR}/setup"
  121. setup "$@"
  122. ;;
  123. 'update-users'|'update-user'|'u')
  124. source "${MASHAREDIR}/update_users"
  125. update_users "$@"
  126. ;;
  127. 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
  128. source "${MASHAREDIR}/add_certifier"
  129. add_certifier "$@"
  130. ;;
  131. 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
  132. source "${MASHAREDIR}/remove_certifier"
  133. remove_certifier "$@"
  134. ;;
  135. 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
  136. source "${MASHAREDIR}/list_certifiers"
  137. list_certifiers "$@"
  138. ;;
  139. 'expert')
  140. SUBCOMMAND="$1"
  141. shift
  142. case "$SUBCOMMAND" in
  143. 'help'|'h'|'?')
  144. cat <<EOF
  145. usage: $PGRM expert <subcommand> [options] [args]
  146. expert subcommands:
  147. diagnostics (d) monkeysphere authentication status
  148. gpg-cmd CMD execute gpg command
  149. EOF
  150. ;;
  151. 'diagnostics'|'d')
  152. source "${MASHAREDIR}/diagnostics"
  153. diagnostics
  154. ;;
  155. 'gpg-cmd')
  156. gpg_sphere "$@"
  157. ;;
  158. *)
  159. failure "Unknown expert subcommand: '$COMMAND'
  160. Type '$PGRM help' for usage."
  161. ;;
  162. esac
  163. ;;
  164. 'version'|'v')
  165. echo "$VERSION"
  166. ;;
  167. '--help'|'help'|'-h'|'h'|'?')
  168. usage
  169. ;;
  170. *)
  171. failure "Unknown command: '$COMMAND'
  172. Type '$PGRM help' for usage."
  173. ;;
  174. esac
  175. exit "$RETURN"