Debian Codegraph @

src/lib/object_store/SessionObject.h

raw
1 /*
2 * Copyright (c) 2010 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 SessionObject.h
29
30 This class implements session objects (i.e. objects that are non-persistent)
31 *****************************************************************************/
32
33 #ifndef _SOFTHSM_V2_SESSIONOBJECT_H
34 #define _SOFTHSM_V2_SESSIONOBJECT_H
35
36 #include "config.h"
37 #include "ByteString.h"
38 #include "OSAttribute.h"
39 #include "MutexFactory.h"
40 #include <string>
41 #include <map>
42 #include "cryptoki.h"
43 #include "OSObject.h"
44
45 // Forward declaration of the session object store
46 class SessionObjectStore;
47
48 class SessionObject : public OSObject
49 {
50 public:
51 // Constructor
52 SessionObject(SessionObjectStore* inParent, CK_SLOT_ID inSlotID, CK_SESSION_HANDLE inHSession, bool inIsPrivate = false);
53
54 // Destructor
55 virtual ~SessionObject();
56
57 // Check if the specified attribute exists
58 virtual bool attributeExists(CK_ATTRIBUTE_TYPE type);
59
60 // Retrieve the specified attribute
61 virtual OSAttribute getAttribute(CK_ATTRIBUTE_TYPE type);
62 virtual bool getBooleanValue(CK_ATTRIBUTE_TYPE type, bool val);
63 virtual unsigned long getUnsignedLongValue(CK_ATTRIBUTE_TYPE type, unsigned long val);
64 virtual ByteString getByteStringValue(CK_ATTRIBUTE_TYPE type);
65
66 // Retrieve the next attribute type
67 virtual CK_ATTRIBUTE_TYPE nextAttributeType(CK_ATTRIBUTE_TYPE type);
68
69 // Set the specified attribute
70 virtual bool setAttribute(CK_ATTRIBUTE_TYPE type, const OSAttribute& attribute);
71
72 // Delete the specified attribute
73 virtual bool deleteAttribute(CK_ATTRIBUTE_TYPE type);
74
75 // The validity state of the object
76 virtual bool isValid();
77
78 bool hasSlotID(CK_SLOT_ID inSlotID);
79
80 // Called by the session object store when a session is closed. If it's the
81 // session this object was associated with, the function returns true and the
82 // object is invalidated
83 bool removeOnSessionClose(CK_SESSION_HANDLE inHSession);
84
85 // Called by the session object store when all the sessions for a token
86 // have been closed.
87 bool removeOnAllSessionsClose(CK_SLOT_ID inSlotID);
88
89 // Called by the session object store when a token is logged out.
90 // Remove when this session object is a private object for this token.
91 bool removeOnTokenLogout(CK_SLOT_ID inSlotID);
92
93 // These functions are just stubs for session objects
94 virtual bool startTransaction(Access access);
95 virtual bool commitTransaction();
96 virtual bool abortTransaction();
97
98 // Destroys the object; WARNING: pointers to the object become invalid after this
99 // call!
100 virtual bool destroyObject();
101
102 // Invalidate the object
103 void invalidate();
104
105 private:
106 // Discard the object's attributes
107 void discardAttributes();
108
109 // The object's raw attributes
110 std::map<CK_ATTRIBUTE_TYPE, OSAttribute*> attributes;
111
112 // The object's validity state
113 bool valid;
114
115 // Mutex object for thread-safeness
116 Mutex* objectMutex;
117
118 // The slotID of the object is associated with.
119 CK_SLOT_ID slotID;
120
121 // The session the object is associated with.
122 CK_SESSION_HANDLE hSession;
123
124 // Indicates whether this object is private
125 bool isPrivate;
126
127 // The parent SessionObjectStore
128 SessionObjectStore* parent;
129 };
130
131 #endif // !_SOFTHSM_V2_SESSIONOBJECT_H
132