Skip to content

Commit

Permalink
Merge pull request #397 from eduvpn/common-go
Browse files Browse the repository at this point in the history
Use common Go library
  • Loading branch information
dzolnai authored Oct 13, 2023
2 parents 0ea27c9 + 77d33b5 commit 120d6d1
Show file tree
Hide file tree
Showing 96 changed files with 2,415 additions and 3,833 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ jobs:
restore-keys: |
${{ runner.os }}-${{ matrix.api-level }}-build-
- name: Cache appauth build
uses: actions/cache@v3
with:
path: |
appauth/library/build
key: ${{ runner.os }}-${{ matrix.api-level }}-appauth-${{ hashFiles('.git/modules/appauth/HEAD') }}
restore-keys: |
${{ runner.os }}-${{ matrix.api-level }}-appauth-
- name: Cache ics-openvpn build
id: cache-ics-openvpn
uses: actions/cache@v3
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "ics-openvpn"]
path = ics-openvpn
url = https://github.com/eduvpn/ics-openvpn
[submodule "appauth"]
path = appauth
url = https://github.com/eduvpn/AppAuth-Android.git
[submodule "common/libs/eduvpn-common"]
path = common/libs/eduvpn-common
url = https://github.com/eduvpn/eduvpn-common
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 3.2 (2023-09-27)
- Use common Go library to discover the instances and to communicate with them. This simplifies the app code, but should have no visible changes to the end user.

## 3.1.1 (2023-05-24)
- Only sort when retrieving lists, not on every keypress
([#394](https://github.com/eduvpn/android/pull/394))
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Or if your git version is below 2.13:

# Running with Android Studio

First install the `swig` package with your operating system package manager.
First install the `swig` and `go` packages with your operating system package manager.

Make sure you have the latest stable version of Android Studio installed, you can download it from [here](https://developer.android.com/studio).
Open the project by opening the build.gradle in the root of this repository with Android Studio.
Expand All @@ -32,7 +32,7 @@ Make sure that you have the following packages installed in the SDK Manager (Too
* SDK Tools - CMake
* SDK Tools - Android SDK Platform-Tools
* SDK Tools - Android SDK Tools
* SDK Tools - NDK - 19.2.x version (a later version might work, but is untested)
* SDK Tools - NDK - 25.1.x version (a later version might work, but is untested)

To find a specific version of a package (for the NDK), check the option 'Show Package Details'
in the bottom-lower corner of the SDK Manager.
Expand Down Expand Up @@ -64,6 +64,7 @@ $ sudo dnf -y install \
tar \
git \
swig \
go \
java-11-openjdk \
java-11-openjdk-devel \
ncurses-compat-libs \
Expand Down
33 changes: 13 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
buildConfigField "String", "CERTIFICATE_DISPLAY_NAME", "\"eduVPN for Android\""

manifestPlaceholders = [
'appAuthRedirectScheme': 'org.eduvpn.app'
'redirectScheme': 'org.eduvpn.app'
]
missingDimensionStrategy 'implementation', 'ui' // Skeleton is no option for us because we need the log activity

Expand Down Expand Up @@ -98,7 +98,7 @@ android {
buildConfigField "String", "CERTIFICATE_DISPLAY_NAME", "\"Let's Connect! for Android\""

manifestPlaceholders = [
'appAuthRedirectScheme': 'org.letsconnect-vpn.app'
'redirectScheme': 'org.letsconnect-vpn.app'
]
}
}
Expand All @@ -114,12 +114,12 @@ android {
// Support Java 8+ on sdk < 24, also necessary for WireGuard
coreLibraryDesugaringEnabled true

sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = JavaVersion.VERSION_11
}

kapt {
Expand All @@ -139,45 +139,38 @@ android {
}
}

def daggerVersion = "2.39.1"
def daggerVersion = "2.44"
def okHttpVersion = "4.10.0"
def lifecycleVersion = "2.2.0"

dependencies {
// The VPN library
// OpenVPN library
implementation project(path: ':ics-openvpn-main')
// WireGuard VPN library
implementation 'com.wireguard.android:tunnel:1.0.20211029'
// OAuth2 client
implementation project(path: ':appauth')
implementation 'com.wireguard.android:tunnel:1.0.20230427'
// eduVPN common library written in Go, stores all data and does the communication with the servers
implementation project(path: ':common')
// Please try to stay in sync with the versions used in the ics-openvpn module
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.activity:activity-ktx:1.1.0"
implementation "androidx.fragment:fragment-ktx:1.2.3"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.browser:browser:1.0.0" // Custom tabs
implementation "androidx.browser:browser:1.5.0" // Custom tabs
implementation "com.android.support.constraint:constraint-layout:1.0.2"
implementation "androidx.security:security-crypto:1.1.0-alpha06" // Secure preferences. Using alpha version for minSDK 21


implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"

// HTTP client
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"
// Dependency injection
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
// Image loader
implementation 'com.squareup.picasso:picasso:2.71828'
// Public key verification
implementation "com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.2@aar"

// Kotlin coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"

implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0"

// All testing related libraries
Expand All @@ -194,7 +187,7 @@ dependencies {
}

// This will fail the build if there is a Kotlin compiler warning.
tasks.withType(KotlinCompile).all {
tasks.withType(KotlinCompile).forEach {
kotlinOptions {
freeCompilerArgs = ["-Werror", "-opt-in=kotlin.RequiresOptIn"]
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/androidTest/java/nl/eduvpn/app/UnitTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import nl.eduvpn.app.service.HistoryServiceTest;
import nl.eduvpn.app.service.PreferencesServiceTest;
import nl.eduvpn.app.service.SecurityServiceTest;
import nl.eduvpn.app.service.SerializerServiceTest;
import nl.eduvpn.app.utils.FormattingUtilsTest;

Expand All @@ -31,8 +30,8 @@
* Created by Daniel Zolnai on 2016-10-18.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({SerializerServiceTest.class, PreferencesServiceTest.class, HistoryServiceTest.class,
SecurityServiceTest.class, FormattingUtilsTest.class})
@Suite.SuiteClasses({SerializerServiceTest.class, PreferencesServiceTest.class,
HistoryServiceTest.class, FormattingUtilsTest.class})
public class UnitTestSuite {
// Test suite used to run all unit tests at once.
// To run the tests, right click on the class name, and select "Run 'UnitTestSuite'".
Expand Down
121 changes: 1 addition & 120 deletions app/src/androidTest/java/nl/eduvpn/app/service/HistoryServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import android.net.Uri
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import net.openid.appauth.AuthState
import net.openid.appauth.AuthorizationServiceConfiguration
import nl.eduvpn.app.entity.*
import org.junit.*
import org.junit.runner.RunWith
Expand Down Expand Up @@ -66,123 +64,6 @@ class HistoryServiceTest {
.putInt("DUMMY_KEY", Random().nextInt())
.commit()
}
_historyService = HistoryService(preferencesService)
}

@Test(timeout = 1500) // The timeout should be lower, but the CI is too slow.
fun testSerializationSpeed() {
// We create, save and restore 10 discovered APIs and 10 access tokens.
// Should be still fast.
val baseURI = "http://example.com/baseURI"
for (i in 0..9) {
val instance = Instance(
baseURI + i,
TranslatableString("displayName"),
TranslatableString("konijn"),
null,
AuthorizationType.Distributed,
"NL",
true,
"https://example.com/template",
ArrayList()
)
_historyService!!.cacheAuthorizationState(instance, AuthState(), Date())
}
reloadHistoryService(false)
for (i in 0..9) {
Assert.assertNotNull(
_historyService!!.getCachedAuthState(
Instance(
baseURI + i,
TranslatableString("displayName"),
TranslatableString("konijn"),
null,
AuthorizationType.Distributed,
"NL",
true,
null,
ArrayList()
)
)
)
}
}

@Test
fun testCacheAccessToken() {
val baseURI = "http://example.com"
val exampleAuthState = AuthState(
AuthorizationServiceConfiguration(
Uri.parse("http://example.com/auth"), Uri
.parse("http://example.com/token"), null
)
)
val instance = Instance(
baseURI,
TranslatableString("displayName"),
TranslatableString("konijn"),
null,
AuthorizationType.Distributed,
"HU",
true,
"https://eduvpn.org/template",
ArrayList()
)
val now = Date()
_historyService!!.cacheAuthorizationState(instance, exampleAuthState, now)
reloadHistoryService(false)
val (restoredAuthState, _) = _historyService!!.getCachedAuthState(instance)!!
Assert.assertEquals(
exampleAuthState.authorizationServiceConfiguration!!.authorizationEndpoint,
restoredAuthState
.authorizationServiceConfiguration!!.authorizationEndpoint
)
Assert.assertEquals(
exampleAuthState.authorizationServiceConfiguration!!.tokenEndpoint, restoredAuthState
.authorizationServiceConfiguration!!.tokenEndpoint
)
}

@Test
fun testStoreSavedKeyPair() {
val keyPair1 = KeyPair(false, "cert1", "pk1")
val instance1 = Instance(
"http://example.com/",
TranslatableString("example.com"),
TranslatableString("konijn"),
null,
AuthorizationType.Distributed,
"DK",
false,
"https://eduvpn.org/template",
ArrayList()
)
val savedKeyPair1 = SavedKeyPair(instance1, keyPair1)
val instance2 = Instance(
"http://something.else/",
TranslatableString("something.else"),
TranslatableString("konijn"),
null,
AuthorizationType.Distributed,
"DK",
false,
null,
ArrayList()
)
val keyPair2 = KeyPair(true, "example certificate", "example private key")
val savedKeyPair2 = SavedKeyPair(instance2, keyPair2)
_historyService!!.storeSavedKeyPair(savedKeyPair1)
_historyService!!.storeSavedKeyPair(savedKeyPair2)
reloadHistoryService(false)
val retrieved1 = _historyService!!.getSavedKeyPairForInstance(instance1)
val retrieved2 = _historyService!!.getSavedKeyPairForInstance(instance2)
Assert.assertNotNull(retrieved1)
Assert.assertNotNull(retrieved2)
Assert.assertEquals(keyPair1.isOK, retrieved1.keyPair.isOK)
Assert.assertEquals(keyPair1.certificate, retrieved1.keyPair.certificate)
Assert.assertEquals(keyPair1.privateKey, retrieved1.keyPair.privateKey)
Assert.assertEquals(keyPair2.isOK, retrieved2.keyPair.isOK)
Assert.assertEquals(keyPair2.certificate, retrieved2.keyPair.certificate)
Assert.assertEquals(keyPair2.privateKey, retrieved2.keyPair.privateKey)
_historyService = HistoryService(BackendService(context, serializerService, preferencesService))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,6 @@ class PreferencesServiceTest {
)
}

@Test
fun testDiscoveredAPISave() {
val discoveredAPIV3 = DiscoveredAPIV3(
"http://example.com/",
"http://example.com/auth_endpoint",
"http://example.com/token_endpoint"
)
_preferencesService.setCurrentDiscoveredAPI(discoveredAPIV3)
val retrievedDiscoveredAPI = _preferencesService.getCurrentDiscoveredAPI()
Assert.assertEquals(
discoveredAPIV3.authorizationEndpoint,
retrievedDiscoveredAPI!!.authorizationEndpoint
)
Assert.assertEquals(
discoveredAPIV3.apiEndpoint,
retrievedDiscoveredAPI.toDiscoveredAPIs().v3!!.apiEndpoint
)
Assert.assertEquals(discoveredAPIV3.tokenEndpoint, retrievedDiscoveredAPI.tokenEndpoint)
}

@Test
fun testLastKnownOrganizationListVersionSave() {
val version = 121_323L
Expand Down
Loading

0 comments on commit 120d6d1

Please sign in to comment.