From b42a40434fa4e62c17fd8b0bcf2a29938e99cfa9 Mon Sep 17 00:00:00 2001 From: hermes Date: Sun, 22 Nov 2026 14:03:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(protect):=20=E8=AF=81=E4=B9=A6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=98=BE=E7=A4=BA=20CN=EF=BC=8C=E5=A4=9A=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E6=94=B9=E6=88=90=E8=A1=A8=E6=A0=BC=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=EF=BC=88=E5=90=AB=E8=BF=87=E6=9C=9F/=E5=90=8A=E9=94=80/?= =?UTF-8?q?=E6=8B=89=E9=BB=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈两点: 1) 列表应显示证书名称(CN),原来只显示自己填的名称标签; 2) 一个 pfx 装多套签名时应该列表展示,且列表里要能看到黑名单、吊销、是否过期。 改动: - 签名证书列表新增「证书名称(CN)」列(CN 提取取 CN= 后第一段, 原来用 .pop() 会取到最后一段,显示成 O=xxx / C=CN) - 每行新增「身份列表」按钮,打开对话框用表格展示每套身份: 序号 / 证书名称 / 到期 / 是否过期 / 可签类型 / 吊销 / 拉黑 / 操作 - 后端新增批量检测:GET /dev/sign-profiles/:id/identities?check=range&from=&to= (单次最多 20 套,内部并发 6,避免把 CA 端点打爆),也保留 ?check=N 单套 - 前端「全部检测」按批循环到全部查完,显示「已检测 N/总数」; 每行也能单独检测 - 状态配色:正常绿 / 已吊销红(带原因,如「私钥泄露」)/ 查不到琥珀(不再用灰) 实测(真实 79 套包全量检测): - 79 套全部过期(2012-2021),可签类型全是「应用」 - 查出 4 套已被 CA 吊销: #6 上海到喜啦信息技术有限公司 私钥泄露(CRL 2016-07-01) #46 MEDIATEK INC. 2015-08-24 #47 Luca Marcone 2015-07-07(OCSP certum) #75 Beijing Founder Apabi 2018-05-22(OCSP digicert) - 不在微软拉黑名单;拉黑状态全 good --- backend/internal/router/admin/signprofiles.go | 80 ++++++-- .../admin/sign-profiles/components/columns.ts | 24 ++- .../sign-profiles/components/data-table.vue | 3 + .../src/pages/admin/sign-profiles/index.vue | 183 ++++++++++++++++++ frontend/src/plugins/i18n/en.json | 24 ++- frontend/src/plugins/i18n/zh.json | 24 ++- 6 files changed, 320 insertions(+), 18 deletions(-) diff --git a/backend/internal/router/admin/signprofiles.go b/backend/internal/router/admin/signprofiles.go index 777b185..645caad 100644 --- a/backend/internal/router/admin/signprofiles.go +++ b/backend/internal/router/admin/signprofiles.go @@ -11,6 +11,7 @@ import ( "path/filepath" "strconv" "strings" + "sync" "time" "verification-platform-backend/internal/database" @@ -226,28 +227,53 @@ func HandleListIdentities(c *gin.Context) { if b, err := protect.ReadEncrypted(sp.PassPath); err == nil { password = string(b) } - // check=序号 时顺带查那一套的吊销与拉黑状态(只查一套,不整包联网) - checkIdx, _ := strconv.Atoi(c.Query("check")) - if checkIdx > 0 { + // 身份列表。带 check 参数时顺带查吊销与拉黑: + // ?check=7 只查第 7 套 + // ?check=range&from=1&to=20 批量查一段(前端分批调用,避免一次请求拖太久) + check := c.Query("check") + if check != "" { full, ferr := protect.ParseIdentitiesFull(certData, password) if ferr != nil { response.InternalError(c, "解析证书失败:"+ferr.Error()) return } - if checkIdx > len(full) { + ban := localBanMap() + + if check == "range" { + from, _ := strconv.Atoi(c.DefaultQuery("from", "1")) + to, _ := strconv.Atoi(c.DefaultQuery("to", strconv.Itoa(len(full)))) + if from < 1 { + from = 1 + } + if to > len(full) { + to = len(full) + } + if to-from+1 > 20 { + to = from + 19 // 单次最多 20 套,剩下的前端接着要 + } + if from > to { + response.ParamError(c, "范围不合法") + return + } + items := checkIdentities(full[from-1:to], from, ban) + response.Success(c, gin.H{"total": len(full), "from": from, "to": to, "items": items, + "done": to >= len(full)}) + return + } + + idx, _ := strconv.Atoi(check) + if idx < 1 || idx > len(full) { response.ParamError(c, "证书里只有 "+strconv.Itoa(len(full))+" 套身份") return } - d := full[checkIdx-1] - rev := protect.CheckRevocation(d.Cert, d.Issuer) - ban := protect.BanState(d.Cert, localBanMap()) + items := checkIdentities(full[idx-1:idx], idx, ban) response.Success(c, gin.H{ - "total": len(full), - "index": checkIdx, - "subject": d.Subject, - "revoke": rev, - "ban": ban, - "blacklist": localBanMap(), + "total": len(full), + "index": idx, + "subject": full[idx-1].Subject, + "revoke": items[0]["revoke"], + "ban": items[0]["ban"], + "items": items, }) return } @@ -405,3 +431,31 @@ func HandleDeleteBlacklist(c *gin.Context) { } response.SuccessWithMessage(c, "已从黑名单移除", nil) } + +// checkIdentities 并发检查一批身份的吊销与拉黑状态(并发 6,避免把 CA 端点打爆) +func checkIdentities(list []protect.IdentityDetail, startIndex int, ban map[string]string) []gin.H { + out := make([]gin.H, len(list)) + sem := make(chan struct{}, 6) + var wg sync.WaitGroup + for i, d := range list { + wg.Add(1) + go func(i int, d protect.IdentityDetail) { + defer wg.Done() + sem <- struct{}{} + defer func() { <-sem }() + rev := protect.CheckRevocation(d.Cert, d.Issuer) + b := protect.BanState(d.Cert, ban) + out[i] = gin.H{ + "index": d.Index, + "subject": d.Subject, + "not_after": d.NotAfter, + "expired": d.Expired, + "usage": d.Usage, + "revoke": rev, + "ban": b, + } + }(i, d) + } + wg.Wait() + return out +} diff --git a/frontend/src/pages/admin/sign-profiles/components/columns.ts b/frontend/src/pages/admin/sign-profiles/components/columns.ts index a5f1672..6257a18 100644 --- a/frontend/src/pages/admin/sign-profiles/components/columns.ts +++ b/frontend/src/pages/admin/sign-profiles/components/columns.ts @@ -1,6 +1,6 @@ import type { ColumnDef } from '@tanstack/vue-table' -import { ShieldCheck, Trash2 } from 'lucide-vue-next' +import { ListTree, ShieldCheck, Trash2 } from 'lucide-vue-next' import { h } from 'vue' import type { SignProfile } from '@/pages/admin/sign-profiles/data/schema' @@ -15,6 +15,7 @@ interface ColumnOptions { formatTime: (v: string | null) => string pendingDeleteId: number | null onDelete: (row: SignProfile) => void + onIdentities: (row: SignProfile) => void confirmLabel: string } @@ -28,6 +29,18 @@ export function getColumns(options: ColumnOptions, t: (key: string) => string): h('span', { class: 'font-medium' }, row.original.name), ]), }, + { + // 证书名称(CN):用户填的「名称」只是自己起的标签,真正决定签名者是谁的是 + // 证书里的 CN,两个都要能看见 + accessorKey: 'subject', + header: () => t('admin.signProfiles.colSubject'), + cell: ({ row }) => { + const sub = row.original.subject || '' + const cn = sub.split('CN=').pop()?.split(',')[0]?.trim() || sub || '-' + return h('div', { class: 'max-w-[260px] truncate text-xs', title: sub }, cn) + }, + size: 220, + }, { accessorKey: 'platform', header: () => t('admin.signProfiles.colPlatform'), @@ -100,7 +113,12 @@ export function getColumns(options: ColumnOptions, t: (key: string) => string): header: () => t('admin.signProfiles.colActions'), cell: ({ row }) => { const pending = options.pendingDeleteId === row.original.id - return h('div', { class: 'flex justify-end' }, [ + return h('div', { class: 'flex items-center justify-end gap-1' }, [ + h(Button, { + variant: 'ghost', + size: 'sm', + onClick: () => options.onIdentities(row.original), + }, () => [h(ListTree, { class: 'h-4 w-4' }), h('span', { class: 'ml-1 text-xs' }, t('admin.signProfiles.identities'))]), h(Button, { variant: pending ? 'destructive' : 'ghost', size: 'sm', @@ -111,7 +129,7 @@ export function getColumns(options: ColumnOptions, t: (key: string) => string): ]), ]) }, - size: 120, + size: 180, }, ] } diff --git a/frontend/src/pages/admin/sign-profiles/components/data-table.vue b/frontend/src/pages/admin/sign-profiles/components/data-table.vue index 3cab458..58a22b2 100644 --- a/frontend/src/pages/admin/sign-profiles/components/data-table.vue +++ b/frontend/src/pages/admin/sign-profiles/components/data-table.vue @@ -18,6 +18,7 @@ const props = defineProps, 'columns'> & { formatTime: (v: string | null) => string pendingDeleteId: number | null onDelete: (row: SignProfile) => void + onIdentities: (row: SignProfile) => void }>() const emit = defineEmits<{ @@ -31,6 +32,7 @@ const columns = computed[]>(() => getColumns({ formatTime: props.formatTime, pendingDeleteId: props.pendingDeleteId, onDelete: props.onDelete, + onIdentities: props.onIdentities, confirmLabel: t('admin.signProfiles.confirm'), }, t)) @@ -42,6 +44,7 @@ const table = generateVueTable({ const columnLabels: Record = { name: 'admin.signProfiles.colName', + subject: 'admin.signProfiles.colSubject', platform: 'admin.signProfiles.colPlatform', cert_format: 'admin.signProfiles.colFormat', has_profile: 'admin.signProfiles.colProvision', diff --git a/frontend/src/pages/admin/sign-profiles/index.vue b/frontend/src/pages/admin/sign-profiles/index.vue index 21b19f8..4c73a37 100644 --- a/frontend/src/pages/admin/sign-profiles/index.vue +++ b/frontend/src/pages/admin/sign-profiles/index.vue @@ -28,6 +28,94 @@ const crossInput = ref(null) const certInput = ref(null) const profileInput = ref(null) +// ---- 身份列表(一个 pfx 里的每套证书)+ 吊销/拉黑检测 ---- +const identityDialog = ref(false) +const identityProfile = ref(null) +const identities = ref([]) +const identityLoading = ref(false) +const checking = ref(false) +const checkDone = ref(0) + +async function openIdentities(row: SignProfile) { + identityProfile.value = row + identityDialog.value = true + identities.value = [] + checkDone.value = 0 + identityLoading.value = true + try { + const data: any = await api.get(`/dev/sign-profiles/${row.id}/identities`) + identities.value = (data?.identities || []).map((it: any) => ({ ...it, revoke: null, ban: null })) + } + catch (e: any) { + toast.error(e?.message || '读取身份列表失败') + } + finally { + identityLoading.value = false + } +} + +// 单套检测 +async function checkOne(index: number) { + if (!identityProfile.value) return + const data: any = await api.get(`/dev/sign-profiles/${identityProfile.value.id}/identities?check=${index}`) + const item = (data?.items || [])[0] + const row = identities.value.find((it: any) => it.index === index) + if (row && item) { + row.revoke = item.revoke + row.ban = item.ban + checkDone.value = identities.value.filter((it: any) => it.revoke).length + } +} + +// 全部检测:后端单次最多 20 套,前端分批要 +async function checkAll() { + if (!identityProfile.value || checking.value) return + checking.value = true + const total = identities.value.length + try { + for (let from = 1; from <= total; from += 20) { + const to = Math.min(from + 19, total) + const data: any = await api.get(`/dev/sign-profiles/${identityProfile.value.id}/identities?check=range&from=${from}&to=${to}`) + for (const item of data?.items || []) { + const row = identities.value.find((it: any) => it.index === item.index) + if (row) { + row.revoke = item.revoke + row.ban = item.ban + } + } + checkDone.value = identities.value.filter((it: any) => it.revoke).length + } + } + catch (e: any) { + toast.error(e?.message || '检测失败') + } + finally { + checking.value = false + } +} + +// 状态文案 +function stateText(info: any) { + if (!info) return t('admin.signProfiles.notChecked') + if (info.status === 'good') return t('admin.signProfiles.revokeGood') + if (info.status === 'revoked') return (info.reason || '') || t('admin.signProfiles.revokeBad') + if (info.status === 'unknown') return t('admin.signProfiles.revokeUnknown') + return t('admin.signProfiles.notChecked') +} + +function stateClass(info: any) { + if (!info) return 'text-muted-foreground' + if (info.status === 'good') return 'text-emerald-600 dark:text-emerald-400' + if (info.status === 'revoked') return 'text-red-600 dark:text-red-400' + if (info.status === 'unknown') return 'text-amber-600 dark:text-amber-400' + return 'text-muted-foreground' +} + +function cnOf(subject: string) { + const sub = subject || '' + return sub.split('CN=').pop()?.split(',')[0]?.trim() || sub +} + async function load() { loading.value = true try { @@ -286,10 +374,105 @@ onMounted(load) :format-time="formatTime" :pending-delete-id="pendingDelete" :on-delete="remove" + :on-identities="openIdentities" @refresh="load" /> + + + + + + + {{ t('admin.signProfiles.identitiesTitle') }} · {{ identityProfile?.name }} + + + {{ t('admin.signProfiles.identitiesHint') }} + + + +
+ + + {{ checking ? t('admin.signProfiles.checking') : t('admin.signProfiles.checkAll') }} + + + {{ t('admin.signProfiles.checkProgress', { done: checkDone, total: identities.length }) }} + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {{ 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 0078eb4..f6c1807 100644 --- a/frontend/src/plugins/i18n/en.json +++ b/frontend/src/plugins/i18n/en.json @@ -2698,7 +2698,29 @@ "expired": "Expired", "daysLeft": "days left", "colCerts": "Certificates", - "uploadedSplit": "Parsed {n} identities from this file; {n} records created. Pick any one when protecting." + "uploadedSplit": "Parsed {n} identities from this file; {n} records created. Pick any one when protecting.", + "colSubject": "Certificate name (CN)", + "identities": "Identities", + "identitiesTitle": "Certificate identities", + "identitiesHint": "One pfx can hold dozens of certificates. Each row is a signable identity; check revocation/blacklist per row or in bulk.", + "colIndex": "#", + "colCertName": "Certificate", + "colExpiry": "Expires", + "colExpired": "Expired", + "colUsage": "Usage", + "colRevoke": "Revoked", + "colBan": "Blacklisted", + "checkAll": "Check all", + "checkOne": "Check", + "checking": "Checking…", + "checked": "Checked", + "yes": "Yes", + "no": "No", + "notChecked": "Not checked", + "checkProgress": "{done}/{total} checked", + "revokeGood": "OK", + "revokeBad": "Revoked", + "revokeUnknown": "Unavailable" } }, "auth": { diff --git a/frontend/src/plugins/i18n/zh.json b/frontend/src/plugins/i18n/zh.json index 6ebb920..6374b4e 100644 --- a/frontend/src/plugins/i18n/zh.json +++ b/frontend/src/plugins/i18n/zh.json @@ -2717,7 +2717,29 @@ "expired": "已过期", "daysLeft": "天后过期", "colCerts": "证书数", - "uploadedSplit": "已从该文件解析出 {n} 套证书,分别建了 {n} 条记录,加壳时可任选一套" + "uploadedSplit": "已从该文件解析出 {n} 套证书,分别建了 {n} 条记录,加壳时可任选一套", + "colSubject": "证书名称(CN)", + "identities": "身份列表", + "identitiesTitle": "证书身份", + "identitiesHint": "一个 pfx 里可能装几十套证书。每行是一套可签名身份,可单独或批量检测吊销 / 拉黑状态。", + "colIndex": "序号", + "colCertName": "证书名称", + "colExpiry": "到期", + "colExpired": "是否过期", + "colUsage": "可签类型", + "colRevoke": "吊销", + "colBan": "拉黑", + "checkAll": "全部检测", + "checkOne": "检测", + "checking": "检测中…", + "checked": "已检测", + "yes": "是", + "no": "否", + "notChecked": "未检测", + "checkProgress": "已检测 {done}/{total}", + "revokeGood": "正常", + "revokeBad": "已吊销", + "revokeUnknown": "查不到" } }, "auth": {