Optimize the source of tls sni
Some checks are pending
Build APK / build (push) Waiting to run
Validate Fastlane metadata / go (push) Waiting to run

This commit is contained in:
2dust 2025-06-28 10:02:25 +08:00
parent 8e03de8055
commit 3f778a1ea2
3 changed files with 27 additions and 4 deletions

View file

@ -97,7 +97,7 @@ object V2rayConfigManager {
val result = ConfigResult(false)
val address = config.server ?: return result
if (!Utils.isIpAddress(address)) {
if (!Utils.isPureIpAddress(address)) {
if (!Utils.isValidUrl(address)) {
Log.w(AppConfig.TAG, "$address is an invalid ip or domain")
return result
@ -154,7 +154,7 @@ object V2rayConfigManager {
val result = ConfigResult(false)
val address = config.server ?: return result
if (!Utils.isIpAddress(address)) {
if (!Utils.isPureIpAddress(address)) {
if (!Utils.isValidUrl(address)) {
Log.w(AppConfig.TAG, "$address is an invalid ip or domain")
return result
@ -1052,7 +1052,15 @@ object V2rayConfigManager {
fun populateTlsSettings(streamSettings: StreamSettingsBean, profileItem: ProfileItem, sniExt: String?) {
val streamSecurity = profileItem.security.orEmpty()
val allowInsecure = profileItem.insecure == true
val sni = if (profileItem.sni.isNullOrEmpty()) sniExt else profileItem.sni
val sni = if (profileItem.sni.isNullOrEmpty()) {
when {
sniExt.isNotNullEmpty() && Utils.isDomainName(sniExt) -> sniExt
profileItem.server.isNotNullEmpty() && Utils.isDomainName(profileItem.server) -> profileItem.server
else -> sniExt
}
} else {
profileItem.sni
}
val fingerprint = profileItem.fingerPrint
val alpns = profileItem.alpn
val publicKey = profileItem.publicKey

View file

@ -102,7 +102,7 @@ object V2RayServiceManager {
val config = MmkvManager.decodeServerConfig(guid) ?: return
if (config.configType != EConfigType.CUSTOM
&& !Utils.isValidUrl(config.server)
&& !Utils.isIpAddress(config.server)
&& !Utils.isPureIpAddress(config.server.orEmpty())
) return
// val result = V2rayConfigUtil.getV2rayConfig(context, guid)
// if (!result.status) return

View file

@ -198,6 +198,21 @@ object Utils {
return isIpv4Address(value) || isIpv6Address(value)
}
/**
* Check if a string is a valid domain name.
*
* A valid domain name must not be an IP address and must be a valid URL format.
*
* @param input The string to check.
* @return True if the string is a valid domain name, false otherwise.
*/
fun isDomainName(input: String?): Boolean {
if (input.isNullOrEmpty()) return false
// Must not be an IP address and must be a valid URL format
return !isPureIpAddress(input) && isValidUrl(input)
}
/**
* Check if a string is a valid IPv4 address.
*