Skip to content

Commit

Permalink
Merge pull request #222 from cconlon/gradleAction
Browse files Browse the repository at this point in the history
Add Github Actions PRB test for Android gradle build
  • Loading branch information
JacobBarthelmeh authored Sep 20, 2024
2 parents 0bc0e07 + ac9670f commit d086267
Show file tree
Hide file tree
Showing 33 changed files with 611 additions and 395 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/android_gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Android Gradle Build test logic

on:
workflow_call:
inputs:
os:
required: true
type: string
jdk_distro:
required: true
type: string
jdk_version:
required: true
type: string

jobs:
build_wolfssljni:
runs-on: ${{ inputs.os }}
steps:
- name: Clone wolfssljni
uses: actions/checkout@v4

# Clone native wolfSSL
- name: Clone native wolfSSL
uses: actions/checkout@v4
with:
repository: 'wolfssl/wolfssl'
path: IDE/Android/app/src/main/cpp/wolfssl

# Copy options.h.in to blank options.h
- name: Create blank options.h
run: cp IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h.in IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h

# Setup Java
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: ${{ inputs.jdk_distro }}
java-version: ${{ inputs.jdk_version }}

# Gradle assembleDebug
- name: Gradle assembleDebug
run: cd IDE/Android && ls && ./gradlew assembleDebug

# Gradle assembleDebugUnitTest
- name: Gradle assembleDebugUnitTest
run: cd IDE/Android && ls && ./gradlew assembleDebugUnitTest

# Gradle assembleDebugAndroidTest
- name: Gradle assembleDebugAndroidTest
run: cd IDE/Android && ls && ./gradlew assembleDebugAndroidTest

15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,18 @@ jobs:
jdk_version: ${{ matrix.jdk_version }}
wolfssl_configure: ${{ matrix.wolfssl_configure }}

# ----------------------- Android Gradle build ------------------------
# Run Android gradle build over PR code, only running on Linux with one
# JDK/version for now.
android-gradle:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
jdk_version: [ '21' ]
name: Android Gradle (${{ matrix.os }} Zulu JDK ${{ matrix.jdk_version }})
uses: ./.github/workflows/android_gradle.yml
with:
os: ${{ matrix.os }}
jdk_distro: "zulu"
jdk_version: ${{ matrix.jdk_version }}

7 changes: 7 additions & 0 deletions IDE/Android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions IDE/Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdk 33
defaultConfig {
applicationId "com.example.wolfssl"
minSdkVersion 30
targetSdkVersion 30
/* Min SDK should stay at 24 to detect if we try to use newer APIs
* than were available in that Android SDK. We have users who are still
on SDK 24 (ref ZD 18311) */
minSdkVersion 24
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -15,6 +18,10 @@ android {
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
buildTypes {
release {
minifyEnabled false
Expand All @@ -26,14 +33,18 @@ android {
path "src/main/cpp/CMakeLists.txt"
}
}
sourceSets {
main.java.srcDirs += '../../src/java'
test.java.srcDirs += '../../src/test'
}
namespace 'com.example.wolfssl'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
3 changes: 1 addition & 2 deletions IDE/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
Expand All @@ -12,7 +11,7 @@
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
7 changes: 7 additions & 0 deletions IDE/Android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ project("wolfssljni-gradle" C ASM)
set(wolfssljni_DIR ${CMAKE_SOURCE_DIR}/../../../../../../)
set(wolfssl_DIR ${CMAKE_SOURCE_DIR}/wolfssl/)

# set warnings as errors, used in this example project but may be different
# in production apps/environments.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")

# ------------------------- wolfSSL Normal vs. FIPS Ready Selection --------------------------------
# Select if wolfSSL is normal ("normal") or FIPS Ready ("fipsready")
# wolfSSL FIPS Ready is available for download on the wolfssl.com download page. For more
Expand Down Expand Up @@ -222,7 +226,10 @@ list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_bn.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_asn1.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_certman.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_crypto.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_load.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_misc.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_p7p12.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_sess.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/x509.c)
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/x509_str.c)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@

package com.example.wolfssl;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
Expand All @@ -35,17 +31,11 @@
import com.wolfssl.WolfSSL;
import com.wolfssl.WolfSSLException;
import com.wolfssl.provider.jsse.WolfSSLProvider;
import com.wolfssl.provider.jsse.WolfSSLX509;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Security;
import java.security.cert.CertificateException;

public class MainActivity extends AppCompatActivity {

Expand All @@ -55,7 +45,7 @@ public void onClick(View v) {
TextView tv = (TextView) findViewById(R.id.sample_text);

try {
testLoadCert(tv);
testFindProvider(tv);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -72,23 +62,11 @@ protected void onCreate(Bundle savedInstanceState) {

TextView tv = (TextView) findViewById(R.id.sample_text);
tv.setText("wolfSSL JNI Android Studio Example App");

if (!Environment.isExternalStorageManager()) {
Intent intent = new Intent(
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
}

public void testLoadCert(TextView tv)
public void testFindProvider(TextView tv)
throws NoSuchProviderException, NoSuchAlgorithmException,
KeyStoreException, IOException, CertificateException,
WolfSSLException {
String file = "/sdcard/examples/provider/all.bks";
WolfSSLX509 x509;
KeyStore ks;

WolfSSL.loadLibrary();

Expand All @@ -100,11 +78,8 @@ public void testLoadCert(TextView tv)
System.out.println("Unable to find wolfJSSE provider");
return;
}
else {

ks = KeyStore.getInstance("BKS");
ks.load(new FileInputStream(file), "wolfSSL test".toCharArray());

x509 = new WolfSSLX509(ks.getCertificate("server").getEncoded());
tv.setText("Server Certificate Found:\n" + x509.toString());
}
}
}
}
9 changes: 7 additions & 2 deletions IDE/Android/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:text="Load Cert File" />
android:text="Test Provider Lookup"
app:layout_constraintBottom_toTopOf="@+id/sample_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/sample_text"
Expand All @@ -19,6 +23,7 @@
android:layout_marginTop="16dp"
android:paddingVertical="16pt"
android:text="Hello World!"
android:textColor="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.461"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down
7 changes: 6 additions & 1 deletion IDE/Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ allprojects {
repositories {
google()
jcenter()

}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Werror"
options.deprecation = false
}
}
}

Expand Down
1 change: 0 additions & 1 deletion IDE/Android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
org.gradle.jvmargs=-Xmx1536m
Expand Down
2 changes: 2 additions & 0 deletions native/com_wolfssl_WolfSSLCertificate.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/java/com/wolfssl/WolfSSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1683,10 +1683,10 @@ protected void finalize() throws Throwable
synchronized(cleanupLock) {
if (this.active == true) {
/* reset logging callback before calling cleanup() */
this.setLoggingCb(null);
setLoggingCb(null);

/* free resources, set state */
this.cleanup();
cleanup();
this.active = false;
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/java/com/wolfssl/WolfSSLCertificate.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.math.BigInteger;
Expand All @@ -49,7 +50,9 @@
/**
* WolfSSLCertificate class, wraps native wolfSSL WOLFSSL_X509 functionality.
*/
public class WolfSSLCertificate {
public class WolfSSLCertificate implements Serializable {

private static final long serialVersionUID = 1L;

private boolean active = false;
private long x509Ptr = 0;
Expand All @@ -59,13 +62,13 @@ public class WolfSSLCertificate {
private boolean weOwnX509Ptr = false;

/* lock around active state */
private final Object stateLock = new Object();
private transient final Object stateLock = new Object();

/* lock around native WOLFSSL_X509 pointer use */
private final Object x509Lock = new Object();
private transient final Object x509Lock = new Object();

/* cache alt names once retrieved once */
private Collection<List<?>> altNames = null;
private ArrayList<List<?>> altNames = null;

/* Public key types used for certificate generation, mirrored from
* native enum in wolfssl/openssl/evp.h */
Expand Down Expand Up @@ -1463,10 +1466,10 @@ public Collection<List<?>> getSubjectAltNames()
synchronized (x509Lock) {
if (this.altNames != null) {
/* already gathered, return cached version */
return this.altNames;
return Collections.unmodifiableCollection(this.altNames);
}

Collection<List<?>> names = new ArrayList<List<?>>();
ArrayList<List<?>> names = new ArrayList<List<?>>();

String nextAltName = X509_get_next_altname(this.x509Ptr);
while (nextAltName != null) {
Expand All @@ -1480,9 +1483,9 @@ public Collection<List<?>> getSubjectAltNames()
}

/* cache altNames collection for later use */
this.altNames = Collections.unmodifiableCollection(names);
this.altNames = names;

return this.altNames;
return Collections.unmodifiableCollection(this.altNames);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/java/com/wolfssl/WolfSSLException.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*/
public class WolfSSLException extends Exception {

/* Exception class is serializable */
private static final long serialVersionUID = 1L;

/**
* Create WolfSSLException with reason String
*
Expand Down
Loading

0 comments on commit d086267

Please sign in to comment.