diff options
author | Matt Goins <mjgoins@openflows.com> | 2009-02-09 21:54:58 -0500 |
---|---|---|
committer | Matt Goins <mjgoins@openflows.com> | 2009-02-09 21:54:58 -0500 |
commit | 3b81cd012e8224490a3836cccbd7d082a061658e (patch) | |
tree | 71fa874a6a98680388ff7a8b1a6e478390bd5b1d /src/share/mh | |
parent | c9a361eecab5ea18d0b868580a3d0703517ab677 (diff) | |
parent | d71cf8d24bd9357a016b1ead375a67ccd955c130 (diff) |
Merge commit 'jrollins/master'
Diffstat (limited to 'src/share/mh')
-rw-r--r-- | src/share/mh/add_hostname | 16 | ||||
-rw-r--r-- | src/share/mh/add_revoker | 85 | ||||
-rw-r--r-- | src/share/mh/gen_key | 68 | ||||
-rw-r--r-- | src/share/mh/import_key | 19 | ||||
-rw-r--r-- | src/share/mh/revoke_hostname | 24 | ||||
-rw-r--r-- | src/share/mh/set_expire (renamed from src/share/mh/extend_key) | 17 |
6 files changed, 134 insertions, 95 deletions
diff --git a/src/share/mh/add_hostname b/src/share/mh/add_hostname index 267f109..46326bb 100644 --- a/src/share/mh/add_hostname +++ b/src/share/mh/add_hostname @@ -27,18 +27,9 @@ fi userID="ssh://${1}" -fingerprint=$(fingerprint_host_key) - -# match to only ultimately trusted user IDs -tmpuidMatch="u:$(echo $userID | gpg_escape)" - -# find the index of the requsted user ID -# NOTE: this is based on circumstantial evidence that the order of -# this output is the appropriate index -if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \ - | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then +# test that the desired user ID does not already exist +find_host_userid > /dev/null && \ failure "Host userID '$userID' already exists." -fi echo "The following user ID will be added to the host key:" echo " $userID" @@ -58,8 +49,7 @@ EOF ) # execute edit-key script -if echo "$adduidCommand" | \ - gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then +if echo "$adduidCommand" | gpg_host_edit ; then show_key diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index f9d0bb6..39dfaca 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -15,7 +15,92 @@ add_revoker() { +local domain= +local trust=full +local depth=1 +local keyID +local importinfo +local fingerprint +local ltsignCommand +local trustval + +keyID="$1" +if [ -z "$keyID" ] ; then + failure "You must specify the key ID of a revoker key, or specify a file to read the key from." +fi +if [ -f "$keyID" ] ; then + log info "Reading key from file '$keyID':" + importinfo=$(gpg_host --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'\''' + + keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ ) + if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then + failure "There was not exactly one gpg key in the file." + fi +else + # create a temporary directory for storing the downloaded key + 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 \ + "GNUPGHOME=$TMPLOC gpg --keyserver $KEYSERVER --recv-key 0x${keyID}!" + + # export the new key to the host keyring + su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --export 0x${keyID}!" \ + | gpg_host --import +fi + +export keyID + +# get the full fingerprint of the revoker key ID +fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \ + | grep '^fpr:' | grep "$keyID" | cut -d: -f10) + +if [ -z "$fingerprint" ] ; then + failure "Key '$keyID' not found." +fi + +log info -e "\nkey 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." +fi + +# edit-key script to add revoker +# NOTE: *all* user IDs will be ltsigned +addrevokerCommand=$(cat <<EOF +addrevoker + +EOF + ) + # FIXME: implement! failure "not implemented yet!" +# core ltsigns the newly imported revoker key +if echo "$addrevokerCommand" | \ + gpg_core_edit ; then + + log info -e "\nRevoker added." +else + failure "Problem adding revoker." +fi + } diff --git a/src/share/mh/gen_key b/src/share/mh/gen_key index eb951cf..7b427e4 100644 --- a/src/share/mh/gen_key +++ b/src/share/mh/gen_key @@ -13,19 +13,16 @@ gen_key() { +local hostName=$(hostname -f) local keyType="RSA" local keyLength="2048" local keyUsage="auth" local keyExpire="0" -local hostName=$(hostname -f) local userID -local keyParameters -local fingerprint -# check for presense of secret key -# FIXME: is this the proper test to be doing here? -fingerprint_host_key >/dev/null \ - && failure "An OpenPGP host key already exists." +# check for presense of a key +[ "$HOST_FINGERPRINT" ] && \ + failure "An OpenPGP host key already exists." # get options while true ; do @@ -39,65 +36,50 @@ while true ; do failure "Unknown option '$1'. Type '$PGRM help' for usage." fi - hostName="$1" - shift break ;; esac done +hostName="$1" userID="ssh://${hostName}" -# set key parameters -keyParameters=\ -"Key-Type: $keyType +# create host home +mkdir -p "$GNUPGHOME_HOST" +chmod 700 "$GNUPGHOME_HOST" + +log debug "generating host key..." +gpg_host --batch --gen-key <<EOF +Key-Type: $keyType Key-Length: $keyLength Key-Usage: $keyUsage Name-Real: $userID -Expire-Date: $keyExpire" - -echo "The following key parameters will be used for the host key:" -echo "$keyParameters" - -read -p "Generate key? (Y/n) " OK; OK=${OK:=Y} -if [ ${OK/y/Y} != 'Y' ] ; then - failure "aborting." -fi - -# add commit command -# must include blank line! -keyParameters=\ -"${keyParameters} +Expire-Date: $keyExpire %commit -%echo done" - -# create host home -mkdir -p "$GNUPGHOME_HOST" -chmod 700 "$GNUPGHOME_HOST" +%echo done -log verbose "generating host key..." -echo "$keyParameters" | gpg_host --batch --gen-key +EOF -# find the key fingerprint of the newly generated key -fingerprint=$(fingerprint_host_key) +# find the key fingerprint of the newly converted key +HOST_FINGERPRINT=$(get_host_fingerprint) +export HOST_FINGERPRINT # translate the private key to ssh format, and export to a file # for sshs usage. # NOTE: assumes that the primary key is the proper key to use -log debug "exporting new secret key to ssh format..." +log debug "exporting ssh secret key..." (umask 077 && \ - gpg_host --export-secret-key "$fingerprint" | \ - openpgp2ssh "$fingerprint" > "${MHDATADIR}/ssh_host_rsa_key") + gpg_host --export-secret-key "$HOST_FINGERPRINT" | \ + openpgp2ssh "$HOST_FINGERPRINT" > "${MHDATADIR}/ssh_host_rsa_key") log info "SSH host private key output to file: ${MHDATADIR}/ssh_host_rsa_key" log debug "creating ssh public key..." -ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "${MHDATADIR}/ssh_host_rsa_key.pub" -log info "SSH host public key output to file: ${MHDATADIR}/ssh_host_rsa_key.pub" +ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB" +log info "SSH host public key output to file: $HOST_KEY_PUB" -log debug "exporting openpgp public key..." -gpg_host --export-options export-minimal --armor --export "0x${fingerprint}!" > "${MHDATADIR}/ssh_host_rsa_key.pub.gpg" -log info "SSH host public key in OpenPGP form: ${MHDATADIR}/ssh_host_rsa_key.pub.gpg" +# export public key to file +gpg_host_export_to_ssh_file # show info about new key show_key diff --git a/src/share/mh/import_key b/src/share/mh/import_key index 2e73a8c..99511a8 100644 --- a/src/share/mh/import_key +++ b/src/share/mh/import_key @@ -15,12 +15,10 @@ import_key() { local hostName local userID -local fingerprint -# check for presense of secret key -# FIXME: is this the proper test to be doing here? -fingerprint_host_key >/dev/null \ - && failure "An OpenPGP host key already exists." +# check for presense of a key +[ "$HOST_FINGERPRINT" ] && \ + failure "An OpenPGP host key already exists." hostName=${1:-$(hostname -f)} @@ -32,16 +30,15 @@ chmod 700 "$GNUPGHOME_HOST" log verbose "importing ssh key..." # translate ssh key to a private key -(umask 077 && \ - pem2openpgp "$userID" | gpg_host --import) +PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" | \ + gpg_host --import # find the key fingerprint of the newly converted key -fingerprint=$(fingerprint_host_key) +HOST_FINGERPRINT=$(get_host_fingerprint) +export HOST_FINGERPRINT # export public key to file -log debug "exporting openpgp public key..." -gpg_host --export-options export-minimal --armor --export "0x${fingerprint}!" > "${MHDATADIR}/ssh_host_rsa_key.pub.gpg" -log info "SSH host public key in OpenPGP form: ${MHDATADIR}/ssh_host_rsa_key.pub.gpg" +gpg_host_export_to_ssh_file # show info about new key show_key diff --git a/src/share/mh/revoke_hostname b/src/share/mh/revoke_hostname index 06b5810..940b5f4 100644 --- a/src/share/mh/revoke_hostname +++ b/src/share/mh/revoke_hostname @@ -38,20 +38,9 @@ fi userID="ssh://${1}" -fingerprint=$(fingerprint_host_key) - -# match to only ultimately trusted user IDs -tmpuidMatch="u:$(echo $userID | gpg_escape)" - -# find the index of the requsted user ID -# NOTE: this is based on circumstantial evidence that the order of -# this output is the appropriate index -if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \ - | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then - uidIndex=${line%%:*} -else - failure "No non-revoked user ID '$userID' is found." -fi +# make sure the user ID to revoke +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" @@ -60,15 +49,13 @@ if [ ${OK/y/Y} != 'Y' ] ; then failure "User ID not revoked." fi -message="Hostname removed by monkeysphere-server $DATE" - # edit-key script command to revoke user ID revuidCommand=$(cat <<EOF $uidIndex revuid y 4 -$message +Hostname removed by monkeysphere-host: $DATE y save @@ -76,8 +63,7 @@ EOF ) # execute edit-key script -if echo "$revuidCommand" | \ - gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then +if echo "$revuidCommand" | gpg_host_edit ; then show_key diff --git a/src/share/mh/extend_key b/src/share/mh/set_expire index 79ee267..653149f 100644 --- a/src/share/mh/extend_key +++ b/src/share/mh/set_expire @@ -1,7 +1,10 @@ # -*-shell-script-*- # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant) -# Monkeysphere host extend-key subcommand +# Monkeysphere host set-expire subcommand +# +# This is a function to set the expiration date of the monkeysphere +# host key. # # The monkeysphere scripts are written by: # Jameson Rollins <jrollins@finestructure.net> @@ -11,18 +14,14 @@ # They are Copyright 2008-2009, and are all released under the GPL, # version 3 or later. -# extend the lifetime of a host key: - -extend_key() { +set_expire() { -local fpr=$(fingerprint_host_key) -local extendTo="$1" +local extendTo # get the new expiration date -extendTo=$(get_gpg_expiration "$extendTo") +extendTo=$(get_gpg_expiration "$1") -gpg_host --quiet --command-fd 0 --edit-key "$fpr" <<EOF -expire +gpg_host_edit expire <<EOF $extendTo save EOF |