]>
git.saurik.com Git - apple/securityd.git/blob - src/tokend.h
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 // tokend - internal tracker for a tokend smartcard driver process
31 #include "structure.h"
33 #include "tokencache.h"
34 #include <security_utilities/pcsc++.h>
35 #include <security_utilities/osxcode.h>
36 #include <security_tokend_client/tdclient.h>
40 // A Mix-in for classes that can receive (progated) fault nofications
44 virtual void relayFault(bool async
) = 0;
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.
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.
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.
64 // NB: If you ever want to make TokenDaemon BE a GenericBundle, you must switch NodeCore
65 // AND OSXCode to virtually derive RefCount.
67 class TokenDaemon
: public PerGlobal
, public ServerChild
, public Tokend::ClientSession
{
69 TokenDaemon(RefPointer
<GenericBundle
> code
,
70 const std::string
&reader
, const PCSC::ReaderState
&state
, TokenCache
&cache
);
71 virtual ~TokenDaemon();
73 bool faulted() const { return mFaulted
; }
74 void fault(bool async
, const char *reason
);
76 void faultRelay(FaultRelay
*rcv
) { mFaultRelay
= rcv
; }
78 string
bundlePath() const { return mMe
->canonicalPath(); }
79 string
bundleIdentifier() const { return mMe
->identifier(); }
80 uint32
maxScore() const;
82 Score
score() const { return mScore
; }
83 bool hasTokenUid() const { return !mTokenUid
.empty(); }
84 std::string
tokenUid() const;
86 uid_t
uid() const { return mUid
; }
87 gid_t
gid() const { return mGid
; }
89 // startup phase calls
90 using ClientSession::probe
;
93 IFDUMP(void dumpNode());
99 void fault(); // relay from Tokend::ClientSession
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)
107 FaultRelay
*mFaultRelay
; // forward initial fault declarations to this object
108 bool mFaulted
; // fault condition
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
115 // credentials of underlying process
116 uid_t mUid
; // uid of tokend process
117 gid_t mGid
; // gid of tokend process