2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere host gen-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)
18 local keyLength="2048"
23 # check for presense of a key
24 [ "$FINGERPRINT" ] && \
25 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."
45 userID="ssh://${hostName}"
48 mkdir -p "$GNUPGHOME_HOST"
49 chmod 700 "$GNUPGHOME_HOST"
51 log debug "generating host key..."
52 gpg_host --batch --gen-key <<EOF
54 Key-Length: $keyLength
57 Expire-Date: $keyExpire
64 # find the key fingerprint of the newly converted key
65 HOST_FINGERPRINT=$(fingerprint_host_key)
66 export HOST_FINGERPRINT
68 # translate the private key to ssh format, and export to a file
70 # NOTE: assumes that the primary key is the proper key to use
71 log debug "exporting ssh secret key..."
73 gpg_host --export-secret-key "$HOST_FINGERPRINT" | \
74 openpgp2ssh "$HOST_FINGERPRINT" > "${MHDATADIR}/ssh_host_rsa_key")
75 log info "SSH host private key output to file: ${MHDATADIR}/ssh_host_rsa_key"
77 log debug "creating ssh public key..."
78 ssh-keygen -y -f "${MHDATADIR}/ssh_host_rsa_key" > "$HOST_KEY_PUB"
79 log info "SSH host public key output to file: $HOST_KEY_PUB"
81 # export public key to file
82 gpg_host_export_to_ssh_file
84 # show info about new key