From f81da5d9575cd1ce9781010adcc9a9dafcd71d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 8 Jan 2025 12:21:21 +0800 Subject: [PATCH] Add support for systemCertificates --- .../sfa/bg/PlatformInterfaceWrapper.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt b/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt index 381fb87..068a529 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt @@ -21,6 +21,9 @@ import java.net.Inet6Address import java.net.InetSocketAddress import java.net.InterfaceAddress import java.net.NetworkInterface +import java.security.KeyStore +import kotlin.io.encoding.Base64 +import kotlin.io.encoding.ExperimentalEncodingApi import io.nekohasekai.libbox.NetworkInterface as LibboxNetworkInterface interface PlatformInterfaceWrapper : PlatformInterface { @@ -174,6 +177,23 @@ interface PlatformInterfaceWrapper : PlatformInterface { return LocalResolver } + @OptIn(ExperimentalEncodingApi::class) + override fun systemCertificates(): StringIterator { + val certificates = mutableListOf() + val keyStore = KeyStore.getInstance("AndroidCAStore") + if (keyStore != null) { + keyStore.load(null, null); + val aliases = keyStore.aliases() + while (aliases.hasMoreElements()) { + val cert = keyStore.getCertificate(aliases.nextElement()) + certificates.add( + "-----BEGIN CERTIFICATE-----\n" + Base64.encode(cert.encoded) + "\n-----END CERTIFICATE-----" + ) + } + } + return StringArray(certificates.iterator()) + } + private class InterfaceArray(private val iterator: Iterator) : NetworkInterfaceIterator {