]> git.saurik.com Git - apple/security.git/blob - securityd/src/token.h
Security-57031.1.35.tar.gz
[apple/security.git] / securityd / src / token.h
1 /*
2 * Copyright (c) 2004,2007-2008 Apple 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, RefPointer<TokenDaemon> tokend);
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 void getAcl(const char *tag, uint32 &count, AclEntryInfo *&acls);
75 ResetGeneration resetGeneration() const;
76 bool resetGeneration(ResetGeneration rg) const { return rg == resetGeneration(); }
77 void resetAcls();
78
79 public:
80 // SecurityServerAcl and TokenAcl personalities
81 AclKind aclKind() const;
82 Token &token(); // myself
83
84 // FaultRelay personality
85 void relayFault(bool async);
86
87 public:
88 class Access {
89 public:
90 Access(Token &token);
91 ~Access();
92
93 Token &token;
94
95 TokenDaemon &tokend() const { return *mTokend; }
96 TokenDaemon &operator () () const { return tokend(); }
97
98 private:
99 RefPointer<TokenDaemon> mTokend;
100 };
101
102 public:
103 // keep track of TokenDbCommons for reset processing
104 // (this interface is for TokenDbCommon only)
105 void addCommon(TokenDbCommon &dbc);
106 void removeCommon(TokenDbCommon &dbc);
107
108 private:
109 RefPointer<TokenDaemon> chooseTokend();
110
111 private:
112 bool mFaulted; // fault state flag
113 RefPointer<TokenDaemon> mTokend; // the (one) tokend that runs the card
114 RefPointer<TokenCache::Token> mCache; // token cache reference
115 std::string mPrintName; // print name of token
116
117 Guid mGuid; // our CSP/DL's Guid
118 uint32 mSubservice; // dynamic subservice of gGuidAppleSdCSPDL
119 PCSC::ReaderState mState; // reader state as of insertion
120
121 TokenDaemon::Score mScore; // score of winning tokend
122
123 private:
124 typedef map<uint32, Token *> SSIDMap;
125 static SSIDMap mSubservices;
126 static Mutex mSSIDLock;
127
128 typedef set<TokenDbCommon *> CommonSet;
129 CommonSet mCommons;
130 ResetGeneration mResetLevel;
131 };
132
133
134 #endif //_H_TOKEN