Skip to content

Instantly share code, notes, and snippets.

@peterdeweese
Created July 26, 2016 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterdeweese/db7cbacb66b21c8c67fd1a86b3a6d7c4 to your computer and use it in GitHub Desktop.
Save peterdeweese/db7cbacb66b21c8c67fd1a86b3a6d7c4 to your computer and use it in GitHub Desktop.
openssl fips help
#!/bin/bash
# This script builds the iOS and Mac openSSL libraries
# Download openssl http://www.openssl.org/source/ and place the tarball next to this script
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
set -e
set -x
usage ()
{
echo "usage: $0 [minimum iOS SDK version (default 7.1)]"
exit 127
}
if [ $1 -e "-h" ]; then
usage
fi
if [ -z $1 ]; then
SDK_VERSION="7.1"
else
SDK_VERSION=$1
fi
OPENSSL_VERSION="openssl-fips-2.0.7"
DEVELOPER=`xcode-select -print-path`
buildIOS()
{
ARCH=$1
pushd . > /dev/null
cd "${OPENSSL_VERSION}"
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
# sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
fi
export $PLATFORM
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
echo "Building ${OPENSSL_VERSION} for ${PLATFORM} ${SDK_VERSION} ${ARCH} build tools ${BUILD_TOOLS}"
chmod +x Configure
if [[ "${ARCH}" == "x86_64" ]]; then
./Configure darwin64-x86_64-cc --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
elif [[ "${ARCH}" == "i386" ]]; then
./Configure darwin-i386-cc --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
else
./Configure iphoneos-cross --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
fi
# add -isysroot to CC=
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${SDK_VERSION} !" "Makefile"
make | tee "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
make install | tee "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
# make clean | tee > "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log"
popd > /dev/null
echo "Copying library"
mkdir -p "lib/${ARCH}/"
cp -r "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}/lib/" "lib/${ARCH}/"
echo "Copying headers"
mkdir -p "include/${ARCH}/"
cp -r "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}/include/" "include/${ARCH}/"
pwd
cp -r "${OPENSSL_VERSION}/crypto/stack/" "include/${ARCH}/openssl"
}
echo "Cleaning up"
rm -rf include/* lib/*
mkdir -p lib
mkdir -p include
rm -rf "/tmp/${OPENSSL_VERSION}-*"
rm -rf "/tmp/${OPENSSL_VERSION}-*.log"
rm -rf "${OPENSSL_VERSION}"
if [ ! -e ${OPENSSL_VERSION}.tar.gz ]; then
echo "Downloading ${OPENSSL_VERSION}.tar.gz"
curl -O http://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz
else
echo "Using ${OPENSSL_VERSION}.tar.gz"
fi
echo "Unpacking openssl"
tar xfz "${OPENSSL_VERSION}.tar.gz"
buildIOS "armv7"
buildIOS "armv7s"
buildIOS "arm64"
buildIOS "x86_64"
buildIOS "i386"
echo "Cleaning up"
rm -rf /tmp/${OPENSSL_VERSION}-*
rm -rf ${OPENSSL_VERSION}
echo "Done"
#
# setenv-macho.sh
#
#
# depending on whether or not we are using the simulator or the real
# device we have slightly different paths which are determined entirely
# by the CROSS_TYPE setting - either Simulator or OS
#
export CROSS_TYPE=Simulator
export CROSS_TYPE=OS
cross_arch=""
cross_arch="-armv7"
##CROSS_DEVELOPER=`xcode-select -print-path`
CROSS_DEVELOPER="/Applications//Xcode.app/Contents/Developer"
# CROSS_TOP is the top of the development tools tree
export CROSS_TOP="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
# CROSS_CHAIN is the location of the actual compiler tools
export CROSS_CHAIN="$CROSS_TOP"/usr/bin/
# CROSS_SDK is the SDK version being used - adjust as appropriate
# for 4.3 or 5.0 (default)
for i in 5.1 5.0 4.3 do
do
if [ -d "$CROSS_DEVELOPER/Platforms/iPhoneOS.platform//Developer/SDKs/iPhoneOS"$i".sdk" ]; then
SDKVER=$i
break
fi
done
export CROSS_SDK=iPhone"$CROSS_TYPE""$SDKVER".sdk
#
# fips/sha/Makefile uses HOSTCC for building fips_standalone_sha1
#
export HOSTCC=/usr/bin/cc
export HOSTCFLAGS="-arch i386"
# CROSS_COMPILE is the prefix for the tools - in this case the scripts
# which invoke the tools with the correct options for 'fat' binary handling
export CROSS_COMPILE="`pwd`"/iOS/
# FIPS_SIG is the tool for determining the incore fingerprint
#export FIPS_SIG=/usr/local/ssl/fingerprint-macho
export FIPS_SIG="`pwd`"/iOS/incore_macho
#
# these remain to be cleaned up ...
#
export IOS_TARGET=darwin-iphoneos-cross
export IOS_INSTALLDIR=/usr/local/ssl/Release-iphoneos
#
# definition for uname output for cross-compilation
#
cross_type=`echo $CROSS_TYPE | tr '[A-Z]' '[a-z]'`
#SYSTEM="iphone"$cross_type"$cross_arch-cross"
#MACHINE="darwin"
#BUILD="build"
MACHINE=`echo "$cross_arch" | sed -e 's/^-//'`
SYSTEM="iphoneos"
BUILD="build"
export MACHINE
export SYSTEM
export BUILD
# adjust the path to ensure we always get the correct tools
export PATH="`pwd`"/iOS:$PATH
# for iOS we have not plugged in ASM or SHLIB support so we disable
# those options for now
export CONFIG_OPTIONS="no-asm no-shared --openssldir=$IOS_INSTALLDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment