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,
24 # check that key file specified
25 if [ -z "$sshKeyFile" ] ; then
26 failure "Must specify ssh key file to import, or specify '-' for stdin."
29 # use the default hostname if not specified
30 if [ -z "$hostName" ] ; then
31 hostName=$(hostname -f) || failure "Could not determine hostname."
32 # test that the domain is not obviously illegitimate
35 'local'|'localdomain')
36 failure "Host domain '$domain' is not legitimate. Aborting key import."
39 # test that there are at least two parts
40 if (( $(echo "$hostName" | tr . ' ' | wc -w) < 2 )) ; then
41 failure "Host name '$hostName' is not legitimate. Aborting key import."
45 userID="ssh://${hostName}"
48 mkdir -p "${MHDATADIR}"
49 mkdir -p "${GNUPGHOME_HOST}"
50 chmod 700 "${GNUPGHOME_HOST}"
52 # import ssh key to a private key
53 if [ "$sshKeyFile" = '-' ] ; then
54 log verbose "importing ssh key from stdin..."
55 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
58 log verbose "importing ssh key from file '$sshKeyFile'..."
59 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
64 # load the new host fpr into the fpr variable. this is so we can
65 # create the gpg pub key file. we have to do this from the secret key
66 # ring since we obviously don't have the gpg pub key file yet, since
67 # that's what we're trying to produce (see below).
68 load_fingerprint_secret
70 # export to gpg public key to file
73 log info "host key imported:"
75 # show info about new key