-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtch.c
113 lines (91 loc) · 2.32 KB
/
tch.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
#include "tch.h"
int check_arguments(int argc, char **argv, CK_FUNCTION_LIST_PTR_PTR pFunctionList)
{
int opt;
CK_RV rv;
CK_C_GetFunctionList tch_C_GetFunctionList;
while ((opt = getopt(argc, argv, "-o-i-a-m:-u:-s:-v")) != -1)
{
switch (opt)
{
case 'o':
sArguments.mode = 1;
break;
case 'm':
sArguments.filename = optarg;
break;
case 'i':
sArguments.initiate = 1;
break;
case 's':
sArguments.soPin = optarg;
break;
case 'u':
sArguments.uPin = optarg;
break;
case 'v':
sArguments.verbose = 1;
break;
default:
fprintf(stderr, "Usage: %s [-o] [-i] [-v] [-m file] [-u User PIN] [-s SO PIN]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
if(sArguments.filename) //try loading the module
{
sArguments.module = dlopen(sArguments.filename, RTLD_NOW);
if (!sArguments.module) printf("Couldn't open library: %s: %s\n", sArguments.filename, dlerror ());
//try to find what function we can use
tch_C_GetFunctionList = (CK_C_GetFunctionList) dlsym (sArguments.module, "C_GetFunctionList");
if (!tch_C_GetFunctionList)
{
printf("Couldn't find function 'C_GetFunctionList' in library: %s: %s\n", sArguments.filename, dlerror ());
}
else
{
rv = tch_C_GetFunctionList(pFunctionList);
if(rv != CKR_OK) returnValuePrinting("C_GetFunctionList", rv);
else
{
}
}
}
return 0;
}
int
main(int argc, char **argv)
{
check_arguments(argc, argv, &pFunctionList);
if(pFunctionList)
{
testFunctionsImplemented();
printTokenInformation();
testCaseMinimal();
testCaseSlotInformation();
testCaseTokenInformation();
testCaseCompareMechanismLists();
testCaseSlotEvents();
testCaseSingleSessionWithUserLogin();
testCaseMultipleSessionWithUserLogin();
testCasePreserveOperationState();
testCaseAdminToken();
testCaseChangePin();
testCaseObjectHandling();
testCaseObjectSearch();
testCaseDeAndEncryptionSimple();
testCaseDeAndEncryptionMultiple();
testCaseDigestSimple();
testCaseDigestMultiple();
testCaseSignAndVerifySimple();
testCaseSignAndVerifyMultiple();
testCaseSignAndVerifyRecover();
testCaseDualPurposeFunctions();
testCaseSingleKeyGeneration();
testCaseKeyPairGeneration();
testCaseWrapAndUnwrapKey();
testCaseDeriveKey();
testCaseGenerateRandom();
}
free(pMechaInfoList);
return 0;
}