新增功能: - 新增 TLS 指纹 Profile CRUD 管理(Ent schema + 迁移 + Admin API + 前端管理界面) - 支持账号绑定数据库中的自定义 TLS Profile,或随机选择(profile_id=-1) - HTTPUpstream.DoWithTLS 接口从 bool 改为 *tlsfingerprint.Profile,支持按账号指定 Profile - AccountUsageService 注入 TLSFingerprintProfileService,统一 usage 场景与网关的 Profile 解析逻辑 代码优化: - 删除已被 TLSFingerprintProfileService 完全取代的 registry.go 死代码(418 行) - 提取 3 个 dialer 的重复 TLS 握手逻辑为 performTLSHandshake() 共用函数 - 修复 GetTLSFingerprintProfileID 缺少 json.Number 处理的 bug - gateway_service.Forward 中 ResolveTLSProfile 从重试循环内重复调用改为预解析局部变量 - 删除冗余的 buildClientHelloSpec() 单行 wrapper 和 int64(e.ID) 无效转换 - tls_fingerprint_profile_cache.go 日志从 log.Printf 改为 slog 结构化日志 - dialer_capture_test.go 添加 //go:build integration 标签,防止 CI 失败 - 去重 TestProfileExpectation 类型至共享 test_types_test.go - 修复 9 个测试文件缺少 tlsfingerprint import 的编译错误 - 修复 error_policy_integration_test.go 中 handleError 回调签名被错误替换的问题
55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
// Package model 定义服务层使用的数据模型。
|
|
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/pkg/tlsfingerprint"
|
|
)
|
|
|
|
// TLSFingerprintProfile TLS 指纹配置模板
|
|
// 包含完整的 ClientHello 参数,用于模拟特定客户端的 TLS 握手特征
|
|
type TLSFingerprintProfile struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description"`
|
|
EnableGREASE bool `json:"enable_grease"`
|
|
CipherSuites []uint16 `json:"cipher_suites"`
|
|
Curves []uint16 `json:"curves"`
|
|
PointFormats []uint16 `json:"point_formats"`
|
|
SignatureAlgorithms []uint16 `json:"signature_algorithms"`
|
|
ALPNProtocols []string `json:"alpn_protocols"`
|
|
SupportedVersions []uint16 `json:"supported_versions"`
|
|
KeyShareGroups []uint16 `json:"key_share_groups"`
|
|
PSKModes []uint16 `json:"psk_modes"`
|
|
Extensions []uint16 `json:"extensions"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// Validate 验证模板配置的有效性
|
|
func (p *TLSFingerprintProfile) Validate() error {
|
|
if p.Name == "" {
|
|
return &ValidationError{Field: "name", Message: "name is required"}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ToTLSProfile 将领域模型转换为运行时使用的 tlsfingerprint.Profile
|
|
// 空切片字段会在 dialer 中 fallback 到内置默认值
|
|
func (p *TLSFingerprintProfile) ToTLSProfile() *tlsfingerprint.Profile {
|
|
return &tlsfingerprint.Profile{
|
|
Name: p.Name,
|
|
EnableGREASE: p.EnableGREASE,
|
|
CipherSuites: p.CipherSuites,
|
|
Curves: p.Curves,
|
|
PointFormats: p.PointFormats,
|
|
SignatureAlgorithms: p.SignatureAlgorithms,
|
|
ALPNProtocols: p.ALPNProtocols,
|
|
SupportedVersions: p.SupportedVersions,
|
|
KeyShareGroups: p.KeyShareGroups,
|
|
PSKModes: p.PSKModes,
|
|
Extensions: p.Extensions,
|
|
}
|
|
}
|