/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to initramfs-tools-hook

  • Committer: Teddy Hogeborn
  • Date: 2019-02-09 23:23:26 UTC
  • Revision ID: teddy@recompile.se-20190209232326-z1z2kzpgfixz7iaj
Add support for using raw public keys in TLS (RFC 7250)

Since GnuTLS removed support for OpenPGP keys in TLS (RFC 6091), and
no other library supports it, we have to change the protocol to use
something else.  We choose to use "raw public keys" (RFC 7250).  Since
we still use OpenPGP keys to decrypt the secret password, this means
that each client will have two keys: One OpenPGP key and one TLS
public/private key, and the key ID of the latter key is used to
identify clients instead of the fingerprint of the OpenPGP key.

Note that this code is still compatible with GnuTLS before version
3.6.0 (when OpenPGP key support was removed).  This commit merely adds
support for using raw pulic keys instead with GnuTLS 3.6.6. or later.

* DBUS-API (Signals/ClientNotFound): Change name of first parameter
                                     from "Fingerprint" to "KeyID".
  (Mandos Client Interface/Properties/KeyID): New.
* INSTALL: Document conflict with GnuTLS 3.6.0 (which removed OpenPGP
           key support) up until 3.6.6, when support for raw public
           keys was added.  Also document new dependency of client on
           "gnutls-bin" package (for certtool).
* Makefile (run-client): Depend on TLS key files, and also pass them
                         as arguments to client.
  (keydir/tls-privkey.pem, keydir/tls-pubkey.pem): New.
  (confdir/clients.conf): Add dependency on TLS public key.
  (purge-client): Add removal of TLS key files.
* clients.conf ([foo]/key_id, [bar]/key_id): New.
* debian/control (Source: mandos/Build-Depends): Also allow
                                                 libgnutls30 (>= 3.6.6)
  (Package: mandos/Depends): - '' -
  (Package: mandos/Description): Alter description to match new
                                 design.
  (Package: mandos-client/Description): - '' -
  (Package: mandos-client/Depends): Move "gnutls-bin | openssl" to
                                    here from "Recommends".
* debian/mandos-client.README.Debian: Add --tls-privkey and
                                      --tls-pubkey options to test
                                      command.
* debian/mandos-client.postinst (create_key): Renamed to "create_keys"
                                             (all callers changed),
                                             and also create TLS key.
* debian/mandos-client.postrm (purge): Also remove TLS key files.
* intro.xml (DESCRIPTION): Describe new dual-key design.
* mandos (GnuTLS): Define different functions depending on whether
                   support for raw public keys is detected.
  (Client.key_id): New attribute.
  (ClientDBus.KeyID_dbus_property): New method.
  (ProxyClient.__init__): Take new "key_id" parameter.
  (ClientHandler.handle): Use key IDs when using raw public keys and
                          use fingerprints when using OpenPGP keys.
  (ClientHandler.peer_certificate): Also handle raw public keys.
  (ClientHandler.key_id): New.
  (MandosServer.handle_ipc): Pass key ID over the pipe IPC.  Also
                             check for key ID matches when looking up
                             clients.
  (main): Default GnuTLS priority string depends on whether we are
          using raw public keys or not.  When unpickling clients, set
          key_id if not set in the pickle.
  (main/MandosDBusService.ClientNotFound): Change name of first
                                           parameter from
                                           "Fingerprint" to "KeyID".
* mandos-clients.conf.xml (OPTIONS): Document new "key_id" option.
  (OPTIONS/secret): Mention new key ID matchning.
  (EXPANSION/RUNTIME EXPANSION): Add new "key_id" option.
  (EXAMPLE): - '' -
* mandos-ctl (tablewords, main/keywords): Add new "KeyID" property.
* mandos-keygen: Create TLS key files.  New "--tls-keytype" (-T)
                 option.  Alter help text to be more clear about key
                 types.  When in password mode, also output "key_id"
                 option.
* mandos-keygen.xml (SYNOPSIS): Add new "--tls-keytype" (-T) option.
  (DESCRIPTION): Alter to match new dual-key design.
  (OVERVIEW): - '' -
  (FILES): Add TLS key files.
* mandos-options.xml (priority): Document new default priority string
                                 when using raw public keys.
* mandos.xml (NETWORK PROTOCOL): Describe new protocol using key ID.
  (BUGS): Remove issue about checking expire times of OpenPGP keys,
          since TLS public keys do not have expiration times.
  (SECURITY/CLIENT): Alter description to match new design.
  (SEE ALSO/GnuTLS): - '' -
  (SEE ALSO): Add reference to RFC 7250, and alter description of when
              RFC 6091 is used.
* overview.xml: Alter text to match new design.
* plugin-runner.xml (EXAMPLE): Add --tls-pubkey and --tls-privkey
                               options to mandos-client options.
* plugins.d/mandos-client.c: Use raw public keys when compiling with
                             supporting GnuTLS versions. Add new
                             "--tls-pubkey" and "--tls-privkey"
                             options (which do nothing if GnuTLS
                             library does not support raw public
                             keys).  Alter text throughout to reflect
                             new design.  Only generate new DH
                             parameters (based on size of OpenPGP key)
                             when using OpenPGP in TLS.  Default
                             GnuTLS priority string depends on whether
                             we are using raw public keys or not.
* plugins.d/mandos-client.xml (SYNOPSIS): Add new "--tls-privkey" (-t)
                                          and "--tls-pubkey" (-T)
                                          options.
  (DESCRIPTION): Describe new dual-key design.
  (OPTIONS): Document new "--tls-privkey" (-t) and "--tls-pubkey" (-T)
             options.
  (OPTIONS/--dh-bits): No longer necessarily depends on OpenPGP key
                       size.
  (FILES): Add default locations for TLS public and private key files.
  (EXAMPLE): Use new --tls-pubkey and --tls-privkey options.
  (SECURITY): Alter wording slightly to reflect new dual-key design.
  (SEE ALSO/GnuTLS): Alter description to match new design.
  (SEE ALSO): Add reference to RFC 7250, and alter description of when
              RFC 6091 is used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
CONFDIR="/conf/conf.d/mandos"
71
71
MANDOSDIR="/lib/mandos"
72
72
PLUGINDIR="${MANDOSDIR}/plugins.d"
 
73
PLUGINHELPERDIR="${MANDOSDIR}/plugin-helpers"
73
74
HOOKDIR="${MANDOSDIR}/network-hooks.d"
74
75
 
75
76
# Make directories
76
77
install --directory --mode=u=rwx,go=rx "${DESTDIR}${CONFDIR}" \
77
78
        "${DESTDIR}${MANDOSDIR}" "${DESTDIR}${HOOKDIR}"
78
79
install --owner=${mandos_user} --group=${mandos_group} --directory \
79
 
    --mode=u=rwx "${DESTDIR}${PLUGINDIR}"
 
80
        --mode=u=rwx "${DESTDIR}${PLUGINDIR}" \
 
81
        "${DESTDIR}${PLUGINHELPERDIR}"
 
82
 
 
83
copy_exec "$libdir"/mandos/mandos-to-cryptroot-unlock "${MANDOSDIR}"
80
84
 
81
85
# Copy the Mandos plugin runner
82
86
copy_exec "$libdir"/mandos/plugin-runner "${MANDOSDIR}"
98
102
    esac
99
103
done
100
104
 
 
105
# Copy the packaged plugin helpers
 
106
for file in "$libdir"/mandos/plugin-helpers/*; do
 
107
    base="`basename \"$file\"`"
 
108
    # Is this plugin overridden?
 
109
    if [ -e "/etc/mandos/plugin-helpers/$base" ]; then
 
110
        continue
 
111
    fi
 
112
    case "$base" in
 
113
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
114
            : ;;
 
115
        "*") : ;;
 
116
        *) copy_exec "$file" "${PLUGINHELPERDIR}" ;;
 
117
    esac
 
118
done
 
119
 
101
120
# Copy any user-supplied plugins
102
121
for file in /etc/mandos/plugins.d/*; do
103
122
    base="`basename \"$file\"`"
109
128
    esac
110
129
done
111
130
 
 
131
# Copy any user-supplied plugin helpers
 
132
for file in /etc/mandos/plugin-helpers/*; do
 
133
    base="`basename \"$file\"`"
 
134
    case "$base" in
 
135
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
136
            : ;;
 
137
        "*") : ;;
 
138
        *) copy_exec "$file" "${PLUGINHELPERDIR}" ;;
 
139
    esac
 
140
done
 
141
 
112
142
# Get DEVICE from initramfs.conf and other files
113
143
. /etc/initramfs-tools/initramfs.conf
114
144
for conf in /etc/initramfs-tools/conf.d/*; do
115
145
    if [ -n `basename \"$conf\" | grep '^[[:alnum:]][[:alnum:]\._-]*$' \
116
146
        | grep -v '\.dpkg-.*$'` ]; then
117
 
        [ -f ${conf} ] && . ${conf}
 
147
        [ -f "${conf}" ] && . "${conf}"
118
148
    fi
119
149
done
120
150
export DEVICE
129
159
    if [ -x "$hook" ]; then
130
160
        # Copy any files needed by the network hook
131
161
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
132
 
            VERBOSITY=0 "$hook" files | while read file target; do
 
162
            VERBOSITY=0 "$hook" files | while read -r file target; do
133
163
            if [ ! -e "${file}" ]; then
134
164
                echo "WARNING: file ${file} not found, requested by Mandos network hook '${hook##*/}'" >&2
135
165
            fi
141
171
        done
142
172
        # Copy and load any modules needed by the network hook
143
173
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=modules \
144
 
            VERBOSITY=0 "$hook" modules | while read module; do
145
 
            if [ -z "${target}" ]; then
146
 
                force_load "$module"
147
 
            fi
 
174
            VERBOSITY=0 "$hook" modules | while read -r module; do
 
175
            force_load "$module"
148
176
        done
149
177
    fi
150
178
done
158
186
            copy_exec /usr/bin/gpgconf
159
187
        fi
160
188
        gpg="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg:[^:]*://p'`"
 
189
        gpgagent="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg-agent:[^:]*://p'`"
 
190
        # Newer versions of GnuPG 2 requires the gpg-agent binary
 
191
        if [ -e "$gpgagent" ] && [ ! -e "${DESTDIR}$gpgagent" ]; then
 
192
            copy_exec "$gpgagent"
 
193
        fi
161
194
    fi
162
195
elif dpkg --compare-versions "$libgpgme11_version" ge 1.4.1-0.1; then
163
196
    gpg=/usr/bin/gpg2
191
224
    if [ -d "$file" ]; then
192
225
        continue
193
226
    fi
194
 
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
195
 
    chown ${mandos_user}:${mandos_group} \
196
 
        "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
227
    case "$file" in
 
228
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
229
            : ;;
 
230
        "*") : ;;
 
231
        *)
 
232
            cp --archive --sparse=always "$file" \
 
233
               "${DESTDIR}${CONFDIR}"
 
234
            chown ${mandos_user}:${mandos_group} \
 
235
                  "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
236
            ;;
 
237
    esac
197
238
done
 
239
# Use Diffie-Hellman parameters file if available
 
240
if [ -e "${DESTDIR}${CONFDIR}"/dhparams.pem ]; then
 
241
    sed --in-place \
 
242
        --expression="1i--options-for=mandos-client:--dh-params=${CONFDIR}/dhparams.pem" \
 
243
        "${DESTDIR}/${CONFDIR}/plugin-runner.conf"
 
244
fi
198
245
 
199
246
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
200
247
# its plugin directory and its config file.  However, since almost all
205
252
# initrd; it is intended to affect the initrd.img file itself, since
206
253
# it now contains secret key files.  There is, however, no other way
207
254
# to set the permission of the initrd.img file without a race
208
 
# condition.  This umask is set by "initramfs-tools-hook-conf",
209
 
# installed as "/usr/share/initramfs-tools/conf-hooks.d/mandos".)
 
255
# condition.  This umask is set by "initramfs-tools-conf", installed
 
256
# as "/usr/share/initramfs-tools/conf.d/mandos-conf".)
210
257
211
258
for full in "${MANDOSDIR}" "${CONFDIR}"; do
212
259
    while [ "$full" != "/" ]; do
224
271
done
225
272
for dir in "${DESTDIR}"/lib* "${DESTDIR}"/usr/lib*; do
226
273
    if [ -d "$dir" ]; then
227
 
        find "$dir" \! -perm -u+rw,g+r -prune -or -print0 \
228
 
            | xargs --null --no-run-if-empty chmod a+rX
 
274
        find "$dir" \! -perm -u+rw,g+r -prune -or \! -type l -print0 \
 
275
            | xargs --null --no-run-if-empty chmod a+rX --
229
276
    fi
230
277
done