Add support for systemCertificates

This commit is contained in:
世界 2025-01-08 12:21:21 +08:00
parent 04a648ec03
commit 9b0f3433ce
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -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<String>()
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<LibboxNetworkInterface>) :
NetworkInterfaceIterator {