fix(sub): emit Hysteria certificate pin for Mihomo (#6651)

buildHysteriaProxy dropped pinnedPeerCertSha256 from Clash/Mihomo YAML although the raw share link already carries it as pinSHA256, so Mihomo rejected a self-signed Hysteria2 certificate whenever allowInsecure was off.

Emit the first valid SHA-256 pin as Mihomo's fingerprint field in its colon-separated form, honouring an external endpoint's override. client-fingerprint stays the uTLS setting. Mihomo accepts a single fingerprint, so of several pins the first valid one wins.

Refs #4683.
This commit is contained in:
libmur-dev
2026-09-26 21:31:42 +03:00
committed by GitHub
parent ee2ff48c81
commit 07ee638a50
2 changed files with 120 additions and 0 deletions
+46
View File
@@ -1,6 +1,7 @@
package sub
import (
"encoding/hex"
"errors"
"fmt"
"maps"
@@ -521,11 +522,17 @@ func (s *SubClashService) buildHysteriaProxy(subReq *SubService, inbound *model.
if fp, ok := inner["fingerprint"].(string); ok && fp != "" {
proxy["client-fingerprint"] = fp
}
if certFingerprint := mihomoCertFingerprint(inner["pinnedPeerCertSha256"]); certFingerprint != "" {
proxy["fingerprint"] = certFingerprint
}
}
}
if insecure, ok := ep["allowInsecure"].(bool); ok && insecure {
proxy["skip-cert-verify"] = true
}
if certFingerprint := mihomoCertFingerprint(ep["pinnedPeerCertSha256"]); certFingerprint != "" {
proxy["fingerprint"] = certFingerprint
}
// Salamander obfs (Hysteria2). Read the same finalmask.udp[salamander]
// block the subscription link generator uses.
@@ -555,6 +562,45 @@ func (s *SubClashService) buildHysteriaProxy(subReq *SubService, inbound *model.
return proxy
}
// Mihomo supports only one certificate fingerprint, so mihomoCertFingerprint
// converts the first valid SHA-256 pin to its colon-separated TLS form.
func mihomoCertFingerprint(value any) string {
var pins []string
switch typed := value.(type) {
case []any:
for _, item := range typed {
if pin, ok := item.(string); ok {
pins = append(pins, pin)
}
}
case []string:
pins = typed
case string:
pins = strings.Split(typed, ",")
}
for _, pin := range pins {
normalized := hysteriaPinHex(pin)
if len(normalized) != 64 {
continue
}
if _, err := hex.DecodeString(normalized); err != nil {
continue
}
normalized = strings.ToUpper(normalized)
var out strings.Builder
out.Grow(95)
for i := 0; i < len(normalized); i += 2 {
if i > 0 {
out.WriteByte(':')
}
out.WriteString(normalized[i : i+2])
}
return out.String()
}
return ""
}
// buildWireguardProxy produces a mihomo-compatible Clash entry for a native
// WireGuard inbound, mirroring genWireguardLink: the peer public key is derived
// from the inbound secretKey, while the private key, tunnel address, and