home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / monkeysphere / ma / setup < prev    next >
Encoding:
Text File  |  2011-03-24  |  4.9 KB  |  121 lines

  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3.  
  4. # Monkeysphere authentication setup subcommand
  5. #
  6. # The monkeysphere scripts are written by:
  7. # Jameson Rollins <jrollins@finestructure.net>
  8. # Jamie McClelland <jm@mayfirst.org>
  9. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  10. #
  11. # They are Copyright 2009, and are all released under the GPL,
  12. # version 3 or later.
  13.  
  14. setup() {
  15.     # make all needed directories
  16.     log debug "checking authentication directory structure..."
  17.     mkdir -p "${MADATADIR}"
  18.     chmod 0750 "${MADATADIR}"
  19.     chgrp "$MONKEYSPHERE_GROUP" "${MADATADIR}"
  20.     mkdir -p "${MATMPDIR}"
  21.     chmod 0750 "${MATMPDIR}"
  22.     chgrp "$MONKEYSPHERE_GROUP" "${MATMPDIR}"
  23.     mkdir -p "${GNUPGHOME_CORE}"
  24.     chmod 0700 "${GNUPGHOME_CORE}"
  25.     mkdir -p "${GNUPGHOME_SPHERE}"
  26.     chmod 0700 "${GNUPGHOME_SPHERE}"
  27.     mkdir -p "${SYSDATADIR}"/authorized_keys
  28.  
  29.     # deliberately replace the config files via truncation
  30.     # FIXME: should we be dumping to tmp files and then moving atomically?
  31.     log debug "writing core gpg.conf..."
  32.     cat >"${GNUPGHOME_CORE}"/gpg.conf <<EOF
  33. # Monkeysphere trust core GnuPG configuration
  34. # This file is maintained by the Monkeysphere software.
  35. # Edits will be overwritten.
  36. no-greeting
  37. EOF
  38.  
  39.     KEYSERVER_OPTIONS=""
  40.     for anchorfile in "${SYSCONFIGDIR}/monkeysphere-authentication-x509-anchors.crt" "${SYSCONFIGDIR}/monkeysphere-x509-anchors.crt"; do
  41.         if [ -z "$KEYSERVER_OPTIONS" ] && [ -r "$anchorfile" ] ; then
  42.             KEYSERVER_OPTIONS="keyserver-options ca-cert-file=$anchorfile"
  43.             log debug "using $anchorfile for keyserver X.509 anchor"
  44.         fi
  45.     done
  46.  
  47.     log debug "writing sphere gpg.conf..."
  48.     cat >"${GNUPGHOME_SPHERE}"/gpg.conf <<EOF
  49. # Monkeysphere trust sphere GnuPG configuration
  50. # This file is maintained by the Monkeysphere software.
  51. # Edits will be overwritten.
  52. no-greeting
  53. list-options show-uid-validity
  54. ${KEYSERVER_OPTIONS}
  55. EOF
  56.  
  57.     # make sure the monkeysphere user owns everything in the sphere
  58.     # gnupghome
  59.     log debug "fixing sphere gnupg home ownership..."
  60.     chown "$MONKEYSPHERE_USER:$MONKEYSPHERE_GROUP" "${GNUPGHOME_SPHERE}" "${GNUPGHOME_SPHERE}"/gpg.conf
  61.  
  62.     # get fingerprint of core key.  this should be empty on unconfigured systems.
  63.     local CORE_FPR=$(core_fingerprint)
  64.     log debug "core fingerprint: $CORE_FPR"
  65.  
  66.     if [ -z "$CORE_FPR" ] ; then
  67.     log info "setting up Monkeysphere authentication trust core..."
  68.  
  69.     local CORE_UID=$(printf "Monkeysphere authentication trust core UID (random string: %s)" $(dd if=/dev/urandom bs=21 count=1 2>/dev/null | perl -MMIME::Base64 -ne 'print encode_base64($_)'))
  70.     
  71.     printf "generating monkeysphere authentication trust core key:\nsize: %d bits\nuid: '%s'\n" "$CORE_KEYLENGTH" "$CORE_UID" | log debug
  72.     PEM2OPENPGP_USAGE_FLAGS=certify \
  73.         PEM2OPENPGP_NEWKEY=$CORE_KEYLENGTH pem2openpgp "$CORE_UID" \
  74.         | gpg_core --import \
  75.         || failure "Could not import new key for Monkeysphere authentication trust core"
  76.  
  77.     # get fingerprint of core key.  should definitely not be empty at this point
  78.     CORE_FPR=$(core_fingerprint)
  79.     log debug "core fingerprint: $CORE_FPR"
  80.     if [ -z "$CORE_FPR" ] ; then
  81.         failure "Failed to create Monkeysphere authentication trust core!"
  82.     fi
  83.     
  84.     else 
  85.     log verbose "Monkeysphere authentication trust core already exists."
  86.     fi
  87.  
  88.     # export the core key to the sphere keyring
  89.     log debug "exporting core pub key to sphere keyring..."
  90.     gpg_core --export | gpg_sphere --import
  91.  
  92.     # ensure that the authentication sphere checker has absolute ownertrust on the expected key.
  93.     log debug "setting ultimate owner trust on core key in gpg_sphere..."
  94.     printf "%s:6:\n" "$CORE_FPR" | gpg_sphere --import-ownertrust 2>&1 | log verbose
  95.     gpg_sphere --export-ownertrust 2>&1 | log debug
  96.  
  97.     # check the owner trust
  98.     log debug "checking gpg_sphere owner trust set properly..."
  99.     local ORIG_TRUST
  100.     if ORIG_TRUST=$(gpg_sphere "--export-ownertrust" | grep '^[^#]') ; then
  101.     if [ "${CORE_FPR}:6:" != "$ORIG_TRUST" ] ; then
  102.         failure "Monkeysphere authentication trust sphere should explicitly trust the core.  It does not have proper ownertrust settings."
  103.     fi
  104.     else
  105.     failure "Could not get monkeysphere-authentication trust guidelines."
  106.     # FIXME: what does this mean?  should we suggest how to fix?
  107.     fi
  108.  
  109.     # ensure that we're using the extended trust model (1), and that
  110.     # our preferences are reasonable (i.e. 3 marginal OR 1 fully
  111.     # trusted certifications are sufficient to grant full validity.
  112.     log debug "checking trust model for authentication ..."
  113.     local TRUST_MODEL=$(gpg_sphere "--with-colons --list-keys" 2>/dev/null \
  114.     | head -n1 | grep "^tru:" | cut -d: -f3,6,7)
  115.     log debug "sphere trust model: $TRUST_MODEL"
  116.     if [ "$TRUST_MODEL" != '1:3:1' ] ; then
  117.     failure "monkeysphere-authentication does not have the expected trust model settings."
  118.     # FIXME: what does this mean?  should we suggest how to fix?
  119.     fi
  120. }
  121.