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