Commit 87b1496f authored by Mygod's avatar Mygod

Handle illegal profiles properly

parent bbc908a5
...@@ -221,13 +221,6 @@ object BaseService { ...@@ -221,13 +221,6 @@ object BaseService {
fun onBind(intent: Intent): IBinder? = if (intent.action == Action.SERVICE) data.binder else null fun onBind(intent: Intent): IBinder? = if (intent.action == Action.SERVICE) data.binder else null
fun forceLoad() { fun forceLoad() {
val (profile, fallback) = Core.currentProfile
?: return stopRunner(false, (this as Context).getString(R.string.profile_empty))
if (profile.host.isEmpty() || (!profile.method.equals("none") && profile.password.isEmpty()) ||
fallback != null && (fallback.host.isEmpty() || (!fallback.method.equals("none") && fallback.password.isEmpty()))) {
stopRunner(false, (this as Context).getString(R.string.proxy_empty))
return
}
val s = data.state val s = data.state
when { when {
s == State.Stopped -> startRunner() s == State.Stopped -> startRunner()
...@@ -330,10 +323,14 @@ object BaseService { ...@@ -330,10 +323,14 @@ object BaseService {
return Service.START_NOT_STICKY return Service.START_NOT_STICKY
} }
val (profile, fallback) = expanded val (profile, fallback) = expanded
profile.name = profile.formattedName // save name for later queries try {
val proxy = ProxyInstance(profile) data.proxy = ProxyInstance(profile)
data.proxy = proxy
data.udpFallback = if (fallback == null) null else ProxyInstance(fallback, profile.route) data.udpFallback = if (fallback == null) null else ProxyInstance(fallback, profile.route)
} catch (e: IllegalArgumentException) {
data.notification = createNotification("")
stopRunner(false, e.message)
return Service.START_NOT_STICKY
}
BootReceiver.enabled = DataStore.persistAcrossReboot BootReceiver.enabled = DataStore.persistAcrossReboot
if (!data.closeReceiverRegistered) { if (!data.closeReceiverRegistered) {
...@@ -369,7 +366,7 @@ object BaseService { ...@@ -369,7 +366,7 @@ object BaseService {
} }
startProcesses() startProcesses()
proxy.scheduleUpdate() data.proxy!!.scheduleUpdate()
data.udpFallback?.scheduleUpdate() data.udpFallback?.scheduleUpdate()
data.changeState(State.Connected) data.changeState(State.Connected)
......
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
package com.github.shadowsocks.bg package com.github.shadowsocks.bg
import android.content.Context import android.content.Context
import com.github.shadowsocks.Core.app
import com.github.shadowsocks.acl.Acl import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.acl.AclSyncer import com.github.shadowsocks.acl.AclSyncer
import com.github.shadowsocks.core.R
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.PluginConfiguration import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.plugin.PluginManager import com.github.shadowsocks.plugin.PluginManager
...@@ -39,6 +41,9 @@ import java.net.URISyntaxException ...@@ -39,6 +41,9 @@ import java.net.URISyntaxException
*/ */
class ProxyInstance(val profile: Profile, private val route: String = profile.route) { class ProxyInstance(val profile: Profile, private val route: String = profile.route) {
init { init {
require(profile.host.isNotEmpty() && (profile.method == "none" || profile.password.isEmpty())) {
app.getString(R.string.proxy_empty)
}
// check the crypto // check the crypto
require(profile.method !in arrayOf("aes-192-gcm", "chacha20", "salsa20")) { require(profile.method !in arrayOf("aes-192-gcm", "chacha20", "salsa20")) {
"cipher ${profile.method} is deprecated." "cipher ${profile.method} is deprecated."
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment