n20-common-lib 3.2.26 → 3.2.27
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
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message, MessageBox, Notification } from 'element-ui'
|
|
2
2
|
import { codeDate } from '../codeMap.js'
|
|
3
3
|
import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
|
|
4
|
+
import { isDnMatched } from '../dn.js'
|
|
4
5
|
/*
|
|
5
6
|
获取证书列表接口:2.7.1 IWSASkfGetCertList (DllFilePath, SucceedFunction)
|
|
6
7
|
Attached签名接口:2.7.2 IWSASkfSignData (PlainText, CertIndex, UsbKeyPin, DigestArithmetic, SucceedFunction)
|
|
@@ -62,17 +63,14 @@ function checkAvailable(fn, url, count) {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
function verifyDn(dnList, dn) {
|
|
65
|
-
if (dnList.length === 0) return 'dnListEmpty'
|
|
66
66
|
if (!dnList) return 'Empty'
|
|
67
|
+
if (dnList.length === 0) return 'dnListEmpty'
|
|
67
68
|
if (!dn) return 'dnIsEmpty'
|
|
68
69
|
|
|
69
|
-
let userDnAttrsArr = dn.split(',').map((c) => c.trim())
|
|
70
|
-
|
|
71
70
|
let isIn = false
|
|
72
71
|
let index = 0
|
|
73
72
|
dnList.find((C, i) => {
|
|
74
|
-
|
|
75
|
-
if (dnAttrsArr.every((dnAttr) => userDnAttrsArr.includes(dnAttr))) {
|
|
73
|
+
if (isDnMatched(C.certDN, dn)) {
|
|
76
74
|
index = i
|
|
77
75
|
return (isIn = true)
|
|
78
76
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message, MessageBox, Notification } from 'element-ui'
|
|
2
2
|
import { codeDate } from '../codeMap.js'
|
|
3
3
|
import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
|
|
4
|
+
import { isDnMatched } from '../dn.js'
|
|
4
5
|
/*
|
|
5
6
|
获取证书列表接口:2.7.1 IWSASkfGetCertList (DllFilePath, SucceedFunction)
|
|
6
7
|
Attached签名接口:2.7.2 IWSASkfSignData (PlainText, CertIndex, UsbKeyPin, DigestArithmetic, SucceedFunction)
|
|
@@ -62,17 +63,14 @@ function checkAvailable(fn, url, count) {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
function verifyDn(dnList, dn) {
|
|
65
|
-
if (dnList.length === 0) return 'dnListEmpty'
|
|
66
66
|
if (!dnList) return 'Empty'
|
|
67
|
+
if (dnList.length === 0) return 'dnListEmpty'
|
|
67
68
|
if (!dn) return 'dnIsEmpty'
|
|
68
69
|
|
|
69
70
|
let checkRes = 0
|
|
70
|
-
let userDnAttrsArr = dn.split(',').map((c) => c.trim())
|
|
71
|
-
|
|
72
71
|
let isIn = false
|
|
73
72
|
dnList.find((C) => {
|
|
74
|
-
|
|
75
|
-
if (dnAttrsArr.every((dnAttr) => userDnAttrsArr.includes(dnAttr))) {
|
|
73
|
+
if (isDnMatched(C.certDN, dn)) {
|
|
76
74
|
return (isIn = true)
|
|
77
75
|
}
|
|
78
76
|
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function parseDnAttrs(dn) {
|
|
2
|
+
if (!dn || typeof dn !== 'string') return []
|
|
3
|
+
return dn
|
|
4
|
+
.split(',')
|
|
5
|
+
.map(item => item.trim())
|
|
6
|
+
.filter(Boolean)
|
|
7
|
+
.map(item => {
|
|
8
|
+
const matched = item.match(/^([^=]+)\s*=\s*(.*)$/)
|
|
9
|
+
if (!matched) return null
|
|
10
|
+
return {
|
|
11
|
+
key: matched[1].trim().toUpperCase(),
|
|
12
|
+
value: matched[2].trim().replace(/\s+/g, ' ')
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
.filter(item => item && item.key && item.value)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function hasAttr(attrs, target) {
|
|
19
|
+
return attrs.some(
|
|
20
|
+
item => item.key === target.key && item.value === target.value
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getCn(attrs) {
|
|
25
|
+
const cn = attrs.find(item => item.key === 'CN')
|
|
26
|
+
return cn && cn.value
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseCA(dn) {
|
|
30
|
+
return getCn(parseDnAttrs(dn)) || ''
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isCertCheckFailed(result) {
|
|
34
|
+
return (
|
|
35
|
+
result === -1 ||
|
|
36
|
+
result === false ||
|
|
37
|
+
['dnListEmpty', 'Empty', 'dnIsEmpty'].includes(result)
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isDnMatched(certDn, userDn) {
|
|
42
|
+
if (!certDn || !userDn) return false
|
|
43
|
+
if (certDn.trim() === userDn.trim()) return true
|
|
44
|
+
|
|
45
|
+
const certAttrs = parseDnAttrs(certDn)
|
|
46
|
+
const userAttrs = parseDnAttrs(userDn)
|
|
47
|
+
if (!certAttrs.length || !userAttrs.length) return false
|
|
48
|
+
|
|
49
|
+
if (userAttrs.every(attr => hasAttr(certAttrs, attr))) return true
|
|
50
|
+
if (certAttrs.every(attr => hasAttr(userAttrs, attr))) return true
|
|
51
|
+
|
|
52
|
+
if (certAttrs.length > 1 && userAttrs.length > 1) return false
|
|
53
|
+
|
|
54
|
+
const certCn = getCn(certAttrs)
|
|
55
|
+
const userCn = getCn(userAttrs)
|
|
56
|
+
return certCn && userCn && certCn === userCn
|
|
57
|
+
}
|
package/src/plugins/Sign/sign.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Message, Notification } from 'element-ui'
|
|
3
3
|
|
|
4
4
|
import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
|
|
5
|
+
import { isCertCheckFailed, isDnMatched, parseCA } from './dn.js'
|
|
5
6
|
|
|
6
7
|
const {
|
|
7
8
|
IWSASetTimeOut,
|
|
@@ -82,7 +83,7 @@ export function verifySign(signedMsg) {
|
|
|
82
83
|
*/
|
|
83
84
|
export async function getSign(plain, dn) {
|
|
84
85
|
let index = await getCertInfo(dn)
|
|
85
|
-
if (index
|
|
86
|
+
if (isCertCheckFailed(index)) return
|
|
86
87
|
let plainText = typeof plain === 'object' ? JSON.stringify(plain) : plain
|
|
87
88
|
|
|
88
89
|
return await performSign(plainText, index)
|
|
@@ -99,22 +100,25 @@ export function getCertInfo(dn) {
|
|
|
99
100
|
}
|
|
100
101
|
if (!dn) {
|
|
101
102
|
Message.error('没有获取到签名参数DN!')
|
|
102
|
-
return
|
|
103
|
+
return 'dnIsEmpty'
|
|
103
104
|
}
|
|
104
105
|
return new Promise((resolve, reject) => {
|
|
105
106
|
let certInfo
|
|
106
107
|
IWSAGetAllCertsListInfoByCertDN('', 'Sign', parseCA(dn), 0, (dnList) => {
|
|
107
108
|
if (!dn) {
|
|
108
109
|
Message.error('没有获取到签名参数DN!')
|
|
109
|
-
|
|
110
|
+
resolve('dnIsEmpty')
|
|
111
|
+
return
|
|
110
112
|
}
|
|
111
113
|
if (!dnList) {
|
|
112
114
|
Message.error('没有获取到证书列表!')
|
|
113
|
-
|
|
115
|
+
resolve('Empty')
|
|
116
|
+
return
|
|
114
117
|
}
|
|
115
118
|
if (dnList.length === 0) {
|
|
116
119
|
Message.error('获取到的证书列表为空!')
|
|
117
|
-
|
|
120
|
+
resolve('dnListEmpty')
|
|
121
|
+
return
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
certInfo = verifyDn(dnList, dn)
|
|
@@ -150,12 +154,6 @@ export async function performSign(plain, index) {
|
|
|
150
154
|
* @param {string} dn 要解析的Dn
|
|
151
155
|
* @returns {string} 解析后的CN
|
|
152
156
|
*/
|
|
153
|
-
function parseCA(dn) {
|
|
154
|
-
const mark = /^CN=/
|
|
155
|
-
let CN = dn.split(',').find((b) => mark.test(b))
|
|
156
|
-
return CN ? CN.replace(mark, '') : ''
|
|
157
|
-
}
|
|
158
|
-
|
|
159
157
|
/**
|
|
160
158
|
* 验证Dn是否存在于Dn列表中
|
|
161
159
|
* @param {Array} dnList 获取到的Dn列表
|
|
@@ -163,12 +161,9 @@ function parseCA(dn) {
|
|
|
163
161
|
* @returns {number} - 如果找到匹配的 DN,则返回其在 dnList 中的索引;如果未找到,则返回 -1
|
|
164
162
|
*/
|
|
165
163
|
function verifyDn(dnList, dn) {
|
|
166
|
-
let userDnAttrsArr = dn.split(',').map((c) => c.trim())
|
|
167
|
-
|
|
168
164
|
let index = -1
|
|
169
165
|
dnList.find((C, i) => {
|
|
170
|
-
|
|
171
|
-
if (userDnAttrsArr.every((dnAttr) => dnAttrsArr.includes(dnAttr))) {
|
|
166
|
+
if (isDnMatched(C.certDN, dn)) {
|
|
172
167
|
index = i
|
|
173
168
|
return true
|
|
174
169
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Message, MessageBox, Notification } from 'element-ui'
|
|
3
3
|
|
|
4
4
|
import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
|
|
5
|
+
import { isCertCheckFailed, isDnMatched } from '../dn.js'
|
|
5
6
|
|
|
6
7
|
const {
|
|
7
8
|
IWSASetTimeOut,
|
|
@@ -84,7 +85,7 @@ export function verifySign(signedMsg) {
|
|
|
84
85
|
*/
|
|
85
86
|
export async function getSign(plain, dn) {
|
|
86
87
|
let index = await getCertInfo(dn)
|
|
87
|
-
if (index
|
|
88
|
+
if (isCertCheckFailed(index)) return
|
|
88
89
|
let plainText = typeof plain === 'object' ? JSON.stringify(plain) : plain
|
|
89
90
|
if (
|
|
90
91
|
navigator.platform.toLowerCase().includes('linux') ||
|
|
@@ -119,7 +120,7 @@ export function getCertInfo(dn) {
|
|
|
119
120
|
}
|
|
120
121
|
if (!dn) {
|
|
121
122
|
Message.error('没有获取到签名参数DN!')
|
|
122
|
-
return
|
|
123
|
+
return 'dnIsEmpty'
|
|
123
124
|
}
|
|
124
125
|
if (
|
|
125
126
|
navigator.platform.toLowerCase().includes('linux') ||
|
|
@@ -135,15 +136,18 @@ export function getCertInfo(dn) {
|
|
|
135
136
|
IWSAGetAllCertsListInfo('infosec.sm2', 'Sign', 0, (dnList) => {
|
|
136
137
|
if (!dn) {
|
|
137
138
|
Message.error('没有获取到签名参数DN!')
|
|
138
|
-
|
|
139
|
+
resolve('dnIsEmpty')
|
|
140
|
+
return
|
|
139
141
|
}
|
|
140
142
|
if (!dnList) {
|
|
141
143
|
Message.error('没有获取到证书列表!')
|
|
142
|
-
|
|
144
|
+
resolve('Empty')
|
|
145
|
+
return
|
|
143
146
|
}
|
|
144
147
|
if (dnList.length === 0) {
|
|
145
148
|
Message.error('用户证书信息与当前用户不匹配!')
|
|
146
|
-
|
|
149
|
+
resolve('dnListEmpty')
|
|
150
|
+
return
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
certInfo = verifyDn(dnList, dn)
|
|
@@ -235,12 +239,10 @@ async function performSignSkf(plainText, value) {
|
|
|
235
239
|
* @returns {number} - 如果找到匹配的 DN,则返回其在 dnList 中的索引;如果未找到,则返回 -1
|
|
236
240
|
*/
|
|
237
241
|
function verifyDn(dnList, dn) {
|
|
238
|
-
let userDnAttrsArr = dn.split(',').map((c) => c.trim())
|
|
239
242
|
let index = -1
|
|
240
243
|
// 先过滤满足证书的条件
|
|
241
244
|
let dnListA = JSON.parse(JSON.stringify(dnList)).filter((C, i) => {
|
|
242
|
-
|
|
243
|
-
if (userDnAttrsArr.every((dnAttr) => dnAttrsArr.includes(dnAttr))) {
|
|
245
|
+
if (isDnMatched(C.certDN, dn)) {
|
|
244
246
|
C.index = i
|
|
245
247
|
certDN = C.certDN
|
|
246
248
|
return C
|