7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
22 # Make temporary GPG home directory
23 homedir=$(mktemp -d /tmp/gpg.XXXXXX)
25 # in case a previous gpg invocation failed in some weird way
26 # and left behind a zero length gpg key (pub or priv).
27 if [ -f $PLC_ROOT_GPG_KEY_PUB -a ! -s $PLC_ROOT_GPG_KEY_PUB ] ; then
28 rm -f $PLC_ROOT_GPG_KEY_PUB
30 if [ -f $PLC_ROOT_GPG_KEY -a ! -s $PLC_ROOT_GPG_KEY ] ; then
31 rm -f $PLC_ROOT_GPG_KEY
34 if [ ! -f $PLC_ROOT_GPG_KEY_PUB -o ! -f $PLC_ROOT_GPG_KEY ] ; then
35 # Generate new GPG keyring
36 MESSAGE=$"Generating GPG keys"
39 mkdir -p $(dirname $PLC_ROOT_GPG_KEY_PUB)
40 mkdir -p $(dirname $PLC_ROOT_GPG_KEY)
42 # Temporarily replace /dev/random with /dev/urandom to
43 # avoid running out of entropy.
46 mknod /dev/random c 1 9
47 # sometimes mknod fails within an improperly setup vserver
49 gpg --homedir=$homedir --no-permission-warning --batch --no-tty --yes \
55 Name-Real: $PLC_NAME Central
56 Name-Comment: http://$PLC_WWW_HOST/
57 Name-Email: $PLC_MAIL_SUPPORT_ADDRESS
59 %pubring $PLC_ROOT_GPG_KEY_PUB
60 %secring $PLC_ROOT_GPG_KEY
65 mknod /dev/random c 1 8
68 MESSAGE=$"Updating GPG keys"
71 # Get the current GPG fingerprint and comment
74 while read -a fields ; do
75 if [ "${fields[0]}" = "pub" ] ; then
76 fingerprint=${fields[4]}
80 gpg --homedir=$homedir --no-permission-warning --batch --no-tty --yes \
81 --no-default-keyring \
82 --secret-keyring=$PLC_ROOT_GPG_KEY \
83 --keyring=$PLC_ROOT_GPG_KEY_PUB \
84 --list-public-keys --with-colons
89 # Add a new UID if appropriate. GPG will detect and merge duplicates.
90 gpg --homedir=$homedir --no-permission-warning --batch --no-tty --yes \
91 --no-default-keyring \
92 --secret-keyring=$PLC_ROOT_GPG_KEY \
93 --keyring=$PLC_ROOT_GPG_KEY_PUB \
94 --command-fd 0 --status-fd 1 --edit-key $fingerprint <<EOF
97 $PLC_MAIL_SUPPORT_ADDRESS
104 # Install the key in the RPM database
105 mkdir -p /etc/pki/rpm-gpg
106 gpg --homedir=$homedir --no-permission-warning --batch --no-tty --yes \
107 --no-default-keyring \
108 --secret-keyring=$PLC_ROOT_GPG_KEY \
109 --keyring=$PLC_ROOT_GPG_KEY_PUB \
110 --export --armor >"/etc/pki/rpm-gpg/RPM-GPG-KEY-$PLC_NAME"
112 if rpm -q gpg-pubkey ; then
113 rpm --allmatches -e gpg-pubkey
116 rpm --import /etc/pki/rpm-gpg/*
119 # Make GPG key readable by apache so that the API can sign peer requests
120 chown apache $PLC_ROOT_GPG_KEY
121 chmod 644 $PLC_ROOT_GPG_KEY_PUB
122 chmod 600 $PLC_ROOT_GPG_KEY