-# 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}!"
+
+}
+
+# command for edit key scripts, takes scripts on stdin
+gpg_host_edit() {
+ gpg_host --quiet --command-fd 0 --edit-key \
+ "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 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 "GPG host public key file: $HOST_KEY_PUB_GPG"
+}