yc-ui2 0.1.2-beta18 → 0.1.2-beta20
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/yc-ui2.common.js +18 -18
- package/dist/yc-ui2.common.js.map +1 -1
- package/dist/yc-ui2.css +1 -1
- package/dist/yc-ui2.umd.js +18 -18
- package/dist/yc-ui2.umd.js.map +1 -1
- package/dist/yc-ui2.umd.min.js +1 -1
- package/dist/yc-ui2.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/mTokenPlugin/base64.js +148 -0
- package/src/utils/mTokenPlugin/base64_backups.js +146 -0
- package/src/utils/mTokenPlugin/hunca_mToken_core.js +1447 -0
- package/src/utils/mTokenPlugin/hunca_mToken_core2.js +1455 -0
- package/src/utils/mTokenPlugin/hunca_mToken_core_backups.js +1425 -0
- package/src/utils/mTokenPlugin/mToken.js +3211 -0
- package/src/utils/mTokenPlugin/mToken_backups.js +3202 -0
- package/src/utils/mTokenPluginBeijin/formateTime.js +10 -0
- package/src/utils/mTokenPluginBeijin/xtxasyn.js +1156 -0
- package/vue.config.js +1 -0
@@ -0,0 +1,1447 @@
|
|
1
|
+
/**
|
2
|
+
* @name mTokenPlugin集成代码
|
3
|
+
* @author Akay
|
4
|
+
* @version 0.7.12
|
5
|
+
* @date 2020.07.21
|
6
|
+
*
|
7
|
+
* @description
|
8
|
+
*ver 0.7.12 2020.12.21
|
9
|
+
* 1. 新增操作系统判断,根据不同的系统加载不同的配置
|
10
|
+
*
|
11
|
+
*ver 0.7.11 2020.07.21
|
12
|
+
* 1. 解决Https的问题
|
13
|
+
*
|
14
|
+
* ver 0.7.10 2020.04.04
|
15
|
+
* 1. 新增获取设备序号
|
16
|
+
* 2. 支持多Key
|
17
|
+
*
|
18
|
+
* ver 0.7.9 2020.01.08
|
19
|
+
* 1. 支持SJK1137型号
|
20
|
+
*
|
21
|
+
* ver 0.7.8 2019.10.23
|
22
|
+
* 1. 新增UKey适配
|
23
|
+
*
|
24
|
+
* ver 0.7.4 2019.09.18
|
25
|
+
* 1. 新增证书生效,失效时间
|
26
|
+
*
|
27
|
+
* ver 0.7.3 2019.08.19
|
28
|
+
* 1. 获取证书使用者信息
|
29
|
+
*
|
30
|
+
* ver 0.7.2 2019.08.08
|
31
|
+
* 1. 新增远程解锁接口
|
32
|
+
*
|
33
|
+
* ver 0.7.1 2019.07.17
|
34
|
+
* TODO: 未安装组件时,判断组件是否安装(暂定,未解决)
|
35
|
+
*
|
36
|
+
* ver 0.7.0 2019.07.04
|
37
|
+
* 1. 更新核心文件,解决多Key插入问题
|
38
|
+
* 2. Ukey目前仅支持国密证书
|
39
|
+
*
|
40
|
+
* ver 0.6.3 2019.06.24
|
41
|
+
* 1. 修复部分Bug
|
42
|
+
*
|
43
|
+
* ver 0.6.1 2019.06.24
|
44
|
+
* 1. 支持数字信封数据解密接口
|
45
|
+
* 2. 修复加密接口错误部分。
|
46
|
+
*
|
47
|
+
* ver 0.6.0 2019.06.20
|
48
|
+
* 1. 支持数字信封数据加密接口
|
49
|
+
* 2. 暂不支持多Ukey
|
50
|
+
*
|
51
|
+
* ver 0.5.1 2019.06.19
|
52
|
+
* 1. 修正新Ukey引入导致的Bug
|
53
|
+
*
|
54
|
+
* ver 0.5 2019.06.18
|
55
|
+
* 1. 适配SJK1137型号Ukey
|
56
|
+
*
|
57
|
+
* ver 0.4 2019.03.16
|
58
|
+
* 1. 新增方法 枚举Ukey获取证书“G项信息”列表
|
59
|
+
* 2. 新增方法 将“证书G项信息”转化为“证书名称”方法
|
60
|
+
*
|
61
|
+
* ver 0.3 2018.12.10
|
62
|
+
* 1. 新增修改Ukey密码的方法
|
63
|
+
*
|
64
|
+
* ver 0.2 2018.09.26
|
65
|
+
* 1. 新增获取签名证书SN号的方法
|
66
|
+
* 2. 修正部分Bug
|
67
|
+
*
|
68
|
+
* ver 0.1 2018.09.21
|
69
|
+
* 1. 搭建初步框架
|
70
|
+
* 2. 完成签名功能
|
71
|
+
*
|
72
|
+
*/
|
73
|
+
function hunca_mToken_core() {
|
74
|
+
|
75
|
+
// eslint-disable-next-line no-undef
|
76
|
+
var token = new mToken("mTokenPlugin");
|
77
|
+
var certInfoList = null;
|
78
|
+
var singleKey = 0;
|
79
|
+
var libraryNameList = null;
|
80
|
+
|
81
|
+
if((navigator.platform == "Win32") || (navigator.platform == "Windows")){
|
82
|
+
libraryNameList = Array("GM3000","HT","SJK1137");
|
83
|
+
}else {
|
84
|
+
libraryNameList = Array("GM3000"); //国产操作系统支持GM3000型号
|
85
|
+
//libraryNameList = Array("HT"); //国产操作系统支持海泰型号
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* 错误信息
|
89
|
+
*/
|
90
|
+
var LAST_ERRORSTRING = "";
|
91
|
+
|
92
|
+
/**
|
93
|
+
* 证书用途
|
94
|
+
*/
|
95
|
+
var KEY_SPEC_TYPE_ENCRYPT = 0;
|
96
|
+
var KEY_SPEC_TYPE_SIGN = 1;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* 摘要算法
|
100
|
+
*/
|
101
|
+
var SGD_SM3 = 1;
|
102
|
+
var SGD_SHA1 = 2;
|
103
|
+
|
104
|
+
/**
|
105
|
+
* 加密算法
|
106
|
+
*/
|
107
|
+
//分组加密算法标识
|
108
|
+
var SGD_SM1_ECB = 0x00000101;
|
109
|
+
var SGD_SM1_CBC = 0x00000102;
|
110
|
+
var SGD_SM1_CFB = 0x00000104;
|
111
|
+
var SGD_SM1_OFB = 0x00000108;
|
112
|
+
var SGD_SM1_MAC = 0x00000110;
|
113
|
+
var SGD_SM4_ECB = 0x00000401;
|
114
|
+
var SGD_SM4_CBC = 0x00000402;
|
115
|
+
var SGD_SM4_CFB = 0x00000404;
|
116
|
+
var SGD_SM4_OFB = 0x00000408;
|
117
|
+
var SGD_SM4_MAC = 0x00000410;
|
118
|
+
|
119
|
+
|
120
|
+
/**
|
121
|
+
* 用户ID(固定)
|
122
|
+
*/
|
123
|
+
var USER_ID = "1234567812345678";
|
124
|
+
|
125
|
+
|
126
|
+
/**
|
127
|
+
* 错误信息提示列表
|
128
|
+
*/
|
129
|
+
var ERROR_MESSAGE_NOT_LOADLIBRARY = "控件加载失败,错误码:";
|
130
|
+
var ERROR_MESSAGE_NOT_FIND_UKEY = "未找到UKey!\n1.请确认是否安装最新驱动!\n2.计算机是否插入湖南CA UKey!";
|
131
|
+
var ERROR_MSSSAGE_FIND_MORE_UKEY = "计算机插入多个UKey,请拔除多余“湖南CA UKey”!";
|
132
|
+
var ERROR_MESSAGE_NOT_INSTANCE_DEVICE = "USBKey实例化失败,请确认此UKey是否插入计算机!\n点击‘刷新’按钮,更新设备列表。\n错误码:";
|
133
|
+
var ERROR_MESSAGE_USERPIN_LENGTH = "Ukey密码必须为4~16位!";
|
134
|
+
var ERROR_MESSAGE_USERPIN_IS_ERROR = "UKey密码错误";
|
135
|
+
var ERROR_MESSAGE_USERPIN_CHANGE_ERROR = "UKey密码修改失败";
|
136
|
+
var ERROR_MESSAGE_KEY_NOT_EXIT = "UKey不存在,请确认此UKey是否插入计算机,并点击'刷新'按钮,更新设备列表!";
|
137
|
+
var ERROR_MESSAGE_USERNAME_IS_NULL = "请点击‘刷新’按钮,更新设备列表并选择相应设备!";
|
138
|
+
var ERROR_MESSAGE_KEY_EXPORT_CERT = "证书获取失败,请加检测Key中是否存在证书!";
|
139
|
+
var ERROR_MESSAGE_SET_DIGEST_METHOD_ERROR = "设置摘要算法失败,请重新刷新浏览器!";
|
140
|
+
var ERROR_MESSAGE_SET_USERID_ERROR = "设置用户ID失败,请重新刷新浏览器";
|
141
|
+
var ERROR_MESSAGE_SIGN_ORIGINALDATA_IS_NULL = "签名失败,待签名原文不能为空";
|
142
|
+
var ERROR_MESSAGE_SIGN_ERROR = "签名失败,返回错误码:";
|
143
|
+
var ERROR_MESSAGE_USERNAMEGN_IS_NULL = "请点击‘刷新’按钮,更新设备列表并选择相应设备!";
|
144
|
+
var ERROR_MESSAGE_USERNAMEGN_TO_USERNAME_ERROR = "证书G项信息转化证书名称失败,请点击“刷新”按钮!";
|
145
|
+
var ERROR_MESSAGE_KEY_LIBRAY = "加载国密库失败!";
|
146
|
+
var ERROR_MESSAGE_ENCRYPT_DATA_IS_NULL = "加密失败:待加密原文不能为空!";
|
147
|
+
var ERROR_MESSAGE_DECRYPT_DATA_IS_NULL = "解密失败:待解密密文不能为空!";
|
148
|
+
var ERROR_MESSAGE_DECRYPT_DATA_IS_ERROR = "解密失败:请确认密文是否完整!\n解密所采用的Ukey是否为加密时的Ukey!";
|
149
|
+
var ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_FAIL = "申请解锁请求失败!";
|
150
|
+
var ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_NOT_SUPPORT = "此型号Ukey不支持解锁!";
|
151
|
+
var ERROR_MESSAGE_REMOTE_UNLOCK_FAIL = "Ukey解锁失败!";
|
152
|
+
|
153
|
+
/**
|
154
|
+
* 私有变量
|
155
|
+
*/
|
156
|
+
var tokenInfoList = null;
|
157
|
+
|
158
|
+
/**
|
159
|
+
* 私有变量
|
160
|
+
*/
|
161
|
+
var signResultSignData = null;
|
162
|
+
var signResultCert = null;
|
163
|
+
|
164
|
+
/**
|
165
|
+
* 证书信息
|
166
|
+
*/
|
167
|
+
var certSn = null; //证书Sn
|
168
|
+
var cert_subject_GN = null; //证书Gn
|
169
|
+
var cert_subject = null; //证书使用者
|
170
|
+
var cert_validTime = null; //证书失效时间
|
171
|
+
var cert_notbeforetime = null; //证书生效时间
|
172
|
+
|
173
|
+
/**
|
174
|
+
* 返回错误信息
|
175
|
+
*/
|
176
|
+
this.Hunca_GetLastError = function () {
|
177
|
+
return LAST_ERRORSTRING;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* 获取证书列表
|
182
|
+
*/
|
183
|
+
this.Hunca_GetUserList = function () {
|
184
|
+
var deviceArray = null;
|
185
|
+
var containerName = null;
|
186
|
+
var userName = null;
|
187
|
+
var tmpInfo = null;
|
188
|
+
|
189
|
+
signResultCert = null;
|
190
|
+
signResultSignData = null;
|
191
|
+
tokenInfoList = new Array(); //清空信息
|
192
|
+
|
193
|
+
for (var index = 0; index < libraryNameList.length; index++) {
|
194
|
+
// eslint-disable-next-line no-undef
|
195
|
+
libraryName = libraryNameList[index];
|
196
|
+
// eslint-disable-next-line no-undef
|
197
|
+
if (!SOF_LoadLibrary(libraryName)) {
|
198
|
+
continue;
|
199
|
+
}
|
200
|
+
|
201
|
+
deviceArray = SOF_EnumDevice();
|
202
|
+
if (null == deviceArray) {
|
203
|
+
continue;
|
204
|
+
}
|
205
|
+
|
206
|
+
for (var i = 0; i < deviceArray.length; i++) {
|
207
|
+
var tokenInfo = new Object();
|
208
|
+
//实例化设备失败
|
209
|
+
if (!SOF_GetDeviceInstance(deviceArray[i])) {
|
210
|
+
break;
|
211
|
+
}
|
212
|
+
|
213
|
+
//获取设备信息
|
214
|
+
tmpInfo = SOF_GetUserList();
|
215
|
+
if (null != tmpInfo || tmpInfo.length != 0) {
|
216
|
+
containerName = tmpInfo[0][1];
|
217
|
+
userName = tmpInfo[0][0];
|
218
|
+
|
219
|
+
// eslint-disable-next-line no-undef
|
220
|
+
tokenInfo.libraryName = libraryName; //Ukey型号
|
221
|
+
tokenInfo.serial = deviceArray[i]; //设备序列号
|
222
|
+
tokenInfo.userName = userName; //证书名称
|
223
|
+
tokenInfo.containerName = containerName; //应用名称
|
224
|
+
|
225
|
+
tokenInfoList.push(tokenInfo);
|
226
|
+
} else {
|
227
|
+
continue;
|
228
|
+
}
|
229
|
+
SOF_LogOut();
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
//返回证书信息
|
234
|
+
var userNameList = new Array();
|
235
|
+
// eslint-disable-next-line no-redeclare
|
236
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
237
|
+
userNameList[i] = tokenInfoList[i].userName;
|
238
|
+
}
|
239
|
+
|
240
|
+
if (userNameList.length == 0) {
|
241
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
242
|
+
return "";
|
243
|
+
}
|
244
|
+
|
245
|
+
return userNameList;
|
246
|
+
}
|
247
|
+
|
248
|
+
/**
|
249
|
+
* 获取证书G项信息列表
|
250
|
+
*/
|
251
|
+
this.Hunca_GetUserListGN = function () {
|
252
|
+
var deviceArray = null;
|
253
|
+
var containerName = null;
|
254
|
+
var userName = null;
|
255
|
+
var tmpInfo = null;
|
256
|
+
var certB64 = null;
|
257
|
+
var deviceSerial = "";
|
258
|
+
|
259
|
+
signResultCert = null;
|
260
|
+
signResultSignData = null;
|
261
|
+
tokenInfoList = new Array(); //清空信息
|
262
|
+
LAST_ERRORSTRING = "";
|
263
|
+
|
264
|
+
for (var index = 0; index < libraryNameList.length; index++) {
|
265
|
+
// eslint-disable-next-line no-undef
|
266
|
+
libraryName = libraryNameList[index];
|
267
|
+
//加载控件
|
268
|
+
// eslint-disable-next-line no-undef
|
269
|
+
if (!SOF_LoadLibrary(libraryName)) {
|
270
|
+
continue;
|
271
|
+
}
|
272
|
+
|
273
|
+
deviceArray = SOF_EnumDevice();
|
274
|
+
if (null == deviceArray) {
|
275
|
+
continue;
|
276
|
+
}
|
277
|
+
|
278
|
+
for (var i = 0; i < deviceArray.length; i++) {
|
279
|
+
cert_subject_GN = null;
|
280
|
+
certSn = null;
|
281
|
+
deviceSerial = deviceArray[i];
|
282
|
+
|
283
|
+
var tokenInfo = new Object();
|
284
|
+
|
285
|
+
//实例化设备失败
|
286
|
+
if (!SOF_GetDeviceInstance(deviceSerial)) {
|
287
|
+
break;
|
288
|
+
}
|
289
|
+
|
290
|
+
//获取设备信息
|
291
|
+
tmpInfo = SOF_GetUserList();
|
292
|
+
if (null != tmpInfo || tmpInfo.length != 0) {
|
293
|
+
containerName = tmpInfo[0][1];
|
294
|
+
userName = tmpInfo[0][0];
|
295
|
+
|
296
|
+
// eslint-disable-next-line no-undef
|
297
|
+
tokenInfo.libraryName = libraryName;
|
298
|
+
tokenInfo.serial = deviceArray[i]; //设备序列号
|
299
|
+
tokenInfo.userName = userName; //证书名称
|
300
|
+
tokenInfo.containerName = containerName;
|
301
|
+
} else {
|
302
|
+
continue;
|
303
|
+
}
|
304
|
+
|
305
|
+
//获取证书G项信息
|
306
|
+
certB64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_SIGN);
|
307
|
+
if (SOF_GetCertInfo(certB64)) {
|
308
|
+
tokenInfo.subjectGN = cert_subject_GN; //设备证书G项目;
|
309
|
+
} else {
|
310
|
+
continue;
|
311
|
+
}
|
312
|
+
|
313
|
+
tokenInfoList.push(tokenInfo);
|
314
|
+
SOF_LogOut();
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
//返回证书G项信息
|
319
|
+
var userNameGNList = new Array();
|
320
|
+
// eslint-disable-next-line no-redeclare
|
321
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
322
|
+
userNameGNList[i] = tokenInfoList[i].subjectGN;
|
323
|
+
}
|
324
|
+
|
325
|
+
if (userNameGNList.length == 0) {
|
326
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
327
|
+
return "";
|
328
|
+
}
|
329
|
+
|
330
|
+
/*****
|
331
|
+
if (userNameGNList.length > 1){
|
332
|
+
LAST_ERRORSTRING = ERROR_MSSSAGE_FIND_MORE_UKEY;
|
333
|
+
return "";
|
334
|
+
}
|
335
|
+
****/
|
336
|
+
return userNameGNList;
|
337
|
+
}
|
338
|
+
|
339
|
+
/**
|
340
|
+
* 将证书G项信息转化为证书名称
|
341
|
+
*/
|
342
|
+
this.Hunca_userNameGNToUserName = function (userNameGN) {
|
343
|
+
var userName = null;
|
344
|
+
LAST_ERRORSTRING = "";
|
345
|
+
if (null == userNameGN || userNameGN.length == 0) {
|
346
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAMEGN_IS_NULL;
|
347
|
+
}
|
348
|
+
|
349
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
350
|
+
if (userNameGN == tokenInfoList[i].subjectGN) {
|
351
|
+
userName = tokenInfoList[i].userName;
|
352
|
+
break;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
if (null == userName || userName.length == 0) {
|
357
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAMEGN_TO_USERNAME_ERROR;
|
358
|
+
return null;
|
359
|
+
}
|
360
|
+
return userName;
|
361
|
+
}
|
362
|
+
|
363
|
+
this.Hunca_GenRemoteUnblockRequest = function (userName) {
|
364
|
+
var tokenInfo = null; //Ukey设备信息
|
365
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
366
|
+
var request = "";
|
367
|
+
|
368
|
+
LAST_ERRORSTRING = "";
|
369
|
+
|
370
|
+
//设备名称为空
|
371
|
+
if (null == userName || userName.length == null) {
|
372
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
373
|
+
return false;
|
374
|
+
}
|
375
|
+
|
376
|
+
//查找匹配的设备序列号
|
377
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
378
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
379
|
+
return false;
|
380
|
+
}
|
381
|
+
|
382
|
+
//索引设备编号
|
383
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
384
|
+
tempTokenInfo = tokenInfoList[i];
|
385
|
+
if (tempTokenInfo.userName == userName) {
|
386
|
+
tokenInfo = tempTokenInfo;
|
387
|
+
break;
|
388
|
+
}
|
389
|
+
}
|
390
|
+
|
391
|
+
//如果所选择的设备不存在
|
392
|
+
if (null == tokenInfo) {
|
393
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
394
|
+
return false;
|
395
|
+
}
|
396
|
+
|
397
|
+
//判断设备是否支持远程解锁
|
398
|
+
if (tokenInfo.libraryName != "GM3000") {
|
399
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_NOT_SUPPORT;
|
400
|
+
return false;
|
401
|
+
}
|
402
|
+
|
403
|
+
//加载库文件
|
404
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
405
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
406
|
+
return false;
|
407
|
+
}
|
408
|
+
|
409
|
+
//实例化设备
|
410
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
411
|
+
return false;
|
412
|
+
}
|
413
|
+
|
414
|
+
//枚举容器,并选择第一个容器
|
415
|
+
if (SOF_GetUserList() == null) {
|
416
|
+
return false;
|
417
|
+
}
|
418
|
+
|
419
|
+
//远程解锁
|
420
|
+
request = SOF_GenRemoteUnblockRequest()
|
421
|
+
|
422
|
+
return request;
|
423
|
+
}
|
424
|
+
|
425
|
+
this.HUnca_GetDeviceNumber = function(userName){
|
426
|
+
var m_devNumber = null;
|
427
|
+
|
428
|
+
//设备名称为空
|
429
|
+
if (null == userName || userName.length == null) {
|
430
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
431
|
+
return false;
|
432
|
+
}
|
433
|
+
|
434
|
+
//查找匹配的设备序列号
|
435
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
436
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
437
|
+
return false;
|
438
|
+
}
|
439
|
+
|
440
|
+
//索引设备编号
|
441
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
442
|
+
// eslint-disable-next-line no-undef
|
443
|
+
tempTokenInfo = tokenInfoList[i];
|
444
|
+
// eslint-disable-next-line no-undef
|
445
|
+
if (tempTokenInfo.userName == userName) {
|
446
|
+
// eslint-disable-next-line no-undef
|
447
|
+
tokenInfo = tempTokenInfo;
|
448
|
+
break;
|
449
|
+
}
|
450
|
+
}
|
451
|
+
|
452
|
+
//如果所选择的设备不存在
|
453
|
+
// eslint-disable-next-line no-undef
|
454
|
+
if (null == tokenInfo) {
|
455
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
|
459
|
+
//加载库文件
|
460
|
+
// eslint-disable-next-line no-undef
|
461
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
462
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
463
|
+
return false;
|
464
|
+
}
|
465
|
+
|
466
|
+
//实例化设备
|
467
|
+
// eslint-disable-next-line no-undef
|
468
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
469
|
+
return false;
|
470
|
+
}
|
471
|
+
m_devNumber =SOF_GetDeviceNumber();
|
472
|
+
|
473
|
+
return m_devNumber + "";
|
474
|
+
}
|
475
|
+
|
476
|
+
this.Hunca_RemoteUnlockPIN = function (userName, response) {
|
477
|
+
var tokenInfo = null; //Ukey设备信息
|
478
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
479
|
+
var result = false;
|
480
|
+
|
481
|
+
LAST_ERRORSTRING = "";
|
482
|
+
|
483
|
+
//设备名称为空
|
484
|
+
if (null == userName || userName.length == null) {
|
485
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
486
|
+
return false;
|
487
|
+
}
|
488
|
+
|
489
|
+
//查找匹配的设备序列号
|
490
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
491
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
492
|
+
return false;
|
493
|
+
}
|
494
|
+
|
495
|
+
//索引设备编号
|
496
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
497
|
+
tempTokenInfo = tokenInfoList[i];
|
498
|
+
if (tempTokenInfo.userName == userName) {
|
499
|
+
tokenInfo = tempTokenInfo;
|
500
|
+
break;
|
501
|
+
}
|
502
|
+
}
|
503
|
+
|
504
|
+
//如果所选择的设备不存在
|
505
|
+
if (null == tokenInfo) {
|
506
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
507
|
+
return false;
|
508
|
+
}
|
509
|
+
|
510
|
+
//判断设备是否支持远程解锁
|
511
|
+
if (tokenInfo.libraryName != "GM3000") {
|
512
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_NOT_SUPPORT;
|
513
|
+
return false;
|
514
|
+
}
|
515
|
+
|
516
|
+
//加载库文件
|
517
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
518
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
519
|
+
return false;
|
520
|
+
}
|
521
|
+
|
522
|
+
//实例化设备
|
523
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
524
|
+
return false;
|
525
|
+
}
|
526
|
+
|
527
|
+
//枚举容器,并选择第一个容器
|
528
|
+
if (SOF_GetUserList() == null) {
|
529
|
+
return false;
|
530
|
+
}
|
531
|
+
|
532
|
+
//远程解锁
|
533
|
+
result = SOF_RemoteUnlockPIN(response)
|
534
|
+
return result;
|
535
|
+
}
|
536
|
+
|
537
|
+
/**
|
538
|
+
* 修改Ukey密码
|
539
|
+
*/
|
540
|
+
this.Hunca_ChangeUserPin = function (userName, oldUserPin, newUserPin) {
|
541
|
+
var tokenInfo = null; //Ukey设备信息
|
542
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
543
|
+
LAST_ERRORSTRING = "";
|
544
|
+
|
545
|
+
//设备名称为空
|
546
|
+
if (null == userName || userName.length == null) {
|
547
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
548
|
+
return false;
|
549
|
+
}
|
550
|
+
|
551
|
+
//查找匹配的设备序列号
|
552
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
553
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
554
|
+
return false;
|
555
|
+
}
|
556
|
+
|
557
|
+
//索引设备编号
|
558
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
559
|
+
tempTokenInfo = tokenInfoList[i];
|
560
|
+
if (tempTokenInfo.userName == userName) {
|
561
|
+
tokenInfo = tempTokenInfo;
|
562
|
+
break;
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
//如果所选择的设备不存在
|
567
|
+
if (null == tokenInfo) {
|
568
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
569
|
+
return false;
|
570
|
+
}
|
571
|
+
|
572
|
+
//加载库文件
|
573
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
574
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
575
|
+
}
|
576
|
+
|
577
|
+
//实例化设备
|
578
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
579
|
+
return false;
|
580
|
+
}
|
581
|
+
|
582
|
+
//修改密码
|
583
|
+
if (!SOF_ChangeUserPin(oldUserPin, newUserPin)) {
|
584
|
+
return false;
|
585
|
+
}
|
586
|
+
|
587
|
+
SOF_LogOut();
|
588
|
+
return true;
|
589
|
+
}
|
590
|
+
|
591
|
+
/**
|
592
|
+
* 对数据进行签名,并返回签名是否成功
|
593
|
+
* @param {string} originalData 待签名原文
|
594
|
+
* @param {string} userName Ukey用户名称
|
595
|
+
* @param {string} userPin Ukey密码
|
596
|
+
*/
|
597
|
+
this.Hunca_PKCS1 = function (originalData, userName, userPin) {
|
598
|
+
var libraryName = null;
|
599
|
+
var tokenInfo = null; //Ukey设备信息
|
600
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
601
|
+
var certBase64 = null; //签名证书值
|
602
|
+
|
603
|
+
LAST_ERRORSTRING = "";
|
604
|
+
// eslint-disable-next-line no-undef
|
605
|
+
signResultInfo = null;
|
606
|
+
// eslint-disable-next-line no-undef
|
607
|
+
certInfo = new Object();
|
608
|
+
//设备名称为空
|
609
|
+
if (null == userName || userName.length == null) {
|
610
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
611
|
+
return false;
|
612
|
+
}
|
613
|
+
|
614
|
+
//查找匹配的设备序列号
|
615
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
616
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
617
|
+
return false;
|
618
|
+
}
|
619
|
+
|
620
|
+
//索引设备编号
|
621
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
622
|
+
tempTokenInfo = tokenInfoList[i];
|
623
|
+
if (tempTokenInfo.userName == userName) {
|
624
|
+
tokenInfo = tempTokenInfo;
|
625
|
+
break;
|
626
|
+
}
|
627
|
+
}
|
628
|
+
|
629
|
+
//如果所选择的设备不存在
|
630
|
+
if (null == tokenInfo) {
|
631
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
632
|
+
return false;
|
633
|
+
}
|
634
|
+
|
635
|
+
//加载库文件
|
636
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
637
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
638
|
+
}
|
639
|
+
|
640
|
+
//实例化设备
|
641
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
642
|
+
return false;
|
643
|
+
}
|
644
|
+
|
645
|
+
//登陆应用
|
646
|
+
if (!SOF_Login(userPin)) {
|
647
|
+
return false;
|
648
|
+
}
|
649
|
+
|
650
|
+
//获取签名证书Base64
|
651
|
+
certBase64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_SIGN);
|
652
|
+
if (null == certBase64) {
|
653
|
+
return false;
|
654
|
+
}
|
655
|
+
|
656
|
+
//设置摘要算法
|
657
|
+
if (!SOF_SetDigestMethod(SGD_SM3)) {
|
658
|
+
return false;
|
659
|
+
}
|
660
|
+
|
661
|
+
if (!SOF_SetUserID()) {
|
662
|
+
return false;
|
663
|
+
}
|
664
|
+
|
665
|
+
//进行签名
|
666
|
+
if (!SOF_SignData(tokenInfo.containerName, SGD_SM3, originalData, certBase64)) {
|
667
|
+
return false;
|
668
|
+
}
|
669
|
+
|
670
|
+
//获取证书信息
|
671
|
+
if (!SOF_GetCertInfo(certBase64)) {
|
672
|
+
return false;
|
673
|
+
}
|
674
|
+
|
675
|
+
SOF_LogOut();
|
676
|
+
return true;
|
677
|
+
}
|
678
|
+
|
679
|
+
/**
|
680
|
+
* 获取签名结果
|
681
|
+
*/
|
682
|
+
this.Hunca_GetSignData = function () {
|
683
|
+
return signResultSignData;
|
684
|
+
}
|
685
|
+
|
686
|
+
/**
|
687
|
+
* 获取签名证书
|
688
|
+
*/
|
689
|
+
this.Hunca_GetSignCert = function () {
|
690
|
+
return signResultCert;
|
691
|
+
}
|
692
|
+
|
693
|
+
this.Hunca_GetSignCertSn = function () {
|
694
|
+
return certSn
|
695
|
+
}
|
696
|
+
|
697
|
+
this.Hunca_GetSignCertSubject = function (){
|
698
|
+
return cert_subject;
|
699
|
+
}
|
700
|
+
|
701
|
+
this.Hunca_GetValidTime = function(){
|
702
|
+
return cert_validTime;
|
703
|
+
}
|
704
|
+
|
705
|
+
this.HUnca_GetNotBeforeTime = function(){
|
706
|
+
return cert_notbeforetime;
|
707
|
+
}
|
708
|
+
/**
|
709
|
+
* 处理设备中签名证书信息
|
710
|
+
* @param {*} userName
|
711
|
+
*/
|
712
|
+
this.Hunca_DealCertInfo = function (userName) {
|
713
|
+
var tokenInfo = null; //Ukey设备信息
|
714
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
715
|
+
var certBase64 = null; //签名证书值
|
716
|
+
|
717
|
+
LAST_ERRORSTRING = "";
|
718
|
+
// eslint-disable-next-line no-undef
|
719
|
+
signResultInfo = null;
|
720
|
+
// eslint-disable-next-line no-undef
|
721
|
+
certInfo = new Object();
|
722
|
+
//设备名称为空
|
723
|
+
if (null == userName || userName.length == null) {
|
724
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
725
|
+
return false;
|
726
|
+
}
|
727
|
+
|
728
|
+
//查找匹配的设备序列号
|
729
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
730
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
731
|
+
return false;
|
732
|
+
}
|
733
|
+
|
734
|
+
//索引设备编号
|
735
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
736
|
+
tempTokenInfo = tokenInfoList[i];
|
737
|
+
if (tempTokenInfo.userName == userName) {
|
738
|
+
tokenInfo = tempTokenInfo;
|
739
|
+
break;
|
740
|
+
}
|
741
|
+
}
|
742
|
+
|
743
|
+
//如果所选择的设备不存在
|
744
|
+
if (null == tokenInfo) {
|
745
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
746
|
+
return false;
|
747
|
+
}
|
748
|
+
|
749
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
750
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
751
|
+
return false;
|
752
|
+
}
|
753
|
+
|
754
|
+
//实例化设备
|
755
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
756
|
+
return false;
|
757
|
+
}
|
758
|
+
|
759
|
+
//导出证书
|
760
|
+
certBase64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_SIGN);
|
761
|
+
if (null == certBase64 || certBase64.length == 0) {
|
762
|
+
return false;
|
763
|
+
}
|
764
|
+
|
765
|
+
SOF_GetCertInfo(certBase64);
|
766
|
+
SOF_LogOut();
|
767
|
+
return true;
|
768
|
+
}
|
769
|
+
|
770
|
+
/**
|
771
|
+
* 对数据进行数字信封加密
|
772
|
+
* @param {string} inData 待加密原文
|
773
|
+
* @param {string} userName Ukey用户名称
|
774
|
+
* @param {string} EncryptMethod 对称加密方式
|
775
|
+
* @param {string} EncryptIV 加密IV值
|
776
|
+
* @returns {string} "",加密失败;非空,加密成功
|
777
|
+
*/
|
778
|
+
this.Hunca_EncryptDataPKCS7 = function (inData, userName, EncryptMethod, EncryptIV) {
|
779
|
+
var tokenInfo = null; //Ukey设备信息
|
780
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
781
|
+
var certBase64 = null; //签名证书值
|
782
|
+
var m_EncryptMethod = "",
|
783
|
+
m_EncryptIV = "";
|
784
|
+
|
785
|
+
LAST_ERRORSTRING = "";
|
786
|
+
// eslint-disable-next-line no-undef
|
787
|
+
signResultInfo = null;
|
788
|
+
// eslint-disable-next-line no-undef
|
789
|
+
certInfo = new Object();
|
790
|
+
|
791
|
+
|
792
|
+
//设备名称为空
|
793
|
+
if (null == userName || userName.length == null) {
|
794
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
795
|
+
return "";
|
796
|
+
}
|
797
|
+
|
798
|
+
//查找匹配的设备序列号
|
799
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
800
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
801
|
+
return "";
|
802
|
+
}
|
803
|
+
|
804
|
+
//索引设备编号
|
805
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
806
|
+
tempTokenInfo = tokenInfoList[i];
|
807
|
+
if (tempTokenInfo.userName == userName) {
|
808
|
+
tokenInfo = tempTokenInfo;
|
809
|
+
break;
|
810
|
+
}
|
811
|
+
}
|
812
|
+
|
813
|
+
//如果所选择的设备不存在
|
814
|
+
if (null == tokenInfo) {
|
815
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
816
|
+
return "";
|
817
|
+
}
|
818
|
+
|
819
|
+
//加载链接库
|
820
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
821
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
822
|
+
return "";
|
823
|
+
}
|
824
|
+
|
825
|
+
//实例化设备
|
826
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
827
|
+
return "";
|
828
|
+
}
|
829
|
+
|
830
|
+
//导出加密证书
|
831
|
+
certBase64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_ENCRYPT);
|
832
|
+
if (null == certBase64 || certBase64.length == 0) {
|
833
|
+
return "";
|
834
|
+
}
|
835
|
+
|
836
|
+
//设置加密方式
|
837
|
+
|
838
|
+
m_EncryptMethod = EncryptMethod + "";
|
839
|
+
m_EncryptIV = EncryptIV + "";
|
840
|
+
|
841
|
+
if (m_EncryptMethod == null || m_EncryptMethod.length == 0) {
|
842
|
+
m_EncryptMethod = SGD_SM4_ECB;
|
843
|
+
m_EncryptIV = "";
|
844
|
+
}
|
845
|
+
|
846
|
+
if (!SOF_SetEncryptMethodAndIV(m_EncryptMethod, m_EncryptIV)) {
|
847
|
+
return "";
|
848
|
+
}
|
849
|
+
|
850
|
+
//对数据进行加密
|
851
|
+
// eslint-disable-next-line no-undef
|
852
|
+
encryptData = SOF_EncryptDataPKCS7(certBase64, inData);
|
853
|
+
|
854
|
+
SOF_LogOut();
|
855
|
+
|
856
|
+
// eslint-disable-next-line no-undef
|
857
|
+
return encryptData;
|
858
|
+
}
|
859
|
+
|
860
|
+
/**
|
861
|
+
* 对密文进行数字信封解密操作
|
862
|
+
* @param {string} encryptData 待解密密文
|
863
|
+
* @param {string} userName Ukey用户名称
|
864
|
+
* @param {string} userPin Ukey用户PIN码
|
865
|
+
* @param {string} EncryptMethod 对称加密方式
|
866
|
+
* @param {string} EncryptIV 加密IV值
|
867
|
+
* @returns {string} "",加密失败;非空,加密成功
|
868
|
+
*/
|
869
|
+
this.Hunca_DecryptDataPKCS7 = function (encryptData, userName, userPin, EncryptMethod, EncryptIV) {
|
870
|
+
var tokenInfo = null; //Ukey设备信息
|
871
|
+
var tempTokenInfo = null; //临时设备信息,循环遍历用
|
872
|
+
var m_EncryptMethod = "",
|
873
|
+
m_EncryptIV = "";
|
874
|
+
var m_EncryptData = "";
|
875
|
+
var m_DecryptData = "";
|
876
|
+
var resData = "";
|
877
|
+
|
878
|
+
LAST_ERRORSTRING = "";
|
879
|
+
// eslint-disable-next-line no-undef
|
880
|
+
signResultInfo = null;
|
881
|
+
// eslint-disable-next-line no-undef
|
882
|
+
certInfo = new Object();
|
883
|
+
|
884
|
+
|
885
|
+
m_EncryptData = "" + encryptData;
|
886
|
+
//设备名称为空
|
887
|
+
if (null == userName || userName.length == null) {
|
888
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
|
889
|
+
return "";
|
890
|
+
}
|
891
|
+
|
892
|
+
//查找匹配的设备序列号
|
893
|
+
if (null == tokenInfoList || tokenInfoList.length == 0) {
|
894
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
895
|
+
return "";
|
896
|
+
}
|
897
|
+
|
898
|
+
//索引设备编号
|
899
|
+
for (var i = 0; i < tokenInfoList.length; i++) {
|
900
|
+
tempTokenInfo = tokenInfoList[i];
|
901
|
+
if (tempTokenInfo.userName == userName) {
|
902
|
+
tokenInfo = tempTokenInfo;
|
903
|
+
break;
|
904
|
+
}
|
905
|
+
}
|
906
|
+
|
907
|
+
//如果所选择的设备不存在
|
908
|
+
if (null == tokenInfo) {
|
909
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
|
910
|
+
return "";
|
911
|
+
}
|
912
|
+
|
913
|
+
//加载链接库
|
914
|
+
if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
|
915
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
|
916
|
+
return "";
|
917
|
+
}
|
918
|
+
|
919
|
+
//实例化设备
|
920
|
+
if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
|
921
|
+
return "";
|
922
|
+
}
|
923
|
+
|
924
|
+
//登陆应用
|
925
|
+
if (!SOF_Login(userPin)) {
|
926
|
+
return "";
|
927
|
+
}
|
928
|
+
|
929
|
+
//设置加密方式
|
930
|
+
m_EncryptMethod = EncryptMethod + "";
|
931
|
+
m_EncryptIV = EncryptIV + "";
|
932
|
+
if (m_EncryptMethod == null || m_EncryptMethod.length == 0) {
|
933
|
+
m_EncryptMethod = SGD_SM4_ECB;
|
934
|
+
m_EncryptIV = "";
|
935
|
+
}
|
936
|
+
|
937
|
+
if (!SOF_SetEncryptMethodAndIV(m_EncryptMethod, m_EncryptIV)) {
|
938
|
+
return "";
|
939
|
+
}
|
940
|
+
|
941
|
+
m_DecryptData = SOF_DecryptDataPKCS7(tokenInfo.containerName, KEY_SPEC_TYPE_ENCRYPT, m_EncryptData);
|
942
|
+
if (m_DecryptData.length == 0) {
|
943
|
+
return "";
|
944
|
+
}
|
945
|
+
|
946
|
+
try {
|
947
|
+
// eslint-disable-next-line no-undef
|
948
|
+
resData = _Base64decode(m_DecryptData);
|
949
|
+
} catch (e) {
|
950
|
+
resData = m_DecryptData;
|
951
|
+
LAST_ERRORSTRING = "解密失败:Base64解码失败";
|
952
|
+
}
|
953
|
+
|
954
|
+
return resData;
|
955
|
+
}
|
956
|
+
|
957
|
+
/**
|
958
|
+
* 加载底层文件
|
959
|
+
* @returns {boolean} true,加载成功;false加载失败;
|
960
|
+
*/
|
961
|
+
function SOF_LoadLibrary(libraryName) {
|
962
|
+
var resultCode = 0;
|
963
|
+
if (libraryName == "GM3000") {
|
964
|
+
resultCode = token.SOF_LoadLibrary(token.GM3000);
|
965
|
+
}
|
966
|
+
else if (libraryName == "HT"){
|
967
|
+
resultCode = token.SOF_LoadLibrary(token.HT);
|
968
|
+
}
|
969
|
+
else if (libraryName == "SJK1137") {
|
970
|
+
resultCode = token.SOF_LoadLibrary(token.SJK1137);
|
971
|
+
}
|
972
|
+
|
973
|
+
if (resultCode != 0) {
|
974
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_LOADLIBRARY + token.SOF_GetLastError();
|
975
|
+
return false;
|
976
|
+
}
|
977
|
+
return true;
|
978
|
+
}
|
979
|
+
|
980
|
+
/**
|
981
|
+
* 枚举设备
|
982
|
+
*/
|
983
|
+
function SOF_EnumDevice() {
|
984
|
+
var deviceNameList = "";
|
985
|
+
|
986
|
+
deviceNameList = token.SOF_EnumDevice();
|
987
|
+
|
988
|
+
//检测是否插入USBKey
|
989
|
+
if (null == deviceNameList || deviceNameList.length == 0) {
|
990
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
|
991
|
+
return null;
|
992
|
+
}
|
993
|
+
|
994
|
+
return deviceNameList;
|
995
|
+
}
|
996
|
+
|
997
|
+
/**
|
998
|
+
* 实例化设备,为后续一系列操作准备
|
999
|
+
* @param {string} deviceName 设备名称
|
1000
|
+
*/
|
1001
|
+
function SOF_GetDeviceInstance(deviceName) {
|
1002
|
+
var resultCode = 0;
|
1003
|
+
|
1004
|
+
resultCode = token.SOF_GetDeviceInstance(deviceName, "");
|
1005
|
+
//设备未正常实例化
|
1006
|
+
if (resultCode != 0) {
|
1007
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_NOT_INSTANCE_DEVICE + token.SOF_GetLastError();
|
1008
|
+
return false;
|
1009
|
+
}
|
1010
|
+
return true;
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
/**
|
1014
|
+
* 枚举应用中的容器
|
1015
|
+
*/
|
1016
|
+
function SOF_GetUserList() {
|
1017
|
+
var userList = "";
|
1018
|
+
|
1019
|
+
userList = token.SOF_GetUserList();
|
1020
|
+
if (null == userList || userList.length == 0) {
|
1021
|
+
LAST_ERRORSTRING = "USBkey中未找到证书!";
|
1022
|
+
return null;
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
return userList;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
/**
|
1029
|
+
* 登陆应用,验证密码是否正确
|
1030
|
+
* @param {string} userPin
|
1031
|
+
*/
|
1032
|
+
function SOF_Login(userPin) {
|
1033
|
+
var resultCode = 0;
|
1034
|
+
var m_userPin = "" + userPin;
|
1035
|
+
var RetryCount = 0;
|
1036
|
+
|
1037
|
+
if (null == m_userPin || m_userPin.length == 0) {
|
1038
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
|
1039
|
+
return false;
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
if (m_userPin.length < 4 || m_userPin.length > 16) {
|
1043
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
|
1044
|
+
return false;
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
resultCode = token.SOF_Login(m_userPin);
|
1048
|
+
if (resultCode != 0) {
|
1049
|
+
RetryCount = SOF_GetPinRetryCount();
|
1050
|
+
if (RetryCount > 0) {
|
1051
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_IS_ERROR + ",还剩 " + RetryCount + " 次重试机会!";
|
1052
|
+
} else {
|
1053
|
+
LAST_ERRORSTRING = "UKey已经锁死,请联系管理员进行解锁!"
|
1054
|
+
}
|
1055
|
+
return false;
|
1056
|
+
}
|
1057
|
+
return true
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
/**
|
1061
|
+
* 修改UKey密码
|
1062
|
+
* @param {*} oldUserPin
|
1063
|
+
* @param {*} newUserPin
|
1064
|
+
*/
|
1065
|
+
function SOF_ChangeUserPin(oldUserPin, newUserPin) {
|
1066
|
+
var resultCode = 0;
|
1067
|
+
var m_oldUserPin = "" + oldUserPin;
|
1068
|
+
var m_newUserPin = "" + newUserPin;
|
1069
|
+
var RetryCount = 0;
|
1070
|
+
|
1071
|
+
if (null == m_oldUserPin || m_oldUserPin.length == 0) {
|
1072
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
|
1073
|
+
return false;
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
if (null == m_newUserPin || m_newUserPin.length == 0) {
|
1077
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
|
1078
|
+
return false;
|
1079
|
+
}
|
1080
|
+
|
1081
|
+
if (m_oldUserPin.length < 4 || m_oldUserPin.length > 16) {
|
1082
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
|
1083
|
+
return false;
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
if (m_newUserPin.length < 4 || m_newUserPin.length > 16) {
|
1087
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
|
1088
|
+
return false;
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
resultCode = token.SOF_ChangePassWd(m_oldUserPin, m_newUserPin);
|
1092
|
+
if (resultCode != 0) {
|
1093
|
+
RetryCount = SOF_GetPinRetryCount();
|
1094
|
+
if (RetryCount > 0) {
|
1095
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_CHANGE_ERROR + ",还剩 " + RetryCount + " 次重试机会!";
|
1096
|
+
} else {
|
1097
|
+
LAST_ERRORSTRING = "UKey已经锁死,请联系管理员进行解锁!"
|
1098
|
+
}
|
1099
|
+
return false;
|
1100
|
+
}
|
1101
|
+
return true;
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
/**
|
1105
|
+
* 返回重试次数
|
1106
|
+
*/
|
1107
|
+
function SOF_GetPinRetryCount() {
|
1108
|
+
var retryCount = 0;
|
1109
|
+
retryCount = token.SOF_GetPinRetryCount();
|
1110
|
+
return retryCount;
|
1111
|
+
}
|
1112
|
+
|
1113
|
+
function SOF_GetDeviceNumber(){
|
1114
|
+
var deviceNumber = null;
|
1115
|
+
deviceNumber = token.SOF_GetDeviceInfo(token.SGD_DEVICE_SERIAL_NUMBER);
|
1116
|
+
return deviceNumber;
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
/**
|
1120
|
+
* 导出证书值
|
1121
|
+
* @param {string} containerName 容器名称
|
1122
|
+
* @param {int} keySec 证书用途
|
1123
|
+
*/
|
1124
|
+
function SOF_ExportUserCert(containerName, keySec) {
|
1125
|
+
var certBase64;
|
1126
|
+
certBase64 = token.SOF_ExportUserCert(containerName, keySec);
|
1127
|
+
if (null == certBase64 || certBase64.length == 0) {
|
1128
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_KEY_EXPORT_CERT;
|
1129
|
+
return null;
|
1130
|
+
}
|
1131
|
+
return certBase64;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
/**
|
1135
|
+
* 设置加密算法
|
1136
|
+
* @param {*} EncryptMethod 设置加密算法
|
1137
|
+
* @param {*} EncryptIV 设置IV值
|
1138
|
+
*/
|
1139
|
+
function SOF_SetEncryptMethodAndIV(EncryptMethod, EncryptIV) {
|
1140
|
+
var resCode = 1;
|
1141
|
+
|
1142
|
+
if (EncryptMethod == undefined || EncryptMethod == null) {
|
1143
|
+
LAST_ERRORSTRING = "请设置加密方式!";
|
1144
|
+
return false;
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
// eslint-disable-next-line no-undef
|
1148
|
+
resCode = token.SOF_SetEncryptMethodAndIV(EncryptMethod, _Base64encode(EncryptIV));
|
1149
|
+
if (resCode != 0) {
|
1150
|
+
LAST_ERRORSTRING = token.SOF_GetLastError();
|
1151
|
+
return false;
|
1152
|
+
}
|
1153
|
+
return true;
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
/**
|
1157
|
+
* 设置签名算法
|
1158
|
+
* @param {}} digestMethod
|
1159
|
+
*/
|
1160
|
+
function SOF_SetDigestMethod(digestMethod) {
|
1161
|
+
var resultCode = 0;
|
1162
|
+
resultCode = token.SOF_SetDigestMethod(digestMethod);
|
1163
|
+
if (resultCode != 0) {
|
1164
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_SET_DIGEST_METHOD_ERROR;
|
1165
|
+
return false;
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
return true;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
/**
|
1172
|
+
* 设置默认USERID
|
1173
|
+
*/
|
1174
|
+
function SOF_SetUserID() {
|
1175
|
+
var resultCode = 0;
|
1176
|
+
resultCode = token.SOF_SetUserID(USER_ID);
|
1177
|
+
if (resultCode != 0) {
|
1178
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_SET_USERID_ERROR;
|
1179
|
+
return false;
|
1180
|
+
}
|
1181
|
+
return true;
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
/**
|
1185
|
+
* 数字信封加密
|
1186
|
+
* @param {String} Base64EncodeCert 加密证书值
|
1187
|
+
* @param {String} inData 待加密原文
|
1188
|
+
* @returns {*} "",表示加密失败;非空,加密成功
|
1189
|
+
*/
|
1190
|
+
function SOF_EncryptDataPKCS7(Base64EncodeCert, inData) {
|
1191
|
+
var encryptData = "";
|
1192
|
+
var inDataBase64 = "";
|
1193
|
+
var m_inData = "";
|
1194
|
+
|
1195
|
+
m_inData = "" + inData;
|
1196
|
+
if (m_inData.length == 0) {
|
1197
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_ENCRYPT_DATA_IS_NULL;
|
1198
|
+
return "";
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
// eslint-disable-next-line no-undef
|
1202
|
+
inDataBase64 = _Base64encode(m_inData)
|
1203
|
+
encryptData = token.SOF_EncryptDataPKCS7(Base64EncodeCert, inDataBase64, inData.length);
|
1204
|
+
|
1205
|
+
if (encryptData == null || encryptData.length == 0) {
|
1206
|
+
LAST_ERRORSTRING = "加密失败," + token.SOF_GetLastError();
|
1207
|
+
return "";
|
1208
|
+
}
|
1209
|
+
return encryptData;
|
1210
|
+
}
|
1211
|
+
|
1212
|
+
/**
|
1213
|
+
* 数字信封解密
|
1214
|
+
* @param {*} containerName 应用名称
|
1215
|
+
* @param {int} cerType
|
1216
|
+
* @param {*} encrypedData
|
1217
|
+
*/
|
1218
|
+
function SOF_DecryptDataPKCS7(containerName, cerType, encrypedData) {
|
1219
|
+
var m_EncrypedData = "",
|
1220
|
+
m_DecryptData = "";
|
1221
|
+
|
1222
|
+
m_EncrypedData = "" + encrypedData;
|
1223
|
+
if (containerName == null || containerName.length == 0) {
|
1224
|
+
LAST_ERRORSTRING = "应用名称不能为空!";
|
1225
|
+
return "";
|
1226
|
+
}
|
1227
|
+
|
1228
|
+
if (m_EncrypedData.length == 0) {
|
1229
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_DECRYPT_DATA_IS_NULL;
|
1230
|
+
return "";
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
try {
|
1234
|
+
m_DecryptData = token.SOF_DecryptDataPKCS7(containerName, cerType, m_EncrypedData);
|
1235
|
+
} catch (e) {
|
1236
|
+
m_DecryptData = "";
|
1237
|
+
}
|
1238
|
+
if (undefined == m_DecryptData || m_DecryptData == null || m_DecryptData == "") {
|
1239
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_DECRYPT_DATA_IS_ERROR;
|
1240
|
+
return "";
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
return m_DecryptData;
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
/**
|
1247
|
+
* 数据签名
|
1248
|
+
* @param {*} containerName
|
1249
|
+
* @param {*} ulKeySpec
|
1250
|
+
* @param {*} data
|
1251
|
+
* @param {*} certBase64
|
1252
|
+
*/
|
1253
|
+
function SOF_SignData(containerName, ulKeySpec, data, certBase64) {
|
1254
|
+
var signData = null;
|
1255
|
+
var b64Data = null;
|
1256
|
+
var m_data = "" + data;
|
1257
|
+
|
1258
|
+
|
1259
|
+
if (null == m_data || m_data.length == 0) {
|
1260
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_SIGN_ORIGINALDATA_IS_NULL;
|
1261
|
+
return false;
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
// eslint-disable-next-line no-undef
|
1265
|
+
b64Data = _Base64encode(m_data);
|
1266
|
+
// eslint-disable-next-line no-undef
|
1267
|
+
signData = token.SOF_SignData(containerName, ulKeySpec, _Base64encode(b64Data), b64Data.length)
|
1268
|
+
if (null == signData || signData.length == 0) {
|
1269
|
+
// eslint-disable-next-line no-undef
|
1270
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_SIGN_ERROR + SOF_GetLastError();
|
1271
|
+
return false;
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
signResultCert = certBase64;
|
1275
|
+
signResultSignData = signData;
|
1276
|
+
|
1277
|
+
return true;
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
/**
|
1281
|
+
* 导出证书
|
1282
|
+
* @param {*} certBase64
|
1283
|
+
*/
|
1284
|
+
function SOF_GetCertInfo(certBase64) {
|
1285
|
+
var str = null;
|
1286
|
+
var subject = null;
|
1287
|
+
var tmpList = null;
|
1288
|
+
var validTime = null;
|
1289
|
+
var notBeforetime = null;
|
1290
|
+
var key, value;
|
1291
|
+
|
1292
|
+
if (null == certBase64 || certBase64.length == 0) {
|
1293
|
+
return false;
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
cert_subject_GN = "";
|
1297
|
+
certSn = "";
|
1298
|
+
cert_subject = "";
|
1299
|
+
|
1300
|
+
str = token.SOF_GetCertInfo(certBase64, token.SGD_CERT_SERIAL);
|
1301
|
+
certSn = hexToDec(str);
|
1302
|
+
|
1303
|
+
subject = token.SOF_GetCertInfo(certBase64, token.SGD_CERT_SUBJECT);
|
1304
|
+
cert_subject = subject;
|
1305
|
+
|
1306
|
+
validTime = token.SOF_GetCertInfo(certBase64,token.SGD_CERT_VALID_TIME);
|
1307
|
+
cert_validTime = validTime;
|
1308
|
+
|
1309
|
+
notBeforetime = token.SOF_GetCertInfo(certBase64,token.SGD_CERT_NOT_BEFORE);
|
1310
|
+
cert_notbeforetime = notBeforetime;
|
1311
|
+
|
1312
|
+
tmpList = subject.split(',');
|
1313
|
+
for (var i = 0; i < tmpList.length; i++) {
|
1314
|
+
if (tmpList[i].indexOf("=") == -1) {
|
1315
|
+
continue;
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
key = tmpList[i].split('=')[0];
|
1319
|
+
value = tmpList[i].split('=')[1];
|
1320
|
+
|
1321
|
+
if (key == 'GN') {
|
1322
|
+
cert_subject_GN = value;
|
1323
|
+
break;
|
1324
|
+
}
|
1325
|
+
}
|
1326
|
+
return true;
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
|
1330
|
+
|
1331
|
+
/**
|
1332
|
+
* 登出UKey
|
1333
|
+
*/
|
1334
|
+
function SOF_LogOut() {
|
1335
|
+
token.SOF_LogOut();
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
/**
|
1339
|
+
* 生成解锁请求
|
1340
|
+
*/
|
1341
|
+
function SOF_GenRemoteUnblockRequest() {
|
1342
|
+
var request = token.SOF_GenRemoteUnblockRequest();
|
1343
|
+
if (request == null || request == "") {
|
1344
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_FAIL;
|
1345
|
+
return "";
|
1346
|
+
}
|
1347
|
+
|
1348
|
+
return request;
|
1349
|
+
}
|
1350
|
+
|
1351
|
+
function SOF_RemoteUnlockPIN(response) {
|
1352
|
+
var result = false;
|
1353
|
+
|
1354
|
+
if (null == response || response.length == 0) {
|
1355
|
+
LAST_ERRORSTRING = "解锁失败解:响应不能为空!";
|
1356
|
+
return false;
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
result = token.SOF_RemoteUnblockPIN(response);
|
1360
|
+
if (result != 0) {
|
1361
|
+
LAST_ERRORSTRING = ERROR_MESSAGE_REMOTE_UNLOCK_FAIL;
|
1362
|
+
return false;
|
1363
|
+
} else {
|
1364
|
+
return true;
|
1365
|
+
}
|
1366
|
+
}
|
1367
|
+
|
1368
|
+
function add(x, y, base) {
|
1369
|
+
var z = [];
|
1370
|
+
var n = Math.max(x.length, y.length);
|
1371
|
+
var carry = 0;
|
1372
|
+
var i = 0;
|
1373
|
+
while (i < n || carry) {
|
1374
|
+
var xi = i < x.length ? x[i] : 0;
|
1375
|
+
var yi = i < y.length ? y[i] : 0;
|
1376
|
+
var zi = carry + xi + yi;
|
1377
|
+
z.push(zi % base);
|
1378
|
+
carry = Math.floor(zi / base);
|
1379
|
+
i++;
|
1380
|
+
}
|
1381
|
+
return z;
|
1382
|
+
}
|
1383
|
+
|
1384
|
+
function multiplyByNumber(num, x, base) {
|
1385
|
+
if (num < 0) return null;
|
1386
|
+
if (num == 0) return [];
|
1387
|
+
|
1388
|
+
var result = [];
|
1389
|
+
var power = x;
|
1390
|
+
// eslint-disable-next-line no-constant-condition
|
1391
|
+
while (true) {
|
1392
|
+
if (num & 1) {
|
1393
|
+
result = add(result, power, base);
|
1394
|
+
}
|
1395
|
+
num = num >> 1;
|
1396
|
+
if (num === 0) break;
|
1397
|
+
power = add(power, power, base);
|
1398
|
+
}
|
1399
|
+
|
1400
|
+
return result;
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
function parseToDigitsArray(str, base) {
|
1404
|
+
var digits = str.split('');
|
1405
|
+
var ary = [];
|
1406
|
+
for (var i = digits.length - 1; i >= 0; i--) {
|
1407
|
+
var n = parseInt(digits[i], base);
|
1408
|
+
if (isNaN(n)) return null;
|
1409
|
+
ary.push(n);
|
1410
|
+
}
|
1411
|
+
return ary;
|
1412
|
+
}
|
1413
|
+
|
1414
|
+
|
1415
|
+
function convertBase(str, fromBase, toBase) {
|
1416
|
+
var digits = parseToDigitsArray(str, fromBase);
|
1417
|
+
if (digits === null) return null;
|
1418
|
+
|
1419
|
+
var outArray = [];
|
1420
|
+
var power = [1];
|
1421
|
+
for (var i = 0; i < digits.length; i++) {
|
1422
|
+
// invariant: at this point, fromBase^i = power
|
1423
|
+
if (digits[i]) {
|
1424
|
+
outArray = add(outArray, multiplyByNumber(digits[i], power, toBase), toBase);
|
1425
|
+
}
|
1426
|
+
power = multiplyByNumber(fromBase, power, toBase);
|
1427
|
+
}
|
1428
|
+
|
1429
|
+
var out = '';
|
1430
|
+
for (let i = outArray.length - 1; i >= 0; i--) {
|
1431
|
+
out += outArray[i].toString(toBase);
|
1432
|
+
}
|
1433
|
+
return out;
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
function decToHex(decStr) {
|
1437
|
+
var hex = convertBase(decStr, 10, 16);
|
1438
|
+
return hex ? '0x' + hex : null;
|
1439
|
+
}
|
1440
|
+
|
1441
|
+
|
1442
|
+
function hexToDec(hexStr) {
|
1443
|
+
if (hexStr.substring(0, 2) === '0x') hexStr = hexStr.substring(2);
|
1444
|
+
hexStr = hexStr.toLowerCase();
|
1445
|
+
return convertBase(hexStr, 16, 10);
|
1446
|
+
}
|
1447
|
+
}
|