Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add insecure for Hysteria2
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Sep 29, 2024
1 parent f5130f5 commit d31085a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class Hysteria2Bean(
)

data class TlsBean(
val sni: String?
val sni: String?,
val insecure: Boolean?,
)
}
23 changes: 14 additions & 9 deletions app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object V2rayConfigUtil {

val result = getV2rayNonCustomConfig(context, config)
//Log.d(ANG_PACKAGE, result.content)
Log.d(ANG_PACKAGE, result.domainPort?:"")
return result
} catch (e: Exception) {
e.printStackTrace()
Expand Down Expand Up @@ -73,9 +74,10 @@ object V2rayConfigUtil {

inbounds(v2rayConfig)

outbounds(v2rayConfig, outbound)
val isPlugin = outbound.protocol.equals(EConfigType.HYSTERIA2.name, true)
val retOut = outbounds(v2rayConfig, outbound, isPlugin)

val retMore = moreOutbounds(v2rayConfig, config.subscriptionId)
val retMore = moreOutbounds(v2rayConfig, config.subscriptionId, isPlugin)

routing(v2rayConfig)

Expand All @@ -93,7 +95,7 @@ object V2rayConfigUtil {

result.status = true
result.content = v2rayConfig.toPrettyPrinting()
result.domainPort = if (retMore.first) retMore.second else outbound.getServerAddressAndPort()
result.domainPort = if (retMore.first) retMore.second else retOut.second
return result
}

Expand Down Expand Up @@ -145,8 +147,8 @@ object V2rayConfigUtil {
return true
}

private fun outbounds(v2rayConfig: V2rayConfig, outbound: V2rayConfig.OutboundBean): Boolean {
if (outbound.protocol.equals(EConfigType.HYSTERIA2.name, true)) {
private fun outbounds(v2rayConfig: V2rayConfig, outbound: V2rayConfig.OutboundBean, isPlugin: Boolean): Pair<Boolean, String> {
if (isPlugin) {
val socksPort = 100 + Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT), AppConfig.PORT_SOCKS.toInt())
val outboundNew = V2rayConfig.OutboundBean(
mux = null,
Expand All @@ -165,11 +167,11 @@ object V2rayConfigUtil {
} else {
v2rayConfig.outbounds.add(outboundNew)
}
return true
return Pair(true, outboundNew.getServerAddressAndPort())
}

val ret = updateOutboundWithGlobalSettings(outbound)
if (!ret) return false
if (!ret) return Pair(false, "")

if (v2rayConfig.outbounds.isNotEmpty()) {
v2rayConfig.outbounds[0] = outbound
Expand All @@ -178,7 +180,7 @@ object V2rayConfigUtil {
}

updateOutboundFragment(v2rayConfig)
return true
return Pair(true, outbound.getServerAddressAndPort())
}

private fun fakedns(v2rayConfig: V2rayConfig) {
Expand Down Expand Up @@ -532,10 +534,13 @@ object V2rayConfigUtil {
return true
}

private fun moreOutbounds(v2rayConfig: V2rayConfig, subscriptionId: String): Pair<Boolean, String> {
private fun moreOutbounds(v2rayConfig: V2rayConfig, subscriptionId: String, isPlugin: Boolean): Pair<Boolean, String> {
val returnPair = Pair(false, "")
var domainPort: String = ""

if (isPlugin) {
return returnPair
}
//fragment proxy
if (settingsStorage?.decodeBool(AppConfig.PREF_FRAGMENT_ENABLED, false) == true) {
return returnPair
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ object Hysteria2Fmt {

fun toNativeConfig(config: ServerConfig, socksPort: Int): Hysteria2Bean? {
val outbound = config.getProxyOutbound() ?: return null
val tls = outbound.streamSettings?.tlsSettings
val bean = Hysteria2Bean(
server = outbound.getServerAddressAndPort(),
auth = outbound.getPassword(),
socks5 = Hysteria2Bean.Socks5Bean(
listen = "$LOOPBACK:${socksPort}"
listen = "$LOOPBACK:${socksPort}",
),
tls = Hysteria2Bean.TlsBean(outbound.getServerAddress())
tls = Hysteria2Bean.TlsBean(
sni = tls?.serverName ?: outbound.getServerAddress(),
insecure = tls?.allowInsecure
)
)
return bean
}
Expand Down

0 comments on commit d31085a

Please sign in to comment.