about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-02-14 15:09:00 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-02-14 15:09:00 +0300
commit5f5f8e01043e617db1d12f82a857d74fbaf4fa6f (patch)
tree81bed93a5e61b880bae25b42a54d40f7ea32b2de
parentb1b861d008fc8a0fca76a1cb1062e6ad574bf3d1 (diff)
downloadtt-rss-android-5f5f8e01043e617db1d12f82a857d74fbaf4fa6f.tar.gz
tt-rss-android-5f5f8e01043e617db1d12f82a857d74fbaf4fa6f.tar.xz
add client certificate handling for article webview
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java17
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleModel.java28
-rwxr-xr-xorg.fox.ttrss/src/main/res/values/strings.xml1
3 files changed, 46 insertions, 0 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java
index ff6fa9a6..3a3f6424 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java
@@ -6,6 +6,8 @@ import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.Handler;
+import android.security.KeyChain;
 import android.util.Log;
 import android.util.TypedValue;
 import android.view.ContextMenu;
@@ -13,6 +15,7 @@ import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.webkit.ClientCertRequest;
 import android.webkit.WebBackForwardList;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
@@ -29,6 +32,8 @@ import org.jsoup.helper.StringUtil;
 
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -233,6 +238,18 @@ public class ArticleFragment extends androidx.fragment.app.Fragment {
 
                 return false;
             }
+
+            @Override
+            public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) {
+                ArticleModel model = Application.getArticlesModel();
+
+                if (m_prefs.getBoolean("mtls_enabled", false) && model.getPrivateKey() != null) {
+                    request.proceed(model.getPrivateKey(), model.getClientCertChain());
+                } else {
+                    m_activity.toast(R.string.error_mtls_cert_not_available);
+                    request.cancel();
+                }
+            }
         });
 
         m_web.setOnLongClickListener(v -> {
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleModel.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleModel.java
index 309b01fa..b07e08d1 100644
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleModel.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleModel.java
@@ -4,6 +4,7 @@ import android.app.Application;
 import android.content.SharedPreferences;
 import android.os.Handler;
 import android.os.Looper;
+import android.security.KeyChain;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -22,6 +23,8 @@ import org.fox.ttrss.types.Article;
 import org.fox.ttrss.types.Feed;
 
 import java.lang.reflect.Type;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -56,6 +59,9 @@ public class ArticleModel extends AndroidViewModel implements ApiCommon.ApiCalle
     private MutableLiveData<Integer> m_loadingProgress = new MutableLiveData<>(Integer.valueOf(0));
     private MutableLiveData<Article> m_activeArticle = new MutableLiveData<>(null);
 
+    private MutableLiveData<X509Certificate[]> m_clientCertChain = new MutableLiveData<>(null);
+    private MutableLiveData<PrivateKey> m_clientCertKey = new MutableLiveData<>(null);
+
     public ArticleModel(@NonNull Application application) {
         super(application);
 
@@ -63,6 +69,28 @@ public class ArticleModel extends AndroidViewModel implements ApiCommon.ApiCalle
 
         // do we need concurrency or not?
         m_executor = Executors.newSingleThreadExecutor();
+
+        // TODO this should probably be moved somewhere global to application, but where?
+        String clientCertAlias = m_prefs.getString("mtls_certificate_alias", null);
+
+        if (m_prefs.getBoolean("mtls_enabled", false) && clientCertAlias != null) {
+            m_executor.execute(() -> {
+                try {
+                    m_clientCertChain.postValue(KeyChain.getCertificateChain(application, clientCertAlias));
+                    m_clientCertKey.postValue(KeyChain.getPrivateKey(application, clientCertAlias));
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            });
+        }
+    }
+
+    public X509Certificate[] getClientCertChain() {
+        return m_clientCertChain.getValue();
+    }
+
+    public PrivateKey getPrivateKey() {
+        return m_clientCertKey.getValue();
     }
 
     public LiveData<Long> getUpdatesData() {
diff --git a/org.fox.ttrss/src/main/res/values/strings.xml b/org.fox.ttrss/src/main/res/values/strings.xml
index 670cc68e..6406b6f3 100755
--- a/org.fox.ttrss/src/main/res/values/strings.xml
+++ b/org.fox.ttrss/src/main/res/values/strings.xml
@@ -321,4 +321,5 @@
     <string name="prefs_mtls_enabled">Enable mTLS</string>
     <string name="prefs_mtls_pick_certificate">Choose client certificate</string>
     <string name="prefs_loop_videos">Loop videos</string>
+    <string name="error_mtls_cert_not_available">Client certificate requested but it\'s not available.</string>
 </resources>