n20-common-lib 2.13.9 → 2.13.11

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,6 @@
1
1
  {
2
2
  "name": "n20-common-lib",
3
- "version": "2.13.9",
3
+ "version": "2.13.11",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -45,7 +45,9 @@
45
45
  :class="data[props.disabled] ? 'cursor-not' : ''"
46
46
  :style="{ color: data[props.disabled] ? 'var(--color-text-placeholder) ' : '' }"
47
47
  >
48
- {{ props.isShowNo ? '(' + data[props.value] + ') ' + data[props.label] : data[props.label] }}
48
+ {{
49
+ props.isShowNo && data[props.value] ? '(' + data[props.value] + ') ' + data[props.label] : data[props.label]
50
+ }}
49
51
  </div></el-tree
50
52
  >
51
53
  </el-select>
@@ -5,14 +5,14 @@ import { IWSAgent } from './InfosecNetSignCNGAgent.min.js'
5
5
  const {
6
6
  IWSASetTimeOut,
7
7
  IWSAAttachedSignAdvDefaultDN,
8
- IWSADetachedSignAdvDefaultDN,
8
+ IWSADetachedSign,
9
9
  IWSAAttachedVerify,
10
10
  IWSASendAvailable,
11
11
  IWSAGetAvailable,
12
12
  IWSAGetAllCertsListInfo
13
13
  } = new IWSAgent()
14
14
  IWSASetTimeOut(6000)
15
- let certType = 'RSA'
15
+ let certIndex = 0
16
16
  let certDN = ''
17
17
  function getDN() {
18
18
  let dn
@@ -103,23 +103,21 @@ export function getCertInfo(dn) {
103
103
  return new Promise((resolve, reject) => {
104
104
  let certInfo
105
105
  IWSAGetAllCertsListInfo('infosec.sm2', 'Sign', 0, (dnList) => {
106
- IWSAGetAllCertsListInfo('infosec.sm2', 'Sign', 2, (dnList2) => {
107
- if (!dn) {
108
- Message.error('没有获取到签名参数DN!')
109
- reject()
110
- }
111
- if (!dnList && !dnList2) {
112
- Message.error('没有获取到证书列表!')
113
- reject()
114
- }
115
- if (dnList.length === 0 && dnList2.length === 0) {
116
- Message.error('用户证书信息与当前用户不匹配!')
117
- reject()
118
- }
106
+ if (!dn) {
107
+ Message.error('没有获取到签名参数DN!')
108
+ reject()
109
+ }
110
+ if (!dnList) {
111
+ Message.error('没有获取到证书列表!')
112
+ reject()
113
+ }
114
+ if (dnList.length === 0) {
115
+ Message.error('用户证书信息与当前用户不匹配!')
116
+ reject()
117
+ }
119
118
 
120
- certInfo = verifyDn([...dnList, ...dnList2], dn)
121
- resolve(certInfo)
122
- })
119
+ certInfo = verifyDn(dnList, dn)
120
+ resolve(certInfo)
123
121
  })
124
122
  })
125
123
  }
@@ -131,16 +129,12 @@ export function getCertInfo(dn) {
131
129
  * @returns {Promise<string>} 签名后的密文信息
132
130
  */
133
131
  export async function performSign(plain, index) {
134
- let certStoreType = 2
135
- if (certType === 'RSA') {
136
- certStoreType = 1
137
- }
138
132
  let signMethod = IWSAAttachedSignAdvDefaultDN
139
133
  if (window.NetSignMethod === 'Detached') {
140
- signMethod = IWSADetachedSignAdvDefaultDN
134
+ signMethod = IWSADetachedSign
141
135
  }
142
136
  return new Promise((resolve, reject) => {
143
- signMethod(plain, 'infosec.sm2', certStoreType, certDN, '1', 'SHA1', (errorCode, signedData) => {
137
+ signMethod(2, plain, certIndex, 'SHA1', (errorCode, signedData) => {
144
138
  if (errorCode === 0 || errorCode === '0') {
145
139
  resolve(signedData)
146
140
  } else {
@@ -159,22 +153,30 @@ export async function performSign(plain, index) {
159
153
  */
160
154
  function verifyDn(dnList, dn) {
161
155
  let userDnAttrsArr = dn.split(',').map((c) => c.trim())
162
-
163
156
  let index = -1
164
- dnList.find((C, i) => {
157
+ // 先过滤满足证书的条件
158
+ let dnListA = JSON.parse(JSON.stringify(dnList)).filter((C, i) => {
165
159
  let dnAttrsArr = C.certDN.split(',').map((c) => c.trim())
166
160
  if (dnAttrsArr.every((dnAttr) => userDnAttrsArr.includes(dnAttr))) {
167
- index = i
168
- certType = C.CertType
169
- certDN = C.certDN // 保存证书DN到全局变量中 =
170
- return true
161
+ C.index = i
162
+ return C
171
163
  }
172
164
  })
165
+ if (dnListA.length > 0) {
166
+ dnListA.forEach((item) => {
167
+ if (item.certType === 'SM2' && item.keyUsage === 'signature') {
168
+ index = item.index
169
+ } else {
170
+ index = dnListA[0].index
171
+ }
172
+ certIndex = item.index
173
+ })
174
+ }
173
175
  if (index === -1) {
174
- let dnListA = dnList?.map((res) => res.certDN)?.join(',')
176
+ let dnListB = dnList?.map((res) => res.certDN)?.join(',')
175
177
  Message({
176
178
  type: 'error',
177
- text: `证书Dn不匹配:${dnListA}里面无法匹配===>${dn}`,
179
+ text: `证书Dn不匹配:${dnListB}里面无法匹配===>${dn}`,
178
180
  duration: 5000
179
181
  })
180
182
  return index