]> git.saurik.com Git - apple/securityd.git/blob - src/tokend.h
securityd-27887.tar.gz
[apple/securityd.git] / src / tokend.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 // tokend - internal tracker for a tokend smartcard driver process
27 //
28 #ifndef _H_TOKEND
29 #define _H_TOKEND
30
31 #include "structure.h"
32 #include "child.h"
33 #include "tokencache.h"
34 #include <security_utilities/pcsc++.h>
35 #include <security_utilities/osxcode.h>
36 #include <security_tokend_client/tdclient.h>
37
38
39 //
40 // A Mix-in for classes that can receive (progated) fault nofications
41 //
42 class FaultRelay {
43 public:
44 virtual void relayFault(bool async) = 0;
45 };
46
47
48 //
49 // A TokenDaemon object is the ServerChild object representing the real
50 // tokend process driving a token. It provides the only (official) communications
51 // and control point between securityd and that tokend.
52 //
53 // TokenDaemon is sufficiently aware to track changes in its tokend, particularly
54 // any sudden, violent, agonizing death it may have suffered.
55 // If TokenDaemon communications with its tokend break down for any rason, it declares
56 // a FAULT condition and cuts off any further attempts at communication. There is no way
57 // to recover from a FAULT condition. (You can create a new TokenDaemon and try again,
58 // of course.) Fault is propagated to the owner object through a simple callback scheme.
59 //
60 // If TokenDaemon is destroyed while its process is still alive, it will (try to) kill
61 // it right there and then. That's good enough for hard error recovery, though you may
62 // try to let it down easier to allow it to save its caches and wind down. Caller's choice.
63 //
64 // NB: If you ever want to make TokenDaemon BE a GenericBundle, you must switch NodeCore
65 // AND OSXCode to virtually derive RefCount.
66 //
67 class TokenDaemon : public PerGlobal, public ServerChild, public Tokend::ClientSession {
68 public:
69 TokenDaemon(RefPointer<GenericBundle> code,
70 const std::string &reader, const PCSC::ReaderState &state, TokenCache &cache);
71 virtual ~TokenDaemon();
72
73 bool faulted() const { return mFaulted; }
74 void fault(bool async, const char *reason);
75
76 void faultRelay(FaultRelay *rcv) { mFaultRelay = rcv; }
77
78 string bundlePath() const { return mMe->canonicalPath(); }
79 string bundleIdentifier() const { return mMe->identifier(); }
80 uint32 maxScore() const;
81
82 Score score() const { return mScore; }
83 bool hasTokenUid() const { return !mTokenUid.empty(); }
84 std::string tokenUid() const;
85
86 uid_t uid() const { return mUid; }
87 gid_t gid() const { return mGid; }
88
89 // startup phase calls
90 using ClientSession::probe;
91 bool probe();
92
93 IFDUMP(void dumpNode());
94
95 protected:
96 void childAction();
97 void dying();
98
99 void fault(); // relay from Tokend::ClientSession
100
101 private:
102 RefPointer<GenericBundle> mMe; // code object for the tokend (it's an Application)
103 std::string mReaderName; // PCSC name of reader we're working with
104 PCSC::ReaderState mState; // card state at time of creation (not updated after that)
105
106 // fault processing
107 FaultRelay *mFaultRelay; // forward initial fault declarations to this object
108 bool mFaulted; // fault condition
109
110 // returned by tokend scoring system
111 bool mProbed; // probe() has succeeded; mScore/mTokenUid valid
112 Score mScore; // token support score as returned by probe()
113 std::string mTokenUid; // tokenUid as returned by probe(), may be empty
114
115 // credentials of underlying process
116 uid_t mUid; // uid of tokend process
117 gid_t mGid; // gid of tokend process
118 };
119
120
121 #endif //_H_TOKEND