Fix a condition to filter out a wrong cred ID
authorJihun Ha <jihun.ha@samsung.com>
Mon, 19 Sep 2016 02:19:10 +0000 (11:19 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 29 Sep 2016 07:34:37 +0000 (07:34 +0000)
A range of cred ID starts from 1 not 0. This patch fixes this wrong comparison.

Change-Id: I46196c38bfbe8a55a59de68e817b8c790b5e73fd
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11909
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
(cherry picked from commit c81cb8564bb5e1df70ceae977cd31620bd9eace8)
Reviewed-on: https://gerrit.iotivity.org/gerrit/12525
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp

index c7fe9a8..0269456 100755 (executable)
@@ -124,7 +124,7 @@ namespace OIC
             CloudProp()
             {
                 m_cloudID = "";
-                m_credID = -1;
+                m_credID = 0;
             }
 
             CloudProp(const CloudProp& cloudProp) :
@@ -148,6 +148,7 @@ namespace OIC
             {
                 m_rep = rep;
                 m_cloudID = "";
+                m_credID = 0;
             }
 
             /**
index 3a6335c..867c0f8 100755 (executable)
@@ -345,15 +345,23 @@ namespace OIC
                 throw ESException("Not found owned devices.");
             }
 
-            if(!cloudUuid.empty()
-                && performACLProvisioningForCloudServer(ownedDevice, cloudUuid) != ESResult::ES_OK)
+            if(cloudUuid.empty())
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,
+                         "ACL provisioning is skipped due to empty UUID of cloud server");
+            }
+            else if(performACLProvisioningForCloudServer(ownedDevice, cloudUuid) != ESResult::ES_OK)
             {
                 OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "error performACLProvisioningForCloudServer");
                 throw ESException("error performACLProvisioningForCloudServer");
             }
 
-            if(credId != -1
-                && performCertProvisioningForCloudServer(ownedDevice, credId) != ESResult::ES_OK)
+            if(credId < 1)
+            {
+                OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG,
+                         "Cert. provisioning is skipped due to wrong cred ID (<1)");
+            }
+            else if(performCertProvisioningForCloudServer(ownedDevice, credId) != ESResult::ES_OK)
             {
                 OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "error performCertProvisioningForCloudServer");
                 throw ESException("error performCertProvisioningForCloudServer");
index f5c8d7f..44d26d6 100755 (executable)
@@ -409,13 +409,17 @@ namespace OIC
 #if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
             try
             {
-                if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() == -1))
+                if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0))
                 {
                     m_enrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource, "");
 
                     m_enrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(),
                                                                         cloudProp.getCredID());
                 }
+                else
+                {
+                    OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped.");
+                }
             }
 
             catch (const std::exception& e)