Modify confirmable certificate OTM
authorJongmin Choi <jminl.choi@samsung.com>
Tue, 31 Jan 2017 09:49:14 +0000 (18:49 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Mon, 13 Feb 2017 08:21:30 +0000 (08:21 +0000)
- In case of user denial, send relevant error message
- Reset in case of confirmation failure
- https://gerrit.iotivity.org/gerrit/#/c/16295/4

Patch #1: initial upload
Patch #2-3: Fix build error
Patch #4: resolve merge conflict

Change-Id: Ib53181fda2300056d69bcc6beac9bad872d0aaea
Signed-off-by: Jongmin Choi <jminl.choi@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16923
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/provisioning/src/ownershiptransfermanager.c [changed mode: 0644->0755]
resource/csdk/security/src/doxmresource.c

old mode 100644 (file)
new mode 100755 (executable)
index 6d73f8f..f631d52
@@ -522,6 +522,7 @@ static void OwnershipTransferSessionEstablished(const CAEndpoint_t *endpoint,
         OicSecDoxm_t *newDevDoxm, OTMContext_t *otmCtx)
 {
     OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
+    OCStackResult res = OC_STACK_ERROR;
 
     //In case of Mutual Verified Just-Works, display mutualVerifNum
     if (OIC_MV_JUST_WORKS == newDevDoxm->oxmSel)
@@ -530,16 +531,16 @@ static void OwnershipTransferSessionEstablished(const CAEndpoint_t *endpoint,
         uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN] = {0};
         OicUuid_t deviceID = {.id = {0}};
 
-        if (OC_STACK_OK != GetDoxmDeviceID(&deviceID))
+        //Generate mutualVerifNum
+        char label[LABEL_LEN] = {0};
+        snprintf(label, LABEL_LEN, "%s%s", MUTUAL_VERIF_NUM, OXM_MV_JUST_WORKS);
+        res = GetDoxmDeviceID(&deviceID);
+        if (OC_STACK_OK != res)
         {
             OIC_LOG(ERROR, TAG, "Error while retrieving Owner's device ID");
+            SetResult(otmCtx, res);
             goto exit;
         }
-
-        //Generate mutualVerifNum
-        char label[LABEL_LEN] = {0};
-        snprintf(label, LABEL_LEN, "%s%s", MUTUAL_VERIF_NUM, OXM_MV_JUST_WORKS);
-
         CAResult_t pskRet = CAGenerateOwnerPSK(endpoint,
                 (uint8_t *)label,
                 strlen(label),
@@ -550,29 +551,34 @@ static void OwnershipTransferSessionEstablished(const CAEndpoint_t *endpoint,
         if (CA_STATUS_OK != pskRet)
         {
             OIC_LOG(WARNING, TAG, "CAGenerateOwnerPSK failed");
+            SetResult(otmCtx, OC_STACK_ERROR);
             goto exit;
         }
 
         memcpy(mutualVerifNum, preMutualVerifNum + sizeof(preMutualVerifNum) - sizeof(mutualVerifNum),
                 sizeof(mutualVerifNum));
-        if (OC_STACK_OK != VerifyOwnershipTransfer(mutualVerifNum, DISPLAY_NUM))
+        res = VerifyOwnershipTransfer(mutualVerifNum, DISPLAY_NUM);
+        if (OC_STACK_OK != res)
         {
             OIC_LOG(ERROR, TAG, "Error while displaying mutualVerifNum");
+            SetResult(otmCtx, res);
             goto exit;
         }
     }
     //In case of confirmed manufacturer cert, display message
     else if (OIC_CON_MFG_CERT == newDevDoxm->oxmSel)
     {
-        if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, DISPLAY_NUM))
+        res = VerifyOwnershipTransfer(NULL, DISPLAY_NUM);
+        if (OC_STACK_OK != res)
         {
             OIC_LOG(ERROR, TAG, "Error while displaying message");
+            SetResult(otmCtx, res);
             goto exit;
         }
     }
 
     //Send request : POST /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
-    OCStackResult res = PostOwnerUuid(otmCtx);
+    res = PostOwnerUuid(otmCtx);
     if(OC_STACK_OK != res)
     {
         OIC_LOG(ERROR, TAG, "Failed to send owner information");
@@ -1011,7 +1017,15 @@ static OCStackApplicationResult OwnerUuidUpdateHandler(void *ctx, OCDoHandle UNU
     }
     else
     {
-        res = clientResponse->result;
+        if (OIC_CON_MFG_CERT == otmCtx->selectedDeviceInfo->doxm->oxmSel &&
+                    OC_STACK_NOT_ACCEPTABLE == clientResponse->result)
+        {
+            res = OC_STACK_USER_DENIED_REQ;
+        }
+        else
+        {
+            res = clientResponse->result;
+        }
         OIC_LOG_V(ERROR, TAG, "OwnerUuidHandler : Unexpected result %d", res);
         SetResult(otmCtx, res);
     }
index 24218a9..d7ba347 100644 (file)
@@ -1327,6 +1327,22 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe
 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
                 else if (OIC_MANUFACTURER_CERTIFICATE ==  newDoxm->oxmSel || OIC_CON_MFG_CERT == newDoxm->oxmSel)
                 {
+                    //In case of Confirm Manufacturer Cert, get user confirmation
+                    if (OIC_CON_MFG_CERT == newDoxm->oxmSel && false == newDoxm->owned &&
+                        false == isDuplicatedMsg &&
+                        memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0)
+                    {
+                        if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM))
+                        {
+                            ehRet = OC_EH_NOT_ACCEPTABLE;
+                            goto exit;
+                        }
+                        else
+                        {
+                            ehRet = OC_EH_OK;
+                        }
+                    }
+
                     //Save the owner's UUID to derive owner credential
                     memcpy(&(gDoxm->owner), &(newDoxm->owner), sizeof(OicUuid_t));
                     gDoxm->oxmSel = newDoxm->oxmSel;
@@ -1346,23 +1362,6 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe
 
                     VERIFY_SUCCESS(TAG, CA_STATUS_OK == CAregisterPkixInfoHandler(GetManufacturerPkixInfo), ERROR);
                     VERIFY_SUCCESS(TAG, CA_STATUS_OK == CAregisterGetCredentialTypesHandler(InitManufacturerCipherSuiteList), ERROR);
-
-                    //In case of Confirm Manufacturer Cert, get user confirmation
-                    if (OIC_CON_MFG_CERT == newDoxm->oxmSel && false == newDoxm->owned &&
-                        false == isDuplicatedMsg &&
-                        memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0)
-                    {
-                        if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM))
-                        {
-                            ehRet = OC_EH_NOT_ACCEPTABLE;
-                        }
-                        else
-                        {
-                            ehRet = OC_EH_OK;
-                        }
-                    }
-
-
                 }
 #endif // __WITH_DTLS__ or __WITH_TLS__
             }