diff --git a/backend/internal/inject/inject.go b/backend/internal/inject/inject.go index 112fbf6..e558b98 100644 --- a/backend/internal/inject/inject.go +++ b/backend/internal/inject/inject.go @@ -28,8 +28,8 @@ type Arch string const ( ArchX86 Arch = "x86" ArchX64 Arch = "x64" - ArchARM Arch = "arm" - ArchARM64 Arch = "arm64" + ArchARM Arch = "arm" + ArchARM64 Arch = "arm64" ArchUniversal Arch = "universal" ) @@ -58,13 +58,13 @@ type InjectResult struct { // InjectService 注入服务 type InjectService struct { - ApktoolPath string - KeystorePath string - KeystorePass string + ApktoolPath string + KeystorePath string + KeystorePass string KeystoreAlias string - KeyPass string + KeyPass string ApksignerPath string - WorkDir string + WorkDir string } // NewInjectService 创建注入服务 @@ -76,12 +76,12 @@ func NewInjectService(workDir string) *InjectService { } return &InjectService{ - WorkDir: absWorkDir, - ApktoolPath: getEnvOrDefault("APKTOOL_PATH", "apktool"), - KeystorePath: getEnvOrDefault("KEYSTORE_PATH", ""), - KeystorePass: getEnvOrDefault("KEYSTORE_PASS", "123456"), + WorkDir: absWorkDir, + ApktoolPath: getEnvOrDefault("APKTOOL_PATH", "apktool"), + KeystorePath: getEnvOrDefault("KEYSTORE_PATH", ""), + KeystorePass: getEnvOrDefault("KEYSTORE_PASS", "123456"), KeystoreAlias: getEnvOrDefault("KEYSTORE_ALIAS", "mykey"), - KeyPass: getEnvOrDefault("KEY_PASS", "123456"), + KeyPass: getEnvOrDefault("KEY_PASS", "123456"), ApksignerPath: getEnvOrDefault("APKSIGNER_PATH", "apksigner"), } } @@ -309,9 +309,9 @@ func (s *InjectService) configureAndroid(decompileDir string, config InjectConfi // 替换配置参数 replacements := map[string]string{ - "[OpenClassName]": config.AppName, - "\"https://example.com\"": fmt.Sprintf("\"%s\"", config.VerifyURL), - "[AppKey]": config.AppKey, + "[OpenClassName]": config.AppName, + "\"https://example.com\"": fmt.Sprintf("\"%s\"", config.VerifyURL), + "[AppKey]": config.AppKey, } for old, new := range replacements { diff --git a/backend/internal/middleware/app_crypto.go b/backend/internal/middleware/app_crypto.go index 9aaeb51..6439295 100644 --- a/backend/internal/middleware/app_crypto.go +++ b/backend/internal/middleware/app_crypto.go @@ -35,10 +35,10 @@ func AppCrypto() gin.HandlerFunc { cryptoManager := crypto.NewCryptoManager(encryptType, app.EncryptKey) shouldEncrypt := encryptType != crypto.EncryptTypeNone - - fmt.Printf("[AppCrypto] AppKey: %s, EncryptType: %s, EncryptKey: %s, ShouldEncrypt: %v\n", + + fmt.Printf("[AppCrypto] AppKey: %s, EncryptType: %s, EncryptKey: %s, ShouldEncrypt: %v\n", appKey, app.EncryptType, app.EncryptKey, shouldEncrypt) - + c.Set("should_encrypt_response", shouldEncrypt) c.Set("crypto_manager", cryptoManager) diff --git a/backend/internal/model/models.go b/backend/internal/model/models.go index 8928a84..2cf3bf1 100644 --- a/backend/internal/model/models.go +++ b/backend/internal/model/models.go @@ -930,20 +930,25 @@ type ProtectTask struct { // SignProfile 签名证书资产(Windows pfx / iOS p12+mobileprovision) // 证书与口令都加密落盘,库里只存元数据;私钥永不下发前端。 type SignProfile struct { - ID uint `gorm:"primaryKey" json:"id"` - UserID uint `gorm:"index" json:"user_id"` - Platform string `gorm:"size:16;index" json:"platform"` // windows / ios - Name string `gorm:"size:100" json:"name"` - CertFormat string `gorm:"size:16" json:"cert_format"` // pfx / p12 - CertPath string `gorm:"size:500" json:"-"` // 加密后的证书文件 - PassPath string `gorm:"size:500" json:"-"` // 加密后的口令 - ProfilePath string `gorm:"size:500" json:"-"` // 加密后的 mobileprovision(仅 iOS) - Subject string `gorm:"size:255" json:"subject"` // 证书主题(openssl 解析得到,可为空) - NotAfter *time.Time `json:"not_after"` - Status string `gorm:"size:20;default:active" json:"status"` - LastUsedAt *time.Time `json:"last_used_at"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + ID uint `gorm:"primaryKey" json:"id"` + UserID uint `gorm:"index" json:"user_id"` + Platform string `gorm:"size:16;index" json:"platform"` // windows / ios + Name string `gorm:"size:100" json:"name"` + CertFormat string `gorm:"size:16" json:"cert_format"` // pfx / p12 + CertPath string `gorm:"size:500" json:"-"` // 加密后的证书文件 + PassPath string `gorm:"size:500" json:"-"` // 加密后的口令 + ProfilePath string `gorm:"size:500" json:"-"` // 加密后的 mobileprovision(仅 iOS) + Subject string `gorm:"size:255" json:"subject"` // 证书主题(提交时解析,可为空) + // CertCount / KeyCount 这个 pfx 里到底装了什么: + // 链式包里证书多但私钥只有一把(正常,签名会带完整链); + // 多身份包里私钥多把,签名只会用第一套。 + CertCount int `gorm:"default:0" json:"cert_count"` + KeyCount int `gorm:"default:0" json:"key_count"` + NotAfter *time.Time `json:"not_after"` + Status string `gorm:"size:20;default:active" json:"status"` + LastUsedAt *time.Time `json:"last_used_at"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } // WebhookConfig Webhook配置 diff --git a/backend/internal/protect/pfx.go b/backend/internal/protect/pfx.go new file mode 100644 index 0000000..e050019 --- /dev/null +++ b/backend/internal/protect/pfx.go @@ -0,0 +1,162 @@ +package protect + +import ( + "crypto" + "crypto/ecdsa" + "crypto/ed25519" + "crypto/rsa" + "crypto/x509" + "fmt" + "time" + + "software.sslmate.com/src/go-pkcs12" +) + +// PFXIdentity 一套「私钥 + 对应证书」,也就是一个真正的签名身份。 +type PFXIdentity struct { + Index int // 第几套(1 起,方便人看) + Subject string // 证书主题 + NotAfter time.Time // 证书到期时间 + Expired bool +} + +// PFXInfo 一个 pfx/p12 文件里到底装了什么。 +// +// 现实里这类文件有三种形态,必须区分清楚: +// 1. 单身份:一张叶子证书 + 它的私钥(最常见) +// 2. 链式:叶子证书 + 它的私钥 + 中间 CA / 根证书(证书多但私钥只有一把) +// —— 这种是好事,签名时会带完整链,验签更容易过 +// 3. 多身份:好几套「私钥+证书」混在一个文件里 +// —— 签名工具只会用其中一套,必须让人知道用的是哪一套 +type PFXInfo struct { + CertCount int // 证书总数(含链上的 CA) + KeyCount int // 私钥总数(= 可签名身份数) + Identities []PFXIdentity // 每套可签名身份 + LooseCerts int // 没有私钥的证书(链上的 CA) + Signing PFXIdentity // 实际会用来签名的那一套 + Note string // 给人看的说明 +} + +// ParsePFX 解析 pfx/p12,给上传接口用:判断能不能签、有几套身份、到期时间。 +// +// 关键点:不能简单取「第一个证书」当签名证书——链式 pfx 里第一个 +// 可能是中间 CA。这里按「公钥与私钥配对」来认叶子证书。 +func ParsePFX(data []byte, password string) (PFXInfo, error) { + var info PFXInfo + + blocks, err := pkcs12.ToPEM(data, password) + if err != nil { + // 有些工具导出的 pfx 对空口令也要显式给空串 + if password != "" { + if blocks2, err2 := pkcs12.ToPEM(data, ""); err2 == nil { + blocks, err = blocks2, nil + } + } + if err != nil { + return info, fmt.Errorf("解析 pfx 失败(口令可能不对): %w", err) + } + } + + var certs []*x509.Certificate + var keys []interface{} + for _, b := range blocks { + switch b.Type { + case "CERTIFICATE": + if c, e := x509.ParseCertificate(b.Bytes); e == nil { + certs = append(certs, c) + } + case "PRIVATE KEY", "RSA PRIVATE KEY", "EC PRIVATE KEY": + // go-pkcs12 的 ToPEM 把 RSA 私钥导成 PKCS#1、ECDSA 导成 SEC1, + // 但 block.Type 统一是 "PRIVATE KEY" —— 三种编码都要试一遍, + // 否则会把「有私钥」的 pfx 误判成「只有证书」。 + if k, e := parseAnyPrivateKey(b.Bytes); e == nil { + keys = append(keys, k) + } + } + } + info.CertCount = len(certs) + info.KeyCount = len(keys) + + // 按公钥配对,找出能真正拿去签名的证书 + var matched []*x509.Certificate + for _, c := range certs { + for _, k := range keys { + if pub, ok := publicOf(k); ok && publicEqual(pub, c.PublicKey) { + matched = append(matched, c) + break + } + } + } + info.LooseCerts = info.CertCount - len(matched) + + for i, c := range matched { + info.Identities = append(info.Identities, PFXIdentity{ + Index: i + 1, + Subject: c.Subject.String(), + NotAfter: c.NotAfter, + Expired: c.NotAfter.Before(time.Now()), + }) + } + // 保持文件内顺序,不要按到期时间重排:osslsigncode(OpenSSL PKCS12_parse) + // 取的是文件里的第一套私钥+证书,报告必须和它一致,否则说一套签一套。 + + switch { + case len(matched) > 0: + info.Signing = info.Identities[0] + case len(certs) > 0: + // 没有私钥:只有证书,签不了名 + info.Signing = PFXIdentity{Subject: certs[0].Subject.String(), NotAfter: certs[0].NotAfter, + Expired: certs[0].NotAfter.Before(time.Now())} + } + + switch { + case info.KeyCount == 0: + info.Note = "该文件里只有证书、没有私钥,无法用于签名;请导出带私钥的 .pfx/.p12" + case info.KeyCount == 1 && info.CertCount > 1: + info.Note = fmt.Sprintf("含 %d 张证书(1 套私钥 + %d 张链上证书),签名会带完整证书链", info.CertCount, info.LooseCerts) + case info.KeyCount > 1: + info.Note = fmt.Sprintf("含 %d 套可签名证书(私钥 %d 把),签名工具只会使用其中一套;"+ + "如需指定其它一套,请把它单独导出成 pfx 再上传", len(matched), info.KeyCount) + } + return info, nil +} + +// publicOf 取任意私钥对象的公钥部分 +func publicOf(key interface{}) (interface{}, bool) { + switch k := key.(type) { + case *rsa.PrivateKey: + return &k.PublicKey, true + case *ecdsa.PrivateKey: + return &k.PublicKey, true + case *ed25519.PrivateKey: + return k.Public(), true + case crypto.Signer: + return k.Public(), true + } + return nil, false +} + +// publicEqual 比较两个公钥是否同一把 +func publicEqual(a, b interface{}) bool { + type equaler interface{ Equal(crypto.PublicKey) bool } + if eq, ok := a.(equaler); ok { + if pk, ok2 := b.(crypto.PublicKey); ok2 { + return eq.Equal(pk) + } + } + return false +} + +// parseAnyPrivateKey 依次尝试 PKCS#8 / PKCS#1 / SEC1 三种私钥编码 +func parseAnyPrivateKey(der []byte) (interface{}, error) { + if k, err := x509.ParsePKCS8PrivateKey(der); err == nil { + return k, nil + } + if k, err := x509.ParsePKCS1PrivateKey(der); err == nil { + return k, nil + } + if k, err := x509.ParseECPrivateKey(der); err == nil { + return k, nil + } + return nil, fmt.Errorf("无法识别的私钥编码") +} diff --git a/backend/internal/protect/pfx_test.go b/backend/internal/protect/pfx_test.go new file mode 100644 index 0000000..69b7bfd --- /dev/null +++ b/backend/internal/protect/pfx_test.go @@ -0,0 +1,62 @@ +package protect + +import ( + "os" + "testing" +) + +// 用真实文件验证三种 pfx 形态的识别结果。 +// 依赖 /tmp/pfxlab 下的样本(单证书 / 链式 / 多身份),缺失则跳过。 +func TestParsePFXShapes(t *testing.T) { + cases := []struct { + file string + pw string + certCount int + keyCount int + wantSubstr string + }{ + {"/tmp/pfxlab/single.pfx", "testpass123", 1, 1, "Leaf Signer"}, + {"/tmp/pfxlab/chain.pfx", "testpass123", 3, 1, "Leaf Signer"}, + {"/tmp/pfxlab/multi.p12", "testpass123", 2, 2, "Signer"}, + } + for _, c := range cases { + data, err := os.ReadFile(c.file) + if err != nil { + t.Logf("跳过 %s(样本不存在)", c.file) + continue + } + info, err := ParsePFX(data, c.pw) + if err != nil { + t.Fatalf("%s 解析失败: %v", c.file, err) + } + t.Logf("%s → 证书 %d 张 / 私钥 %d 把 / 身份 %d 套 / 实际签名=%q / 说明=%q", + c.file, info.CertCount, info.KeyCount, len(info.Identities), info.Signing.Subject, info.Note) + if info.CertCount != c.certCount { + t.Errorf("%s 证书数 = %d, 期望 %d", c.file, info.CertCount, c.certCount) + } + if info.KeyCount != c.keyCount { + t.Errorf("%s 私钥数 = %d, 期望 %d", c.file, info.KeyCount, c.keyCount) + } + if info.Signing.Subject == "" { + t.Errorf("%s 没认到签名证书", c.file) + } + } +} + +// 只有证书没有私钥的文件必须被标出来(不能用它签名) +func TestParsePFXCertOnly(t *testing.T) { + data, err := os.ReadFile("/tmp/pfxlab/certonly.pfx") + if err != nil { + t.Skip("样本不存在") + } + info, err := ParsePFX(data, "testpass123") + if err != nil { + // 有些实现直接报错,也算识别出来了 + t.Logf("cert-only 直接报错(可接受): %v", err) + return + } + t.Logf("cert-only → 证书 %d / 私钥 %d / 说明=%q", info.CertCount, info.KeyCount, info.Note) + if info.KeyCount != 0 { + t.Errorf("私钥数应为 0,实得 %d", info.KeyCount) + } +} diff --git a/backend/internal/router/admin/signprofiles.go b/backend/internal/router/admin/signprofiles.go index d8a9cd7..e77af9c 100644 --- a/backend/internal/router/admin/signprofiles.go +++ b/backend/internal/router/admin/signprofiles.go @@ -4,14 +4,12 @@ package admin // 供加壳产物重签时取用;任何响应都不回证书内容与口令。 import ( - "crypto/x509" "io" "mime/multipart" "os" "path/filepath" "strconv" "strings" - "time" "verification-platform-backend/internal/database" "verification-platform-backend/internal/model" @@ -19,7 +17,6 @@ import ( "verification-platform-backend/pkg/response" "github.com/gin-gonic/gin" - "software.sslmate.com/src/go-pkcs12" ) func SetupSignProfileRoutes(r *gin.RouterGroup) { @@ -82,11 +79,25 @@ func HandleCreateSignProfile(c *gin.Context) { } } - // 解析证书本身:Subject 与到期时间。 - // 生产镜像是 Alpine,没有 openssl CLI,所以用纯 Go 解 PKCS#12。 - // 解析失败不影响上传(口令错/格式怪也能存下来给别的工具用),只是列表上 - // 看不到到期时间,也就没有过期提醒。 - subject, notAfter := parseCertInfo(certData, password) + // 解析 pfx 内容:证书数、私钥数、真正能签名的证书及到期时间。 + // 生产镜像是 Alpine,没有 openssl CLI,全部纯 Go 解 PKCS#12。 + pfx, perr := protect.ParsePFX(certData, password) + if perr != nil { + // 「只有证书没有私钥」的 pfx 会让解析库直接报结构错误, + // 这种报错对人没意义,翻成人话 + msg := perr.Error() + if strings.Contains(msg, "expected exactly 2 items") || strings.Contains(msg, "certificate missing") { + response.ParamError(c, "这个文件里只有证书、没有私钥(不是标准 pfx),签不了名。请重新导出为带私钥的 .pfx/.p12") + return + } + response.ParamError(c, "证书解析失败:"+msg+"(口令是否正确?)") + return + } + if pfx.KeyCount == 0 { + response.ParamError(c, "这个文件里只有证书、没有私钥,签不了名。请导出带私钥的 .pfx/.p12") + return + } + subject, notAfter := pfx.Signing.Subject, &pfx.Signing.NotAfter sp := model.SignProfile{ UserID: userID, @@ -95,6 +106,8 @@ func HandleCreateSignProfile(c *gin.Context) { CertFormat: strings.TrimPrefix(ext, "."), Subject: subject, NotAfter: notAfter, + CertCount: pfx.CertCount, + KeyCount: pfx.KeyCount, Status: "active", } if err := database.DB.Create(&sp).Error; err != nil { @@ -139,6 +152,13 @@ func HandleCreateSignProfile(c *gin.Context) { "format": sp.CertFormat, "has_profile": sp.ProfilePath != "", "fingerprint": protect.Fingerprint(certData), + "subject": sp.Subject, + "not_after": sp.NotAfter, + // 这个 pfx 里装了什么:证书几张、私钥几把、以及说明 + "cert_count": pfx.CertCount, + "key_count": pfx.KeyCount, + "note": pfx.Note, + "identities": pfx.Identities, }) } @@ -156,6 +176,7 @@ func HandleListSignProfiles(c *gin.Context) { out = append(out, gin.H{ "id": sp.ID, "platform": sp.Platform, "name": sp.Name, "cert_format": sp.CertFormat, "subject": sp.Subject, "not_after": sp.NotAfter, + "cert_count": sp.CertCount, "key_count": sp.KeyCount, "status": sp.Status, "has_profile": sp.ProfilePath != "", "last_used_at": sp.LastUsedAt, "created_at": sp.CreatedAt, }) @@ -173,7 +194,9 @@ func HandleGetSignProfile(c *gin.Context) { return } response.Success(c, gin.H{ - "id": sp.ID, "platform": sp.Platform, "name": sp.Name, + "cert_count": sp.CertCount, + "key_count": sp.KeyCount, + "id": sp.ID, "platform": sp.Platform, "name": sp.Name, "cert_format": sp.CertFormat, "subject": sp.Subject, "not_after": sp.NotAfter, "status": sp.Status, "has_profile": sp.ProfilePath != "", "created_at": sp.CreatedAt, "updated_at": sp.UpdatedAt, @@ -202,28 +225,3 @@ func readUploaded(fh *multipart.FileHeader) ([]byte, error) { defer f.Close() return io.ReadAll(io.LimitReader(f, 16<<20)) } - -// parseCertInfo 从 pfx/p12 里取主题与到期时间(纯 Go,不依赖 openssl CLI)。 -// 口令错、格式不认识时返回空值,不阻断上传。 -func parseCertInfo(certData []byte, password string) (subject string, notAfter *time.Time) { - blocks, err := pkcs12.ToPEM(certData, password) - if err != nil && password != "" { - // 有些导出工具对空口令的 pfx 也要显式传空串,换个姿势再试一次 - blocks, err = pkcs12.ToPEM(certData, "") - } - if err != nil { - return "", nil - } - for _, b := range blocks { - if b.Type != "CERTIFICATE" { - continue - } - cert, perr := x509.ParseCertificate(b.Bytes) - if perr != nil { - continue - } - // 取第一张证书(叶子证书通常在最前) - return cert.Subject.String(), &cert.NotAfter - } - return "", nil -} diff --git a/backend/internal/router/agent/agent.go b/backend/internal/router/agent/agent.go index 1871e37..ac479a6 100644 --- a/backend/internal/router/agent/agent.go +++ b/backend/internal/router/agent/agent.go @@ -81,7 +81,7 @@ func handleGetStats(c *gin.Context) { database.DB.First(&agent, userID) response.Success(c, gin.H{ - "totalApps": totalApps, + "totalApps": totalApps, "totalCards": totalCards, "totalUsers": totalUsers, "totalRevenue": totalRevenue, @@ -306,7 +306,7 @@ func handleGetCards(c *gin.Context) { "unused_count": unusedCount, "used_count": usedCount, "expired_count": expiredCount, - "banned_count": bannedCount, + "banned_count": bannedCount, }) } @@ -499,19 +499,19 @@ func handleGetUsers(c *gin.Context) { } item := gin.H{ - "id": u.ID, - "username": u.Username, - "email": u.Email, - "status": u.Status, - "balance": u.Balance, - "expiry_at": u.ExpiryAt, - "last_login_at": u.LastLoginAt, + "id": u.ID, + "username": u.Username, + "email": u.Email, + "status": u.Status, + "balance": u.Balance, + "expiry_at": u.ExpiryAt, + "last_login_at": u.LastLoginAt, "last_heartbeat_at": u.LastHeartbeatAt, - "device_count": deviceCount, - "online_status": onlineStatus, - "application_id": u.ApplicationID, - "is_trial_user": u.IsTrialUser, - "created_at": u.CreatedAt, + "device_count": deviceCount, + "online_status": onlineStatus, + "application_id": u.ApplicationID, + "is_trial_user": u.IsTrialUser, + "created_at": u.CreatedAt, } if u.Application.ID > 0 { item["application"] = gin.H{ @@ -868,18 +868,18 @@ func handleGetCloudVariables(c *gin.Context) { appName = appMap[*v.AppID] } result = append(result, gin.H{ - "id": v.ID, - "key": v.Key, - "app_id": v.AppID, - "application_name": appName, - "default_value": v.DefaultValue, - "var_type": v.VarType, - "max_records": v.MaxRecords, - "scope": v.Scope, - "write_permission": v.WritePermission, - "status": v.Status, - "description": v.Description, - "created_at": v.CreatedAt.Format("2006-01-02T15:04:05Z07:00"), + "id": v.ID, + "key": v.Key, + "app_id": v.AppID, + "application_name": appName, + "default_value": v.DefaultValue, + "var_type": v.VarType, + "max_records": v.MaxRecords, + "scope": v.Scope, + "write_permission": v.WritePermission, + "status": v.Status, + "description": v.Description, + "created_at": v.CreatedAt.Format("2006-01-02T15:04:05Z07:00"), }) } diff --git a/backend/internal/router/extension/extension.go b/backend/internal/router/extension/extension.go index 6e2e051..0274c06 100644 --- a/backend/internal/router/extension/extension.go +++ b/backend/internal/router/extension/extension.go @@ -819,18 +819,18 @@ func handleGetAppInfo(c *gin.Context) { } response.Success(c, gin.H{ - "id": app.ID, - "name": app.Name, - "description": app.Description, - "billing_type": app.BillingType, - "encrypt_type": app.EncryptType, - "bind_type": app.BindType, - "max_devices": app.MaxDevices, + "id": app.ID, + "name": app.Name, + "description": app.Description, + "billing_type": app.BillingType, + "encrypt_type": app.EncryptType, + "bind_type": app.BindType, + "max_devices": app.MaxDevices, "multi_open_mode": app.MultiOpenMode, - "enable_trial": app.EnableTrial, - "trial_balance": app.TrialBalance, - "status": app.Status, - "created_at": app.CreatedAt, + "enable_trial": app.EnableTrial, + "trial_balance": app.TrialBalance, + "status": app.Status, + "created_at": app.CreatedAt, }) } diff --git a/backend/internal/router/frontend/frontend.go b/backend/internal/router/frontend/frontend.go index a4dd376..f24eace 100644 --- a/backend/internal/router/frontend/frontend.go +++ b/backend/internal/router/frontend/frontend.go @@ -798,8 +798,8 @@ func handleGetPublicStats(c *gin.Context) { database.DB.Model(&model.Card{}).Where("status = ?", "used").Count(&totalVerifications) response.Success(c, gin.H{ - "totalApps": totalApps, - "totalUsers": totalUsers, + "totalApps": totalApps, + "totalUsers": totalUsers, "totalVerifications": totalVerifications, }) } diff --git a/backend/internal/router/install/install.go b/backend/internal/router/install/install.go index 041601b..7b97f75 100644 --- a/backend/internal/router/install/install.go +++ b/backend/internal/router/install/install.go @@ -120,21 +120,21 @@ func handleTestDatabase(c *gin.Context) { } type SetupRequest struct { - DbType string `json:"db_type"` - DbHost string `json:"db_host"` - DbPort string `json:"db_port"` - DbName string `json:"db_name"` - DbUsername string `json:"db_username"` - DbPassword string `json:"db_password"` - JwtSecret string `json:"jwt_secret"` - AdminUser string `json:"admin_user"` - AdminPass string `json:"admin_pass"` - AdminEmail string `json:"admin_email"` - UseRedis bool `json:"use_redis"` - RedisHost string `json:"redis_host"` - RedisPort string `json:"redis_port"` - RedisPass string `json:"redis_password"` - RedisDb int `json:"redis_db"` + DbType string `json:"db_type"` + DbHost string `json:"db_host"` + DbPort string `json:"db_port"` + DbName string `json:"db_name"` + DbUsername string `json:"db_username"` + DbPassword string `json:"db_password"` + JwtSecret string `json:"jwt_secret"` + AdminUser string `json:"admin_user"` + AdminPass string `json:"admin_pass"` + AdminEmail string `json:"admin_email"` + UseRedis bool `json:"use_redis"` + RedisHost string `json:"redis_host"` + RedisPort string `json:"redis_port"` + RedisPass string `json:"redis_password"` + RedisDb int `json:"redis_db"` } func handleSetup(c *gin.Context) { diff --git a/backend/internal/router/router.go b/backend/internal/router/router.go index afee5f7..a9094d1 100644 --- a/backend/internal/router/router.go +++ b/backend/internal/router/router.go @@ -4,9 +4,9 @@ import ( "time" "verification-platform-backend/internal/middleware" + "verification-platform-backend/internal/router/admin" "verification-platform-backend/internal/router/agent" "verification-platform-backend/internal/router/app" - "verification-platform-backend/internal/router/admin" "verification-platform-backend/internal/router/extension" "verification-platform-backend/internal/router/frontend" "verification-platform-backend/internal/router/install" diff --git a/backend/internal/scheduler/cleanup.go b/backend/internal/scheduler/cleanup.go index 83fbfce..a7a56a2 100644 --- a/backend/internal/scheduler/cleanup.go +++ b/backend/internal/scheduler/cleanup.go @@ -10,22 +10,22 @@ import ( ) type CleanupConfig struct { - EnableAutoCleanup bool - CleanupIntervalHours int - CaptchaRetentionDays int - VerifyCodeRetentionDays int - ApiUsageRetentionDays int - WebhookLogRetentionDays int + EnableAutoCleanup bool + CleanupIntervalHours int + CaptchaRetentionDays int + VerifyCodeRetentionDays int + ApiUsageRetentionDays int + WebhookLogRetentionDays int DeviceSessionRetentionDays int } var defaultConfig = CleanupConfig{ - EnableAutoCleanup: false, - CleanupIntervalHours: 24, - CaptchaRetentionDays: 1, - VerifyCodeRetentionDays: 7, - ApiUsageRetentionDays: 30, - WebhookLogRetentionDays: 30, + EnableAutoCleanup: false, + CleanupIntervalHours: 24, + CaptchaRetentionDays: 1, + VerifyCodeRetentionDays: 7, + ApiUsageRetentionDays: 30, + WebhookLogRetentionDays: 30, DeviceSessionRetentionDays: 7, } diff --git a/frontend/src/pages/admin/protect/index.vue b/frontend/src/pages/admin/protect/index.vue index dcfdd85..317099c 100644 --- a/frontend/src/pages/admin/protect/index.vue +++ b/frontend/src/pages/admin/protect/index.vue @@ -81,17 +81,32 @@ const eligibleProfiles = computed(() => { const selectedProfile = computed(() => eligibleProfiles.value.find(p => String(p.id) === selectedSignProfile.value) || null) +const selectedMultiIdentity = computed(() => { + const p = selectedProfile.value + return !!p && (p.key_count || 0) > 1 +}) + const selectedExpired = computed(() => { const p = selectedProfile.value if (!p || !p.not_after) return false return new Date(p.not_after).getTime() < Date.now() }) +function certMeta(p: SignProfile) { + const certs = p.cert_count || 0 + const keys = p.key_count || 0 + if (!certs) return '' + if (keys > 1) return ` · ${keys} 套私钥` + if (certs > 1) return ` · 含链 ${certs} 张` + return '' +} + function certLabel(p: SignProfile) { const exp = p.not_after ? new Date(p.not_after).toISOString().slice(0, 10) : '无到期信息' const left = p.not_after ? Math.ceil((new Date(p.not_after).getTime() - Date.now()) / 86400000) : null - if (left !== null && left < 0) return `${p.name}(到期 ${exp} · 已过期)` - return `${p.name}(到期 ${exp})` + const meta = certMeta(p) + if (left !== null && left < 0) return `${p.name}(到期 ${exp} · 已过期${meta})` + return `${p.name}(到期 ${exp}${meta})` } function daysToExpire(p: SignProfile) { @@ -455,6 +470,9 @@ onBeforeUnmount(() => {

{{ eligibleProfiles.length ? t('admin.protect.signProfileHint') : t('admin.protect.signProfileEmpty') }}

+

+ {{ t('admin.protect.signProfileMultiWarn', { n: selectedProfile!.key_count, subject: selectedProfile!.subject }) }} +

{{ t('admin.protect.signProfileExpiredWarn') }}

diff --git a/frontend/src/pages/admin/sign-profiles/components/columns.ts b/frontend/src/pages/admin/sign-profiles/components/columns.ts index 2e142ad..a5f1672 100644 --- a/frontend/src/pages/admin/sign-profiles/components/columns.ts +++ b/frontend/src/pages/admin/sign-profiles/components/columns.ts @@ -67,6 +67,20 @@ export function getColumns(options: ColumnOptions, t: (key: string) => string): }, size: 190, }, + { + accessorKey: 'cert_count', + header: () => t('admin.signProfiles.colCerts'), + // 链式包(1 私钥 + N 张链证书)是好事;多身份包要提示只用了第一套 + cell: ({ row }) => { + const certs = row.original.cert_count || 0 + const keys = row.original.key_count || 0 + if (!certs) return h('span', { class: 'text-xs text-muted-foreground' }, '-') + if (keys > 1) + return h(Badge, { variant: 'outline', class: 'border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-400' }, () => `${certs} 张 / ${keys} 套私钥`) + return h('span', { class: 'text-xs text-muted-foreground' }, keys === 1 && certs > 1 ? `${certs} 张(含链)` : `${certs} 张`) + }, + size: 150, + }, { accessorKey: 'has_profile', header: () => t('admin.signProfiles.colProvision'), diff --git a/frontend/src/pages/admin/sign-profiles/data/schema.ts b/frontend/src/pages/admin/sign-profiles/data/schema.ts index ee41977..3f6eef2 100644 --- a/frontend/src/pages/admin/sign-profiles/data/schema.ts +++ b/frontend/src/pages/admin/sign-profiles/data/schema.ts @@ -3,6 +3,8 @@ export interface SignProfile { platform: 'windows' | 'ios' name: string cert_format: string + cert_count: number + key_count: number subject: string not_after: string | null status: string diff --git a/frontend/src/plugins/i18n/en.json b/frontend/src/plugins/i18n/en.json index 7b00b59..deb02d6 100644 --- a/frontend/src/plugins/i18n/en.json +++ b/frontend/src/plugins/i18n/en.json @@ -2630,7 +2630,8 @@ "signProfileHint": "The artifact is Authenticode re-signed with the selected certificate after patching; leave empty to keep it unsigned", "signProfileEmpty": "No active certificate for this platform — upload one in Signing certificates first", "signProfileUnsupported": "This file type has no code-signing: APK uses the server keystore, ELF is not signed", - "signProfileExpiredWarn": "The selected certificate has expired: the signature is still written into the artifact, but Windows treats it as untrusted. Fine for internal distribution; use a valid certificate for public releases." + "signProfileExpiredWarn": "The selected certificate has expired: the signature is still written into the artifact, but Windows treats it as untrusted. Fine for internal distribution; use a valid certificate for public releases.", + "signProfileMultiWarn": "This file holds {n} private keys; only the first identity ({subject}) is used. Export another identity as its own pfx if you need it." }, "signProfiles": { "title": "Signing certificates", @@ -2676,7 +2677,8 @@ "colExpires": "Expires", "noExpiry": "No expiry info", "expired": "Expired", - "daysLeft": "days left" + "daysLeft": "days left", + "colCerts": "Certificates" } }, "auth": { diff --git a/frontend/src/plugins/i18n/zh.json b/frontend/src/plugins/i18n/zh.json index 2f1b8a2..9556b61 100644 --- a/frontend/src/plugins/i18n/zh.json +++ b/frontend/src/plugins/i18n/zh.json @@ -2649,7 +2649,8 @@ "signProfileHint": "选中证书会在加壳完成后用它对产物做 Authenticode 重签;不选则产物保持未签名", "signProfileEmpty": "还没有可用的同平台证书,先去「签名证书」上传", "signProfileUnsupported": "该文件类型没有代码签名机制:APK 用服务端 keystore,ELF 不签名", - "signProfileExpiredWarn": "所选证书已过期:签名仍会写入产物,但 Windows 会因证书过期判定签名不受信任(自用/内网分发可用,对外发布建议换新证书)" + "signProfileExpiredWarn": "所选证书已过期:签名仍会写入产物,但 Windows 会因证书过期判定签名不受信任(自用/内网分发可用,对外发布建议换新证书)", + "signProfileMultiWarn": "该证书文件里含 {n} 套私钥,签名只会使用第一套({subject});如需用其它一套,请把它单独导出成 pfx" }, "signProfiles": { "title": "签名证书", @@ -2695,7 +2696,8 @@ "colExpires": "到期时间", "noExpiry": "无到期信息", "expired": "已过期", - "daysLeft": "天后过期" + "daysLeft": "天后过期", + "colCerts": "证书数" } }, "auth": {