Update security module according to ocstack update
authorChul Lee <chuls.lee@samsung.com>
Tue, 19 Jul 2016 12:20:45 +0000 (21:20 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 19 Jul 2016 12:32:50 +0000 (12:32 +0000)
in order to guarantee OTM success.

   1. Change the response check condition about POST request.
   2. Prevent restore of doxm,pstat in case of owned status and retransmission.

Change-Id: I69d2b3e497517373add683e7765b3521422e329b
Signed-off-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9465
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Tested-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/pstatresource.c

index 793525c..9bdc2c5 100644 (file)
@@ -483,7 +483,7 @@ static OCStackApplicationResult OwnerTransferModeHandler(void *ctx, OCDoHandle U
 
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
     (void)UNUSED;
-    if(clientResponse->result == OC_STACK_OK)
+    if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         OIC_LOG(INFO, TAG, "OwnerTransferModeHandler : response result = OC_STACK_OK");
         //Send request : GET /oic/sec/pstat
@@ -603,7 +603,7 @@ static OCStackApplicationResult OwnerUuidUpdateHandler(void *ctx, OCDoHandle UNU
     OCStackResult res = OC_STACK_OK;
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
 
-    if(OC_STACK_OK == clientResponse->result)
+    if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         if(otmCtx && otmCtx->selectedDeviceInfo)
         {
@@ -658,7 +658,7 @@ static OCStackApplicationResult OperationModeUpdateHandler(void *ctx, OCDoHandle
 
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
     (void) UNUSED;
-    if  (OC_STACK_OK == clientResponse->result)
+    if  (OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         OCStackResult res = OC_STACK_ERROR;
         OicSecOxm_t selOxm = otmCtx->selectedDeviceInfo->doxm->oxmSel;
@@ -810,7 +810,7 @@ static OCStackApplicationResult OwnershipInformationHandler(void *ctx, OCDoHandl
     OCStackResult res = OC_STACK_OK;
     OTMContext_t* otmCtx = (OTMContext_t*)ctx;
 
-    if(OC_STACK_OK == clientResponse->result)
+    if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         if(otmCtx && otmCtx->selectedDeviceInfo)
         {
@@ -859,7 +859,7 @@ static OCStackApplicationResult ProvisioningStatusHandler(void *ctx, OCDoHandle
     (void)UNUSED;
     OCStackResult res = OC_STACK_OK;
 
-    if(OC_STACK_OK == clientResponse->result)
+    if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         if(otmCtx && otmCtx->selectedDeviceInfo)
         {
@@ -905,7 +905,7 @@ static OCStackApplicationResult ReadyForNomalStatusHandler(void *ctx, OCDoHandle
     OTMContext_t* otmCtx = (OTMContext_t*) ctx;
     (void)UNUSED;
 
-    if (OC_STACK_OK == clientResponse->result)
+    if (OC_STACK_RESOURCE_CHANGED == clientResponse->result)
     {
         OIC_LOG(INFO, TAG, "Device state is in Ready for Normal Operation.");
         OCStackResult res = PDMAddDevice(&otmCtx->selectedDeviceInfo->doxm->deviceID);
index 47c7c59..aa05845 100644 (file)
@@ -612,6 +612,9 @@ static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest
         }
     }
 
+    OIC_LOG(DEBUG, TAG, "Send payload for doxm GET request");
+    OIC_LOG_BUFFER(DEBUG, TAG, payload, size);
+
     // Send response payload to request originator
     if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
     {
@@ -751,7 +754,6 @@ static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest
                                 OIC_LOG(ERROR, TAG, "Failed to generate random PIN");
                                 ehRet = OC_EH_ERROR;
                             }
-                            previousMsgId = ehRequest->messageID;
                         }
 #endif //__WITH_DTLS__
                     }
@@ -851,15 +853,29 @@ static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest
 exit:
     if(OC_EH_OK != ehRet)
     {
-        OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request,"\
-                            "DOXM will be reverted.");
 
         /*
          * If some error is occured while ownership transfer,
          * ownership transfer related resource should be revert back to initial status.
-         */
-        RestoreDoxmToInitState();
-        RestorePstatToInitState();
+        */
+        if(gDoxm)
+        {
+            if(!gDoxm->owned && previousMsgId != ehRequest->messageID)
+            {
+                OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request,"\
+                                    "DOXM will be reverted.");
+                RestoreDoxmToInitState();
+                RestorePstatToInitState();
+            }
+        }
+        else
+        {
+            OIC_LOG(ERROR, TAG, "Invalid DOXM resource.");
+        }
+    }
+    else
+    {
+        previousMsgId = ehRequest->messageID;
     }
 
     //Send payload to request originator
index 39d1d26..050c497 100644 (file)
@@ -436,6 +436,7 @@ static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
     OIC_LOG(INFO, TAG, "HandlePstatPostRequest  processing POST request");
     OicSecPstat_t *pstat = NULL;
+    static uint16_t prevMsgId = 0;
 
     if (ehRequest->payload)
     {
@@ -484,15 +485,31 @@ static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest
         }
     }
  exit:
-    if(OC_EH_OK != ehRet)
-    {
-        /*
-          * If some error is occured while ownership transfer,
-          * ownership transfer related resource should be revert back to initial status.
-          */
-        RestoreDoxmToInitState();
-        RestorePstatToInitState();
-    }
+     if(OC_EH_OK != ehRet)
+     {
+         /*
+           * If some error is occured while ownership transfer,
+           * ownership transfer related resource should be revert back to initial status.
+           */
+         const OicSecDoxm_t* doxm = GetDoxmResourceData();
+         if(doxm)
+         {
+             if(!doxm->owned && prevMsgId !=  ehRequest->messageID)
+             {
+                 RestoreDoxmToInitState();
+                 RestorePstatToInitState();
+             }
+         }
+         else
+         {
+             OIC_LOG(ERROR, TAG, "Invalid DOXM resource.");
+         }
+     }
+     else
+     {
+         prevMsgId = ehRequest->messageID;
+     }
+
 
     //Send payload to request originator
     if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))