3 # Monkeysphere host import-key subcommand
5 # The monkeysphere scripts are written by:
6 # Jameson Rollins <jrollins@fifthhorseman.net>
7 # Jamie McClelland <jm@mayfirst.org>
8 # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
10 # They are Copyright 2008, and are all released under the GPL, version 3
13 local hostName=$(hostname -f)
14 local keyFile="/etc/ssh/ssh_host_rsa_key"
18 # check for presense of secret key
19 # FIXME: is this the proper test to be doing here?
20 fingerprint_server_key >/dev/null \
21 && failure "An OpenPGP host key already exists."
35 if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
36 failure "Unknown option '$1'.
37 Type '$PGRM help' for usage."
47 if [ ! -f "$keyFile" ] ; then
48 failure "SSH secret key file '$keyFile' not found."
51 userID="ssh://${hostName}"
53 # prompt about key expiration if not specified
54 keyExpire=$(get_gpg_expiration "$keyExpire")
56 echo "The following key parameters will be used for the host private key:"
57 echo "Import: $keyFile"
58 echo "Name-Real: $userID"
59 echo "Expire-Date: $keyExpire"
61 read -p "Import key? (Y/n) " OK; OK=${OK:=Y}
62 if [ ${OK/y/Y} != 'Y' ] ; then
66 log verbose "importing ssh key..."
67 # translate ssh key to a private key
69 pem2openpgp "$userID" "$keyExpire" < "$sshKey" | gpg_host --import)
71 # find the key fingerprint of the newly converted key
72 fingerprint=$(fingerprint_server_key)
74 # export host ownertrust to authentication keyring
75 log verbose "setting ultimate owner trust for host key..."
76 echo "${fingerprint}:6:" | gpg_host "--import-ownertrust"
77 echo "${fingerprint}:6:" | gpg_authentication "--import-ownertrust"
79 # export public key to file
80 gpg_authentication "--export-options export-minimal --armor --export 0x${fingerprint}\!" > "${SYSDATADIR}/ssh_host_rsa_key.pub.gpg"
81 log info "SSH host public key in OpenPGP form: ${SYSDATADIR}/ssh_host_rsa_key.pub.gpg"
83 # show info about new key