2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere host import-key subcommand
6 # The monkeysphere scripts are written by:
7 # Jameson Rollins <jrollins@finestructure.net>
8 # Jamie McClelland <jm@mayfirst.org>
9 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
11 # They are Copyright 2008-2009 and are all released under the GPL,
16 local hostName=$(hostname -f)
17 local keyFile="/etc/ssh/ssh_host_rsa_key"
21 # check for presense of secret key
22 # FIXME: is this the proper test to be doing here?
23 fingerprint_server_key >/dev/null \
24 && failure "An OpenPGP host key already exists."
38 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
39 failure "Unknown option '$1'.
40 Type '$PGRM help' for usage."
50 if [ ! -f "$keyFile" ] ; then
51 failure "SSH secret key file '$keyFile' not found."
54 userID="ssh://${hostName}"
56 # prompt about key expiration if not specified
57 keyExpire=$(get_gpg_expiration "$keyExpire")
59 echo "The following key parameters will be used for the host private key:"
60 echo "Import: $keyFile"
61 echo "Name-Real: $userID"
62 echo "Expire-Date: $keyExpire"
64 read -p "Import key? (Y/n) " OK; OK=${OK:=Y}
65 if [ ${OK/y/Y} != 'Y' ] ; then
69 log verbose "importing ssh key..."
70 # translate ssh key to a private key
72 pem2openpgp "$userID" "$keyExpire" < "$sshKey" | gpg_host --import)
74 # find the key fingerprint of the newly converted key
75 fingerprint=$(fingerprint_server_key)
77 # export host ownertrust to authentication keyring
78 log verbose "setting ultimate owner trust for host key..."
79 echo "${fingerprint}:6:" | gpg_host "--import-ownertrust"
80 echo "${fingerprint}:6:" | gpg_authentication "--import-ownertrust"
82 # export public key to file
83 gpg_authentication "--export-options export-minimal --armor --export 0x${fingerprint}\!" > "${SYSDATADIR}/ssh_host_rsa_key.pub.gpg"
84 log info "SSH host public key in OpenPGP form: ${SYSDATADIR}/ssh_host_rsa_key.pub.gpg"
86 # show info about new key