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
|
/*
* Copyright (C) 2007 Stef Walter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef CKCAPI_SESSION_H
#define CKCAPI_SESSION_H
#include "ckcapi.h"
/* Callback to cleanup a current operation */
typedef void (*CkCapiSessionCancel) (struct _CkCapiSession* sess);
/* Represents an open session */
typedef struct _CkCapiSession
{
CK_SESSION_HANDLE id; /* Unique ID for this session */
CK_SLOT_ID slot;
int in_call; /* Whether this session is use in PKCS#11 function */
HCERTSTORE store; /* Handle to an open certificate store */
BOOL read_write; /* A read-write session? */
int operation_type; /* Whether an operation is happening or not */
void* operation_data; /* Data for this operation */
CkCapiSessionCancel operation_cancel; /* Callback to cancel operation when necessary */
CkCapiHash* object_data;
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 */
}
CkCapiSession;
/* Debug print something related to a session */
#define DBGS(sess, msg) \
ckcapi_debug("S%d: %s", (sess) ? (sess)->id : 0, (msg))
/* Create a session */
CK_RV ckcapi_session_create (CK_SLOT_ID slot, CkCapiSession** ret);
/* Destroy a session */
void ckcapi_session_destroy (CkCapiSession* sess);
/* Register a new session */
CK_RV ckcapi_session_register (CkCapiSession* sess);
/* Get information about a session */
void ckcapi_session_get_info (CkCapiSession* sess,
CK_SESSION_INFO_PTR info);
/* Get a session from a handle, and lock it */
CK_RV ckcapi_session_get_lock_ref (CK_ULONG id, BOOL writable,
CkCapiSession **sess);
/* Get a session from a handle, remove it from list, and lock it */
CK_RV ckcapi_session_remove_lock_ref (CK_ULONG id, CkCapiSession **sess);
/* Unlock and unreference a session */
void ckcapi_session_unref_unlock (CkCapiSession* sess);
/* Close all sessions on a certain slot/token */
CK_RV ckcapi_session_close_all (CK_SLOT_ID slot);
/* Start a find operation on a session */
CK_RV ckcapi_session_find_init (CkCapiSession* sess,
CK_ATTRIBUTE_PTR templ,
CK_ULONG count);
/* Return results from a find operation */
CK_RV ckcapi_session_find (CkCapiSession* sess,
CK_OBJECT_HANDLE_PTR objects,
CK_ULONG max_object_count,
CK_ULONG_PTR object_count);
/* End a find operation */
CK_RV ckcapi_session_find_final (CkCapiSession* sess);
/* Start a sign operation on a session */
CK_RV ckcapi_session_sign_init (CkCapiSession* sess,
CK_MECHANISM_PTR mech,
CkCapiObjectData *objdata);
/* Perform sign operation */
CK_RV ckcapi_session_sign (CkCapiSession* sess,
CK_BYTE_PTR data, CK_ULONG n_data,
CK_BYTE_PTR sig, CK_ULONG_PTR n_sig);
/* Start a decrypt operation on a session */
CK_RV ckcapi_session_decrypt_init (CkCapiSession* sess,
CK_MECHANISM_PTR mech,
CkCapiObjectData *objdata);
/* Perform decrypt operation */
CK_RV ckcapi_session_decrypt (CkCapiSession* sess,
CK_BYTE_PTR encdata, CK_ULONG n_encdata,
CK_BYTE_PTR result, CK_ULONG_PTR n_result);
/* Get object data for an object */
CK_RV ckcapi_session_get_object_data (CkCapiSession* sess,
CkCapiObject* obj,
CkCapiObjectData** objdata);
/* Get object data for an object handle */
CK_RV ckcapi_session_get_object_data_for (CkCapiSession* sess,
CK_OBJECT_HANDLE hand,
CkCapiObjectData** objdata);
/* Set object data for an object */
void ckcapi_session_take_object_data (CkCapiSession* sess,
CkCapiObject* obj,
CkCapiObjectData* objdata);
/* Clear object data for an object */
void ckcapi_session_clear_object_data (CkCapiSession* sess,
CkCapiObject* obj);
/* Enumerate object data for all objects */
typedef void (*CkCapiEnumObjectData) (CkCapiSession* sess,
CkCapiObject* obj,
CkCapiObjectData* data,
void* arg);
void ckcapi_session_enum_object_data (CkCapiSession* sess,
CkCapiEnumObjectData enum_func,
void* arg);
void ckcapi_session_cleanup_all (void);
#endif /* CKCAPI_SESSION_H */
|