Skip to content

Commit 9d0587d

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

4 files changed

Lines changed: 135 additions & 1 deletion

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

phases/19-libcurl.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
10+
# load environment and prepare project
11+
if ! prepare_project $PROJECT $GITHUB_REPO; then
12+
exit 0
13+
fi
14+
15+
. "$ROOT_DIR"/scripts/toolchain.sh
16+
17+
echo -e "\n### Running cmake"
18+
mkdir -p build-${ABI_NAME}
19+
cd build-${ABI_NAME}
20+
21+
${CMAKE} .. \
22+
${CMAKE_OPTIONS} \
23+
-DBUILD_SHARED_LIBS=YES \
24+
-DBUILD_CURL_EXE=NO \
25+
-DCURL_CA_BUNDLE=NONE `# disable CA bundle path, needs to be read at runtime from app bundle` \
26+
-DCMAKE_FIND_ROOT_PATH=${INSTALL_PREFIX} `# make CMake look for OpenSSL in installation directory` \
27+
28+
echo -e "\n### Building"
29+
make -j${MAKE_JOBS}
30+
31+
echo -e "\n### Installing"
32+
make install

0 commit comments

Comments
 (0)