Skip to content

Commit

Permalink
support fp share link
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Mar 16, 2023
1 parent 7354a1f commit dc1515d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
18 changes: 15 additions & 3 deletions app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/V2RayFmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ fun StandardV2RayBean.parseDuckSoft(url: HttpUrl) {
encryption = it
}
}

url.queryParameter("fp")?.let {
utlsFingerprint = it
}
}

// 不确定是谁的格式
Expand Down Expand Up @@ -266,7 +270,8 @@ fun parseV2RayN(link: String): VMessBean {

bean.name = json.getStr("ps") ?: ""
bean.sni = json.getStr("sni") ?: bean.host
bean.security = json.getStr("tls")
bean.security = json.getStr("tls") ?: "none"
bean.utlsFingerprint = json.getStr("fp") ?: ""

if (json.optInt("v", 2) < 2) {
when (bean.type) {
Expand Down Expand Up @@ -354,7 +359,8 @@ data class VmessQRCode(
var path: String = "",
var tls: String = "",
var sni: String = "",
var alpn: String = ""
var alpn: String = "",
var fp: String = "",
)

fun VMessBean.toV2rayN(): String {
Expand All @@ -379,6 +385,7 @@ fun VMessBean.toV2rayN(): String {
tls = if (this@toV2rayN.security == "tls") "tls" else ""
sni = this@toV2rayN.sni
scy = this@toV2rayN.encryption
fp = this@toV2rayN.utlsFingerprint
}.let {
NGUtil.encode(Gson().toJson(it))
}
Expand Down Expand Up @@ -438,7 +445,12 @@ fun StandardV2RayBean.toUri(standard: Boolean = true): String {
if (certificates.isNotBlank()) {
builder.addQueryParameter("cert", certificates)
}
if (allowInsecure) builder.addQueryParameter("allowInsecure", "1")
if (allowInsecure) {
builder.addQueryParameter("allowInsecure", "1")
}
if (utlsFingerprint.isNotBlank()) {
builder.addQueryParameter("fp", utlsFingerprint)
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/io/nekohasekai/sagernet/group/RawUpdater.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.nekohasekai.sagernet.group

import android.annotation.SuppressLint
import android.net.Uri
import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.database.*
Expand Down Expand Up @@ -30,6 +31,7 @@ import java.io.StringReader
@Suppress("EXPERIMENTAL_API_USAGE")
object RawUpdater : GroupUpdater() {

@SuppressLint("Recycle")
override suspend fun doUpdate(
proxyGroup: ProxyGroup,
subscription: SubscriptionBean,
Expand Down Expand Up @@ -283,6 +285,8 @@ object RawUpdater : GroupUpdater() {
"h2" -> bean.type = "http"
}
}
"client-fingerprint" -> bean.utlsFingerprint =
opt.value as String
"tls" -> bean.security =
if (opt.value?.toString() == "true") "tls" else ""
"skip-cert-verify" -> bean.allowInsecure =
Expand Down Expand Up @@ -354,6 +358,8 @@ object RawUpdater : GroupUpdater() {
"server" -> bean.serverAddress = opt.value as String
"port" -> bean.serverPort = opt.value.toString().toInt()
"password" -> bean.password = opt.value?.toString()
"client-fingerprint" -> bean.utlsFingerprint =
opt.value as String
"sni" -> bean.sni = opt.value?.toString()
"skip-cert-verify" -> bean.allowInsecure =
opt.value?.toString() == "true"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun Project.requireFlavor(): String {
fun Project.requireMetadata(): Properties {
if (!::metadata.isInitialized) {
metadata = Properties().apply {
load(rootProject.file("sager.properties").inputStream())
load(rootProject.file("nb4a.properties").inputStream())
}
}
return metadata
Expand Down
File renamed without changes.

0 comments on commit dc1515d

Please sign in to comment.