]> git.saurik.com Git - apple/securityd.git/blob - src/pcscmonitor.h
securityd-30544.tar.gz
[apple/securityd.git] / src / pcscmonitor.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 // pcscmonitor - use PCSC to monitor smartcard reader/card state for securityd
27 //
28 #ifndef _H_PCSCMONITOR
29 #define _H_PCSCMONITOR
30
31 #include "server.h"
32 #include "tokencache.h"
33 #include "reader.h"
34 #include "token.h"
35 #include "notifications.h"
36 #include <security_utilities/unixchild.h>
37 #include <security_utilities/powerwatch.h>
38 #include <security_utilities/pcsc++.h>
39 #include <security_utilities/iodevices.h>
40 #include <set>
41
42
43 //
44 // A PCSCMonitor uses PCSC to monitor the state of smartcard readers and
45 // tokens (cards) in the system, and dispatches messages and events to the
46 // various related players in securityd. There should be at most one of these
47 // objects active within securityd.
48 //
49 class PCSCMonitor : private Listener,
50 private MachServer::Timer,
51 private IOKit::NotificationPort::Receiver,
52 private MachPlusPlus::PowerWatcher,
53 private UnixPlusPlus::Child,
54 private Mutex {
55 public:
56 enum ServiceLevel {
57 forcedOff, // no service under any circumstances
58 conservative, // launch pcscd for certain smartcard devices
59 aggressive, // launch pcscd for possible (and certain) smartcard devices
60 forcedOn, // keep pcscd running at all times
61 externalDaemon // use externally launched daemon if present (do not manage pcscd)
62 };
63
64 PCSCMonitor(Server &server, const char* pathToCache, ServiceLevel level = conservative);
65
66 protected:
67 void pollReaders();
68
69 Server &server;
70 TokenCache *cache;
71 std::string cachePath;
72 TokenCache& getTokenCache ();
73
74 protected:
75 // Listener
76 void notifyMe(SecurityServer::NotificationDomain domain,
77 SecurityServer::NotificationEvent event, const CssmData &data);
78
79 // MachServer::Timer
80 void action();
81
82 // NotificationPort::Receiver
83 void ioChange(IOKit::DeviceIterator &iterator);
84
85 // PowerWatcher
86 void systemWillSleep();
87 void systemIsWaking();
88
89 // Unix++/Child
90 void childAction();
91 void dying();
92
93 protected:
94 void launchPcscd();
95 void scheduleTimer(bool enable);
96 void initialSetup();
97 void noDeviceTimeout();
98
99 enum DeviceSupport {
100 impossible, // certain this is not a smartcard
101 definite, // definitely a smartcard device
102 possible // perhaps... we're not sure
103 };
104 DeviceSupport deviceSupport(const IOKit::Device &dev);
105
106 private:
107 ServiceLevel mServiceLevel; // level of service requested/determined
108 void (PCSCMonitor::*mTimerAction)(); // what to do when our timer fires
109 bool mGoingToSleep; // between sleep and wakeup; special timer handling
110
111 PCSC::Session mSession; // PCSC client session
112 IOKit::MachPortNotificationPort mIOKitNotifier; // IOKit connection
113
114 typedef map<string, RefPointer<Reader> > ReaderMap;
115 typedef set<RefPointer<Reader> > ReaderSet;
116 ReaderMap mReaders; // presently known PCSC Readers (aka slots)
117 };
118
119
120 #endif //_H_PCSCMONITOR