Skip to content

Commit 60ed3b9

Browse files
Merge pull request #316 from cconlon/androidUpdate
Update Android Studio example projects
2 parents 788202c + feb6477 commit 60ed3b9

14 files changed

Lines changed: 142 additions & 96 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ contains a Makefile as well as a simple tutorial on the given topic.
1111
## Current Examples
1212

1313

14-
#### android (Android NDK Examples)
14+
#### android (Android Studio and NDK Examples)
1515

16-
This directory contains examples that demonstrate using wolfSSL and wolfSSLJNI
17-
on the Android platform, using the Android NDK toolchain.
16+
This directory contains examples that demonstrate using wolfSSL,
17+
wolfSSL JNI/JSSE, and wolfCrypt JNI/JCE on the Android platform. Examples
18+
use either Android Studio with Gradle or the Android NDK standalone toolchain.
1819

1920
Please see the [android/README.md](android/README.md) for further usage and
2021
details.

android/README.md

Lines changed: 83 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,99 @@
1-
# wolfSSL / wolfSSL JNI Android Examples
1+
# wolfSSL JNI/JSSE and wolfCrypt JNI/JCE Android Examples
22

3-
This directory contains:
3+
This directory contains two Android Studio projects that demonstrate how
4+
wolfCrypt JNI/JCE and wolfSSL JNI/JSSE can be integrated into an
5+
Android Studio project using the Gradle build system to compile both
6+
shared libraries and the application.
47

5-
**wolfssljni-ndk-sample** - Example project that demonstrates how to integrate
6-
wolfSSL and wolfSSL JNI into an Android NDK application's Android.mk build
7-
file.
8+
[wolfcryptjni-ndk-gradle](./wolfcryptjni-ndk-gradle)
89

9-
**wolfssljni-ndk-gradle** - Example project that demonstrates how to integrate
10-
wolfSSL and wolfSSL JNI into an Android Studio NDK application using the
11-
Gradle build system to compile both shared libraries and the application.
10+
[wolfssljni-ndk-gradle](./wolfssljni-ndk-gradle)
11+
12+
This directory also contains one older example of how wolfSSL JNI/JSSE
13+
could be integrated into an older standalone NDK toolchain project's Android.mk
14+
build file. The above Android Studio projects are the recommended approach
15+
unless using an older standalone NDK toolchain setup.
16+
17+
[wolfssljni-ndk-sample](./wolfssljni-ndk-sample)
18+
19+
wolfSSL also maintains an Android Studio example project that is shipped
20+
as part of the wolfSSL JNI/JSSE bundle. This example project is set up to
21+
run the wolfSSL JNI/JSSE tests on an emulator as well, and is located here:
22+
23+
[wolfSSL JNI/JSSE IDE/Android Example](https://github.com/wolfSSL/wolfssljni/tree/master/IDE/Android)
24+
25+
## wolfSSL Android Studio NDK Gradle Examples
26+
27+
### Prerequisites for successful installation
28+
29+
In order to build the wolfSSL JNI/JSSE or wolfCrypt JNI/JCE Android Studio
30+
sample applications you need to Install **Android Studio**,
31+
along with **Android NDK** support.
32+
33+
### Compiling and Running wolfssljni-ndk-gradle or wolfcryptjni-ndk-gradle
34+
35+
After a development environment has been set up, follow these instructions
36+
to compile and install either the wolfSSL JNI/JSSE + wolfSSL bundle, or the
37+
wolfCrypt JNI/JCE + wolfSSL bundle on the Emulator:
38+
39+
1) Change directories into the android/wolfssljni-ndk-gradle directory
40+
41+
2) Checkout wolfssl and wolfssljni git submodules
42+
43+
3) Create stub options.h (since we're using the GitHub repo for wolfSSL)
44+
45+
4) Open "wolfssljni-ndk-gradle" project in Android Studio and build project
46+
47+
```
48+
$ cd android/wolfssljni-ndk-gradle
49+
$ git submodule init
50+
$ git submodule update
51+
$ cp ./wolfssl/wolfssl/options.h.in ./wolfssl/wolfssl/options.h
52+
```
53+
54+
wolfSSL stable releases, available from the wolfSSL download page, contain
55+
<wolfssl/options.h>, but the GitHub development branch for wolfSSL does not.
56+
This is why options.h.in needs to be copied to options.h above.
57+
58+
If you would like to update the git submodules for wolfssl and wolfssljni to
59+
the most current development HEAD, use the following submodule update command
60+
in place of the one above:
61+
62+
```
63+
$ git submodule update --remote
64+
```
65+
66+
Or, to use a specific tag or commit, use `git checkout`:
67+
68+
```
69+
$ cd android/wolfssljni-ndk-gradle/wolfssl
70+
$ git checkout vX.X.X-stable
71+
```
72+
73+
To install and run the application in an Android emulator, set one up
74+
in Android Studio, then click the Debug application button on the Android
75+
Studio toolbar. This will allow you to choose what Android virtual machine
76+
you would like to use.
77+
78+
Logcat output from the emulator can be viewed by opening a new terminal window
79+
while the emulator is running and issuing:
80+
81+
```
82+
$ adb logcat
83+
```
1284

1385
## wolfSSL NDK Standalone Toolchain Example
1486

1587
### Prerequisites for successful installation
1688

17-
Prerequisites
18-
In order to build the wolfSSL JNI sample application,
19-
you need to:
89+
In order to build the wolfSSL JNI sample application, you need to:
90+
2091
* Install the `Android SDK` [link](http://developer.android.com/sdk/index.html)
2192
* Install the `Android NDK` [link](https://developer.android.com/tools/sdk/ndk/index.html)
2293

2394
Note that these instructions do not use the Android Studio IDE and environment.
2495
This package has been developed and tested using the Android NDK and SDK
25-
command line tools.
96+
command line tools only.
2697

2798
After installing the Android SDK, run the `SDK Tools` app packaged with it and
2899
install Android 4.4:
@@ -126,60 +197,6 @@ After compilation:
126197
on the phone, as described above for the emulator - using
127198
"adb debug install".
128199

129-
## wolfSSL Android Studio NDK Gradle Example
130-
131-
### Prerequisites for successful installation
132-
133-
Prerequisites
134-
In order to build the wolfSSL JNI Android Studio sample application,
135-
you need to:
136-
* Install Android Studio, along with Android NDK support
137-
138-
### Compiling and Running the wolfssljni-ndk-gradle or wolfcryptjni-ndk-gradle
139-
140-
After the development environment has been set up, follow these instructions
141-
to compile and install either the wolfSSL JNI + wolfSSL bundle, or the
142-
wolfCrypt JNI + wolfSSL bundle on the Emulator:
143-
144-
1) Change directories into the android/wolfssljni-ndk-sample directory
145-
146-
2) Checkout wolfssl and wolfssljni git submodules
147-
148-
3) Create stub options.h (since we're using the GitHub repo for wolfSSL)
149-
150-
4) Open "wolfssljni-ndk-gradle" project in Android Studio and build project
151-
152-
```
153-
$ cd android/wolfssljni-ndk-gradle
154-
$ git submodule init
155-
$ git submodule update
156-
$ cp ./wolfssl/wolfssl/options.h.in ./wolfssl/wolfssl/options.h
157-
```
158-
159-
wolfSSL stable releases, available from the wolfSSL download page, contain
160-
<wolfssl/options.h>, but the GitHub development branch for wolfSSL does not.
161-
This is why options.h.in needs to be copied to options.h above.
162-
163-
If you would like to update the git submodules for wolfssl and wolfssljni to
164-
the most current development HEAD, use the following submodule update command
165-
in place of the one above:
166-
167-
```
168-
$ git submodule update --remote
169-
```
170-
171-
To install and run the application in an Android emulator, set one up
172-
in Android Studio, then click the Debug application button on the Android
173-
Studio toolbar. This will allow you to choose what Android virtual machine
174-
you would like to use.
175-
176-
Logcat output from the emulator can be viewed by opening a new terminal window
177-
while the emulator is running and issuing:
178-
179-
```
180-
$ adb logcat
181-
```
182-
183200
## Support
184201

185202
Please contact wolfSSL at support@wolfssl.com with any questions, bug fixes,

android/wolfcryptjni-ndk-gradle/app/CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
# Sets the minimum version of CMake required to build the native library.
55

66
cmake_minimum_required(VERSION 3.4.1)
7+
project("wolfcryptjni-ndk-gradle")
78

8-
# Add preprocessor defines to CFLAGS
9-
add_definitions(-DNO_DSA -DNO_PSK -DNO_MD4 -DNO_HC128 -DNO_RABBIT
10-
-DWOLFSSL_SHA512 -DWOLFSSL_SHA384 -DHAVE_AESGCM -DHAVE_HASHDRBG
11-
-DHAVE_ECC -DWOLFSSL_KEY_GEN -DNO_PWDBASED -DUSE_FAST_MATH
12-
-DTFM_ECC256 -DHAVE_DH -DUSE_FAST_MATH -DTFM_TIMING_RESISTANT
13-
-DECC_TIMING_RESISTANT -DWC_RSA_BLINDING -DTFM_NO_ASM
14-
)
9+
# Add preprocessor defines to CFLAGS. These mirror the CFLAGS set in
10+
# wolfssl/options.h if using './configure --enable-keygen'
11+
add_definitions(-DUSE_FAST_MATH -DTFM_TIMING_RESISTANT -DECC_TIMING_RESISTANT
12+
-DWC_RSA_BLINDING -DWOLFSSL_SHA224 -DWOLFSSL_SHA384
13+
-DWOLFSSL_SHA512 -DHAVE_HKDF -DNO_DSA -DHAVE_ECC -DTFM_ECC256
14+
-DECC_SHAMIR -DWC_RSA_PSS -DWOLFSSL_BASE64_ENCODE -DWOLFSSL_SHA3
15+
-DHAVE_POLY1305 -DHAVE_CHACHA -DHAVE_HASHDRBG
16+
-DHAVE_TLS_EXTENSIONS -DHAVE_SUPPORTED_CURVES -DHAVE_FFDHE_2048
17+
-DWOLFSSL_TLS13 -DHAVE_EXTENDED_MASTER -DNO_RC4 -DNO_MD4
18+
-DHAVE_ENCRYPT_THEN_MAC -DNO_PSK -DHAVE_DH_DEFAULT_PARAMS
19+
-DWOLFSSL_KEY_GEN -DNO_DES3 -DGCM_TABLE_4BIT -DHAVE_AESGCM
20+
-DTFM_NO_ASM)
1521

1622
# set wolfSSL JNI location as environment variable, change if needed
1723
set(wolfcryptjni_DIR ${CMAKE_SOURCE_DIR}/../wolfcrypt-jni)
@@ -52,6 +58,7 @@ add_library(wolfssl SHARED
5258
${wolfssl_DIR}/wolfcrypt/src/hash.c
5359
${wolfssl_DIR}/wolfcrypt/src/hmac.c
5460
${wolfssl_DIR}/wolfcrypt/src/integer.c
61+
${wolfssl_DIR}/wolfcrypt/src/kdf.c
5562
${wolfssl_DIR}/wolfcrypt/src/logging.c
5663
${wolfssl_DIR}/wolfcrypt/src/md2.c
5764
${wolfssl_DIR}/wolfcrypt/src/md4.c
@@ -99,6 +106,7 @@ add_library(wolfcryptjni SHARED
99106
${wolfcryptjni_DIR}/jni/jni_ecc.c
100107
${wolfcryptjni_DIR}/jni/jni_ed25519.c
101108
${wolfcryptjni_DIR}/jni/jni_error.c
109+
${wolfcryptjni_DIR}/jni/jni_feature_detect.c
102110
${wolfcryptjni_DIR}/jni/jni_fips.c
103111
${wolfcryptjni_DIR}/jni/jni_hmac.c
104112
${wolfcryptjni_DIR}/jni/jni_logging.c
@@ -107,6 +115,7 @@ add_library(wolfcryptjni SHARED
107115
${wolfcryptjni_DIR}/jni/jni_rng.c
108116
${wolfcryptjni_DIR}/jni/jni_rsa.c
109117
${wolfcryptjni_DIR}/jni/jni_sha.c
118+
${wolfcryptjni_DIR}/jni/jni_wolfobject.c
110119
)
111120

112121
# Include libraries needed for wolfSSL and wolfCrypt JNI libs

android/wolfcryptjni-ndk-gradle/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.4.1'
9+
classpath 'com.android.tools.build:gradle:7.2.0'
1010

1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Jul 03 11:55:41 PDT 2019
1+
#Mon May 23 14:17:29 MDT 2022
22
distributionBase=GRADLE_USER_HOME
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
34
distributionPath=wrapper/dists
4-
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
6+
zipStoreBase=GRADLE_USER_HOME
Submodule wolfcrypt-jni updated 114 files
Submodule wolfssl updated 1795 files

android/wolfssljni-ndk-gradle/app/CMakeLists.txt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,31 @@
44
# Sets the minimum version of CMake required to build the native library.
55

66
cmake_minimum_required(VERSION 3.4.1)
7+
project("wolfssljni-ndk-gradle")
78

8-
# Add preprocessor defines to CFLAGS
9-
add_definitions(-DWOLFSSL_JNI -DWOLFSSL_DTLS -DOPENSSL_EXTRA -DHAVE_CRL -DHAVE_CRL_MONITOR
10-
-DHAVE_OCSP -DPERSIST_SESSION_CACHE -DPERSIST_CERT_CACHE -DATOMIC_USER
11-
-DHAVE_ECC -DTFM_ECC256 -DHAVE_PK_CALLBACKS -DHAVE_DH -DUSE_FAST_MATH
12-
-DTFM_TIMING_RESISTANT -DECC_TIMING_RESISTANT -DWC_RSA_BLINDING -DTFM_NO_ASM
13-
)
9+
# Add preprocessor defines to CFLAGS, these match those placed into
10+
# wolfssl/options.h by configure if using: "./configure --enable-jni".
11+
# This list may be configurable depending on use case.
12+
add_definitions(-DUSE_FAST_MATH -DTFM_TIMING_RESISTANT -DECC_TIMING_RESISTANT
13+
-DWC_RSA_BLINDING -DWOLFSSL_SHA224 -DWOLFSSL_SHA384
14+
-DWOLFSSL_SHA512 -DHAVE_HKDF -DNO_DSA -DHAVE_ECC -DTFM_ECC256
15+
-DECC_SHAMIR -DWC_RSA_PSS -DWOLFSSL_BASE64_ENCODE
16+
-DWOLFSSL_SHA3 -DHAVE_POLY1305 -DHAVE_CHACHA -DHAVE_HASHDRBG
17+
-DHAVE_TLS_EXTENSIONS -DHAVE_SUPPORTED_CURVES -DHAVE_FFDHE_2048
18+
-DWOLFSSL_TLS13 -DHAVE_EXTENDED_MASTER -DWOLFSSL_JNI
19+
-DHAVE_EX_DATA -DWOLFSSL_DTLS -DOPENSSL_EXTRA -DOPENSSL_ALL
20+
-DHAVE_CRL -DHAVE_OCSP -DHAVE_CRL_MONITOR
21+
-DPERSIST_SESSION_CACHE -DPERSIST_CERT_CACHE -DATOMIC_USER
22+
-DHAVE_PK_CALLBACKS -DWOLFSSL_CERT_EXT -DWOLFSSL_CERT_GEN
23+
-DHAVE_SNI -DHAVE_ALPN -DNO_RC4 -DHAVE_ENCRYPT_THEN_MAC
24+
-DNO_MD4 -DWOLFSSL_ENCRYPTED_KEYS -DHAVE_DH_DEFAULT_PARAMS
25+
-DNO_ERROR_QUEUE -DWOLFSSL_EITHER_SIDE -DWC_RSA_NO_PADDING
26+
-DWC_RSA_PSS -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_TICKET_HAVE_ID
27+
-DWOLFSSL_ERROR_CODE_OPENSSL -DWOLFSSL_ALWAYS_VERIFY_CB
28+
-DWOLFSSL_VERIFY_CB_ALL_CERTS -DWOLFSSL_EXTRA_ALERTS
29+
-DHAVE_EXT_CACHE -DWOLFSSL_FORCE_CACHE_ON_TICKET
30+
-DWOLFSSL_AKID_NAME -DHAVE_CTS -DNO_DES3 -DGCM_TABLE_4BIT
31+
-DHAVE_AESGCM -DSIZEOF_LONG=4 -DSIZEOF_LONG_LONG=8 -DTFM_NO_ASM)
1432

1533
# set wolfSSL JNI location as environment variable, change if needed
1634
set(wolfssljni_DIR ${CMAKE_SOURCE_DIR}/../wolfssljni)
@@ -51,6 +69,7 @@ add_library(wolfssl SHARED
5169
${wolfssl_DIR}/wolfcrypt/src/hash.c
5270
${wolfssl_DIR}/wolfcrypt/src/hmac.c
5371
${wolfssl_DIR}/wolfcrypt/src/integer.c
72+
${wolfssl_DIR}/wolfcrypt/src/kdf.c
5473
${wolfssl_DIR}/wolfcrypt/src/logging.c
5574
${wolfssl_DIR}/wolfcrypt/src/md2.c
5675
${wolfssl_DIR}/wolfcrypt/src/md4.c

android/wolfssljni-ndk-gradle/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ android {
3131
// wolfSSL JNI Java source files are added here
3232
main.java.srcDirs += '../wolfssljni/src/java'
3333
}
34+
namespace 'com.wolfssl.wolfssljni_ndk_gradle'
3435
}
3536

3637
dependencies {

android/wolfssljni-ndk-gradle/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.wolfssl.wolfssljni_ndk_gradle">
3+
xmlns:tools="http://schemas.android.com/tools">
54

65
<application
76
android:allowBackup="false"

0 commit comments

Comments
 (0)