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);
65 while (!result.second);
68 _DBG("assign handle : newHandle [%d]", newHandle);
73 void IntegerHandle::releaseHandle(unsigned int handle)
75 _DBG("will be released : Handle [%d]", handle);
79 setHandles.erase(handle);
83 #define OMAPI_SE_PATH "/usr/lib/se"
85 ServerResource::ServerResource() : seLoaded(false)
91 ServerResource::~ServerResource()
95 ServerResource &ServerResource::getInstance()
97 static ServerResource serverResource;
99 return serverResource;
102 bool ServerResource::createClient(const char *name, pid_t pid)
106 if (getClient(name) == NULL) {
107 ClientInstance *instance = new ClientInstance(name, pid);
108 if (instance != NULL) {
109 mapClients.insert(make_pair(name, instance));
112 _ERR("alloc failed"); //LCOV_EXCL_LINE
115 _ERR("client already exist, name [%s]", name); //LCOV_EXCL_LINE
121 ClientInstance *ServerResource::getClient(const char *name)
123 ClientInstance *result = NULL;
124 map<string, ClientInstance *>::iterator item;
126 if ((item = mapClients.find(name)) != mapClients.end())
128 result = item->second;
134 void ServerResource::removeClient(const char *name)
136 map<string, ClientInstance *>::iterator item;
138 if ((item = mapClients.find(name)) != mapClients.end()) {
140 mapClients.erase(item);
142 _DBG("client removed already, name [%s]", name); //LCOV_EXCL_LINE
146 /* LCOV_EXCL_START */
147 void ServerResource::removeClients()
149 map<string, ClientInstance *>::iterator item;
151 for (item = mapClients.begin(); item != mapClients.end(); item++)
159 int ServerResource::getClientCount() const
161 return (int)mapClients.size();
164 ServiceInstance *ServerResource::createService(const char *name)
166 ServiceInstance *result = NULL;
167 ClientInstance *instance = NULL;
169 if ((instance = getClient(name)) != NULL) {
170 if ((result = instance->createService()) == NULL) {
171 _ERR("ClientInstance::createService failed [%s]", name);
174 _ERR("client doesn't exist, name [%s]", name);
180 ServiceInstance *ServerResource::getService(const char *name, unsigned int handle)
182 ServiceInstance *result = NULL;
183 ClientInstance *instance = NULL;
185 if ((instance = getClient(name)) != NULL) {
186 result = instance->getService(handle);
188 _ERR("client doesn't exist, name [%s]", name);
194 void ServerResource::removeService(const char *name, unsigned int handle)
196 ClientInstance *instance = NULL;
198 if ((instance = getClient(name)) != NULL) {
199 instance->removeService(handle);
200 if (instance->getServiceCounts() == 0) {
201 /* remove client instance */
205 _ERR("client doesn't exist, name [%s]", name);
209 void ServerResource::removeServices(const char *name)
211 ClientInstance *instance = NULL;
213 if ((instance = getClient(name)) != NULL) {
214 instance->removeServices();
216 /* remove client instance */
219 _ERR("client doesn't exist, name [%s]", name);
223 unsigned int ServerResource::createSession(const char *name, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
225 unsigned int result = -1;
226 Terminal *temp = NULL;
227 ServiceInstance *instance = NULL;
229 if ((instance = getService(name, handle)) != NULL) {
230 if ((temp = getTerminalByReaderID(readerID)) != NULL) {
231 result = instance->openSession(temp, certHashes, caller);
234 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
240 ServerSession *ServerResource::getSession(const char *name, unsigned int handle, unsigned int sessionID)
242 ServerSession *result = NULL;
243 ServiceInstance *instance = NULL;
245 if ((instance = getService(name, handle)) != NULL) {
246 result = instance->getSession(sessionID);
248 _ERR("Session doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, sessionID);
254 bool ServerResource::isValidSessionHandle(const char *name, unsigned int handle, unsigned int session)
256 ServiceInstance *instance = NULL;
258 return (((instance = getService(name, handle)) != NULL) && (instance->isVaildSessionHandle(session)));
261 bool ServerResource::isValidChannelHandle(const char *name, unsigned int handle, unsigned int channel)
263 ServiceInstance *instance = NULL;
265 return (((instance = getService(name, handle)) != NULL) && (instance->isVaildChannelHandle(channel)));
268 unsigned int ServerResource::getChannelCount(const char *name, unsigned int handle, unsigned int sessionID)
270 unsigned int result = -1;
271 ServiceInstance *instance = NULL;
273 if ((instance = getService(name, handle)) != NULL) {
274 result = instance->getChannelCountBySession(sessionID);
276 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
282 void ServerResource::removeSession(const char *name, unsigned int handle, unsigned int sessionID)
284 ServiceInstance *instance = NULL;
286 if ((instance = getService(name, handle)) != NULL) {
287 instance->closeSession(sessionID);
289 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
293 unsigned int ServerResource::createChannel(const char *name, unsigned int handle, unsigned int sessionID, int channelType, ByteArray aid)
294 throw(ExceptionBase &)
296 unsigned int result = -1;
297 ServiceInstance *service = NULL;
299 if ((service = getService(name, handle)) != NULL) {
300 if (service->isVaildSessionHandle(sessionID) == true) {
301 ServerSession *session = NULL;
302 Terminal *terminal = NULL;
304 terminal = service->getTerminal(sessionID);
305 session = service->getSession(sessionID);
306 if (terminal != NULL && session != NULL) {
307 if (terminal->open() == true) {
308 result = _createChannel(terminal, service, channelType, sessionID, aid);
309 if (result == IntegerHandle::INVALID_HANDLE) {
310 _ERR("create channel failed [%d]", sessionID);
315 _ERR("terminal open failed");
316 throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
319 _ERR("session is invalid [%d]", sessionID);
320 throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
323 _ERR("session is invalid [%d]", sessionID);
324 throw ExceptionBase(SCARD_ERROR_ILLEGAL_STATE);
327 _ERR("getService is failed, name [%s], handle [%d]", name, handle);
328 throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
334 Channel *ServerResource::getChannel(const char *name, unsigned int handle, unsigned int channelID)
336 Channel *result = NULL;
337 ServiceInstance *instance = NULL;
339 if ((instance = getService(name, handle)) != NULL) {
340 result = instance->getChannel(channelID);
342 _ERR("Channel doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, channelID);
348 void ServerResource::removeChannel(const char *name, unsigned int handle, unsigned int channelID)
350 ServiceInstance *instance = NULL;
352 if ((instance = getService(name, handle)) != NULL) {
353 ServerChannel *channel;
354 Terminal *terminal = NULL;
356 channel = instance->getChannel(channelID);
357 if (channel != NULL) {
358 terminal = channel->getTerminal();
361 instance->closeChannel(channelID);
363 if (terminal != NULL) {
367 _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
371 Terminal *ServerResource::getTerminal(unsigned int terminalID)
373 Terminal *result = NULL;
374 map<unsigned int, Terminal *>::iterator item;
376 if ((item = mapTerminals.find(terminalID)) != mapTerminals.end()) {
377 result = item->second;
379 _ERR("Terminal doesn't exist [%d]", terminalID);
385 const Terminal *ServerResource::getTerminal(unsigned int terminalID) const
387 const Terminal *result = NULL;
388 map<unsigned int, Terminal *>::const_iterator item;
390 if ((item = mapTerminals.find(terminalID)) != mapTerminals.end()) {
391 result = item->second;
393 _ERR("Terminal doesn't exist [%d]", terminalID);
399 Terminal *ServerResource::getTerminal(const char *name)
401 Terminal *result = NULL;
402 map<unsigned int, Terminal *>::iterator item;
404 for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
406 if (strncmp(name, item->second->getName(), strlen(name)) == 0)
408 result = item->second;
416 Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
418 Terminal *result = NULL;
419 map<unsigned int, unsigned int>::iterator item;
421 if ((item = mapReaders.find(readerID)) != mapReaders.end()) {
422 result = getTerminal(item->second);
424 _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
430 const Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID) const
432 const Terminal *result = NULL;
433 map<unsigned int, unsigned int>::const_iterator item;
435 if ((item = mapReaders.find(readerID)) != mapReaders.end()) {
436 result = getTerminal(item->second);
438 _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
444 unsigned int ServerResource::getTerminalID(const char *name) const
446 unsigned int result = IntegerHandle::INVALID_HANDLE;
447 map<unsigned int, Terminal *>::const_iterator item;
449 for (item = mapTerminals.begin();
450 item != mapTerminals.end(); item++)
452 if (strncmp(name, item->second->getName(),
455 result = item->first;
463 bool ServerResource::_isAuthorizedAccess(ServerChannel *channel,
464 const ByteArray &aid, const vector<ByteArray> &hashes)
467 AccessControlList *acList = NULL;
469 /* request open channel sequence */
470 if ((acList = getAccessControlList(channel)) == NULL) {
471 /* load access control defined by Global Platform */
472 GPACE *acl = new GPACE();
476 ret = acl->loadACL(channel);
477 if (ret >= SCARD_ERROR_OK) {
479 addAccessControlList(channel, acList);
481 _ERR("unknown error, 0x%x", -ret);
485 _ERR("alloc failed");
488 acList->loadACL(channel);
491 if (acList != NULL) {
492 result = acList->isAuthorizedAccess(aid, hashes);
498 int ServerResource::_openLogicalChannel(Terminal *terminal)
506 command = APDUHelper::generateAPDU(APDUHelper::COMMAND_OPEN_LOGICAL_CHANNEL, 0, ByteArray::EMPTY);
508 _DBG("command [%zu] : %s", command.size(), command.toString().c_str());
510 rv = terminal->transmitSync(command, response);
511 if (rv == 0 && response.size() >= 2) {
512 ResponseHelper resp(response);
514 if (resp.getStatus() >= 0) {
515 result = resp.getDataField()[0];
517 result = resp.getStatus();
520 _ERR("transmitSync failed, rv [%d], length [%zu]", rv, response.size());
526 int ServerResource::_closeLogicalChannel(Terminal *terminal, int channelNum)
528 int result = SCARD_ERROR_UNKNOWN;
534 command = APDUHelper::generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
536 _DBG("command [%zu] : %s", command.size(), command.toString().c_str());
538 rv = terminal->transmitSync(command, response);
539 if (rv == 0 && response.size() >= 2) {
540 ResponseHelper resp(response);
542 if (resp.getStatus() >= 0) {
543 _DBG("channel closed [%d]", channelNum);
544 result = SCARD_ERROR_OK;
546 _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
549 _ERR("select apdu is failed, rv [%d], length [%zu]", rv, response.size());
555 unsigned int ServerResource::_createChannel(Terminal *terminal,
556 ServiceInstance *service, int channelType,
557 unsigned int sessionID, const ByteArray &aid)
558 throw(ExceptionBase &)
560 unsigned int result = IntegerHandle::INVALID_HANDLE;
562 ServerChannel *channel = NULL;
564 /* open logical channel */
565 if (channelType == 1) {
566 channelNum = _openLogicalChannel(terminal);
567 if (channelNum > 0) {
568 _DBG("channelNum [%d]", channelNum);
570 _ERR("_openLogicalChannel failed [%d]", channelNum);
571 throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
575 /* create channel instance */
576 result = service->openChannel(sessionID, channelNum, ByteArray::EMPTY);
577 if (result == IntegerHandle::INVALID_HANDLE)
579 _ERR("channel is null.");
581 /* close logical channel */
584 _closeLogicalChannel(terminal, channelNum);
586 throw ExceptionBase(SCARD_ERROR_OUT_OF_MEMORY);
589 channel = service->getChannel(result);
592 _ERR("channel is null.");
594 throw ExceptionBase(SCARD_ERROR_OUT_OF_MEMORY);
597 /* NOTICE : This code is Access contol implementation in OpenMobile Specification.
598 If you need the Access control in your target, please remove this comment.*/
600 if (_isAuthorizedAccess(channel, aid,
601 service->getParent()->getCertificationHashes()) == true) {
604 if (aid == PKCS15::PKCS15_AID) {
605 PKCS15 pkcs15(channel);
607 rv = pkcs15.select();
608 if (rv >= SCARD_ERROR_OK) {
609 channel->unsetPrivilegeMode();
610 channel->setSelectResponse(pkcs15.getSelectResponse());
612 _ERR("select failed, [%x]", -rv);
614 service->closeChannel(result);
615 throw ExceptionBase(SCARD_ERROR_IO_FAILED);
618 FileObject file(channel);
620 rv = file.select(aid);
621 if (rv >= SCARD_ERROR_OK) {
622 channel->unsetPrivilegeMode();
623 channel->setSelectResponse(file.getSelectResponse());
625 _ERR("select failed [%x]", -rv);
627 service->closeChannel(result);
628 throw ExceptionBase(SCARD_ERROR_IO_FAILED);
632 _ERR("unauthorized access");
634 service->closeChannel(result);
635 throw ExceptionBase(SCARD_ERROR_SECURITY_NOT_ALLOWED);
641 void ServerResource::addAccessControlList(Terminal *terminal, AccessControlList *acl)
643 map<Terminal *, AccessControlList *>::iterator item;
645 if ((item = mapACL.find(terminal)) == mapACL.end()) {
646 mapACL.insert(make_pair(terminal, acl));
652 void ServerResource::addAccessControlList(ServerChannel *channel, AccessControlList *acl)
654 map<Terminal *, AccessControlList *>::iterator item;
656 if ((item = mapACL.find(channel->getTerminal())) == mapACL.end()) {
657 mapACL.insert(make_pair(channel->getTerminal(), acl));
663 AccessControlList *ServerResource::getAccessControlList(Terminal *terminal)
665 AccessControlList *result = NULL;
666 map<Terminal *, AccessControlList *>::iterator item;
668 if ((item = mapACL.find(terminal)) != mapACL.end())
670 result = item->second;
676 AccessControlList *ServerResource::getAccessControlList(ServerChannel *channel)
678 AccessControlList *result = NULL;
679 map<Terminal *, AccessControlList *>::iterator item;
681 if ((item = mapACL.find(channel->getTerminal())) != mapACL.end())
683 result = item->second;
689 Terminal *ServerResource::createInstance(void *library)
691 Terminal *terminal = NULL;
692 terminal_create_instance_fn createInstance = NULL;
694 /* create se instance */
695 createInstance = (terminal_create_instance_fn)dlsym(library, "create_instance");
696 if (createInstance != NULL) {
697 terminal = (Terminal *)createInstance();
698 if (terminal != NULL) {
699 _DBG("terminal [%p]", terminal);
701 _ERR("terminal is null");
704 _ERR("create_instance is null [%d]", errno);
710 bool ServerResource::appendSELibrary(char *library)
712 void *libHandle = NULL;
715 libHandle = dlopen(library, RTLD_LAZY);
716 if (libHandle != NULL) {
717 Terminal *terminal = NULL;
719 terminal = createInstance(libHandle);
720 if (terminal != NULL) {
721 unsigned int handle = IntegerHandle::assignHandle();
723 mapTerminals.insert(make_pair(handle, terminal));
724 libraries.push_back(libHandle);
726 terminal->setStatusCallback(&ServerResource::terminalCallback);
728 _DBG("register success [%s] [%p] [%s] [%p]", library, libHandle, terminal->getName(), terminal);
730 if (terminal->isSecureElementPresence() == true) {
731 createReader(handle);
736 _ERR("terminal is null [%s]", library);
741 _ERR("it is not se file [%s] [%d]", library, errno);
747 int ServerResource::loadSecureElements()
751 if (seLoaded == false) {
753 struct dirent *entry;
755 if ((dir = opendir(OMAPI_SE_PATH)) != NULL) {
756 while ((entry = readdir(dir)) != NULL) {
757 if (strncmp(entry->d_name, ".", 1) != 0 &&
758 strncmp(entry->d_name, "..", 2) != 0) {
760 /* TODO : need additional name rule :) */
762 /* append each files */
763 snprintf(fullPath, sizeof(fullPath),
764 "%s/%s", OMAPI_SE_PATH, entry->d_name);
766 SECURE_LOGD("se name [%s]", fullPath); //LCOV_EXCL_LINE
768 result = appendSELibrary(fullPath);
783 void ServerResource::unloadSecureElements()
785 if (seLoaded == true)
788 map<unsigned int, Terminal *>::iterator item;
790 for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
792 item->second->finalize();
794 IntegerHandle::releaseHandle(item->first);
797 mapTerminals.clear();
799 for (i = 0; i < libraries.size(); i++)
801 if (libraries[i] != NULL)
802 dlclose(libraries[i]);
811 bool ServerResource::isValidReaderHandle(unsigned int reader) const
813 return (getTerminalByReaderID(reader) != NULL);
816 void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers) const
818 const Terminal *terminal;
819 map<unsigned int, unsigned int>::const_iterator item;
823 for (item = mapReaders.begin(); item != mapReaders.end(); item++)
825 if (item->second != IntegerHandle::INVALID_HANDLE)
827 terminal = getTerminal(item->second);
828 if (terminal != NULL && terminal->isSecureElementPresence() == true)
830 readers.push_back(make_pair(item->first, terminal->getName()));
836 int ServerResource::getReadersInformation(ByteArray &info) const
839 unsigned char *buffer = NULL;
840 unsigned int length = 0;
841 unsigned int offset = 0;
842 unsigned int nameLen = 0;
844 if (mapReaders.size() > 0) {
845 const Terminal *terminal = NULL;
846 map<unsigned int, unsigned int>::const_iterator item;
848 for (item = mapReaders.begin(); item != mapReaders.end(); item++) {
849 if (item->second != IntegerHandle::INVALID_HANDLE) {
850 terminal = getTerminal(item->second);
851 if (terminal != NULL) {
852 if (terminal->getName() == NULL) {
853 _ERR("terminal name is NULL");
857 if (terminal->isSecureElementPresence()) {
858 length += sizeof(nameLen) + strlen(terminal->getName()) + sizeof(unsigned int);
865 buffer = new unsigned char[length + 1];
866 if (buffer != NULL) {
867 memset(buffer, 0, length + 1);
869 for (item = mapReaders.begin(); item != mapReaders.end(); item++) {
870 if (item->second != IntegerHandle::INVALID_HANDLE) {
871 terminal = getTerminal(item->second);
872 if (terminal != NULL) {
873 if (terminal->isSecureElementPresence()) {
874 nameLen = strlen(terminal->getName());
876 memcpy(buffer + offset, &nameLen, sizeof(nameLen));
877 offset += sizeof(nameLen);
879 memcpy(buffer + offset, terminal->getName(), nameLen);
882 memcpy(buffer + offset, &item->first, sizeof(unsigned int));
883 offset += sizeof(unsigned int);
885 buffer[offset] = '\0';
891 info.assign(buffer, length);
894 _ERR("alloc failed");
898 _INFO("no secure element");
904 void ServerResource::terminalCallback(const void *terminal, int event,
905 int error, void *user_param)
907 _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
911 case Terminal::NOTIFY_SE_AVAILABLE :
913 ServerResource &instance = ServerResource::getInstance();
914 unsigned int terminalID = IntegerHandle::INVALID_HANDLE;
916 _INFO("[NOTIFY_SE_AVAILABLE]");
918 terminalID = instance.getTerminalID((char *)terminal);
919 if (terminalID != IntegerHandle::INVALID_HANDLE)
921 unsigned int readerID = instance.createReader(terminalID);
923 ServerGDBus::getInstance().emitReaderInserted(readerID, (const char *)terminal);
928 case Terminal::NOTIFY_SE_NOT_AVAILABLE :
930 ServerResource &instance = ServerResource::getInstance();
931 unsigned int readerID = IntegerHandle::INVALID_HANDLE;
933 _INFO("[NOTIFY_SE_NOT_AVAILABLE]");
935 readerID = instance.getReaderID((char *)terminal);
937 ServerGDBus::getInstance().emitReaderRemoved(
938 readerID, (const char *)terminal);
940 instance.removeReader(readerID);
945 _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
950 unsigned int ServerResource::createReader(unsigned int terminalID)
952 unsigned int result = -1;
954 result = IntegerHandle::assignHandle();
956 mapReaders.insert(make_pair(result, terminalID));
961 unsigned int ServerResource::getReaderID(const char *name) const
963 unsigned int result = IntegerHandle::INVALID_HANDLE,
964 terminalID = IntegerHandle::INVALID_HANDLE;
966 terminalID = getTerminalID(name);
967 if (terminalID != IntegerHandle::INVALID_HANDLE)
969 map<unsigned int, unsigned int>::const_iterator item;
971 for (item = mapReaders.begin();
972 item != mapReaders.end(); item++)
974 if (item->second == terminalID)
976 result = item->first;
985 void ServerResource::removeReader(unsigned int readerID)
987 map<unsigned int, unsigned int>::iterator item;
989 if ((item = mapReaders.find(readerID)) != mapReaders.end())
991 item->second = IntegerHandle::INVALID_HANDLE;
995 ServerChannel *ServerResource::createInternalChannel(Terminal *terminal,
999 ServerChannel *channel = NULL;
1001 /* open logical channel */
1002 if (channelType == 1) {
1003 channelNum = _openLogicalChannel(terminal);
1004 if (channelNum > 0) {
1005 _DBG("channelNum [%d]", channelNum);
1007 _ERR("_openLogicalChannel failed [%d]", channelNum);
1008 throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
1012 /* create channel instance */
1013 channel = new ServerChannel(NULL, NULL, channelNum, terminal);
1018 bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal,
1019 const ByteArray &aid, const vector<ByteArray> &hashes)
1021 bool result = false;
1022 ServerChannel *channel;
1024 if (terminal == NULL) {
1028 channel = createInternalChannel(terminal, 1);
1029 if (channel != NULL) {
1030 AccessControlList *acl = getAccessControlList(channel);
1032 /* load access control defined by Global Platform */
1037 ret = acl->loadACL(channel);
1038 if (ret >= SCARD_ERROR_OK) {
1039 addAccessControlList(channel, acl);
1041 _ERR("unknown error, 0x%x", -ret);
1047 _ERR("alloc failed");
1050 acl->updateACL(channel);
1054 result = acl->isAuthorizedNFCAccess(aid, hashes);
1056 _ERR("acl is null");
1061 _ERR("alloc failed");
1067 bool ServerResource::isAuthorizedAccess(Terminal *terminal,
1068 const ByteArray &aid, const vector<ByteArray> &hashes)
1070 bool result = false;
1071 ServerChannel *channel;
1073 if (terminal == NULL) {
1077 channel = createInternalChannel(terminal, 1);
1078 if (channel != NULL) {
1079 AccessControlList *acl = getAccessControlList(channel);
1081 /* load access control defined by Global Platform */
1086 ret = acl->loadACL(channel);
1087 if (ret >= SCARD_ERROR_OK) {
1088 addAccessControlList(channel, acl);
1090 _ERR("unknown error, 0x%x", -ret);
1096 _ERR("alloc failed");
1099 acl->updateACL(channel);
1103 result = acl->isAuthorizedAccess(aid, hashes);
1105 _ERR("acl is null");
1110 _ERR("alloc failed");
1115 /* LCOV_EXCL_STOP */
1117 void ServerResource::finish()
1119 if (getClientCount() == 0) {
1120 _INFO("no client connected. terminate server");
1122 smartcard_daemon_exit();
1125 } /* namespace smartcard_service_api */