diff --git a/backend/internal/router/admin/flatidentities.go b/backend/internal/router/admin/flatidentities.go new file mode 100644 index 0000000..2ccca28 --- /dev/null +++ b/backend/internal/router/admin/flatidentities.go @@ -0,0 +1,194 @@ +package admin + +// 把所有证书记录里的「每一套签名身份」拉平成一张表。 +// +// 一个 pfx 里可能装几十套证书(驱动签名包常见),用户要的是「一眼看到全部证书」, +// 而不是先点某个文件再看里面。所以这里提供扁平列表:每行就是一套身份, +// 带来源文件、到期、可签类型,吊销/拉黑状态按需检测。 + +import ( + "strconv" + "strings" + + "github.com/gin-gonic/gin" + + "verification-platform-backend/internal/database" + "verification-platform-backend/internal/model" + "verification-platform-backend/internal/protect" + "verification-platform-backend/pkg/response" +) + +// FlatIdentity 扁平列表里的一行 +type FlatIdentity struct { + Key string `json:"key"` // "profileID:index" + ProfileID uint `json:"profile_id"` + ProfileName string `json:"profile_name"` + Platform string `json:"platform"` + HasCross bool `json:"has_cross"` + Index int `json:"index"` + Subject string `json:"subject"` + CN string `json:"cn"` + NotAfter string `json:"not_after"` + Expired bool `json:"expired"` + Usage string `json:"usage_label"` + UsageApp bool `json:"usage_app"` + UsageDriver bool `json:"usage_driver"` + ParseError string `json:"parse_error,omitempty"` +} + +// HandleFlatIdentities 全部证书身份(分页) +// +// GET /dev/sign-profiles/identities-flat?page=1&page_size=50 +func HandleFlatIdentities(c *gin.Context) { + userID := c.GetUint("user_id") + page, _ := strconv.Atoi(c.DefaultQuery("page", "1")) + size, _ := strconv.Atoi(c.DefaultQuery("page_size", "50")) + if page < 1 { + page = 1 + } + if size < 1 || size > 200 { + size = 50 + } + + var profiles []model.SignProfile + if err := database.DB.Where("user_id = ?", userID).Order("id desc").Find(&profiles).Error; err != nil { + response.InternalError(c, "读取证书失败") + return + } + + all := make([]FlatIdentity, 0, len(profiles)*4) + for _, sp := range profiles { + certData, err := protect.ReadEncrypted(sp.CertPath) + if err != nil { + all = append(all, FlatIdentity{ + Key: strconv.FormatUint(uint64(sp.ID), 10) + ":0", ProfileID: sp.ID, + ProfileName: sp.Name, Platform: sp.Platform, HasCross: sp.CrossPath != "", + Subject: sp.Subject, CN: cnFromSubject(sp.Subject), ParseError: "读取证书失败", + }) + continue + } + password := "" + if b, e := protect.ReadEncrypted(sp.PassPath); e == nil { + password = string(b) + } + full, perr := protect.ParseIdentitiesFull(certData, password) + if perr != nil || len(full) == 0 { + all = append(all, FlatIdentity{ + Key: strconv.FormatUint(uint64(sp.ID), 10) + ":0", ProfileID: sp.ID, + ProfileName: sp.Name, Platform: sp.Platform, HasCross: sp.CrossPath != "", + Subject: sp.Subject, CN: cnFromSubject(sp.Subject), ParseError: "解析失败", + }) + continue + } + for _, d := range full { + all = append(all, FlatIdentity{ + Key: strconv.FormatUint(uint64(sp.ID), 10) + ":" + strconv.Itoa(d.Index), + ProfileID: sp.ID, + ProfileName: sp.Name, + Platform: sp.Platform, + HasCross: sp.CrossPath != "", + Index: d.Index, + Subject: d.Subject, + CN: cnFromSubject(d.Subject), + NotAfter: d.NotAfter.Format("2006-01-02"), + Expired: d.Expired, + Usage: d.Usage.Label, + UsageApp: d.Usage.App, + UsageDriver: d.Usage.Driver, + }) + } + } + + total := len(all) + from := (page - 1) * size + if from > total { + from = total + } + to := from + size + if to > total { + to = total + } + response.Success(c, gin.H{ + "total": total, + "page": page, + "page_size": size, + "items": all[from:to], + }) +} + +// HandleCheckIdentities 批量检测指定身份的吊销 / 拉黑(单次最多 20 个) +// +// POST /dev/sign-profiles/identities-check +// +// { "keys": ["12:3", "12:7", "15:1"] } +func HandleCheckIdentities(c *gin.Context) { + userID := c.GetUint("user_id") + var req struct { + Keys []string `json:"keys"` + } + if err := c.ShouldBindJSON(&req); err != nil || len(req.Keys) == 0 { + response.ParamError(c, "请提供要检测的身份(key = profileID:index)") + return + } + if len(req.Keys) > 20 { + req.Keys = req.Keys[:20] // 一批最多 20,剩下的前端接着要 + } + + // 按 profile 分组,减少重复解析 + byProfile := map[uint][]int{} + order := []string{} + for _, k := range req.Keys { + parts := strings.Split(k, ":") + if len(parts) != 2 { + continue + } + pid, err1 := strconv.ParseUint(parts[0], 10, 64) + idx, err2 := strconv.Atoi(parts[1]) + if err1 != nil || err2 != nil { + continue + } + byProfile[uint(pid)] = append(byProfile[uint(pid)], idx) + order = append(order, k) + } + + out := map[string]gin.H{} + ban := localBanMap() + for pid, idxs := range byProfile { + var sp model.SignProfile + if err := database.DB.Where("id = ? AND user_id = ?", pid, userID).First(&sp).Error; err != nil { + continue + } + certData, err := protect.ReadEncrypted(sp.CertPath) + if err != nil { + continue + } + password := "" + if b, e := protect.ReadEncrypted(sp.PassPath); e == nil { + password = string(b) + } + full, perr := protect.ParseIdentitiesFull(certData, password) + if perr != nil { + continue + } + var list []protect.IdentityDetail + for _, i := range idxs { + if i >= 1 && i <= len(full) { + list = append(list, full[i-1]) + } + } + res := checkIdentities(list, 0, ban) + for _, r := range res { + key := strconv.FormatUint(uint64(pid), 10) + ":" + strconv.Itoa(r["index"].(int)) + out[key] = r + } + } + + items := make([]gin.H, 0, len(order)) + for _, k := range order { + if r, ok := out[k]; ok { + r["key"] = k + items = append(items, r) + } + } + response.Success(c, gin.H{"items": items, "checked": len(items)}) +} diff --git a/backend/internal/router/admin/signprofiles.go b/backend/internal/router/admin/signprofiles.go index 1989e1c..729ba8d 100644 --- a/backend/internal/router/admin/signprofiles.go +++ b/backend/internal/router/admin/signprofiles.go @@ -27,6 +27,9 @@ func SetupSignProfileRoutes(r *gin.RouterGroup) { { g.POST("", HandleCreateSignProfile) g.GET("", HandleListSignProfiles) + // 扁平列表与批量检测要放在 /:id 之前注册,否则会被 /:id 匹配走 + g.GET("/identities-flat", HandleFlatIdentities) + g.POST("/identities-check", HandleCheckIdentities) g.GET("/:id", HandleGetSignProfile) g.GET("/:id/identities", HandleListIdentities) g.POST("/:id/export", HandleExportIdentities) diff --git a/frontend/src/pages/admin/sign-profiles/index.vue b/frontend/src/pages/admin/sign-profiles/index.vue index 500133c..962bf56 100644 --- a/frontend/src/pages/admin/sign-profiles/index.vue +++ b/frontend/src/pages/admin/sign-profiles/index.vue @@ -1,19 +1,15 @@ @@ -408,148 +397,131 @@ onMounted(load) - + - {{ t('admin.signProfiles.list') }} + {{ t('admin.signProfiles.flatListTitle') }} +

+ {{ t('admin.signProfiles.flatListHint', { total }) }} +

- - + +
+ + {{ allSelected ? t('admin.signProfiles.unselectAll') : t('admin.signProfiles.selectAll') }} + + {{ t('admin.signProfiles.selectedCount', { n: selected.length }) }} + + + {{ checking ? t('admin.signProfiles.checking') : t('admin.signProfiles.checkPage') }} + + {{ t('admin.signProfiles.checkProgress', { done: checkDone, total: rows.length }) }} + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + {{ t('admin.signProfiles.colCertName') }}{{ t('admin.signProfiles.colSource') }}{{ t('admin.signProfiles.colExpiry') }}{{ t('admin.signProfiles.colExpired') }}{{ t('admin.signProfiles.colUsage') }}{{ t('admin.signProfiles.colRevoke') }}{{ t('admin.signProfiles.colBan') }}{{ t('admin.signProfiles.colActions') }}
+ + +
+ + {{ row.cn || '-' }} +
+
+ {{ row.profile_name }} + 交叉证书 + {{ row.not_after || '-' }} + + {{ row.expired ? t('admin.signProfiles.yes') : t('admin.signProfiles.no') }} + + {{ row.usage_label || '-' }} + {{ stateText(row.revoke) }} + + {{ stateText(row.ban) }} + +
+ + {{ t('admin.signProfiles.checkOne') }} + + + + +
+
+ + {{ t('admin.signProfiles.checking') }} +
+ {{ t('admin.signProfiles.emptyList') }} +
+
+ +
+ + {{ t('admin.signProfiles.pageInfo', { page, pages: pageCount, total }) }} + +
+ + {{ t('admin.signProfiles.prevPage') }} + + + {{ t('admin.signProfiles.nextPage') }} + +
+
- - - - - - - {{ t('admin.signProfiles.identitiesTitle') }} · {{ identityProfile?.name }} - - - {{ t('admin.signProfiles.identitiesHint') }} - - - -
- - {{ selected.length === identities.length && identities.length ? t('admin.signProfiles.unselectAll') : t('admin.signProfiles.selectAll') }} - - {{ t('admin.signProfiles.selectedCount', { n: selected.length }) }} - - - {{ checking ? t('admin.signProfiles.checking') : t('admin.signProfiles.checkAll') }} - - - {{ t('admin.signProfiles.checkProgress', { done: checkDone, total: identities.length }) }} - -
- - -
- {{ t('admin.signProfiles.exportTitle') }} - - - - - {{ exporting ? t('admin.signProfiles.exporting') : t('admin.signProfiles.exportSelected') }} - - {{ t('admin.signProfiles.exportHint') }} -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - {{ t('admin.signProfiles.colIndex') }} - - {{ t('admin.signProfiles.colCertName') }} - - {{ t('admin.signProfiles.colExpiry') }} - - {{ t('admin.signProfiles.colExpired') }} - - {{ t('admin.signProfiles.colUsage') }} - - {{ t('admin.signProfiles.colRevoke') }} - - {{ t('admin.signProfiles.colBan') }} - - {{ t('admin.signProfiles.colActions') }} -
- - - {{ it.index }} - - {{ cnOf(it.subject) }} - - {{ String(it.not_after).slice(0, 10) }} - - - {{ it.expired ? t('admin.signProfiles.yes') : t('admin.signProfiles.no') }} - - - {{ it.usage?.label || '-' }} - - {{ stateText(it.revoke) }} - - {{ stateText(it.ban) }} - - - {{ t('admin.signProfiles.checkOne') }} - -
- {{ t('admin.signProfiles.checking') }} -
-
-
-
diff --git a/frontend/src/plugins/i18n/en.json b/frontend/src/plugins/i18n/en.json index f5f68a0..26b1c24 100644 --- a/frontend/src/plugins/i18n/en.json +++ b/frontend/src/plugins/i18n/en.json @@ -2732,7 +2732,20 @@ "exportDone": "Exported {n} certificates", "exportHint": "Each pfx holds one identity; filenames carry index + CN", "exportPwdHint": "Password must be at least 4 characters", - "nothingToExport": "Nothing to export" + "nothingToExport": "Nothing to export", + "flatListTitle": "Certificates (one per row)", + "flatListHint": "{total} certificates, one per row; select to check revocation/blacklist or export", + "colSource": "Source file", + "checkPage": "Check this page", + "deleteFile": "Delete whole certificate file", + "emptyList": "No certificates yet — upload a pfx above", + "pageInfo": "Page {page}/{pages} · {total} total", + "prevPage": "Prev", + "nextPage": "Next", + "uploadedWithCount": "Parsed {n} certificates", + "confirmDeleteFile": "Click again to delete the whole file: {name}", + "checkFailed": "Check failed", + "exportFailed": "Export failed" } }, "auth": { diff --git a/frontend/src/plugins/i18n/zh.json b/frontend/src/plugins/i18n/zh.json index d280cf4..75d2cab 100644 --- a/frontend/src/plugins/i18n/zh.json +++ b/frontend/src/plugins/i18n/zh.json @@ -2751,7 +2751,20 @@ "exportDone": "已导出 {n} 套证书", "exportHint": "每个 pfx 只含一套私钥+证书,文件名带序号和 CN", "exportPwdHint": "导出密码至少 4 位(pfx 必须有口令)", - "nothingToExport": "没有可导出的身份" + "nothingToExport": "没有可导出的身份", + "flatListTitle": "证书列表(每行一套证书)", + "flatListHint": "共 {total} 套证书,一行一套,可直接勾选检测吊销/拉黑或批量导出", + "colSource": "来源文件", + "checkPage": "检测本页", + "deleteFile": "删除整个证书文件", + "emptyList": "还没有证书,先在上方上传 pfx", + "pageInfo": "第 {page}/{pages} 页 · 共 {total} 套", + "prevPage": "上一页", + "nextPage": "下一页", + "uploadedWithCount": "已解析 {n} 套证书", + "confirmDeleteFile": "再点一次删除整个文件:{name}", + "checkFailed": "检测失败", + "exportFailed": "导出失败" } }, "auth": {