#!/bin/rc
# build.rc -- rebuild libsec, its userspace consumers, and the kernel
# after applying tls-1.2.
#
# rc build.rc # rebuild everything (default)
# rc build.rc userspace # libsec and its consumers; no kernel
# rc build.rc kernel # kernel only; CONF auto-detected from
# /env/bootfile. Override for unusual
# installs: kconf=pccpuf rc build.rc kernel
#
# Run as a user with write access to /sys and /$cputype. Most patches
# touch userspace only; tls-aead-record-layer and the devtls hunks of
# tls-ecdhe-ecdsa-and-chain also modify the in-kernel TLS driver
# and require a kernel rebuild + reboot.
#
# After the kernel build, fshalt -r and boot the fresh /$cputype/9*.
mode=$1
if(~ $#mode 0)
mode=all
echo 'building for objtype='^$objtype^' mode='^$mode
if(~ $mode userspace all){
echo
echo '=== mk libsec ==='
cd /sys/src/libsec
mk clean >[2]/dev/null
mk all || exit 'libsec: mk failed'
mk install || exit 'libsec: mk install failed'
echo
echo '=== mk webfs ==='
cd /sys/src/cmd/webfs
mk clean >[2]/dev/null
mk all || echo 'warn: webfs: mk failed' >[1=2]
mk install || echo 'warn: webfs: mk install failed' >[1=2]
echo
echo '=== mk hget, tlsclient, tlssrv ==='
cd /sys/src/cmd
# On 9legacy both sources live directly in /sys/src/cmd and the
# top-level mkfile knows about them. mk <prog>.install compiles
# with the correct $cputype-matched compiler/linker.
#
# Plan 9 mk does not track /$objtype/lib/libsec.a as a dependency
# of <prog>.install, so after a libsec rebuild `mk hget.install`
# reports "up to date" and never relinks. Delete intermediates to
# force the link. Pattern *.hget covers 6.hget / 8.hget / v.hget.
#
# tlssrv belongs on this list. It is the general-purpose TLS
# server wrapper, so leaving it linked against the old libsec
# leaves a system with patched hget and webfs still serving
# without ECDHE, AEAD, SNI or the RFC 5746 echo.
rm -f hget.[568qv] [568qv].hget tlsclient.[568qv] [568qv].tlsclient \
tlssrv.[568qv] [568qv].tlssrv
for(t in hget.install tlsclient.install tlssrv.install){
mk $t || echo 'warn: '^$t^' failed' >[1=2]
}
# Every program that links libsec's TLS needs the relink, not only
# the ones this series edits. Plan 9 links statically, so a
# consumer left unbuilt keeps a whole copy of the old handshake --
# no ECDHE, no AEAD, SSL 3.0 and TLS 1.0 still accepted, RC4 still
# selectable -- on a machine whose hget and webfs are patched.
# The list below is every in-tree caller of tlsClient or tlsServer.
#
# These directories hold TLS consumers and little else, so mk clean
# forces the relink, as it does for webfs above. ip/httpd also
# picks up the per-vhost certificate routing ip-httpd-vhosts-sni
# adds; without the rebuild it serves one certificate under every
# name it answers to.
for(d in /sys/src/cmd/ip/httpd /sys/src/cmd/vnc /sys/src/cmd/ip/ftpfs){
if(test -d $d){
echo
echo '=== mk '^$d^' ==='
# guard the cd: mk clean one directory up recurses
# through every command directory in the tree.
cd $d || exit 'cd '^$d^' failed'
mk clean >[2]/dev/null
mk all || echo 'warn: '^$d^': mk failed' >[1=2]
mk install || echo 'warn: '^$d^': mk install failed' >[1=2]
}
}
# upas wants a shape of its own. Build from its top, because its
# mkfile puts common ahead of the programs and upas/fs links
# ../common/libcommon.a; building one mail directory alone fails on
# that library. Install only the three that speak TLS, because a
# whole-upas install also copies mail data files and stops on a
# machine with no /mail.
if(test -d /sys/src/cmd/upas){
echo
echo '=== mk upas ==='
cd /sys/src/cmd/upas || exit 'cd upas failed'
mk all || echo 'warn: upas: mk failed' >[1=2]
for(u in fs smtp pop3){
if(test -d /sys/src/cmd/upas/$u){
cd /sys/src/cmd/upas/$u
mk install \
|| echo 'warn: upas/'^$u^': mk install failed' >[1=2]
}
}
}
# aux and ip hold many programs with no TLS in them, so clean only
# the two that link it and build those by name.
echo
echo '=== mk wpa, httpfile ==='
cd /sys/src/cmd/aux
rm -f wpa.[568qv] [568qv].wpa
mk wpa.install || echo 'warn: wpa: mk failed' >[1=2]
cd /sys/src/cmd/ip
rm -f httpfile.[568qv] [568qv].httpfile
mk httpfile.install || echo 'warn: httpfile: mk failed' >[1=2]
}
if(~ $mode kernel all){
echo
echo '=== mk kernel ==='
if(~ $objtype 386)
cd /sys/src/9/pc
if(~ $objtype amd64)
cd /sys/src/9k/k10
if(! ~ $objtype 386 amd64){
echo 'unknown objtype for kernel build: '^$objtype >[1=2]
exit 'kernel: unknown arch'
}
# Auto-detect CONF from /env/bootfile (e.g. sdC0!9fat!9pcf -> pcf)
# so the rebuilt kernel matches the one plan9.ini boots. Honor
# an explicit $kconf override from the environment (cpu-server
# or other non-default installs where /env/bootfile is unset).
if(~ $#kconf 0)
kconf=`{cat /env/bootfile >[2]/dev/null | sed 's,.*!9,,'}
if(~ $#kconf 0){
echo 'cannot detect kernel CONF: /env/bootfile is empty.' >[1=2]
echo ' set kconf explicitly: kconf=pccpuf rc '^$0^' kernel' >[1=2]
exit 'kernel: CONF unknown'
}
mk clean >[2]/dev/null
mk 'CONF='^$kconf || exit 'kernel: mk failed'
mk 'CONF='^$kconf install || exit 'kernel: mk install failed'
# `mk install` writes the new kernel to /$objtype/ on fossil, but
# the 9load bootloader reads from the DOS FAT 9fat partition per
# plan9.ini's `bootfile=sdC0!9fat!9<CONF>`. Without an explicit
# copy the next cold boot still loads the stale pre-patch kernel.
# Copy the freshly built kernel into 9fat so fshalt -r or cold
# boot picks it up.
echo
echo '=== copy kernel to 9fat partition ==='
# auto-detect installed disk from plan9.ini's bootfile=sdXX!9fat!9<CONF>
kdisk=`{cat /env/bootfile | sed 's/!.*//'}
if(~ $#kdisk 0) kdisk=sdC0 # fallback if bootfile unavailable
if(test -f /dev/$kdisk/9fat){
if(! test -e /srv/9fatbuild){
dossrv -f /dev/$kdisk/9fat 9fatbuild
}
mkdir -p /n/9fatbuild
unmount /n/9fatbuild >[2]/dev/null
mount /srv/9fatbuild /n/9fatbuild || exit 'mount 9fat failed'
cp /$objtype/9^$kconf /n/9fatbuild/9^$kconf \
|| echo 'warn: 9fat kernel copy failed' >[1=2]
unmount /n/9fatbuild
rm -f /srv/9fatbuild
echo 'updated /9fat/9'^$kconf^' on '$kdisk
}
if not {
echo 'warn: no /dev/'^$kdisk^'/9fat found; 9fat kernel copy skipped.' >[1=2]
echo ' bootloader will keep loading the stale kernel -- update' >[1=2]
echo ' plan9.ini or manually cp /'^$objtype^'/9'^$kconf^' to your 9fat.' >[1=2]
}
}
echo
echo '=== build complete ==='
switch($mode){
case userspace
echo 'userspace rebuilt. If a devtls patch (tls-aead-record-layer'
echo 'or tls-ecdhe-ecdsa-and-chain) was applied, also run'
echo '`rc '^$0^' kernel` and reboot before retrying HTTPS.'
case kernel
echo 'kernel installed. fshalt -r and boot the new image.'
case all
echo 'userspace + kernel installed. fshalt -r and boot the new image.'
}
|