Skip to content

Commit

Permalink
Merge pull request #1689 from BI7PRK/master
Browse files Browse the repository at this point in the history
Add uTLS option
  • Loading branch information
2dust committed Oct 14, 2022
2 parents 02bc466 + 0ae459a commit 1987880
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 185 deletions.
2 changes: 1 addition & 1 deletion V2rayNG/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
buildToolsVersion "$buildToolsVer"

compileOptions {
targetCompatibility = "8"
targetCompatibility = "11"
sourceCompatibility = "8"
}

Expand Down
5 changes: 3 additions & 2 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/V2rayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ data class V2rayConfig(
return sni
}

fun populateTlsSettings(streamSecurity: String, allowInsecure: Boolean, sni: String) {
fun populateTlsSettings(streamSecurity: String, allowInsecure: Boolean, sni: String, fingerprint: String?) {
security = streamSecurity
val tlsSetting = TlsSettingsBean(
allowInsecure = allowInsecure,
serverName = sni
serverName = sni,
fingerprint = fingerprint
)
if (security == TLS) {
tlsSettings = tlsSetting
Expand Down
15 changes: 13 additions & 2 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ServerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class ServerActivity : BaseActivity() {
private val allowinsecures: Array<out String> by lazy {
resources.getStringArray(R.array.allowinsecures)
}

private val uTlsItems: Array<out String> by lazy {
resources.getStringArray(R.array.streamsecurity_utls)
}
// Kotlin synthetics was used, but since it is removed in 1.8. We switch to old manual approach.
// We don't use AndroidViewBinding because, it is better to share similar logics for different
// protocols. Use findViewById manually ensures the xml are de-coupled with the activity logic.
Expand All @@ -82,6 +84,7 @@ class ServerActivity : BaseActivity() {
private val sp_stream_security: Spinner? by lazy { findViewById(R.id.sp_stream_security) }
private val sp_allow_insecure: Spinner? by lazy { findViewById(R.id.sp_allow_insecure) }
private val et_sni: EditText? by lazy { findViewById(R.id.et_sni) }
private val sp_stream_fingerprint: Spinner? by lazy { findViewById(R.id.sp_stream_fingerprint) } //uTLS
private val sp_network: Spinner? by lazy { findViewById(R.id.sp_network) }
private val sp_header_type: Spinner? by lazy { findViewById(R.id.sp_header_type) }
private val sp_header_type_title: TextView? by lazy { findViewById(R.id.sp_header_type_title) }
Expand Down Expand Up @@ -170,6 +173,12 @@ class ServerActivity : BaseActivity() {
sp_allow_insecure?.setSelection(allowinsecure)
}
et_sni?.text = Utils.getEditable(tlsSetting.serverName)

tlsSetting.fingerprint?.let {
val utlsIndex = Utils.arrayFind(uTlsItems, tlsSetting.fingerprint)
sp_stream_fingerprint?.setSelection(utlsIndex)
}

}
}
val network = Utils.arrayFind(networks, streamSetting.network)
Expand Down Expand Up @@ -310,6 +319,7 @@ class ServerActivity : BaseActivity() {
val sniField = et_sni?.text?.toString()?.trim() ?: return
val allowInsecureField = sp_allow_insecure?.selectedItemPosition ?: return
val streamSecurity = sp_stream_security?.selectedItemPosition ?: return
var utlsIndex = sp_stream_fingerprint?.selectedItemPosition ?: return

var sni = streamSetting.populateTransportSettings(
transport = networks[network],
Expand All @@ -330,7 +340,8 @@ class ServerActivity : BaseActivity() {
} else {
allowinsecures[allowInsecureField].toBoolean()
}
streamSetting.populateTlsSettings(streamSecuritys[streamSecurity], allowInsecure, sni)

streamSetting.populateTlsSettings(streamSecuritys[streamSecurity], allowInsecure, sni, uTlsItems[utlsIndex])
}

private fun transportTypes(network: String?): Array<out String> {
Expand Down
24 changes: 17 additions & 7 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ object AngConfigManager {
} else {
vmessBean.allowInsecure.toBoolean()
}
var fingerprint = streamSetting.tlsSettings?.fingerprint
streamSetting.populateTlsSettings(vmessBean.streamSecurity, allowInsecure,
vmessBean.sni.ifBlank { sni })
vmessBean.sni.ifBlank { sni }, fingerprint)
}
}
val key = MmkvManager.encodeServerConfig(vmessBean.guid, config)
Expand Down Expand Up @@ -185,6 +186,9 @@ object AngConfigManager {
config = ServerConfig.create(EConfigType.VMESS)
val streamSetting = config.outboundBean?.streamSettings ?: return -1

var fingerprint = streamSetting.tlsSettings?.fingerprint


if (!tryParseNewVmess(str, config, allowInsecure)) {
if (str.indexOf("?") > 0) {
if (!tryResolveVmess4Kitsunebi(str, config)) {
Expand Down Expand Up @@ -216,8 +220,10 @@ object AngConfigManager {
}
val sni = streamSetting.populateTransportSettings(vmessQRCode.net, vmessQRCode.type, vmessQRCode.host,
vmessQRCode.path, vmessQRCode.path, vmessQRCode.host, vmessQRCode.path, vmessQRCode.type, vmessQRCode.path)


streamSetting.populateTlsSettings(vmessQRCode.tls, allowInsecure,
if (TextUtils.isEmpty(vmessQRCode.sni)) sni else vmessQRCode.sni)
if (TextUtils.isEmpty(vmessQRCode.sni)) sni else vmessQRCode.sni, fingerprint)
}
}
} else if (str.startsWith(EConfigType.SHADOWSOCKS.protocolScheme)) {
Expand Down Expand Up @@ -292,17 +298,19 @@ object AngConfigManager {
config.remarks = Utils.urlDecode(uri.fragment ?: "")

var flow = ""
var fingerprint = config.outboundBean?.streamSettings?.tlsSettings?.fingerprint
if (uri.rawQuery != null) {
val queryParam = uri.rawQuery.split("&")
.associate { it.split("=").let { (k, v) -> k to Utils.urlDecode(v) } }

val sni = config.outboundBean?.streamSettings?.populateTransportSettings(queryParam["type"] ?: "tcp", queryParam["headerType"],
queryParam["host"], queryParam["path"], queryParam["seed"], queryParam["quicSecurity"], queryParam["key"],
queryParam["mode"], queryParam["serviceName"])
config.outboundBean?.streamSettings?.populateTlsSettings(queryParam["security"] ?: TLS, allowInsecure, queryParam["sni"] ?: sni!!)
config.outboundBean?.streamSettings?.populateTlsSettings(queryParam["security"] ?: TLS, allowInsecure, queryParam["sni"] ?: sni!!, fingerprint)
flow = queryParam["flow"] ?: ""
} else {
config.outboundBean?.streamSettings?.populateTlsSettings(TLS, allowInsecure, "")

config.outboundBean?.streamSettings?.populateTlsSettings(TLS, allowInsecure, "", fingerprint)
}

config.outboundBean?.settings?.servers?.get(0)?.let { server ->
Expand All @@ -317,6 +325,8 @@ object AngConfigManager {
.associate { it.split("=").let { (k, v) -> k to Utils.urlDecode(v) } }
config = ServerConfig.create(EConfigType.VLESS)
val streamSetting = config.outboundBean?.streamSettings ?: return -1
var fingerprint = streamSetting.tlsSettings?.fingerprint

config.remarks = Utils.urlDecode(uri.fragment ?: "")
config.outboundBean?.settings?.vnext?.get(0)?.let { vnext ->
vnext.address = uri.idnHost
Expand All @@ -329,7 +339,7 @@ object AngConfigManager {
val sni = streamSetting.populateTransportSettings(queryParam["type"] ?: "tcp", queryParam["headerType"],
queryParam["host"], queryParam["path"], queryParam["seed"], queryParam["quicSecurity"], queryParam["key"],
queryParam["mode"], queryParam["serviceName"])
streamSetting.populateTlsSettings(queryParam["security"] ?: "", allowInsecure, queryParam["sni"] ?: sni)
streamSetting.populateTlsSettings(queryParam["security"] ?: "", allowInsecure, queryParam["sni"] ?: sni, fingerprint)
}
if (config == null){
return R.string.toast_incorrect_protocol
Expand Down Expand Up @@ -369,12 +379,12 @@ object AngConfigManager {
vnext.users[0].security = DEFAULT_SECURITY
vnext.users[0].alterId = alterId.toInt()
}

var fingerprint = streamSetting.tlsSettings?.fingerprint
val sni = streamSetting.populateTransportSettings(protocol, queryParam["type"],
queryParam["host"]?.split("|")?.get(0) ?: "",
queryParam["path"]?.takeIf { it.trim() != "/" } ?: "", queryParam["seed"], queryParam["security"],
queryParam["key"], queryParam["mode"], queryParam["serviceName"])
streamSetting.populateTlsSettings(if (tls) TLS else "", allowInsecure, sni)
streamSetting.populateTlsSettings(if (tls) TLS else "", allowInsecure, sni, fingerprint)
true
}.getOrElse { false }
}
Expand Down
59 changes: 1 addition & 58 deletions V2rayNG/app/src/main/res/layout/activity_server_trojan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,64 +202,7 @@
android:inputType="text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_stream_security" />

<Spinner
android:id="@+id/sp_stream_security"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:entries="@array/streamsecurityxs"
android:nextFocusDown="@+id/et_sni" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_sni" />

<EditText
android:id="@+id/et_sni"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:inputType="text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_allow_insecure" />

<Spinner
android:id="@+id/sp_allow_insecure"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:entries="@array/allowinsecures"
android:nextFocusUp="@+id/et_sni" />

</LinearLayout>

<include layout="@layout/tls_layout" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
58 changes: 1 addition & 57 deletions V2rayNG/app/src/main/res/layout/activity_server_vless.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,63 +223,7 @@
android:inputType="text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_stream_security" />

<Spinner
android:id="@+id/sp_stream_security"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:entries="@array/streamsecurityxs"
android:nextFocusDown="@+id/et_sni" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_sni" />

<EditText
android:id="@+id/et_sni"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:inputType="text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_allow_insecure" />

<Spinner
android:id="@+id/sp_allow_insecure"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:entries="@array/allowinsecures"
android:nextFocusUp="@+id/et_sni" />

</LinearLayout>
<include layout="@layout/tls_layout" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
59 changes: 1 addition & 58 deletions V2rayNG/app/src/main/res/layout/activity_server_vmess.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,64 +222,7 @@
android:inputType="text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_stream_security" />

<Spinner
android:id="@+id/sp_stream_security"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:entries="@array/streamsecuritys"
android:nextFocusDown="@+id/et_sni" />

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_sni" />

<EditText
android:id="@+id/et_sni"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:inputType="text" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_top_height"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_allow_insecure" />

<Spinner
android:id="@+id/sp_allow_insecure"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:entries="@array/allowinsecures"
android:nextFocusUp="@+id/et_sni" />

</LinearLayout>
<include layout="@layout/tls_layout" />

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 1987880

Please sign in to comment.