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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
#ifndef P11TESTST_H_
#define P11TESTST_H_
#ifndef _WIN32
#include "config.h"
#endif
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
#include "pkcs11/pkcs11.h"
#include <assert.h>
#include <stdarg.h>
#include <openssl/rsa.h>
#define CK_INVALID ((CK_ULONG)-1)
extern int p11t_test_unexpected;
/* -------------------------------------------------------------------
* msg.c
*/
const char* p11t_msg_rv(CK_RV rv);
const char* p11t_msg_lasterr(void);
void p11t_msg_va(const char *message, va_list va);
void p11t_msg_code(const char* code, const char *message, va_list va);
void p11t_msg_print(const char *message, ...);
void p11t_msg_fatal(const char *message, ...);
const char* p11t_msg_prefix(const char *prefix);
#define p11t_msg_here() \
(__func__ "() at " __FILE__ ":" __LINE__)
/* -------------------------------------------------------------------
* check.c
*/
enum
{
STOP = 0,
CONTINUE = 1
};
extern int p11t_check_verbose;
#define P11T_SECTION(check) \
p11t_msg_prefix(check)
#define _P11T_BEGIN do {
#define _P11T_END } while(0)
#define P11T_CHECK_FAIL(what) \
_P11T_BEGIN p11t_check_fail("%s", (what)); return STOP; _P11T_END
int p11t_check_fail(const char *message, ...);
int p11t_check_warn(const char *message, ...);
int p11t_check_info(const char *message, ...);
#define P11T_CHECK_RV(what, have, want) \
_P11T_BEGIN if(!_p11t_check_rv((what), (have), (want))) return STOP; _P11T_END
int _p11t_check_rv(const char *what, CK_RV have, CK_RV want);
#define P11T_CHECK_PADDED(what, padded) \
_P11T_BEGIN if(!_p11t_check_padded((what), (padded), sizeof(padded))) return STOP; _P11T_END
int _p11t_check_padded(const char *what, const CK_UTF8CHAR_PTR padded, CK_ULONG length);
#define P11T_CHECK_ULONG(what, have, want) \
_P11T_BEGIN if(!_p11t_check_ulong((what), (have), (want))) return STOP; _P11T_END
int _p11t_check_ulong(const char *what, CK_ULONG have, CK_ULONG want);
#define P11T_CHECK_MASK(what, have, want) \
_P11T_BEGIN if(!_p11t_check_mask((what), (have), (want))) return STOP; _P11T_END
int _p11t_check_mask(const char *what, CK_ULONG flags, CK_ULONG mask);
#define P11T_CHECK_FLAG(what, have, want) \
_P11T_BEGIN if(!_p11t_check_flag((what), (have), (want))) return STOP; _P11T_END
int _p11t_check_flag(const char *what, CK_ULONG flags, CK_ULONG flag);
#define P11T_CHECK_NFLAG(what, have, want) \
_P11T_BEGIN if(!_p11t_check_nflag((what), (have), (want))) return STOP; _P11T_END
int _p11t_check_nflag(const char *what, CK_ULONG flags, CK_ULONG nflag);
#define P11T_CHECK_BOOL(what, value) \
_P11T_BEGIN if(!_p11t_check_bool((what), (value))) return STOP; _P11T_END
int _p11t_check_bool(const char *what, CK_BBOOL value);
#define P11T_CHECK_STRING(what, value, length) \
_P11T_BEGIN if(!_p11t_check_string((what), (value), (length))) return STOP; _P11T_END
int _p11t_check_string(const char *what, CK_UTF8CHAR_PTR value, CK_ULONG length);
#define P11T_CHECK_NOTE(what)
/* -------------------------------------------------------------------
* config.c
*/
void p11t_config_parse(const char* filename);
void p11t_config_cleanup(void);
/* -------------------------------------------------------------------
* key.c
*/
CK_OBJECT_HANDLE p11t_key_get_public(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
CK_OBJECT_HANDLE p11t_key_get_private(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
RSA* p11t_key_export_public_rsa(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key);
/* -------------------------------------------------------------------
* module.c
*/
extern CK_FUNCTION_LIST_PTR p11t_module_funcs;
void p11t_module_config(const char *name, const char *value);
int p11t_module_load(const char *filename);
int p11t_module_unload(void);
int p11t_module_initialize(void);
int p11t_module_finalize(void);
/* -------------------------------------------------------------------
* object.c
*/
CK_OBJECT_HANDLE_PTR p11t_object_find(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attrs,
CK_ULONG n_attrs, CK_ULONG_PTR n_objects);
int p11t_object_get(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object,
CK_ATTRIBUTE_PTR attrs, CK_ULONG count);
CK_OBJECT_HANDLE p11t_object_find_one(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attrs,
CK_ULONG n_attrs);
void p11t_object_tests(void);
/* -------------------------------------------------------------------
* rsa.c
*/
void p11t_rsa_tests(void);
/* -------------------------------------------------------------------
* session.c
*/
CK_SESSION_HANDLE p11t_session_open(CK_SLOT_ID slot, int readwrite);
int p11t_session_login(CK_SESSION_HANDLE handle);
int p11t_session_logout(CK_SESSION_HANDLE handle);
int p11t_session_close(CK_SESSION_HANDLE handle);
int p11t_session_close_all(CK_SLOT_ID slot);
void p11t_session_config(const char *name, const char *value);
void p11t_session_tests(void);
/* -------------------------------------------------------------------
* slot.c
*/
extern CK_ULONG p11t_slot_count;
void p11t_slot_tests(void);
CK_SLOT_ID p11t_slot_get_id(int index);
CK_SLOT_INFO_PTR p11t_slot_get_info(CK_SLOT_ID slot);
CK_TOKEN_INFO_PTR p11t_slot_get_token_info(CK_SLOT_ID slot);
typedef void (*P11tSlotMechCallback)(CK_SLOT_ID slot, CK_MECHANISM_TYPE mech_type,
CK_MECHANISM_INFO_PTR mech_info);
void p11t_slot_for_each_mech(CK_MECHANISM_TYPE mech_type, P11tSlotMechCallback callback);
/* ------------------------------------------------------------------
* test-data.c
*/
#define P11T_BLOCK 1024
extern const CK_BYTE p11t_test_data[];
extern const CK_ULONG p11t_test_data_size;
extern const CK_ULONG p11t_test_data_bits;
#endif /* P11TESTST_H_ */
|