Change import_key to take the path to the file to import as an argument. dkg won...
[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 keyFile
17 local hostName
18 local userID
19
20 keyFile="$1"
21 [ -f "$keyFile" ]
22
23 hostName=${2:-$(hostname -f)}
24 userID="ssh://${hostName}"
25
26 # create host home
27 mkdir -p "$GNUPGHOME_HOST"
28 chmod 700 "$GNUPGHOME_HOST"
29
30 log verbose "importing ssh key..."
31 # translate ssh key to a private key
32 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" <"$keyFile" \
33     | gpg_host --import
34
35 # load the new host fpr into the fpr variable
36 load_fingerprint_secret
37
38 # export the host public key to the monkeysphere ssh pub key file
39 log debug "creating ssh public key file..."
40 ssh-keygen -y -f "$keyFile" > "$HOST_KEY_PUB"
41 log info "SSH host public key file: $HOST_KEY_PUB"
42
43 # export to gpg public key to file
44 create_gpg_pub_file
45
46 # show info about new key
47 show_key
48
49 }