2 # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
4 # Monkeysphere authentication setup 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 2009, and are all released under the GPL,
15 # make all needed directories
16 mkdir -p "${MADATADIR}"
17 mkdir -p "${MATMPDIR}"
18 mkdir -p "${GNUPGHOME_SPHERE}"
19 mkdir -p "${GNUPGHOME_CORE}"
21 # deliberately replace the config files via truncation
22 # FIXME: should we be dumping to tmp files and then moving atomically?
23 cat >"${GNUPGHOME_CORE}"/gpg.conf <<EOF
24 # Monkeysphere trust core GnuPG configuration
25 # This file is maintained by the Monkeysphere software.
26 # Edits will be overwritten.
28 list-options show-uid-validity
31 cat >"${GNUPGHOME_SPHERE}"/gpg.conf <<EOF
32 # Monkeysphere trust sphere GnuPG configuration
33 # This file is maintained by the Monkeysphere software.
34 # Edits will be overwritten.
36 primary-keyring ${GNUPGHOME_SPHERE}/pubring.gpg
37 keyring ${GNUPGHOME_CORE}/pubring.gpg
39 list-options show-uid-validity
42 # fingerprint of core key. this should be empty on unconfigured systems.
43 local CORE_FPR=$(gpg_core --with-colons --fixed-list-mode --fingerprint --list-secret-key | grep ^fpr: | cut -f10 -d: )
45 if [ -z "$CORE_FPR" ] ; then
46 log info "Setting up Monkeysphere authentication trust core"
48 local CORE_UID=$(printf "Monkeysphere authentication trust core UID (random string: %s)" $(head -c21 </dev/urandom | base64))
50 local TMPLOC=$(mktemp -d "${MATMPDIR}"/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!"
52 # generate the key with ssh-keygen...
53 ssh-keygen -q -b 1024 -t rsa -N '' -f "${TMPLOC}/authkey" || failure "Could not generate new key for Monkeysphere authentication trust core"
54 # and then translate to openpgp encoding and import
55 # FIXME: pem2openpgp currently sets the A flag and a short
56 # expiration date. We should set the C flag and no expiration
58 < "${TMPLOC}/authkey" pem2openpgp "$CORE_UID" | gpg --import || failure "Could not import new key for Monkeysphere authentication trust core"
60 gpg_core --with-colons --fixed-list-mode --fingerprint --list-secret-key
61 CORE_FPR=$(gpg_core --with-colons --fixed-list-mode --fingerprint --list-secret-key | grep ^fpr: | cut -f10 -d: )
62 if [ -z "$CORE_FPR" ] ; then
63 failure "Failed to create Monkeysphere authentication trust core!"
67 log verbose "This system has already set up the Monkeysphere authentication trust core"
71 # ensure that the authentication sphere checker has absolute ownertrust on the expected key.
72 printf "%s:6:\n" "$CORE_FPR" | gpg_sphere --import-ownertrust
74 if ORIG_TRUST=$(gpg_sphere --export-ownertrust | grep '^[^#]') ; then
75 if [ "${CORE_FPR}:6:" != "$ORIG_TRUST" ] ; then
76 failure "Monkeysphere authentication trust sphere should explicitly trust the core. It does not have proper ownertrust settings."
79 failure "Could not get monkeysphere-authentication trust guidelines."
82 # ensure that we're using the extended trust model (1), and that
83 # our preferences are reasonable (i.e. 3 marginal OR 1 fully
84 # trusted certifications are sufficient to grant full validity.
85 if [ "1:3:1" != $(gpg_sphere --with-colons --fixed-list-mode --list-keys | head -n1 | grep ^tru: cut -f3,6,7 -d:) ] ; then
86 failure "monkeysphere-preference does not have the expected trust model settings"