Skip to content

Commit 94775f1

Browse files
committed
Migrate Hysteria2 pinSHA256 to pinnedCA256
Rename and migrate Hysteria2 certificate pin field from pinSHA256 to pinnedCA256 across code and UI, and add a one-time migration at startup. Changes: - Added SettingsManager.migrateHysteria2PinSHA256() and call in AngApplication to copy existing profile.pinSHA256 -> profile.pinnedCA256 and clear the old field, guarded by a migration flag. - Updated Hysteria2Fmt to read/write the query param "pinSHA256" into the new ProfileItem.pinnedCA256 field. - Updated ProfileItem equality to compare pinnedCA256 instead of pinSHA256. - Removed the old EditText binding and reads/writes for et_pinsha256 in ServerActivity; UI now uses et_pinned_ca256 (layout id renamed). - Updated layout and string resources: renamed the label/id to reflect pinned_ca256 and removed legacy pinSHA256 string entries in several locale files. This ensures existing Hysteria2 profiles keep their pin data while the code and UI use the new field name.
1 parent abd23b3 commit 94775f1

File tree

15 files changed

+34
-18
lines changed

15 files changed

+34
-18
lines changed

V2rayNG/app/src/main/java/com/v2ray/ang/AngApplication.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AngApplication : MultiDexApplication() {
4141
WorkManager.initialize(this, workManagerConfiguration)
4242

4343
SettingsManager.initRoutingRulesets(this)
44+
SettingsManager.migrateHysteria2PinSHA256()
4445

4546
es.dmoral.toasty.Toasty.Config.getInstance()
4647
.setGravity(android.view.Gravity.BOTTOM, 0, 200)

V2rayNG/app/src/main/java/com/v2ray/ang/dto/ProfileItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ data class ProfileItem(
124124
&& this.obfsPassword == obj.obfsPassword
125125
&& this.portHopping == obj.portHopping
126126
&& this.portHoppingInterval == obj.portHoppingInterval
127-
&& this.pinSHA256 == obj.pinSHA256
127+
&& this.pinnedCA256 == obj.pinnedCA256
128128
)
129129
}
130130
}

V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object Hysteria2Fmt : FmtBase() {
4444
if (config.portHopping.isNotNullEmpty()) {
4545
config.portHoppingInterval = queryParam["mportHopInt"]
4646
}
47-
config.pinSHA256 = queryParam["pinSHA256"]
47+
config.pinnedCA256 = queryParam["pinSHA256"]
4848

4949
}
5050

@@ -75,8 +75,8 @@ object Hysteria2Fmt : FmtBase() {
7575
if (config.portHoppingInterval.isNotNullEmpty()) {
7676
dicQuery["mportHopInt"] = config.portHoppingInterval.orEmpty()
7777
}
78-
if (config.pinSHA256.isNotNullEmpty()) {
79-
dicQuery["pinSHA256"] = config.pinSHA256.orEmpty()
78+
if (config.pinnedCA256.isNotNullEmpty()) {
79+
dicQuery["pinSHA256"] = config.pinnedCA256.orEmpty()
8080
}
8181

8282
return toUri(config, config.password, dicQuery)

V2rayNG/app/src/main/java/com/v2ray/ang/handler/SettingsManager.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.v2ray.ang.enums.Language
1616
import com.v2ray.ang.dto.ProfileItem
1717
import com.v2ray.ang.enums.RoutingType
1818
import com.v2ray.ang.dto.RulesetItem
19+
import com.v2ray.ang.dto.ServersCache
1920
import com.v2ray.ang.dto.V2rayConfig
2021
import com.v2ray.ang.enums.VpnInterfaceAddressConfig
2122
import com.v2ray.ang.handler.MmkvManager.decodeServerConfig
@@ -422,4 +423,30 @@ object SettingsManager {
422423
MmkvManager.encodeSettings(key, default)
423424
}
424425
}
426+
427+
fun migrateHysteria2PinSHA256() {
428+
// Check if migration has already been done
429+
val migrationKey = "hysteria2_pin_sha256_migrated"
430+
if (MmkvManager.decodeSettingsBool(migrationKey, false)) {
431+
return
432+
}
433+
434+
val serverList = decodeServerList()
435+
436+
for (guid in serverList) {
437+
val profile = decodeServerConfig(guid) ?: continue
438+
if (profile.configType != EConfigType.HYSTERIA2) {
439+
continue
440+
}
441+
if (profile.pinSHA256.isNullOrEmpty() || !profile.pinnedCA256.isNullOrEmpty()) {
442+
continue
443+
}
444+
profile.pinnedCA256 = profile.pinSHA256
445+
profile.pinSHA256 = null
446+
MmkvManager.encodeServerConfig(guid, profile)
447+
}
448+
449+
MmkvManager.encodeSettings(migrationKey, true)
450+
}
451+
425452
}

V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class ServerActivity : BaseActivity() {
129129
private val et_obfs_password: EditText? by lazy { findViewById(R.id.et_obfs_password) }
130130
private val et_port_hop: EditText? by lazy { findViewById(R.id.et_port_hop) }
131131
private val et_port_hop_interval: EditText? by lazy { findViewById(R.id.et_port_hop_interval) }
132-
private val et_pinsha256: EditText? by lazy { findViewById(R.id.et_pinsha256) }
133132
private val et_bandwidth_down: EditText? by lazy { findViewById(R.id.et_bandwidth_down) }
134133
private val et_bandwidth_up: EditText? by lazy { findViewById(R.id.et_bandwidth_up) }
135134
private val et_extra: EditText? by lazy { findViewById(R.id.et_extra) }
@@ -367,7 +366,6 @@ class ServerActivity : BaseActivity() {
367366
et_obfs_password?.text = Utils.getEditable(config.obfsPassword)
368367
et_port_hop?.text = Utils.getEditable(config.portHopping)
369368
et_port_hop_interval?.text = Utils.getEditable(config.portHoppingInterval)
370-
et_pinsha256?.text = Utils.getEditable(config.pinSHA256)
371369
et_bandwidth_down?.text = Utils.getEditable(config.bandwidthDown)
372370
et_bandwidth_up?.text = Utils.getEditable(config.bandwidthUp)
373371
}
@@ -536,7 +534,6 @@ class ServerActivity : BaseActivity() {
536534
config.obfsPassword = et_obfs_password?.text?.toString()
537535
config.portHopping = et_port_hop?.text?.toString()
538536
config.portHoppingInterval = et_port_hop_interval?.text?.toString()
539-
config.pinSHA256 = et_pinsha256?.text?.toString()
540537
config.bandwidthDown = et_bandwidth_down?.text?.toString()
541538
config.bandwidthUp = et_bandwidth_up?.text?.toString()
542539
}

V2rayNG/app/src/main/res/layout/layout_tls_hysteria2.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
<TextView
8181
android:layout_width="wrap_content"
8282
android:layout_height="wrap_content"
83-
android:text="@string/server_lab_stream_pinsha256" />
83+
android:text="@string/server_lab_pinned_ca256" />
8484

8585
<EditText
86-
android:id="@+id/et_pinsha256"
86+
android:id="@+id/et_pinned_ca256"
8787
android:layout_width="match_parent"
8888
android:layout_height="wrap_content"
8989
android:inputType="text" />

V2rayNG/app/src/main/res/values-ar/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
<string name="server_obfs_password">Obfs password</string>
110110
<string name="server_lab_port_hop">Port Hopping</string>
111111
<string name="server_lab_port_hop_interval">Port Hopping Interval</string>
112-
<string name="server_lab_stream_pinsha256">pinSHA256</string>
113112
<string name="server_lab_bandwidth_down">Bandwidth down (Supported units: k/m/g/t)</string>
114113
<string name="server_lab_bandwidth_up">Bandwidth up (Supported units: k/m/g/t)</string>
115114
<string name="server_lab_xhttp_mode">XHTTP Mode</string>

V2rayNG/app/src/main/res/values-bn/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
<string name="server_obfs_password">Obfs password</string>
109109
<string name="server_lab_port_hop">Port Hopping</string>
110110
<string name="server_lab_port_hop_interval">Port Hopping Interval</string>
111-
<string name="server_lab_stream_pinsha256">pinSHA256</string>
112111
<string name="server_lab_bandwidth_down">Bandwidth down (Supported units: k/m/g/t)</string>
113112
<string name="server_lab_bandwidth_up">Bandwidth up (Supported units: k/m/g/t)</string>
114113
<string name="server_lab_xhttp_mode">XHTTP Mode</string>

V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
<string name="server_obfs_password">رزم obfs</string>
109109
<string name="server_lab_port_hop">پورت گوم (درگا سرورن ز نۊ هؽل اکونه)</string>
110110
<string name="server_lab_port_hop_interval">فاسله پورت گوم (سانیه)</string>
111-
<string name="server_lab_stream_pinsha256">pinSHA256</string>
112111
<string name="server_lab_bandwidth_down">ب لم ٱووڌن پئنا باند (واهڌ)</string>
113112
<string name="server_lab_bandwidth_up">وا روء رئڌن پئنا باند (واهڌ)</string>
114113
<string name="server_lab_xhttp_mode">هالت XHTTP</string>

V2rayNG/app/src/main/res/values-fa/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
<string name="server_obfs_password">رمز عبور obfs</string>
109109
<string name="server_lab_port_hop">پورت پرش (درگاه سرور را بازنویسی می کند)</string>
110110
<string name="server_lab_port_hop_interval">فاصله پورت پرش (ثانیه)</string>
111-
<string name="server_lab_stream_pinsha256">pinSHA256</string>
112111
<string name="server_lab_bandwidth_down">کاهش پهنای باند (واحد)</string>
113112
<string name="server_lab_bandwidth_up">افزایش پهنای باند (واحد)</string>
114113
<string name="server_lab_xhttp_mode">حالت XHTTP</string>

0 commit comments

Comments
 (0)