mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-10-10 04:03:11 +08:00
chore: allow override IV_VER by peer-info for OpenVPN
This commit is contained in:
@@ -174,6 +174,10 @@ func InstallScriptOptionsString(proto, cipher, auth string, compLZO string) stri
|
||||
}
|
||||
|
||||
func InstallScriptPeerInfo(cipher string, dataCiphers []string, compLZO string, peerInfo map[string]string) string {
|
||||
ivVer := "mihomo-openvpn"
|
||||
if value, ok := peerInfo["IV_VER"]; ok {
|
||||
ivVer = value
|
||||
}
|
||||
lzo := ""
|
||||
if compLZO == CompLzoYes {
|
||||
lzo = "IV_LZO=1\n"
|
||||
@@ -188,11 +192,19 @@ func InstallScriptPeerInfo(cipher string, dataCiphers []string, compLZO string,
|
||||
}
|
||||
ivCiphers = strings.Join(normalized, ":")
|
||||
}
|
||||
info := fmt.Sprintf("IV_VER=mihomo-openvpn\nIV_PROTO=6\n%sIV_CIPHERS=%s\n", lzo, ivCiphers)
|
||||
info := fmt.Sprintf("IV_VER=%s\nIV_PROTO=6\n%sIV_CIPHERS=%s\n", ivVer, lzo, ivCiphers)
|
||||
// Append user-defined peer-info entries (e.g. IV_HWADDR, UV_*) after the
|
||||
// built-in fields. Keys are sorted so the output is deterministic.
|
||||
keys := make([]string, 0, len(peerInfo))
|
||||
for key := range peerInfo {
|
||||
switch key {
|
||||
case "IV_VER", "IV_PROTO", "IV_CIPHERS":
|
||||
continue
|
||||
case "IV_LZO":
|
||||
if lzo != "" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
@@ -107,6 +107,19 @@ func TestInstallScriptPeerInfo(t *testing.T) {
|
||||
if info != want {
|
||||
t.Fatalf("unexpected peer-info:\n got %q\nwant %q", info, want)
|
||||
}
|
||||
|
||||
// A user-defined IV_VER replaces the built-in value, while other generated
|
||||
// fields are not duplicated by peer-info entries.
|
||||
overridden := InstallScriptPeerInfo(CipherAES128GCM, nil, CompLzoYes, map[string]string{
|
||||
"IV_VER": "custom-client/1.0",
|
||||
"IV_PROTO": "999",
|
||||
"IV_LZO": "0",
|
||||
"IV_CIPHERS": "AES-256-CBC",
|
||||
})
|
||||
want = "IV_VER=custom-client/1.0\nIV_PROTO=6\nIV_LZO=1\nIV_CIPHERS=AES-128-GCM\n"
|
||||
if overridden != want {
|
||||
t.Fatalf("unexpected overridden peer-info:\n got %q\nwant %q", overridden, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServerKeyMethod2Record(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user