Skip to content

Commit

Permalink
Add support for client certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanritscher committed Sep 1, 2023
1 parent 957c7f1 commit 79453ce
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "InteractiveKeyManager"]
path = InteractiveKeyManager
url = https://github.com/stephanritscher/InteractiveKeyManager
[submodule "MemorizingTrustManager"]
path = MemorizingTrustManager
url = https://github.com/stephanritscher/MemorizingTrustManager.git
1 change: 1 addition & 0 deletions InteractiveKeyManager
Submodule InteractiveKeyManager added at cca85b
1 change: 1 addition & 0 deletions MemorizingTrustManager
Submodule MemorizingTrustManager added at d98391
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {

defaultConfig {
applicationId "xyz.zedler.patrick.grocy"
minSdk 21
minSdk 23
targetSdk 34
compileSdk 34
versionCode 49
Expand Down Expand Up @@ -89,6 +89,8 @@ android {
}

dependencies {
implementation project(':InteractiveKeyManager')
implementation project(':MemorizingTrustManager')
// Fix for Kotlin build error from some AndroidX dependencies
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
Expand Down Expand Up @@ -144,4 +146,4 @@ dependencies {
// prevents bug https://github.com/patzly/grocy-android/issues/425
//noinspection GradleDependency
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
}
}
5 changes: 4 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@
# This was generated automatically by the Android Gradle plugin to hide warnings
# Only has effected these pre-KitKat two compatibility classes
-dontwarn com.android.org.conscrypt.SSLParametersImpl
-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl

# This is generated automatically by the Android Gradle plugin.
-dontwarn lombok.NonNull
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
android:theme="@style/Theme.Grocy.WebDialog">
</activity>

<!-- InteractiveKeyManager -->
<activity
android:name="de.ritscher.ssl.SelectKeyStoreActivity"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar"/>
<!-- MemorizingTrustManager -->
<activity android:name="de.duenndns.ssl.MemorizingActivity"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar"/>

<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.DiskBasedCache;
import com.android.volley.toolbox.HurlStack;

import de.duenndns.ssl.MemorizingTrustManager;
import de.ritscher.ssl.InteractiveKeyManager;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;

import xyz.zedler.patrick.grocy.Constants.SETTINGS.NETWORK;
import xyz.zedler.patrick.grocy.Constants.SETTINGS_DEFAULT;

Expand Down Expand Up @@ -78,7 +86,7 @@ public void newRequestQueue() {
stack = new ProxyHurlStack(sharedPrefs, useTor);
} else {
try {
stack = new HurlStack(null, new TLSSocketFactory());
stack = new HurlStack(null, new TLSSocketFactory(ctx));
} catch (NoSuchAlgorithmException | KeyManagementException e) {
stack = new HurlStack();
}
Expand All @@ -92,9 +100,11 @@ private static class TLSSocketFactory extends SSLSocketFactory {

private final SSLSocketFactory internalSSLSocketFactory;

public TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
public TLSSocketFactory(Context ctx) throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
KeyManager keyManager = new InteractiveKeyManager(ctx.getApplicationContext());
TrustManager mtm = new MemorizingTrustManager(ctx);
context.init(new KeyManager[]{keyManager}, new TrustManager[]{mtm}, new SecureRandom());
internalSSLSocketFactory = context.getSocketFactory();
}

Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url "https://a8c-libs.s3.amazonaws.com/android" }
}
}

buildscript {
repositories {
google()
mavenCentral()
maven { url "https://a8c-libs.s3.amazonaws.com/android" }
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.0'
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
*/

include ':app'
rootProject.name = "Grocy Android"
include ':InteractiveKeyManager'
include ':MemorizingTrustManager'
rootProject.name = "Grocy Android"

0 comments on commit 79453ce

Please sign in to comment.