Debian Codegraph @

src/lib/slot_mgr/Token.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 Token.h
29
30 This class represents a single PKCS #11 token
31 *****************************************************************************/
32
33 #ifndef _SOFTHSM_V2_TOKEN_H
34 #define _SOFTHSM_V2_TOKEN_H
35
36 #include "config.h"
37 #include "ByteString.h"
38 #include "ObjectStore.h"
39 #include "ObjectStoreToken.h"
40 #include "SecureDataManager.h"
41 #include "cryptoki.h"
42 #include <string>
43 #include <vector>
44
45 class Token
46 {
47 public:
48 // Constructor
49 Token();
50 Token(ObjectStoreToken *inToken);
51
52 // Destructor
53 virtual ~Token();
54
55 // Create a new token
56 CK_RV createToken(ObjectStore* objectStore, ByteString& soPIN, CK_UTF8CHAR_PTR label);
57
58 // Is the token valid?
59 bool isValid();
60
61 // Is the token initialized?
62 bool isInitialized();
63
64 // Is SO or user logged in?
65 bool isSOLoggedIn();
66 bool isUserLoggedIn();
67
68 // Login
69 CK_RV loginSO(ByteString& pin);
70 CK_RV loginUser(ByteString& pin);
71
72 // Re-authentication
73 CK_RV reAuthenticate(ByteString& pin);
74
75 // Logout any user on this token;
76 void logout();
77
78 // Change PIN
79 CK_RV setSOPIN(ByteString& oldPIN, ByteString& newPIN);
80 CK_RV setUserPIN(ByteString& oldPIN, ByteString& newPIN);
81 CK_RV initUserPIN(ByteString& pin);
82
83 // Retrieve token information for the token
84 CK_RV getTokenInfo(CK_TOKEN_INFO_PTR info);
85
86 // Create object
87 OSObject *createObject();
88
89 // Insert all token objects into the given set.
90 void getObjects(std::set<OSObject *> &objects);
91
92 // Decrypt the supplied data
93 bool decrypt(const ByteString& encrypted, ByteString& plaintext);
94
95 // Encrypt the supplied data
96 bool encrypt(const ByteString& plaintext, ByteString& encrypted);
97
98 private:
99 // Token validity
100 bool valid;
101
102 // A reference to the object store token
103 ObjectStoreToken* token;
104
105 // The secure data manager for this token
106 SecureDataManager* sdm;
107
108 Mutex* tokenMutex;
109 };
110
111 #endif // !_SOFTHSM_V2_TOKEN_H
112