[IOT-2820] make /pstat.dos.p read-only 95/22895/3
authorNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Wed, 18 Oct 2017 05:59:59 +0000 (22:59 -0700)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Thu, 19 Oct 2017 16:47:15 +0000 (16:47 +0000)
The Parameter "p" in the /pstat "dos" Property is meant
to be read-only in every Device Onboarding State.  This
fixes the Update handler to treat "p" as read-only.  It
also fixes the pstat->CBOR marshaling code to provide the
option to omit "p". And it updates the provisioningclient
code to omit "p" from Updates to /pstat.

Change-Id: I25a92bd33e5476d7d5896021e42102762deb6c31
Signed-off-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
resource/csdk/security/include/internal/pstatresource.h
resource/csdk/security/provisioning/src/ownershiptransfermanager.c
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/src/pstatresource.c
resource/csdk/security/unittest/pstatresource.cpp

index 86b3f7c..5d54032 100644 (file)
@@ -71,11 +71,14 @@ OCStackResult DeInitPstatResource();
  * @param propertiesToInclude Array of bools, size "PSTAT_PROPERTY_COUNT",
  * where "true" indicates the corresponding property should be
  * included in the CBOR representation that is created.
+ * @param includeDosP boolean value indicating whether to include
+ * the "dos" Property "p" Parameter (read-only) in the representation.
  *
  * @return ::OC_STACK_OK for Success, otherwise some error value.
  */
  OCStackResult PstatToCBORPayloadPartial(const OicSecPstat_t *pstat,
-       uint8_t **payload, size_t *size, const bool *propertiesToInclude);
+       uint8_t **payload, size_t *size, const bool *propertiesToInclude,
+    const bool includeDosP);
 
 
 /**
index 93eeff3..345f79f 100644 (file)
@@ -2091,7 +2091,7 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
     propertiesToInclude[PSTAT_OM] = true;
 
     OCStackResult res = PstatToCBORPayloadPartial(deviceInfo->pstat, &secPayload->securityData,
-                                           &secPayload->payloadSize, propertiesToInclude);
+                                           &secPayload->payloadSize, propertiesToInclude, false);
    if (OC_STACK_OK != res)
     {
         OCPayloadDestroy((OCPayload *)secPayload);
@@ -2475,7 +2475,7 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
     propertiesToInclude[PSTAT_TM] = true;
 
     if (OC_STACK_OK != PstatToCBORPayloadPartial(otmCtx->selectedDeviceInfo->pstat,
-            &secPayload->securityData, &secPayload->payloadSize, propertiesToInclude))
+            &secPayload->securityData, &secPayload->payloadSize, propertiesToInclude, false))
     {
         OCPayloadDestroy((OCPayload *)secPayload);
         return OC_STACK_INVALID_JSON;
@@ -2540,7 +2540,7 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
     propertiesToInclude[PSTAT_DOS] = true;
 
     if (OC_STACK_OK != PstatToCBORPayloadPartial(otmCtx->selectedDeviceInfo->pstat,
-            &secPayload->securityData, &secPayload->payloadSize, propertiesToInclude))
+            &secPayload->securityData, &secPayload->payloadSize, propertiesToInclude, false))
     {
         OCPayloadDestroy((OCPayload *)secPayload);
         return OC_STACK_INVALID_JSON;
index 8d3a373..cbc1ecc 100644 (file)
@@ -515,7 +515,7 @@ static OCStackApplicationResult ProvisionCredentialDosCB1(void *ctx, OCDoHandle
                 // A second device was not specified. Add the cred to the local cred store.
                 res = ProvisionLocalCredential(ctx, credInfo);
             }
-            
+
             if ((NULL != deviceInfo) || (OC_STACK_OK != res))
             {
                 DeleteCredList(credInfo);
@@ -708,7 +708,7 @@ static OCStackResult ProvisionLocalCredential(void *ctx, OicSecCred_t *cred)
     CredentialData_t *credData = (CredentialData_t *)((Data_t *)ctx)->ctx;
 
     OCStackResult res = AddCredential(cred);
-    
+
     /* Call the result callback directly. */
     registerResultForCredProvisioning(credData, OC_STACK_RESOURCE_CHANGED, DEVICE_LOCAL_FINISHED);
     (credData->resultCallback)(credData->ctx, credData->numOfResults, credData->resArr, false);
@@ -904,7 +904,7 @@ OCStackResult SetDOS(const Data_t *data, OicSecDeviceOnboardingState_t dos,
     propertiesToInclude[PSTAT_DOS] = true;
 
     if (OC_STACK_OK != PstatToCBORPayloadPartial(pstat, &(secPayload->securityData),
-            &(secPayload->payloadSize), propertiesToInclude))
+            &(secPayload->payloadSize), propertiesToInclude, false))
     {
         OCPayloadDestroy((OCPayload *) secPayload);
         OIC_LOG(ERROR, TAG, "Failed to PstatToCBORPayload");
@@ -1422,7 +1422,7 @@ static OCStackApplicationResult ProvisionCertificateCB(void *ctx, OCDoHandle han
     OCCallbackData cbData =  {.context = ctx, .cb = ProvisionCB, .cd = NULL};
     OCDoHandle lHandle = NULL;
 
-    ret = OCDoResource(&lHandle, OC_REST_POST, query, 
+    ret = OCDoResource(&lHandle, OC_REST_POST, query,
                                 &pDev->endpoint, (OCPayload *)secPayload,
                                 pDev->connType, OC_HIGH_QOS, &cbData, NULL, 0);
     OIC_LOG_V(DEBUG, TAG, "POST:%s ret:%d", query, ret);
@@ -1582,7 +1582,7 @@ OCStackResult SRPProvisionCredentials(void *ctx, OicSecCredType_t type, size_t k
 
             OicSecCred_t *firstCred = NULL;
             OicSecCred_t *secondCred = NULL;
-            OCStackResult res = PMGeneratePairWiseCredentials(type, keySize, 
+            OCStackResult res = PMGeneratePairWiseCredentials(type, keySize,
                     &firstDevice->doxm->deviceID, (NULL != secondDevice) ? &secondDevice->doxm->deviceID : &provTooldeviceID,
                     role1, role2,
                     &firstCred, &secondCred);
@@ -3184,7 +3184,7 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
     propertiesToInclude[PSTAT_DOS] = true;
 
     if (OC_STACK_OK != PstatToCBORPayloadPartial(pstat, &(secPayload->securityData),
-                &(secPayload->payloadSize), propertiesToInclude))
+                &(secPayload->payloadSize), propertiesToInclude, false))
     {
         OCPayloadDestroy((OCPayload *) secPayload);
         OIC_LOG(ERROR, TAG, "Failed to PstatToCBORPayload");
index 1d7a213..0ca4920 100644 (file)
@@ -172,7 +172,8 @@ static bool UpdatePersistentStorage(OicSecPstat_t *pstat)
 OCStackResult PstatToCBORPayloadPartial(const OicSecPstat_t *pstat,
                                         uint8_t **payload,
                                         size_t *size,
-                                        const bool *propertiesToInclude)
+                                        const bool *propertiesToInclude,
+                                        const bool includeDosP)
 {
     if (NULL == pstat || NULL == payload || NULL != *payload || NULL == size)
     {
@@ -237,15 +238,18 @@ OCStackResult PstatToCBORPayloadPartial(const OicSecPstat_t *pstat,
         cborEncoderResult = cbor_encode_int(&dosMap, pstat->dos.state);
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding pstat.dos.s value.");
 
-        cborEncoderResult = cbor_encode_text_string(&dosMap, OIC_JSON_P_NAME,
-            strlen(OIC_JSON_P_NAME));
-        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding pstat.dos.p tag.");
+        if (includeDosP)
+        {
+            cborEncoderResult = cbor_encode_text_string(&dosMap, OIC_JSON_P_NAME,
+                strlen(OIC_JSON_P_NAME));
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding pstat.dos.p tag.");
 
-        cborEncoderResult = cbor_encode_boolean(&dosMap, pstat->dos.pending);
-        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding pstat.dos.p value.");
+            cborEncoderResult = cbor_encode_boolean(&dosMap, pstat->dos.pending);
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed adding pstat.dos.p value.");
+        }
 
         cborEncoderResult = cbor_encoder_close_container(&pstatMap, &dosMap);
-        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed closing pstat.dos map");
+            VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed closing pstat.dos map");
     }
 
     // isop Property
@@ -369,7 +373,7 @@ exit:
         // Since the allocated initial memory failed, double the memory.
         cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
         cborEncoderResult = CborNoError;
-        ret = PstatToCBORPayloadPartial(pstat, payload, &cborLen, propertiesToInclude);
+        ret = PstatToCBORPayloadPartial(pstat, payload, &cborLen, propertiesToInclude, includeDosP);
         if (OC_STACK_OK == ret)
         {
             *size = cborLen;
@@ -398,7 +402,7 @@ OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat,
         allProps[i] = true;
     }
 
-    return PstatToCBORPayloadPartial(pstat, payload, size, allProps);
+    return PstatToCBORPayloadPartial(pstat, payload, size, allProps, true);
 }
 
 OCStackResult CBORPayloadToPstat(const uint8_t *cborPayload, const size_t size,
@@ -493,6 +497,10 @@ static OCStackResult CBORPayloadToPstatBin(const uint8_t *cborPayload,
                 }
                 else if (strcmp(dosTagName, OIC_JSON_P_NAME) == 0)
                 {
+                    if (roParsed)
+                    {
+                        *roParsed = true;
+                    }
                     OIC_LOG(DEBUG, TAG, "Found pstat.dos.p tag; getting boolean value.");
                     bool p = false;
                     cborFindResult = cbor_value_get_boolean(&dosMap, &p);
index 8fcc832..ebd5b7b 100644 (file)
@@ -84,7 +84,8 @@ TEST(PstatResourceTest, PstatEntityHandlerWithPostRequest)
                                                       true,    // sm
                                                       true      // rowneruuid
                                                     };
-    EXPECT_EQ(OC_STACK_OK, PstatToCBORPayloadPartial(defaultPstat, &cbor, &size, propertiesToInclude));
+    EXPECT_EQ(OC_STACK_OK, PstatToCBORPayloadPartial(defaultPstat, &cbor, &size,
+        propertiesToInclude, false));
     DeletePstatBinData(defaultPstat);
     ASSERT_TRUE(cbor != NULL);