-
Notifications
You must be signed in to change notification settings - Fork 3
/
ukey_tool.c
123 lines (99 loc) · 2.8 KB
/
ukey_tool.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// Created by a8398 on 2020/6/4.
//
#include "auth.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "include/dev_manager.h"
#include "include/util.h"
const char* usage = "usage: ukey_tool {reset | init} \n\treset: delete app in ukey \n\tinit: create app and file in ukey";
extern const int gMaxRetryCnt;
extern const int gFileLen;
//删除ukey内的app
int DelApp(){
ULONG ret = 0 ;
char* errmsg = NULL;
DEVMANAGER *devman = DEVMANAGER_new();
ret = DEVMANAGER_DevAuth(devman);
if (ret != SAR_OK){
errmsg = "DEVMANAGER_DevAuth";
goto END;
}
char nameList[1024]; memset(nameList,0,sizeof nameList);
ULONG ulBufSize = sizeof nameList;
ret = SKF_EnumApplication(devman->devhandle, nameList, &ulBufSize);
if (ret != SAR_OK){
errmsg = "SKF_EnumApplication";
goto END;
}
if( strlen(nameList) == 0 ){
errmsg = "no app in ukey ";
goto END;
}
ret = SKF_DeleteApplication(devman->devhandle, nameList);
if (ret != SAR_OK){
errmsg = "SKF_DeleteApplication";
goto END;
}
END:
DEVMANAGER_free(devman);
if (errmsg){ printf("%s \t",errmsg);}
ShowErrInfo(ret);
return ret;
}
//创建默认应用和文件
int FactoryInit() {
int ret = 0;
char* errmsg = NULL;
DEVMANAGER *devman = DEVMANAGER_new();
ret = DEVMANAGE_PromtDevname(devman);
if (ret!=SAR_OK){
goto END;
}
DEVMANAGER_OpenDev(devman);
ret = DEVMANAGER_DevAuth(devman);
if (ret != SAR_OK){
errmsg = "DEVMANAGER_DevAuth";
goto END;
}
ret = SKF_CreateApplication(devman->devhandle, devman->appName,\
devman->adminPIN, gMaxRetryCnt,devman->userPIN , gMaxRetryCnt, \
SECURE_USER_ACCOUNT,&devman->happlication);
if (ret != SAR_OK){
errmsg = "SKF_CreateApplication";
goto END;
}
ULONG ulRetryCount;
ret = SKF_VerifyPIN(devman->happlication, USER_TYPE, devman->userPIN, &ulRetryCount);
if (ret != SAR_OK){
errmsg = "SKF_VerifyPIN";
goto END;
}
ret = SKF_CreateFile(devman->happlication, (LPSTR)devman->fileName, gFileLen, SECURE_USER_ACCOUNT , SECURE_USER_ACCOUNT);
if (ret != SAR_OK){
errmsg = "SKF_VerifyPIN";
goto END;
}
END:
DEVMANAGER_free(devman);
if (errmsg){ printf("%s \t",errmsg);}
ShowErrInfo(ret);
return ret;
}
int main(int argc, char* argv[])
{
if (argc!=2){
printf("%s \n",usage);
return 0;
}
int ret = 0;
if ( 0 == strcmp(argv[1], "init") ){
if ( (ret = FactoryInit())!=0) goto END;
}else if ( 0 == strcmp(argv[1], "reset") ){
if ( (ret = DelApp())!=0) goto END;
}
END:
ShowErrInfo(ret);
return ret;
}