Send (correct) response to client when cynara danied access 59/160159/5
authorKrzysztof Dynowski <k.dynowski@samsung.com>
Tue, 14 Nov 2017 14:27:02 +0000 (15:27 +0100)
committerRafa? Tymi?ski <r.tyminski@partner.samsung.com>
Tue, 21 Nov 2017 11:14:09 +0000 (11:14 +0000)
Change-Id: I53b11b0149725dc88679febb6706af42b8d37cb3

simulatordaemon/inc/TEEContext.h
simulatordaemon/src/ConnectionSession.cpp
simulatordaemon/src/TEEContext.cpp

index 4db8506..ab68665 100644 (file)
@@ -61,6 +61,7 @@ public:
        uint32_t mContextID;
        /* Security context wich stores info about low-level connection data*/
        SecurityContext secContext;
+       bool cynara_check_result;
 
        /* For TA internal APIs support, dummy Context is created and for recognizing
         * the context as dummy isInternal member variable is used
index 31fb181..8fadf2f 100644 (file)
@@ -48,22 +48,23 @@ void ConnectionSession::start() {
        // init SecurityContext of current session after initializing socket
        this->secContext = SecurityContext(clientSocket.native());
 
+       // Create a new Context
+       pthread_rwlock_wrlock(&ctxIDLock);
+       TEECtx = new TEEContext(ctxID, this);
+       // Increment the Context ID to be assigned to next Context
+       ctxID++;
+       if (ctxID == 0) ctxID++;
+       pthread_rwlock_unlock(&ctxIDLock);
+
 #ifdef _CYNARA_INTEGRATION
        /* Check if client has cynara permission */
        const string privilege("http://tizen.org/privilege/tee.client");
        if (!secContext.clientHasCynaraPermission(privilege)) {
                LOGE(SIM_DAEMON, "Client has no permission to use TEE");
-               return;
+               TEECtx->cynara_check_result = false;
        }
 #endif /* _CYNARA_INTEGRATION */
 
-       // Create a new Context
-       pthread_rwlock_wrlock(&ctxIDLock);
-       TEECtx = new TEEContext(ctxID, this);
-       // Increment the Context ID to be assigned to next Context
-       ctxID++;
-       if (ctxID == 0) ctxID++;
-       pthread_rwlock_unlock(&ctxIDLock);
        currentState = CMD_READ;
 
        // read exactly 1 byte to identify the command and execute callback when
index f85729c..189f918 100644 (file)
@@ -57,6 +57,8 @@ TEEContext::TEEContext(uint32_t contextID, IConnectionSession* connSession):
        /* Clear the shared memory list (mShmList) and Session map (mSessionMap) */
        mSessionMap.clear();
        mShmList.clear();
+
+       cynara_check_result = true;
 }
 
 /**
@@ -75,6 +77,17 @@ TEEC_Result TEEContext::initContext(InitContextData* data) {
         */
        isInternal = false;
 
+       if (!cynara_check_result) {
+               result = TEEC_ERROR_ACCESS_DENIED;
+               data->returnValue = result;
+               result = mConnSess->write(INITIALIZE_CONTEXT, (char*)data,
+                   sizeof(InitContextData));
+               if (result != TEEC_SUCCESS) {
+                       LOGE(SIM_DAEMON, "Initialize Context response write to CA FAILED");
+               }
+               return result;
+       }
+
        /* Check if the TEEName is proper or not */
        if (data->nameLength != 0) {
                string TName(data->TEEName);
@@ -167,6 +180,7 @@ TEEC_Result TEEContext::openSession(OpenSessionData data) {
        LOGD(SIM_DAEMON, "Entry");
        data.returnOrigin = TEEC_ORIGIN_TEE;
        data.returnValue = TEEC_ERROR_GENERIC;
+
        pthread_rwlock_wrlock(&sessIDLock);
        data.sessionID = sessID;
        sessID++;