pcscmonitor.h
1 /* 2 * Copyright (c) 2004-2008,2014 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 // 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 <security_utilities/pcsc++.h> 36 #include <security_utilities/coderepository.h> 37 #include <set> 38 39 40 // 41 // A PCSCMonitor uses PCSC to monitor the state of smartcard readers and 42 // tokens (cards) in the system, and dispatches messages and events to the 43 // various related players in securityd. There should be at most one of these 44 // objects active within securityd. 45 // 46 class PCSCMonitor : private Listener, private MachServer::Timer { 47 public: 48 enum ServiceLevel { 49 forcedOff, // no service under any circumstances 50 externalDaemon // use externally launched daemon if present (do not manage pcscd) 51 }; 52 53 PCSCMonitor(Server &server, const char* pathToCache, ServiceLevel level = externalDaemon); 54 55 protected: 56 Server &server; 57 TokenCache& tokenCache(); 58 59 protected: 60 // Listener 61 void notifyMe(Notification *message); 62 63 // MachServer::Timer 64 void action(); 65 66 void clearReaders(Reader::Type type); 67 68 public: //@@@@ 69 void startSoftTokens(); 70 void loadSoftToken(Bundle *tokendBundle); 71 72 private: 73 ServiceLevel mServiceLevel; // level of service requested/determined 74 75 std::string mCachePath; // path to cache directory 76 TokenCache *mTokenCache; // cache object (lazy) 77 78 typedef map<string, RefPointer<Reader> > ReaderMap; 79 typedef set<RefPointer<Reader> > ReaderSet; 80 ReaderMap mReaders; // presently known PCSC Readers (aka slots) 81 82 class Watcher : public Thread { 83 public: 84 Watcher(Server &server, TokenCache &tokenCache, ReaderMap& readers); 85 86 protected: 87 void threadAction(); 88 89 private: 90 Server &mServer; 91 TokenCache &mTokenCache; 92 PCSC::Session mSession; // PCSC client session 93 ReaderMap& mReaders; 94 }; 95 }; 96 97 98 #endif //_H_PCSCMONITOR