Prevent empty credential to be added
authorJongmin Choi <jminl.choi@samsung.com>
Tue, 18 Oct 2016 09:28:42 +0000 (18:28 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 19 Oct 2016 10:29:15 +0000 (10:29 +0000)
Prevent empty credential to be added
(e.g. only rowneruuid is sent)

Patch #1: initial upload
Patch #2-3: fix arduino build error

Change-Id: I7802dcb76daab3269eb0a9638659087643b0c141
Signed-off-by: Jongmin Choi <jminl.choi@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13379
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/src/credresource.c

index f973e44..9819887 100644 (file)
@@ -1371,31 +1371,41 @@ OCStackResult AddCredential(OicSecCred_t * newCred)
     OCStackResult ret = OC_STACK_ERROR;
     OicSecCred_t * temp = NULL;
     bool validFlag = true;
+    OicUuid_t emptyOwner = { .id = {0} };
     VERIFY_SUCCESS(TAG, NULL != newCred, ERROR);
 
     //Assigning credId to the newCred
     newCred->credId = GetCredId();
     VERIFY_SUCCESS(TAG, newCred->credId != 0, ERROR);
 
-    LL_FOREACH(gCred, temp)
+    //the newCred is not valid if it is empty
+
+    if (memcmp(&(newCred->subject.id), &emptyOwner, UUID_IDENTITY_SIZE) == 0)
+    {
+        validFlag = false;
+    }
+    else
     {
-        CredCompareResult_t cmpRes = CompareCredential(temp, newCred);
-        if(CRED_CMP_EQUAL == cmpRes)
+        LL_FOREACH(gCred, temp)
         {
-            OIC_LOG_V(WARNING, TAG, "Detected same credential ID(%d)" \
-                      "new credential's ID will be replaced.", temp->credId);
-            newCred->credId = temp->credId;
-            ret = OC_STACK_OK;
-            validFlag = false;
-            break;
-        }
+            CredCompareResult_t cmpRes = CompareCredential(temp, newCred);
+            if(CRED_CMP_EQUAL == cmpRes)
+            {
+                OIC_LOG_V(WARNING, TAG, "Detected same credential ID(%d)" \
+                          "new credential's ID will be replaced.", temp->credId);
+                newCred->credId = temp->credId;
+                ret = OC_STACK_OK;
+                validFlag = false;
+                break;
+            }
 
-        if (CRED_CMP_ERROR == cmpRes)
-        {
-            OIC_LOG_V(WARNING, TAG, "Credential skipped : %d", cmpRes);
-            ret = OC_STACK_ERROR;
-            validFlag = false;
-            break;
+            if (CRED_CMP_ERROR == cmpRes)
+            {
+                OIC_LOG_V(WARNING, TAG, "Credential skipped : %d", cmpRes);
+                ret = OC_STACK_ERROR;
+                validFlag = false;
+                break;
+            }
         }
     }