Merge commit 'dkg/master'
authorMatt Goins <mjgoins@openflows.com>
Sat, 31 Jan 2009 23:32:12 +0000 (18:32 -0500)
committerMatt Goins <mjgoins@openflows.com>
Sat, 31 Jan 2009 23:32:12 +0000 (18:32 -0500)
Conflicts:

src/monkeysphere-host

1  2 
src/monkeysphere-host
src/subcommands/mh/gen-key
src/subcommands/mh/import-key

diff --combined src/monkeysphere-host
index 31f031ed91618f9e0e3e89e41d0a978484ad83f7,19ab5fcf8e7c84c72c13cff342b0c30872b524c9..94392647c32693ce74bce898debcfd818e69170b
@@@ -20,6 -20,11 +20,6 @@@ export SYSSHAREDI
  SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere/host"}
  export SYSDATADIR
  
 -# monkeysphere temp directory, in sysdatadir to enable atomic moves of
 -# authorized_keys files
 -MSTMPDIR="${SYSDATADIR}/tmp"
 -export MSTMPDIR
 -
  # UTC date in ISO 8601 format if needed
  DATE=$(date -u '+%FT%T')
  
@@@ -48,12 -53,13 +48,12 @@@ subcommands
   publish-key (p)                     publish server host key to keyserver
  
   expert
-   import-key (i) [NAME[:PORT]]       import existing ssh key to gpg
+   import-key (i)  NAME[:PORT]        import existing ssh key to gpg
     --keyfile (-f) FILE                 key file to import
     --expire (-e) EXPIRE                date to expire
-   gen-key (g) [NAME[:PORT]]          generate gpg key for the host
+   gen-key (g) NAME[:PORT]            generate gpg key for the host
     --length (-l) BITS                  key length in bits (2048)
     --expire (-e) EXPIRE                date to expire
 -   --revoker (-r) FINGERPRINT          add a revoker
    diagnostics (d)                    monkeysphere host status
  
   version (v)                         show version number
@@@ -97,16 -103,6 +97,6 @@@ gpg_host() 
      return "$returnCode"
  }
  
- # check if user is root
- is_root() {
-     [ $(id -u 2>/dev/null) = '0' ]
- }
- # check that user is root, for functions that require root access
- check_user() {
-     is_root || failure "You must be root to run this command."
- }
  # output just key fingerprint
  fingerprint_server_key() {
      # set the pipefail option so functions fails if can't read sec key
@@@ -123,35 -119,6 +113,35 @@@ check_host_keyring() 
        || failure "You don't appear to have a Monkeysphere host key on this server.  Please run 'monkeysphere-server gen-key' first."
  }
  
 +# show info about the host key
 +show_key() {
 +    local fingerprintPGP
 +    local fingerprintSSH
 +    local ret=0
 +
 +    # FIXME: you shouldn't have to be root to see the host key fingerprint
 +    if is_root ; then
 +      check_host_keyring
 +      fingerprintPGP=$(fingerprint_server_key)
 +      gpg_authentication "--fingerprint --list-key --list-options show-unusable-uids $fingerprintPGP" 2>/dev/null
 +      echo "OpenPGP fingerprint: $fingerprintPGP"
 +    else
 +      log info "You must be root to see host OpenPGP fingerprint."
 +      ret='1'
 +    fi
 +
 +    if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
 +      fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
 +          awk '{ print $1, $2, $4 }')
 +      echo "ssh fingerprint: $fingerprintSSH"
 +    else
 +      log info "SSH host key not found."
 +      ret='1'
 +    fi
 +
 +return $ret
 +}
 +
  ########################################################################
  # MAIN
  ########################################################################
@@@ -202,37 -169,31 +192,31 @@@ case $COMMAND i
        ;;
  
      'extend-key'|'e')
-       check_user
        check_host_keyring
        extend_key "$@"
        ;;
  
      'add-hostname'|'add-name'|'n+')
-       check_user
        check_host_keyring
        add_hostname "$@"
        ;;
  
      'revoke-hostname'|'revoke-name'|'n-')
-       check_user
        check_host_keyring
        revoke_hostname "$@"
        ;;
  
      'add-revoker'|'o')
-       check_user
        check_host_keyring
        add_revoker "$@"
        ;;
  
      'revoke-key'|'r')
-       check_user
        check_host_keyring
        revoke_key "$@"
        ;;
  
      'publish-key'|'publish'|'p')
-       check_user
        check_host_keyring
        publish_server_key
        ;;
index 9f260873362031dd638f48cbe2259f311caaef9b,554c04c5a8a43ccc1cffe2290cff7e80448fad47..8558441a9499b00bcf9750ef56dadeb274cc841c
@@@ -14,6 -14,7 +14,6 @@@ local keyType="RSA
  local keyLength="2048"
  local keyUsage="auth"
  local keyExpire
 -local revoker
  local hostName=$(hostname -f)
  local userID
  local keyParameters
@@@ -27,10 -28,6 +27,6 @@@ fingerprint_server_key >/dev/null 
  # get options
  while true ; do
        case "$1" in
-           -h|--hostname)
-               hostName="$2"
-               shift 2
-               ;;
            -l|--length)
                keyLength="$2"
                shift 2
                keyExpire="$2"
                shift 2
                ;;
 -          -r|--revoker)
 -              revoker="$2"
 -              shift 2
 -              ;;
            *)
                if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
                    failure "Unknown option '$1'.
  Type '$PGRM help' for usage."
                fi
+               hostName="$1"
+               shift;
                break
                ;;
        esac
@@@ -62,6 -65,15 +60,6 @@@ Key-Usage: $keyUsag
  Name-Real: $userID
  Expire-Date: $keyExpire"
  
 -# add the revoker field if specified
 -# FIXME: the "1:" below assumes that $REVOKER's key is an RSA key.
 -# FIXME: key is marked "sensitive"?  is this appropriate?
 -if [ "$revoker" ] ; then
 -      keyParameters=\
 -"${keyParameters}
 -Revoker: 1:${revoker} sensitive"
 -fi
 -
  echo "The following key parameters will be used for the host private key:"
  echo "$keyParameters"
  
@@@ -101,4 -113,4 +99,4 @@@ gpg_authentication "--export-options ex
  log info "SSH host public key in OpenPGP form: ${SYSDATADIR}/ssh_host_rsa_key.pub.gpg"
  
  # show info about new key
 -show_server_key
 +show_key
index d60e982c38a047852b3c4b51620f888674a838c7,bbeb37fb2dbf8a370ed005b6b73ba61fe9a89752..ac67711742859ad20e898fc2c45248d9fafd35f9
@@@ -23,10 -23,6 +23,6 @@@ fingerprint_server_key >/dev/null 
  # get options
  while true ; do
        case "$1" in
-           -h|--hostname)
-               hostName="$2"
-               shift 2
-               ;;
            -f|--keyfile)
                keyFile="$2"
                shift 2
@@@ -40,6 -36,9 +36,9 @@@
                    failure "Unknown option '$1'.
  Type '$PGRM help' for usage."
                fi
+               hostName="$1"
+               shift
+               ;;
                break
                ;;
        esac
@@@ -82,4 -81,4 +81,4 @@@ gpg_authentication "--export-options ex
  log info "SSH host public key in OpenPGP form: ${SYSDATADIR}/ssh_host_rsa_key.pub.gpg"
  
  # show info about new key
 -show_server_key
 +show_key