summaryrefslogtreecommitdiff
path: root/src/monkeysphere-server
blob: 3259e3360166b0776c49d3e6b344b817587d1820 (plain)
  1. #!/bin/bash
  2. # monkeysphere-server: MonkeySphere server admin tool
  3. #
  4. # The monkeysphere scripts are written by:
  5. # Jameson Rollins <jrollins@fifthhorseman.net>
  6. #
  7. # They are Copyright 2008, and are all released under the GPL, version 3
  8. # or later.
  9. ########################################################################
  10. PGRM=$(basename $0)
  11. SHARE=${MONKEYSPHERE_SHARE:="/usr/share/monkeysphere"}
  12. export SHARE
  13. . "${SHARE}/common" || exit 1
  14. VARLIB="/var/lib/monkeysphere"
  15. export VARLIB
  16. # date in UTF format if needed
  17. DATE=$(date -u '+%FT%T')
  18. # unset some environment variables that could screw things up
  19. unset GREP_OPTIONS
  20. # default return code
  21. RETURN=0
  22. ########################################################################
  23. # FUNCTIONS
  24. ########################################################################
  25. usage() {
  26. cat <<EOF
  27. usage: $PGRM <subcommand> [options] [args]
  28. MonkeySphere server admin tool.
  29. subcommands:
  30. update-users (u) [USER]... update user authorized_keys files
  31. gen-key (g) [NAME[:PORT]] generate gpg key for the server
  32. -l|--length BITS key length in bits (2048)
  33. -e|--expire EXPIRE date to expire
  34. -r|--revoker FINGERPRINT add a revoker
  35. add-hostname (n+) NAME[:PORT] add hostname user ID to server key
  36. revoke-hostname (n-) NAME[:PORT] revoke hostname user ID
  37. show-key (s) output all server host key information
  38. fingerprint (f) output just the key fingerprint
  39. publish-key (p) publish server host key to keyserver
  40. diagnostics (d) report on server monkeysphere status
  41. add-id-certifier (c+) KEYID import and tsign a certification key
  42. -n|--domain DOMAIN limit ID certifications to DOMAIN
  43. -t|--trust TRUST trust level of certifier (full)
  44. -d|--depth DEPTH trust depth for certifier (1)
  45. remove-id-certifier (c-) KEYID remove a certification key
  46. list-id-certifiers (c) list certification keys
  47. gpg-authentication-cmd CMD gnupg-authentication command
  48. -h|--help|help (h,?) this help
  49. EOF
  50. }
  51. su_monkeysphere_user() {
  52. su --preserve-environment "$MONKEYSPHERE_USER" -- -c "$@"
  53. }
  54. # function to interact with the host gnupg keyring
  55. gpg_host() {
  56. local returnCode
  57. GNUPGHOME="$GNUPGHOME_HOST"
  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 --no-permission-warning "$@"
  64. returnCode="$?"
  65. # always reset the permissions on the host pubring so that the
  66. # monkeysphere user can read the trust signatures
  67. chgrp "$MONKEYSPHERE_USER" "${GNUPGHOME_HOST}/pubring.gpg"
  68. chmod g+r "${GNUPGHOME_HOST}/pubring.gpg"
  69. return "$returnCode"
  70. }
  71. # function to interact with the authentication gnupg keyring
  72. # FIXME: this function requires basically accepts only a single
  73. # argument because of problems with quote expansion. this needs to be
  74. # fixed/improved.
  75. gpg_authentication() {
  76. GNUPGHOME="$GNUPGHOME_AUTHENTICATION"
  77. export GNUPGHOME
  78. su_monkeysphere_user "gpg $@"
  79. }
  80. # output key information
  81. show_server_key() {
  82. gpg_host --list-secret-keys --fingerprint
  83. }
  84. # output just key fingerprint
  85. fingerprint_server_key() {
  86. gpg_host --list-secret-keys --fingerprint --with-colons --fixed-list-mode | \
  87. grep '^fpr:' | head -1 | cut -d: -f10
  88. }
  89. # update authorized_keys for users
  90. update_users() {
  91. if [ "$1" ] ; then
  92. # get users from command line
  93. unames="$@"
  94. else
  95. # or just look at all users if none specified
  96. unames=$(getent passwd | cut -d: -f1)
  97. fi
  98. # set mode
  99. MODE="authorized_keys"
  100. # set gnupg home
  101. GNUPGHOME="$GNUPGHOME_AUTHENTICATION"
  102. # check to see if the gpg trust database has been initialized
  103. if [ ! -s "${GNUPGHOME}/trustdb.gpg" ] ; then
  104. failure "GNUPG trust database uninitialized. Please see MONKEYSPHERE-SERVER(8)."
  105. fi
  106. # make sure the authorized_keys directory exists
  107. mkdir -p "${VARLIB}/authorized_keys"
  108. # loop over users
  109. for uname in $unames ; do
  110. # check all specified users exist
  111. if ! getent passwd "$uname" >/dev/null ; then
  112. log "----- unknown user '$uname' -----"
  113. continue
  114. fi
  115. # set authorized_user_ids and raw authorized_keys variables,
  116. # translating ssh-style path variables
  117. authorizedUserIDs=$(translate_ssh_variables "$uname" "$AUTHORIZED_USER_IDS")
  118. rawAuthorizedKeys=$(translate_ssh_variables "$uname" "$RAW_AUTHORIZED_KEYS")
  119. # if neither is found, skip user
  120. if [ ! -s "$authorizedUserIDs" ] ; then
  121. if [ "$rawAuthorizedKeys" = '-' -o ! -s "$rawAuthorizedKeys" ] ; then
  122. continue
  123. fi
  124. fi
  125. log "----- user: $uname -----"
  126. # exit if the authorized_user_ids file is empty
  127. if ! check_key_file_permissions "$uname" "$AUTHORIZED_USER_IDS" ; then
  128. log "Improper permissions on authorized_user_ids file path."
  129. continue
  130. fi
  131. # check permissions on the authorized_keys file path
  132. if ! check_key_file_permissions "$uname" "$RAW_AUTHORIZED_KEYS" ; then
  133. log "Improper permissions on authorized_keys file path path."
  134. continue
  135. fi
  136. # make temporary directory
  137. TMPDIR=$(mktemp -d)
  138. # trap to delete temporary directory on exit
  139. trap "rm -rf $TMPDIR" EXIT
  140. # create temporary authorized_user_ids file
  141. TMP_AUTHORIZED_USER_IDS="${TMPDIR}/authorized_user_ids"
  142. touch "$TMP_AUTHORIZED_USER_IDS"
  143. # create temporary authorized_keys file
  144. AUTHORIZED_KEYS="${TMPDIR}/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 "$TMPDIR"
  149. chmod 0600 "$AUTHORIZED_KEYS"
  150. chmod 0600 "$TMP_AUTHORIZED_USER_IDS"
  151. chown -R "$MONKEYSPHERE_USER" "$TMPDIR"
  152. # if the authorized_user_ids file exists...
  153. if [ -s "$authorizedUserIDs" ] ; then
  154. # copy user authorized_user_ids file to temporary
  155. # location
  156. cat "$authorizedUserIDs" > "$TMP_AUTHORIZED_USER_IDS"
  157. # export needed variables
  158. export AUTHORIZED_KEYS
  159. export TMP_AUTHORIZED_USER_IDS
  160. # process authorized_user_ids file, as monkeysphere
  161. # user
  162. su_monkeysphere_user \
  163. ". ${SHARE}/common; process_authorized_user_ids $TMP_AUTHORIZED_USER_IDS"
  164. RETURN="$?"
  165. fi
  166. # add user-controlled authorized_keys file path if specified
  167. if [ "$rawAuthorizedKeys" != '-' -a -s "$rawAuthorizedKeys" ] ; then
  168. log -n "adding raw authorized_keys file... "
  169. cat "$rawAuthorizedKeys" >> "$AUTHORIZED_KEYS"
  170. loge "done."
  171. fi
  172. # openssh appears to check the contents of the
  173. # authorized_keys file as the user in question, so the
  174. # file must be readable by that user at least.
  175. # FIXME: is there a better way to do this?
  176. chown root "$AUTHORIZED_KEYS"
  177. chgrp $(getent passwd "$uname" | cut -f4 -d:) "$AUTHORIZED_KEYS"
  178. chmod g+r "$AUTHORIZED_KEYS"
  179. # move the resulting authorized_keys file into place
  180. mv -f "$AUTHORIZED_KEYS" "${VARLIB}/authorized_keys/${uname}"
  181. # destroy temporary directory
  182. rm -rf "$TMPDIR"
  183. done
  184. }
  185. # generate server gpg key
  186. gen_key() {
  187. local keyType
  188. local keyLength
  189. local keyUsage
  190. local keyExpire
  191. local revoker
  192. local hostName
  193. local userID
  194. local keyParameters
  195. local fingerprint
  196. # set default key parameter values
  197. keyType="RSA"
  198. keyLength="2048"
  199. keyUsage="auth"
  200. keyExpire=
  201. revoker=
  202. # get options
  203. TEMP=$(getopt -o e:l:r -l expire:,length:,revoker: -n "$PGRM" -- "$@")
  204. if [ $? != 0 ] ; then
  205. exit 1
  206. fi
  207. # Note the quotes around `$TEMP': they are essential!
  208. eval set -- "$TEMP"
  209. while true ; do
  210. case "$1" in
  211. -l|--length)
  212. keyLength="$2"
  213. shift 2
  214. ;;
  215. -e|--expire)
  216. keyExpire="$2"
  217. shift 2
  218. ;;
  219. -r|--revoker)
  220. revoker="$2"
  221. shift 2
  222. ;;
  223. --)
  224. shift
  225. ;;
  226. *)
  227. break
  228. ;;
  229. esac
  230. done
  231. hostName=${1:-$(hostname --fqdn)}
  232. userID="ssh://${hostName}"
  233. # check for presense of key with user ID
  234. if gpg_host --list-key ="$userID" > /dev/null 2>&1 ; then
  235. failure "Key for '$userID' already exists"
  236. fi
  237. # prompt about key expiration if not specified
  238. if [ -z "$keyExpire" ] ; then
  239. cat <<EOF
  240. Please specify how long the key should be valid.
  241. 0 = key does not expire
  242. <n> = key expires in n days
  243. <n>w = key expires in n weeks
  244. <n>m = key expires in n months
  245. <n>y = key expires in n years
  246. EOF
  247. while [ -z "$keyExpire" ] ; do
  248. read -p "Key is valid for? (0) " keyExpire
  249. if ! test_gpg_expire ${keyExpire:=0} ; then
  250. echo "invalid value"
  251. unset keyExpire
  252. fi
  253. done
  254. elif ! test_gpg_expire "$keyExpire" ; then
  255. failure "invalid key expiration value '$keyExpire'."
  256. fi
  257. # set key parameters
  258. keyParameters=$(cat <<EOF
  259. Key-Type: $keyType
  260. Key-Length: $keyLength
  261. Key-Usage: $keyUsage
  262. Name-Real: $userID
  263. Expire-Date: $keyExpire
  264. EOF
  265. )
  266. # add the revoker field if specified
  267. # FIXME: the "1:" below assumes that $REVOKER's key is an RSA key.
  268. # FIXME: key is marked "sensitive"? is this appropriate?
  269. if [ "$revoker" ] ; then
  270. keyParameters="${keyParameters}"$(cat <<EOF
  271. Revoker: 1:$revoker sensitive
  272. EOF
  273. )
  274. fi
  275. echo "The following key parameters will be used for the host private key:"
  276. echo "$keyParameters"
  277. read -p "Generate key? (Y/n) " OK; OK=${OK:=Y}
  278. if [ ${OK/y/Y} != 'Y' ] ; then
  279. failure "aborting."
  280. fi
  281. # add commit command
  282. keyParameters="${keyParameters}"$(cat <<EOF
  283. %commit
  284. %echo done
  285. EOF
  286. )
  287. log "generating server key..."
  288. echo "$keyParameters" | gpg_host --batch --gen-key
  289. # output the server fingerprint
  290. fingerprint_server_key "=${userID}"
  291. # find the key fingerprint of the newly generated key
  292. fingerprint=$(fingerprint_server_key)
  293. # export host ownertrust to authentication keyring
  294. log "setting ultimate owner trust for server key..."
  295. echo "${fingerprint}:6:" | gpg_authentication "--import-ownertrust"
  296. # translate the private key to ssh format, and export to a file
  297. # for sshs usage.
  298. # NOTE: assumes that the primary key is the proper key to use
  299. (umask 077 && \
  300. gpg_host --export-secret-key "$fingerprint" | \
  301. openpgp2ssh "$fingerprint" > "${VARLIB}/ssh_host_rsa_key")
  302. log "Private SSH host key output to file: ${VARLIB}/ssh_host_rsa_key"
  303. }
  304. # add hostname user ID to server key
  305. add_hostname() {
  306. if [ -z "$1" ] ; then
  307. failure "You must specify a hostname to add."
  308. fi
  309. userID="ssh://${1}"
  310. if [ "$(gpg_host --list-key "=${userID}")" ] ; then
  311. failure "Host userID '$userID' already exists."
  312. fi
  313. fingerprint=$(fingerprint_server_key)
  314. adduidCommand=$(cat <<EOF
  315. adduid
  316. $userID
  317. O
  318. save
  319. EOF
  320. )
  321. # add uid
  322. echo "$adduidCommand" | gpg_host --quiet --command-fd 0 --edit-key "$fingerprint"
  323. echo "NOTE: new host userID has not been published."
  324. echo "Use '$PGRM publish-key' to publish these changes."
  325. }
  326. # revoke hostname user ID to server key
  327. revoke_hostname() {
  328. if [ -z "$1" ] ; then
  329. failure "You must specify a hostname to revoke."
  330. fi
  331. failure "Sorry, not yet implemented."
  332. echo "NOTE: host userID revokation has not been published."
  333. echo "Use '$PGRM publish-key' to publish these changes."
  334. }
  335. # publish server key to keyserver
  336. publish_server_key() {
  337. read -p "Really publish host key to $KEYSERVER? (y/N) " OK; OK=${OK:=N}
  338. if [ ${OK/y/Y} != 'Y' ] ; then
  339. failure "aborting."
  340. fi
  341. # find the key fingerprint
  342. fingerprint=$(fingerprint_server_key)
  343. # publish host key
  344. # FIXME: need to figure out better way to identify host key
  345. # dummy command so as not to publish fakes keys during testing
  346. # eventually:
  347. gpg_authentication "--keyserver $KEYSERVER --send-keys $fingerprint"
  348. }
  349. diagnostics() {
  350. # * check on the status and validity of the key and public certificates
  351. local seckey
  352. local keysfound
  353. local curdate
  354. local warnwindow
  355. local warndate
  356. local create
  357. local expire
  358. local uid
  359. local fingerprint
  360. local badhostkeys
  361. seckey=$(fingerprint_server_key)
  362. keysfound=$(echo "$seckey" | grep -c ^sec:)
  363. curdate=$(date +%s)
  364. # warn when anything is 2 months away from expiration
  365. warnwindow='2 months'
  366. warndate=$(date +%s -d "$warnwindow")
  367. echo "Checking host GPG key..."
  368. if (( "$keysfound" < 1 )); then
  369. echo "! No host key found."
  370. echo " - Recommendation: run 'monkeysphere-server gen-key'"
  371. elif (( "$keysfound" > 1 )); then
  372. echo "! More than one host key found?"
  373. # FIXME: recommend a way to resolve this
  374. else
  375. create=$(echo "$seckey" | grep ^sec: | cut -f6 -d:)
  376. expire=$(echo "$seckey" | grep ^sec: | cut -f7 -d:)
  377. fingerprint=$(echo "$seckey" | grep ^fpr: | head -n1 | cut -f10 -d:)
  378. # check for key expiration:
  379. if [ "$expire" ]; then
  380. if (( "$expire" < "$curdate" )); then
  381. echo "! Host key is expired."
  382. # FIXME: recommend a way to resolve this other than re-keying?
  383. elif (( "$expire" < "$warndate" )); then
  384. echo "! Host key expires in less than $warnwindow:" $(date -d "$(( $expire - $curdate )) seconds" +%F)
  385. # FIXME: recommend a way to resolve this?
  386. fi
  387. fi
  388. # and weirdnesses:
  389. if [ "$create" ] && (( "$create" > "$curdate" )); then
  390. echo "! Host key was created in the future(?!). Is your clock correct?"
  391. echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
  392. fi
  393. # check for UserID expiration:
  394. echo "$seckey" | grep ^uid: | cut -d: -f6,7,10 | \
  395. while IFS=: read create expire uid ; do
  396. # FIXME: should we be doing any checking on the form
  397. # of the User ID? Should we be unmangling it somehow?
  398. if [ "$create" ] && (( "$create" > "$curdate" )); then
  399. echo "! User ID '$uid' was created in the future(?!). Is your clock correct?"
  400. echo " - Recommendation: Check clock ($(date +%F_%T)); use NTP?"
  401. fi
  402. if [ "$expire" ] ; then
  403. if (( "$expire" < "$curdate" )); then
  404. echo "! User ID '$uid' is expired."
  405. # FIXME: recommend a way to resolve this
  406. elif (( "$expire" < "$warndate" )); then
  407. echo "! User ID '$uid' expires in less than $warnwindow:" $(date -d "$(( $expire - $curdate )) seconds" +%F)
  408. # FIXME: recommend a way to resolve this
  409. fi
  410. fi
  411. done
  412. # FIXME: verify that the host key is properly published to the
  413. # keyservers (do this with the non-privileged user)
  414. # FIXME: check that there are valid, non-expired certifying signatures
  415. # attached to the host key after fetching from the public keyserver
  416. # (do this with the non-privileged user as well)
  417. # FIXME: propose adding a revoker to the host key if none exist (do we
  418. # have a way to do that after key generation?)
  419. # Ensure that the ssh_host_rsa_key file is present and non-empty:
  420. echo "Checking host SSH key..."
  421. if [ ! -s "${VARLIB}/ssh_host_rsa_key" ] ; then
  422. echo "! The host key as prepared for SSH (${VARLIB}/ssh_host_rsa_key) is missing or empty."
  423. else
  424. if [ $(stat -c '%a' "${VARLIB}/ssh_host_rsa_key") != 600 ] ; then
  425. echo "! Permissions seem wrong for ${VARLIB}/ssh_host_rsa_key -- should be 0600."
  426. fi
  427. # propose changes needed for sshd_config (if any)
  428. if ! grep -q "^HostKey[[:space:]]\+${VARLIB}/ssh_host_rsa_key$" /etc/ssh/sshd_config; then
  429. echo "! /etc/ssh/sshd_config does not point to the monkeysphere host key (${VARLIB}/ssh_host_rsa_key)."
  430. echo " - Recommendation: add a line to /etc/ssh/sshd_config: 'HostKey ${VARLIB}/ssh_host_rsa_key'"
  431. fi
  432. if badhostkeys=$(grep -i '^HostKey' | grep -q -v "^HostKey[[:space:]]\+${VARLIB}/ssh_host_rsa_key$") ; then
  433. echo "! /etc/sshd_config refers to some non-monkeysphere host keys:"
  434. echo "$badhostkeys"
  435. echo " - Recommendation: remove the above HostKey lines from /etc/ssh/sshd_config"
  436. fi
  437. fi
  438. fi
  439. # FIXME: look at the ownership/privileges of the various keyrings,
  440. # directories housing them, etc (what should those values be? can
  441. # we make them as minimal as possible?)
  442. # FIXME: look to see that the ownertrust rules are set properly on the
  443. # authentication keyring
  444. # FIXME: make sure that at least one identity certifier exists
  445. echo "Checking for MonkeySphere-enabled public-key authentication for users ..."
  446. # Ensure that User ID authentication is enabled:
  447. if ! grep -q "^AuthorizedKeysFile[[:space:]]\+${VARLIB}/authorized_keys/%u$" /etc/ssh/sshd_config; then
  448. echo "! /etc/ssh/sshd_config does not point to monkeysphere authorized keys."
  449. echo " - Recommendation: add a line to /etc/ssh/sshd_config: 'AuthorizedKeysFile ${VARLIB}/authorized_keys/%u'"
  450. fi
  451. if badauthorizedkeys=$(grep -i '^AuthorizedKeysFile' | grep -q -v "^AuthorizedKeysFile[[:space:]]\+${VARLIB}/authorized_keys/%u$") ; then
  452. echo "! /etc/sshd_config refers to non-monkeysphere authorized_keys files:"
  453. echo "$badauthorizedkeys"
  454. echo " - Recommendation: remove the above AuthorizedKeysFile lines from /etc/ssh/sshd_config"
  455. fi
  456. }
  457. # retrieve key from web of trust, import it into the host keyring, and
  458. # ltsign the key in the host keyring so that it may certify other keys
  459. add_certifier() {
  460. local domain
  461. local trust
  462. local depth
  463. local keyID
  464. local fingerprint
  465. local ltsignCommand
  466. local trustval
  467. # set default values for trust depth and domain
  468. domain=
  469. trust=full
  470. depth=1
  471. # get options
  472. TEMP=$(getopt -o n:t:d: -l domain:,trust:,depth: -n "$PGRM" -- "$@")
  473. if [ $? != 0 ] ; then
  474. exit 1
  475. fi
  476. # Note the quotes around `$TEMP': they are essential!
  477. eval set -- "$TEMP"
  478. while true ; do
  479. case "$1" in
  480. -n|--domain)
  481. domain="$2"
  482. shift 2
  483. ;;
  484. -t|--trust)
  485. trust="$2"
  486. shift 2
  487. ;;
  488. -d|--depth)
  489. depth="$2"
  490. shift 2
  491. ;;
  492. --)
  493. shift
  494. ;;
  495. *)
  496. break
  497. ;;
  498. esac
  499. done
  500. keyID="$1"
  501. if [ -z "$keyID" ] ; then
  502. failure "You must specify the key ID of a key to add."
  503. fi
  504. export keyID
  505. # get the key from the key server
  506. gpg_authentication "--keyserver $KEYSERVER --recv-key '$keyID'"
  507. # get the full fingerprint of a key ID
  508. fingerprint=$(gpg_authentication "--list-key --with-colons --with-fingerprint $keyID" | \
  509. grep '^fpr:' | grep "$keyID" | cut -d: -f10)
  510. echo "key found:"
  511. gpg_authentication "--fingerprint $fingerprint"
  512. echo "Are you sure you want to add this key as a certifier of"
  513. read -p "users on this system? (y/N) " OK; OK=${OK:-N}
  514. if [ "${OK/y/Y}" != 'Y' ] ; then
  515. failure "aborting."
  516. fi
  517. # export the key to the host keyring
  518. gpg_authentication "--export $keyID" | gpg_host --import
  519. if [ "$trust" == marginal ]; then
  520. trustval=1
  521. elif [ "$trust" == full ]; then
  522. trustval=2
  523. else
  524. failure "trust value requested ('$trust') was unclear (only 'marginal' or 'full' are supported)"
  525. fi
  526. # ltsign command
  527. # NOTE: *all* user IDs will be ltsigned
  528. ltsignCommand=$(cat <<EOF
  529. ltsign
  530. y
  531. $trustval
  532. $depth
  533. $domain
  534. y
  535. save
  536. EOF
  537. )
  538. # ltsign the key
  539. echo "$ltsignCommand" | gpg_host --quiet --command-fd 0 --edit-key "$fingerprint"
  540. # update the trustdb for the authentication keyring
  541. gpg_authentication "--check-trustdb"
  542. }
  543. # delete a certifiers key from the host keyring
  544. remove_certifier() {
  545. local keyID
  546. local fingerprint
  547. keyID="$1"
  548. if [ -z "$keyID" ] ; then
  549. failure "You must specify the key ID of a key to remove."
  550. fi
  551. # delete the requested key (with prompting)
  552. gpg_host --delete-key "$keyID"
  553. # update the trustdb for the authentication keyring
  554. gpg_authentication "--check-trustdb"
  555. }
  556. # list the host certifiers
  557. list_certifiers() {
  558. gpg_host --list-keys
  559. }
  560. # issue command to gpg-authentication keyring
  561. gpg_authentication_cmd() {
  562. gpg_authentication "$@"
  563. }
  564. ########################################################################
  565. # MAIN
  566. ########################################################################
  567. # unset variables that should be defined only in config file
  568. unset KEYSERVER
  569. unset AUTHORIZED_USER_IDS
  570. unset RAW_AUTHORIZED_KEYS
  571. unset MONKEYSPHERE_USER
  572. # load configuration file
  573. [ -e ${MONKEYSPHERE_SERVER_CONFIG:="${ETC}/monkeysphere-server.conf"} ] && . "$MONKEYSPHERE_SERVER_CONFIG"
  574. # set empty config variable with ones from the environment, or with
  575. # defaults
  576. KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="subkeys.pgp.net"}}
  577. AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.config/monkeysphere/authorized_user_ids"}}
  578. RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
  579. MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
  580. # other variables
  581. CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
  582. REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
  583. GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${VARLIB}/gnupg-host"}
  584. GNUPGHOME_AUTHENTICATION=${MONKEYSPHERE_GNUPGHOME_AUTHENTICATION:="${VARLIB}/gnupg-authentication"}
  585. # export variables needed in su invocation
  586. export DATE
  587. export MODE
  588. export MONKEYSPHERE_USER
  589. export KEYSERVER
  590. export CHECK_KEYSERVER
  591. export REQUIRED_USER_KEY_CAPABILITY
  592. export GNUPGHOME_HOST
  593. export GNUPGHOME_AUTHENTICATION
  594. export GNUPGHOME
  595. # get subcommand
  596. COMMAND="$1"
  597. [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
  598. shift
  599. case $COMMAND in
  600. 'update-users'|'update-user'|'u')
  601. update_users "$@"
  602. ;;
  603. 'gen-key'|'g')
  604. gen_key "$@"
  605. ;;
  606. 'add-hostname'|'add-name'|'n+')
  607. add_hostname "$@"
  608. ;;
  609. 'revoke-hostname'|'revoke-name'|'n-')
  610. revoke_hostname "$@"
  611. ;;
  612. 'show-key'|'show'|'s')
  613. show_server_key
  614. ;;
  615. 'show-fingerprint'|'fingerprint'|'f')
  616. fingerprint_server_key
  617. ;;
  618. 'publish-key'|'publish'|'p')
  619. publish_server_key
  620. ;;
  621. 'diagnostics'|'d')
  622. diagnostics
  623. ;;
  624. 'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
  625. add_certifier "$@"
  626. ;;
  627. 'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
  628. remove_certifier "$@"
  629. ;;
  630. 'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
  631. list_certifiers "$@"
  632. ;;
  633. 'gpg-authentication-cmd')
  634. gpg_authentication_cmd "$@"
  635. ;;
  636. '--help'|'help'|'-h'|'h'|'?')
  637. usage
  638. ;;
  639. *)
  640. failure "Unknown command: '$COMMAND'
  641. Type '$PGRM help' for usage."
  642. ;;
  643. esac
  644. exit "$RETURN"