From c4f049f6a8dfd1e0e301a6abffafb5c0012ccc0e Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Thu, 12 Feb 2009 13:25:35 -0500 Subject: break out a bunch of common functions in monkeysphere-host: - create_*_*_file to create the key files - load_*fingerprint to load the host fingerprint into an exported variable (HOST_FINGERPRINT) - check_host_*key to check for the presence of a host key modified {import,gen}_key to use these new functions. --- src/monkeysphere-host | 128 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 40 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index be398b1..4aab995 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -32,6 +32,10 @@ MHSHAREDIR="${SYSSHAREDIR}/mh" # datadir for host functions MHDATADIR="${SYSDATADIR}/host" +# host pub key files +HOST_KEY_PUB="${SYSDATADIR}/ssh_host_rsa_key.pub" +HOST_KEY_PUB_GPG="${SYSDATADIR}/ssh_host_rsa_key.pub.gpg" + # UTC date in ISO 8601 format if needed DATE=$(date -u '+%FT%T') @@ -93,22 +97,71 @@ gpg_host_export() { "0x${HOST_FINGERPRINT}!" } -# export the host key to the monkeysphere host file key -gpg_host_export_to_ssh_file() { - log debug "exporting openpgp public key..." +# export the host secret key to the monkeysphere ssh sec key file +# NOTE: assumes that the primary key is the proper key to use +create_ssh_sec_file() { + log debug "creating ssh secret key file..." + (umask 077 && \ + gpg_host --export-secret-key "$HOST_FINGERPRINT" | \ + openpgp2ssh "$HOST_FINGERPRINT" > "${MHDATADIR}/ssh_host_rsa_key") + log info "SSH host secret key file: ${MHDATADIR}/ssh_host_rsa_key" +} + +# export the host public key to the monkeysphere ssh pub key file +create_ssh_pub_file() { + log debug "creating ssh public key file..." + ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB" + log info "SSH host public key file: $HOST_KEY_PUB" +} +# export the host public key to the monkeysphere gpg pub key file +create_gpg_pub_file() { + log debug "creating openpgp public key file..." gpg_host_export > "$HOST_KEY_PUB_GPG" - log info "SSH host public key in OpenPGP form: $HOST_KEY_PUB_GPG" + log info "GPG host public key file: $HOST_KEY_PUB_GPG" +} + +# load the host fingerprint into the fingerprint variable, using the +# export gpg pub key file +load_fingerprint() { + if [ -f "$HOST_KEY_PUB_GPG" ] ; then + HOST_FINGERPRINT=$( \ + (FUBAR=$(mktemp -d) && export GNUPGHOME="$FUBAR" \ + && gpg --quiet --import \ + && gpg --quiet --list-keys --with-colons --with-fingerprint \ + && rm -rf "$FUBAR") <"$HOST_KEY_PUB_GPG" \ + | grep '^fpr:' | cut -d: -f10 ) + else + HOST_FINGERPRINT= + fi +} + +# load the host fingerprint into the fingerprint variable, using the +# gpg host secret key +load_fingerprint_secret() { + HOST_FINGERPRINT=$( \ + gpg_host --quiet --list-secret-key \ + --with-colons --with-fingerprint \ + | grep '^fpr:' | cut -d: -f10 ) } -# output just key fingerprint -# FIXME: should not have to be priviledged user to get host -# fingerprint. should be taken from publicly accessible key files, -# instead of the keyring. -get_host_fingerprint() { - gpg_host --list-secret-keys --fingerprint \ - --with-colons --fixed-list-mode 2> /dev/null | \ - grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null || true +# output host key ssh fingerprint +load_ssh_fingerprint() { + [ -f "$HOST_KEY_PUB" ] || return 0 + HOST_FINGERPRINT_SSH=$(ssh-keygen -l -f "$HOST_KEY_PUB" \ + | awk '{ print $1, $2, $4 }') +} + +# fail if host key present +check_host_key() { + [ -z "$HOST_FINGERPRINT" ] \ + || failure "An OpenPGP host key already exists." +} + +# fail if host key not present +check_host_no_key() { + [ "$HOST_FINGERPRINT" ] \ + || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host expert import-key' first." } # output the index of a user ID on the host key @@ -135,27 +188,18 @@ find_host_userid() { fi } -# function to check for host secret key -check_host_fail() { - [ "$HOST_FINGERPRINT" ] || \ - failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host expert import-key' first." -} - # show info about the host key show_key() { - local fingerprintSSH - gpg_host --fingerprint --list-key --list-options show-unusable-uids \ "0x${HOST_FINGERPRINT}!" 2>/dev/null # FIXME: make sure expiration date is shown echo "OpenPGP fingerprint: $HOST_FINGERPRINT" - if [ -f "$HOST_KEY_PUB" ] ; then - fingerprintSSH=$(ssh-keygen -l -f "$HOST_KEY_PUB" | \ - awk '{ print $1, $2, $4 }') + load_ssh_fingerprint - echo "ssh fingerprint: $fingerprintSSH" + if [ "$HOST_FINGERPRINT_SSH" ] ; then + echo "ssh fingerprint: $HOST_FINGERPRINT_SSH" else log error "SSH host key not found." fi @@ -186,13 +230,6 @@ MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=${MONKEYSPHERE_USER:="monkey CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"} GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${MHDATADIR}"} -# host key fingerprint -HOST_FINGERPRINT=$(get_host_fingerprint) - -# host pub key files -HOST_KEY_PUB="${SYSDATADIR}/ssh_host_rsa_key.pub" -HOST_KEY_PUB_GPG="${SYSDATADIR}/ssh_host_rsa_key.pub.gpg" - # export variables needed in su invocation export DATE export MODE @@ -201,52 +238,59 @@ export MONKEYSPHERE_USER export KEYSERVER export GNUPGHOME_HOST export GNUPGHOME -export HOST_FINGERPRINT +export HOST_FINGERPRINT= +export HOST_FINGERPRINT_SSH= # get subcommand COMMAND="$1" [ "$COMMAND" ] || failure "Type '$PGRM help' for usage." shift - case $COMMAND in 'show-key'|'show'|'s') - check_host_fail + load_fingerprint + check_host_no_key show_key ;; 'set-expire'|'extend-key'|'e') - check_host_fail + load_fingerprint + check_host_no_key source "${MHSHAREDIR}/set_expire" set_expire "$@" ;; 'add-hostname'|'add-name'|'n+') - check_host_fail + load_fingerprint + check_host_no_key source "${MHSHAREDIR}/add_hostname" add_hostname "$@" ;; 'revoke-hostname'|'revoke-name'|'n-') - check_host_fail + load_fingerprint + check_host_no_key source "${MHSHAREDIR}/revoke_hostname" revoke_hostname "$@" ;; 'add-revoker'|'o') - check_host_fail + load_fingerprint + check_host_no_key source "${MHSHAREDIR}/add_revoker" add_revoker "$@" ;; 'revoke-key'|'r') - check_host_fail + load_fingerprint + check_host_no_key source "${MHSHAREDIR}/revoke_key" revoke_key "$@" ;; 'publish-key'|'publish'|'p') - check_host_fail + load_fingerprint + check_host_no_key source "${MHSHAREDIR}/publish_key" publish_key ;; @@ -269,11 +313,15 @@ EOF ;; 'import-key'|'i') + load_fingerprint + check_host_key source "${MHSHAREDIR}/import_key" import_key "$@" ;; 'gen-key'|'g') + load_fingerprint + check_host_key source "${MHSHAREDIR}/gen_key" gen_key "$@" ;; -- cgit v1.2.3 From 07316c65eb5302a1d5385301876be7971e26fd1f Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Thu, 12 Feb 2009 16:17:00 -0500 Subject: fix reference to MONKEYSPHER_USER in ma/setup --- src/monkeysphere-host | 3 +++ src/share/ma/setup | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 4aab995..f79c2bb 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -123,6 +123,9 @@ create_gpg_pub_file() { # load the host fingerprint into the fingerprint variable, using the # export gpg pub key file +# FIXME: this seems much less than ideal, with all this temp keyring +# stuff. is there a way we can do this without having to create temp +# files? load_fingerprint() { if [ -f "$HOST_KEY_PUB_GPG" ] ; then HOST_FINGERPRINT=$( \ diff --git a/src/share/ma/setup b/src/share/ma/setup index 894db84..0cd92e0 100644 --- a/src/share/ma/setup +++ b/src/share/ma/setup @@ -40,10 +40,10 @@ primary-keyring ${GNUPGHOME_SPHERE}/pubring.gpg list-options show-uid-validity EOF - # make sure the monkeysphere user owns everything in th sphere + # make sure the monkeysphere user owns everything in the sphere # gnupghome - chown -R "$MONKEYPSHER_USER" "${GNUPGHOME_SPHERE}" - chgrp -R "$MONKEYPSHER_USER" "${GNUPGHOME_SPHERE}" + chown -R "$MONKEYPSHERE_USER" "${GNUPGHOME_SPHERE}" + chgrp -R "$MONKEYPSHERE_USER" "${GNUPGHOME_SPHERE}" # get fingerprint of core key. this should be empty on unconfigured systems. local CORE_FPR=$(gpg_core --with-colons --fixed-list-mode --fingerprint --list-secret-key | grep ^fpr: | cut -f10 -d: ) -- cgit v1.2.3 From ea4d25a641c19dc66c6066f46070065e22d46d91 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Sun, 15 Feb 2009 23:27:12 -0500 Subject: unbreakout some functions that were broken out earlier for handling creating ssh key files, since they are actually done in different ways under different circumstances. --- src/monkeysphere-host | 21 ++------------------- src/share/mh/gen_key | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 25 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index f79c2bb..32d843b 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -97,23 +97,6 @@ gpg_host_export() { "0x${HOST_FINGERPRINT}!" } -# export the host secret key to the monkeysphere ssh sec key file -# NOTE: assumes that the primary key is the proper key to use -create_ssh_sec_file() { - log debug "creating ssh secret key file..." - (umask 077 && \ - gpg_host --export-secret-key "$HOST_FINGERPRINT" | \ - openpgp2ssh "$HOST_FINGERPRINT" > "${MHDATADIR}/ssh_host_rsa_key") - log info "SSH host secret key file: ${MHDATADIR}/ssh_host_rsa_key" -} - -# export the host public key to the monkeysphere ssh pub key file -create_ssh_pub_file() { - log debug "creating ssh public key file..." - ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB" - log info "SSH host public key file: $HOST_KEY_PUB" -} - # export the host public key to the monkeysphere gpg pub key file create_gpg_pub_file() { log debug "creating openpgp public key file..." @@ -194,7 +177,7 @@ find_host_userid() { # show info about the host key show_key() { gpg_host --fingerprint --list-key --list-options show-unusable-uids \ - "0x${HOST_FINGERPRINT}!" 2>/dev/null + "0x${HOST_FINGERPRINT}!" 2>/dev/null || true # FIXME: make sure expiration date is shown echo "OpenPGP fingerprint: $HOST_FINGERPRINT" @@ -307,7 +290,7 @@ case $COMMAND in usage: $PGRM expert [options] [args] expert subcommands: - import-key (i) [NAME[:PORT]] import existing ssh key to gpg + import-key (i) FILE [NAME[:PORT]] import existing ssh key to gpg gen-key (g) [NAME[:PORT]] generate gpg key for the host --length (-l) BITS key length in bits (2048) diagnostics (d) monkeysphere host status diff --git a/src/share/mh/gen_key b/src/share/mh/gen_key index 873ed02..3b9a269 100644 --- a/src/share/mh/gen_key +++ b/src/share/mh/gen_key @@ -13,7 +13,7 @@ gen_key() { -local hostName=$(hostname -f) +local hostName local keyType="RSA" local keyLength="2048" local keyUsage="auth" @@ -37,7 +37,7 @@ Type '$PGRM help' for usage." esac done -hostName="$1" +hostName=${1:-$(hostname -f)} userID="ssh://${hostName}" # create host home @@ -60,11 +60,18 @@ EOF # load the new host fpr into the fpr variable load_fingerprint_secret -# export to ssh secret key file -create_ssh_sec_file +# export the host secret key to the monkeysphere ssh sec key file +# NOTE: assumes that the primary key is the proper key to use +log debug "creating ssh secret key file..." +(umask 077 && \ + gpg_host --export-secret-key "$HOST_FINGERPRINT" | \ + openpgp2ssh "$HOST_FINGERPRINT" > "${MHDATADIR}/ssh_host_rsa_key") +log info "SSH host secret key file: ${MHDATADIR}/ssh_host_rsa_key" -# export to ssh public key file -create_ssh_pub_file +# export the host public key to the monkeysphere ssh pub key file +log debug "creating ssh public key file..." +ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB" +log info "SSH host public key file: $HOST_KEY_PUB" # export to gpg public key to file create_gpg_pub_file -- cgit v1.2.3 From b55981fb8aa689aede58ed7ab4d8692c52b5c472 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Mon, 16 Feb 2009 01:08:28 -0500 Subject: make sure MHTMPDIR is defined and created --- src/monkeysphere-host | 4 ++++ src/share/mh/add_revoker | 2 +- src/share/mh/gen_key | 6 ++++-- src/share/mh/import_key | 6 ++++-- 4 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 32d843b..d6e4c68 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -32,6 +32,10 @@ MHSHAREDIR="${SYSSHAREDIR}/mh" # datadir for host functions MHDATADIR="${SYSDATADIR}/host" +# temp directory for temp gnupghome directories for add_revoker +MHTMPDIR="${MHDATADIR}/tmp" +export MHTMPDIR + # host pub key files HOST_KEY_PUB="${SYSDATADIR}/ssh_host_rsa_key.pub" HOST_KEY_PUB_GPG="${SYSDATADIR}/ssh_host_rsa_key.pub.gpg" diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index 8d160a8..5b637a5 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -53,7 +53,7 @@ if [ -f "$keyID" ] ; then fi else # create a temporary directory for storing the downloaded key - TMPLOC=$(mktemp -d ${MHTMPDIR}/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!" + TMPLOC=$(mktemp -d "${MHTMPDIR}"/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!" # download the key from the keyserver as the monkeysphere user su_monkeysphere_user \ diff --git a/src/share/mh/gen_key b/src/share/mh/gen_key index 3b9a269..96053bc 100644 --- a/src/share/mh/gen_key +++ b/src/share/mh/gen_key @@ -41,8 +41,10 @@ hostName=${1:-$(hostname -f)} userID="ssh://${hostName}" # create host home -mkdir -p "$GNUPGHOME_HOST" -chmod 700 "$GNUPGHOME_HOST" +mkdir -p "${MHDATADIR}" +mkdir -p "${MHTMPDIR}" +mkdir -p "${GNUPGHOME_HOST}" +chmod 700 "${GNUPGHOME_HOST}" log debug "generating host key..." gpg_host --batch --gen-key < Date: Mon, 16 Feb 2009 20:15:58 -0500 Subject: Stop all creation of a ssh_host_rsa_key.pub. Use openpgp2ssh to get the fingerprint from the host pgp public key. Prevents us from having to maintain the ssh pub key file, and generally makes things simpler. Also allows us to go back to having import_key take the key on stdin (which dkg will like). --- src/monkeysphere-host | 40 ++++++++++++---------------------------- src/share/mh/import_key | 18 ++++++------------ 2 files changed, 18 insertions(+), 40 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index d6e4c68..64023e0 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -37,8 +37,7 @@ MHTMPDIR="${MHDATADIR}/tmp" export MHTMPDIR # host pub key files -HOST_KEY_PUB="${SYSDATADIR}/ssh_host_rsa_key.pub" -HOST_KEY_PUB_GPG="${SYSDATADIR}/ssh_host_rsa_key.pub.gpg" +HOST_KEY_FILE="${SYSDATADIR}/ssh_host_rsa_key.pub.gpg" # UTC date in ISO 8601 format if needed DATE=$(date -u '+%FT%T') @@ -95,17 +94,12 @@ gpg_host_edit() { "0x${HOST_FINGERPRINT}!" "$@" } -# export the host key to stdout -gpg_host_export() { - gpg_host --export --armor --export-options export-minimal \ - "0x${HOST_FINGERPRINT}!" -} - # export the host public key to the monkeysphere gpg pub key file create_gpg_pub_file() { log debug "creating openpgp public key file..." - gpg_host_export > "$HOST_KEY_PUB_GPG" - log info "GPG host public key file: $HOST_KEY_PUB_GPG" + gpg_host --export --armor --export-options export-minimal \ + "0x${HOST_FINGERPRINT}!" > "$HOST_KEY_FILE" + log info "GPG host public key file: $HOST_KEY_FILE" } # load the host fingerprint into the fingerprint variable, using the @@ -114,12 +108,12 @@ create_gpg_pub_file() { # stuff. is there a way we can do this without having to create temp # files? load_fingerprint() { - if [ -f "$HOST_KEY_PUB_GPG" ] ; then + if [ -f "$HOST_KEY_FILE" ] ; then HOST_FINGERPRINT=$( \ (FUBAR=$(mktemp -d) && export GNUPGHOME="$FUBAR" \ && gpg --quiet --import \ && gpg --quiet --list-keys --with-colons --with-fingerprint \ - && rm -rf "$FUBAR") <"$HOST_KEY_PUB_GPG" \ + && rm -rf "$FUBAR") <"$HOST_KEY_FILE" \ | grep '^fpr:' | cut -d: -f10 ) else HOST_FINGERPRINT= @@ -135,13 +129,6 @@ load_fingerprint_secret() { | grep '^fpr:' | cut -d: -f10 ) } -# output host key ssh fingerprint -load_ssh_fingerprint() { - [ -f "$HOST_KEY_PUB" ] || return 0 - HOST_FINGERPRINT_SSH=$(ssh-keygen -l -f "$HOST_KEY_PUB" \ - | awk '{ print $1, $2, $4 }') -} - # fail if host key present check_host_key() { [ -z "$HOST_FINGERPRINT" ] \ @@ -186,13 +173,11 @@ show_key() { echo "OpenPGP fingerprint: $HOST_FINGERPRINT" - load_ssh_fingerprint - - if [ "$HOST_FINGERPRINT_SSH" ] ; then - echo "ssh fingerprint: $HOST_FINGERPRINT_SSH" - else - log error "SSH host key not found." - fi + echo -n "ssh fingerprint: " + ssh-keygen -l -f /dev/stdin \ + <<<$( gpg_host --export FEE16FA3 2>/dev/null \ + | openpgp2ssh 8445B5203A8443B4B04F637DD4DE66B2FEE16FA3 2>/dev/null) \ + | awk '{ print $1, $2, $4 }' # FIXME: other relevant key parameters? } @@ -229,7 +214,6 @@ export KEYSERVER export GNUPGHOME_HOST export GNUPGHOME export HOST_FINGERPRINT= -export HOST_FINGERPRINT_SSH= # get subcommand COMMAND="$1" @@ -294,7 +278,7 @@ case $COMMAND in usage: $PGRM expert [options] [args] expert subcommands: - import-key (i) FILE [NAME[:PORT]] import existing ssh key to gpg + import-key (i) [NAME[:PORT]] import existing ssh key to gpg gen-key (g) [NAME[:PORT]] generate gpg key for the host --length (-l) BITS key length in bits (2048) diagnostics (d) monkeysphere host status diff --git a/src/share/mh/import_key b/src/share/mh/import_key index e5982ca..74dc0b3 100644 --- a/src/share/mh/import_key +++ b/src/share/mh/import_key @@ -13,14 +13,10 @@ import_key() { -local keyFile local hostName local userID -keyFile="$1" -[ -f "$keyFile" ] - -hostName=${2:-$(hostname -f)} +hostName=${1:-$(hostname -f)} userID="ssh://${hostName}" # create host home @@ -31,17 +27,15 @@ chmod 700 "${GNUPGHOME_HOST}" log verbose "importing ssh key..." # translate ssh key to a private key -PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" <"$keyFile" \ +PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \ | gpg_host --import -# load the new host fpr into the fpr variable +# load the new host fpr into the fpr variable. this is so we can +# create the gpg pub key file. we have to do this from the secret key +# ring since we obviously don't have the gpg pub key file yet, since +# that's what we're trying to produce (see below). load_fingerprint_secret -# export the host public key to the monkeysphere ssh pub key file -log debug "creating ssh public key file..." -ssh-keygen -y -f "$keyFile" > "$HOST_KEY_PUB" -log info "SSH host public key file: $HOST_KEY_PUB" - # export to gpg public key to file create_gpg_pub_file -- cgit v1.2.3 From e93a298ec6f9abd80e30a933b0dd84c764d11bff Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Mon, 16 Feb 2009 21:28:32 -0500 Subject: REMOVE GEN_KEY. The gen_key function is entirely removed. Decided this was OK now that import_key works, and we can't really see a reason to keep it around. We can resurect it down the line if need be. Also, removed "expert" subcommand, after promting import_key, since it may be need semi-regularly. The other "expert" commands are now just not listed in the usage. --- man/man8/monkeysphere-authentication.8 | 27 +++++------ man/man8/monkeysphere-host.8 | 46 ++++++------------- src/monkeysphere-authentication | 38 +++------------ src/monkeysphere-host | 53 +++++---------------- src/share/mh/gen_key | 84 ---------------------------------- 5 files changed, 43 insertions(+), 205 deletions(-) delete mode 100644 src/share/mh/gen_key (limited to 'src/monkeysphere-host') diff --git a/man/man8/monkeysphere-authentication.8 b/man/man8/monkeysphere-authentication.8 index 2b0091e..4187c70 100644 --- a/man/man8/monkeysphere-authentication.8 +++ b/man/man8/monkeysphere-authentication.8 @@ -60,6 +60,17 @@ Instruct system to ignore user identity certifications made by KEYID. List key IDs trusted by the system to certify user identities. `c' may be used in place of `list-id-certifiers'. .TP +.B diagnostics +Review the state of the server with respect to authentication. `d' +may be used in place of `diagnostics'. +.TP +.B gpg-cmd +Execute a gpg command, as the monkeysphere user, on the monkeysphere +authentication "sphere" keyring. This takes a single argument +(multiple gpg arguments need to be quoted). Use this command with +caution, as modifying the authentication sphere keyring can affect ssh +user authentication. +.TP .B help Output a brief usage summary. `h' or `?' may be used in place of `help'. @@ -67,22 +78,6 @@ Output a brief usage summary. `h' or `?' may be used in place of .B version show version number -.SH "EXPERT" SUBCOMMANDS - -Some commands are very unlikely to be needed by most administrators. -These commands must prefaced by the word `expert'. -.TP -.B diagnostics -Review the state of the server with respect to authentication. `d' -may be used in place of `diagnostics'. -.TP -.B gpg-cmd -Execute a gpg command on the gnupg-authentication keyring as the -monkeysphere user. This takes a single command (multiple gpg -arguments need to be quoted). Use this command with caution, as -modifying the gnupg-authentication keyring can affect ssh user -authentication. - .SH SETUP USER AUTHENTICATION If the server will handle user authentication through diff --git a/man/man8/monkeysphere-host.8 b/man/man8/monkeysphere-host.8 index 78b6b4a..062f0aa 100644 --- a/man/man8/monkeysphere-host.8 +++ b/man/man8/monkeysphere-host.8 @@ -61,33 +61,13 @@ Revoke the host's OpenPGP key. `r' may be used in place of Publish the host's OpenPGP key to the keyserver. `p' may be used in place of `publish-key'. .TP -.B help -Output a brief usage summary. `h' or `?' may be used in place of -`help'. -.TP -.B version -show version number - -.SH "EXPERT" SUBCOMMANDS - -Some commands are very unlikely to be needed by most administrators. -These commands must prefaced by the word `expert'. -.TP -.B gen-key [HOSTNAME] -Generate a OpenPGP key for the host. If HOSTNAME is not specified, -then the system fully-qualified domain name will be user. An -alternate key bit length can be specified with the `-l' or `--length' -option (default 2048). An expiration length can be specified with the -`-e' or `--expire' option (prompt otherwise). The expiration format -is the same as that of \fBextend-key\fP, below. `g' may be used in -place of `gen-key'. -.TP -.B import-key -FIXME: - import-key (i) import existing ssh key to gpg - --hostname (-h) NAME[:PORT] hostname for key user ID - --keyfile (-f) FILE key file to import - --expire (-e) EXPIRE date to expire +.B import-key [NAME[:PORT]] +Import a pem-encoded ssh secret host key, from stdin. NAME[:PORT] is +used to specify the hostname (and port) used in the user ID of the new +OpenPGP key. If NAME is not specified, then the system +fully-qualified domain name will be used (ie. `hostname -f'). If PORT +is not specified, the no port is added to the user ID, which means +port 22 is assumed. `i' may be used in place of `import-key'. .TP .B diagnostics Review the state of the monkeysphere server host key and report on @@ -95,6 +75,13 @@ suggested changes. Among other checks, this includes making sure there is a valid host key, that the key is published, that the sshd configuration points to the right place, etc. `d' may be used in place of `diagnostics'. +.TP +.B help +Output a brief usage summary. `h' or `?' may be used in place of +`help'. +.TP +.B version +show version number .SH SETUP HOST AUTHENTICATION @@ -104,11 +91,6 @@ publish the host key to the keyservers, run the following command: $ monkeysphere-host publish-key -You must also modify the sshd_config on the server to tell sshd where -the new server host key is located: - -HostKey /var/lib/monkeysphere/host/ssh_host_rsa_key - In order for users logging into the system to be able to identify the host via the monkeysphere, at least one person (e.g. a server admin) will need to sign the host's key. This is done using standard OpenPGP diff --git a/src/monkeysphere-authentication b/src/monkeysphere-authentication index 2d6079f..4a09527 100755 --- a/src/monkeysphere-authentication +++ b/src/monkeysphere-authentication @@ -61,12 +61,10 @@ subcommands: remove-id-certifier (c-) KEYID remove a certification key list-id-certifiers (c) list certification keys - expert run expert command - expert help expert command help - version (v) show version number help (h,?) this help +See ${PGRM}(8) for more info. EOF } @@ -176,35 +174,13 @@ case $COMMAND in list_certifiers "$@" ;; - 'expert') - SUBCOMMAND="$1" - shift - case "$SUBCOMMAND" in - 'help'|'h'|'?') - cat < [options] [args] - -expert subcommands: - diagnostics (d) monkeysphere authentication status - gpg-cmd CMD execute gpg command - -EOF - ;; - - 'diagnostics'|'d') - source "${MASHAREDIR}/diagnostics" - diagnostics - ;; - - 'gpg-cmd') - gpg_sphere "$@" - ;; + 'diagnostics'|'d') + source "${MASHAREDIR}/diagnostics" + diagnostics + ;; - *) - failure "Unknown expert subcommand: '$COMMAND' -Type '$PGRM help' for usage." - ;; - esac + 'gpg-cmd') + gpg_sphere "$@" ;; 'version'|'v') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 64023e0..2e69d41 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -66,12 +66,12 @@ subcommands: revoke-key (r) revoke host key publish-key (p) publish host key to keyserver - expert run expert command - expert help expert command help + import-key (i) [NAME[:PORT]] import existing ssh key to gpg version (v) show version number help (h,?) this help +See ${PGRM}(8) for more info. EOF } @@ -269,47 +269,16 @@ case $COMMAND in publish_key ;; - 'expert') - SUBCOMMAND="$1" - shift - case "$SUBCOMMAND" in - 'help'|'h'|'?') - cat < [options] [args] - -expert subcommands: - import-key (i) [NAME[:PORT]] import existing ssh key to gpg - gen-key (g) [NAME[:PORT]] generate gpg key for the host - --length (-l) BITS key length in bits (2048) - diagnostics (d) monkeysphere host status + 'import-key'|'i') + load_fingerprint + check_host_key + source "${MHSHAREDIR}/import_key" + import_key "$@" + ;; -EOF - ;; - - 'import-key'|'i') - load_fingerprint - check_host_key - source "${MHSHAREDIR}/import_key" - import_key "$@" - ;; - - 'gen-key'|'g') - load_fingerprint - check_host_key - source "${MHSHAREDIR}/gen_key" - gen_key "$@" - ;; - - 'diagnostics'|'d') - source "${MHSHAREDIR}/diagnostics" - diagnostics - ;; - - *) - failure "Unknown expert subcommand: '$COMMAND' -Type '$PGRM help' for usage." - ;; - esac + 'diagnostics'|'d') + source "${MHSHAREDIR}/diagnostics" + diagnostics ;; 'version'|'v') diff --git a/src/share/mh/gen_key b/src/share/mh/gen_key deleted file mode 100644 index 96053bc..0000000 --- a/src/share/mh/gen_key +++ /dev/null @@ -1,84 +0,0 @@ -# -*-shell-script-*- -# This should be sourced by bash (though we welcome changes to make it POSIX sh compliant) - -# Monkeysphere host gen-key subcommand -# -# The monkeysphere scripts are written by: -# Jameson Rollins -# Jamie McClelland -# Daniel Kahn Gillmor -# -# They are Copyright 2008-2009, and are all released under the GPL, -# version 3 or later. - -gen_key() { - -local hostName -local keyType="RSA" -local keyLength="2048" -local keyUsage="auth" -local keyExpire="0" -local userID - -# get options -while true ; do - case "$1" in - -l|--length) - keyLength="$2" - shift 2 - ;; - *) - if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then - failure "Unknown option '$1'. -Type '$PGRM help' for usage." - fi - break - ;; - esac -done - -hostName=${1:-$(hostname -f)} -userID="ssh://${hostName}" - -# create host home -mkdir -p "${MHDATADIR}" -mkdir -p "${MHTMPDIR}" -mkdir -p "${GNUPGHOME_HOST}" -chmod 700 "${GNUPGHOME_HOST}" - -log debug "generating host key..." -gpg_host --batch --gen-key < "${MHDATADIR}/ssh_host_rsa_key") -log info "SSH host secret key file: ${MHDATADIR}/ssh_host_rsa_key" - -# export the host public key to the monkeysphere ssh pub key file -log debug "creating ssh public key file..." -ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB" -log info "SSH host public key file: $HOST_KEY_PUB" - -# export to gpg public key to file -create_gpg_pub_file - -# show info about new key -show_key - -} -- cgit v1.2.3 From cc26b64f9d83de2d9e567f9a1c223233fe0bb860 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Mon, 16 Feb 2009 21:39:17 -0500 Subject: fix reference to HOST_FINGERPRINT in show-key, and fix some references to "expert" in test. --- src/monkeysphere-host | 4 ++-- tests/basic | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 2e69d41..bd956e0 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -175,8 +175,8 @@ show_key() { echo -n "ssh fingerprint: " ssh-keygen -l -f /dev/stdin \ - <<<$( gpg_host --export FEE16FA3 2>/dev/null \ - | openpgp2ssh 8445B5203A8443B4B04F637DD4DE66B2FEE16FA3 2>/dev/null) \ + <<<$( gpg_host --export "$HOST_FINGERPRINT" 2>/dev/null \ + | openpgp2ssh "$HOST_FINGERPRINT" 2>/dev/null) \ | awk '{ print $1, $2, $4 }' # FIXME: other relevant key parameters? diff --git a/tests/basic b/tests/basic index 9844454..4c19a85 100755 --- a/tests/basic +++ b/tests/basic @@ -166,9 +166,9 @@ EOF # import host key echo "##################################################" -echo "### testing host key importing..." +echo "### import host key..." ssh-keygen -b 1024 -t rsa -N '' -f "$TEMPDIR"/ssh_host_rsa_key -monkeysphere-host expert import-key testhost < "$TEMPDIR"/ssh_host_rsa_key +monkeysphere-host import-key testhost < "$TEMPDIR"/ssh_host_rsa_key # change host key expiration echo "##################################################" -- cgit v1.2.3 From 26ff353050a173bea139cce630d47b91ee2b95b6 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Mon, 16 Feb 2009 23:57:55 -0500 Subject: make host show_key use just the pgp pub key file to get the ssh fingerprint, as it should have been doing before --- src/monkeysphere-host | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index bd956e0..ff28486 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -175,8 +175,7 @@ show_key() { echo -n "ssh fingerprint: " ssh-keygen -l -f /dev/stdin \ - <<<$( gpg_host --export "$HOST_FINGERPRINT" 2>/dev/null \ - | openpgp2ssh "$HOST_FINGERPRINT" 2>/dev/null) \ + <<<$(openpgp2ssh <"$HOST_KEY_FILE" 2>/dev/null) \ | awk '{ print $1, $2, $4 }' # FIXME: other relevant key parameters? -- cgit v1.2.3 From 650969a09be64ceda9a9773b1ba1803584ca9ada Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Tue, 17 Feb 2009 00:26:09 -0500 Subject: check host for gpg pub key file instead of fingerprint, and modify show_key to be able to show full key info to all users. --- src/monkeysphere-host | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index ff28486..6220760 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -131,14 +131,14 @@ load_fingerprint_secret() { # fail if host key present check_host_key() { - [ -z "$HOST_FINGERPRINT" ] \ + [ ! -s "$HOST_KEY_FILE" ] \ || failure "An OpenPGP host key already exists." } # fail if host key not present check_host_no_key() { - [ "$HOST_FINGERPRINT" ] \ - || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host expert import-key' first." + [ -s "$HOST_KEY_FILE" ] \ + || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host import-key' first." } # output the index of a user ID on the host key @@ -167,18 +167,34 @@ find_host_userid() { # show info about the host key show_key() { - gpg_host --fingerprint --list-key --list-options show-unusable-uids \ - "0x${HOST_FINGERPRINT}!" 2>/dev/null || true - # FIXME: make sure expiration date is shown + local GNUPGHOME + # tmp gpghome dir + export GNUPGHOME=$(mktemp -d) + + # trap to remove tmp dir if break + trap "rm -rf $GNUPGHOME" EXIT + + gpg --quiet --import <"$HOST_KEY_FILE" + + HOST_FINGERPRINT=$(gpg --quiet --list-keys --with-colons --with-fingerprint \ + | grep '^fpr:' | cut -d: -f10 ) + + # list the host key info + gpg --list-key --fingerprint --list-options show-unusable-uids 2>/dev/null + + # list the pgp fingerprint echo "OpenPGP fingerprint: $HOST_FINGERPRINT" + # list the ssh fingerprint echo -n "ssh fingerprint: " ssh-keygen -l -f /dev/stdin \ <<<$(openpgp2ssh <"$HOST_KEY_FILE" 2>/dev/null) \ | awk '{ print $1, $2, $4 }' - # FIXME: other relevant key parameters? + # remove the tmp file + trap - EXIT + rm -rf "$GNUPGHOME" } ######################################################################## @@ -221,61 +237,60 @@ shift case $COMMAND in 'show-key'|'show'|'s') - load_fingerprint check_host_no_key show_key ;; 'set-expire'|'extend-key'|'e') - load_fingerprint check_host_no_key + load_fingerprint source "${MHSHAREDIR}/set_expire" set_expire "$@" ;; 'add-hostname'|'add-name'|'n+') - load_fingerprint check_host_no_key + load_fingerprint source "${MHSHAREDIR}/add_hostname" add_hostname "$@" ;; 'revoke-hostname'|'revoke-name'|'n-') - load_fingerprint check_host_no_key + load_fingerprint source "${MHSHAREDIR}/revoke_hostname" revoke_hostname "$@" ;; 'add-revoker'|'o') - load_fingerprint check_host_no_key + load_fingerprint source "${MHSHAREDIR}/add_revoker" add_revoker "$@" ;; 'revoke-key'|'r') - load_fingerprint check_host_no_key + load_fingerprint source "${MHSHAREDIR}/revoke_key" revoke_key "$@" ;; 'publish-key'|'publish'|'p') - load_fingerprint check_host_no_key + load_fingerprint source "${MHSHAREDIR}/publish_key" publish_key ;; 'import-key'|'i') - load_fingerprint check_host_key source "${MHSHAREDIR}/import_key" import_key "$@" ;; 'diagnostics'|'d') + load_fingerprint source "${MHSHAREDIR}/diagnostics" diagnostics ;; -- cgit v1.2.3 From 54e5dd2bd3d63238142c748c64fdf66135a47136 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Tue, 17 Feb 2009 00:36:07 -0500 Subject: fix a couple of left over references to expert --- src/monkeysphere-authentication | 4 ++-- src/monkeysphere-host | 3 ++- src/share/ma/diagnostics | 2 +- src/share/mh/diagnostics | 2 +- tests/basic | 12 ++++++------ 5 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-authentication b/src/monkeysphere-authentication index 4a09527..465777d 100755 --- a/src/monkeysphere-authentication +++ b/src/monkeysphere-authentication @@ -86,8 +86,8 @@ gpg_sphere() { su_monkeysphere_user "gpg $@" } -# load the core fingerprint into the fingerprint variable, using the -# gpg host secret key +# output to stdout the core fingerprint from the gpg core secret +# keyring core_fingerprint() { log debug "determining core key fingerprint..." gpg_core --quiet --list-secret-key \ diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 6220760..8562ec6 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -181,7 +181,8 @@ show_key() { | grep '^fpr:' | cut -d: -f10 ) # list the host key info - gpg --list-key --fingerprint --list-options show-unusable-uids 2>/dev/null + gpg --list-keys --fingerprint \ + --list-options show-unusable-uids 2>/dev/null # list the pgp fingerprint echo "OpenPGP fingerprint: $HOST_FINGERPRINT" diff --git a/src/share/ma/diagnostics b/src/share/ma/diagnostics index 45a8ce2..0411080 100644 --- a/src/share/ma/diagnostics +++ b/src/share/ma/diagnostics @@ -120,7 +120,7 @@ fi if [ "$problemsfound" -gt 0 ]; then echo "When the above $problemsfound issue"$(if [ "$problemsfound" -eq 1 ] ; then echo " is" ; else echo "s are" ; fi)" resolved, please re-run:" - echo " monkeysphere-authentication expert diagnostics" + echo " monkeysphere-authentication diagnostics" else echo "Everything seems to be in order!" fi diff --git a/src/share/mh/diagnostics b/src/share/mh/diagnostics index 96065e6..d774723 100644 --- a/src/share/mh/diagnostics +++ b/src/share/mh/diagnostics @@ -152,7 +152,7 @@ fi if [ "$problemsfound" -gt 0 ]; then echo "When the above $problemsfound issue"$(if [ "$problemsfound" -eq 1 ] ; then echo " is" ; else echo "s are" ; fi)" resolved, please re-run:" - echo " monkeysphere-host expert diagnostics" + echo " monkeysphere-host diagnostics" else echo "Everything seems to be in order!" fi diff --git a/tests/basic b/tests/basic index 4c19a85..d78a594 100755 --- a/tests/basic +++ b/tests/basic @@ -170,17 +170,17 @@ echo "### import host key..." ssh-keygen -b 1024 -t rsa -N '' -f "$TEMPDIR"/ssh_host_rsa_key monkeysphere-host import-key testhost < "$TEMPDIR"/ssh_host_rsa_key +echo "##################################################" +echo "### getting host key fingerprint..." +HOSTKEYID=$( monkeysphere-host show-key | grep '^OpenPGP fingerprint: ' | cut -f3 -d\ ) +echo "$HOSTKEYID" + # change host key expiration echo "##################################################" echo "### setting host key expiration..." monkeysphere-host set-expire 1 # FIXME: how do we check that the expiration has really been set? -echo "##################################################" -echo "### getting host key fingerprint..." -HOSTKEYID=$( monkeysphere-host show-key | grep '^OpenPGP fingerprint: ' | cut -f3 -d\ ) -echo "$HOSTKEYID" - # certify host key with the "Admin's Key". # (this would normally be done via keyservers) echo "##################################################" @@ -236,7 +236,7 @@ gpgadmin --armor --export "$HOSTKEYID" | gpg --import # teach the "server" about the testuser's key echo "##################################################" echo "### export testuser key to server..." -gpg --export testuser | monkeysphere-authentication expert gpg-cmd --import +gpg --export testuser | monkeysphere-authentication gpg-cmd --import # update authorized_keys for user echo "##################################################" -- cgit v1.2.3 From 13ff1e0198424833a9fd110a4373c3511dbb7614 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Tue, 17 Feb 2009 02:02:58 -0500 Subject: tweak the show-key output, and fix some comments. --- src/monkeysphere-host | 10 ++++++++-- src/share/mh/add_revoker | 1 - src/share/mh/revoke_hostname | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 8562ec6..9d3ccb1 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -89,6 +89,8 @@ gpg_host_list() { } # command for edit key scripts, takes scripts on stdin +# FIXME: should we supress all the edit script spew? or pipe it +# through log debug? gpg_host_edit() { gpg_host --quiet --command-fd 0 --edit-key \ "0x${HOST_FINGERPRINT}!" "$@" @@ -106,7 +108,7 @@ create_gpg_pub_file() { # export gpg pub key file # FIXME: this seems much less than ideal, with all this temp keyring # stuff. is there a way we can do this without having to create temp -# files? +# files? what if we stored the fingerprint in MHDATADIR/fingerprint? load_fingerprint() { if [ -f "$HOST_KEY_FILE" ] ; then HOST_FINGERPRINT=$( \ @@ -181,8 +183,12 @@ show_key() { | grep '^fpr:' | cut -d: -f10 ) # list the host key info + # FIXME: make no-show-keyring work so we don't have to do the grep'ing + # FIXME: why is this not showing key expiration? gpg --list-keys --fingerprint \ - --list-options show-unusable-uids 2>/dev/null + --list-options show-unusable-uids 2>/dev/null \ + | grep -v "^${GNUPGHOME}/pubring.gpg$" \ + | egrep -v '^-+$' # list the pgp fingerprint echo "OpenPGP fingerprint: $HOST_FINGERPRINT" diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index 5b637a5..b6affbb 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -84,7 +84,6 @@ if [ "${OK/y/Y}" != 'Y' ] ; then fi # edit-key script to add revoker -# NOTE: *all* user IDs will be ltsigned addrevokerCommand=$(cat < Date: Tue, 17 Feb 2009 02:23:17 -0500 Subject: rename create_gpg_pub_file to be update_gpg_pub_file, and add it to every function that alters the host keyring, so that all changes will show up in exported pub key file, and in show-key. --- src/monkeysphere-host | 10 +++++----- src/share/mh/add_hostname | 2 ++ src/share/mh/add_revoker | 2 ++ src/share/mh/import_key | 2 +- src/share/mh/revoke_hostname | 2 ++ src/share/mh/set_expire | 2 ++ 6 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-host b/src/monkeysphere-host index 9d3ccb1..a7b9697 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -97,11 +97,10 @@ gpg_host_edit() { } # export the host public key to the monkeysphere gpg pub key file -create_gpg_pub_file() { - log debug "creating openpgp public key file..." +update_gpg_pub_file() { + log debug "updating openpgp public key file '$HOST_KEY_FILE'..." gpg_host --export --armor --export-options export-minimal \ "0x${HOST_FINGERPRINT}!" > "$HOST_KEY_FILE" - log info "GPG host public key file: $HOST_KEY_FILE" } # load the host fingerprint into the fingerprint variable, using the @@ -140,7 +139,8 @@ check_host_key() { # fail if host key not present check_host_no_key() { [ -s "$HOST_KEY_FILE" ] \ - || failure "You don't appear to have a Monkeysphere host key on this server. Please run 'monkeysphere-host import-key' first." + || failure "You don't appear to have a Monkeysphere host key on this server. +Please run 'monkeysphere-host import-key' first." } # output the index of a user ID on the host key @@ -184,7 +184,7 @@ show_key() { # list the host key info # FIXME: make no-show-keyring work so we don't have to do the grep'ing - # FIXME: why is this not showing key expiration? + # FIXME: can we show uid validity somehow? gpg --list-keys --fingerprint \ --list-options show-unusable-uids 2>/dev/null \ | grep -v "^${GNUPGHOME}/pubring.gpg$" \ diff --git a/src/share/mh/add_hostname b/src/share/mh/add_hostname index 46326bb..910faf6 100644 --- a/src/share/mh/add_hostname +++ b/src/share/mh/add_hostname @@ -51,6 +51,8 @@ EOF # execute edit-key script if echo "$adduidCommand" | gpg_host_edit ; then + update_gpg_pub_file + show_key echo diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index b6affbb..1464ae8 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -97,6 +97,8 @@ failure "not implemented yet!" if echo "$addrevokerCommand" | \ gpg_core_edit ; then + update_gpg_pub_file + log info "Revoker added." else failure "Problem adding revoker." diff --git a/src/share/mh/import_key b/src/share/mh/import_key index ed6ee4f..6f12b7f 100644 --- a/src/share/mh/import_key +++ b/src/share/mh/import_key @@ -61,7 +61,7 @@ printf "%s:6:\n" "$HOST_FINGERPRINT" | gpg_host --import-ownertrust gpg_host --check-trustdb # export to gpg public key to file -create_gpg_pub_file +update_gpg_pub_file # show info about new key show_key diff --git a/src/share/mh/revoke_hostname b/src/share/mh/revoke_hostname index 3addf90..99ba603 100644 --- a/src/share/mh/revoke_hostname +++ b/src/share/mh/revoke_hostname @@ -65,6 +65,8 @@ EOF # execute edit-key script if echo "$revuidCommand" | gpg_host_edit ; then + update_gpg_pub_file + show_key echo diff --git a/src/share/mh/set_expire b/src/share/mh/set_expire index b03e0d0..0b581d9 100644 --- a/src/share/mh/set_expire +++ b/src/share/mh/set_expire @@ -29,6 +29,8 @@ $extendTo save EOF +update_gpg_pub_file + cat < Date: Tue, 17 Feb 2009 19:09:44 -0500 Subject: add ability to bypass prompting with a MONKEYSPHERE_PROMPT variable, for functions that prompt for confirmation. Also fix publish_key function (NOT TESTED). --- src/monkeysphere-authentication | 9 +++++++-- src/monkeysphere-host | 13 +++++++++---- src/share/ma/add_certifier | 8 +------- src/share/ma/remove_certifier | 7 +++++-- src/share/mh/add_hostname | 14 +++++++++----- src/share/mh/add_revoker | 12 ++++++++---- src/share/mh/publish_key | 29 +++++++++++++++++++++++++---- src/share/mh/revoke_hostname | 14 +++++++++----- src/share/mh/set_expire | 9 +++++++++ tests/basic | 2 +- 10 files changed, 83 insertions(+), 34 deletions(-) (limited to 'src/monkeysphere-host') diff --git a/src/monkeysphere-authentication b/src/monkeysphere-authentication index 60cb5f2..c349e6f 100755 --- a/src/monkeysphere-authentication +++ b/src/monkeysphere-authentication @@ -114,11 +114,14 @@ gpg_core_sphere_sig_transfer() { # MAIN ######################################################################## -# unset variables that should be defined only in config file +# 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 # load configuration file [ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG" @@ -130,6 +133,7 @@ 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"}} # other variables CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"} @@ -142,8 +146,9 @@ CORE_KEYLENGTH=${MONKEYSPHERE_CORE_KEYLENGTH:="2048"} export DATE export MODE export LOG_LEVEL -export MONKEYSPHERE_USER export KEYSERVER +export MONKEYSPHERE_USER +export PROMPT export CHECK_KEYSERVER export REQUIRED_USER_KEY_CAPABILITY export GNUPGHOME_CORE diff --git a/src/monkeysphere-host b/src/monkeysphere-host index a7b9697..2dc6003 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -177,6 +177,7 @@ show_key() { # trap to remove tmp dir if break trap "rm -rf $GNUPGHOME" EXIT + # import the host key into the tmp dir gpg --quiet --import <"$HOST_KEY_FILE" HOST_FINGERPRINT=$(gpg --quiet --list-keys --with-colons --with-fingerprint \ @@ -208,9 +209,12 @@ show_key() { # MAIN ######################################################################## -# unset variables that should be defined only in config file +# unset variables that should be defined only in config file of in +# MONKEYSPHERE_ variables +unset LOG_LEVEL unset KEYSERVER unset MONKEYSPHERE_USER +unset PROMPT # load configuration file [ -e ${MONKEYSPHERE_HOST_CONFIG:="${SYSCONFIGDIR}/monkeysphere-host.conf"} ] && . "$MONKEYSPHERE_HOST_CONFIG" @@ -219,9 +223,8 @@ unset MONKEYSPHERE_USER # 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"}} # other variables CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:="true"} @@ -231,8 +234,10 @@ GNUPGHOME_HOST=${MONKEYSPHERE_GNUPGHOME_HOST:="${MHDATADIR}"} export DATE export MODE export LOG_LEVEL -export MONKEYSPHERE_USER export KEYSERVER +export MONKEYSPHERE_USER +export PROMPT +export CHECK_KEYSERVER export GNUPGHOME_HOST export GNUPGHOME export HOST_FINGERPRINT= diff --git a/src/share/ma/add_certifier b/src/share/ma/add_certifier index 28c229a..54ea673 100644 --- a/src/share/ma/add_certifier +++ b/src/share/ma/add_certifier @@ -36,8 +36,6 @@ local fingerprint local ltsignCommand local trustval -PROMPT=true - # get options while true ; do case "$1" in @@ -53,10 +51,6 @@ while true ; do depth="$2" shift 2 ;; - -y) - PROMPT=false - shift 1 - ;; *) if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then failure "Unknown option '$1'. @@ -114,7 +108,7 @@ fi log info "key found:" gpg_sphere "--fingerprint 0x${fingerprint}!" -if [ "$PROMPT" = true ] ; then +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} if [ "${OK/y/Y}" != 'Y' ] ; then diff --git a/src/share/ma/remove_certifier b/src/share/ma/remove_certifier index 4e56264..8271ae0 100644 --- a/src/share/ma/remove_certifier +++ b/src/share/ma/remove_certifier @@ -23,13 +23,16 @@ if [ -z "$keyID" ] ; then failure "You must specify the key ID of a key to remove." fi -if gpg_sphere "--list-key --fingerprint 0x${keyID}!" ; then +# FIXME: should we be doing a fancier list_certifier output here? +gpg_core --list-key --fingerprint "0x${keyID}!" || failure + +if [ "$PROMPT" = "true" ] ; then read -p "Really remove above listed identity certifier? (y/N) " OK; OK=${OK:-N} if [ "${OK/y/Y}" != 'Y' ] ; then failure "Identity certifier not removed." fi else - failure + log debug "certifier removed without prompting." fi # delete the requested key from the sphere keyring diff --git a/src/share/mh/add_hostname b/src/share/mh/add_hostname index 910faf6..70bbec3 100644 --- a/src/share/mh/add_hostname +++ b/src/share/mh/add_hostname @@ -31,11 +31,15 @@ userID="ssh://${1}" find_host_userid > /dev/null && \ failure "Host userID '$userID' already exists." -echo "The following user ID will be added to the host key:" -echo " $userID" -read -p "Are you sure you would like to add this user ID? (y/N) " OK; OK=${OK:=N} -if [ ${OK/y/Y} != 'Y' ] ; then - failure "User ID not added." +if [ "$PROMPT" = "true" ] ; then + echo "The following user ID will be added to the host key:" + echo " $userID" + read -p "Are you sure you would like to add this user ID? (y/N) " OK; OK=${OK:=N} + if [ ${OK/y/Y} != 'Y' ] ; then + failure "User ID not added." + fi +else + log debug "adding user ID without prompting." fi # edit-key script command to add user ID diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index 1464ae8..b4113df 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -77,10 +77,14 @@ fi log info "key found:" gpg_host --fingerprint "0x${fingerprint}!" -echo "Are you sure you want to add the above key as a" -read -p "revoker of the host key? (y/N) " OK; OK=${OK:-N} -if [ "${OK/y/Y}" != 'Y' ] ; then - failure "Revoker not added." +if [ "$PROMPT" = "true" ] ; then + echo "Are you sure you want to add the above key as a" + read -p "revoker of the host key? (y/N) " OK; OK=${OK:-N} + if [ "${OK/y/Y}" != 'Y' ] ; then + failure "revoker not added." + fi +else + log debug "adding revoker without prompting." fi # edit-key script to add revoker diff --git a/src/share/mh/publish_key b/src/share/mh/publish_key index 600dfcf..b433ad7 100644 --- a/src/share/mh/publish_key +++ b/src/share/mh/publish_key @@ -15,12 +15,33 @@ publish_key() { -read -p "Really publish host key to $KEYSERVER? (y/N) " OK; OK=${OK:=N} -if [ ${OK/y/Y} != 'Y' ] ; then - failure "key not published." +local GNUPGHOME + +if [ "$PROMPT" = "true" ] ; then + read -p "Really publish host key to $KEYSERVER? (y/N) " OK; OK=${OK:=N} + if [ ${OK/y/Y} != 'Y' ] ; then + failure "key not published." + fi +else + log debug "publishing key without prompting." fi +# create a temporary gnupg directory from which to publish the key +export GNUPGHOME=$(mktemp -d) + +# trap to remove tmp dir if break +trap "rm -rf $GNUPGHOME" EXIT + +# import the host key into the tmp dir +su_monkeysphere_user \ + "gpg --quiet --import" <"$HOST_KEY_FILE" + # publish host key -gpg_sphere "--keyserver $KEYSERVER --send-keys '0x${HOST_FINGERPRINT}!'" +su_monkeysphere_user \ + "gpg --keyserver $KEYSERVER --send-keys '0x${HOST_FINGERPRINT}!'" + +# remove the tmp file +trap - EXIT +rm -rf "$GNUPGHOME" } diff --git a/src/share/mh/revoke_hostname b/src/share/mh/revoke_hostname index 99ba603..77f1f0d 100644 --- a/src/share/mh/revoke_hostname +++ b/src/share/mh/revoke_hostname @@ -42,11 +42,15 @@ userID="ssh://${1}" uidIndex=$(find_host_userid) || \ failure "No non-revoked user ID found matching '$userID'." -echo "The following host key user ID will be revoked:" -echo " $userID" -read -p "Are you sure you would like to revoke this user ID? (y/N) " OK; OK=${OK:=N} -if [ ${OK/y/Y} != 'Y' ] ; then - failure "User ID not revoked." +if [ "$PROMPT" = "true" ] ; then + echo "The following host key user ID will be revoked:" + echo " $userID" + read -p "Are you sure you would like to revoke this user ID? (y/N) " OK; OK=${OK:=N} + if [ ${OK/y/Y} != 'Y' ] ; then + failure "User ID not revoked." + fi +else + log debug "revoking user ID without prompting." fi # edit-key script command to revoke user ID diff --git a/src/share/mh/set_expire b/src/share/mh/set_expire index 0b581d9..14d2501 100644 --- a/src/share/mh/set_expire +++ b/src/share/mh/set_expire @@ -21,6 +21,15 @@ local extendTo # get the new expiration date extendTo=$(get_gpg_expiration "$1") +if [ "$PROMPT" = "true" ] ; then + read -p "Are you sure you want to change the expiration on the host key to '$extendTo'? (y/N) " OK; OK=${OK:-N} + if [ "${OK/y/Y}" != 'Y' ] ; then + failure "expiration not set." + fi +else + log debug "extending without prompting." +fi + log info "setting host key expiration to ${extendTo}:" log debug "executing host expire script..." diff --git a/tests/basic b/tests/basic index d78a594..9114f32 100755 --- a/tests/basic +++ b/tests/basic @@ -242,7 +242,7 @@ gpg --export testuser | monkeysphere-authentication gpg-cmd --import echo "##################################################" echo "### update server authorized_keys file for this testuser..." monkeysphere-authentication update-users $(whoami) -# FIXME: NOT FAILING PROPERLY FOR: +# FIXME: this is maybe not failing properly for: # ms: improper group or other writability on path '/tmp'. -- cgit v1.2.3