summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/basic77
-rwxr-xr-xtests/keytrans47
-rw-r--r--tests/openssl.cnf26
3 files changed, 119 insertions, 31 deletions
diff --git a/tests/basic b/tests/basic
index 6fe3237..4ceabd4 100755
--- a/tests/basic
+++ b/tests/basic
@@ -10,7 +10,7 @@
# Jameson Rollins <jrollins@fifthhorseman.net>
# Micah Anderson <micah@riseup.net>
#
-# Copyright: 2008-2009
+# Copyright: © 2008-2010
# License: GPL v3 or later
# these tests should all be able to run as a non-privileged user.
@@ -73,7 +73,7 @@ ssh_test() {
# make a client connection to the socket
echo "##### starting ssh client..."
ssh-agent bash -c \
- "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config ${target_hostname:-testhost} true" \
+ "monkeysphere subkey-to-ssh-agent && ssh -F $TEMPDIR/testuser/.ssh/config ${target_hostname:-testhost.example} true" \
|| RETURN="$?"
# kill the sshd process if it's still running
@@ -133,6 +133,8 @@ export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src/share
export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
+HOST_KEY_FILE="$MONKEYSPHERE_SYSCONFIGDIR"/host_keys.pub.pgp
+
export MONKEYSPHERE_CHECK_KEYSERVER=false
# example.org does not respond to the HKP port, so this should cause
# any keyserver connection attempts that do happen (they shouldn't!)
@@ -250,13 +252,13 @@ echo
echo "##################################################"
echo "### import host key..."
ssh-keygen -b 1024 -t rsa -N '' -f "$TEMPDIR"/ssh_host_rsa_key
-monkeysphere-host import-key "$TEMPDIR"/ssh_host_rsa_key testhost
+monkeysphere-host import-key "$TEMPDIR"/ssh_host_rsa_key ssh://testhost.example
echo
echo "##################################################"
echo "### getting host key fingerprint..."
-HOSTKEYID=$( monkeysphere-host show-key | grep '^OpenPGP fingerprint: ' | cut -f3 -d\ )
-echo "$HOSTKEYID"
+SSHHOSTKEYID=$( monkeysphere-host show-keys | grep '^OpenPGP fingerprint: ' | cut -f3 -d\ )
+echo "$SSHHOSTKEYID"
# change host key expiration
echo
@@ -270,8 +272,8 @@ monkeysphere-host set-expire 1
echo
echo "##################################################"
echo "### certifying server host key..."
-< "$MONKEYSPHERE_SYSCONFIGDIR"/ssh_host_rsa_key.pub.gpg gpgadmin --import
-echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
+< "$HOST_KEY_FILE" gpgadmin --import
+echo y | gpgadmin --command-fd 0 --sign-key "$SSHHOSTKEYID"
# FIXME: add revoker?
@@ -295,7 +297,7 @@ EOF
monkeysphere-authentication setup
get_gpg_prng_arg >> "$MONKEYSPHERE_SYSDATADIR"/authentication/sphere/gpg.conf
-# add admin as identity certifier for testhost
+# add admin as identity certifier for testhost.example
echo
echo "##################################################"
echo "### adding admin as certifier..."
@@ -321,7 +323,7 @@ monkeysphere gen-subkey
echo
echo "##################################################"
echo "### export server key to testuser..."
-gpgadmin --armor --export "$HOSTKEYID" | gpg --import
+gpgadmin --armor --export "$SSHHOSTKEYID" | gpg --import
# teach the "server" about the testuser's key
echo
@@ -340,6 +342,12 @@ monkeysphere-authentication update-users $(whoami)
######################################################################
### TESTS
+## see whether keys-for-userid works from the client's perspective:
+echo
+echo "##################################################"
+echo "### testing monkeysphere keys-for-userid ..."
+diff -q <( monkeysphere keys-for-userid ssh://testhost.example ) <( cut -f1,2 -d' ' < "$TEMPDIR"/ssh_host_rsa_key.pub )
+
# connect to test sshd, using monkeysphere ssh-proxycommand to verify
# the identity before connection. This should work in both directions!
echo
@@ -495,43 +503,41 @@ ssh_test
echo
echo "##################################################"
-echo "### ssh connection test directly to 'testhost2' without new name..."
-target_hostname=testhost2 ssh_test 255
+echo "### ssh connection test directly to 'testhost2.example' without new name..."
+target_hostname=testhost2.example ssh_test 255
echo
echo "##################################################"
-echo "### add hostname, certify by admin, import by user..."
-monkeysphere-host add-hostname testhost2
-< "$MONKEYSPHERE_SYSCONFIGDIR"/ssh_host_rsa_key.pub.gpg gpgadmin --import
-printf "y\ny\n" | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
+echo "### add servicename, certify by admin, import by user..."
+monkeysphere-host add-servicename ssh://testhost2.example
+<"$HOST_KEY_FILE" gpgadmin --import
+printf "y\ny\n" | gpgadmin --command-fd 0 --sign-key "$SSHHOSTKEYID"
echo
echo "##################################################"
-echo "### ssh connection test with hostname 'testhost2' added..."
-gpgadmin --export "$HOSTKEYID" | gpg --import
+echo "### ssh connection test with hostname 'testhost2.example' added..."
+gpgadmin --export "$SSHHOSTKEYID" | gpg --import
gpg --check-trustdb
ssh_test
echo
echo "##################################################"
-echo "### ssh connection test directly to 'testhost2' ..."
-gpg --import <"$MONKEYSPHERE_SYSCONFIGDIR"/ssh_host_rsa_key.pub.gpg
+echo "### ssh connection test directly to 'testhost2.example' ..."
+gpg --import <"$HOST_KEY_FILE"
gpg --check-trustdb
-target_hostname=testhost2 ssh_test
+target_hostname=testhost2.example ssh_test
echo
echo "##################################################"
-echo "### ssh connection test for failure with 'testhost2' revoked..."
-monkeysphere-host revoke-hostname testhost2
-gpg --import <"$MONKEYSPHERE_SYSCONFIGDIR"/ssh_host_rsa_key.pub.gpg
+echo "### ssh connection test for failure with 'testhost2.example' revoked..."
+monkeysphere-host revoke-servicename ssh://testhost2.example
+gpg --import <"$HOST_KEY_FILE"
gpg --check-trustdb
-target_hostname=testhost2 ssh_test 255
+target_hostname=testhost2.example ssh_test 255
# FIXME: addtest: remove admin as id-certifier and check ssh failure
# FIXME: addtest: how do we test that set-expire makes sense after new
-# hostnames have been added?
-
-# FIXME: addtest: revoke the host key and check ssh failure
+# servicenames have been added?
# test to make sure things are OK after the previous tests:
echo
@@ -545,10 +551,23 @@ ssh_test
echo
echo "##################################################"
-echo "### revoking host key..."
+echo "### Testing TLS setup..."
+
+openssl req -config "$TESTDIR"/openssl.cnf -x509 -newkey rsa:1024 -subj '/DC=example/DC=testhost/CN=testhost.example/' -days 3 -keyout "$TEMPDIR"/tls_key.pem -nodes >"$TEMPDIR"/tls_cert.pem
+monkeysphere-host import-key "$TEMPDIR"/tls_key.pem https://testhost.example
+
+# FIXME: how can we test this via an https client?
+# We don't currently provide one.
+
+# FIXME: should we test other monkeysphere-host operations somehow now
+# that we have more than one key in the host keyring?
+
+echo
+echo "##################################################"
+echo "### revoking ssh host key..."
# generate the revocation certificate and feed it directly to the test
# user's keyring (we're not publishing to the keyservers)
-monkeysphere-host revoke-key | gpg --import
+monkeysphere-host revoke-key "$SSHHOSTKEYID" | gpg --import
echo
echo "##################################################"
echo "### ssh connection test for failure..."
diff --git a/tests/keytrans b/tests/keytrans
index 8808cbc..411b42e 100755
--- a/tests/keytrans
+++ b/tests/keytrans
@@ -106,8 +106,8 @@ diff -u \
<(hd "$TEMPDIR"/secret.key) \
<(hd "$TEMPDIR"/converted.secret.key)
-
-KEYID=$(gpg --fingerprint --with-colons --list-keys | grep ^fpr | cut -f10 -d: | cut -b25-40)
+KEYFPR=$(gpg --fingerprint --with-colons --list-keys | grep ^fpr | cut -f10 -d:)
+KEYID=$(printf "%s" "$KEYFPR" | cut -b25-40)
echo "conversions look good!"
@@ -162,6 +162,49 @@ EOF
diff -u "$TEMPDIR"/expectedout <(gpg --check-sigs --with-colons --fixed-list-mode | grep -v ^tru)
+echo "##################################################"
+echo "### test working with two primary keys ... "
+
+ssh-keygen -t rsa -b 1024 -N '' -f "$TEMPDIR"/newkey
+
+PEM2OPENPGP_USAGE_FLAGS=authenticate,certify \
+PEM2OPENPGP_TIMESTAMP="$(( $timestamp + 1 ))" pem2openpgp fubar \
+ < "$TEMPDIR"/newkey > "$TEMPDIR"/newkey.gpg
+
+NEWKEYFPR=$(< "$TEMPDIR"/newkey.gpg keytrans listfprs)
+NEWKEYID=$( printf "%s" "$NEWKEYFPR" | cut -b25-40)
+
+< "$TEMPDIR"/newkey.gpg gpg --import
+
+< "$TEMPDIR"/secring.gpg \
+PEM2OPENPGP_TIMESTAMP="$timestamp" \
+ keytrans adduserid "$KEYID" "baz" | gpg --import
+
+cat >"$TEMPDIR"/expectedout <<EOF
+pub:u:1024:1:$KEYID:$timestamp:::u:::scSC:
+uid:u::::$timestamp::E90EC72E68C6C2A0751DADC70F54F60D27B88C3D::monkeymonkey:
+sig:!::1:$KEYID:$timestamp::::monkeymonkey:13x:
+uid:r::::::8200BD0425CC70C7D698DF3FE412044EAAB83F94::testtest:
+sig:!::1:$KEYID:$timestamp::::monkeymonkey:13x:
+rev:!::1:$KEYID:$revtime::::monkeymonkey:30x:
+uid:u::::$timestamp::EDDC32D783E7F4C7B6982D9AE5DC4A61000648BA::baz:
+sig:!::1:$KEYID:$timestamp::::monkeymonkey:13x:
+pub:-:1024:1:$NEWKEYID:$(($timestamp + 1)):::-:::caCA:
+uid:-::::$(($timestamp + 1))::A0D708F51CC257DEFC01AEDE1E0A5F329DFD8F16::fubar:
+sig:!::1:$NEWKEYID:$(($timestamp + 1))::::fubar:13x:
+EOF
+
+echo "test: diff expected gpg list output"
+diff -u "$TEMPDIR"/expectedout <(gpg --check-sigs --with-colons --fixed-list-mode | grep -v ^tru)
+
+sort >"$TEMPDIR"/expectedout <<EOF
+$KEYFPR
+$NEWKEYFPR
+EOF
+
+echo "test: diff expected keytrans listfpr output"
+diff -u "$TEMPDIR"/expectedout <( < "$TEMPDIR"/secring.gpg keytrans listfprs | sort )
+
## FIXME: addtest: not testing subkeys at the moment.
diff --git a/tests/openssl.cnf b/tests/openssl.cnf
new file mode 100644
index 0000000..3456dc5
--- /dev/null
+++ b/tests/openssl.cnf
@@ -0,0 +1,26 @@
+# OpenSSL configuration for the purposes of the monkeysphere test suite:
+
+# This definition stops the following lines choking if HOME isn't
+# defined.
+HOME = .
+RANDFILE = $ENV::HOME/.rnd
+
+[ req ]
+attributes = req_attributes
+x509_extensions = monkeysphere_self_signed
+distinguished_name = req_dn
+attributes = req_attrs
+
+[ monkeysphere_self_signed ]
+
+# Just generate an X.509 cert that is for specific use as a TLS server
+basicConstraints = CA:FALSE
+keyUsage = digitalSignature, keyEncipherment
+extendedKeyUsage = serverAuth
+nsCertType = server
+
+[ req_dn ]
+commonName = Common Name
+commonName_max = 64
+
+[ req_attrs ]