updated pem2openpgp invocation in m-h import-key
[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 local fingerprint
19
20 # check for presence of secret key
21 # FIXME: is this the proper test to be doing here?
22 fingerprint_host_key >/dev/null \
23         && failure "An OpenPGP host key already exists."
24
25 hostName=${1:-$(hostname -f)}
26
27 userID="ssh://${hostName}"
28
29 # create host home
30 mkdir -p "$GNUPGHOME_HOST"
31 chmod 700 "$GNUPGHOME_HOST"
32
33 log verbose "importing ssh key..."
34 # translate ssh key to a private key
35 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" | gpg_host --import
36
37 # find the key fingerprint of the newly converted key
38 fingerprint=$(fingerprint_host_key)
39
40 # export public key to file
41 log debug "exporting openpgp public key..."
42 gpg_host --export-options export-minimal --armor --export "0x${fingerprint}!" > "${MHDATADIR}/ssh_host_rsa_key.pub.gpg"
43 log info "SSH host public key in OpenPGP form: ${MHDATADIR}/ssh_host_rsa_key.pub.gpg"
44
45 # show info about new key
46 show_key
47
48 }