@toolspack/ttd-common 0.4.8 → 0.5.0

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.
@@ -1,28 +1,16 @@
1
1
  <!--无纸化 签署-->
2
2
  <template>
3
3
  <div class="CryptoAgent-wrapper">
4
- <template v-if="isIE">
5
- <!-- id="CryptoAgent" -->
6
4
  <object ref="CryptoAgent" :codebase="publicPath+codebase" :classid="classid"></object>
7
- </template>
8
- <template v-else>
9
- <embed
10
- ref="CryptoAgent"
11
- type="application/npCryptoKit.Paperless.x86"
12
- style="height: 0px; width: 0px"
13
- />
14
- </template>
15
5
  </div>
16
6
  </template>
17
7
  <script>
18
8
  // import { getSignHash, mergeHash } from '@/api/ess'
19
9
 
20
10
  import { getUrl } from '../utils'
21
- import CheckUkeyMethods from './CheckUkeyMethods'
22
11
 
23
12
  export default {
24
13
  name: 'wzh-sing',
25
- mixins: [CheckUkeyMethods],
26
14
  data() {
27
15
  let codebase = ''
28
16
  let classid = ''
@@ -60,41 +48,37 @@ export default {
60
48
  if (this.CryptoAgent) {
61
49
  return false
62
50
  }
63
- if (this.isIE) {
64
- // 使用refs 拿到的元素 不能ukey签章
65
- // this.CryptoAgent = document.getElementById('CryptoAgent')
66
- this.CryptoAgent = this.$refs.CryptoAgent
67
- if (!this.CryptoAgent) {
68
- alert('验签插件加载失败!')
69
- }
70
- console.log('加载this.CryptoAgent ', this.CryptoAgent)
71
- } else {
72
- return false
51
+ // 使用refs 拿到的元素 不能ukey签章
52
+ // this.CryptoAgent = document.getElementById('CryptoAgent')
53
+ this.CryptoAgent = this.$refs.CryptoAgent
54
+ if (!this.CryptoAgent) {
55
+ alert('验签插件加载失败!')
73
56
  }
57
+ console.log('加载this.CryptoAgent ', this.CryptoAgent)
74
58
  },
75
59
 
76
60
  getUkeyImage() {
77
61
  let image = ''
78
62
  try {
79
63
  image = this.CryptoAgent.GetSealImage('CFCA_UKEY_P11.dll')
80
- console.log('UyeePKCS11', image)
64
+ console.log('CFCA_UKEY_P11', image)
81
65
  } catch (e) {
82
- console.log('error', e)
66
+ console.log('CFCA_UKEY_P11 error', e)
83
67
  }
84
68
  if (!image) {
85
69
  try {
86
70
  image = this.CryptoAgent.GetSealImage('UyeePKCS11.Enterprise.dll')
87
- console.log('CFCA_UKEY_P11', image)
71
+ console.log('UyeePKCS11', image)
88
72
  } catch (e) {
89
- console.log('error', e)
73
+ console.log('UyeePKCS11 error', e)
90
74
  }
91
75
  }
92
76
  if (!image) {
93
77
  try {
94
78
  image = this.CryptoAgent.GetSealImage('UlanPKCS11.Enterprise.dll')
95
- console.log('UlanPKCS11', image)
79
+ console.log('UlanPKCS11.Enterprise', image)
96
80
  } catch (e) {
97
- console.log('error', e)
81
+ console.log('UlanPKCS11.Enterprise error', e)
98
82
  }
99
83
  }
100
84
  if (!image) {
@@ -110,6 +94,40 @@ export default {
110
94
  }
111
95
  return image
112
96
  },
97
+ // 消息签名, 生成Base64 编码的 PKCS#7 签名结果
98
+ SignOnClick() {
99
+ let errorDesc = ''
100
+ this.sourceData = `${new Date().getTime() }`
101
+ try {
102
+ const source = this.sourceData
103
+ let signature = ''
104
+ const signType = 'Attach' // 签名类型
105
+ const selectedAlg = 'SHA-1' // 哈希算法(仅对RSA算法有效,SM2默认使用SM3哈希算法):
106
+
107
+ if (signType === 'Attach') {
108
+ // PKCS#7 Attach
109
+ signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, true)
110
+ } else if (signType === 'Detach') {
111
+ // PKCS#7 Detach
112
+ signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, false)
113
+ } else {
114
+ // PKCS#1
115
+ signature = this.CryptoAgent.SignMsgPKCS1(source, selectedAlg)
116
+ }
117
+ if (!signature) {
118
+ errorDesc = this.CryptoAgent.GetLastErrorDesc()
119
+ alert(errorDesc)
120
+ return ''
121
+ }
122
+ console.log('SignOnClick 签名结果:', signature)
123
+ return signature
124
+ } catch (e) {
125
+ console.log('SignOnClick error=', e)
126
+ errorDesc = this.CryptoAgent.GetLastErrorDesc()
127
+ alert(errorDesc)
128
+ }
129
+ return ''
130
+ },
113
131
  GetCertInfoOnClick(InfoTypeID) {
114
132
  InfoTypeID = InfoTypeID || 'SubjectDN'
115
133
  console.log('GetCertInfoOnClick:InfoTypeID ', InfoTypeID)
@@ -134,7 +152,7 @@ export default {
134
152
  }
135
153
  try {
136
154
  const subjectDNFilter = '';
137
- const issuerDNFilter = 'CFCA ACS ';// CFCA ACS OCA31 ,CFCA ACS OCA32, CFCA ACS TEST OCA31
155
+ const issuerDNFilter = 'CFCA ACS';// CFCA ACS OCA31 ,CFCA ACS OCA32, CFCA ACS TEST OCA31
138
156
  const serialNumFilter = serialNo;
139
157
  const bstrSM2CSPNameList = 'Uyee CSP v6.0 (Enterprise)||CFCA FOR UKEY CSP v1.1.0'
140
158
  let bSelectCertResult = '';
@@ -0,0 +1,261 @@
1
+ <!--无纸化 签署-->
2
+ <template>
3
+ <div class="CryptoAgent-wrapper">
4
+ </div>
5
+ </template>
6
+ <script>
7
+ // import { getSignHash, mergeHash } from '@/api/ess'
8
+
9
+ import { getUrl } from '../utils'
10
+
11
+ import WZHforChrome from './WZHforChrome'
12
+
13
+ export default {
14
+ mixins: [WZHforChrome],
15
+ data() {
16
+ return {
17
+ isIE: navigator.appName.indexOf('Internet') >= 0 || navigator.appVersion.indexOf('Trident') >= 0,
18
+ sourceData: '', // 签名原文, 动态随机字符串
19
+ certType: 'RSA', // 签名算法
20
+ CryptoAgent: null,
21
+ }
22
+ },
23
+ props: {
24
+ api: {
25
+ type: Object,
26
+ required: true,
27
+ },
28
+ },
29
+ mounted() {
30
+ this.onLoad()
31
+ },
32
+ provide() {
33
+ return {
34
+ GetCertInfoOnClick: this.GetCertInfoOnClick,
35
+ SelectCertificateOnClick: this.SelectCertificateOnClick,
36
+ }
37
+ },
38
+ methods: {
39
+ /**
40
+ * 初始化验签工具包,加载 验签空间(object)
41
+ */
42
+ onLoad() {
43
+ if (this.CryptoAgent) {
44
+ console.log(3333, this.CryptoAgent)
45
+ return false
46
+ }
47
+ this.LoadObj()
48
+ },
49
+
50
+ getUkeyImage() {
51
+ let image = ''
52
+ try {
53
+ image = this.CryptoAgent.GetSealImage('CFCA_UKEY_P11.dll')
54
+ console.log('CFCA_UKEY_P11', image)
55
+ } catch (e) {
56
+ console.log('CFCA_UKEY_P11 error', e)
57
+ }
58
+ if (!image) {
59
+ try {
60
+ image = this.CryptoAgent.GetSealImage('UyeePKCS11.Enterprise.dll')
61
+ console.log('UyeePKCS11', image)
62
+ } catch (e) {
63
+ console.log('UyeePKCS11 error', e)
64
+ }
65
+ }
66
+ if (!image) {
67
+ try {
68
+ image = this.CryptoAgent.GetSealImage('UlanPKCS11.Enterprise.dll')
69
+ console.log('UlanPKCS11.Enterprise', image)
70
+ } catch (e) {
71
+ console.log('UlanPKCS11.Enterprise error', e)
72
+ }
73
+ }
74
+ if (!image) {
75
+ try {
76
+ image = this.CryptoAgent.GetSealImage('UlanPKCS11.dll')
77
+ console.log('UlanPKCS11', image)
78
+ } catch (e) {
79
+ console.log('error', e)
80
+ }
81
+ }
82
+ if (!image) {
83
+ alert('读取Ukey印章图片失败!')
84
+ }
85
+ return image
86
+ },
87
+ GetCertInfoOnClick(InfoTypeID) {
88
+ InfoTypeID = InfoTypeID || 'SubjectDN'
89
+ console.log('GetCertInfoOnClick:InfoTypeID ', InfoTypeID)
90
+ return this.CryptoAgent.GetSignCertInfo(InfoTypeID).then((response) => response.result).catch((e) => {
91
+ console.log('GetCertInfoOnClick-WzhSign: ', e)
92
+ alert(e)
93
+ })
94
+ },
95
+
96
+ async SignOnClick() {
97
+ const errorDesc = ''
98
+ this.sourceData = `${new Date().getTime() }`
99
+ const source = this.sourceData
100
+ let signature = ''
101
+ const signType = 'Attach' // 签名类型
102
+ const selectedAlg = 'SHA-1' // 哈希算法(仅对RSA算法有效,SM2默认使用SM3哈希算法):
103
+
104
+ if (signType === 'Attach') {
105
+ // PKCS#7 Attach
106
+ signature = await this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, true)
107
+ } else if (signType === 'Detach') {
108
+ // PKCS#7 Detach
109
+ signature = await this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, false)
110
+ } else {
111
+ // PKCS#1
112
+ signature = await this.CryptoAgent.SignMsgPKCS1(source, selectedAlg)
113
+ }
114
+ console.log('SignOnClick 签名结果:', signature)
115
+ return signature.result
116
+ },
117
+ async SelectCertificateOnClick(serialNo = '') {
118
+ const subjectDNFilter = '';
119
+ const issuerDNFilter = 'CFCA ACS ';// CFCA ACS OCA31 ,CFCA ACS OCA32, CFCA ACS TEST OCA31
120
+ const serialNumFilter = serialNo;
121
+ const bstrSM2CSPNameList = 'Uyee CSP v6.0 (Enterprise)||CFCA FOR UKEY CSP v1.1.0'
122
+
123
+ return this.CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter, bstrSM2CSPNameList)
124
+ .then((response) => response.result)
125
+ .catch((response) => {
126
+ console.log('SelectCertificate:', response)
127
+ alert('证书选择失败!');
128
+ });
129
+
130
+ // 返回值resSelect 在chrome下是 对象,在ie下返回是 true/false
131
+ },
132
+ async getHashValue(label, fileOss, sealImage) {
133
+ const CertContent = await this.GetCertInfoOnClick('CertContent');
134
+ this.$emit('getImg', sealImage)
135
+ if (!CertContent) {
136
+ alert('获取证书公钥失败!')
137
+ return Promise.reject()
138
+ }
139
+ if (fileOss.bucketName && fileOss.objectKey) {
140
+ return this.api.getSignHash({
141
+ jsonData: {
142
+ source: 'TTDFUND',
143
+ timestamp: new Date().getTime(),
144
+ msgBody: {
145
+ // 合同地址, 相对路径--合同文件全路径。网络地址:http://xxxxxx.pdf;阿里云地址:oss:bucketxx:key
146
+ attachfile: `oss:${fileOss.bucketName}:${fileOss.objectKey}`,
147
+ reason: '', // 签署原因
148
+ location: '', // 签署地点
149
+ signImgfileName: '', // 图片名称
150
+ signImgfile: sealImage, // 图片路径,格式同文件字段类似
151
+ pageNo: label.pageIndex, // 签章页
152
+ pageX: Number(label.X), // 签章页签章位置X坐标
153
+ pageY: Number(label.Y), // 签章页签章位置Y坐标
154
+ certBase64: CertContent, // 证书公钥
155
+ },
156
+ },
157
+ })
158
+ }
159
+ alert('文件对象不合规!')
160
+ return Promise.reject()
161
+ },
162
+ async getSignHashValue(item, fileItem, image) {
163
+ let sourceHashData = ''
164
+ const { code, data } = await this.getHashValue(item, fileItem, image);
165
+ if (code === 0) {
166
+ if (`${data.bean.code}` === '200') { sourceHashData = data.bean.pdfHash }
167
+ }
168
+ if (!sourceHashData) {
169
+ alert(`CFCA计算HASH值失败!( ${data.bean.msg || ''})`)
170
+ return false
171
+ }
172
+ // 将原文Hash值的Base64编码解码后,对其进行PKCS#7分离式签名
173
+ return this.CryptoAgent.SignHashMsgPKCS7Detached(sourceHashData, 'SHA-1')
174
+ .then((response) => ({
175
+ signature: response.result,
176
+ id: data.bean.id,
177
+ }))
178
+ .catch((response) => {
179
+ alert(response);
180
+ return false;
181
+ });
182
+ },
183
+ async signFileKeyImage(item, fileItem, image) {
184
+ const res = await this.getSignHashValue(item, fileItem, image)
185
+ let errorMsg = '计算Hash 失败!'
186
+ if (res) {
187
+ const { data, code } = await this.api.mergeHash({
188
+ jsonData: {
189
+ source: 'TTDFUND',
190
+ timestamp: new Date().getTime(),
191
+ msgBody: {
192
+ sigString: res.signature, // 签名后的hash值
193
+ id: res.id, // 计算接口返回的ID
194
+ },
195
+ },
196
+ })
197
+ // 此方法 code 不能完全说明正确,调用失败code 也是0
198
+ if (code === 0) {
199
+ if (data.bean.url) {
200
+ return data.bean
201
+ }
202
+ errorMsg = data.bean.msg
203
+ } else {
204
+ errorMsg = data.msg
205
+ }
206
+ }
207
+ this.$message.error(errorMsg || 'error计算Hash失败!')
208
+ return false
209
+ },
210
+ // fileOss: 为文件对象 {obje}
211
+ // isOffset: 修正印章的位置,印章加时间后需要向下修正
212
+ async multipleSign(labels, fileOss, serialNo, image, isOffset = 18) {
213
+ const serialNoBegin = await this.GetCertInfoOnClick('SerialNumber');
214
+ let result = ''
215
+ if (!image) {
216
+ alert('印章图片缺失!')
217
+ return false
218
+ }
219
+
220
+ for (let index = 0; index < labels.length; index++) {
221
+ const item = getUrl(labels[index])
222
+ // 此处for循环多个文件时候以前签署,所以提示无意义
223
+ // const message = `签署 [${text}] 位于第${label.pageIndex}页的位置,[总共:${index + 1}/${labels.length}个位置]`
224
+ if (typeof isOffset === 'number') {
225
+ // 印章统一向下偏移
226
+ item.Y -= isOffset
227
+ }
228
+ if (index > 0) {
229
+ const serialNoAgain = await this.GetCertInfoOnClick('SerialNumber');
230
+ if (serialNoBegin !== serialNoAgain) {
231
+ alert('签署过程中,请不要更换ukey!')
232
+ return false
233
+ }
234
+ // 这里签署第二个章,需要在第一个签好的文件上签署 所以用result中是文件
235
+ if (result) {
236
+ // eslint-disable-next-line
237
+ result = await this.signFileKeyImage((item), result, image)
238
+ }
239
+
240
+ console.log(`iterateSign 签章结果${index}---result----`, result)
241
+ } else {
242
+ // eslint-disable-next-line
243
+ result = await this.signFileKeyImage((item), fileOss, image)
244
+ console.log('第一个章 签章结果', result)
245
+ }
246
+ }
247
+ console.log('multipleSign 签章的结果', result)
248
+ return result
249
+ },
250
+ },
251
+ }
252
+
253
+ </script>
254
+ <style lang="less" scoped>
255
+ .CryptoAgent-wrapper {
256
+ height: 0;
257
+ width: 0;
258
+ position: absolute;
259
+ left: -5000px;
260
+ }
261
+ </style>>