Debian Codegraph @

src/lib/object_store/DBToken.h

raw
1 /*
2 * Copyright (c) 2013 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 DBToken.h
29
30 The token class; a token is stored in a directory containing a single
31 database file.
32 Each object is stored in multiple tables with every attribute base type
33 stored in a different table.
34 *****************************************************************************/
35
36 #ifndef _SOFTHSM_V2_DBTOKEN_H
37 #define _SOFTHSM_V2_DBTOKEN_H
38
39 #include "config.h"
40 #include "ByteString.h"
41 #include "MutexFactory.h"
42 #include "OSAttribute.h"
43 #include "cryptoki.h"
44 #include "OSObject.h"
45 #include "ObjectStoreToken.h"
46
47 #include <string>
48 #include <set>
49
50 namespace DB { class Connection; }
51
52 class DBToken : public ObjectStoreToken
53 {
54 public:
55 // Constructor to create a new token
56 DBToken(const std::string &baseDir, const std::string &tokenName, const ByteString& label, const ByteString& serial);
57
58 // Constructor to access an existing token
59 DBToken(const std::string &baseDir, const std::string &tokenName);
60
61 // Create a new token
62 static DBToken* createToken(const std::string basePath, const std::string tokenDir, const ByteString& label, const ByteString& serial);
63
64 // Access an existing token
65 static DBToken* accessToken(const std::string &basePath, const std::string &tokenDir);
66
67 // Destructor
68 virtual ~DBToken();
69
70 // Set the SO PIN
71 virtual bool setSOPIN(const ByteString& soPINBlob);
72
73 // Get the SO PIN
74 virtual bool getSOPIN(ByteString& soPINBlob);
75
76 // Set the user PIN
77 virtual bool setUserPIN(ByteString userPINBlob);
78
79 // Get the user PIN
80 virtual bool getUserPIN(ByteString& userPINBlob);
81
82 // Get the token flags
83 virtual bool getTokenFlags(CK_ULONG& flags);
84
85 // Set the token flags
86 virtual bool setTokenFlags(const CK_ULONG flags);
87
88 // Retrieve the token label
89 virtual bool getTokenLabel(ByteString& label);
90
91 // Retrieve the token serial
92 virtual bool getTokenSerial(ByteString& serial);
93
94 // Retrieve objects
95 virtual std::set<OSObject*> getObjects();
96
97 // Insert objects into the given set
98 virtual void getObjects(std::set<OSObject*> &objects);
99
100 // Create a new object
101 virtual OSObject* createObject();
102
103 // Delete an object
104 virtual bool deleteObject(OSObject* object);
105
106 // Checks if the token is consistent
107 virtual bool isValid();
108
109 // Invalidate the token (for instance if it is deleted)
110 virtual void invalidate();
111
112 // Delete the token
113 virtual bool clearToken();
114
115 // Reset the token
116 virtual bool resetToken(const ByteString& label);
117
118 private:
119 DB::Connection *_connection;
120
121 // All the objects ever associated with this token
122 //
123 // This map is kept to be able to clean up when the token
124 // instance is discarded; in case the contents of a token
125 // change, some objects may disappear but we cannot simply
126 // delete them since they may still be referenced from an
127 // object outside of this class.
128 std::map<long long, OSObject*> _allObjects;
129
130 // For thread safeness
131 Mutex* _tokenMutex;
132 };
133
134 #endif // !_SOFTHSM_V2_DBTOKEN_H
135