]> git.saurik.com Git - apple/securityd.git/blob - src/token.h
securityd-26674.tar.gz
[apple/securityd.git] / src / token.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // token - internal representation of a (single distinct) hardware token
27 //
28 #ifndef _H_TOKEN
29 #define _H_TOKEN
30
31 #include "structure.h"
32 #include "tokencache.h"
33 #include "tokenacl.h"
34 #include "tokend.h"
35 #include <security_utilities/pcsc++.h>
36 #include <securityd_client/ssnotify.h>
37
38 class Reader;
39 class TokenDbCommon;
40
41
42 //
43 // Token is the global-scope object representing a smartcard token.
44 // It also acts as the global-scope database object for the TokenDatabase representing
45 // its content, and carries the ObjectAcls for objects on the token.
46 //
47 class Token : public PerGlobal, public virtual TokenAcl, public FaultRelay {
48 public:
49 class Access; friend class Access;
50
51 public:
52 Token();
53 ~Token();
54
55 ::Reader &reader() const;
56 TokenDaemon &tokend();
57 GenericHandle tokenHandle() const;
58 uint32 subservice() const { return mSubservice; }
59 std::string printName() const { return mPrintName; }
60 TokenCache::Token &cache() const { return *mCache; }
61
62 void insert(::Reader &slot);
63 void remove();
64
65 void notify(NotificationEvent event);
66 void fault(bool async);
67
68 void kill();
69
70 IFDUMP(void dumpNode());
71
72 static RefPointer<Token> find(uint32 ssid);
73
74 ResetGeneration resetGeneration() const;
75 bool resetGeneration(ResetGeneration rg) const { return rg == resetGeneration(); }
76 void resetAcls();
77
78 public:
79 // SecurityServerAcl and TokenAcl personalities
80 AclKind aclKind() const;
81 Token &token(); // myself
82
83 // FaultRelay personality
84 void relayFault(bool async);
85
86 public:
87 class Access {
88 public:
89 Access(Token &token);
90 ~Access();
91
92 Token &token;
93
94 TokenDaemon &tokend() const { return *mTokend; }
95 TokenDaemon &operator () () const { return tokend(); }
96
97 private:
98 RefPointer<TokenDaemon> mTokend;
99 };
100
101 public:
102 // keep track of TokenDbCommons for reset processing
103 // (this interface is for TokenDbCommon only)
104 void addCommon(TokenDbCommon &dbc);
105 void removeCommon(TokenDbCommon &dbc);
106
107 private:
108 RefPointer<TokenDaemon> chooseTokend();
109
110 private:
111 bool mFaulted; // fault state flag
112 RefPointer<TokenDaemon> mTokend; // the (one) tokend that runs the card
113 RefPointer<TokenCache::Token> mCache; // token cache reference
114 std::string mPrintName; // print name of token
115
116 Guid mGuid; // our CSP/DL's Guid
117 uint32 mSubservice; // dynamic subservice of gGuidAppleSdCSPDL
118 PCSC::ReaderState mState; // reader state as of insertion
119
120 TokenDaemon::Score mScore; // score of winning tokend
121
122 private:
123 typedef map<uint32, Token *> SSIDMap;
124 static SSIDMap mSubservices;
125 static Mutex mSSIDLock;
126
127 typedef set<TokenDbCommon *> CommonSet;
128 CommonSet mCommons;
129 ResetGeneration mResetLevel;
130 };
131
132
133 #endif //_H_TOKEN