[PR #6651] [MERGED] fix(sub): emit Hysteria certificate pin for Mihomo #6396

Closed
opened 2026-11-02 04:08:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6651
Author: @libmur-dev
Created: 9/25/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei

Base: main ← Head: fix/hysteria-mihomo-certificate-pin


📝 Commits (2)

  • e2cca36 fix(sub): emit Hysteria certificate pin for Mihomo
  • 9ad794f Merge branch 'main' into fix/hysteria-mihomo-certificate-pin

📊 Changes

2 files changed (+120 additions, -0 deletions)

View changed files

📝 internal/sub/clash_service.go (+46 -0)
📝 internal/sub/clash_service_test.go (+74 -0)

📄 Description

Summary

Emit Hysteria/Hysteria2 server certificate pins as Mihomo's fingerprint field
in Clash/Mihomo subscriptions. Preserve client-fingerprint as the separate
uTLS client setting.

Why

For an IP-based Hysteria2 inbound with a self-signed certificate,
pinnedPeerCertSha256 already appears as pinSHA256 in the raw share link, but
buildHysteriaProxy drops it from /clash/ and /mihomo/ YAML. Mihomo then
fails certificate verification when allowInsecure is disabled:

tls: failed to verify certificate: x509: certificate signed by unknown authority

The change normalizes the configured pin with the existing hysteriaPinHex
logic, validates that it is a SHA-256 value, formats it as colon-separated
uppercase bytes, and emits it as fingerprint. It also honors an external
endpoint pin override. Mihomo supports only one certificate fingerprint, so
when multiple pins are configured the first valid pin is exported in
configuration order.

Refs #4683. Related to #4818 and #4948.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  1. Added TestBuildHysteriaProxyIncludesCertificateFingerprint, using a
    deterministic SHA-256 value and TEST-NET address, and verifying that an
    external endpoint pin overrides the inbound pin.

  2. Added table-driven coverage confirming that an invalid first pin falls back
    to the second valid pin and that two valid pins select the first.

  3. Ran:

    go test ./internal/sub -run 'TestBuildHysteriaProxyIncludesCertificateFingerprint|TestMihomoCertFingerprintUsesFirstValidPin|TestHysteriaPinHex' -count=1
    

    Result: ok github.com/mhsanaei/3x-ui/v3/internal/sub 0.034s.

  4. Ran go test ./... successfully on Ubuntu 24.04 with Go 1.27.1.

  5. Ran go build ./... successfully in the same environment.

  6. Built and deployed a Linux amd64 panel binary from v3.8.5 on Debian 12.

  7. Before the change, a valid subscription contained two Hysteria2 nodes and
    zero certificate fingerprint fields. After the change, it contained the
    same two nodes and one expected certificate fingerprint field.

  8. Refreshed the subscription in FlClashX 0.4.2 with Mihomo 1.19.28 and
    confirmed that the previously failing Hysteria2 node connected.

Screenshots / recordings

N/A — backend subscription serialization only.

Breaking changes

None. Existing Hysteria subscriptions without a valid configured certificate
pin are unchanged.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: N/A, no frontend files changed.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
    N/A, this restores an already configured certificate pin in another
    subscription format.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6651 **Author:** [@libmur-dev](https://github.com/libmur-dev) **Created:** 9/25/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/hysteria-mihomo-certificate-pin` --- ### 📝 Commits (2) - [`e2cca36`](https://github.com/MHSanaei/3x-ui/commit/e2cca36731b2816485e5a386f769081af6ff0fb3) fix(sub): emit Hysteria certificate pin for Mihomo - [`9ad794f`](https://github.com/MHSanaei/3x-ui/commit/9ad794ff3df39de79bc3b3abc792725f88939cf7) Merge branch 'main' into fix/hysteria-mihomo-certificate-pin ### 📊 Changes **2 files changed** (+120 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/clash_service.go` (+46 -0) 📝 `internal/sub/clash_service_test.go` (+74 -0) </details> ### 📄 Description ## Summary Emit Hysteria/Hysteria2 server certificate pins as Mihomo's `fingerprint` field in Clash/Mihomo subscriptions. Preserve `client-fingerprint` as the separate uTLS client setting. ## Why For an IP-based Hysteria2 inbound with a self-signed certificate, `pinnedPeerCertSha256` already appears as `pinSHA256` in the raw share link, but `buildHysteriaProxy` drops it from `/clash/` and `/mihomo/` YAML. Mihomo then fails certificate verification when `allowInsecure` is disabled: ```text tls: failed to verify certificate: x509: certificate signed by unknown authority ``` The change normalizes the configured pin with the existing `hysteriaPinHex` logic, validates that it is a SHA-256 value, formats it as colon-separated uppercase bytes, and emits it as `fingerprint`. It also honors an external endpoint pin override. Mihomo supports only one certificate `fingerprint`, so when multiple pins are configured the first valid pin is exported in configuration order. Refs #4683. Related to #4818 and #4948. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? 1. Added `TestBuildHysteriaProxyIncludesCertificateFingerprint`, using a deterministic SHA-256 value and TEST-NET address, and verifying that an external endpoint pin overrides the inbound pin. 2. Added table-driven coverage confirming that an invalid first pin falls back to the second valid pin and that two valid pins select the first. 3. Ran: ```bash go test ./internal/sub -run 'TestBuildHysteriaProxyIncludesCertificateFingerprint|TestMihomoCertFingerprintUsesFirstValidPin|TestHysteriaPinHex' -count=1 ``` Result: `ok github.com/mhsanaei/3x-ui/v3/internal/sub 0.034s`. 4. Ran `go test ./...` successfully on Ubuntu 24.04 with Go 1.27.1. 5. Ran `go build ./...` successfully in the same environment. 6. Built and deployed a Linux amd64 panel binary from v3.8.5 on Debian 12. 7. Before the change, a valid subscription contained two Hysteria2 nodes and zero certificate `fingerprint` fields. After the change, it contained the same two nodes and one expected certificate `fingerprint` field. 8. Refreshed the subscription in FlClashX 0.4.2 with Mihomo 1.19.28 and confirmed that the previously failing Hysteria2 node connected. ## Screenshots / recordings N/A — backend subscription serialization only. ## Breaking changes None. Existing Hysteria subscriptions without a valid configured certificate pin are unchanged. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: N/A, no frontend files changed. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. N/A, this restores an already configured certificate pin in another subscription format. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:28 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6396
No description provided.