Skip to content

Commit

Permalink
Add OpenSSL 3.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Jul 17, 2023
1 parent 68f8c06 commit 58792e4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 48 deletions.
9 changes: 5 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ set -e
# EDIT this section to Select Default Versions #
################################################

OPENSSL="1.1.1t" # https://www.openssl.org/source/
LIBCURL="8.0.1" # https://curl.haxx.se/download.html
NGHTTP2="1.52.0" # https://nghttp2.org/
#OPENSSL="1.1.1u" # https://www.openssl.org/source/
OPENSSL="3.0.9" # https://www.openssl.org/source/
LIBCURL="8.1.2" # https://curl.haxx.se/download.html
NGHTTP2="1.55.1" # https://nghttp2.org/

################################################

Expand All @@ -26,7 +27,7 @@ BUILD_CMD=$*
# Set minimum OS versions for target
MACOS_X86_64_VERSION="" # Empty = use host version
MACOS_ARM64_VERSION="" # Min supported is MacOS 11.0 Big Sur
CATALYST_IOS="15.0" # Min supported is iOS 15.0 for Mac Catalyst
CATALYST_IOS="15.0" # Min supported is iOS 15.0 for Mac Catalyst
IOS_MIN_SDK_VERSION="8.0"
TVOS_MIN_SDK_VERSION="9.0"

Expand Down
2 changes: 1 addition & 1 deletion clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
echo "Cleaning Build-OpenSSL-cURL"
rm -fr curl/curl-* curl/include curl/lib openssl/openssl-1* openssl/openssl-ios* openssl/Mac openssl/iOS* openssl/tvOS* openssl/Catalyst nghttp2/nghttp2-1* nghttp2/Mac nghttp2/iOS* nghttp2/tvOS* nghttp2/lib nghttp2/Catalyst example/iOS\ Test\ App/build/* *.tgz *.pkg nghttp2/pkg-config* /tmp/curl /tmp/openssl /tmp/pkg_config
rm -fr curl/curl-* curl/include curl/lib openssl/openssl-1* openssl/openssl-3* openssl/openssl-ios* openssl/Mac openssl/iOS* openssl/tvOS* openssl/Catalyst nghttp2/nghttp2-1* nghttp2/Mac nghttp2/iOS* nghttp2/tvOS* nghttp2/lib nghttp2/Catalyst example/iOS\ Test\ App/build/* *.tgz *.pkg nghttp2/pkg-config* /tmp/curl /tmp/openssl /tmp/pkg_config
66 changes: 41 additions & 25 deletions openssl/openssl-build-phase1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ buildMac()

pushd . > /dev/null
cd "${OPENSSL_VERSION}"
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure no-asm ${TARGET} -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-${ARCH}.log"
else
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-${ARCH}.log"
fi
make -j${CORES} >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
make install_sw >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
Expand Down Expand Up @@ -249,10 +249,10 @@ buildCatalyst()

echo -e "${subbold}Building ${OPENSSL_VERSION} for ${archbold}${ARCH}${dim} (MacOS ${MACOS_VER} Catalyst iOS ${CATALYST_IOS})"

if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure no-asm ${TARGET} -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}.log"
else
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-catalyst-${ARCH}.log"
fi

#if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
Expand Down Expand Up @@ -305,30 +305,37 @@ buildTVOS()
LANG=C sed -i -- 's/fork()/-1/' "./test/drbgtest.c"
LANG=C sed -i -- 's/!defined(OPENSSL_NO_ASYNC)/defined(HAVE_FORK)/' "./crypto/async/arch/async_posix.h"
fi
if [[ "$OPENSSL_VERSION" = "openssl-3.0"* ]]; then
# LANG=C sed -i -- 's/!defined(OPENSSL_NO_POSIX_IO)/defined(HAVE_FORK)/' "./apps/ocsp.c"
LANG=C sed -i -- 's/fork()/-1/' "./apps/speed.c"
LANG=C sed -i -- 's/fork()/-1/' "./apps/lib/http_server.c"
LANG=C sed -i -- 's/fork()/-1/' "./test/drbgtest.c"
LANG=C sed -i -- 's/undef NO_FORK/define NO_FORK/' "./crypto/async/arch/async_posix.h"
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
fi

# Patch Configure to build for tvOS, not iOS
LANG=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:tvOS/' "./Configure"
chmod u+x ./Configure

if [[ "${ARCH}" == "x86_64" ]]; then
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure no-asm darwin64-x86_64-cc -no-shared --prefix="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure no-asm darwin64-x86_64-cc --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log"
else
./Configure no-asm darwin64-x86_64-cc -no-shared --prefix="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log"
fi
else
export CC="${BUILD_TOOLS}/usr/bin/gcc -fembed-bitcode -arch ${ARCH}"
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure iphoneos-cross DSO_LDFLAGS=-fembed-bitcode --prefix="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure iphoneos-cross --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log"
else
./Configure iphoneos-cross DSO_LDFLAGS=-fembed-bitcode --prefix="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log"
fi
fi
# add -isysroot to CC=
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
sed -ie "s!^CFLAGS=!CFLAGS=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
else
sed -ie "s!^CFLAGS=!CFLAGS=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
fi

make -j${CORES} >> "/tmp/${OPENSSL_VERSION}-tvOS-${ARCH}.log" 2>&1
Expand Down Expand Up @@ -377,22 +384,31 @@ buildTVOSsim()
LANG=C sed -i -- 's/fork()/-1/' "./test/drbgtest.c"
LANG=C sed -i -- 's/!defined(OPENSSL_NO_ASYNC)/defined(HAVE_FORK)/' "./crypto/async/arch/async_posix.h"
fi
if [[ "$OPENSSL_VERSION" = "openssl-3.0"* ]]; then
# LANG=C sed -i -- 's/!defined(OPENSSL_NO_POSIX_IO)/defined(HAVE_FORK)/' "./apps/ocsp.c"
LANG=C sed -i -- 's/fork()/-1/' "./apps/speed.c"
LANG=C sed -i -- 's/fork()/-1/' "./apps/lib/http_server.c"
LANG=C sed -i -- 's/fork()/-1/' "./test/drbgtest.c"
LANG=C sed -i -- 's/undef NO_FORK/define NO_FORK/' "./crypto/async/arch/async_posix.h"
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
export CFLAGS=" -Os -arch ${ARCH} ${RUNTARGET} "
fi

# Patch Configure to build for tvOS, not iOS
LANG=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:tvOS/' "./Configure"
chmod u+x ./Configure

if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure no-asm --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}.log"
else
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}.log"
fi

# add -isysroot to CC=
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
sed -ie "s!^CFLAGS=!CFLAGS=-isysroot ${SYSROOT} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${SYSROOT} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
else
sed -ie "s!^CFLAGS=!CFLAGS=-isysroot ${SYSROOT} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
fi

make -j${CORES} >> "/tmp/${OPENSSL_VERSION}-tvOS-Simulator-${ARCH}.log" 2>&1
Expand Down Expand Up @@ -440,11 +456,11 @@ else
echo "Using ${OPENSSL_VERSION}.tar.gz"
fi

if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
echo "** Building OpenSSL 1.1.1 **"
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* || "$OPENSSL_VERSION" = "openssl-3"* ]]; then
echo "** Building OpenSSL ${OPENSSL_VERSION} **"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0."* ]]; then
echo "** Building OpenSSL 1.0.x ** "
echo "** Building OpenSSL ${OPENSSL_VERSION} ** "
echo -e "${alert}** WARNING: End of Life Version - Upgrade to 1.1.1 **${dim}"
else
echo -e "${alert}** WARNING: This build script has not been tested with $OPENSSL_VERSION **${dim}"
Expand Down
55 changes: 37 additions & 18 deletions openssl/openssl-build-phase2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,16 @@ buildIOS()
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${IOS_SDK_VERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
export CC="${BUILD_TOOLS}/usr/bin/gcc -fembed-bitcode -arch ${ARCH}"
ADDCFLAG=""
if [[ "$OPENSSL_VERSION" = "openssl-3.0"* ]]; then
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
if [[ "${ARCH}" == "armv7" || "${ARCH}" == "armv7s" ]]; then
# armv7 doesn't work with atomic
ADDCFLAG="-DBROKEN_CLANG_ATOMICS "
fi
else
export CC="${BUILD_TOOLS}/usr/bin/gcc -fembed-bitcode -arch ${ARCH}"
fi

echo -e "${subbold}Building ${OPENSSL_VERSION} for ${PLATFORM} ${IOS_SDK_VERSION} ${archbold}${ARCH}${dim} (iOS ${IOS_MIN_SDK_VERSION})"

Expand All @@ -158,24 +167,24 @@ buildIOS()
if [[ $ARCH == "x86_64" ]]; then
TARGET="darwin64-x86_64-cc"
fi
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure no-asm ${TARGET} -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
else
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
fi
else
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
# export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
./Configure iphoneos-cross DSO_LDFLAGS=-fembed-bitcode --prefix="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
else
./Configure iphoneos-cross -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
else
./Configure iphoneos-cross DSO_LDFLAGS=-fembed-bitcode --prefix="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
fi
fi
# add -isysroot to CC=
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
sed -ie "s!^CFLAGS=!CFLAGS=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${IOS_MIN_SDK_VERSION} !" "Makefile"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${IOS_MIN_SDK_VERSION} !" "Makefile"
else
sed -ie "s!^CFLAGS=!CFLAGS=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${IOS_MIN_SDK_VERSION} ${ADDCFLAG} !" "Makefile"
fi

make -j${CORES} >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1
Expand Down Expand Up @@ -218,9 +227,18 @@ buildIOSsim()
# fi
#fi
fi

# set up exports for build
export CFLAGS=" -Os -miphoneos-version-min=${MIPHONEOS} -fembed-bitcode -arch ${ARCH} ${RUNTARGET} "
if [[ "$OPENSSL_VERSION" = "openssl-3.0"* ]]; then
if [[ "${ARCH}" == "armv7" || "${ARCH}" == "armv7s" || "${ARCH}" == "i386" ]]; then
# armv7 and i386 doesn't work with atomic
export CFLAGS=" -Os -miphoneos-version-min=${MIPHONEOS} -DBROKEN_CLANG_ATOMICS -arch ${ARCH} ${RUNTARGET} "
else
export CFLAGS=" -Os -miphoneos-version-min=${MIPHONEOS} ${ADDCFLAG} -arch ${ARCH} ${RUNTARGET} "
fi
else
export CFLAGS=" -Os -miphoneos-version-min=${MIPHONEOS} -fembed-bitcode -arch ${ARCH} ${RUNTARGET} "
fi
export LDFLAGS=" -arch ${ARCH} -isysroot ${DEVELOPER}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk "
export CPPFLAGS=" -I.. -isysroot ${DEVELOPER}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk "
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
Expand All @@ -232,10 +250,10 @@ buildIOSsim()
echo -e "${subbold}Building ${OPENSSL_VERSION} for ${PLATFORM} ${iOS_SDK_VERSION} ${archbold}${ARCH}${dim} (iOS ${MIPHONEOS})"

# configure
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}.log"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0"* ]]; then
./Configure no-asm ${TARGET} -no-shared --openssldir="/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}.log"
else
./Configure no-asm ${TARGET} -no-shared --prefix="/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}" --openssldir="/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}" $CUSTOMCONFIG &> "/tmp/${OPENSSL_VERSION}-iOS-Simulator-${ARCH}.log"
fi

# add -isysroot to CC=
Expand Down Expand Up @@ -292,11 +310,11 @@ else
echo "Using ${OPENSSL_VERSION}.tar.gz"
fi

if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* ]]; then
echo "** Building OpenSSL 1.1.1 **"
if [[ "$OPENSSL_VERSION" = "openssl-1.1.1"* || "$OPENSSL_VERSION" = "openssl-3"* ]]; then
echo "** Building OpenSSL ${OPENSSL_VERSION} **"
else
if [[ "$OPENSSL_VERSION" = "openssl-1.0."* ]]; then
echo "** Building OpenSSL 1.0.x ** "
echo "** Building OpenSSL ${OPENSSL_VERSION} ** "
echo -e "${alert}** WARNING: End of Life Version - Upgrade to 1.1.1 **${dim}"
else
echo -e "${alert}** WARNING: This build script has not been tested with $OPENSSL_VERSION **${dim}"
Expand All @@ -312,6 +330,7 @@ if [ "$engine" == "1" ]; then
fi

echo -e "${bold}Building iOS libraries${dim}"

buildIOS "armv7"
buildIOS "armv7s"
buildIOS "arm64"
Expand Down

0 comments on commit 58792e4

Please sign in to comment.