2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* standard library header */
24 /* SLP library header */
28 #include "ServerResource.h"
29 #include "TerminalInterface.h"
30 #include "APDUHelper.h"
31 #include "SignatureHelper.h"
34 #include "ServerGDBus.h"
35 #include "smartcard-daemon.h"
38 #define EXTERN_API __attribute__((visibility("default")))
43 namespace smartcard_service_api
45 unsigned int IntegerHandle::newHandle = 0;
46 set<unsigned int> IntegerHandle::setHandles;
47 PMutex IntegerHandle::mutexLock;
49 unsigned int IntegerHandle::assignHandle()
53 pair<set<unsigned int>::iterator, bool> result;
58 if (newHandle == (unsigned int)-1)
63 result = setHandles.insert(newHandle);
66 while (!result.second);
69 _DBG("assign handle : newHandle [%d]", newHandle);
74 void IntegerHandle::releaseHandle(unsigned int handle)
76 _DBG("will be released : Handle [%d]", handle);
80 setHandles.erase(handle);
84 #define OMAPI_SE_PATH "/usr/lib/se"
86 ServerResource::ServerResource() : seLoaded(false)
92 ServerResource::~ServerResource()
96 ServerResource &ServerResource::getInstance()
98 static ServerResource serverResource;
100 return serverResource;
103 bool ServerResource::createClient(const char *name, pid_t pid)
107 if (getClient(name) == NULL)
109 ClientInstance *instance = new ClientInstance(name, pid);
110 if (instance != NULL)
112 mapClients.insert(make_pair(name, instance));
117 _ERR("alloc failed");
122 _ERR("client already exist, name [%s]", name);
128 ClientInstance *ServerResource::getClient(const char *name)
130 ClientInstance *result = NULL;
131 map<string, ClientInstance *>::iterator item;
133 if ((item = mapClients.find(name)) != mapClients.end())
135 result = item->second;
141 void ServerResource::removeClient(const char *name)
143 map<string, ClientInstance *>::iterator item;
145 if ((item = mapClients.find(name)) != mapClients.end())
148 mapClients.erase(item);
152 _DBG("client removed already, name [%s]", name);
156 void ServerResource::removeClients()
158 map<string, ClientInstance *>::iterator item;
160 for (item = mapClients.begin(); item != mapClients.end(); item++)
168 int ServerResource::getClientCount() const
170 return (int)mapClients.size();
173 ServiceInstance *ServerResource::createService(const char *name)
175 ServiceInstance *result = NULL;
176 ClientInstance *instance = NULL;
178 if ((instance = getClient(name)) != NULL)
180 if ((result = instance->createService()) == NULL)
182 _ERR("ClientInstance::createService failed [%d]", name);
187 _ERR("client doesn't exist, name [%s]", name);
193 ServiceInstance *ServerResource::getService(const char *name, unsigned int handle)
195 ServiceInstance *result = NULL;
196 ClientInstance *instance = NULL;
198 if ((instance = getClient(name)) != NULL)
200 result = instance->getService(handle);
204 _ERR("client doesn't exist, name [%s]", name);
210 void ServerResource::removeService(const char *name, unsigned int handle)
212 ClientInstance *instance = NULL;
214 if ((instance = getClient(name)) != NULL)
216 instance->removeService(handle);
217 if (instance->getServiceCounts() == 0) {
219 /* remove client instance */
225 _ERR("client doesn't exist, name [%s]", name);
229 void ServerResource::removeServices(const char *name)
231 ClientInstance *instance = NULL;
233 if ((instance = getClient(name)) != NULL)
235 instance->removeServices();
237 /* remove client instance */
242 _ERR("client doesn't exist, name [%s]", name);
246 unsigned int ServerResource::createSession(const char *name, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
248 unsigned int result = -1;
249 Terminal *temp = NULL;
250 ServiceInstance *instance = NULL;
252 if ((instance = getService(name, handle)) != NULL)
254 if ((temp = getTerminalByReaderID(readerID)) != NULL)
256 result = instance->openSession(temp, certHashes, caller);
261 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
267 ServerSession *ServerResource::getSession(const char *name, unsigned int handle, unsigned int sessionID)
269 ServerSession *result = NULL;
270 ServiceInstance *instance = NULL;
272 if ((instance = getService(name, handle)) != NULL)
274 result = instance->getSession(sessionID);
278 _ERR("Session doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, sessionID);
284 bool ServerResource::isValidSessionHandle(const char *name, unsigned int handle, unsigned int session)
286 ServiceInstance *instance = NULL;
288 return (((instance = getService(name, handle)) != NULL) && (instance->isVaildSessionHandle(session)));
291 bool ServerResource::isValidChannelHandle(const char *name, unsigned int handle, unsigned int channel)
293 ServiceInstance *instance = NULL;
295 return (((instance = getService(name, handle)) != NULL) && (instance->isVaildChannelHandle(channel)));
298 unsigned int ServerResource::getChannelCount(const char *name, unsigned int handle, unsigned int sessionID)
300 unsigned int result = -1;
301 ServiceInstance *instance = NULL;
303 if ((instance = getService(name, handle)) != NULL)
305 result = instance->getChannelCountBySession(sessionID);
309 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
315 void ServerResource::removeSession(const char *name, unsigned int handle, unsigned int sessionID)
317 ServiceInstance *instance = NULL;
319 if ((instance = getService(name, handle)) != NULL)
321 instance->closeSession(sessionID);
325 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
329 unsigned int ServerResource::createChannel(const char *name, unsigned int handle, unsigned int sessionID, int channelType, ByteArray aid)
330 throw(ExceptionBase &)
332 unsigned int result = -1;
333 ServiceInstance *service = NULL;
335 if ((service = getService(name, handle)) != NULL)
337 if (service->isVaildSessionHandle(sessionID) == true)
339 ServerSession *session = NULL;
340 Terminal *terminal = NULL;
342 terminal = service->getTerminal(sessionID);
343 session = service->getSession(sessionID);
344 if (terminal != NULL && session != NULL)
346 if (terminal->open() == true) {
347 result = _createChannel(terminal, service, channelType, sessionID, aid);
348 if (result == IntegerHandle::INVALID_HANDLE)
350 _ERR("create channel failed [%d]", sessionID);
355 _ERR("terminal open failed");
356 throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
361 _ERR("session is invalid [%d]", sessionID);
362 throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
367 _ERR("session is invalid [%d]", sessionID);
368 throw ExceptionBase(SCARD_ERROR_ILLEGAL_STATE);
373 _ERR("getService is failed, name [%s], handle [%d]", name, handle);
374 throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
380 Channel *ServerResource::getChannel(const char *name, unsigned int handle, unsigned int channelID)
382 Channel *result = NULL;
383 ServiceInstance *instance = NULL;
385 if ((instance = getService(name, handle)) != NULL)
387 result = instance->getChannel(channelID);
391 _ERR("Channel doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, channelID);
397 void ServerResource::removeChannel(const char *name, unsigned int handle, unsigned int channelID)
399 ServiceInstance *instance = NULL;
401 if ((instance = getService(name, handle)) != NULL)
403 ServerChannel *channel;
404 Terminal *terminal = NULL;
406 channel = instance->getChannel(channelID);
407 if (channel != NULL) {
408 terminal = channel->getTerminal();
411 instance->closeChannel(channelID);
413 if (terminal != NULL) {
419 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
423 Terminal *ServerResource::getTerminal(unsigned int terminalID)
425 Terminal *result = NULL;
426 map<unsigned int, Terminal *>::iterator item;
428 if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
430 result = item->second;
434 _ERR("Terminal doesn't exist [%d]", terminalID);
440 const Terminal *ServerResource::getTerminal(unsigned int terminalID) const
442 const Terminal *result = NULL;
443 map<unsigned int, Terminal *>::const_iterator item;
445 if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
447 result = item->second;
451 _ERR("Terminal doesn't exist [%d]", terminalID);
457 Terminal *ServerResource::getTerminal(const char *name)
459 Terminal *result = NULL;
460 map<unsigned int, Terminal *>::iterator item;
462 for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
464 if (strncmp(name, item->second->getName(), strlen(name)) == 0)
466 result = item->second;
474 Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
476 Terminal *result = NULL;
477 map<unsigned int, unsigned int>::iterator item;
479 if ((item = mapReaders.find(readerID)) != mapReaders.end())
481 result = getTerminal(item->second);
485 _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
491 const Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID) const
493 const Terminal *result = NULL;
494 map<unsigned int, unsigned int>::const_iterator item;
496 if ((item = mapReaders.find(readerID)) != mapReaders.end())
498 result = getTerminal(item->second);
502 _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
508 unsigned int ServerResource::getTerminalID(const char *name) const
510 unsigned int result = IntegerHandle::INVALID_HANDLE;
511 map<unsigned int, Terminal *>::const_iterator item;
513 for (item = mapTerminals.begin();
514 item != mapTerminals.end(); item++)
516 if (strncmp(name, item->second->getName(),
519 result = item->first;
527 bool ServerResource::_isAuthorizedAccess(ServerChannel *channel,
528 const ByteArray &aid, const vector<ByteArray> &hashes)
531 AccessControlList *acList = NULL;
533 /* request open channel sequence */
534 if ((acList = getAccessControlList(channel)) == NULL)
536 /* load access control defined by Global Platform */
537 GPACE *acl = new GPACE();
542 ret = acl->loadACL(channel);
543 if (ret >= SCARD_ERROR_OK)
546 addAccessControlList(channel, acList);
550 _ERR("unknown error, 0x%x", -ret);
556 _ERR("alloc failed");
561 acList->loadACL(channel);
566 result = acList->isAuthorizedAccess(aid, hashes);
572 int ServerResource::_openLogicalChannel(Terminal *terminal)
580 command = APDUHelper::generateAPDU(APDUHelper::COMMAND_OPEN_LOGICAL_CHANNEL, 0, ByteArray::EMPTY);
582 _DBG("command [%d] : %s", command.size(), command.toString().c_str());
584 rv = terminal->transmitSync(command, response);
585 if (rv == 0 && response.size() >= 2)
587 ResponseHelper resp(response);
589 if (resp.getStatus() >= 0)
591 result = resp.getDataField()[0];
595 result = resp.getStatus();
600 _ERR("transmitSync failed, rv [%d], length [%d]", rv, response.size());
606 int ServerResource::_closeLogicalChannel(Terminal *terminal, int channelNum)
608 int result = SCARD_ERROR_UNKNOWN;
614 command = APDUHelper::generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
616 _DBG("command [%d] : %s", command.size(), command.toString().c_str());
618 rv = terminal->transmitSync(command, response);
619 if (rv == 0 && response.size() >= 2)
621 ResponseHelper resp(response);
623 if (resp.getStatus() >= 0)
625 _DBG("channel closed [%d]", channelNum);
626 result = SCARD_ERROR_OK;
630 _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
635 _ERR("select apdu is failed, rv [%d], length [%d]", rv, response.size());
641 unsigned int ServerResource::_createChannel(Terminal *terminal,
642 ServiceInstance *service, int channelType,
643 unsigned int sessionID, const ByteArray &aid)
644 throw(ExceptionBase &)
646 unsigned int result = IntegerHandle::INVALID_HANDLE;
648 ServerChannel *channel = NULL;
650 /* open logical channel */
651 if (channelType == 1)
653 channelNum = _openLogicalChannel(terminal);
656 _DBG("channelNum [%d]", channelNum);
660 _ERR("_openLogicalChannel failed [%d]", channelNum);
661 throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
665 /* create channel instance */
666 result = service->openChannel(sessionID, channelNum, ByteArray::EMPTY);
667 if (result == IntegerHandle::INVALID_HANDLE)
669 _ERR("channel is null.");
671 /* close logical channel */
674 _closeLogicalChannel(terminal, channelNum);
676 throw ExceptionBase(SCARD_ERROR_OUT_OF_MEMORY);
679 channel = service->getChannel(result);
682 _ERR("channel is null.");
684 throw ExceptionBase(SCARD_ERROR_OUT_OF_MEMORY);
688 if (_isAuthorizedAccess(channel, aid,
689 service->getParent()->getCertificationHashes()) == true)
694 if (aid == PKCS15::PKCS15_AID)
696 PKCS15 pkcs15(channel);
698 rv = pkcs15.select();
699 if (rv >= SCARD_ERROR_OK)
701 /* remove privilege mode */
702 channel->unsetPrivilegeMode();
703 channel->setSelectResponse(pkcs15.getSelectResponse());
707 _ERR("select failed, [%x]", -rv);
709 service->closeChannel(result);
710 throw ExceptionBase(SCARD_ERROR_IO_FAILED);
715 FileObject file(channel);
717 rv = file.select(aid);
718 if (rv >= SCARD_ERROR_OK)
720 /* remove privilege mode */
721 channel->unsetPrivilegeMode();
722 channel->setSelectResponse(file.getSelectResponse());
726 _ERR("select failed [%x]", -rv);
728 service->closeChannel(result);
729 throw ExceptionBase(SCARD_ERROR_IO_FAILED);
735 _ERR("unauthorized access");
737 service->closeChannel(result);
738 throw ExceptionBase(SCARD_ERROR_SECURITY_NOT_ALLOWED);
744 void ServerResource::addAccessControlList(Terminal *terminal, AccessControlList *acl)
746 map<Terminal *, AccessControlList *>::iterator item;
748 if ((item = mapACL.find(terminal)) == mapACL.end())
750 mapACL.insert(make_pair(terminal, acl));
758 void ServerResource::addAccessControlList(ServerChannel *channel, AccessControlList *acl)
760 map<Terminal *, AccessControlList *>::iterator item;
762 if ((item = mapACL.find(channel->getTerminal())) == mapACL.end())
764 mapACL.insert(make_pair(channel->getTerminal(), acl));
772 AccessControlList *ServerResource::getAccessControlList(Terminal *terminal)
774 AccessControlList *result = NULL;
775 map<Terminal *, AccessControlList *>::iterator item;
777 if ((item = mapACL.find(terminal)) != mapACL.end())
779 result = item->second;
785 AccessControlList *ServerResource::getAccessControlList(ServerChannel *channel)
787 AccessControlList *result = NULL;
788 map<Terminal *, AccessControlList *>::iterator item;
790 if ((item = mapACL.find(channel->getTerminal())) != mapACL.end())
792 result = item->second;
798 Terminal *ServerResource::createInstance(void *library)
800 Terminal *terminal = NULL;
801 terminal_create_instance_fn createInstance = NULL;
803 /* create se instance */
804 createInstance = (terminal_create_instance_fn)dlsym(library, "create_instance");
805 if (createInstance != NULL)
807 terminal = (Terminal *)createInstance();
808 if (terminal != NULL)
810 _DBG("terminal [%p]", terminal);
814 _ERR("terminal is null");
819 _ERR("create_instance is null [%d]", errno);
825 bool ServerResource::appendSELibrary(char *library)
827 void *libHandle = NULL;
830 libHandle = dlopen(library, RTLD_LAZY);
831 if (libHandle != NULL)
833 Terminal *terminal = NULL;
835 terminal = createInstance(libHandle);
836 if (terminal != NULL)
838 unsigned int handle = IntegerHandle::assignHandle();
840 mapTerminals.insert(make_pair(handle, terminal));
841 libraries.push_back(libHandle);
843 terminal->setStatusCallback(&ServerResource::terminalCallback);
845 _DBG("register success [%s] [%p] [%s] [%p]", library, libHandle, terminal->getName(), terminal);
847 if (terminal->isSecureElementPresence() == true)
849 createReader(handle);
856 _ERR("terminal is null [%s]", library);
863 _ERR("it is not se file [%s] [%d]", library, errno);
869 int ServerResource::loadSecureElements()
873 if (seLoaded == false)
876 struct dirent *entry;
878 if ((dir = opendir(OMAPI_SE_PATH)) != NULL)
880 while ((entry = readdir(dir)) != NULL)
882 if (strncmp(entry->d_name, ".", 1) != 0 &&
883 strncmp(entry->d_name, "..", 2) != 0)
886 /* TODO : need additional name rule :) */
888 /* append each files */
889 snprintf(fullPath, sizeof(fullPath),
890 "%s/%s", OMAPI_SE_PATH, entry->d_name);
892 SECURE_LOGD("se name [%s]", fullPath);
894 result = appendSELibrary(fullPath);
911 void ServerResource::unloadSecureElements()
913 if (seLoaded == true)
916 map<unsigned int, Terminal *>::iterator item;
918 for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
920 item->second->finalize();
922 IntegerHandle::releaseHandle(item->first);
925 mapTerminals.clear();
927 for (i = 0; i < libraries.size(); i++)
929 if (libraries[i] != NULL)
930 dlclose(libraries[i]);
939 bool ServerResource::isValidReaderHandle(unsigned int reader) const
941 return (getTerminalByReaderID(reader) != NULL);
944 void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers) const
946 const Terminal *terminal;
947 map<unsigned int, unsigned int>::const_iterator item;
951 for (item = mapReaders.begin(); item != mapReaders.end(); item++)
953 if (item->second != IntegerHandle::INVALID_HANDLE)
955 terminal = getTerminal(item->second);
956 if (terminal != NULL && terminal->isSecureElementPresence() == true)
958 readers.push_back(make_pair(item->first, terminal->getName()));
964 int ServerResource::getReadersInformation(ByteArray &info) const
967 unsigned char *buffer = NULL;
968 unsigned int length = 0;
969 unsigned int offset = 0;
970 unsigned int nameLen = 0;
972 if (mapReaders.size() > 0)
974 const Terminal *terminal = NULL;
975 map<unsigned int, unsigned int>::const_iterator item;
977 for (item = mapReaders.begin(); item != mapReaders.end(); item++)
979 if (item->second != IntegerHandle::INVALID_HANDLE)
981 terminal = getTerminal(item->second);
982 if (terminal != NULL)
984 if (terminal->isSecureElementPresence())
986 length += sizeof(nameLen) + strlen(terminal->getName()) + sizeof(unsigned int);
993 buffer = new unsigned char[length];
996 memset(buffer, 0, length);
998 for (item = mapReaders.begin(); item != mapReaders.end(); item++)
1000 if (item->second != IntegerHandle::INVALID_HANDLE)
1002 terminal = getTerminal(item->second);
1003 if (terminal != NULL)
1005 if (terminal->isSecureElementPresence())
1007 nameLen = strlen(terminal->getName());
1009 memcpy(buffer + offset, &nameLen, sizeof(nameLen));
1010 offset += sizeof(nameLen);
1012 memcpy(buffer + offset, terminal->getName(), nameLen);
1015 memcpy(buffer + offset, &item->first, sizeof(unsigned int));
1016 offset += sizeof(unsigned int);
1022 info.assign(buffer, length);
1027 _ERR("alloc failed");
1033 _INFO("no secure element");
1039 void ServerResource::terminalCallback(const void *terminal, int event,
1040 int error, void *user_param)
1042 _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
1046 case Terminal::NOTIFY_SE_AVAILABLE :
1048 ServerResource &instance = ServerResource::getInstance();
1049 unsigned int terminalID = IntegerHandle::INVALID_HANDLE;
1051 _INFO("[NOTIFY_SE_AVAILABLE]");
1053 terminalID = instance.getTerminalID((char *)terminal);
1054 if (terminalID != IntegerHandle::INVALID_HANDLE)
1056 unsigned int readerID = instance.createReader(terminalID);
1058 ServerGDBus::getInstance().emitReaderInserted(readerID, (const char *)terminal);
1063 case Terminal::NOTIFY_SE_NOT_AVAILABLE :
1065 ServerResource &instance = ServerResource::getInstance();
1066 unsigned int readerID = IntegerHandle::INVALID_HANDLE;
1068 _INFO("[NOTIFY_SE_NOT_AVAILABLE]");
1070 readerID = instance.getReaderID((char *)terminal);
1072 ServerGDBus::getInstance().emitReaderRemoved(
1073 readerID, (const char *)terminal);
1075 instance.removeReader(readerID);
1080 _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
1085 unsigned int ServerResource::createReader(unsigned int terminalID)
1087 unsigned int result = -1;
1089 result = IntegerHandle::assignHandle();
1091 mapReaders.insert(make_pair(result, terminalID));
1096 unsigned int ServerResource::getReaderID(const char *name) const
1098 unsigned int result = IntegerHandle::INVALID_HANDLE,
1099 terminalID = IntegerHandle::INVALID_HANDLE;
1101 terminalID = getTerminalID(name);
1102 if (terminalID != IntegerHandle::INVALID_HANDLE)
1104 map<unsigned int, unsigned int>::const_iterator item;
1106 for (item = mapReaders.begin();
1107 item != mapReaders.end(); item++)
1109 if (item->second == terminalID)
1111 result = item->first;
1120 void ServerResource::removeReader(unsigned int readerID)
1122 map<unsigned int, unsigned int>::iterator item;
1124 if ((item = mapReaders.find(readerID)) != mapReaders.end())
1126 item->second = IntegerHandle::INVALID_HANDLE;
1130 ServerChannel *ServerResource::createInternalChannel(Terminal *terminal,
1134 ServerChannel *channel = NULL;
1136 /* open logical channel */
1137 if (channelType == 1)
1139 channelNum = _openLogicalChannel(terminal);
1142 _DBG("channelNum [%d]", channelNum);
1146 _ERR("_openLogicalChannel failed [%d]", channelNum);
1147 throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
1151 /* create channel instance */
1152 channel = new ServerChannel(NULL, NULL, channelNum, terminal);
1157 bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal,
1158 const ByteArray &aid, const vector<ByteArray> &hashes)
1160 bool result = false;
1161 ServerChannel *channel;
1163 if (terminal == NULL) {
1167 channel = createInternalChannel(terminal, 1);
1168 if (channel != NULL) {
1169 AccessControlList *acl = getAccessControlList(channel);
1172 /* load access control defined by Global Platform */
1177 ret = acl->loadACL(channel);
1178 if (ret >= SCARD_ERROR_OK) {
1179 addAccessControlList(channel, acl);
1181 _ERR("unknown error, 0x%x", -ret);
1187 _ERR("alloc failed");
1190 acl->updateACL(channel);
1194 result = acl->isAuthorizedNFCAccess(aid, hashes);
1196 _ERR("acl is null");
1201 _ERR("alloc failed");
1207 bool ServerResource::isAuthorizedAccess(Terminal *terminal,
1208 const ByteArray &aid, const vector<ByteArray> &hashes)
1210 bool result = false;
1211 ServerChannel *channel;
1213 if (terminal == NULL) {
1217 channel = createInternalChannel(terminal, 1);
1218 if (channel != NULL) {
1219 AccessControlList *acl = getAccessControlList(channel);
1222 /* load access control defined by Global Platform */
1227 ret = acl->loadACL(channel);
1228 if (ret >= SCARD_ERROR_OK) {
1229 addAccessControlList(channel, acl);
1231 _ERR("unknown error, 0x%x", -ret);
1237 _ERR("alloc failed");
1240 acl->updateACL(channel);
1244 result = acl->isAuthorizedAccess(aid, hashes);
1246 _ERR("acl is null");
1251 _ERR("alloc failed");
1257 void ServerResource::finish()
1259 if (getClientCount() == 0) {
1260 _INFO("no client connected. terminate server");
1262 smartcard_daemon_exit();
1265 } /* namespace smartcard_service_api */