Skip to content

Commit d31085a

Browse files
2dustAnGgIt886
authored andcommitted
Add insecure for Hysteria2
1 parent f5130f5 commit d31085a

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

app/src/main/kotlin/com/neko/v2ray/dto/Hysteria2Bean.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ data class Hysteria2Bean(
1212
)
1313

1414
data class TlsBean(
15-
val sni: String?
15+
val sni: String?,
16+
val insecure: Boolean?,
1617
)
1718
}

app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ object V2rayConfigUtil {
4343

4444
val result = getV2rayNonCustomConfig(context, config)
4545
//Log.d(ANG_PACKAGE, result.content)
46+
Log.d(ANG_PACKAGE, result.domainPort?:"")
4647
return result
4748
} catch (e: Exception) {
4849
e.printStackTrace()
@@ -73,9 +74,10 @@ object V2rayConfigUtil {
7374

7475
inbounds(v2rayConfig)
7576

76-
outbounds(v2rayConfig, outbound)
77+
val isPlugin = outbound.protocol.equals(EConfigType.HYSTERIA2.name, true)
78+
val retOut = outbounds(v2rayConfig, outbound, isPlugin)
7779

78-
val retMore = moreOutbounds(v2rayConfig, config.subscriptionId)
80+
val retMore = moreOutbounds(v2rayConfig, config.subscriptionId, isPlugin)
7981

8082
routing(v2rayConfig)
8183

@@ -93,7 +95,7 @@ object V2rayConfigUtil {
9395

9496
result.status = true
9597
result.content = v2rayConfig.toPrettyPrinting()
96-
result.domainPort = if (retMore.first) retMore.second else outbound.getServerAddressAndPort()
98+
result.domainPort = if (retMore.first) retMore.second else retOut.second
9799
return result
98100
}
99101

@@ -145,8 +147,8 @@ object V2rayConfigUtil {
145147
return true
146148
}
147149

148-
private fun outbounds(v2rayConfig: V2rayConfig, outbound: V2rayConfig.OutboundBean): Boolean {
149-
if (outbound.protocol.equals(EConfigType.HYSTERIA2.name, true)) {
150+
private fun outbounds(v2rayConfig: V2rayConfig, outbound: V2rayConfig.OutboundBean, isPlugin: Boolean): Pair<Boolean, String> {
151+
if (isPlugin) {
150152
val socksPort = 100 + Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT), AppConfig.PORT_SOCKS.toInt())
151153
val outboundNew = V2rayConfig.OutboundBean(
152154
mux = null,
@@ -165,11 +167,11 @@ object V2rayConfigUtil {
165167
} else {
166168
v2rayConfig.outbounds.add(outboundNew)
167169
}
168-
return true
170+
return Pair(true, outboundNew.getServerAddressAndPort())
169171
}
170172

171173
val ret = updateOutboundWithGlobalSettings(outbound)
172-
if (!ret) return false
174+
if (!ret) return Pair(false, "")
173175

174176
if (v2rayConfig.outbounds.isNotEmpty()) {
175177
v2rayConfig.outbounds[0] = outbound
@@ -178,7 +180,7 @@ object V2rayConfigUtil {
178180
}
179181

180182
updateOutboundFragment(v2rayConfig)
181-
return true
183+
return Pair(true, outbound.getServerAddressAndPort())
182184
}
183185

184186
private fun fakedns(v2rayConfig: V2rayConfig) {
@@ -532,10 +534,13 @@ object V2rayConfigUtil {
532534
return true
533535
}
534536

535-
private fun moreOutbounds(v2rayConfig: V2rayConfig, subscriptionId: String): Pair<Boolean, String> {
537+
private fun moreOutbounds(v2rayConfig: V2rayConfig, subscriptionId: String, isPlugin: Boolean): Pair<Boolean, String> {
536538
val returnPair = Pair(false, "")
537539
var domainPort: String = ""
538540

541+
if (isPlugin) {
542+
return returnPair
543+
}
539544
//fragment proxy
540545
if (settingsStorage?.decodeBool(AppConfig.PREF_FRAGMENT_ENABLED, false) == true) {
541546
return returnPair

app/src/main/kotlin/com/neko/v2ray/util/fmt/Hysteria2Fmt.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ object Hysteria2Fmt {
7575

7676
fun toNativeConfig(config: ServerConfig, socksPort: Int): Hysteria2Bean? {
7777
val outbound = config.getProxyOutbound() ?: return null
78+
val tls = outbound.streamSettings?.tlsSettings
7879
val bean = Hysteria2Bean(
7980
server = outbound.getServerAddressAndPort(),
8081
auth = outbound.getPassword(),
8182
socks5 = Hysteria2Bean.Socks5Bean(
82-
listen = "$LOOPBACK:${socksPort}"
83+
listen = "$LOOPBACK:${socksPort}",
8384
),
84-
tls = Hysteria2Bean.TlsBean(outbound.getServerAddress())
85+
tls = Hysteria2Bean.TlsBean(
86+
sni = tls?.serverName ?: outbound.getServerAddress(),
87+
insecure = tls?.allowInsecure
88+
)
8589
)
8690
return bean
8791
}

0 commit comments

Comments
 (0)