libressl-portable/update.sh

395 lines
12 KiB
Bash
Raw Normal View History

#!/bin/sh
2014-07-10 06:07:09 -05:00
set -e
openbsd_branch=`cat OPENBSD_BRANCH`
# pull in latest upstream code
echo "pulling upstream openbsd source"
if [ ! -d openbsd ]; then
if [ -z "$LIBRESSL_GIT" ]; then
git clone https://github.com/libressl-portable/openbsd.git
else
git clone $LIBRESSL_GIT/openbsd
fi
fi
(cd openbsd
git fetch
git checkout $openbsd_branch
git pull --rebase)
2014-07-10 06:07:09 -05:00
# setup source paths
CWD=`pwd`
OPENBSD_SRC=$CWD/openbsd/src
libc_src=$OPENBSD_SRC/lib/libc
libc_regress=$OPENBSD_SRC/regress/lib/libc
libcrypto_src=$OPENBSD_SRC/lib/libcrypto
libcrypto_regress=$OPENBSD_SRC/regress/lib/libcrypto
libssl_src=$OPENBSD_SRC/lib/libssl
libssl_regress=$OPENBSD_SRC/regress/lib/libssl
libtls_src=$OPENBSD_SRC/lib/libtls
libtls_regress=$OPENBSD_SRC/regress/lib/libtls
bin_src=$OPENBSD_SRC/usr.bin
sbin_src=$OPENBSD_SRC/usr.sbin
# load library versions
. "$libcrypto_src/shlib_version"
libcrypto_version=$major:$minor:0
echo "libcrypto version $libcrypto_version"
echo $libcrypto_version > crypto/VERSION
2014-07-10 06:07:09 -05:00
. "$libssl_src/shlib_version"
2014-07-10 06:07:09 -05:00
libssl_version=$major:$minor:0
echo "libssl version $libssl_version"
echo $libssl_version > ssl/VERSION
2014-07-10 06:07:09 -05:00
. "$libtls_src/shlib_version"
libtls_version=$major:$minor:0
echo "libtls version $libtls_version"
echo $libtls_version > tls/VERSION
2014-07-10 06:07:09 -05:00
do_mv() {
if ! cmp -s "$1" "$2"
then
mv "$1" "$2"
else
rm -f "$1"
fi
}
MV='do_mv'
2015-08-31 07:49:50 -05:00
do_cp_libc() {
sed "/DEF_WEAK/d" < "$1" > "$2"/`basename "$1"`
}
CP_LIBC='do_cp_libc'
CP='cp -p'
GREP='grep'
if [ -x /opt/csw/bin/ggrep ]; then
GREP='/opt/csw/bin/ggrep'
fi
2015-08-31 07:49:50 -05:00
2016-09-02 12:43:30 -05:00
$CP $libssl_src/LICENSE COPYING
2014-07-10 06:07:09 -05:00
2016-09-02 12:43:30 -05:00
$CP $libcrypto_src/arch/amd64/opensslconf.h include/openssl
$CP $libcrypto_src/opensslfeatures.h include/openssl
$CP $libssl_src/pqueue.h include
2014-07-10 06:07:09 -05:00
2015-06-19 02:09:27 -05:00
$CP $libtls_src/tls.h include
for i in crypto/compat; do
2015-08-31 02:30:25 -05:00
for j in $libc_src/crypt/arc4random.c \
2015-12-06 23:32:18 -06:00
$libc_src/crypt/arc4random_uniform.c \
$libc_src/crypt/chacha_private.h \
$libc_src/stdlib/reallocarray.c \
2017-03-09 22:49:04 +09:00
$libc_src/stdlib/recallocarray.c \
$libc_src/stdlib/strtonum.c \
$libc_src/string/explicit_bzero.c \
$libc_src/string/strcasecmp.c \
$libc_src/string/strlcpy.c \
$libc_src/string/strlcat.c \
$libc_src/string/strndup.c \
$libc_src/string/strnlen.c \
$libc_src/string/strsep.c \
$libc_src/string/timingsafe_bcmp.c \
$libc_src/string/timingsafe_memcmp.c \
2016-09-02 12:43:30 -05:00
$libcrypto_src/arc4random/getentropy_*.c \
$libcrypto_src/arc4random/arc4random_*.h; do
2015-08-31 07:49:50 -05:00
$CP_LIBC $j $i
2015-08-31 02:30:25 -05:00
done
2014-07-10 06:07:09 -05:00
done
2016-09-02 12:43:30 -05:00
(cd $libcrypto_src/objects/;
2014-07-10 06:07:09 -05:00
perl objects.pl objects.txt obj_mac.num obj_mac.h;
perl obj_dat.pl obj_mac.h obj_dat.h )
mkdir -p include/openssl crypto/objects
2016-09-02 12:43:30 -05:00
$MV $libcrypto_src/objects/obj_mac.h ./include/openssl/obj_mac.h
$MV $libcrypto_src/objects/obj_dat.h ./crypto/objects/obj_dat.h
2014-07-10 06:07:09 -05:00
copy_hdrs() {
for file in $2; do
2016-09-02 12:43:30 -05:00
$CP $1/$file include/openssl
done
}
2016-09-02 12:43:30 -05:00
copy_hdrs $libcrypto_src "stack/stack.h lhash/lhash.h stack/safestack.h
2014-07-10 06:07:09 -05:00
ossl_typ.h err/err.h crypto.h comp/comp.h x509/x509.h buffer/buffer.h
objects/objects.h asn1/asn1.h bn/bn.h ec/ec.h ecdsa/ecdsa.h
ecdh/ecdh.h rsa/rsa.h sha/sha.h x509/x509_vfy.h pkcs7/pkcs7.h pem/pem.h
2017-05-02 00:21:57 +09:00
pem/pem2.h hkdf/hkdf.h hmac/hmac.h rand/rand.h md5/md5.h
2020-09-13 22:18:49 +09:00
x509/x509v3.h x509/x509_verify.h conf/conf.h ocsp/ocsp.h
2014-07-10 06:07:09 -05:00
aes/aes.h modes/modes.h asn1/asn1t.h dso/dso.h bf/blowfish.h
2019-09-09 23:40:50 -05:00
bio/bio.h cast/cast.h cmac/cmac.h cms/cms.h conf/conf_api.h des/des.h dh/dh.h
2016-09-14 08:49:53 -05:00
dsa/dsa.h engine/engine.h ui/ui.h pkcs12/pkcs12.h ts/ts.h
2015-06-20 10:40:04 -05:00
md4/md4.h ripemd/ripemd.h whrlpool/whrlpool.h idea/idea.h
2015-02-10 11:10:04 -06:00
rc2/rc2.h rc4/rc4.h ui/ui_compat.h txt_db/txt_db.h
2019-03-02 12:32:12 -05:00
sm3/sm3.h sm4/sm4.h chacha/chacha.h evp/evp.h poly1305/poly1305.h
2021-11-27 22:12:11 +09:00
camellia/camellia.h gost/gost.h curve25519/curve25519.h
2022-05-09 02:21:16 -05:00
ct/ct.h kdf/kdf.h"
2014-07-10 06:07:09 -05:00
2016-09-02 12:43:30 -05:00
copy_hdrs $libssl_src "srtp.h ssl.h ssl2.h ssl3.h ssl23.h tls1.h dtls1.h"
2014-07-10 06:07:09 -05:00
# override upstream opensslv.h if a local version exists
if [ -f patches/opensslv.h ]; then
$CP patches/opensslv.h include/openssl
else
$CP $libcrypto_src/opensslv.h include/openssl
fi
awk '/LIBRESSL_VERSION_TEXT/ {print $4}' < include/openssl/opensslv.h | cut -d\" -f1 > VERSION
echo "LibreSSL version `cat VERSION`"
# copy libcrypto source
echo copying libcrypto source
rm -f crypto/*.c crypto/*.h
for i in `awk '/SOURCES|HEADERS/ { print $3 }' crypto/Makefile.am` ; do
dir=`dirname $i`
mkdir -p crypto/$dir
if [ $dir != "compat" ]; then
2016-09-02 12:43:30 -05:00
if [ -e $libcrypto_src/$i ]; then
$CP $libcrypto_src/$i crypto/$i
fi
fi
done
$CP crypto/compat/b_win.c crypto/bio
$CP crypto/compat/ui_openssl_win.c crypto/ui
# add the libcrypto symbol export list
$GREP -v OPENSSL_ia32cap_P $libcrypto_src/Symbols.list | $GREP '^[A-Za-z0-9_]' > crypto/crypto.sym
2014-07-10 06:07:09 -05:00
2019-06-05 23:08:41 -05:00
fixup_masm() {
cpp -I./crypto $1 \
| sed -e 's/^#/;/' \
| sed -e 's/|/OR/g' \
| sed -e 's/~/NOT/g' \
| sed -e 's/1 << \([0-9]*\)/1 SHL \1/g' \
> $2
}
# generate assembly crypto algorithms
2016-09-02 12:43:30 -05:00
asm_src=$libcrypto_src
gen_asm_stdout() {
CC=true perl $asm_src/$2 $1 > $3.tmp
[ $1 = "elf" ] && cat <<-EOF >> $3.tmp
#if defined(HAVE_GNU_STACK)
.section .note.GNU-stack,"",%progbits
#endif
EOF
if [ $1 = "masm" ]; then
2019-06-05 23:08:41 -05:00
fixup_masm $3.tmp $3
else
$MV $3.tmp $3
fi
}
gen_asm() {
CC=true perl $asm_src/$2 $1 $3.tmp
[ $1 = "elf" ] && cat <<-EOF >> $3.tmp
#if defined(HAVE_GNU_STACK)
.section .note.GNU-stack,"",%progbits
#endif
EOF
if [ $1 = "masm" ]; then
2019-06-05 23:08:41 -05:00
fixup_masm $3.tmp $3
else
$MV $3.tmp $3
fi
}
echo generating arm ASM source for elf
gen_asm_stdout elf aes/asm/aes-armv4.pl crypto/aes/aes-elf-armv4.S
gen_asm_stdout elf bn/asm/armv4-gf2m.pl crypto/bn/gf2m-elf-armv4.S
gen_asm_stdout elf bn/asm/armv4-mont.pl crypto/bn/mont-elf-armv4.S
gen_asm_stdout elf sha/asm/sha1-armv4-large.pl crypto/sha/sha1-elf-armv4.S
gen_asm_stdout elf sha/asm/sha256-armv4.pl crypto/sha/sha256-elf-armv4.S
gen_asm_stdout elf sha/asm/sha512-armv4.pl crypto/sha/sha512-elf-armv4.S
gen_asm_stdout elf modes/asm/ghash-armv4.pl crypto/modes/ghash-elf-armv4.S
2022-03-25 11:37:50 +09:00
$CP $libcrypto_src/arch/arm/armv4cpuid.S crypto
$CP $libcrypto_src/arch/arm/armcap.c crypto
$CP $libcrypto_src/arch/arm/arm_arch.h crypto
2019-01-20 19:56:07 -06:00
for abi in elf macosx masm mingw64; do
echo generating x86_64 ASM source for $abi
2016-11-05 05:21:29 -05:00
gen_asm_stdout $abi aes/asm/aes-x86_64.pl crypto/aes/aes-$abi-x86_64.S
gen_asm_stdout $abi aes/asm/vpaes-x86_64.pl crypto/aes/vpaes-$abi-x86_64.S
gen_asm_stdout $abi aes/asm/bsaes-x86_64.pl crypto/aes/bsaes-$abi-x86_64.S
gen_asm_stdout $abi aes/asm/aesni-x86_64.pl crypto/aes/aesni-$abi-x86_64.S
gen_asm_stdout $abi aes/asm/aesni-sha1-x86_64.pl crypto/aes/aesni-sha1-$abi-x86_64.S
gen_asm_stdout $abi bn/asm/modexp512-x86_64.pl crypto/bn/modexp512-$abi-x86_64.S
gen_asm_stdout $abi bn/asm/x86_64-mont.pl crypto/bn/mont-$abi-x86_64.S
gen_asm_stdout $abi bn/asm/x86_64-mont5.pl crypto/bn/mont5-$abi-x86_64.S
gen_asm_stdout $abi bn/asm/x86_64-gf2m.pl crypto/bn/gf2m-$abi-x86_64.S
gen_asm_stdout $abi camellia/asm/cmll-x86_64.pl crypto/camellia/cmll-$abi-x86_64.S
gen_asm_stdout $abi md5/asm/md5-x86_64.pl crypto/md5/md5-$abi-x86_64.S
gen_asm_stdout $abi modes/asm/ghash-x86_64.pl crypto/modes/ghash-$abi-x86_64.S
gen_asm_stdout $abi rc4/asm/rc4-x86_64.pl crypto/rc4/rc4-$abi-x86_64.S
gen_asm_stdout $abi rc4/asm/rc4-md5-x86_64.pl crypto/rc4/rc4-md5-$abi-x86_64.S
gen_asm_stdout $abi sha/asm/sha1-x86_64.pl crypto/sha/sha1-$abi-x86_64.S
gen_asm $abi sha/asm/sha512-x86_64.pl crypto/sha/sha256-$abi-x86_64.S
gen_asm $abi sha/asm/sha512-x86_64.pl crypto/sha/sha512-$abi-x86_64.S
2016-11-05 05:21:29 -05:00
gen_asm_stdout $abi whrlpool/asm/wp-x86_64.pl crypto/whrlpool/wp-$abi-x86_64.S
gen_asm $abi x86_64cpuid.pl crypto/cpuid-$abi-x86_64.S
done
# copy libtls source
echo copying libtls source
2015-04-30 04:44:35 -05:00
rm -f tls/*.c tls/*.h libtls/src/*.c libtls/src/*.h
for i in `awk '/SOURCES|HEADERS/ { print $3 }' tls/Makefile.am` ; do
2015-02-14 20:03:39 -06:00
if [ -e $libtls_src/$i ]; then
$CP $libtls_src/$i tls
fi
done
# add the libtls symbol export list
$GREP '^[A-Za-z0-9_]' < $libtls_src/Symbols.list > tls/tls.sym
2015-08-31 07:49:50 -05:00
# copy nc(1) source
echo "copying nc(1) source"
2017-01-24 06:06:07 -06:00
$CP $bin_src/nc/nc.1 apps/nc
rm -f apps/nc/*.c apps/nc/*.h
$CP_LIBC $libc_src/net/base64.c apps/nc/compat
for i in `awk '/SOURCES|HEADERS|MANS/ { print $3 }' apps/nc/Makefile.am` ; do
2017-01-24 06:06:07 -06:00
if [ -e $bin_src/nc/$i ]; then
$CP $bin_src/nc/$i apps/nc
fi
done
# copy ocspcheck(1) source
echo "copying ocspcheck(1) source"
$CP $sbin_src/ocspcheck/ocspcheck.8 apps/ocspcheck
rm -f apps/ocspcheck/*.c apps/ocspcheck/*.h
2017-01-26 13:58:27 +09:00
$CP_LIBC $libc_src/string/memmem.c apps/ocspcheck/compat
2017-01-24 06:06:07 -06:00
for i in `awk '/SOURCES|HEADERS|MANS/ { print $3 }' apps/ocspcheck/Makefile.am` ; do
if [ -e $sbin_src/ocspcheck/$i ]; then
$CP $sbin_src/ocspcheck/$i apps/ocspcheck
fi
done
# copy openssl(1) source
echo "copying openssl(1) source"
2017-01-24 06:06:07 -06:00
$CP $bin_src/openssl/openssl.1 apps/openssl
$CP $libcrypto_src/cert.pem .
$CP $libcrypto_src/openssl.cnf .
$CP $libcrypto_src/x509v3.cnf .
for i in `awk '/SOURCES|HEADERS|MANS/ { print $3 }' apps/openssl/Makefile.am` ; do
2017-01-24 06:06:07 -06:00
if [ -e $bin_src/openssl/$i ]; then
$CP $bin_src/openssl/$i apps/openssl
fi
done
2014-07-10 06:07:09 -05:00
# copy libssl source
echo "copying libssl source"
rm -f ssl/*.c ssl/*.h
for i in `awk '/SOURCES|HEADERS/ { print $3 }' ssl/Makefile.am` ; do
2016-09-02 12:43:30 -05:00
$CP $libssl_src/$i ssl
done
# add the libssl symbol export list
$GREP '^[A-Za-z0-9_]' < $libssl_src/Symbols.list > ssl/ssl.sym
# copy libcrypto tests
echo "copying tests"
for i in `find $libcrypto_regress -name '*.c'`; do
$CP "$i" tests
2014-07-10 06:07:09 -05:00
done
$CP $libcrypto_regress/evp/evptests.txt tests
2022-07-31 23:31:18 -05:00
$CP $libcrypto_regress/aead/*.txt tests
2018-07-21 00:15:20 +09:00
# generate libcrypto freenull.c
awk -f $libcrypto_regress/free/freenull.awk \
< $libcrypto_src/Symbols.list > tests/freenull.c.body
cat $libcrypto_regress/free/freenull.c.head tests/freenull.c.body \
$libcrypto_regress/free/freenull.c.tail > tests/freenull.c.tmp
$MV tests/freenull.c.tmp tests/freenull.c
2018-07-21 00:15:20 +09:00
# copy libc tests
$CP $libc_regress/arc4random-fork/arc4random-fork.c tests/arc4randomforktest.c
$CP $libc_regress/explicit_bzero/explicit_bzero.c tests
$CP_LIBC $libc_src/string/memmem.c tests/compat
$CP $libc_regress/timingsafe/timingsafe.c tests
2014-07-10 06:07:09 -05:00
# copy libssl tests
$CP $libssl_regress/ssl/testssl tests
for i in `find $libssl_regress -name '*.c'`; do
$CP "$i" tests
done
2015-06-29 22:49:37 -05:00
$CP $libssl_regress/unit/tests.h tests
2022-07-10 21:44:36 -05:00
$CP $libssl_regress/certs/*.pem tests
$CP $libssl_regress/certs/*.crl tests
2016-11-05 05:21:29 -05:00
$CP $libssl_regress/pqueue/expected.txt tests/pq_expected.txt
2015-09-12 05:18:47 -05:00
# copy libtls tests
for i in `find $libtls_regress -name '*.c'`; do
$CP "$i" tests
done
2014-07-10 06:07:09 -05:00
chmod 755 tests/testssl
# add headers
2014-07-10 06:07:09 -05:00
(cd include/openssl
$CP Makefile.am.tpl Makefile.am
2014-07-10 06:07:09 -05:00
for i in `ls -1 *.h|sort`; do
echo "opensslinclude_HEADERS += $i" >> Makefile.am
done
echo endif >> Makefile.am
2014-07-10 06:07:09 -05:00
)
2015-05-03 22:25:22 -05:00
add_man_links() {
filter=$1
dest=$2
echo "install-data-hook:" >> $dest
for i in `$GREP $filter man/links`; do
2015-05-03 22:25:22 -05:00
IFS=","; set $i; unset IFS
if [ "$2" != "" ]; then
2016-11-05 12:45:47 -05:00
echo " ln -sf \"$1\" \"\$(DESTDIR)\$(mandir)/man3/$2\"" >> $dest
2015-05-03 22:25:22 -05:00
fi
done
echo "" >> $dest
echo "uninstall-local:" >> $dest
for i in `$GREP $filter man/links`; do
2015-05-03 22:25:22 -05:00
IFS=","; set $i; unset IFS
if [ "$2" != "" ]; then
2016-11-05 12:45:47 -05:00
echo " -rm -f \"\$(DESTDIR)\$(mandir)/man3/$2\"" >> $dest
2015-05-03 22:25:22 -05:00
fi
done
}
# apply local patches
2016-01-03 19:00:25 -06:00
PATCH=patch
# Prefer gnu patch on AIX systems, if available
if [ -x /opt/freeware/bin/patch ]; then
PATCH=/opt/freeware/bin/patch
fi
for i in patches/*.patch; do
2016-01-03 19:00:25 -06:00
$PATCH -p0 < $i
done
# copy manpages
echo "copying manpages"
2015-09-07 00:31:59 -05:00
echo EXTRA_DIST = CMakeLists.txt > man/Makefile.am
echo "if !ENABLE_LIBTLS_ONLY" >> man/Makefile.am
2017-10-22 16:10:38 +02:00
echo dist_man3_MANS = >> man/Makefile.am
echo dist_man5_MANS = >> man/Makefile.am
2015-05-03 22:25:22 -05:00
(cd man
for i in `ls -1 $libssl_src/man/*.3 | sort`; do
2014-10-13 06:12:07 -05:00
NAME=`basename "$i"`
$CP $i .
2017-10-22 16:10:38 +02:00
echo "dist_man3_MANS += $NAME" >> Makefile.am
2014-10-13 06:12:07 -05:00
done
2015-05-03 22:25:22 -05:00
2017-10-22 16:10:38 +02:00
for i in `ls -1 $libcrypto_src/man/*.3 | sort`; do
NAME=`basename "$i"`
$CP $i .
2017-10-22 16:10:38 +02:00
echo "dist_man3_MANS += $NAME" >> Makefile.am
done
for i in `ls -1 $libtls_src/man/*.3 | sort`; do
NAME=`basename "$i"`
$CP $i .
2017-10-22 16:10:38 +02:00
echo "dist_man3_MANS += $NAME" >> Makefile.am
done
for i in `ls -1 $libcrypto_src/man/*.5 | sort`; do
NAME=`basename "$i"`
$CP $i .
echo "dist_man5_MANS += $NAME" >> Makefile.am
done
)
2015-05-03 22:25:22 -05:00
add_man_links . man/Makefile.am
echo endif >> man/Makefile.am