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