Skip to content

Commit 8830357

Browse files
authored
Merge pull request beeware#22 from paulproteus/openssl-upgrade
Upgrade OpenSSL to 1.1.1g
2 parents 12d78a7 + 15cd4d5 commit 8830357

File tree

2 files changed

+105
-98
lines changed

2 files changed

+105
-98
lines changed

main.sh

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -105,34 +105,43 @@ function build_one_abi() {
105105
fix_permissions
106106
}
107107

108-
# Download a file and verify its sha256sum.
109-
function download_verify_sha256() {
110-
local url="$1"
111-
local sha256="$2"
112-
local filename_prefix="${3:-}"
113-
local DOWNLOAD_CACHE="$PWD/downloads"
114-
local DOWNLOAD_CACHE_TMP="$PWD/downloads.tmp"
115-
local expected_filename="${filename_prefix}$(echo "$url" | tr '/' '\n' | tail -n1)"
108+
# Download a file into downloads/$name/$filename and verify its sha256sum.
109+
# If any files exist under downloads/$name, remove them. In the Dockerfile,
110+
# we refer to the tarball as downloads/$name/* , allowing the Dockerfile
111+
# to avoid redundantly stating the version number.
112+
function download() {
113+
local name="$1"
114+
local url="$2"
115+
local sha256="$3"
116+
local download_dir="${PWD}/downloads/$name"
117+
local base_filename="$(echo "$url" | tr '/' '\n' | tail -n1)"
118+
local full_filename="$download_dir/$base_filename"
119+
local full_filename_tmp="${full_filename}.tmp"
116120

117121
# Check existing file.
118-
if [ -f "${DOWNLOAD_CACHE}/${expected_filename}" ] ; then
119-
echo "Using ${expected_filename} from downloads/"
122+
if [ -f "${full_filename}" ] ; then
123+
echo "Using $name (${full_filename})"
120124
return
121125
fi
122126

123-
echo "Downloading $expected_filename"
124-
rm -rf downloads.tmp && mkdir -p downloads.tmp
125-
curl -L "$url" -o "downloads.tmp/$expected_filename"
127+
echo "Downloading $name ($full_filename)"
128+
rm -rf "$download_dir"
129+
mkdir -p "$download_dir"
130+
curl -L "$url" -o "$full_filename_tmp"
126131
local OK="no"
127-
shasum -a 256 "${DOWNLOAD_CACHE_TMP}/${expected_filename}" | grep -q "$sha256" && OK="yes"
132+
local actual_sha256=$(shasum -a 256 "${full_filename_tmp}")
133+
echo $actual_sha256 | grep -q "$sha256" && OK="yes"
128134
if [ "$OK" = "yes" ] ; then
129-
mkdir -p "$DOWNLOAD_CACHE"
130-
mv "${DOWNLOAD_CACHE_TMP}/${expected_filename}" "${DOWNLOAD_CACHE}/${expected_filename}"
131-
rmdir "${DOWNLOAD_CACHE_TMP}"
135+
mv "${full_filename_tmp}" "${full_filename}"
132136
else
133-
echo "Checksum mismatch while downloading: $url"
137+
echo "Checksum mismatch while downloading $name <$url>"
138+
echo "Expected: $sha256"
139+
echo " Got: $actual_sha256"
134140
echo ""
135-
echo "Maybe your Internet connection got disconnected during the download. Please re-run the script."
141+
echo "Maybe your Internet connection got disconnected during the download. Re-run"
142+
echo "the script to re-download. If you're updating the version of this package"
143+
echo "update the expected SHA in this script."
144+
echo "Partial file remains in: ${full_filename_tmp}"
136145
echo "Aborting."
137146
exit 1
138147
fi
@@ -149,8 +158,8 @@ fix_permissions() {
149158
function main() {
150159
# Interpret argv for settings; first, set defaults. For some settings, create
151160
# DEFAULT_* variables for inclusion into help output.
152-
local DEFAULT_VERSIONS="3.6,3.7"
153-
local VERSIONS="$DEFAULT_VERSIONS"
161+
local DEFAULT_VERSION="3.7"
162+
local VERSION="$DEFAULT_VERSION"
154163
local DEFAULT_TARGET_ABIS="x86,x86_64,armeabi-v7a,arm64-v8a"
155164
local TARGET_ABIS="$DEFAULT_TARGET_ABIS"
156165
local DEFAULT_COMPRESS_LEVEL="8"
@@ -159,7 +168,7 @@ function main() {
159168
while getopts ":v:a:n:z:" opt; do
160169
case "${opt}" in
161170
v) # process Python version
162-
VERSIONS="$OPTARG"
171+
VERSION="$OPTARG"
163172
;;
164173
a) # process Android ABIs
165174
TARGET_ABIS="$OPTARG"
@@ -174,12 +183,12 @@ function main() {
174183
echo "Invalid option: $OPTARG requires an argument" 1>&2
175184
;;
176185
\? )
177-
echo "Usage: main.sh [-v versions] [-a ABIs] [-n build_number] [-z compression_level]
186+
echo "Usage: main.sh [-v version] [-a ABIs] [-n build_number] [-z compression_level]
178187
179188
Build ZIP file of Python resources for Android, including CPython compiled as a .so.
180189
181-
-v: Specify Python versions to build, separated by commas. For example: -v 3.6,3.7
182-
Default: ${DEFAULT_VERSIONS}
190+
-v: Specify Python version to build. For example: -v 3.6
191+
Default: ${DEFAULT_VERSION}
183192
184193
-a: Specify Android ABIs to build, separated by commas. For example: -a x86,arm64-v8a
185194
Default: ${TARGET_ABIS}
@@ -207,58 +216,50 @@ Build ZIP file of Python resources for Android, including CPython compiled as a
207216

208217
echo "Downloading compile-time dependencies."
209218

210-
local build_dependencies=(
211-
"https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz=f39b523c724d0e0047d238eb2bb17a9565a60574cf651206c867ee5fc000ab43"
212-
"https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip=8381c440fe61fcbb01e209211ac01b519cd6adf51ab1c2281d5daad6ca4c8c8c"
213-
"https://www.openssl.org/source/openssl-1.1.1f.tar.gz=186c6bfe6ecfba7a5b48c47f8a1673d0f3b0e5ba2e25602dd23b629975da3f35"
214-
"https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz=72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056"
215-
"https://tukaani.org/xz/xz-5.2.4.tar.gz=b512f3b726d3b37b6dc4c8570e137b9311e7552e8ccbab4d39d47ce5f4177145"
216-
"https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz=ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269"
217-
"http://archive.ubuntu.com/ubuntu/pool/main/s/sqlite3/sqlite3_3.11.0.orig.tar.xz=79fb8800b8744337d5317270899a5a40612bb76f81517e131bf496c26b044490"
218-
)
219-
for build_dependency in "${build_dependencies[@]}" ; do
220-
download_verify_sha256 ${build_dependency/=/ }
221-
done
222-
223-
# Download rubicon-java source tarball with a rubicon-java-* filename prefix. This allows the
224-
# Dockerfile to find it as rubicon-java-*.tar.gz . Other tarballs don't need this treatment
225-
# because they have the project name in the filename.
226-
download_verify_sha256 "https://github.com/beeware/rubicon-java/archive/v0.2.0.tar.gz" "b0d3d9ad4988c2d0e6995e2cbec085a5ef49b15e1be0d325b6141fb90fccccf7" "rubicon-java-"
219+
download jdk "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz" "f39b523c724d0e0047d238eb2bb17a9565a60574cf651206c867ee5fc000ab43"
220+
download ndk "https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip" "8381c440fe61fcbb01e209211ac01b519cd6adf51ab1c2281d5daad6ca4c8c8c"
221+
download openssl "https://www.openssl.org/source/openssl-1.1.1g.tar.gz" "ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46"
222+
download libffi "https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz" "72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056"
223+
download xz "https://tukaani.org/xz/xz-5.2.5.tar.gz" "f6f4910fd033078738bd82bfba4f49219d03b17eb0794eb91efbae419f4aba10"
224+
download bzip2 "https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz" "ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269"
225+
download sqlite3 "http://archive.ubuntu.com/ubuntu/pool/main/s/sqlite3/sqlite3_3.11.0.orig.tar.xz" "79fb8800b8744337d5317270899a5a40612bb76f81517e131bf496c26b044490"
226+
download rubicon-java "https://github.com/beeware/rubicon-java/archive/v0.2.1.tar.gz" "a1d1c6edccbd75631a0c3cc129239e10f7b6d8f221a393b96fbdc83293636f8b"
227227

228-
echo "Downloading Python versions, as needed."
229-
for version in ${VERSIONS//,/ } ; do
230-
if [ "$version" = "3.7" ] ; then
231-
download_verify_sha256 "https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz" "55a2cce72049f0794e9a11a84862e9039af9183603b78bc60d89539f82cf533f"
232-
elif [ "$version" = "3.6" ] ; then
233-
download_verify_sha256 "https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tar.xz" "0a833c398ac8cd7c5538f7232d8531afef943c60495c504484f308dac3af40de"
234-
else
235-
echo "Unknown Python version: $version. Aborting."
228+
echo "Downloading Python version."
229+
case "$VERSION" in
230+
3.6)
231+
download "python-3.6" "https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tar.xz" "0a833c398ac8cd7c5538f7232d8531afef943c60495c504484f308dac3af40de"
232+
;;
233+
3.7)
234+
download "python-3.7" "https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz" "55a2cce72049f0794e9a11a84862e9039af9183603b78bc60d89539f82cf533f"
235+
;;
236+
*)
237+
echo "Invalid Python version: $VERSION"
236238
exit 1
237-
fi
238-
done
239+
;;
240+
esac
239241

240242
echo 'Starting Docker builds.'
241-
for VERSION in ${VERSIONS//,/ } ; do
242-
# Clear the build directory.
243-
mkdir -p build
244-
mkdir -p dist
245-
fix_permissions
246-
rm -rf ./build/"$VERSION"
247-
mkdir -p build/"$VERSION"
248243

249-
# Build each ABI.
250-
for TARGET_ABI_SHORTNAME in ${TARGET_ABIS//,/ }; do
251-
echo "Building Python $VERSION for $TARGET_ABI_SHORTNAME"
252-
build_one_abi "$TARGET_ABI_SHORTNAME" "$VERSION" "$COMPRESS_LEVEL"
253-
done
244+
# Clear the build directory.
245+
mkdir -p build
246+
mkdir -p dist
247+
fix_permissions
248+
rm -rf ./build/"$VERSION"
249+
mkdir -p build/"$VERSION"
254250

255-
# Make a ZIP file, writing it first to `.tmp` so that we atomically clobber an
256-
# existing ZIP file rather than attempt to merge the new contents with old.
257-
pushd build/"$VERSION"/app > /dev/null
258-
zip -x@../../../excludes/all/excludes -r -"${COMPRESS_LEVEL}" "../../../dist/Python-$VERSION-Android-support${BUILD_TAG}.zip".tmp .
259-
mv "../../../dist/Python-$VERSION-Android-support${BUILD_TAG}.zip".tmp "../../../dist/Python-$VERSION-Android-support${BUILD_TAG}.zip"
260-
popd
251+
# Build each ABI.
252+
for TARGET_ABI_SHORTNAME in ${TARGET_ABIS//,/ }; do
253+
echo "Building Python $VERSION for $TARGET_ABI_SHORTNAME"
254+
build_one_abi "$TARGET_ABI_SHORTNAME" "$VERSION" "$COMPRESS_LEVEL"
261255
done
256+
257+
# Make a ZIP file, writing it first to `.tmp` so that we atomically clobber an
258+
# existing ZIP file rather than attempt to merge the new contents with old.
259+
pushd build/"$VERSION"/app > /dev/null
260+
zip -x@../../../excludes/all/excludes -r -"${COMPRESS_LEVEL}" "../../../dist/Python-$VERSION-Android-support${BUILD_TAG}.zip".tmp .
261+
mv "../../../dist/Python-$VERSION-Android-support${BUILD_TAG}.zip".tmp "../../../dist/Python-$VERSION-Android-support${BUILD_TAG}.zip"
262+
popd
262263
}
263264

264265
main "$@"

python.Dockerfile

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ RUN apt-get update -qq && apt-get -qq install unzip rsync
66

77
# Install toolchains: Android NDK & Java JDK.
88
WORKDIR /opt/ndk
9-
ADD downloads/android-ndk-r20b-linux-x86_64.zip .
10-
RUN unzip -q android-ndk-r20b-linux-x86_64.zip && rm android-ndk-r20b-linux-x86_64.zip
11-
ENV NDK /opt/ndk/android-ndk-r20b
9+
ADD downloads/ndk/* .
10+
RUN unzip -q android-ndk-*-linux-x86_64.zip && rm android-ndk-*-linux-x86_64.zip && mv android-ndk-* android-ndk
11+
ENV NDK /opt/ndk/android-ndk
1212
WORKDIR /opt/jdk
13-
ADD downloads/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz .
14-
ENV JAVA_HOME /opt/jdk/jdk8u242-b08/
15-
ENV PATH "/opt/jdk/jdk8u242-b08/bin:${PATH}"
13+
ADD downloads/jdk/* .
14+
RUN mv jdk* jdk_home
15+
ENV JAVA_HOME /opt/jdk/jdk_home/
16+
ENV PATH "/opt/jdk/jdk_home/bin:${PATH}"
1617

1718
# Store output here; the directory structure corresponds to our Android app template.
1819
ENV APPROOT /opt/python-build/approot
@@ -49,51 +50,56 @@ ENV AR=$TOOLCHAIN/bin/$TOOLCHAIN_TRIPLE-ar \
4950
# We hard-code avoid_version=yes into libtool so that libsqlite3.so is the SONAME.
5051
FROM toolchain as build_sqlite
5152
RUN apt-get update -qq && apt-get -qq install make autoconf autotools-dev tcl8.6-dev build-essential
52-
ADD downloads/sqlite3_3.11.0.orig.tar.xz .
53-
RUN cd sqlite3-3.11.0 && autoreconf && cp -f /usr/share/misc/config.sub . && cp -f /usr/share/misc/config.guess .
54-
RUN cd sqlite3-3.11.0 && ./configure --host "$TOOLCHAIN_TRIPLE" --build "$COMPILER_TRIPLE" --prefix="$BUILD_HOME/built/sqlite"
55-
RUN cd sqlite3-3.11.0 && sed -i -E 's,avoid_version=no,avoid_version=yes,' ltmain.sh libtool
56-
RUN cd sqlite3-3.11.0 && make install
53+
ADD downloads/sqlite3/* .
54+
RUN mv sqlite3-* sqlite3-src
55+
RUN cd sqlite3-src && autoreconf && cp -f /usr/share/misc/config.sub . && cp -f /usr/share/misc/config.guess .
56+
RUN cd sqlite3-src && ./configure --host "$TOOLCHAIN_TRIPLE" --build "$COMPILER_TRIPLE" --prefix="$BUILD_HOME/built/sqlite"
57+
RUN cd sqlite3-src && sed -i -E 's,avoid_version=no,avoid_version=yes,' ltmain.sh libtool
58+
RUN cd sqlite3-src && make install
5759

5860
# Install bzip2 & lzma libraries, for stdlib's _bzip2 and _lzma modules.
5961
FROM toolchain as build_xz
6062
RUN apt-get update -qq && apt-get -qq install make
61-
ADD downloads/xz-5.2.4.tar.gz .
63+
ADD downloads/xz/* .
64+
RUN mv xz-* xz-src
6265
ENV LIBXZ_INSTALL_DIR="$BUILD_HOME/built/xz"
6366
RUN mkdir -p "$LIBXZ_INSTALL_DIR"
64-
RUN cd xz-5.2.4 && ./configure --host "$TOOLCHAIN_TRIPLE" --build "$COMPILER_TRIPLE" --prefix="$LIBXZ_INSTALL_DIR"
65-
RUN cd xz-5.2.4 && make install
67+
RUN cd xz-src && ./configure --host "$TOOLCHAIN_TRIPLE" --build "$COMPILER_TRIPLE" --prefix="$LIBXZ_INSTALL_DIR"
68+
RUN cd xz-src && make install
6669

6770
FROM toolchain as build_bz2
6871
RUN apt-get update -qq && apt-get -qq install make
6972
ENV LIBBZ2_INSTALL_DIR="$BUILD_HOME/built/libbz2"
70-
ADD downloads/bzip2-1.0.8.tar.gz .
73+
ADD downloads/bzip2/* .
74+
RUN mv bzip2-* bzip2-src
7175
RUN mkdir -p "$LIBBZ2_INSTALL_DIR" && \
72-
cd bzip2-1.0.8 && \
76+
cd bzip2-src && \
7377
sed -i -e 's,[.]1[.]0.8,,' -e 's,[.]1[.]0,,' -e 's,ln -s,#ln -s,' -e 's,rm -f libbz2.so,#rm -f libbz2.so,' -e 's,^CC=,#CC=,' Makefile-libbz2_so
74-
RUN cd bzip2-1.0.8 && make -f Makefile-libbz2_so
78+
RUN cd bzip2-src && make -f Makefile-libbz2_so
7579
RUN mkdir -p "${LIBBZ2_INSTALL_DIR}/lib"
76-
RUN cp bzip2-1.0.8/libbz2.so "${LIBBZ2_INSTALL_DIR}/lib"
80+
RUN cp bzip2-src/libbz2.so "${LIBBZ2_INSTALL_DIR}/lib"
7781
RUN mkdir -p "${LIBBZ2_INSTALL_DIR}/include"
78-
RUN cp bzip2-1.0.8/bzlib.h "${LIBBZ2_INSTALL_DIR}/include"
82+
RUN cp bzip2-src/bzlib.h "${LIBBZ2_INSTALL_DIR}/include"
7983

8084
# libffi is required by ctypes
8185
FROM toolchain as build_libffi
8286
RUN apt-get update -qq && apt-get -qq install file make
83-
ADD downloads/libffi-3.3.tar.gz .
87+
ADD downloads/libffi/* .
88+
RUN mv libffi-* libffi-src
8489
ENV LIBFFI_INSTALL_DIR="$BUILD_HOME/built/libffi"
8590
RUN mkdir -p "$LIBFFI_INSTALL_DIR"
86-
RUN cd libffi-3.3 && ./configure --host "$TOOLCHAIN_TRIPLE" --build "$COMPILER_TRIPLE" --prefix="$LIBFFI_INSTALL_DIR"
87-
RUN cd libffi-3.3 && make install
91+
RUN cd libffi-src && ./configure --host "$TOOLCHAIN_TRIPLE" --build "$COMPILER_TRIPLE" --prefix="$LIBFFI_INSTALL_DIR"
92+
RUN cd libffi-src && make install
8893

8994
FROM toolchain as build_openssl
9095
# OpenSSL requires libfindlibs-libs-perl. make is nice, too.
9196
RUN apt-get update -qq && apt-get -qq install libfindbin-libs-perl make
92-
ADD downloads/openssl-1.1.1f.tar.gz .
97+
ADD downloads/openssl/* .
98+
RUN mv openssl-* openssl-src
9399
ARG OPENSSL_BUILD_TARGET
94-
RUN cd openssl-1.1.1f && ANDROID_NDK_HOME="$NDK" ./Configure ${OPENSSL_BUILD_TARGET} -D__ANDROID_API__="$ANDROID_API_LEVEL" --prefix="$BUILD_HOME/built/openssl" --openssldir="$BUILD_HOME/built/openssl"
95-
RUN cd openssl-1.1.1f && make SHLIB_EXT='${SHLIB_VERSION_NUMBER}.so'
96-
RUN cd openssl-1.1.1f && make install SHLIB_EXT='${SHLIB_VERSION_NUMBER}.so'
100+
RUN cd openssl-src && ANDROID_NDK_HOME="$NDK" ./Configure ${OPENSSL_BUILD_TARGET} -D__ANDROID_API__="$ANDROID_API_LEVEL" --prefix="$BUILD_HOME/built/openssl" --openssldir="$BUILD_HOME/built/openssl"
101+
RUN cd openssl-src && make SHLIB_EXT='${SHLIB_VERSION_NUMBER}.so'
102+
RUN cd openssl-src && make install SHLIB_EXT='${SHLIB_VERSION_NUMBER}.so'
97103

98104
# This build container builds Python, rubicon-java, and any dependencies. Each Python version
99105
# requires itself to be installed globally during a cross-compile, and Python 3.6 additionally
@@ -116,7 +122,7 @@ ENV PKG_CONFIG_PATH="/opt/python-build/built/libffi/lib/pkgconfig:/opt/python-bu
116122

117123
# Download & patch Python. We assume that there is only one Python-${VERSION}.*.tar.xz file.
118124
ARG PYTHON_VERSION
119-
ADD downloads/Python-${PYTHON_VERSION}.*.tar.xz .
125+
ADD downloads/python-${PYTHON_VERSION}/* .
120126
RUN mv Python-* python-src
121127
# Modify ./configure so that, even though this is Linux, it does not append .1.0 to the .so file.
122128
RUN sed -i -e 's,INSTSONAME="$LDLIBRARY".$SOVERSION,,' python-src/configure
@@ -205,7 +211,7 @@ RUN cp -a $PYTHON_INSTALL_DIR/lib/libpython${PYTHON_VERSION}m.so "$JNI_LIBS"
205211
# Download & install rubicon-java's Java & C parts. The *.py files in rubicon-java are
206212
# incorporated into apps via app dependency management and are ABI-independent since
207213
# they access the C library via `ctypes`.
208-
ADD downloads/rubicon-java-* .
214+
ADD downloads/rubicon-java/* .
209215
RUN mv rubicon-java-* rubicon-java-src
210216
RUN cd rubicon-java-src && \
211217
LDFLAGS='-landroid -llog' PYTHON_CONFIG=$PYTHON_INSTALL_DIR/bin/python3-config make

0 commit comments

Comments
 (0)