summaryrefslogtreecommitdiff
path: root/src/monkeysphere-authentication
blob: 2d6079f11a57396780d972af97a5f03a2b29f806 (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 MATMPDIR
  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. gpg "$@"
  60. }
  61. # function to interact with the gpg sphere keyring
  62. # FIXME: this function requires only a single argument because of
  63. # problems with quote expansion. this needs to be fixed/improved.
  64. gpg_sphere() {
  65. GNUPGHOME="$GNUPGHOME_SPHERE"
  66. export GNUPGHOME
  67. su_monkeysphere_user "gpg $@"
  68. }
  69. # load the core fingerprint into the fingerprint variable, using the
  70. # gpg host secret key
  71. core_fingerprint() {
  72. log debug "determining core key fingerprint..."
  73. gpg_core --quiet --list-secret-key \
  74. --with-colons --fixed-list-mode --with-fingerprint \
  75. | grep ^fpr: | cut -d: -f10
  76. }
  77. # export signatures from core to sphere
  78. gpg_core_sphere_sig_transfer() {
  79. log debug "exporting core local sigs to sphere..."
  80. gpg_core --export-options export-local-sigs --export | \
  81. gpg_sphere "--import-options import-local-sigs --import"
  82. }
  83. ########################################################################
  84. # MAIN
  85. ########################################################################
  86. # unset variables that should be defined only in config file
  87. unset KEYSERVER
  88. unset AUTHORIZED_USER_IDS
  89. unset RAW_AUTHORIZED_KEYS
  90. unset MONKEYSPHERE_USER
  91. # load configuration file
  92. [ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG"
  93. # set empty config variable with ones from the environment, or with
  94. # defaults
  95. LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
  96. KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
  97. AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
  98. RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
  99. MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
  100. # other variables
  101. CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
  102. REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
  103. GNUPGHOME_CORE=${MONKEYSPHERE_GNUPGHOME_CORE:="${MADATADIR}/core"}
  104. GNUPGHOME_SPHERE=${MONKEYSPHERE_GNUPGHOME_SPHERE:="${MADATADIR}/sphere"}
  105. CORE_KEYLENGTH=${MONKEYSPHERE_CORE_KEYLENGTH:="2048"}
  106. # export variables needed in su invocation
  107. export DATE
  108. export MODE
  109. export LOG_LEVEL
  110. export MONKEYSPHERE_USER
  111. export KEYSERVER
  112. export CHECK_KEYSERVER
  113. export REQUIRED_USER_KEY_CAPABILITY
  114. export GNUPGHOME_CORE
  115. export GNUPGHOME_SPHERE
  116. export GNUPGHOME
  117. export CORE_KEYLENGTH
  118. # get subcommand
  119. COMMAND="$1"
  120. [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
  121. shift
  122. case $COMMAND in
  123. 'setup'|'setup'|'s')
  124. source "${MASHAREDIR}/setup"
  125. setup "$@"
  126. ;;
  127. 'update-users'|'update-user'|'u')
  128. source "${MASHAREDIR}/update_users"
  129. update_users "$@"
  130. ;;
  131. 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
  132. source "${MASHAREDIR}/add_certifier"
  133. add_certifier "$@"
  134. ;;
  135. 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
  136. source "${MASHAREDIR}/remove_certifier"
  137. remove_certifier "$@"
  138. ;;
  139. 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
  140. source "${MASHAREDIR}/list_certifiers"
  141. list_certifiers "$@"
  142. ;;
  143. 'expert')
  144. SUBCOMMAND="$1"
  145. shift
  146. case "$SUBCOMMAND" in
  147. 'help'|'h'|'?')
  148. cat <<EOF
  149. usage: $PGRM expert <subcommand> [options] [args]
  150. expert subcommands:
  151. diagnostics (d) monkeysphere authentication status
  152. gpg-cmd CMD execute gpg command
  153. EOF
  154. ;;
  155. 'diagnostics'|'d')
  156. source "${MASHAREDIR}/diagnostics"
  157. diagnostics
  158. ;;
  159. 'gpg-cmd')
  160. gpg_sphere "$@"
  161. ;;
  162. *)
  163. failure "Unknown expert subcommand: '$COMMAND'
  164. Type '$PGRM help' for usage."
  165. ;;
  166. esac
  167. ;;
  168. 'version'|'v')
  169. echo "$VERSION"
  170. ;;
  171. '--help'|'help'|'-h'|'h'|'?')
  172. usage
  173. ;;
  174. *)
  175. failure "Unknown command: '$COMMAND'
  176. Type '$PGRM help' for usage."
  177. ;;
  178. esac
  179. exit "$RETURN"