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 check_key_userid "$serviceName" "$serviceName" && \
31 failure "A key with service name '$serviceName' already exists."
33 # check that the service name is well formatted
34 check_service_name "$serviceName"
37 mkdir -p "${MHDATADIR}"
38 mkdir -p "${GNUPGHOME_HOST}"
39 chmod 700 "${GNUPGHOME_HOST}"
41 # import pem-encoded key to an OpenPGP private key
42 if [ "$keyFile" = '-' ] ; then
43 log verbose "importing key from stdin..."
44 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$serviceName" \
47 log verbose "importing key from file '$keyFile'..."
48 PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$serviceName" \
53 # export to OpenPGP public key to file
56 log info "host key imported:"
58 # show info about new key
59 show_key "$serviceName"