Commit 87b1496f authored by Mygod's avatar Mygod

Handle illegal profiles properly

parent bbc908a5
......@@ -221,13 +221,6 @@ object BaseService {
fun onBind(intent: Intent): IBinder? = if (intent.action == Action.SERVICE) data.binder else null
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
when {
s == State.Stopped -> startRunner()
......@@ -330,10 +323,14 @@ object BaseService {
return Service.START_NOT_STICKY
}
val (profile, fallback) = expanded
profile.name = profile.formattedName // save name for later queries
val proxy = ProxyInstance(profile)
data.proxy = proxy
try {
data.proxy = ProxyInstance(profile)
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
if (!data.closeReceiverRegistered) {
......@@ -369,7 +366,7 @@ object BaseService {
}
startProcesses()
proxy.scheduleUpdate()
data.proxy!!.scheduleUpdate()
data.udpFallback?.scheduleUpdate()
data.changeState(State.Connected)
......
......@@ -21,8 +21,10 @@
package com.github.shadowsocks.bg
import android.content.Context
import com.github.shadowsocks.Core.app
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.acl.AclSyncer
import com.github.shadowsocks.core.R
import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.plugin.PluginManager
......@@ -39,6 +41,9 @@ import java.net.URISyntaxException
*/
class ProxyInstance(val profile: Profile, private val route: String = profile.route) {
init {
require(profile.host.isNotEmpty() && (profile.method == "none" || profile.password.isEmpty())) {
app.getString(R.string.proxy_empty)
}
// check the crypto
require(profile.method !in arrayOf("aes-192-gcm", "chacha20", "salsa20")) {
"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