[IOT-2280] update /doxm.rowneruuid in POST handler
authorNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Fri, 19 May 2017 00:53:36 +0000 (17:53 -0700)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Sun, 21 May 2017 18:18:31 +0000 (18:18 +0000)
This workaround fixes issue reported in 2280, but the root cause of
2280 is that the /doxm POST handler still does all sorts of strange
things per IOT-2107.  IOT-2107 will certainly result in another failed
TC shortly.  I am changing IOT-2107 to P1 and to Fix In 1.3.0.  This
patch doesn't hurt in the meantime to resolve 2280.

Change-Id: I2204cddabe943941f46136b60d0922a77f208665
Signed-off-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20083
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
resource/csdk/security/src/doxmresource.c

index 38a43bf4c8f2590bef70a2d5b90b30b76d3ba74b..36aa3e9006ab061c7f1fac32b404f20f00ed9da4 100644 (file)
@@ -968,20 +968,49 @@ OCStackResult DoxmUpdateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t*
     {
         // Update oxmsel
         dst->oxmSel = src->oxmSel;
+        OIC_LOG_V(DEBUG, TAG, "%s: updated doxm.oxmsel = %d", __func__,
+            (int)dst->oxmSel);
 
-        // Update owner
+        // Update devowneruuid
         memcpy(&(dst->owner), &(src->owner), sizeof(OicUuid_t));
+#ifndef NDEBUG // if debug build, log the new uuid
+        char uuidString[UUID_STRING_SIZE] = { 0 };
+        bool convertedUUID = OCConvertUuidToString(dst->owner.id, uuidString);
+        if (convertedUUID)
+        {
+            OIC_LOG_V(DEBUG, TAG, "%s: updated doxm.devowneruuid = %s", __func__,
+                uuidString);
+        }
+#endif
 
-        // Update rowner
+        // Update rowneruuid
         memcpy(&(dst->rownerID), &(src->rownerID), sizeof(OicUuid_t));
+#ifndef NDEBUG // if debug build, log the new uuid
+        convertedUUID = OCConvertUuidToString(dst->rownerID.id, uuidString);
+        if (convertedUUID)
+        {
+            OIC_LOG_V(DEBUG, TAG, "%s: updated doxm.rowneruuid = %s", __func__,
+                uuidString);
+        }
+#endif
 
         // Update deviceuuid
         memcpy(&(dst->deviceID), &(src->deviceID), sizeof(OicUuid_t));
+#ifndef NDEBUG // if debug build, log the new uuid
+        convertedUUID = OCConvertUuidToString(dst->deviceID.id, uuidString);
+        if (convertedUUID)
+        {
+            OIC_LOG_V(DEBUG, TAG, "%s: updated doxm.deviceuuid = %s", __func__,
+                uuidString);
+        }
+#endif
 
         // Update owned status
         if(dst->owned != src->owned)
         {
             dst->owned = src->owned;
+            OIC_LOG_V(DEBUG, TAG, "%s: updated owned = %s", __func__,
+                dst->owned?"true":"false");
         }
 
 #ifdef MULTIPLE_OWNER
@@ -1000,6 +1029,8 @@ OCStackResult DoxmUpdateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t*
             if (NULL != dst->mom)
             {
                 dst->mom->mode = src->mom->mode;
+                OIC_LOG_V(DEBUG, TAG, "%s: updated mom->mode = %d", __func__,
+                    (int)dst->mom->mode);
             }
         }
 #endif //MULTIPLE_OWNER
@@ -1302,6 +1333,12 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe
             }
 
             // in unowned state
+            // TODO [IOT-2107] this logic assumes that the only POST to /doxm in
+            // unowned state is either a) changing to owned or b) setting oxmsel and
+            // therefore (in case b) should enable the proper cipher for OTM.  But it's
+            // allowable for Client to be posting other things such as /doxm.rowneruuid
+            // when owned == false, too.  Added a workaround (see 'workaround' below)
+            // but this POST handler needs to be fixed per IOT-2107.
             if ((false == gDoxm->owned) && (false == newDoxm->owned))
             {
                 if (false == ValidateOxmsel(gDoxm->oxm, gDoxm->oxmLen, &newDoxm->oxmSel))
@@ -1311,6 +1348,19 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe
                     goto exit;
                 }
 
+                // workaround
+                // We wouldn't be at this point in the
+                // code if the POST contained R-only Properties for the current /pstat.dos.s
+                // state, so we want to update writeable properties now that we've validated
+                // oxmsel is a valid oxm for this device.
+                res = DoxmUpdateWriteableProperty(newDoxm, gDoxm);
+                if (OC_STACK_OK != res)
+                {
+                    OIC_LOG(ERROR, TAG, "gDoxm properties were not able to be updated so we cannot handle the request.");
+                    ehRet = OC_EH_ERROR;
+                    goto exit;
+                }
+
                 if (OIC_JUST_WORKS == newDoxm->oxmSel || OIC_MV_JUST_WORKS == newDoxm->oxmSel)
                 {
                     /*