fix: Converter VMess security field typo

This commit is contained in:
Hellojack 2022-08-19 21:17:44 +08:00 committed by H1JK
parent fecbc7a091
commit 732e82e3d0

View file

@ -136,13 +136,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
if strings.HasSuffix(tls, "tls") { if strings.HasSuffix(tls, "tls") {
vless["tls"] = true vless["tls"] = true
} }
sni := query.Get("sni") if sni := query.Get("sni"); sni != "" {
if sni != "" {
vless["servername"] = sni vless["servername"] = sni
} }
flow := strings.ToLower(query.Get("flow")) if flow := strings.ToLower(query.Get("flow")); flow != "" {
if flow != "" {
vless["flow"] = flow vless["flow"] = flow
} }
@ -161,16 +159,16 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
httpOpts := make(map[string]any) httpOpts := make(map[string]any)
httpOpts["path"] = []string{"/"} httpOpts["path"] = []string{"/"}
if query.Get("host") != "" { if host := query.Get("host"); host != "" {
headers["Host"] = []string{query.Get("host")} headers["Host"] = []string{host}
} }
if query.Get("method") != "" { if method := query.Get("method"); method != "" {
httpOpts["method"] = query.Get("method") httpOpts["method"] = method
} }
if query.Get("path") != "" { if path := query.Get("path"); path != "" {
httpOpts["path"] = []string{query.Get("path")} httpOpts["path"] = []string{path}
} }
httpOpts["headers"] = headers httpOpts["headers"] = headers
vless["http-opts"] = httpOpts vless["http-opts"] = httpOpts
@ -180,11 +178,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
headers := make(map[string]any) headers := make(map[string]any)
h2Opts := make(map[string]any) h2Opts := make(map[string]any)
h2Opts["path"] = []string{"/"} h2Opts["path"] = []string{"/"}
if query.Get("path") != "" { if path := query.Get("path"); path != "" {
h2Opts["path"] = []string{query.Get("path")} h2Opts["path"] = []string{path}
} }
if query.Get("host") != "" { if host := query.Get("host"); host != "" {
h2Opts["host"] = []string{query.Get("host")} h2Opts["host"] = []string{host}
} }
h2Opts["headers"] = headers h2Opts["headers"] = headers
vless["h2-opts"] = h2Opts vless["h2-opts"] = h2Opts
@ -208,8 +206,12 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
proxies = append(proxies, vless) proxies = append(proxies, vless)
case "vmess": case "vmess":
dcBuf, err := encRaw.DecodeString(body) // V2RayN-styled share link
// https://github.com/2dust/v2rayN/wiki/%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E(ver-2)
dcBuf, err := tryDecodeBase64([]byte(body))
if err != nil { if err != nil {
// TODO: Xray VMessAEAD / VLESS share link standard
// https://github.com/XTLS/Xray-core/discussions/716
continue continue
} }
@ -233,17 +235,16 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
} else { } else {
vmess["alterId"] = 0 vmess["alterId"] = 0
} }
vmess["cipher"] = "auto"
vmess["udp"] = true vmess["udp"] = true
vmess["tls"] = false vmess["tls"] = false
vmess["skip-cert-verify"] = false vmess["skip-cert-verify"] = false
if values["cipher"] != nil && values["cipher"] != "" { vmess["cipher"] = "auto"
vmess["cipher"] = values["cipher"] if cipher, ok := values["scy"]; ok && cipher != "" {
vmess["cipher"] = cipher
} }
sni := values["sni"] if sni, ok := values["sni"]; ok && sni != "" {
if sni != "" {
vmess["servername"] = sni vmess["servername"] = sni
} }
@ -256,7 +257,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
vmess["network"] = network vmess["network"] = network
tls := strings.ToLower(values["tls"].(string)) tls := strings.ToLower(values["tls"].(string))
if strings.Contains(tls, "tls") { if strings.HasSuffix(tls, "tls") {
vmess["tls"] = true vmess["tls"] = true
} }
@ -264,12 +265,12 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
case "http": case "http":
headers := make(map[string]any) headers := make(map[string]any)
httpOpts := make(map[string]any) httpOpts := make(map[string]any)
if values["host"] != "" && values["host"] != nil { if host, ok := values["host"]; ok && host != "" {
headers["Host"] = []string{values["host"].(string)} headers["Host"] = []string{host.(string)}
} }
httpOpts["path"] = []string{"/"} httpOpts["path"] = []string{"/"}
if values["path"] != "" && values["path"] != nil { if path, ok := values["path"]; ok && path != "" {
httpOpts["path"] = []string{values["path"].(string)} httpOpts["path"] = []string{path.(string)}
} }
httpOpts["headers"] = headers httpOpts["headers"] = headers
@ -278,8 +279,8 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
case "h2": case "h2":
headers := make(map[string]any) headers := make(map[string]any)
h2Opts := make(map[string]any) h2Opts := make(map[string]any)
if values["host"] != "" && values["host"] != nil { if host, ok := values["host"]; ok && host != "" {
headers["Host"] = []string{values["host"].(string)} headers["Host"] = []string{host.(string)}
} }
h2Opts["path"] = values["path"] h2Opts["path"] = values["path"]
@ -291,11 +292,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
headers := make(map[string]any) headers := make(map[string]any)
wsOpts := make(map[string]any) wsOpts := make(map[string]any)
wsOpts["path"] = []string{"/"} wsOpts["path"] = []string{"/"}
if values["host"] != "" && values["host"] != nil { if host, ok := values["host"]; ok && host != "" {
headers["Host"] = values["host"].(string) headers["Host"] = host.(string)
} }
if values["path"] != "" && values["path"] != nil { if path, ok := values["path"]; ok && path != "" {
wsOpts["path"] = values["path"].(string) wsOpts["path"] = path.(string)
} }
wsOpts["headers"] = headers wsOpts["headers"] = headers
vmess["ws-opts"] = wsOpts vmess["ws-opts"] = wsOpts