summaryrefslogtreecommitdiff
path: root/src/p11-tests.h
blob: 9be69da12c37c1fa92bd8988a34cb53a789d1ddf (plain)
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
#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_print(const char *message, ...);
void p11t_msg_fatal(const char *message, ...);
void p11t_msg_exit(int code, const char *message, ...);
void p11t_msg_prefix(const char *prefix);

#define p11t_msg_here() \
	(__func__ "() at " __FILE__ ":"  __LINE__)

/* -------------------------------------------------------------------
 * check.c
 */

int p11t_check_fail(const char *message, ...);

int p11t_check_returns(const char *message, CK_RV have, CK_RV want);

#define p11t_check_padded(msg, padded) \
	(p11t_check_padded_len((msg), (padded), sizeof(padded)))

int p11t_check_padded_len(const char *message, const CK_UTF8CHAR_PTR padded, CK_ULONG length);

int p11t_check_ulong(const char *message, CK_ULONG have, CK_ULONG want);

int p11t_check_mask(const char *message, CK_ULONG flags, CK_ULONG mask);

int p11t_check_flag(const char *message, CK_ULONG flags, CK_ULONG flag);

int p11t_check_nflag(const char *message, CK_ULONG flags, CK_ULONG nflag);

int p11t_check_bool(const char *message, CK_BBOOL value);

int p11t_check_string(const char *message, CK_UTF8CHAR_PTR value, CK_ULONG length);

/* -------------------------------------------------------------------
 * 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);

void p11t_module_load(const char *filename);
void p11t_module_unload(void);

void p11t_module_initialize(void);
void 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_ */