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
|
#ifndef CRYPTOKI_CAPI_H
#define CRYPTOKI_CAPI_H
#ifndef ASSERT
#include "assert.h"
#define ASSERT assert
#endif
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x400
#include <windows.h>
#define CRYPTOKI_EXPORTS
#include "pkcs11/cryptoki.h"
#include "cryptoki-capi-util.h"
struct _Object;
struct _Session;
/* ------------------------------------------------------------------
* cryptoki-capi.c
*/
#define DBG(args) \
ckcapi_debug args
void ckcapi_debug(const char* msg, ...);
void ckcapi_lock_global(void);
void ckcapi_unlock_global(void);
CK_RV ckcapi_winerr_to_ckr (DWORD werr);
/* ------------------------------------------------------------------
* cryptoki-capi-session.c
*/
/* For operation_type in Session */
enum
{
OPERATION_NONE = 0,
OPERATION_FIND = 1,
};
typedef void (*SessionCancel) (struct _Session* sess);
typedef struct _Session
{
CK_ULONG id; /* Unique ID for this session */
int in_call; /* Whether this session is use in PKCS#11 function */
int operation_type; /* Whether an operation is happening or not */
void* operation_data; /* Data for this operation */
SessionCancel operation_cancel; /* Callback to cancel operation when necessary */
CK_NOTIFY notify_callback; /* Application specified callback */
CK_VOID_PTR user_data; /* Argument for above */
int refs; /* Reference count */
HANDLE mutex; /* Mutex for protecting this structure */
}
Session;
#define DBGS(sess, msg) \
ckcapi_debug("S%d: %s", (sess) ? (sess)->id : 0, (msg))
Session* ckcapi_session_create(void);
void ckcapi_session_destroy(Session* sess);
CK_RV ckcapi_session_register(Session* sess);
CK_RV ckcapi_session_find_lock_ref(CK_ULONG id, int remove, Session **sess);
void ckcapi_session_unref_unlock(Session* sess);
void ckcapi_session_close_all();
/* ------------------------------------------------------------------
* cryptoki-capi-object.c
*/
typedef struct _Object
{
CK_ULONG id; /* Unique ID for this object */
CK_ATTRIBUTE_PTR attrs; /* All the attributes of this object */
CK_ULONG n_attrs; /* Number of attributes */
}
Object;
/*
Object* ckcapi_object_create(Session* sess, CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs);
void ckcapi_object_destroy(Session* sess, Object* obj);
*/
CK_RV ckcapi_object_find_init (Session* sess, CK_ATTRIBUTE_PTR templ, CK_ULONG count);
CK_RV ckcapi_object_find (Session* sess, CK_OBJECT_HANDLE_PTR objects,
CK_ULONG max_object_count, CK_ULONG_PTR object_count);
CK_RV ckcapi_objects_find_final (Session* sess);
#endif /* CRYPTOKI_CAPI_H */
|