channel change for access control
authorSangSoo Lee <constant.lee@samsung.com>
Thu, 3 Jan 2013 12:50:29 +0000 (21:50 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Thu, 10 Jan 2013 09:20:41 +0000 (18:20 +0900)
Change-Id: If053227582775aa471bd552d2e12a35d91dd8512
Signed-off-by: SangSoo Lee <constant.lee@samsung.com>
client/Session.cpp
common/SignatureHelper.cpp
packaging/smartcard-service.spec
server/ServerResource.cpp
server/include/ServerResource.h

index 8bad4e8..b22af25 100644 (file)
@@ -691,7 +691,7 @@ EXTERN_API channel_h session_open_logical_channel_sync(session_h handle, unsigne
 
 #ifdef CLIENT_IPC_THREAD
        SESSION_EXTERN_BEGIN;
-       result = session->openBasicChannelSync(aid, length);
+       result = session->openLogicalChannelSync(aid, length);
        SESSION_EXTERN_END;
 #endif
 
index d512bc0..3d3fa93 100644 (file)
@@ -49,8 +49,8 @@ namespace smartcard_service_api
                if (pid < 0 || processName == NULL || length == 0)
                        return ret;
 
-               snprintf(buffer, sizeof(buffer), "/proc/%d/exec", pid);
-               SCARD_DEBUG("pid : %d, exec : %s", pid, buffer);
+               snprintf(buffer, sizeof(buffer), "/proc/%d/exe", pid);
+               SCARD_DEBUG("pid : %d, exe : %s", pid, buffer);
 
                if ((len = readlink(buffer, filename, sizeof(filename) - 1)) < sizeof(filename) - 1)
                {
index 4da0fcb..8f95c70 100644 (file)
@@ -1,7 +1,7 @@
 Name:       smartcard-service
 Summary:    Smartcard Service FW
-Version:    0.1.7
-Release:    1
+Version:    0.1.8
+Release:    0
 Group:      libs
 License:    Samsung Proprietary License
 Source0:    %{name}-%{version}.tar.gz
index 4b6970e..f28a4a0 100644 (file)
@@ -422,6 +422,46 @@ namespace smartcard_service_api
                return result;
        }
 
+       bool ServerResource::_isAuthorizedAccess(Terminal *terminal, int pid, ByteArray aid, vector<ByteArray> &hashes, int channelNum)
+       {
+               bool result = true;
+
+#if 1 /* disable for temporary */
+               char filename[1024] = { 0, };
+               AccessControlList *acList = NULL;
+
+               SCARD_DEBUG_ERR("=== _isAuthorizedAccess22");
+
+               /* check exceptional case */
+               SignatureHelper::getProcessName(pid, filename, sizeof(filename));
+               if (strncmp(filename, "ozD3Dw1MZruTDKHWGgYaDib2B2LV4/nfT+8b/g1Vsk8=", sizeof(filename)) != 0)
+               {
+                       /* request open channel sequence */
+                       if ((acList = getAccessControlList(terminal, channelNum)) != NULL)
+                       {
+#if 1
+                               result = acList->isAuthorizedAccess(aid, hashes);
+
+                               SCARD_DEBUG_ERR("AC result [%d]", result);
+
+#else
+                               SCARD_DEBUG_ERR("=== Get access control done");
+
+//                             result = acList->isAuthorizedAccess(aid, session->packageCert);
+#endif
+                       }
+                       else
+                       {
+                               SCARD_DEBUG_ERR("acList is null");
+                               result = false;
+                       }
+               }
+#endif
+
+               return result;
+       }
+
+
        unsigned int ServerResource::_createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid)
        {
                unsigned int result = IntegerHandle::INVALID_HANDLE;
@@ -461,38 +501,42 @@ namespace smartcard_service_api
                        }
                }
 
-               /* select aid */
-               APDUCommand apdu;
-               apdu.setCommand(0, APDUCommand::INS_SELECT_FILE, APDUCommand::P1_SELECT_BY_DF_NAME, APDUCommand::P2_SELECT_GET_FCP, aid, 0);
-               apdu.setChannel(1, channelNum);
-               apdu.getBuffer(command);
 
-               rv = terminal->transmitSync(command, response);
-               if (rv == 0 && response.getLength() >= 2)
+               if (_isAuthorizedAccess(terminal, service->getParent()->getPID(), aid, service->getParent()->getCertificationHashes(), channelNum) == true)
                {
-                       ResponseHelper resp(response);
+                       /* select aid */
+                       APDUCommand apdu;
+                       apdu.setCommand(0, APDUCommand::INS_SELECT_FILE, APDUCommand::P1_SELECT_BY_DF_NAME, APDUCommand::P2_SELECT_GET_FCP, aid, 0);
+                       apdu.setChannel(1, channelNum);
+                       apdu.getBuffer(command);
 
-                       if (resp.getStatus() == 0)
+                       rv = terminal->transmitSync(command, response);
+                       if (rv == 0 && response.getLength() >= 2)
                        {
-                               result = service->openChannel(sessionID, channelNum, response);
-                               if (result == IntegerHandle::INVALID_HANDLE)
+                               ResponseHelper resp(response);
+
+                               if (resp.getStatus() == 0)
                                {
-                                       SCARD_DEBUG_ERR("channel is null.");
+                                       result = service->openChannel(sessionID, channelNum, response);
+                                       if (result == IntegerHandle::INVALID_HANDLE)
+                                       {
+                                               SCARD_DEBUG_ERR("channel is null.");
+                                       }
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                               SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, response.getLength());
                        }
                }
-               else
-               {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, response.getLength());
-               }
-
                return result;
        }
 
+#if 0
        unsigned int ServerResource::createChannel(int socket, unsigned int context, unsigned int sessionID, int channelType, ByteArray aid)
        {
                unsigned int result = -1;
@@ -536,6 +580,46 @@ namespace smartcard_service_api
                return result;
        }
 
+#endif
+
+
+/****************************************************************************************************/
+       unsigned int ServerResource::createChannel(int socket, unsigned int context, unsigned int sessionID, int channelType, ByteArray aid)
+       {
+               unsigned int result = -1;
+               ServiceInstance *service = NULL;
+
+               if ((service = getService(socket, context)) != NULL)
+               {
+                       if (service->isVaildSessionHandle(sessionID) == true)
+                       {
+                               ServerSession *session = NULL;
+                               Terminal *terminal = NULL;
+
+                               terminal = service->getTerminal(sessionID);
+                               session = service->getSession(sessionID);
+                               if (terminal != NULL && session != NULL)
+                               {
+                                       result = _createChannel(terminal, service, channelType, sessionID, aid);
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG_ERR("session is invalid [%d]", sessionID);
+                               }
+                       }
+                       else
+                       {
+                               SCARD_DEBUG_ERR("session is invalid [%d]", sessionID);
+                       }
+               }
+               else
+               {
+                       SCARD_DEBUG_ERR("getService is failed [%d] [%d]", socket, context);
+               }
+
+               return result;
+       }
+
        Channel *ServerResource::getChannel(int socket, unsigned int context, unsigned int channelID)
        {
                Channel *result = NULL;
@@ -601,6 +685,40 @@ namespace smartcard_service_api
                return result;
        }
 
+       AccessControlList *ServerResource::getAccessControlList(Terminal *terminal, int channelNuml)
+       {
+               AccessControlList *result = NULL;
+               map<Terminal *, AccessControlList *>::iterator item;
+
+               if ((item = mapACL.find(terminal)) == mapACL.end())
+               {
+                       ServerChannel *channel = new ServerChannel(NULL, NULL, channelNuml, terminal);
+                       if (channel != NULL)
+                       {
+                               /* load access control */
+                               result = new GPSEACL(channel);
+                               if (result != NULL)
+                               {
+                                       mapACL.insert(make_pair(terminal, result));
+                               }
+                               else
+                               {
+                                       SCARD_DEBUG_ERR("alloc failed");
+                               }
+                       }
+                       else
+                       {
+                               SCARD_DEBUG_ERR("alloc failed");
+                       }
+               }
+               else
+               {
+                       result = item->second;
+               }
+
+               return result;
+       }
+
        Terminal *ServerResource::createInstance(void *library)
        {
                Terminal *terminal = NULL;
index 4479462..9b93d81 100644 (file)
@@ -127,12 +127,15 @@ namespace smartcard_service_api
                bool isValidSessionHandle(int socket, unsigned int context, unsigned int sessionID);
 
                bool _isAuthorizedAccess(Terminal *terminal, int pid, ByteArray aid, vector<ByteArray> &hashes);
+               bool _isAuthorizedAccess(Terminal *terminal, int pid, ByteArray aid, vector<ByteArray> &hashes, int channelNum);
+
                unsigned int _createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid);
                unsigned int createChannel(int socket, unsigned int context, unsigned int sessionID, int channelType, ByteArray aid);
                Channel *getChannel(int socket, unsigned int context, unsigned int channelID);
                void removeChannel(int socket, unsigned int context, unsigned int channelID);
 
                AccessControlList *getAccessControlList(Terminal *terminal);
+               AccessControlList *getAccessControlList(Terminal *termina, int channelNuml);
 
                bool sendMessageToAllClients(Message &msg);