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-2010 and are all released under the GPL,
17 local serviceName="$2"
19 # check that key file specified
20 if [ -z "$keyFile" ] ; then
21 failure "Must specify PEM-encoded key file to import, or specify '-' for stdin."
24 # fail if hostname not specified
25 if [ -z "$serviceName" ] ; then
26 failure "You must specify a service name for use in the OpenPGP certificate user ID."
29 # test that a key with that user ID does not already exist
30 prompt_userid_exists "$serviceName"
32 # check that the service name is well formatted
33 check_service_name "$serviceName"
36 mkdir -p "${MHDATADIR}"
37 mkdir -p "${GNUPGHOME_HOST}"
38 chmod 700 "${GNUPGHOME_HOST}"
40 # import pem-encoded key to an OpenPGP private key
41 if [ "$keyFile" = '-' ] ; then
42 log verbose "importing key from stdin..."
43 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$serviceName" \
46 log verbose "importing key from file '$keyFile'..."
47 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$serviceName" \
52 # export to OpenPGP public key to file
55 log info "host key imported:"
57 # show info about new key
58 show_key "$serviceName"