summaryrefslogtreecommitdiff
path: root/src/monkeysphere-authentication
blob: 71ca91fda48c86fb54cf21df02331074a3f9b5a6 (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@fifthhorseman.net>
  6. # Jamie McClelland <jm@mayfirst.org>
  7. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  8. #
  9. # They are Copyright 2008, and are all released under the GPL, version 3
  10. # or later.
  11. ########################################################################
  12. PGRM=$(basename $0)
  13. SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
  14. export SYSSHAREDIR
  15. . "${SYSSHAREDIR}/common" || exit 1
  16. SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere/authentication"}
  17. export SYSDATADIR
  18. # monkeysphere temp directory, in sysdatadir to enable atomic moves of
  19. # authorized_keys files
  20. MSTMPDIR="${SYSDATADIR}/tmp"
  21. export MSTMPDIR
  22. # UTC date in ISO 8601 format if needed
  23. DATE=$(date -u '+%FT%T')
  24. # unset some environment variables that could screw things up
  25. unset GREP_OPTIONS
  26. # default return code
  27. RETURN=0
  28. ########################################################################
  29. # FUNCTIONS
  30. ########################################################################
  31. usage() {
  32. cat <<EOF >&2
  33. usage: $PGRM <subcommand> [options] [args]
  34. Monkeysphere authentication admin tool.
  35. subcommands:
  36. update-users (u) [USER]... update user authorized_keys files
  37. add-id-certifier (c+) KEYID import and tsign a certification key
  38. --domain (-n) DOMAIN limit ID certifications to DOMAIN
  39. --trust (-t) TRUST trust level of certifier (full)
  40. --depth (-d) DEPTH trust depth for certifier (1)
  41. remove-id-certifier (c-) KEYID remove a certification key
  42. list-id-certifiers (c) list certification keys
  43. expert
  44. diagnostics (d) monkeysphere authentication status
  45. gpg-cmd CMD execute gpg command
  46. version (v) show version number
  47. help (h,?) this help
  48. EOF
  49. }
  50. # function to run command as monkeysphere user
  51. su_monkeysphere_user() {
  52. # if the current user is the monkeysphere user, then just eval
  53. # command
  54. if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
  55. eval "$@"
  56. # otherwise su command as monkeysphere user
  57. else
  58. su "$MONKEYSPHERE_USER" -c "$@"
  59. fi
  60. }
  61. # function to interact with the host gnupg keyring
  62. gpg_host() {
  63. local returnCode
  64. GNUPGHOME="$GNUPGHOME_HOST"
  65. export GNUPGHOME
  66. # NOTE: we supress this warning because we need the monkeysphere
  67. # user to be able to read the host pubring. we realize this might
  68. # be problematic, but it's the simplest solution, without too much
  69. # loss of security.
  70. gpg --no-permission-warning "$@"
  71. returnCode="$?"
  72. # always reset the permissions on the host pubring so that the
  73. # monkeysphere user can read the trust signatures
  74. chgrp "$MONKEYSPHERE_USER" "${GNUPGHOME_HOST}/pubring.gpg"
  75. chmod g+r "${GNUPGHOME_HOST}/pubring.gpg"
  76. return "$returnCode"
  77. }
  78. # function to interact with the authentication gnupg keyring
  79. # FIXME: this function requires basically accepts only a single
  80. # argument because of problems with quote expansion. this needs to be
  81. # fixed/improved.
  82. gpg_authentication() {
  83. GNUPGHOME="$GNUPGHOME_AUTHENTICATION"
  84. export GNUPGHOME
  85. su_monkeysphere_user "gpg $@"
  86. }
  87. # check if user is root
  88. is_root() {
  89. [ $(id -u 2>/dev/null) = '0' ]
  90. }
  91. # check that user is root, for functions that require root access
  92. check_user() {
  93. is_root || failure "You must be root to run this command."
  94. }
  95. # output just key fingerprint
  96. fingerprint_server_key() {
  97. # set the pipefail option so functions fails if can't read sec key
  98. set -o pipefail
  99. gpg_host --list-secret-keys --fingerprint \
  100. --with-colons --fixed-list-mode 2> /dev/null | \
  101. grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null
  102. }
  103. # function to check for host secret key
  104. check_host_keyring() {
  105. fingerprint_server_key >/dev/null \
  106. || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-server gen-key' first."
  107. }
  108. # update authorized_keys for users
  109. update_users() {
  110. if [ "$1" ] ; then
  111. # get users from command line
  112. unames="$@"
  113. else
  114. # or just look at all users if none specified
  115. unames=$(getent passwd | cut -d: -f1)
  116. fi
  117. RETCODE=0
  118. # set mode
  119. MODE="authorized_keys"
  120. # set gnupg home
  121. GNUPGHOME="$GNUPGHOME_AUTHENTICATION"
  122. # check to see if the gpg trust database has been initialized
  123. if [ ! -s "${GNUPGHOME}/trustdb.gpg" ] ; then
  124. failure "GNUPG trust database uninitialized. Please see MONKEYSPHERE-SERVER(8)."
  125. fi
  126. # make sure the authorized_keys directory exists
  127. mkdir -p "${SYSDATADIR}/authorized_keys"
  128. # loop over users
  129. for uname in $unames ; do
  130. # check all specified users exist
  131. if ! id "$uname" >/dev/null ; then
  132. log error "----- unknown user '$uname' -----"
  133. continue
  134. fi
  135. log verbose "----- user: $uname -----"
  136. # make temporary directory
  137. TMPLOC=$(mktemp -d ${MSTMPDIR}/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!"
  138. # trap to delete temporary directory on exit
  139. trap "rm -rf $TMPLOC" EXIT
  140. # create temporary authorized_user_ids file
  141. TMP_AUTHORIZED_USER_IDS="${TMPLOC}/authorized_user_ids"
  142. touch "$TMP_AUTHORIZED_USER_IDS"
  143. # create temporary authorized_keys file
  144. AUTHORIZED_KEYS="${TMPLOC}/authorized_keys"
  145. touch "$AUTHORIZED_KEYS"
  146. # set restrictive permissions on the temporary files
  147. # FIXME: is there a better way to do this?
  148. chmod 0700 "$TMPLOC"
  149. chmod 0600 "$AUTHORIZED_KEYS"
  150. chmod 0600 "$TMP_AUTHORIZED_USER_IDS"
  151. chown -R "$MONKEYSPHERE_USER" "$TMPLOC"
  152. # process authorized_user_ids file
  153. log debug "checking for authorized_user_ids..."
  154. # translating ssh-style path variables
  155. authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS")
  156. if [ -s "$authorizedUserIDs" ] ; then
  157. # check permissions on the authorized_user_ids file path
  158. if check_key_file_permissions "$uname" "$authorizedUserIDs" ; then
  159. # copy user authorized_user_ids file to temporary
  160. # location
  161. cat "$authorizedUserIDs" > "$TMP_AUTHORIZED_USER_IDS"
  162. # export needed variables
  163. export AUTHORIZED_KEYS
  164. export TMP_AUTHORIZED_USER_IDS
  165. # process authorized_user_ids file, as monkeysphere
  166. # user
  167. su_monkeysphere_user \
  168. ". ${SYSSHAREDIR}/common; process_authorized_user_ids $TMP_AUTHORIZED_USER_IDS"
  169. RETURN="$?"
  170. else
  171. log debug "not processing authorized_user_ids."
  172. fi
  173. else
  174. log debug "empty or absent authorized_user_ids file."
  175. fi
  176. # add user-controlled authorized_keys file if specified
  177. # translate ssh-style path variables
  178. rawAuthorizedKeys=$(translate_ssh_variables "$uname" "$RAW_AUTHORIZED_KEYS")
  179. if [ "$rawAuthorizedKeys" != 'none' ] ; then
  180. log debug "checking for raw authorized_keys..."
  181. if [ -s "$rawAuthorizedKeys" ] ; then
  182. # check permissions on the authorized_keys file path
  183. if check_key_file_permissions "$uname" "$rawAuthorizedKeys" ; then
  184. log verbose "adding raw authorized_keys file... "
  185. cat "$rawAuthorizedKeys" >> "$AUTHORIZED_KEYS"
  186. else
  187. log debug "not adding raw authorized_keys file."
  188. fi
  189. else
  190. log debug "empty or absent authorized_keys file."
  191. fi
  192. fi
  193. # move the new authorized_keys file into place
  194. if [ -s "$AUTHORIZED_KEYS" ] ; then
  195. # openssh appears to check the contents of the
  196. # authorized_keys file as the user in question, so the
  197. # file must be readable by that user at least.
  198. # but in general, we don't want the user tampering with
  199. # this file directly, so we'll adopt this approach: Own
  200. # the file by the monkeysphere-server invoker (usually
  201. # root, but should be the same uid that sshd is launched
  202. # as); change the group of the file so that members of the
  203. # user's group can read it.
  204. # FIXME: is there a better way to do this?
  205. chown $(whoami) "$AUTHORIZED_KEYS" && \
  206. chgrp $(id -g "$uname") "$AUTHORIZED_KEYS" && \
  207. chmod g+r "$AUTHORIZED_KEYS" && \
  208. mv -f "$AUTHORIZED_KEYS" "${SYSDATADIR}/authorized_keys/${uname}" || \
  209. {
  210. log error "Failed to install authorized_keys for '$uname'!"
  211. rm -f "${SYSDATADIR}/authorized_keys/${uname}"
  212. # indicate that there has been a failure:
  213. RETURN=1
  214. }
  215. else
  216. rm -f "${SYSDATADIR}/authorized_keys/${uname}"
  217. fi
  218. # unset the trap
  219. trap - EXIT
  220. # destroy temporary directory
  221. rm -rf "$TMPLOC"
  222. done
  223. }
  224. diagnostics() {
  225. # * check on the status and validity of the key and public certificates
  226. local seckey
  227. local keysfound
  228. local curdate
  229. local warnwindow
  230. local warndate
  231. local create
  232. local expire
  233. local uid
  234. local fingerprint
  235. local badhostkeys
  236. local sshd_config
  237. local problemsfound=0
  238. # FIXME: what's the correct, cross-platform answer?
  239. sshd_config=/etc/ssh/sshd_config
  240. seckey=$(gpg_host --list-secret-keys --fingerprint --with-colons --fixed-list-mode)
  241. keysfound=$(echo "$seckey" | grep -c ^sec:)
  242. curdate=$(date +%s)
  243. # warn when anything is 2 months away from expiration
  244. warnwindow='2 months'
  245. warndate=$(advance_date $warnwindow +%s)
  246. if ! id monkeysphere >/dev/null ; then
  247. echo "! No monkeysphere user found! Please create a monkeysphere system user with bash as its shell."
  248. problemsfound=$(($problemsfound+1))
  249. fi
  250. if ! [ -d "$SYSDATADIR" ] ; then
  251. echo "! no $SYSDATADIR directory found. Please create it."
  252. problemsfound=$(($problemsfound+1))
  253. fi
  254. echo "Checking host GPG key..."
  255. if (( "$keysfound" < 1 )); then
  256. echo "! No host key found."
  257. echo " - Recommendation: run 'monkeysphere-server gen-key'"
  258. problemsfound=$(($problemsfound+1))
  259. elif (( "$keysfound" > 1 )); then
  260. echo "! More than one host key found?"
  261. # FIXME: recommend a way to resolve this
  262. problemsfound=$(($problemsfound+1))
  263. else
  264. create=$(echo "$seckey" | grep ^sec: | cut -f6 -d:)
  265. expire=$(echo "$seckey" | grep ^sec: | cut -f7 -d:)
  266. fingerprint=$(echo "$seckey" | grep ^fpr: | head -n1 | cut -f10 -d:)
  267. # check for key expiration:
  268. if [ "$expire" ]; then
  269. if (( "$expire" < "$curdate" )); then
  270. echo "! Host key is expired."
  271. echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
  272. problemsfound=$(($problemsfound+1))
  273. elif (( "$expire" < "$warndate" )); then
  274. echo "! Host key expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
  275. echo " - Recommendation: extend lifetime of key with 'monkeysphere-server extend-key'"
  276. problemsfound=$(($problemsfound+1))
  277. fi
  278. fi
  279. # and weirdnesses:
  280. if [ "$create" ] && (( "$create" > "$curdate" )); then
  281. echo "! Host key was created in the future(?!). Is your clock correct?"
  282. echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
  283. problemsfound=$(($problemsfound+1))
  284. fi
  285. # check for UserID expiration:
  286. echo "$seckey" | grep ^uid: | cut -d: -f6,7,10 | \
  287. while IFS=: read create expire uid ; do
  288. # FIXME: should we be doing any checking on the form
  289. # of the User ID? Should we be unmangling it somehow?
  290. if [ "$create" ] && (( "$create" > "$curdate" )); then
  291. echo "! User ID '$uid' was created in the future(?!). Is your clock correct?"
  292. echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
  293. problemsfound=$(($problemsfound+1))
  294. fi
  295. if [ "$expire" ] ; then
  296. if (( "$expire" < "$curdate" )); then
  297. echo "! User ID '$uid' is expired."
  298. # FIXME: recommend a way to resolve this
  299. problemsfound=$(($problemsfound+1))
  300. elif (( "$expire" < "$warndate" )); then
  301. echo "! User ID '$uid' expires in less than $warnwindow:" $(advance_date $(( $expire - $curdate )) seconds +%F)
  302. # FIXME: recommend a way to resolve this
  303. problemsfound=$(($problemsfound+1))
  304. fi
  305. fi
  306. done
  307. # FIXME: verify that the host key is properly published to the
  308. # keyservers (do this with the non-privileged user)
  309. # FIXME: check that there are valid, non-expired certifying signatures
  310. # attached to the host key after fetching from the public keyserver
  311. # (do this with the non-privileged user as well)
  312. # FIXME: propose adding a revoker to the host key if none exist (do we
  313. # have a way to do that after key generation?)
  314. # Ensure that the ssh_host_rsa_key file is present and non-empty:
  315. echo
  316. echo "Checking host SSH key..."
  317. if [ ! -s "${SYSDATADIR}/ssh_host_rsa_key" ] ; then
  318. echo "! The host key as prepared for SSH (${SYSDATADIR}/ssh_host_rsa_key) is missing or empty."
  319. problemsfound=$(($problemsfound+1))
  320. else
  321. if [ $(ls -l "${SYSDATADIR}/ssh_host_rsa_key" | cut -f1 -d\ ) != '-rw-------' ] ; then
  322. echo "! Permissions seem wrong for ${SYSDATADIR}/ssh_host_rsa_key -- should be 0600."
  323. problemsfound=$(($problemsfound+1))
  324. fi
  325. # propose changes needed for sshd_config (if any)
  326. if ! grep -q "^HostKey[[:space:]]\+${SYSDATADIR}/ssh_host_rsa_key$" "$sshd_config"; then
  327. echo "! $sshd_config does not point to the monkeysphere host key (${SYSDATADIR}/ssh_host_rsa_key)."
  328. echo " - Recommendation: add a line to $sshd_config: 'HostKey ${SYSDATADIR}/ssh_host_rsa_key'"
  329. problemsfound=$(($problemsfound+1))
  330. fi
  331. if badhostkeys=$(grep -i '^HostKey' "$sshd_config" | grep -v "^HostKey[[:space:]]\+${SYSDATADIR}/ssh_host_rsa_key$") ; then
  332. echo "! $sshd_config refers to some non-monkeysphere host keys:"
  333. echo "$badhostkeys"
  334. echo " - Recommendation: remove the above HostKey lines from $sshd_config"
  335. problemsfound=$(($problemsfound+1))
  336. fi
  337. # FIXME: test (with ssh-keyscan?) that the running ssh
  338. # daemon is actually offering the monkeysphere host key.
  339. fi
  340. fi
  341. # FIXME: look at the ownership/privileges of the various keyrings,
  342. # directories housing them, etc (what should those values be? can
  343. # we make them as minimal as possible?)
  344. # FIXME: look to see that the ownertrust rules are set properly on the
  345. # authentication keyring
  346. # FIXME: make sure that at least one identity certifier exists
  347. # FIXME: look at the timestamps on the monkeysphere-generated
  348. # authorized_keys files -- warn if they seem out-of-date.
  349. # FIXME: check for a cronjob that updates monkeysphere-generated
  350. # authorized_keys?
  351. echo
  352. echo "Checking for MonkeySphere-enabled public-key authentication for users ..."
  353. # Ensure that User ID authentication is enabled:
  354. if ! grep -q "^AuthorizedKeysFile[[:space:]]\+${SYSDATADIR}/authorized_keys/%u$" "$sshd_config"; then
  355. echo "! $sshd_config does not point to monkeysphere authorized keys."
  356. echo " - Recommendation: add a line to $sshd_config: 'AuthorizedKeysFile ${SYSDATADIR}/authorized_keys/%u'"
  357. problemsfound=$(($problemsfound+1))
  358. fi
  359. if badauthorizedkeys=$(grep -i '^AuthorizedKeysFile' "$sshd_config" | grep -v "^AuthorizedKeysFile[[:space:]]\+${SYSDATADIR}/authorized_keys/%u$") ; then
  360. echo "! $sshd_config refers to non-monkeysphere authorized_keys files:"
  361. echo "$badauthorizedkeys"
  362. echo " - Recommendation: remove the above AuthorizedKeysFile lines from $sshd_config"
  363. problemsfound=$(($problemsfound+1))
  364. fi
  365. if [ "$problemsfound" -gt 0 ]; then
  366. echo "When the above $problemsfound issue"$(if [ "$problemsfound" -eq 1 ] ; then echo " is" ; else echo "s are" ; fi)" resolved, please re-run:"
  367. echo " monkeysphere-server diagnostics"
  368. else
  369. echo "Everything seems to be in order!"
  370. fi
  371. }
  372. # retrieve key from web of trust, import it into the host keyring, and
  373. # ltsign the key in the host keyring so that it may certify other keys
  374. add_certifier() {
  375. local domain
  376. local trust
  377. local depth
  378. local keyID
  379. local fingerprint
  380. local ltsignCommand
  381. local trustval
  382. # set default values for trust depth and domain
  383. domain=
  384. trust=full
  385. depth=1
  386. # get options
  387. while true ; do
  388. case "$1" in
  389. -n|--domain)
  390. domain="$2"
  391. shift 2
  392. ;;
  393. -t|--trust)
  394. trust="$2"
  395. shift 2
  396. ;;
  397. -d|--depth)
  398. depth="$2"
  399. shift 2
  400. ;;
  401. *)
  402. if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
  403. failure "Unknown option '$1'.
  404. Type '$PGRM help' for usage."
  405. fi
  406. break
  407. ;;
  408. esac
  409. done
  410. keyID="$1"
  411. if [ -z "$keyID" ] ; then
  412. failure "You must specify the key ID of a key to add, or specify a file to read the key from."
  413. fi
  414. if [ -f "$keyID" ] ; then
  415. echo "Reading key from file '$keyID':"
  416. importinfo=$(gpg_authentication "--import" < "$keyID" 2>&1) || failure "could not read key from '$keyID'"
  417. # FIXME: if this is tried when the key database is not
  418. # up-to-date, i got these errors (using set -x):
  419. # ++ su -m monkeysphere -c '\''gpg --import'\''
  420. # Warning: using insecure memory!
  421. # gpg: key D21739E9: public key "Daniel Kahn Gillmor <dkg@fifthhorseman.net>" imported
  422. # gpg: Total number processed: 1
  423. # gpg: imported: 1 (RSA: 1)
  424. # gpg: can'\''t create `/var/monkeysphere/gnupg-host/pubring.gpg.tmp'\'': Permission denied
  425. # gpg: failed to rebuild keyring cache: Permission denied
  426. # gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
  427. # gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
  428. # gpg: next trustdb check due at 2009-01-10'
  429. # + failure 'could not read key from '\''/root/dkg.gpg'\'''
  430. # + echo 'could not read key from '\''/root/dkg.gpg'\'''
  431. keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ )
  432. if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then
  433. failure "Expected there to be a single gpg key in the file."
  434. fi
  435. else
  436. # get the key from the key server
  437. gpg_authentication "--keyserver $KEYSERVER --recv-key '0x${keyID}!'" || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
  438. fi
  439. export keyID
  440. # get the full fingerprint of a key ID
  441. fingerprint=$(gpg_authentication "--list-key --with-colons --with-fingerprint 0x${keyID}!" | \
  442. grep '^fpr:' | grep "$keyID" | cut -d: -f10)
  443. if [ -z "$fingerprint" ] ; then
  444. failure "Key '$keyID' not found."
  445. fi
  446. echo
  447. echo "key found:"
  448. gpg_authentication "--fingerprint 0x${fingerprint}!"
  449. echo "Are you sure you want to add the above key as a"
  450. read -p "certifier of users on this system? (y/N) " OK; OK=${OK:-N}
  451. if [ "${OK/y/Y}" != 'Y' ] ; then
  452. failure "Identity certifier not added."
  453. fi
  454. # export the key to the host keyring
  455. gpg_authentication "--export 0x${fingerprint}!" | gpg_host --import
  456. if [ "$trust" = marginal ]; then
  457. trustval=1
  458. elif [ "$trust" = full ]; then
  459. trustval=2
  460. else
  461. failure "Trust value requested ('$trust') was unclear (only 'marginal' or 'full' are supported)."
  462. fi
  463. # ltsign command
  464. # NOTE: *all* user IDs will be ltsigned
  465. ltsignCommand=$(cat <<EOF
  466. ltsign
  467. y
  468. $trustval
  469. $depth
  470. $domain
  471. y
  472. save
  473. EOF
  474. )
  475. # ltsign the key
  476. if echo "$ltsignCommand" | \
  477. gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
  478. # update the trustdb for the authentication keyring
  479. gpg_authentication "--check-trustdb"
  480. echo
  481. echo "Identity certifier added."
  482. else
  483. failure "Problem adding identify certifier."
  484. fi
  485. }
  486. # delete a certifiers key from the host keyring
  487. remove_certifier() {
  488. local keyID
  489. local fingerprint
  490. keyID="$1"
  491. if [ -z "$keyID" ] ; then
  492. failure "You must specify the key ID of a key to remove."
  493. fi
  494. if gpg_authentication "--no-options --list-options show-uid-validity --keyring ${GNUPGHOME_AUTHENTICATION}/pubring.gpg --list-key 0x${keyID}!" ; then
  495. read -p "Really remove above listed identity certifier? (y/N) " OK; OK=${OK:-N}
  496. if [ "${OK/y/Y}" != 'Y' ] ; then
  497. failure "Identity certifier not removed."
  498. fi
  499. else
  500. failure
  501. fi
  502. # delete the requested key
  503. if gpg_authentication "--delete-key --batch --yes 0x${keyID}!" ; then
  504. # delete key from host keyring as well
  505. gpg_host --delete-key --batch --yes "0x${keyID}!"
  506. # update the trustdb for the authentication keyring
  507. gpg_authentication "--check-trustdb"
  508. echo
  509. echo "Identity certifier removed."
  510. else
  511. failure "Problem removing identity certifier."
  512. fi
  513. }
  514. # list the host certifiers
  515. list_certifiers() {
  516. local keys
  517. local key
  518. # find trusted keys in authentication keychain
  519. keys=$(gpg_authentication "--no-options --list-options show-uid-validity --keyring ${GNUPGHOME_AUTHENTICATION}/pubring.gpg --list-keys --with-colons --fingerprint" | \
  520. grep ^pub: | cut -d: -f2,5 | egrep '^(u|f):' | cut -d: -f2)
  521. # output keys
  522. for key in $keys ; do
  523. gpg_authentication "--no-options --list-options show-uid-validity --keyring ${GNUPGHOME_AUTHENTICATION}/pubring.gpg --list-key --fingerprint $key"
  524. done
  525. }
  526. ########################################################################
  527. # MAIN
  528. ########################################################################
  529. # unset variables that should be defined only in config file
  530. unset KEYSERVER
  531. unset AUTHORIZED_USER_IDS
  532. unset RAW_AUTHORIZED_KEYS
  533. unset MONKEYSPHERE_USER
  534. # load configuration file
  535. [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${SYSCONFIGDIR}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
  536. # set empty config variable with ones from the environment, or with
  537. # defaults
  538. LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
  539. KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
  540. AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
  541. RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
  542. MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
  543. # other variables
  544. CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
  545. REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
  546. GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/gnupg-host"}
  547. GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${SYSDATADIR}/gnupg-authentication"}
  548. # export variables needed in su invocation
  549. export DATE
  550. export MODE
  551. export MONKEYSPHERE_USER
  552. export LOG_LEVEL
  553. export KEYSERVER
  554. export CHECK_KEYSERVER
  555. export REQUIRED_USER_KEY_CAPABILITY
  556. export GNUPGHOME_HOST
  557. export GNUPGHOME_AUTHENTICATION
  558. export GNUPGHOME
  559. # get subcommand
  560. COMMAND="$1"
  561. [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
  562. shift
  563. case $COMMAND in
  564. 'update-users'|'update-user'|'u')
  565. check_user
  566. check_host_keyring
  567. update_users "$@"
  568. ;;
  569. 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
  570. check_user
  571. check_host_keyring
  572. add_certifier "$@"
  573. ;;
  574. 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
  575. check_user
  576. check_host_keyring
  577. remove_certifier "$@"
  578. ;;
  579. 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
  580. check_user
  581. check_host_keyring
  582. list_certifiers "$@"
  583. ;;
  584. 'expert'|'e')
  585. check_user
  586. SUBCOMMAND="$1"
  587. shift
  588. case "$SUBCOMMAND" in
  589. 'diagnostics'|'d')
  590. diagnostics
  591. ;;
  592. 'gpg-cmd')
  593. gpg_authentication "$@"
  594. ;;
  595. *)
  596. failure "Unknown expert subcommand: '$COMMAND'
  597. Type '$PGRM help' for usage."
  598. ;;
  599. esac
  600. ;;
  601. 'version'|'v')
  602. echo "$VERSION"
  603. ;;
  604. '--help'|'help'|'-h'|'h'|'?')
  605. usage
  606. ;;
  607. *)
  608. failure "Unknown command: '$COMMAND'
  609. Type '$PGRM help' for usage."
  610. ;;
  611. esac
  612. exit "$RETURN"