You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wolfSSL-JNI/src/chapter01.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,9 @@
1
1
# Introduction
2
2
3
+
wolfSSL JNI/JSSE is a provider implementation of the Java Secure Socket Extension. It also includes a thin JNI wrapper around the native wolfSSL SSL/TLS library.
4
+
3
5
The Java Secure Socket Extension ( **JSSE** ) framework supports the installation of security providers. These providers can implement a subset of the functionality used by the Java JSSE security APIs, including SSL/TLS.
4
6
5
-
This document describes wolfSSL’s JSSE provider implementation, named “ **wolfJSSE** ”. wolfJSSE wraps the native wolfSSL SSL/TLS library, providing Java users the opportunity to take advantage of wolfSSL’s progressive features, performance, and resource optimizations. This interface gives Java applications access to all the benefits of using wolfSSL, including current SSL/TLS standards up to [TLS 1.3](https://www.wolfssl.com/tls13), [FIPS 140-2 and 140-3](https://www.wolfssl.com/license/fips/) support, performance optimizations, hardware cryptography support, [commercial support](https://www.wolfssl.com/products/support-and-maintenance/), and more!
7
+
This document describes wolfSSL’s JSSE provider implementation, named “ **wolfJSSE** ”. wolfJSSE wraps the native wolfSSL SSL/TLS library. This interface gives Java applications access to all the benefits of using wolfSSL, including current SSL/TLS standards up to [TLS 1.3](https://www.wolfssl.com/tls13), [FIPS 140-2 and 140-3](https://www.wolfssl.com/license/fips/) support, performance optimizations, hardware cryptography support, [commercial support](https://www.wolfssl.com/products/support-and-maintenance/), and more!
6
8
7
9
wolfJSSE is distributed as part of the “ **wolfssljni** ”package. This package includes both a thin JNI wrapper for wolfSSL and the wolfJSSE provider.
Copy file name to clipboardExpand all lines: wolfSSL-JNI/src/chapter02.md
+38-21Lines changed: 38 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,62 +2,79 @@
2
2
3
3
## Java / JDK
4
4
5
-
wolfJSSE requires Java to be installed on the host system. There are several JDK variants available to users and developers - including the Oracle JDK, OpenJDK, Zulu JDK, and Android.
5
+
wolfJSSE requires Java to be installed on the host system. There are several
6
+
JDK variants available to users and developers. wolfSSL JNI/JSSE has been tested
7
+
on the following:
8
+
9
+
- Unix/Linux:
10
+
+ Oracle JDK
11
+
+ OpenJDK
12
+
+ Zulu JDK
13
+
+ Amazon Coretto
14
+
- Android
15
+
16
+
The build system for wolfSSL JNI/JSSE has not been set up to run on Microsoft
17
+
Windows yet. If this is something you are interested in, contact wolfSSL at
project included, under `IDE/Android` has been tested on both Linux and Windows.
6
20
7
21
## JUnit
8
22
9
-
In order to run the unit tests, JUnit is required to be installed on the development system. JUnit can be downloaded from the project website at [www.junit.org]().
23
+
In order to run the unit tests, JUnit 4 is required to be installed on the
24
+
development system. JUnit can be downloaded from the project website at
25
+
[www.junit.org]().
10
26
11
27
To install JUnit on a Unix/Linux/OSX system:
12
28
13
-
1. Download “ **junit-4.13.jar** ” and “ **hamcrest-all-1.3.jar** ”from [junit.org/junit4/](). At the time of writing, the above mentioned .jar files could be downloaded from the following links:
29
+
1) Download “ **junit-4.13.2.jar** ” and “ **hamcrest-all-1.3.jar** ”from [junit.org/junit4/](). At the time of writing, the above mentioned .jar files could be downloaded from the following links:
2. Place these JAR files on your system and set **JUNIT_HOME** to point to that location. Ex:
34
+
2) Place these JAR files on your system and set **JUNIT_HOME** to point to that location. Ex:
19
35
20
36
```
21
37
$ export JUNIT_HOME=/path/to/jar/files
22
38
```
23
-
## gcc and ant
24
39
25
-
Both “ gcc ” and “ ant ” are used to compile native Ccode and Java code, respectively. Please ensure that these are installed on your development machine.
40
+
## System Dependencies (gcc and ant)
26
41
27
-
**Note**: The java.sh script uses a common location for the Java install location. If your Java install location is different, this could lead to an error when running java.sh. In this case, you should modify java.sh to match your environment.
42
+
**gcc** and **ant** are used to compile native C code and Java code, respectively. Please ensure that these are installed on your development machine.
28
43
29
-
Build targets for ant are :
30
-
- ant build (only builds the jar necessary for an app to use)
31
-
- ant test (builds the jar and tests then runs the tests, requires JUNIT setup)
32
-
- ant examples (builds the jar and example cases)
33
-
- ant clean (cleans all Java artifacts)
34
-
- ant cleanjni (cleans native artifacts)
44
+
**Note**: The `java.sh` script uses a common location for the Java install location. If your Java install location is different, this could lead to an error when running `java.sh`. In this case, you should modify `java.sh` to match your environment.
35
45
36
-
## wolfSSL Library
46
+
## wolfSSL SSL/TLS Library
37
47
38
-
As a wrapper around the native wolfSSL library, the wolfSSL C library must be installed on the host platform and placed on the include and library search paths.
48
+
As a wrapper around the native wolfSSL library, the [wolfSSL](https://www.wolfssl.com/products/wolfssl/) C library must be installed on the host platform and placed on the include and library search paths before compiling wolfSSL JNI/JSSE.
39
49
40
50
### Compiling wolfSSL and wolfCrypt C Library
41
51
42
-
To compile and install wolfSSL in a Unix/Linux environment for use with wolfJSSE, please follow build instructions in the wolfSSL Manual. The most common way to compile wolfSSL is with the Autoconf system.
52
+
To compile and install wolfSSL in a Unix/Linux environment for use with wolfJSSE, please follow build instructions in the [wolfSSL Manual](https://www.wolfssl.com/documentation/wolfssl-manual/index.html). The most common way to compile wolfSSL is using Autoconf.
53
+
54
+
When using Autoconf to configure wolfSSL, the `--enable-jni` option will need to be used:
43
55
44
-
When using Autoconf to configure wolfSSL, the “ --enable-jni ”option will need to be used:
45
56
```
46
57
$ cd wolfssl-X.X.X
47
58
$ ./configure --enable-jni
48
59
$ make
49
60
```
50
-
Verify “ make check ” passes successfully, then install the library:
61
+
62
+
Verify `make check` passes successfully, then install the library:
63
+
51
64
```
52
65
$ make check
53
66
$ sudo make install
54
67
```
68
+
55
69
This will install the wolfSSL library to your system default installation location. On many platforms this is:
70
+
56
71
```
57
72
/usr/local/lib
58
73
/usr/local/include
59
74
```
60
-
If wolfSSL has installed to a non-standard library installation location, you may need to update LD_LIBRARY_PATH (Unix/Linux) or DYLD_LIBRARY_PATH (OSX):
75
+
76
+
If wolfSSL has been installed to a non-standard library installation location, you may need to update `LD_LIBRARY_PATH` (Unix/Linux) or `DYLD_LIBRARY_PATH` (OSX):
There are three ways to compile wolfJSSE listed in this section, including using the Unix Command Line, Android Studio Build and Generic IDE Build.
3
+
There are three ways to compile wolfJSSE listed in this chapter, including
4
+
using the Unix Command Line, Android Studio Build and Generic IDE Build.
4
5
5
-
## Unix Command Line
6
+
## Unix Command Line
7
+
8
+
Before following steps in this section, please ensure that the dependencies
9
+
listed in Chapter 2 are installed.
10
+
11
+
The `java.sh` script in the root package directory is used to compile the native
12
+
JNI C source files into a shared library for either Unix/Linux or Mac OSX.
13
+
This script tries to auto-detect between OSX (Darwin) and Linux to set up
14
+
include paths and shared library extension type. This script directly calls gcc
15
+
on the JNI C source files, producing `./lib/libwolfssljni.so` or
16
+
`./lib/libwolfssljni.dylib`.
6
17
7
-
Before following steps in this section, please ensure that the dependencies listed in Chapter 1 are installed. The “ java.sh ” script in the root package directory is used to compile the native JNI C source files into a shared library for either Unix/Linux or Mac. This script tries to auto-detect between OSX (Darwin) and Linux to set up include paths and shared library extension type. This script directly calls gcc on the JNI C source files, producing “./lib/libwolfssljni.so” or “./lib/libwolfssljni.dylib”
8
18
```
9
19
$ ./java.sh
10
20
11
21
Compiling Native JNI library:
12
-
WOLFSSL_INSTALL_DIR = /usr/local
13
-
Detected Linux host OS
14
-
Generated ./lib/libwolfssljni.so
22
+
WOLFSSL_INSTALL_DIR = /usr/local
23
+
Detected Linux host OS
24
+
Linux x86_64
25
+
Java Home = /usr/lib/jvm/java-8-openjdk-amd64
26
+
Generated ./lib/libwolfssljni.so
27
+
```
28
+
29
+
If linking against a native wolfSSL library not installed to `/usr/local`, one
30
+
argument may be passed to `java.sh` which represents the wolfSSL installation
31
+
location. For example:
32
+
33
+
```
34
+
$ ./java.sh /path/to/wolfssl/install
15
35
```
16
-
To compile the Java sources, “ ant ” is used:
36
+
37
+
To compile the Java sources, `ant` is used:
38
+
17
39
```
18
40
$ ant
19
41
```
20
-
This will build the wolfJSSE jar and native code necessary to use wolfJSSE in a project. To compile and run tests the command “ ant test ”is used:
42
+
43
+
Available build targets for `ant` are :
44
+
45
+
-`ant` (only builds the jar necessary for an app to use)
46
+
-`ant test` (builds the jar and tests then runs the tests, requires JUNIT setup)
47
+
-`ant examples` (builds the jar and example cases)
48
+
-`ant clean` (cleans all Java artifacts)
49
+
-`ant cleanjni` (cleans native artifacts)
50
+
51
+
These two commands will build the wolfJSSE jar and native code necessary to use
52
+
wolfJSSE in a project. To compile and run JUnit tests the command `ant test`
53
+
is used:
54
+
21
55
```
22
56
$ ant test
23
57
```
24
-
This will compile tests and the main wolfJSSE code and output with the results of the tests will be displayed along with a summary of total tests that passed at the end of the wolfJSSE testsuite and wolfSSL JNI testsuite. A successful build will display the message “BUILD SUCCESSFUL” at the end.
58
+
59
+
This will compile tests and the main wolfJSSE code and output with the results
60
+
of the tests will be displayed along with a summary of total tests that passed
61
+
at the end of the wolfJSSE testsuite and wolfSSL JNI testsuite. A successful
62
+
build will display the message “BUILD SUCCESSFUL” at the end.
25
63
26
64
```
27
65
[junit] WolfSSLTrustX509 Class
@@ -30,35 +68,116 @@ This will compile tests and the main wolfJSSE code and output with the results o
30
68
[junit] Testing parse all.jks ... passed
31
69
[junit] Testing verify ... passed
32
70
...
33
-
...
34
-
...
35
71
36
72
build:
37
73
38
74
BUILD SUCCESSFUL
39
75
Total time: 18 seconds
40
76
```
41
-
To compile and run examples bundled with wolfJSSE the command “ ant examples ” is used:
77
+
78
+
To compile and run examples bundled with wolfJSSE the command `ant examples`
79
+
is used:
80
+
42
81
```
43
82
$ ant examples
44
83
```
45
-
## Android Studio Build
46
84
47
-
An example Android Studio project is located in the directory IDE/Android. To run the example Android Studio project use the following steps;
85
+
## Android Studio Build
86
+
87
+
An example Android Studio project is located in the directory `IDE/Android`.
88
+
This is an example Android Studio project file for wolfssljni / wolfJSSE.
89
+
This project should be used for reference only.
90
+
91
+
More details on tool and version information used when testing can be found in
92
+
the `wolfssljni/IDE/Android/README.md`. The following steps outline what is
93
+
required to run this example on an Android device or emulator.
94
+
95
+
### 1. Add Native wolfSSL Library Source Code to Project
96
+
97
+
This example project is already set up to compile and build the native
98
+
wolfSSL library source files, but the wolfSSL files themselves have not been
99
+
included in this package. You must download or link an appropriate version
100
+
of wolfSSL to this project using one of the options below.
101
+
102
+
The project looks for the directory
103
+
`wolfssljni/IDE/Android/app/src/main/cpp/wolfssl` for wolfSSL source code.
104
+
This can added in multiple ways:
105
+
106
+
- OPTION A: Download the latest wolfSSL library release from www.wolfssl.com,
107
+
unzip it, rename it to `wolfssl`, and place it in the direcotry
2. Push BKS bundles up to the device along with certificates. To do this, start up the emulator/device and use "adb push". An example of this would be the following commands from root wolfssljni directory:
173
+
### 4. Push BKS files to Android Device or Emulator
174
+
175
+
Push BKS bundles up to the device along with certificates. To do this start
176
+
up the emulator/device and use `adb push`. An example of this would be the
177
+
following commands from root wolfssljni directory. This step may be done
178
+
after the starting Android Studio and compiling the project, but must be done
3. Add wolfSSL source code for compiling. The project looks for the directory wolfssljni/IDE/Android/app/src/main/cpp/wolfssl for wolfSSL source code. This can be done multiple ways one being to download the latest release from wolfSSL's website, unzip it, rename it to wolfssl, and place it in the directory wolfssljni/IDE/Android/app/src/main/cpp/. Alternatively GitHub can be used with "cd /IDE/Android/app/src/main/cpp/ && git clone https://github.com/wolfssl/wolfssl". And the final method to be mentioned in this document is by creating a symbolic link to a wolfssl directory on the system by using "cd /IDE/Android/app/src/main/cpp/ && ln -s /path/to/local/wolfssl ./wolfssl".
74
-
75
-
4. Open the Android studio project by double clicking on the Android folder in wolfssljni/IDE/.
193
+
### 5. Import and Build the Example Project with Android Studio
76
194
77
-
5. Compile the project and run MainActivity from app -> java -> com ->example.wolfssl. This will ask for permissions to access the certificates in the
78
-
/sdcard/ directory and then print out the server certificate information on success.
195
+
1) Open the Android Studio project by double clicking on the `Android` folder
196
+
in wolfssljni/IDE/. Or, from inside Android Studio, open the `Android` project
197
+
located in the wolfssljni/IDE directory.
79
198
80
-
6. OPTIONAL : The androidTests can then be run after permissions have been given. app->java->com.wolfssl->provider.jsse.test->WolfSSLJSSETestSuite and
81
-
app->java->com.wolfssl->test->WolfSSLTestSuite.
199
+
2) Build the project and run MainActivity from app -> java/com/example.wolfssl.
200
+
This will ask for permissions to access the certificates in the /sdcard/
201
+
directory and then print out the server certificate information on success.
82
202
83
-
7. OPTIONAL : To build with TLS 1.3 enabled macros need added to IDE/Android/app/src/main/cpp/CMakeLists.txt. The macros needed to be defined
84
-
are; `HAVE_HKDF`, `WC_RSA_PSS`, `HAVE_FFDHE_2048`, `HAVE_SUPPORTED_CURVES`,`WOLFSSL_TLS13` and `HAVE_TLS_EXTENSION`. Each of those should be added to the “add_definitions” list in the CMakeLists.txt file.
203
+
3) OPTIONAL: The androidTests can be run after permissions has been given.
204
+
app->java->com.wolfssl->provider.jsse.test->WolfSSLJSSETestSuite and
205
+
app->java->com.wolfssl->test->WolfSSLTestSuite
85
206
86
207
## Generic IDE Build
87
208
88
-
For generic IDE builds create a new project in the IDE, then add source files from src/java. This will be the following packages:
209
+
For generic IDE builds create a new project in the IDE, then add source files
210
+
from `src/java`. This will be the following packages:
211
+
89
212
```
90
213
com.wolfssl
91
214
com.wolfssl.provider.jsse
92
215
com.wolfssl.wolfcrypt
93
216
```
94
-
Run java.sh from the command line or have the IDE execute "java.sh" to generate the native shim layer linking against wolfSSL.
95
-
96
-
Add native library reference to the project. It should look in the lib directory for libwolfssl.jnilib (i.e. wolfssljni/lib/).
97
-
98
-
To compile test cases add the packages com.wolfssl.provider.jsse.test and com.wolfssl.test from the directory src/test. The project will also need JUNIT5 to run the tests.
99
-
100
-
If adding in optional examples then the source code in examples/provider/ can be added to the project. Optionally the IDE can execute examples/provider/ClientJSSE.sh. One of the difficult parts to adding in the examples is making sure the path to keystores is known to the IDE when it runs the examples, if trying to use the default keystores.
101
217
218
+
Run java.sh from the command line or have the IDE execute `java.sh` to generate
219
+
the native shim layer linking against wolfSSL.
102
220
221
+
Add native library reference to the project. It should look in the lib
222
+
directory for libwolfssl.jnilib (i.e. wolfssljni/lib/).
223
+
224
+
To compile test cases add the packages `com.wolfssl.provider.jsse.test` and
225
+
`com.wolfssl.test` from the directory `src/test`. The project will also need
226
+
Junit to run the tests.
227
+
228
+
If adding in optional examples then the source code in
229
+
`examples/provider/` can be added to the project. Optionally the IDE can
230
+
execute `examples/provider/ClientJSSE.sh`. One of the difficult parts to adding
231
+
in the examples is making sure the path to keystores is known to the IDE when
232
+
it runs the examples, if trying to use the default keystores.
0 commit comments