Merge commit 'dkg/master'
authorJameson Graef Rollins <jrollins@finestructure.net>
Thu, 19 Feb 2009 06:20:44 +0000 (01:20 -0500)
committerJameson Graef Rollins <jrollins@finestructure.net>
Thu, 19 Feb 2009 06:20:44 +0000 (01:20 -0500)
1  2 
src/monkeysphere-authentication
src/share/common
src/share/ma/add_certifier

index 0e60cc424592bdab9388b79de317416106f34da6,e7a0580dc4c49598eb4d23f261a2e518fabf0e98..75ab732ccdbe9c44edd18af1b2b6c3be168f256f
@@@ -84,8 -84,8 +84,8 @@@ gpg_core() 
  gpg_sphere() {
      GNUPGHOME="$GNUPGHOME_SPHERE"
      export GNUPGHOME
-     su_monkeysphere_user "gpg --no-greeting --no-tty $@"
+  
+     su_monkeysphere_user "gpg --no-greeting --quiet --no-tty $@"
  }
  
  # output to stdout the core fingerprint from the gpg core secret
@@@ -108,24 -108,29 +108,24 @@@ gpg_core_sphere_sig_transfer() 
  # MAIN
  ########################################################################
  
 -# unset variables that should be defined only in config file of in
 -# MONKEYSPHERE_ variables
 -unset LOG_LEVEL
 -unset KEYSERVER
 -unset AUTHORIZED_USER_IDS
 -unset RAW_AUTHORIZED_KEYS
 -unset MONKEYSPHERE_USER
 -unset PROMPT
 +# set unset default variables
 +AUTHORIZED_USER_IDS="%h/.monkeysphere/authorized_user_ids"
 +RAW_AUTHORIZED_KEYS="%h/.ssh/authorized_keys"
  
  # load configuration file
 -[ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG"
 -
 -# set empty config variable with ones from the environment, or with
 -# defaults
 -LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=${LOG_LEVEL:="INFO"}}
 -KEYSERVER=${MONKEYSPHERE_KEYSERVER:=${KEYSERVER:="pool.sks-keyservers.net"}}
 -AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=${AUTHORIZED_USER_IDS:="%h/.monkeysphere/authorized_user_ids"}}
 -RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=${RAW_AUTHORIZED_KEYS:="%h/.ssh/authorized_keys"}}
 -MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkeysphere"}}
 -PROMPT=${MONKEYSPHERE_PROMPT:=${PROMPT:="true"}}
 +[ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] \
 +    && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG"
 +
 +# set empty config variable with ones from the environment
 +LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=$LOG_LEVEL}
 +KEYSERVER=${MONKEYSPHERE_KEYSERVER:=$KEYSERVER}
 +CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:=$CHECK_KEYSERVER}
 +MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=$MONKEYSPHERE_USER}
 +PROMPT=${MONKEYSPHERE_PROMPT:=$PROMPT}
 +AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=$AUTHORIZED_USER_IDS}
 +RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=$RAW_AUTHORIZED_KEYS}
  
  # other variables
 -CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
  REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
  GNUPGHOME_CORE=${MONKEYSPHERE_GNUPGHOME_CORE:="${MADATADIR}/core"}
  GNUPGHOME_SPHERE=${MONKEYSPHERE_GNUPGHOME_SPHERE:="${MADATADIR}/sphere"}
diff --combined src/share/common
index 96fea7721ac3fdc31e7b922b82871a1cf4c4acda,b78f64a3156a54ea8372df40999e2d5de4770d77..d185fddf70cf142aab145ec2e7013eef2fd66b44
@@@ -23,21 -23,6 +23,21 @@@ export SYSCONFIGDI
  # monkeysphere version
  VERSION=__VERSION__
  
 +# default log level
 +LOG_LEVEL="INFO"
 +
 +# default keyserver
 +KEYSERVER="pool.sks-keyservers.net"
 +
 +# whether or not to check keyservers by defaul
 +CHECK_KEYSERVER="true"
 +
 +# default monkeysphere user
 +MONKEYSPHERE_USER="monkeysphere"
 +
 +# default about whether or not to prompt
 +PROMPT="true"
 +
  ########################################################################
  ### UTILITY FUNCTIONS
  
@@@ -815,9 -800,6 +815,9 @@@ process_host_known_hosts() 
      local sshKey
      local tmpfile
  
 +    # set the key processing mode
 +    export MODE='known_hosts'
 +
      host="$1"
      userID="ssh://${host}"
  
@@@ -897,13 -879,6 +897,13 @@@ update_known_hosts() 
      nHostsOK=0
      nHostsBAD=0
  
 +    # touch the known_hosts file so that the file permission check
 +    # below won't fail upon not finding the file
 +    (umask 0022 && touch "$KNOWN_HOSTS")
 +
 +    # check permissions on the known_hosts file path
 +    check_key_file_permissions "$USER" "$KNOWN_HOSTS" || failure
 +
      # create a lockfile on known_hosts:
      lock create "$KNOWN_HOSTS"
      # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
  process_known_hosts() {
      local hosts
  
 +    # exit if the known_hosts file does not exist
 +    if [ ! -e "$KNOWN_HOSTS" ] ; then
 +      failure "known_hosts file '$KNOWN_HOSTS' does not exist."
 +    fi
 +
      log debug "processing known_hosts file..."
  
      hosts=$(meat "$KNOWN_HOSTS" | cut -d ' ' -f 1 | grep -v '^|.*$' | tr , ' ' | tr '\n' ' ')
@@@ -986,9 -956,6 +986,9 @@@ process_uid_authorized_keys() 
      local ok
      local sshKey
  
 +    # set the key processing mode
 +    export MODE='authorized_keys'
 +
      userID="$1"
  
      log verbose "processing: $userID"
@@@ -1050,9 -1017,6 +1050,9 @@@ update_authorized_keys() 
      nIDsOK=0
      nIDsBAD=0
  
 +    # check permissions on the authorized_keys file path
 +    check_key_file_permissions "$USER" "$AUTHORIZED_KEYS" || failure
 +
      # create a lockfile on authorized_keys
      lock create "$AUTHORIZED_KEYS"
      # FIXME: we're discarding any pre-existing EXIT trap; is this bad?
@@@ -1118,14 -1082,6 +1118,14 @@@ process_authorized_user_ids() 
  
      authorizedUserIDs="$1"
  
 +    # exit if the authorized_user_ids file is empty
 +    if [ ! -e "$authorizedUserIDs" ] ; then
 +      failure "authorized_user_ids file '$authorizedUserIDs' does not exist."
 +    fi
 +
 +    # check permissions on the authorized_user_ids file path
 +    check_key_file_permissions "$USER" "$authorizedUserIDs" || failure
 +
      log debug "processing authorized_user_ids file..."
  
      if ! meat "$authorizedUserIDs" > /dev/null ; then
  
      update_authorized_keys "${userIDs[@]}"
  }
+ # takes a gpg key or keys on stdin, and outputs a list of
+ # fingerprints, one per line:
+ list_primary_fingerprints() {
+     local file="$1"
+     local fake=$(msmktempdir)
+     GNUPGHOME="$fake" gpg --no-tty --quiet --import
+     GNUPGHOME="$fake" gpg --with-colons --fingerprint --list-keys | \
+       awk -F: '/^fpr:/{ print $10 }'
+     rm -rf "$fake"
+ }
index 9865e5c733f93fd196db29f5586a33d8306c05ab,e543d94d986ad84cd04bdd379c94ff047b3823f7..1b484f547954ee341a772a7f3dde7ff4aa5c177b
@@@ -67,28 -67,17 +67,17 @@@ if [ -z "$keyID" ] ; the
  fi
  if [ -f "$keyID" ] ; then
      log info "Reading key from file '$keyID':"
-     importinfo=$(gpg_sphere "--import" < "$keyID" 2>&1) || failure "could not read key from '$keyID'"
-     # FIXME: if this is tried when the key database is not
-     # up-to-date, i got these errors (using set -x):
  
-     # ++ su -m monkeysphere -c '\''gpg --import'\''
-     # Warning: using insecure memory!
-     # gpg: key D21739E9: public key "Daniel Kahn Gillmor <dkg@fifthhorseman.net>" imported
-     # gpg: Total number processed: 1
-     # gpg:               imported: 1  (RSA: 1)
-     # gpg: can'\''t create `/var/monkeysphere/gnupg-host/pubring.gpg.tmp'\'': Permission denied
-     # gpg: failed to rebuild keyring cache: Permission denied
-     # gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
-     # gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
-     # gpg: next trustdb check due at 2009-01-10'
-     # + failure 'could not read key from '\''/root/dkg.gpg'\'''
-     # + echo 'could not read key from '\''/root/dkg.gpg'\'''
+     fingerprints=$(su_monkeysphere_user \
+       ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
  
-     keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ ) || \
-       failure "There were no gpg keys in the file $keyID."
-     if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then
+     if [ $(printf "%s" "$fingerprints" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
        failure "There was not exactly one gpg key in the file."
      fi
+     gpg_sphere "--import" < "$keyID" || failure "could not read key from '$keyID'"
+     keyID="$fingerprints"
  else
      # get the key from the key server
      log debug "retrieving key from keyserver..."
@@@ -111,7 -100,7 +100,7 @@@ gpg_sphere "--fingerprint 0x${fingerpri
  
  if [ "$PROMPT" = "true" ] ; then
      echo "Are you sure you want to add the above key as a"
 -    read -p "certifier of users on this system? (y/N) " OK; OK=${OK:-N}
 +    read -p "certifier of users on this system? (Y/n) " OK; OK=${OK:-Y}
      if [ "${OK/y/Y}" != 'Y' ] ; then
        failure "Identity certifier not added."
      fi