Skip to content

Commit 98e84d2

Browse files
committed
Add OpenSSL and libcurl libraries
Enables support for NSURLSession in GNUstep Base.
1 parent 730551c commit 98e84d2

5 files changed

Lines changed: 151 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The toolchain is built using the Android NDK (installed e.g. via [Android Studio
1111
Libraries
1212
---------
1313

14-
The toolchain currently compiles the following libraries for Android:
14+
The toolchain consists of the following libraries:
1515

1616
* [GNUstep Base Library](https://github.com/gnustep/libs-base) (Foundation)
1717
* [GNUstep CoreBase Library](https://github.com/gnustep/libs-corebase) (CoreFoundation)
@@ -21,6 +21,8 @@ The toolchain currently compiles the following libraries for Android:
2121
* [libiconv](https://www.gnu.org/software/libiconv/)
2222
* [libxml2](https://github.com/GNOME/libxml2)
2323
* [libxslt](https://github.com/GNOME/libxslt)
24+
* [libcurl](https://github.com/curl/curl)
25+
* [OpenSSL](https://github.com/KDAB/android_openssl)
2426
* [ICU](https://github.com/unicode-org/icu)
2527

2628

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/Source/GSEasyHandle.m b/Source/GSEasyHandle.m
2+
index 576a41205..7eb15d512 100644
3+
--- a/Source/GSEasyHandle.m
4+
+++ b/Source/GSEasyHandle.m
5+
@@ -173,6 +173,24 @@ @implementation GSEasyHandle
6+
struct curl_slist *_headerList;
7+
}
8+
9+
+#ifdef __ANDROID__
10+
+static NSData *CABundleData() {
11+
+ static NSData *result = nil;
12+
+ static dispatch_once_t predicate;
13+
+
14+
+ dispatch_once(&predicate, ^{
15+
+ NSString *caBundlePath = [[NSBundle mainBundle] pathForResource:@"cacert" ofType:@"pem"];
16+
+ if (caBundlePath) {
17+
+ result = [[NSData alloc] initWithContentsOfFile:caBundlePath];
18+
+ } else {
19+
+ NSLog(@"Warning: missing CA bundle path (cacert.pem) in app bundle");
20+
+ }
21+
+ });
22+
+
23+
+ return result;
24+
+}
25+
+#endif
26+
+
27+
- (instancetype) initWithDelegate: (id<GSEasyHandleDelegate>)delegate
28+
{
29+
if (nil != (self = [super init]))
30+
@@ -184,6 +202,18 @@ - (instancetype) initWithDelegate: (id<GSEasyHandleDelegate>)delegate
31+
_errorBuffer = memset(eb, 0, sizeof(char) * (CURL_ERROR_SIZE + 1));
32+
33+
[self setupCallbacks];
34+
+
35+
+#ifdef __ANDROID__
36+
+ // set CA certificate store (must be stored in app bundle)
37+
+ NSData *caBundleData = CABundleData();
38+
+ if (caBundleData) {
39+
+ struct curl_blob blob;
40+
+ blob.data = (void *)caBundleData.bytes;
41+
+ blob.len = caBundleData.length;
42+
+ blob.flags = CURL_BLOB_COPY;
43+
+ handleEasyCode(curl_easy_setopt(_rawHandle, CURLOPT_CAINFO_BLOB, &blob));
44+
+ }
45+
+#endif
46+
}
47+
48+
return self;

phases/18-openssl.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
set -e # make any subsequent failing command exit the script
4+
5+
. `dirname $0`/../scripts/common.sh
6+
7+
PROJECT=openssl
8+
GITHUB_REPO=KDAB/android_openssl
9+
10+
# load environment and prepare project
11+
if ! prepare_project $PROJECT $GITHUB_REPO; then
12+
exit 0
13+
fi
14+
15+
case $ABI_NAME in
16+
armeabi-v7a)
17+
ABI_FOLDER=arm
18+
;;
19+
arm64-v8a)
20+
ABI_FOLDER=arm64
21+
;;
22+
*)
23+
ABI_FOLDER=$ABI_NAME
24+
esac
25+
26+
echo -e "\n### Installing headers"
27+
28+
cp -Rf no-asm/static/include/ ${INSTALL_PREFIX}/include
29+
30+
echo -e "\n### Installing libraries"
31+
32+
cp -f latest/$ABI_FOLDER/*.so ${INSTALL_PREFIX}/lib
33+
34+
# create version-less symlinks for libcrypto/libssl.so to versioned libraries
35+
libraries=`ls latest/$ABI_FOLDER/*.so`
36+
cd ${INSTALL_PREFIX}/lib
37+
for lib in $libraries; do
38+
libname=`basename $lib`
39+
if [[ $libname =~ ([a-z]+)[0-9\_]+.so ]]; then
40+
ln -sf $libname ${BASH_REMATCH[1]}.so
41+
fi
42+
done
43+
44+
echo -e "\n### Downloading CA bundle (must be installed into Android app bundle)"
45+
mkdir -p "$CACHE_ROOT"
46+
cd "$CACHE_ROOT"
47+
ETAG="cacert-etag.txt"
48+
[ -f $ETAG ] && ETAG_COMPARE="--etag-compare $ETAG"
49+
curl --show-error --fail-with-body --remote-name --etag-save $ETAG $ETAG_COMPARE https://curl.se/ca/cacert.pem
50+
mkdir -p ${INSTALL_PREFIX}/etc/ssl/
51+
cp -f cacert.pem ${INSTALL_PREFIX}/etc/ssl/

phases/19-libcurl.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e # make any subsequent failing command exit the script
4+
5+
. `dirname $0`/../scripts/common.sh
6+
7+
PROJECT=libcurl
8+
GITHUB_REPO=curl/curl
9+
TAG=$(get_latest_github_release_tag $GITHUB_REPO curl-)
10+
11+
# load environment and prepare project
12+
if ! prepare_project $PROJECT $GITHUB_REPO $TAG; then
13+
exit 0
14+
fi
15+
16+
. "$ROOT_DIR"/scripts/toolchain.sh
17+
18+
echo -e "\n### Running cmake"
19+
mkdir -p build-${ABI_NAME}
20+
cd build-${ABI_NAME}
21+
22+
${CMAKE} .. \
23+
${CMAKE_OPTIONS} \
24+
-DBUILD_SHARED_LIBS=YES \
25+
-DBUILD_CURL_EXE=NO \
26+
-DCURL_CA_BUNDLE=NONE `# disable CA bundle path, needs to be read at runtime from app bundle` \
27+
-DCMAKE_FIND_ROOT_PATH=${INSTALL_PREFIX} `# make CMake look for OpenSSL in installation directory` \
28+
29+
echo -e "\n### Building"
30+
make -j${MAKE_JOBS}
31+
32+
echo -e "\n### Installing"
33+
make install

scripts/common.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,24 @@ export ROOT_DIR="$PWD"
1010

1111
get_latest_github_release_tag () {
1212
GITHUB_REPO=$1
13+
TAG_PREFIX=$2
14+
15+
# use GitHub token authentication on CI to prevent rate limit errors
16+
if [ -n "$GITHUB_TOKEN" ]; then
17+
GITHUB_AUTHORIZATION_HEADER="Authorization: Bearer $GITHUB_TOKEN"
18+
fi
19+
20+
# get the tags JSON from the GitHub API and parse it manually,
21+
# or output it to stderr if the server returns an error
22+
github_tags=`curl \
23+
--silent --show-error --fail-with-body \
24+
--header "$GITHUB_AUTHORIZATION_HEADER" \
25+
https://api.github.com/repos/$GITHUB_REPO/tags`
1326

14-
# get the tags JSON from the GitHub API and parse it manually
15-
curl -s https://api.github.com/repos/$GITHUB_REPO/tags \
27+
echo "$github_tags" \
1628
| grep '"name":' \
1729
| sed -E 's/.*"([^"]+)".*/\1/' \
18-
| egrep '^(release\-|v)[0-9]+[\.-][0-9]+([\.-][0-9]+)?$' \
30+
| egrep "^${TAG_PREFIX:-[a-z_-]+}[0-9]+[\._-][0-9]+([\._-][0-9]+)?\$" \
1931
| head -n 1
2032
}
2133

@@ -73,7 +85,7 @@ prepare_project () {
7385
if [ "$NO_UPDATE" != true ]; then
7486
# check out tag/branch if any
7587
if [ -n $TAG ]; then
76-
echo -e "\n### Checking out $TAG"
88+
echo -e "\n### Checking out \"$TAG\""
7789
git fetch --tags
7890
git checkout -q $TAG
7991
fi

0 commit comments

Comments
 (0)