[IOT-1520] Allow MOT to be disabled after it is enabled.
authorAlex Kelley <alexke@microsoft.com>
Tue, 21 Mar 2017 21:54:23 +0000 (14:54 -0700)
committerGreg Zaverucha <gregz@microsoft.com>
Fri, 24 Mar 2017 23:52:14 +0000 (23:52 +0000)
These changes do the following:
1. Fix updateWriteableProperty to honor the 'mom'
   property any time that it is changed.
2. Rename updateWriteableProperty to
   DoxmUpdateWriteableProperty to clarify its usage.
3. Fix an invalid check in the ProvisioningClient.
4. Added tests to ensure that mom can be enabled
   and disabled when MOT is available.

Change-Id: I97c01a9dc8f44bcf5a6aeac3bf459777c97e19b0
Signed-off-by: Alex Kelley <alexke@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18109
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Reviewed-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Pawel Winogrodzki <pawelwi@microsoft.com>
Reviewed-by: Greg Zaverucha <gregz@microsoft.com>
resource/csdk/security/include/internal/doxmresource.h
resource/csdk/security/include/securevirtualresourcetypes.h
resource/csdk/security/provisioning/sample/provisioningclient.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/unittest/doxmresource.cpp

index 1c315ca..e389618 100644 (file)
@@ -191,6 +191,17 @@ void MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object,
  */
 OCStackResult SetDoxmSelfOwnership(const OicUuid_t* newROwner);
 
+/**
+ * Internal function to update the writable properties of an /oic/sec/doxm
+ * struct with the values from another /oic/sec/doxm struct.
+ *
+ * @param src is a pointer to the source @ref OicSecDoxm_t data.
+ * @param dst is a pointer to the destination @ref OicSecDoxm_t data. 
+ *
+ * @retval ::OC_STACK_OK for Success, otherwise some error value
+ */
+OCStackResult DoxmUpdateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst);
+
 #ifdef __cplusplus
 }
 #endif
index c58d722..1e2e9b4 100644 (file)
@@ -527,6 +527,8 @@ struct OicSecMom{
 /**
  * /oic/sec/doxm (Device Owner Transfer Methods) data type
  * Derived from OIC Security Spec; see Spec for details.
+ * @note If the struct is updated please update
+ * DoxmUpdateWriteableProperty appropriately.
  */
 struct OicSecDoxm
 {
index 2513c8f..fac71bc 100644 (file)
@@ -1347,17 +1347,17 @@ static int changeMultipleOwnershipTrnasferMode(void)
     int mom = 0;
     for( ; ; )
     {
-        printf("   0. Disable Multuple Ownership Transfer\n");
-        printf("   1. Enable Multuple Ownership Transfer\n");
-        printf("   2. (Not Supported yet) Timely Enable Multuple Ownership Transfer\n");
-        printf("   > Enter Mode of Multuple Ownership Transfer : ");
+        printf("   0. Disable Multiple Ownership Transfer\n");
+        printf("   1. Enable Multiple Ownership Transfer\n");
+        printf("   2. (Not Supported yet) Timely Enable Multiple Ownership Transfer\n");
+        printf("   > Enter Mode of Multiple Ownership Transfer : ");
         for(int ret=0; 1!=ret; )
         {
             ret = scanf("%d", &mom);
             for( ; 0x20<=getchar(); );  // for removing overflow garbages
                                         // '0x20<=code' is character region
         }
-        if(0 <= dev_num && OIC_NUMBER_OF_MOM_TYPE > dev_num)
+        if((0 <= mom) && (OIC_NUMBER_OF_MOM_TYPE > mom))
         {
             break;
         }
index 92d9fe3..82aef18 100644 (file)
@@ -844,23 +844,25 @@ static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest
     return ehRet;
 }
 
-static void updateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst)
+OCStackResult DoxmUpdateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst)
 {
+    OCStackResult result = OC_STACK_OK;
+
     if(src && dst)
-   {
-        // update oxmsel
+    {
+        // Update oxmsel
         dst->oxmSel = src->oxmSel;
 
-        //update owner
+        // Update owner
         memcpy(&(dst->owner), &(src->owner), sizeof(OicUuid_t));
 
-        //update rowner
+        // Update rowner
         memcpy(&(dst->rownerID), &(src->rownerID), sizeof(OicUuid_t));
 
-        //update deviceuuid
+        // Update deviceuuid
         memcpy(&(dst->deviceID), &(src->deviceID), sizeof(OicUuid_t));
 
-        //Update owned status
+        // Update owned status
         if(dst->owned != src->owned)
         {
             dst->owned = src->owned;
@@ -869,18 +871,25 @@ static void updateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst)
 #ifdef MULTIPLE_OWNER
         if(src->mom)
         {
-            OIC_LOG(DEBUG, TAG, "dectected 'mom' property");
+            OIC_LOG(DEBUG, TAG, "Detected 'mom' property");
             if(NULL == dst->mom)
             {
                 dst->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t));
-                if(NULL != dst->mom)
+                if (NULL == dst->mom)
                 {
-                    dst->mom->mode = src->mom->mode;
+                    result = OC_STACK_NO_MEMORY;
                 }
             }
+
+            if (NULL != dst->mom)
+            {
+                dst->mom->mode = src->mom->mode;
+            }
         }
 #endif //MULTIPLE_OWNER
     }
+
+    return result;
 }
 
 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
@@ -1066,8 +1075,15 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe
                     ehRet = OC_EH_NOT_ACCEPTABLE;
                     goto exit;
                 }
-                //Update gDoxm based on newDoxm
-                updateWriteableProperty(newDoxm, gDoxm);
+
+                // Update gDoxm based on newDoxm
+                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 defined(__WITH_DTLS__) || defined (__WITH_TLS__)
 #ifdef MULTIPLE_OWNER
index 26d6628..b415cd3 100644 (file)
@@ -1024,4 +1024,135 @@ TEST_F(DoxmComparisonTests, subOwnerMomMismatch)
 
     EXPECT_FALSE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
 }
+
+TEST_F(DoxmComparisonTests, createMom)
+{
+    DoxmTestParameter param1 =
+    {
+        { "oxmType1" },
+        { OIC_JUST_WORKS },
+        OIC_JUST_WORKS,
+        SYMMETRIC_PAIR_WISE_KEY,
+        false,
+        { 0 },    // m_deviceID
+        false,
+        { 0 },    // m_owner
+        {},
+        OIC_MULTIPLE_OWNER_ENABLE,
+        { 0 }     // m_rownerID
+    };
+    GenerateDoxmTestParameterUUIDs(&param1);
+
+    DoxmTestParameter param2 = param1;
+
+    DoxmBinFromParameters(param1, param2);
+
+    OICFreeAndSetToNull(reinterpret_cast<void**>(&m_doxm2->mom));
+
+    OCStackResult result = DoxmUpdateWriteableProperty(m_doxm1, m_doxm2);
+    EXPECT_TRUE(OC_STACK_OK == result);
+
+    EXPECT_TRUE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+}
+
+TEST_F(DoxmComparisonTests, updateMomEnable)
+{
+    DoxmTestParameter param1 =
+    {
+        { "oxmType1" },
+        { OIC_JUST_WORKS },
+        OIC_JUST_WORKS,
+        SYMMETRIC_PAIR_WISE_KEY,
+        false,
+        { 0 },    // m_deviceID
+        false,
+        { 0 },    // m_owner
+        {},
+        OIC_MULTIPLE_OWNER_DISABLE,
+        { 0 }     // m_rownerID
+    };
+    GenerateDoxmTestParameterUUIDs(&param1);
+
+    DoxmTestParameter param2 = param1;
+
+    DoxmBinFromParameters(param1, param2);
+
+    m_doxm1->mom->mode = OIC_MULTIPLE_OWNER_ENABLE;
+
+    EXPECT_FALSE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+
+    OCStackResult result = DoxmUpdateWriteableProperty(m_doxm1, m_doxm2);
+    EXPECT_TRUE(OC_STACK_OK == result);
+
+    EXPECT_TRUE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+}
+
+TEST_F(DoxmComparisonTests, updateMomDisable)
+{
+    DoxmTestParameter param1 =
+    {
+        { "oxmType1" },
+        { OIC_JUST_WORKS },
+        OIC_JUST_WORKS,
+        SYMMETRIC_PAIR_WISE_KEY,
+        false,
+        { 0 },    // m_deviceID
+        false,
+        { 0 },    // m_owner
+        {},
+        OIC_MULTIPLE_OWNER_ENABLE,
+        { 0 }     // m_rownerID
+    };
+    GenerateDoxmTestParameterUUIDs(&param1);
+
+    DoxmTestParameter param2 = param1;
+
+    DoxmBinFromParameters(param1, param2);
+
+    m_doxm1->mom->mode = OIC_MULTIPLE_OWNER_DISABLE;
+
+    EXPECT_FALSE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+
+    OCStackResult result = DoxmUpdateWriteableProperty(m_doxm1, m_doxm2);
+    EXPECT_TRUE(OC_STACK_OK == result);
+
+    EXPECT_TRUE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+}
+
+TEST_F(DoxmComparisonTests, updateMomEnableDisable)
+{
+    DoxmTestParameter param1 =
+    {
+        { "oxmType1" },
+        { OIC_JUST_WORKS },
+        OIC_JUST_WORKS,
+        SYMMETRIC_PAIR_WISE_KEY,
+        false,
+        { 0 },    // m_deviceID
+        false,
+        { 0 },    // m_owner
+        {},
+        OIC_MULTIPLE_OWNER_DISABLE,
+        { 0 }     // m_rownerID
+    };
+    GenerateDoxmTestParameterUUIDs(&param1);
+
+    DoxmTestParameter param2 = param1;
+
+    DoxmBinFromParameters(param1, param2);
+
+    m_doxm1->mom->mode = OIC_MULTIPLE_OWNER_ENABLE;
+
+    OCStackResult result = DoxmUpdateWriteableProperty(m_doxm1, m_doxm2);
+    EXPECT_TRUE(OC_STACK_OK == result);
+
+    EXPECT_TRUE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+
+    m_doxm1->mom->mode = OIC_MULTIPLE_OWNER_DISABLE;
+
+    result = DoxmUpdateWriteableProperty(m_doxm1, m_doxm2);
+    EXPECT_TRUE(OC_STACK_OK == result);
+
+    EXPECT_TRUE(AreDoxmBinPropertyValuesEqual(m_doxm1, m_doxm2));
+}
 #endif // #ifdef MULTIPLE_OWNER