(ib inbounds.Inbound, host inbounds.Host, acc users.UserInbound, username, addr string, port int)
| 363 | } |
| 364 | |
| 365 | func shadowsocksLink(ib inbounds.Inbound, host inbounds.Host, acc users.UserInbound, username, addr string, port int) string { |
| 366 | method := ib.Method |
| 367 | if method == "" { |
| 368 | method = "aes-128-gcm" |
| 369 | } |
| 370 | userPSK := acc.Secret |
| 371 | // SS 2022 user PSK 须与 xray 配置派生逻辑一致(HMAC-SHA256,指定字节长度) |
| 372 | if strings.HasPrefix(method, "2022-") && userPSK != "" { |
| 373 | keyLen := 16 |
| 374 | if strings.Contains(method, "256") || strings.Contains(method, "chacha20") { |
| 375 | keyLen = 32 |
| 376 | } |
| 377 | mac := hmac.New(sha256.New, []byte(userPSK)) |
| 378 | mac.Write([]byte(fmt.Sprintf("ss2022-%d", keyLen))) |
| 379 | userPSK = base64.StdEncoding.EncodeToString(mac.Sum(nil)[:keyLen]) |
| 380 | } |
| 381 | var credentials string |
| 382 | if strings.HasPrefix(method, "2022-") { |
| 383 | credentials = fmt.Sprintf("%s:%s:%s", method, ib.Password, userPSK) |
| 384 | } else { |
| 385 | credentials = fmt.Sprintf("%s:%s", method, userPSK) |
| 386 | } |
| 387 | encoded := base64.RawURLEncoding.EncodeToString([]byte(credentials)) |
| 388 | return fmt.Sprintf("ss://%s@%s:%d#%s", encoded, addr, port, url.PathEscape(username)) |
| 389 | } |
no test coverage detected