Merge commit 'jrollins/master'
authorMatt Goins <mjgoins@openflows.com>
Tue, 10 Feb 2009 02:54:58 +0000 (21:54 -0500)
committerMatt Goins <mjgoins@openflows.com>
Tue, 10 Feb 2009 02:54:58 +0000 (21:54 -0500)
17 files changed:
man/man1/pem2openpgp.1
src/keytrans/pem2openpgp
src/monkeysphere-authentication
src/monkeysphere-host
src/share/common
src/share/ma/add_certifier
src/share/ma/setup
src/share/mh/add_hostname
src/share/mh/add_revoker
src/share/mh/extend_key [deleted file]
src/share/mh/gen_key
src/share/mh/import_key
src/share/mh/revoke_hostname
src/share/mh/set_expire [new file with mode: 0644]
tests/basic
tests/etc/monkeysphere/monkeysphere-authentication.conf
tests/home/testuser/.ssh/proxy-command

index 8ac230b19a9f6a728ca0b0c7b6487625e1d09bde..ae75b113701d0871cb14beea351804aca9953c40 100644 (file)
@@ -4,24 +4,82 @@
 .Os
 .Sh NAME
 pem2openpgp
-.Nd translate PEM encoded keys to OpenPGP keys
+.Nd translate PEM-encoded RSA keys to OpenPGP certificates
 .Sh SYNOPSIS
-.Nm pem2openpgp $USERID < mykey.pem 
+.Nm pem2openpgp "$USERID" < mykey.pem | gpg --import
 .Pp
-.Nm ??? gpg --export $KEYID | openpgp2ssh $KEYID
-.Pp
-.Nm ????gpg --export-secret-key $KEYID | openpgp2ssh $KEYID
+.Nm PEM2OPENPGP_EXPIRATION=$((86400 * $DAYS)) PEM2OPENPGP_USAGE_FLAGS=authentication,certify pem2openpgp "$USERID" <mykey.pem
 .Sh DESCRIPTION
 .Nm
-WRITE ME!!!
+is a low-level utility for transforming raw, PEM-encoded RSA secret
+keys into OpenPGP-formatted certificates.  The generated certificates
+include the secret key material, so they should be handled carefully.
+.Pp
+It works as an element within a pipeline: feed it the raw key on
+stdin, supply the desired User ID as a command line argument.  Note
+that you may need to quote the string to ensure that it is entirely in
+a single argument.
+.Pp
+Other choices about how to generate the new OpenPGP certificate are
+governed by environment variables.
+.Sh ENVIRONMENT
+The following environment variables influence the behavior of
+.Nm :
+.Pp
+.ti 3
+\fBPEM2OPENPGP_TIMESTAMP\fP controls the timestamp (measured in
+seconds since the UNIX epoch) indicated as the creation time (a.k.a
+"not valid before") of the generated certificate.  By default,
+.Nm
+uses the current time.
+.Pp
+.ti 3
+\fBPEM2OPENPGP_USAGE_FLAGS\fP should contain a comma-separated list of
+valid OpenPGP usage flags (see section 5.2.3.21 of RFC 4880 for what
+these mean).  The available choices are: certify, sign, encrypt_comms,
+encrypt_storage, encrypt (this means both encrypt_comms and
+encrypt_storage), authenticate, split, shared.  By default, 
+.Nm
+only sets the certify flag.
+.Pp
+.ti 3
+\fBPEM2OPENPGP_EXPIRATION\fP sets an expiration (measured in seconds
+after the creation time of the key) in each self-signature packet.  By
+default, no expiration subpacket is included.
+.Pp
+.ti 3
+\fBPEM2OPENPGP_NEWKEY\fP indicates that
+.Nm
+should ignore stdin, and instead generate a new key internally and
+build the certificate based on this new key.  Set this variable to the
+number of bits for the new key (e.g. 2048).  By default (when this is
+unset), 
+.Nm
+will read the key from stdin.
 .Sh AUTHOR
 .Nm
 and this man page were written by Daniel Kahn Gillmor
 <dkg@fifthhorseman.net>.
 .Sh BUGS
+Only handles RSA keys at the moment.  It would be nice to handle DSA
+keys as well.
+.Pp
+Currently only creates certificates with a single User ID.  Should be
+able to create certificates with multiple User IDs.
+.Pp
+Currently only accepts unencrypted RSA keys.  It should be able to
+deal with passphrase-locked key material.
+.Pp
+Currently outputs OpenPGP certificates with cleartext secret key
+material.  It would be good to be able to lock the output with a
+passphrase.
+.Pp
+If you find other bugs, please report them at
+https://labs.riseup.net/code/projects/show/monkeysphere
 .Sh SEE ALSO
 .Xr openpgp2ssh 1,
 .Xr monkeysphere 1 ,
 .Xr monkeysphere 7 ,
 .Xr ssh 1 ,
-.Xr monkeysphere-server 8
+.Xr monkeysphere-host 8 ,
+.Xr monkeysphere-authentication 8
index c765002b2a1cec100b95476589e105e06d51dfd0..2631da6e99b8bb04bb2a91b5df6be69171f7bea6 100755 (executable)
@@ -347,13 +347,16 @@ sub fingerprint {
   return Digest::SHA1::sha1(pack('Cn', 0x99, length($rsabody)).$rsabody);
 }
 
-# we're just not dealing with newline business right now.  slurp in
-# the whole file.
-undef $/;
-my $buf = <STDIN>;
 
-
-my $rsa = Crypt::OpenSSL::RSA->new_private_key($buf);
+my $rsa;
+if (defined $ENV{PEM2OPENPGP_NEWKEY}) {
+  $rsa = Crypt::OpenSSL::RSA->generate_key($ENV{PEM2OPENPGP_NEWKEY});
+} else {
+  # we're just not dealing with newline business right now.  slurp in
+  # the whole file.
+  undef $/;
+  $rsa = Crypt::OpenSSL::RSA->new_private_key(<STDIN>);
+}
 
 $rsa->use_sha1_hash();
 
index 4485bd4ffcdfcbbd92fd8152badaea6fd3071686..6d2e72cbe34d62aa82843f9121b9a8fa7e5e2297 100755 (executable)
@@ -70,19 +70,6 @@ subcommands:
 EOF
 }
 
-# function to run command as monkeysphere user
-su_monkeysphere_user() {
-    # if the current user is the monkeysphere user, then just eval
-    # command
-    if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
-       eval "$@"
-
-    # otherwise su command as monkeysphere user
-    else
-       su "$MONKEYSPHERE_USER" -c "$@"
-    fi
-}
-
 # function to interact with the gpg core keyring
 gpg_core() {
     GNUPGHOME="$GNUPGHOME_CORE"
@@ -184,7 +171,7 @@ case $COMMAND in
        list_certifiers "$@"
        ;;
 
-    'expert'|'e')
+    'expert')
        SUBCOMMAND="$1"
        shift
        case "$SUBCOMMAND" in
index a6fa62fbd80dafcb4fb218b7b7d3e58b82a50cdb..be398b159dfe22f5789157c795cad849ba280b45 100755 (executable)
@@ -14,6 +14,9 @@
 ########################################################################
 set -e
 
+# set the pipefail option so pipelines fail on first command failure
+set -o pipefail
+
 PGRM=$(basename $0)
 
 SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
@@ -65,70 +68,98 @@ subcommands:
 EOF
 }
 
-# function to run command as monkeysphere user
-su_monkeysphere_user() {
-    # if the current user is the monkeysphere user, then just eval
-    # command
-    if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
-       eval "$@"
+# function to interact with the gpg keyring
+gpg_host() {
+    GNUPGHOME="$GNUPGHOME_HOST" gpg "$@"
+}
+
+# command to list the info about the host key, in colon format
+gpg_host_list() {
+    gpg_host --list-keys --with-colons --fixed-list-mode \
+       --with-fingerprint --with-fingerprint \
+       "0x${HOST_FINGERPRINT}!"
 
-    # otherwise su command as monkeysphere user
-    else
-       su "$MONKEYSPHERE_USER" -c "$@"
-    fi
 }
 
-# function to interact with the gpg keyring
-gpg_host() {
-    local returnCode
+# command for edit key scripts, takes scripts on stdin
+gpg_host_edit() {
+    gpg_host --quiet --command-fd 0 --edit-key \
+       "0x${HOST_FINGERPRINT}!" "$@"
+}
 
-    GNUPGHOME="$GNUPGHOME_HOST"
-    export GNUPGHOME
+# export the host key to stdout
+gpg_host_export() {
+    gpg_host --export --armor --export-options export-minimal \
+       "0x${HOST_FINGERPRINT}!"
+}
 
-    # NOTE: we supress this warning because we need the monkeysphere
-    # user to be able to read the host pubring.  we realize this might
-    # be problematic, but it's the simplest solution, without too much
-    # loss of security.
-    gpg "$@"
+# export the host key to the monkeysphere host file key
+gpg_host_export_to_ssh_file() {
+    log debug "exporting openpgp public key..."
+
+    gpg_host_export > "$HOST_KEY_PUB_GPG"
+    log info "SSH host public key in OpenPGP form: $HOST_KEY_PUB_GPG"
 }
 
 # output just key fingerprint
-fingerprint_host_key() {
-    # set the pipefail option so functions fails if can't read sec key
-    set -o pipefail
-
+# 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
+       grep '^fpr:' | head -1 | cut -d: -f10 2>/dev/null || true
+}
+
+# output the index of a user ID on the host key
+# return 1 if user ID not found
+find_host_userid() {
+    local userID="$1"
+    local tmpuidMatch
+    local line
+
+    # 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
+    line=$(gpg_host_list | egrep '^(uid|uat):' | cut -f2,10 -d: | \
+       grep -n -x -F "$tmpuidMatch" 2>/dev/null)
+
+    if [ "$line" ] ; then
+       echo ${line%%:*}
+       return 0
+    else
+       return 1
+    fi
 }
 
 # function to check for host secret key
-check_host_keyring() {
-    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."
+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 fingerprintPGP
     local fingerprintSSH
 
-    # FIXME: you shouldn't have to be root to see the host key fingerprint
-    check_host_keyring
-    fingerprintPGP=$(fingerprint_host_key)
+    gpg_host --fingerprint --list-key --list-options show-unusable-uids \
+       "0x${HOST_FINGERPRINT}!" 2>/dev/null
+    # FIXME: make sure expiration date is shown
 
-    gpg_host --fingerprint --list-key --list-options show-unusable-uids "0x${fingerprintPGP}!" 2>/dev/null
-    echo "OpenPGP fingerprint: $fingerprintPGP"
+    echo "OpenPGP fingerprint: $HOST_FINGERPRINT"
 
-    if [ -f "${MHDATADIR}/ssh_host_rsa_key.pub" ] ; then
-       fingerprintSSH=$(ssh-keygen -l -f "${MHDATADIR}/ssh_host_rsa_key.pub" | \
+    if [ -f "$HOST_KEY_PUB" ] ; then
+       fingerprintSSH=$(ssh-keygen -l -f "$HOST_KEY_PUB" | \
            awk '{ print $1, $2, $4 }')
+
        echo "ssh fingerprint: $fingerprintSSH"
     else
-       log info "SSH host key not found."
+       log error "SSH host key not found."
     fi
 
-    # FIXME: show expiration date
     # FIXME: other relevant key parameters?
 }
 
@@ -155,6 +186,13 @@ 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
@@ -163,56 +201,57 @@ export MONKEYSPHERE_USER
 export KEYSERVER
 export GNUPGHOME_HOST
 export GNUPGHOME
+export HOST_FINGERPRINT
 
 # get subcommand
 COMMAND="$1"
 [ "$COMMAND" ] || failure "Type '$PGRM help' for usage."
 shift
 
+
 case $COMMAND in
     'show-key'|'show'|'s')
-       check_host_keyring
+       check_host_fail
        show_key
        ;;
 
-    # FIXME: what should we call this command?
     'set-expire'|'extend-key'|'e')
-       check_host_keyring
-       source "${MHSHAREDIR}/extend_key"
-       extend_key "$@"
+       check_host_fail
+       source "${MHSHAREDIR}/set_expire"
+       set_expire "$@"
        ;;
 
     'add-hostname'|'add-name'|'n+')
-       check_host_keyring
+       check_host_fail
        source "${MHSHAREDIR}/add_hostname"
        add_hostname "$@"
        ;;
 
     'revoke-hostname'|'revoke-name'|'n-')
-       check_host_keyring
+       check_host_fail
        source "${MHSHAREDIR}/revoke_hostname"
        revoke_hostname "$@"
        ;;
 
     'add-revoker'|'o')
-       check_host_keyring
+       check_host_fail
        source "${MHSHAREDIR}/add_revoker"
        add_revoker "$@"
        ;;
 
     'revoke-key'|'r')
-       check_host_keyring
+       check_host_fail
        source "${MHSHAREDIR}/revoke_key"
        revoke_key "$@"
        ;;
 
     'publish-key'|'publish'|'p')
-       check_host_keyring
+       check_host_fail
        source "${MHSHAREDIR}/publish_key"
        publish_key
        ;;
 
-    'expert'|'e')
+    'expert')
        SUBCOMMAND="$1"
        shift
        case "$SUBCOMMAND" in
index 00a10080008571b4cd89b40f10fcc59015f26dfd..2a20c1c9311e203f0f30009da0ba91172fad1ca3 100644 (file)
@@ -90,6 +90,19 @@ log() {
     done
 }
 
+# run command as monkeysphere user
+su_monkeysphere_user() {
+    # if the current user is the monkeysphere user, then just eval
+    # command
+    if [ $(id -un) = "$MONKEYSPHERE_USER" ] ; then
+       eval "$@"
+
+    # otherwise su command as monkeysphere user
+    else
+       su "$MONKEYSPHERE_USER" -c "$@"
+    fi
+}
+
 # cut out all comments(#) and blank lines from standard input
 meat() {
     grep -v -e "^[[:space:]]*#" -e '^$' "$1"
index 60a4f9d408d07b528020007a71a81a5f77d36944..e9731cc8da17740da7d73d4287286ccb2c5d73b3 100644 (file)
 
 add_certifier() {
 
-local domain
-local trust
-local depth
+local domain=
+local trust=full
+local depth=1
 local keyID
+local importinfo
 local fingerprint
 local ltsignCommand
 local trustval
 
-# set default values for trust depth and domain
-domain=
-trust=full
-depth=1
-
 # get options
 while true ; do
     case "$1" in
@@ -90,7 +86,7 @@ if [ -f "$keyID" ] ; then
 
     keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ )
     if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then
-       failure "Expected there to be a single gpg key in the file."
+       failure "There was not exactly one gpg key in the file."
     fi
 else
     # get the key from the key server
@@ -132,8 +128,7 @@ case "$trust" in
        ;;
 esac
 
-# this is the gpg "script" that gpg --edit-key will execute for the
-# core to sign certifier.
+# edit-key script to ltsign key
 # NOTE: *all* user IDs will be ltsigned
 ltsignCommand=$(cat <<EOF
 ltsign
index 422cfd3efcc58e009bb10b2370e59ee5219fbc16..034f0471bbc980f5985e676ee4cbbcdd4dbd84e5 100644 (file)
@@ -53,17 +53,8 @@ EOF
 
        local CORE_UID=$(printf "Monkeysphere authentication trust core UID (random string: %s)" $(head -c21 </dev/urandom | base64))
     
-       local TMPLOC=$(mktemp -d "${MATMPDIR}"/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!"
-
-       # generate the key with ssh-keygen...
-       log debug "generating ssh key ($CORE_KEYLENGTH bits)..."
-       ssh-keygen -q -b "$CORE_KEYLENGTH" -t rsa -N '' -f "${TMPLOC}/authkey" || failure "Could not generate new key for Monkeysphere authentication trust core"
-       # and then translate to openpgp encoding and import
-       # FIXME: pem2openpgp currently sets the A flag and a short
-       # expiration date.  We should set the C flag and no expiration
-       # date.
-       log debug "converting ssh key to openpgp key and importing into core..."
-       < "${TMPLOC}/authkey" pem2openpgp "$CORE_UID" | gpg_core --import || failure "Could not import new key for Monkeysphere authentication trust core"
+       log debug "generating monkeysphere authentication trust core key ($CORE_KEYLENGTH bits)..."
+       PEM2OPENPGP_USAGE_FLAGS=certify PEM2OPENPGP_NEWKEY=$CORE_KEYLENGTH pem2openpgp "$CORE_UID" | gpg_core --import || failure "Could not import new key for Monkeysphere authentication trust core"
 
        # get fingerprint of core key.  should definitely not be empty at this point
        log debug "get core key fingerprint..."
index 267f109e811b662597e5cd97c4a9f6a1285b30ad..46326bb998e0544f2f5ff901940b48afbc4d87b5 100644 (file)
@@ -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
 
index f9d0bb67c82b50f725bab752ce281ce050c0c23b..39dfacac6544774c0caaead19876c4cb22e26d9b 100644 (file)
 
 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/extend_key b/src/share/mh/extend_key
deleted file mode 100644 (file)
index 79ee267..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-# -*-shell-script-*-
-# This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
-
-# Monkeysphere host extend-key subcommand
-#
-# The monkeysphere scripts are written by:
-# Jameson Rollins <jrollins@finestructure.net>
-# Jamie McClelland <jm@mayfirst.org>
-# Daniel Kahn Gillmor <dkg@fifthhorseman.net>
-#
-# 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() {
-
-local fpr=$(fingerprint_host_key)
-local extendTo="$1"
-
-# get the new expiration date
-extendTo=$(get_gpg_expiration "$extendTo")
-
-gpg_host --quiet --command-fd 0 --edit-key "$fpr" <<EOF 
-expire
-$extendTo
-save
-EOF
-
-cat <<EOF | log info
-NOTE: Host key expiration date adjusted, but not yet published.
-Run '$PGRM publish-key' to publish the new expiration date.
-EOF
-
-}
index eb951cf1f112c1e7efd12fce0852c316c8076002..7b427e4cf628d69b9b661ffbc8a0abc567560d9d 100644 (file)
 
 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
index 2e73a8c6cc32878a11e413ca706f5290d91e55c7..99511a86095ef9f806a6aaa8b58052867c0f047a 100644 (file)
@@ -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
index 06b5810f886f99800a1cac53109917db66cdf64b..940b5f462f2ef7694a1d772e9aee2992d5bb3d54 100644 (file)
@@ -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/set_expire b/src/share/mh/set_expire
new file mode 100644 (file)
index 0000000..653149f
--- /dev/null
@@ -0,0 +1,34 @@
+# -*-shell-script-*-
+# This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
+
+# 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>
+# Jamie McClelland <jm@mayfirst.org>
+# Daniel Kahn Gillmor <dkg@fifthhorseman.net>
+#
+# They are Copyright 2008-2009, and are all released under the GPL,
+# version 3 or later.
+
+set_expire() {
+
+local extendTo
+
+# get the new expiration date
+extendTo=$(get_gpg_expiration "$1")
+
+gpg_host_edit expire <<EOF
+$extendTo
+save
+EOF
+
+cat <<EOF | log info
+NOTE: Host key expiration date adjusted, but not yet published.
+Run '$PGRM publish-key' to publish the new expiration date.
+EOF
+
+}
index 5c6b4bb24300d7bfc9e4adf990a5e70ae9f1aa71..d9399f0943e66509520934457cfd793bceec6d2c 100755 (executable)
@@ -17,7 +17,8 @@ set -e
 # piped commands should return the code of the first non-zero return
 set -o pipefail
 
-export TESTDIR=$(dirname "$0")
+# make sure the TESTDIR is an absolute path, not a relative one.
+export TESTDIR=$(cd $(dirname "$0") && pwd)
 
 source "$TESTDIR"/common
 
@@ -32,6 +33,7 @@ which socat >/dev/null || { echo "You must have socat installed to run this test
 
 # gpg command for test admin user
 gpgadmin() {
+    chmod 0700 "$TEMPDIR"/admin
     GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg "$@"
 }
 
@@ -89,12 +91,8 @@ trap failed_cleanup EXIT
 ## the tests, not system-wide:
 
 # make temp dir
-TEMPDIR="$TESTDIR"/tmp
-if [ -e "$TEMPDIR" ] ; then
-    echo "tempdir '$TEMPDIR' already exists."
-    exit 1
-fi
-mkdir -p "$TEMPDIR"
+mkdir -p "$TESTDIR"/tmp
+TEMPDIR=$(mktemp -d "${TMPDIR:-$TESTDIR/tmp}/monkeyspheretest.XXXXXXX")
 
 # Use the local copy of executables first, instead of system ones.
 # This should help us test without installing.
@@ -130,6 +128,7 @@ cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
 # set up environment for testuser
 export TESTHOME="$TEMPDIR"/testuser
 export GNUPGHOME="$TESTHOME"/.gnupg
+chmod 0700 "$GNUPGHOME"
 export SSH_ASKPASS="$TESTHOME"/.ssh/askpass
 export MONKEYSPHERE_HOME="$TESTHOME"/.monkeysphere
 cat <<EOF >> "$TESTHOME"/.ssh/config
@@ -207,7 +206,7 @@ echo "##################################################"
 echo "### setup monkeysphere authentication..."
 cp "$TESTDIR"/etc/monkeysphere/monkeysphere-authentication.conf "$TEMPDIR"/
 cat <<EOF >> "$TEMPDIR"/monkeysphere-authentication.conf
-AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authentication/authorized_user_ids"
+AUTHORIZED_USER_IDS="$MONKEYSPHERE_HOME/authorized_user_ids"
 EOF
 monkeysphere-authentication setup
 get_gpg_prng_arg >> "$MONKEYSPHERE_SYSDATADIR"/authentication/sphere/gpg.conf
@@ -236,7 +235,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 gpg-cmd --import
+gpg --export testuser | monkeysphere-authentication expert gpg-cmd --import
 
 # update authorized_keys for user
 echo "##################################################"
@@ -247,7 +246,7 @@ monkeysphere-authentication update-users $(whoami)
 ######################################################################
 ### TESTS
 
-# connect to test sshd, using monkeysphere-ssh-proxycommand to verify
+# connect to test sshd, using monkeysphere ssh-proxycommand to verify
 # the identity before connection.  This should work in both directions!
 echo "##################################################"
 echo "### ssh connection test for success..."
index 9cc396f718ab661fa3dcb8229b6fc350f8d2b306..b4ecc05b41687e88683417ed188a79dc3cfecc11 100644 (file)
@@ -1,4 +1,4 @@
-# Base monkeysphere-server.conf for monkeysphere tests
+# Base monkeysphere-authentication.conf for monkeysphere tests
 
 # AUTHORIZED_USER_IDS variable will be added dynamically during test.
 
index 21c66faaf7dc2e046c3198844a338cdbad1ea38f..214cc23b7a29c5ef4fe2753cf157ab22f9d5f26c 100755 (executable)
@@ -3,6 +3,7 @@
 # simple socket-based proxy-command wrapper for testing monkeysphere.
 
 # pass this thing the host, the port, and the socket.
+which monkeysphere >&2
 
-monkeysphere-ssh-proxycommand --no-connect "$1" "$2" && \
+monkeysphere ssh-proxycommand --no-connect "$1" "$2" && \
 exec socat STDIO UNIX:"$3"