Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for client certificates #771

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 51eacf
1 change: 1 addition & 0 deletions MemorizingTrustManager
Submodule MemorizingTrustManager added at de1d93
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ dependencies {
implementation libs.lifecycle.viewmodel.savedstate
implementation libs.lifecycle.viewmodel.ktx
implementation libs.paging

// Certificate and trust management
implementation project(':InteractiveKeyManager')
implementation project(':MemorizingTrustManager')

// Navigation framework for easy navigation control using XML
implementation libs.navigation.fragment
implementation libs.navigation.ui
Expand Down Expand Up @@ -127,4 +132,4 @@ dependencies {
// https://github.com/journeyapps/zxing-android-embedded#option-2-desugaring-advanced
// prevents bug https://github.com/patzly/grocy-android/issues/425
coreLibraryDesugaring libs.desugar
}
}
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
10 changes: 9 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@

</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 Expand Up @@ -119,4 +127,4 @@

</application>

</manifest>
</manifest>
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: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.navigation.safeargs) apply false
}
}
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ dependencyResolutionManagement {
}

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