尝试修复对2022的兼容性
This commit is contained in:
@@ -29,13 +29,24 @@ func fixSSKey(key string, length int) string {
|
||||
if key == "" {
|
||||
return ""
|
||||
}
|
||||
// Try to decode as-is first
|
||||
// If it's already a valid Base64 of the correct length, use it directly (as a B64 key)
|
||||
if data, err := base64.StdEncoding.DecodeString(key); err == nil && len(data) == length {
|
||||
return key
|
||||
}
|
||||
// Use SHA256 to derive a fixed-length key from the password
|
||||
hash := sha256.Sum256([]byte(key))
|
||||
return base64.StdEncoding.EncodeToString(hash[:length])
|
||||
|
||||
// Legacy repetition/truncation logic for raw string keys (common in Xboard/V2board)
|
||||
password := key
|
||||
if len(password) > length {
|
||||
password = password[:length]
|
||||
}
|
||||
for len(password) < length {
|
||||
password += password
|
||||
}
|
||||
// Re-truncate after repetition
|
||||
password = password[:length]
|
||||
|
||||
// Convert to Base64 so sing-box treats it as a raw byte key
|
||||
return base64.StdEncoding.EncodeToString([]byte(password))
|
||||
}
|
||||
|
||||
func RegisterService(registry *boxService.Registry) {
|
||||
@@ -406,6 +417,17 @@ func (s *Service) fetchConfig() (*XNodeConfig, error) {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Check time drift
|
||||
if dateStr := resp.Header.Get("Date"); dateStr != "" {
|
||||
if panelTime, err := http.ParseTime(dateStr); err == nil {
|
||||
drift := time.Since(panelTime)
|
||||
if drift < 0 { drift = -drift }
|
||||
if drift > 30*time.Second {
|
||||
s.logger.Error("CRITICAL TIME DRIFT: ", drift, " off from Panel. SS 2022 WILL FAIL. Sync your time!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
|
||||
Reference in New Issue
Block a user