n20-common-lib 2.22.84 → 2.22.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/i18n.json +7 -0
- package/src/plugins/Sign/dn.js +21 -0
- package/src/plugins/Sign/sign.js +21 -13
- package/src/plugins/Sign/signV3/sign.js +40 -1
package/package.json
CHANGED
package/src/i18n.json
CHANGED
|
@@ -6145,6 +6145,13 @@
|
|
|
6145
6145
|
"vi": "Chứng chỉ đã hết hạn",
|
|
6146
6146
|
"ja": "証明書の有効期限が切れています"
|
|
6147
6147
|
},
|
|
6148
|
+
"证书已过期": {
|
|
6149
|
+
"en": "Certificate expired",
|
|
6150
|
+
"es": "Certificado caducado",
|
|
6151
|
+
"th": "ใบรับรองหมดอายุ",
|
|
6152
|
+
"vi": "Chứng chỉ đã hết hạn",
|
|
6153
|
+
"ja": "証明書の有効期限が切れています"
|
|
6154
|
+
},
|
|
6148
6155
|
"证书已废止": {
|
|
6149
6156
|
"en": "The certificate has been revoked",
|
|
6150
6157
|
"es": "El certificado ha sido revocado",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对 NSGetCertsListInfo 中已满足业务条件的证书过滤过期项,再按到期时间倒序排列。
|
|
3
|
+
* 保留原始索引,后续签名继续使用 SDK 返回列表中的证书位置。
|
|
4
|
+
*/
|
|
5
|
+
export function getValidCerts(matchedCerts) {
|
|
6
|
+
const now = Date.now()
|
|
7
|
+
return matchedCerts
|
|
8
|
+
.map(item => ({
|
|
9
|
+
...item,
|
|
10
|
+
// SDK 已解码 validEnd,补齐 GMT 前的空格后按时间戳比较。
|
|
11
|
+
validEndTime: new Date(item.cert.validEnd?.replace(/GMT$/, ' GMT')).getTime()
|
|
12
|
+
}))
|
|
13
|
+
// 保留对缺失或无效日期的原有兼容行为,仅剔除明确过期的证书。
|
|
14
|
+
.filter(({ validEndTime }) => !(validEndTime <= now))
|
|
15
|
+
.sort((a, b) => {
|
|
16
|
+
// 无效日期放到最后;相同到期时间沿用原始列表顺序。
|
|
17
|
+
const aTime = Number.isNaN(a.validEndTime) ? -Infinity : a.validEndTime
|
|
18
|
+
const bTime = Number.isNaN(b.validEndTime) ? -Infinity : b.validEndTime
|
|
19
|
+
return bTime - aTime || a.index - b.index
|
|
20
|
+
})
|
|
21
|
+
}
|
package/src/plugins/Sign/sign.js
CHANGED
|
@@ -2,6 +2,7 @@ import { $lc } from '../../utils/i18n/index.js'
|
|
|
2
2
|
// Attached方式签名
|
|
3
3
|
import { Message, Notification } from 'element-ui'
|
|
4
4
|
import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
|
|
5
|
+
import { getValidCerts } from './dn.js'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
const {
|
|
@@ -163,24 +164,31 @@ function parseCA(dn) {
|
|
|
163
164
|
* 验证Dn是否存在于Dn列表中
|
|
164
165
|
* @param {Array} dnList 获取到的Dn列表
|
|
165
166
|
* @param {string} dn 要验证的Dn
|
|
166
|
-
* @returns {number} -
|
|
167
|
+
* @returns {number} - 返回可用证书的原始索引;未匹配或全部过期时返回 -1
|
|
167
168
|
*/
|
|
168
169
|
function verifyDn(dnList, dn) {
|
|
169
170
|
let userDnAttrsArr = dn.split(',').map((c) => c.trim())
|
|
170
171
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
172
|
+
// 沿用本分支现有 DN 属性匹配条件,同时保留每张证书的原始索引。
|
|
173
|
+
const matchedCerts = dnList
|
|
174
|
+
.map((cert, index) => ({ cert, index }))
|
|
175
|
+
.filter(({ cert }) => {
|
|
176
|
+
let dnAttrsArr = cert.certDN.split(',').map((c) => c.trim())
|
|
177
|
+
return dnAttrsArr.every((dnAttr) => userDnAttrsArr.includes(dnAttr))
|
|
178
|
+
})
|
|
179
|
+
if (matchedCerts.length === 0) {
|
|
180
|
+
const certDns = dnList.map((res) => res.certDN).join(',')
|
|
181
|
+
Message.error(`${$lc('证书Dn不匹配:')}${certDns}${$lc('里面无法匹配===>')}${dn}`)
|
|
182
|
+
return -1
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 业务匹配后过滤过期项,优先使用 validEnd 最晚的证书。
|
|
186
|
+
const validCerts = getValidCerts(matchedCerts)
|
|
187
|
+
if (validCerts.length === 0) {
|
|
188
|
+
Message.error($lc('证书已过期'))
|
|
189
|
+
return -1
|
|
183
190
|
}
|
|
191
|
+
const index = validCerts[0].index
|
|
184
192
|
if (index !== -1) {
|
|
185
193
|
// GMT时间字符串
|
|
186
194
|
const gmtTimeString = dnList[index].validEnd?.replace(/GMT$/, ' GMT')
|
|
@@ -2,6 +2,7 @@ import { $lc } from '../../../utils/i18n/index.js'
|
|
|
2
2
|
// Attached方式签名
|
|
3
3
|
import { Message, MessageBox,Notification } from 'element-ui'
|
|
4
4
|
import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
|
|
5
|
+
import { getValidCerts } from '../dn.js'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
const {
|
|
@@ -149,7 +150,8 @@ export function getCertInfo(dn) {
|
|
|
149
150
|
reject()
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
// 仅 NSGetCertsListInfo 的证书数据执行过期过滤和到期排序。
|
|
154
|
+
certInfo = verifyCertsList(dnList, dn)
|
|
153
155
|
resolve(certInfo)
|
|
154
156
|
})
|
|
155
157
|
})
|
|
@@ -231,6 +233,43 @@ async function performSignSkf(plainText, value) {
|
|
|
231
233
|
})
|
|
232
234
|
}
|
|
233
235
|
|
|
236
|
+
/**
|
|
237
|
+
* 按原有 DN、证书类型和用途筛选,过滤过期项后优先使用有效期最长的 SM2。
|
|
238
|
+
* SKF 接口继续使用原 verifyDn,不参与本次有效期处理。
|
|
239
|
+
*/
|
|
240
|
+
function verifyCertsList(dnList, dn) {
|
|
241
|
+
const userDnAttrsArr = dn.split(',').map((c) => c.trim())
|
|
242
|
+
const matchedCerts = dnList
|
|
243
|
+
.map((cert, index) => ({ cert, index }))
|
|
244
|
+
.filter(({ cert }) => {
|
|
245
|
+
const dnAttrsArr = cert.certDN.split(',').map((c) => c.trim())
|
|
246
|
+
return dnAttrsArr.every((dnAttr) => userDnAttrsArr.includes(dnAttr))
|
|
247
|
+
})
|
|
248
|
+
.filter(
|
|
249
|
+
({ cert }) => (cert.CertType === 'SM2' && cert.KeyUsage === 'signature') || cert.CertType === 'RSA'
|
|
250
|
+
)
|
|
251
|
+
if (matchedCerts.length === 0) {
|
|
252
|
+
const certDns = dnList.map((cert) => cert.certDN).join(',')
|
|
253
|
+
Message.error(`${$lc('证书Dn不匹配:')}${certDns}${$lc('里面无法匹配===>')}${dn}`)
|
|
254
|
+
return -1
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const validCerts = getValidCerts(matchedCerts)
|
|
258
|
+
if (validCerts.length === 0) {
|
|
259
|
+
Message.error($lc('证书已过期'))
|
|
260
|
+
return -1
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 列表已按到期时间倒序;优先取有效 SM2,SM2 均过期或不存在时再取 RSA。
|
|
264
|
+
const selectedCert = validCerts.find(({ cert }) => cert.CertType === 'SM2') || validCerts[0]
|
|
265
|
+
// 同步选中证书的原始索引、DN 和算法,供后续签名使用。
|
|
266
|
+
const { cert, index } = selectedCert
|
|
267
|
+
certIndex = index
|
|
268
|
+
certDN = cert.certDN
|
|
269
|
+
certType = cert.CertType === 'SM2' ? 'SM3' : 'SHA1'
|
|
270
|
+
return index
|
|
271
|
+
}
|
|
272
|
+
|
|
234
273
|
/**
|
|
235
274
|
* 验证Dn是否存在于Dn列表中
|
|
236
275
|
* @param {Array} dnList 获取到的Dn列表
|