Skip to content

Commit 045d3d8

Browse files
authored
CocoaPods spec: CLOpenSSL (#3)
Support publishing our OpenSSL build on CocoaPods. Now running "make specs" will also generate "cocoapods/CLOpenSSL.podspec" which can be uploaded to CocoaPods repositories. The spec does not actually build OpenSSL on the user machine. Instead, it downloads prebuilt frameworks (the same as used by Carthage). This results in considerable savings of the installation time. The framework binaries are currently hosted as GitHub releases. Not checking them into the repository also gives some savings (or rather, will give over time). Since the spec still clones *this* repository, it will be possible to build OpenSSL from source on developers' machines, if needed. Only dynamic frameworks are supported with CocoaPods. There is an option to include static frameworks, but that does not work out of the box and is very inconvenient for us to support. Note that at the moment there is no "v1.0.221" tag in this repository so the produced Podspec will not pass linting. It can be properly and fully linted only after the tag is published. (That's how Cocoapods works.)
1 parent 200ffc0 commit 045d3d8

File tree

4 files changed

+260
-5
lines changed

4 files changed

+260
-5
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ endif
1313
## OpenSSL version to build
1414
VERSION ?= 1.1.1g
1515

16+
MIN_IOS_SDK = 8.0
17+
MIN_OSX_SDK = 10.9
18+
1619
BUILD_ARCHS += ios_i386 ios_x86_64 ios_arm64 ios_armv7s ios_armv7
1720
BUILD_ARCHS += mac_x86_64
1821
BUILD_TARGETS += ios-sim-cross-i386 ios-sim-cross-x86_64
@@ -22,8 +25,8 @@ BUILD_TARGETS += macos64-x86_64
2225
BUILD_FLAGS += --version=$(VERSION)
2326
BUILD_FLAGS += --archs="$(BUILD_ARCHS)"
2427
BUILD_FLAGS += --targets="$(BUILD_TARGETS)"
25-
BUILD_FLAGS += --min-ios-sdk=8.0
26-
BUILD_FLAGS += --min-macos-sdk=10.9
28+
BUILD_FLAGS += --min-ios-sdk=$(MIN_IOS_SDK)
29+
BUILD_FLAGS += --min-macos-sdk=$(MIN_OSX_SDK)
2730

2831

2932
#===== Building ================================================================

cocoapods/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Keep generated file on maintainer's machine only,
2+
# no need to duplicate it with the template.
3+
CLOpenSSL.podspec
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
Pod::Spec.new do |s|
2+
# These parts of the spec are filled in by the template generator.
3+
openssl_version = "%%OPENSSL_VERSION%%"
4+
min_target_ios = "%%MIN_IOS_SDK%%"
5+
min_target_osx = "%%MIN_OSX_SDK%%"
6+
7+
github_repo = "%%GITHUB_REPO%%"
8+
iPhone_archive_name = "%%IPHONE_ARCHIVE_NAME%%"
9+
iPhone_archive_hash = "%%IPHONE_ARCHIVE_HASH%%"
10+
macOSX_archive_name = "%%MACOSX_ARCHIVE_NAME%%"
11+
macOSX_archive_hash = "%%MACOSX_ARCHIVE_HASH%%"
12+
13+
# Project metadata
14+
s.name = "CLOpenSSL"
15+
s.version = "#{openssl_version}"
16+
s.summary = "Pre-built OpenSSL framework for iOS and macOS: full-featured toolkit for the TLS and SSL protocols as well as a general-purpose cryptography library."
17+
s.homepage = "https://www.openssl.org/"
18+
s.authors = [
19+
"Andy Polyakov",
20+
"Ben Laurie",
21+
"Ben Kaduk",
22+
"Bernd Edlinger",
23+
"Bodo Möller",
24+
"David Benjamin",
25+
"Emilia Käsper",
26+
"Eric Young",
27+
"Geoff Thorpe",
28+
"Holger Reif",
29+
"Kurt Roeckx",
30+
"Lutz Jänicke",
31+
"Mark J. Cox",
32+
"Matt Caswell",
33+
"Matthias St. Pierre",
34+
"Nils Larsch",
35+
"Paul Dale",
36+
"Paul C. Sutton",
37+
"Ralf S. Engelschall",
38+
"Rich Salz",
39+
"Richard Levitte",
40+
"Stephen Henson",
41+
"Steve Marquess",
42+
"Tim Hudson",
43+
"Ulf Möller",
44+
"Viktor Dukhovni",
45+
]
46+
47+
# Source code location. Actually, this is the script that builds OpenSSL
48+
# after downloading its source tarball from the official site.
49+
s.source = { :git => "#{github_repo}.git", :tag => "v#{openssl_version}" }
50+
s.license = {
51+
:type => "OpenSSL/SSLeay",
52+
:text => <<~EOF
53+
54+
LICENSE ISSUES
55+
==============
56+
57+
The OpenSSL toolkit stays under a double license, i.e. both the conditions of
58+
the OpenSSL License and the original SSLeay license apply to the toolkit.
59+
See below for the actual license texts.
60+
61+
OpenSSL License
62+
---------------
63+
64+
/* ====================================================================
65+
* Copyright (c) 1998-2019 The OpenSSL Project. All rights reserved.
66+
*
67+
* Redistribution and use in source and binary forms, with or without
68+
* modification, are permitted provided that the following conditions
69+
* are met:
70+
*
71+
* 1. Redistributions of source code must retain the above copyright
72+
* notice, this list of conditions and the following disclaimer.
73+
*
74+
* 2. Redistributions in binary form must reproduce the above copyright
75+
* notice, this list of conditions and the following disclaimer in
76+
* the documentation and/or other materials provided with the
77+
* distribution.
78+
*
79+
* 3. All advertising materials mentioning features or use of this
80+
* software must display the following acknowledgment:
81+
* "This product includes software developed by the OpenSSL Project
82+
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
83+
*
84+
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
85+
* endorse or promote products derived from this software without
86+
* prior written permission. For written permission, please contact
87+
88+
*
89+
* 5. Products derived from this software may not be called "OpenSSL"
90+
* nor may "OpenSSL" appear in their names without prior written
91+
* permission of the OpenSSL Project.
92+
*
93+
* 6. Redistributions of any form whatsoever must retain the following
94+
* acknowledgment:
95+
* "This product includes software developed by the OpenSSL Project
96+
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
97+
*
98+
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
99+
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
101+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
102+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
103+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
105+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
107+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
108+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
109+
* OF THE POSSIBILITY OF SUCH DAMAGE.
110+
* ====================================================================
111+
*
112+
* This product includes cryptographic software written by Eric Young
113+
* ([email protected]). This product includes software written by Tim
114+
* Hudson ([email protected]).
115+
*
116+
*/
117+
118+
Original SSLeay License
119+
-----------------------
120+
121+
/* Copyright (C) 1995-1998 Eric Young ([email protected])
122+
* All rights reserved.
123+
*
124+
* This package is an SSL implementation written
125+
* by Eric Young ([email protected]).
126+
* The implementation was written so as to conform with Netscapes SSL.
127+
*
128+
* This library is free for commercial and non-commercial use as long as
129+
* the following conditions are aheared to. The following conditions
130+
* apply to all code found in this distribution, be it the RC4, RSA,
131+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
132+
* included with this distribution is covered by the same copyright terms
133+
* except that the holder is Tim Hudson ([email protected]).
134+
*
135+
* Copyright remains Eric Young's, and as such any Copyright notices in
136+
* the code are not to be removed.
137+
* If this package is used in a product, Eric Young should be given attribution
138+
* as the author of the parts of the library used.
139+
* This can be in the form of a textual message at program startup or
140+
* in documentation (online or textual) provided with the package.
141+
*
142+
* Redistribution and use in source and binary forms, with or without
143+
* modification, are permitted provided that the following conditions
144+
* are met:
145+
* 1. Redistributions of source code must retain the copyright
146+
* notice, this list of conditions and the following disclaimer.
147+
* 2. Redistributions in binary form must reproduce the above copyright
148+
* notice, this list of conditions and the following disclaimer in the
149+
* documentation and/or other materials provided with the distribution.
150+
* 3. All advertising materials mentioning features or use of this software
151+
* must display the following acknowledgement:
152+
* "This product includes cryptographic software written by
153+
* Eric Young ([email protected])"
154+
* The word 'cryptographic' can be left out if the rouines from the library
155+
* being used are not cryptographic related :-).
156+
* 4. If you include any Windows specific code (or a derivative thereof) from
157+
* the apps directory (application code) you must include an acknowledgement:
158+
* "This product includes software written by Tim Hudson ([email protected])"
159+
*
160+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
161+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
163+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
164+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
165+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
166+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
167+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
168+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
169+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
170+
* SUCH DAMAGE.
171+
*
172+
* The licence and distribution terms for any publically available version or
173+
* derivative of this code cannot be changed. i.e. this code cannot simply be
174+
* copied and put under another distribution licence
175+
* [including the GNU Public Licence.]
176+
*/
177+
EOF
178+
}
179+
180+
# This is where all the action happens. Since OpenSSL is so huge and building it
181+
# properly is so painful to setup, "pod install" will download prebuilt binaries
182+
# that we publish elsewhere (not in the git repo with the build script code).
183+
s.prepare_command = <<-EOF
184+
(
185+
echo "#{iPhone_archive_name} #{iPhone_archive_hash}"
186+
echo "#{macOSX_archive_name} #{macOSX_archive_hash}"
187+
) | while read name hash
188+
do
189+
echo "Downloading $name..."
190+
curl --location --output "$name" \
191+
"#{github_repo}/releases/download/v#{openssl_version}/$name"
192+
echo "Verifying $name..."
193+
if [[ "$(shasum -a 256 "$name" | awk '{print $1}')" != "$hash" ]]
194+
then
195+
echo "Checksum mismatch for $name"
196+
exit 1
197+
fi
198+
echo "Unpacking $name..."
199+
unzip "$name"
200+
rm "$name"
201+
mkdir -p "$name"
202+
mv openssl.framework "$name"
203+
done
204+
EOF
205+
206+
# Set the minimum platform versions. We just know the right ones from the
207+
# prebuilt frameworks we download.
208+
s.ios.deployment_target = min_target_ios
209+
s.osx.deployment_target = min_target_osx
210+
211+
# These are prebuilt frameworks that will be vendored into the final app.
212+
s.ios.vendored_frameworks = "#{iPhone_archive_name}/openssl.framework"
213+
s.osx.vendored_frameworks = "#{macOSX_archive_name}/openssl.framework"
214+
end

scripts/update-specs.sh

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,29 @@
99
# Environment variables:
1010
#
1111
# OUTPUT output directory (default: output)
12+
# MIN_IOS_SDK minimum iOS SDK version (default: 8.0)
13+
# MIN_OSX_SDK minimum macOS SDK version (default: 10.9)
1214

1315
set -eu
1416

1517
OUTPUT=${OUTPUT:-output}
18+
MIN_IOS_SDK=${MIN_IOS_SDK:-8.0}
19+
MIN_OSX_SDK=${MIN_OSX_SDK:-10.9}
20+
21+
# GitHub repository where build script and binaries are hosted
22+
GITHUB_REPO="https://github.com/cossacklabs/openssl-apple"
23+
24+
# Output framework archive names
25+
IPHONE_STATIC_NAME="openssl-static-iPhone.zip"
26+
MACOSX_STATIC_NAME="openssl-static-MacOSX.zip"
27+
IPHONE_DYNAMIC_NAME="openssl-dynamic-iPhone.zip"
28+
MACOSX_DYNAMIC_NAME="openssl-dynamic-MacOSX.zip"
29+
OUTPUT_ARCHIVES=(
30+
"$IPHONE_STATIC_NAME"
31+
"$MACOSX_STATIC_NAME"
32+
"$IPHONE_DYNAMIC_NAME"
33+
"$MACOSX_DYNAMIC_NAME"
34+
)
1635

1736
die() {
1837
echo 2>&1 "$@"
@@ -27,19 +46,35 @@ fi
2746
version="$(cat "$OUTPUT/version")"
2847

2948
# Carthage
30-
for package in "$OUTPUT"/openssl-*.zip
49+
for package in "${OUTPUT_ARCHIVES[@]}"
3150
do
32-
package="$(basename "$package")"
3351
spec="carthage/${package%%.zip}.json"
3452
if grep -q "\"$version\"" "$spec"
3553
then
3654
echo "OpenSSL $version is already present in $spec"
3755
else
3856
(
3957
head -1 "$spec" 2> /dev/null || echo "{"
40-
echo " \"$version\": \"https://github.com/cossacklabs/openssl-apple/releases/download/v$version/$package\","
58+
echo " \"$version\": \"$GITHUB_REPO/releases/download/v$version/$package\","
4159
tail +2 "$spec" 2> /dev/null || echo "}"
4260
) > "$OUTPUT/tmp.spec"
4361
mv "$OUTPUT/tmp.spec" "$spec"
4462
fi
4563
done
64+
echo "Updated carthage/*.json"
65+
echo
66+
67+
# Unfortuntely, CocoaPods does not support static frameworks very well
68+
# so we provide only dynamic flavor of the Podspec.
69+
podspec="cocoapods/CLOpenSSL.podspec"
70+
sed -e "s/%%OPENSSL_VERSION%%/$version/g" \
71+
-e "s!%%GITHUB_REPO%%!$GITHUB_REPO!g" \
72+
-e "s/%%MIN_IOS_SDK%%/$MIN_IOS_SDK/g" \
73+
-e "s/%%MIN_OSX_SDK%%/$MIN_OSX_SDK/g" \
74+
-e "s/%%IPHONE_ARCHIVE_NAME%%/$IPHONE_DYNAMIC_NAME/g" \
75+
-e "s/%%IPHONE_ARCHIVE_HASH%%/$(shasum -a 256 "$OUTPUT/$IPHONE_DYNAMIC_NAME" | awk '{print $1}')/g" \
76+
-e "s/%%MACOSX_ARCHIVE_NAME%%/$MACOSX_DYNAMIC_NAME/g" \
77+
-e "s/%%MACOSX_ARCHIVE_HASH%%/$(shasum -a 256 "$OUTPUT/$MACOSX_DYNAMIC_NAME" | awk '{print $1}')/g" \
78+
$podspec.template > $podspec
79+
echo "Updated $podspec"
80+
echo

0 commit comments

Comments
 (0)