feat(protect): 证书列表显示 CN,多身份改成表格展示(含过期/吊销/拉黑)
Docker Build / Build and Push Docker Image (push) Successful in 58s
Docker Build / Deploy to Server (push) Successful in 3s

用户反馈两点:
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
This commit is contained in:
hermes
2026-11-22 14:03:42 +08:00
parent 8134874c64
commit b42a40434f
6 changed files with 320 additions and 18 deletions
+67 -13
View File
@@ -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
}
@@ -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,
},
]
}
@@ -18,6 +18,7 @@ const props = defineProps<Omit<DataTableProps<SignProfile>, '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<ColumnDef<SignProfile>[]>(() => 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<SignProfile>({
const columnLabels: Record<string, string> = {
name: 'admin.signProfiles.colName',
subject: 'admin.signProfiles.colSubject',
platform: 'admin.signProfiles.colPlatform',
cert_format: 'admin.signProfiles.colFormat',
has_profile: 'admin.signProfiles.colProvision',
@@ -28,6 +28,94 @@ const crossInput = ref<HTMLInputElement | null>(null)
const certInput = ref<HTMLInputElement | null>(null)
const profileInput = ref<HTMLInputElement | null>(null)
// ---- 身份列表(一个 pfx 里的每套证书)+ 吊销/拉黑检测 ----
const identityDialog = ref(false)
const identityProfile = ref<SignProfile | null>(null)
const identities = ref<any[]>([])
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"
/>
</UiCardContent>
</UiCard>
</div>
<!-- 一个 pfx 里的所有身份:列表展示,含过期 / 吊销 / 拉黑状态 -->
<UiDialog v-model:open="identityDialog">
<UiDialogContent class="sm:max-w-4xl">
<UiDialogHeader>
<UiDialogTitle>
{{ t('admin.signProfiles.identitiesTitle') }} · {{ identityProfile?.name }}
</UiDialogTitle>
<UiDialogDescription>
{{ t('admin.signProfiles.identitiesHint') }}
</UiDialogDescription>
</UiDialogHeader>
<div class="flex flex-wrap items-center gap-2">
<UiButton size="sm" :disabled="checking || identityLoading" @click="checkAll">
<Loader2 v-if="checking" class="mr-1.5 h-3.5 w-3.5 animate-spin" />
{{ checking ? t('admin.signProfiles.checking') : t('admin.signProfiles.checkAll') }}
</UiButton>
<span class="text-xs text-muted-foreground">
{{ t('admin.signProfiles.checkProgress', { done: checkDone, total: identities.length }) }}
</span>
</div>
<div class="max-h-[60vh] overflow-auto rounded-md border">
<table class="w-full text-sm">
<thead class="sticky top-0 bg-muted/80 backdrop-blur">
<tr class="text-left text-xs text-muted-foreground">
<th class="px-2 py-2">
{{ t('admin.signProfiles.colIndex') }}
</th>
<th class="px-2 py-2">
{{ t('admin.signProfiles.colCertName') }}
</th>
<th class="px-2 py-2">
{{ t('admin.signProfiles.colExpiry') }}
</th>
<th class="px-2 py-2">
{{ t('admin.signProfiles.colExpired') }}
</th>
<th class="px-2 py-2">
{{ t('admin.signProfiles.colUsage') }}
</th>
<th class="px-2 py-2">
{{ t('admin.signProfiles.colRevoke') }}
</th>
<th class="px-2 py-2">
{{ t('admin.signProfiles.colBan') }}
</th>
<th class="px-2 py-2 text-right">
{{ t('admin.signProfiles.colActions') }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="it in identities" :key="it.index" class="border-t">
<td class="px-2 py-1.5 font-mono text-xs text-muted-foreground">
{{ it.index }}
</td>
<td class="max-w-[300px] truncate px-2 py-1.5" :title="it.subject">
{{ cnOf(it.subject) }}
</td>
<td class="px-2 py-1.5 text-xs">
{{ String(it.not_after).slice(0, 10) }}
</td>
<td class="px-2 py-1.5 text-xs">
<span :class="it.expired ? 'text-amber-600 dark:text-amber-400' : 'text-muted-foreground'">
{{ it.expired ? t('admin.signProfiles.yes') : t('admin.signProfiles.no') }}
</span>
</td>
<td class="px-2 py-1.5 text-xs">
{{ it.usage?.label || '-' }}
</td>
<td class="px-2 py-1.5 text-xs" :class="stateClass(it.revoke)" :title="it.revoke?.detail">
{{ stateText(it.revoke) }}
</td>
<td class="px-2 py-1.5 text-xs" :class="stateClass(it.ban)" :title="it.ban?.detail">
{{ stateText(it.ban) }}
</td>
<td class="px-2 py-1.5 text-right">
<UiButton variant="outline" size="sm" class="h-7 px-2 text-xs" :disabled="checking" @click="checkOne(it.index)">
{{ t('admin.signProfiles.checkOne') }}
</UiButton>
</td>
</tr>
<tr v-if="identityLoading">
<td colspan="8" class="px-2 py-6 text-center text-xs text-muted-foreground">
{{ t('admin.signProfiles.checking') }}
</td>
</tr>
</tbody>
</table>
</div>
</UiDialogContent>
</UiDialog>
</BasicPage>
</template>
+23 -1
View File
@@ -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": {
+23 -1
View File
@@ -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": {