Merge commit 'jrollins/master'
[monkeysphere.git] / src / share / mh / import_key
1 # -*-shell-script-*-
2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
3
4 # Monkeysphere host import-key subcommand
5 #
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>
10 #
11 # They are Copyright 2008-2009 and are all released under the GPL,
12 # version 3 or later.
13
14 import_key() {
15
16 local hostName
17 local userID
18
19 # check for presense of a key
20 [ "$HOST_FINGERPRINT" ] && \
21     failure "An OpenPGP host key already exists."
22
23 hostName=${1:-$(hostname -f)}
24
25 userID="ssh://${hostName}"
26
27 # create host home
28 mkdir -p "$GNUPGHOME_HOST"
29 chmod 700 "$GNUPGHOME_HOST"
30
31 log verbose "importing ssh key..."
32 # translate ssh key to a private key
33 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" | \
34     gpg_host --import
35
36 # find the key fingerprint of the newly converted key
37 HOST_FINGERPRINT=$(get_host_fingerprint)
38 export HOST_FINGERPRINT
39
40 # export public key to file
41 gpg_host_export_to_ssh_file
42
43 # show info about new key
44 show_key
45
46 }