fix up gen/import-key:
[monkeysphere.git] / src / monkeysphere-host
index 4c978c94809b3075056d5b9045b61b3b207a0629..a6fa62fbd80dafcb4fb218b7b7d3e58b82a50cdb 100755 (executable)
 # version 3 or later.
 
 ########################################################################
+set -e
+
 PGRM=$(basename $0)
 
 SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
 export SYSSHAREDIR
 . "${SYSSHAREDIR}/common" || exit 1
 
+SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
+export SYSDATADIR
+
 # sharedir for host functions
 MHSHAREDIR="${SYSSHAREDIR}/mh"
 
-SYSDATADIR=${MONKEYSPHERE_SYSDATADIR:-"/var/lib/monkeysphere"}
-export SYSDATADIR
+# datadir for host functions
+MHDATADIR="${SYSDATADIR}/host"
 
 # UTC date in ISO 8601 format if needed
 DATE=$(date -u '+%FT%T')
@@ -44,12 +49,12 @@ Monkeysphere host admin tool.
 
 subcommands:
  show-key (s)                        output all host key information
extend-key (e) EXPIRE               extend host key expiration
set-expire (e) EXPIRE               set host key expiration
  add-hostname (n+) NAME[:PORT]       add hostname user ID to host key
  revoke-hostname (n-) NAME[:PORT]    revoke hostname user ID
  add-revoker (o) FINGERPRINT         add a revoker to the host key
  revoke-key (r)                      revoke host key
- publish-key (p)                     publish server host key to keyserver
+ publish-key (p)                     publish host key to keyserver
 
  expert <expert-subcommand>          run expert command
  expert help                         expert command help
@@ -88,7 +93,7 @@ gpg_host() {
 }
 
 # output just key fingerprint
-fingerprint_server_key() {
+fingerprint_host_key() {
     # set the pipefail option so functions fails if can't read sec key
     set -o pipefail
 
@@ -99,37 +104,32 @@ fingerprint_server_key() {
 
 # function to check for host secret key
 check_host_keyring() {
-    fingerprint_server_key >/dev/null \
-       || failure "You don't appear to have a Monkeysphere host key on this server.  Please run 'monkeysphere-server gen-key' first."
+    fingerprint_host_key >/dev/null \
+       || failure "You don't appear to have a Monkeysphere host key on this server.  Please run 'monkeysphere-host import-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
+    check_host_keyring
+    fingerprintPGP=$(fingerprint_host_key)
+
+    gpg_host --fingerprint --list-key --list-options show-unusable-uids "0x${fingerprintPGP}!" 2>/dev/null
+    echo "OpenPGP fingerprint: $fingerprintPGP"
 
-    if [ -f "${SYSDATADIR}/ssh_host_rsa_key.pub" ] ; then
-       fingerprintSSH=$(ssh-keygen -l -f "${SYSDATADIR}/ssh_host_rsa_key.pub" | \
+    if [ -f "${MHDATADIR}/ssh_host_rsa_key.pub" ] ; then
+       fingerprintSSH=$(ssh-keygen -l -f "${MHDATADIR}/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
+    # FIXME: show expiration date
+    # FIXME: other relevant key parameters?
 }
 
 ########################################################################
@@ -153,7 +153,7 @@ MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkey
 
 # other variables
 CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"}
-GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${SYSDATADIR}/host"}
+GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${MHDATADIR}"}
 
 # export variables needed in su invocation
 export DATE
@@ -175,7 +175,8 @@ case $COMMAND in
        show_key
        ;;
 
-    'extend-key'|'e')
+    # FIXME: what should we call this command?
+    'set-expire'|'extend-key'|'e')
        check_host_keyring
        source "${MHSHAREDIR}/extend_key"
        extend_key "$@"
@@ -221,11 +222,8 @@ usage: $PGRM expert <subcommand> [options] [args]
 
 expert subcommands:
  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
    --length (-l) BITS                  key length in bits (2048)
-   --expire (-e) EXPIRE                date to expire
  diagnostics (d)                     monkeysphere host status
 
 EOF