Skip to content

Commit 151c67a

Browse files
committed
fix: include I1-I5 in AmneziaWG conf detection; correct error wording
- isAmneziaWGConf now also checks the CPS signature keys I1-I5, so a .conf carrying only those AmneziaWG fields is no longer misparsed as plain WireGuard (dropping the AWG params). (CodeRabbit, Greptile) - parseAmneziaWG error messages: 'selection' -> 'section'. (Greptile)
1 parent f64c414 commit 151c67a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/group/RawUpdater.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -985,19 +985,23 @@ object RawUpdater : GroupUpdater() {
985985
private fun isAmneziaWGConf(conf: String): Boolean {
986986
return try {
987987
val iface = Ini(StringReader(conf))["Interface"] ?: return false
988-
listOf("Jc", "Jmin", "Jmax", "S1", "S2", "S3", "S4", "H1", "H2", "H3", "H4")
989-
.any { !iface[it].isNullOrBlank() }
988+
listOf(
989+
"Jc", "Jmin", "Jmax",
990+
"S1", "S2", "S3", "S4",
991+
"H1", "H2", "H3", "H4",
992+
"I1", "I2", "I3", "I4", "I5",
993+
).any { !iface[it].isNullOrBlank() }
990994
} catch (e: Exception) {
991995
false
992996
}
993997
}
994998

995999
fun parseAmneziaWG(conf: String): List<AmneziaWGBean> {
9961000
val ini = Ini(StringReader(conf))
997-
val iface = ini["Interface"] ?: error("Missing 'Interface' selection")
1001+
val iface = ini["Interface"] ?: error("Missing 'Interface' section")
9981002
val bean = AmneziaWGBean().applyDefaultValues()
9991003
val localAddresses = iface.getAll("Address")
1000-
if (localAddresses.isNullOrEmpty()) error("Empty address in 'Interface' selection")
1004+
if (localAddresses.isNullOrEmpty()) error("Empty address in 'Interface' section")
10011005
bean.localAddress = localAddresses.flatMap { it.split(",") }.joinToString("\n")
10021006
bean.privateKey = iface["PrivateKey"]
10031007
iface["MTU"]?.toIntOrNull()?.let { bean.mtu = it }
@@ -1019,7 +1023,7 @@ object RawUpdater : GroupUpdater() {
10191023
bean.i4 = iface["I4"] ?: ""
10201024
bean.i5 = iface["I5"] ?: ""
10211025
val peers = ini.getAll("Peer")
1022-
if (peers.isNullOrEmpty()) error("Missing 'Peer' selections")
1026+
if (peers.isNullOrEmpty()) error("Missing 'Peer' sections")
10231027
val beans = mutableListOf<AmneziaWGBean>()
10241028
for (peer in peers) {
10251029
val endpoint = peer["Endpoint"]

0 commit comments

Comments
 (0)