Skip to content

Commit

Permalink
feat: add clash format parsing for WireGuard and SSH
Browse files Browse the repository at this point in the history
  • Loading branch information
Restia-Ashbell committed Oct 22, 2024
1 parent fbc697f commit ee15946
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SSHBean extends AbstractBean {
public String privateKey;
public String privateKeyPassphrase;
public String publicKey;
public String publicKeyAlgorithms;

@Override
public void initializeDefaultValues() {
Expand All @@ -35,6 +36,7 @@ public void initializeDefaultValues() {
if (privateKey == null) privateKey = "";
if (privateKeyPassphrase == null) privateKeyPassphrase = "";
if (publicKey == null) publicKey = "";
if (publicKeyAlgorithms == null) publicKeyAlgorithms = "";
}

@Override
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/io/nekohasekai/sagernet/group/RawUpdater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.nekohasekai.sagernet.fmt.shadowsocks.parseShadowsocks
import io.nekohasekai.sagernet.fmt.shadowsocksr.ShadowsocksRBean
import io.nekohasekai.sagernet.fmt.shadowsocksr.parseShadowsocksR
import io.nekohasekai.sagernet.fmt.socks.SOCKSBean
import io.nekohasekai.sagernet.fmt.ssh.SSHBean
import io.nekohasekai.sagernet.fmt.trojan.TrojanBean
import io.nekohasekai.sagernet.fmt.trojan_go.parseTrojanGo
import io.nekohasekai.sagernet.fmt.tuic.TuicBean
Expand Down Expand Up @@ -625,6 +626,42 @@ object RawUpdater : GroupUpdater() {
}
proxies.add(bean)
}

"wireguard" -> {
proxies.add(WireGuardBean().apply {
for (opt in proxy) {
when (opt.key) {
"name" -> name = opt.value?.toString()
"server" -> serverAddress = opt.value as String
"port" -> serverPort = opt.value.toString().toInt()
"ip", "ipv6" -> localAddress = opt.value as String
"private-key" -> privateKey = opt.value as String
"public-key" -> peerPublicKey = opt.value as String
"pre-shared-key" -> peerPreSharedKey = opt.value?.toString()
"reserved" -> reserved = opt.value?.toString()
"mtu" -> mtu = opt.value?.toString()?.toInt()
}
}
})
}

"ssh" -> {
proxies.add(SSHBean().apply {
for (opt in proxy) {
when (opt.key) {
"name" -> name = opt.value?.toString()
"server" -> serverAddress = opt.value as String
"port" -> serverPort = opt.value.toString().toInt()
"username" -> username = opt.value as String
"password" -> password = opt.value?.toString()
"private-key" -> privateKey = opt.value?.toString()
"private-key-passphrase" -> privateKeyPassphrase = opt.value?.toString()
"host-key" -> publicKey = opt.value?.toString()
"host-key-algorithms" -> publicKeyAlgorithms = opt.value?.toString()
}
}
})
}
}
}

Expand Down

0 comments on commit ee15946

Please sign in to comment.