tls_fingerprint_profile.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Package schema 定义 Ent ORM 的数据库 schema。
  2. package schema
  3. import (
  4. "github.com/Wei-Shaw/sub2api/ent/schema/mixins"
  5. "entgo.io/ent"
  6. "entgo.io/ent/dialect"
  7. "entgo.io/ent/dialect/entsql"
  8. "entgo.io/ent/schema"
  9. "entgo.io/ent/schema/field"
  10. )
  11. // TLSFingerprintProfile 定义 TLS 指纹配置模板的 schema。
  12. //
  13. // TLS 指纹模板用于模拟特定客户端(如 Claude Code / Node.js)的 TLS 握手特征。
  14. // 每个模板包含完整的 ClientHello 参数:加密套件、曲线、扩展等。
  15. // 通过 Account.Extra.tls_fingerprint_profile_id 绑定到具体账号。
  16. type TLSFingerprintProfile struct {
  17. ent.Schema
  18. }
  19. // Annotations 返回 schema 的注解配置。
  20. func (TLSFingerprintProfile) Annotations() []schema.Annotation {
  21. return []schema.Annotation{
  22. entsql.Annotation{Table: "tls_fingerprint_profiles"},
  23. }
  24. }
  25. // Mixin 返回该 schema 使用的混入组件。
  26. func (TLSFingerprintProfile) Mixin() []ent.Mixin {
  27. return []ent.Mixin{
  28. mixins.TimeMixin{},
  29. }
  30. }
  31. // Fields 定义 TLS 指纹模板实体的所有字段。
  32. func (TLSFingerprintProfile) Fields() []ent.Field {
  33. return []ent.Field{
  34. // name: 模板名称,唯一标识
  35. field.String("name").
  36. MaxLen(100).
  37. NotEmpty().
  38. Unique(),
  39. // description: 模板描述
  40. field.Text("description").
  41. Optional().
  42. Nillable(),
  43. // enable_grease: 是否启用 GREASE 扩展(Chrome 使用,Node.js 不使用)
  44. field.Bool("enable_grease").
  45. Default(false),
  46. // cipher_suites: TLS 加密套件列表(顺序敏感,影响 JA3)
  47. field.JSON("cipher_suites", []uint16{}).
  48. Optional().
  49. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  50. // curves: 椭圆曲线/支持的组列表
  51. field.JSON("curves", []uint16{}).
  52. Optional().
  53. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  54. // point_formats: EC 点格式列表
  55. field.JSON("point_formats", []uint16{}).
  56. Optional().
  57. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  58. // signature_algorithms: 签名算法列表
  59. field.JSON("signature_algorithms", []uint16{}).
  60. Optional().
  61. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  62. // alpn_protocols: ALPN 协议列表(如 ["http/1.1"])
  63. field.JSON("alpn_protocols", []string{}).
  64. Optional().
  65. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  66. // supported_versions: 支持的 TLS 版本列表(如 [0x0304, 0x0303])
  67. field.JSON("supported_versions", []uint16{}).
  68. Optional().
  69. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  70. // key_share_groups: Key Share 中发送的曲线组(如 [29] 即 X25519)
  71. field.JSON("key_share_groups", []uint16{}).
  72. Optional().
  73. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  74. // psk_modes: PSK 密钥交换模式(如 [1] 即 psk_dhe_ke)
  75. field.JSON("psk_modes", []uint16{}).
  76. Optional().
  77. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  78. // extensions: TLS 扩展类型 ID 列表,按发送顺序排列
  79. field.JSON("extensions", []uint16{}).
  80. Optional().
  81. SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
  82. }
  83. }