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