[IOT-2052] Update to support OCF 1.0 85/24385/3
authorv.riznyk <v.riznyk@samsung.com>
Tue, 13 Mar 2018 16:13:58 +0000 (18:13 +0200)
committerAleksey Volkov <a.volkov@samsung.com>
Thu, 22 Mar 2018 16:19:58 +0000 (16:19 +0000)
Update Acl recource with adding partial generating CBOR.

Change-Id: I03853040433e091ecb99daa559e12cd37496b7ad
Signed-off-by: v.riznyk <v.riznyk@samsung.com>
resource/csdk/security/include/internal/aclresource.h
resource/csdk/security/provisioning/src/secureresourceprovider.c
resource/csdk/security/src/aclresource.c

index 01880af..663f972 100644 (file)
 extern "C" {
 #endif
 
+typedef enum {
+    ACL_ACELIST = 0,
+    ACL_ROWNERUUID,
+    ACL_PROPERTY_COUNT
+} ACLProperty_t;
+
 /**
  * Initialize ACL resource by loading data from persistent storage.
  *
@@ -90,6 +96,22 @@ const OicSecAce_t* GetACLResourceDataByConntype(const OicSecConntype_t conntype,
  */
 OCStackResult AclToCBORPayload(const OicSecAcl_t *acl, OicSecAclVersion_t aclVersion, uint8_t **outPayload, size_t *size);
 
+/**
+ * This function converts ACL data into CBOR format, including only the
+ * Properties marked "true" in the propertiesToInclude array.
+ *
+ * @param acl instance of @ref OicSecAcl_t structure.
+ * @param aclVersion Version of ACL resource to produce; can be OIC_SEC_ACL_V1 or OIC_SEC_ACL_V2
+ * @param outPayload is the pointer to allocated memory for cbor payload.
+ * @param size of the cbor payload.
+ * @param propertyToInclude Array of bools, size "ACL_PROPERTY_COUNT",
+ * where "true" indicates the corresponding property should be
+ * included in the CBOR representation that is created.
+ *
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult AclToCBORPayloadPartial(const OicSecAcl_t *acl, OicSecAclVersion_t aclVersion, uint8_t **outPayload, size_t *size, const bool *propertyToInclude);
+
 #ifdef MULTIPLE_OWNER
 /**
  * Function to check the ACL access of SubOwner
index c51d746..c05c688 100644 (file)
@@ -4019,11 +4019,14 @@ static OCStackApplicationResult ProvisionAclCB(void *ctx, OCDoHandle UNUSED,
             return OC_STACK_NO_MEMORY;
         }
         secPayload->base.type = PAYLOAD_TYPE_SECURITY;
-        if (OC_STACK_OK != AclToCBORPayload(aclData->acl, aclData->aclVersion, &secPayload->securityData,
-                                            &secPayload->payloadSize))
+        bool propertiesToInclude[PSTAT_PROPERTY_COUNT];
+        memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
+        propertiesToInclude[ACL_ACELIST] = true;
+        if (OC_STACK_OK != AclToCBORPayloadPartial(aclData->acl, aclData->aclVersion, &secPayload->securityData,
+                                            &secPayload->payloadSize, propertiesToInclude))
         {
             OCPayloadDestroy((OCPayload *)secPayload);
-            OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayload");
+            OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayloadPartial");
             OIC_LOG_V(ERROR, TAG, "OUT %s", __func__);
             return OC_STACK_NO_MEMORY;
         }
index ac9b77e..34488da 100644 (file)
@@ -363,9 +363,21 @@ static size_t OicSecAclSize(const OicSecAcl_t *secAcl)
     }
     return size;
 }
-
 OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl,
     OicSecAclVersion_t aclVersion, uint8_t **payload, size_t *size)
+    {
+        bool allProps[ACL_PROPERTY_COUNT];
+
+        for (int i = 0; i < ACL_PROPERTY_COUNT; i++)
+        {
+            allProps[i] = true;
+        }
+        return AclToCBORPayloadPartial(secAcl, aclVersion, payload, size, allProps);
+
+    }
+
+OCStackResult AclToCBORPayloadPartial(const OicSecAcl_t *secAcl,
+    OicSecAclVersion_t aclVersion, uint8_t **payload, size_t *size, const bool *propertiesToInclude)
 {
     if (NULL == secAcl || NULL == payload || NULL != *payload || NULL == size)
     {
@@ -412,11 +424,13 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl,
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     // Create ACL Map which contains aclist or aclist2, rowneruuid, rt and if
-    cborEncoderResult = cbor_encoder_create_map(&encoder, &aclMap, ACL_MAP_SIZE);
-    VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Creating ACL Map.");
-    OIC_LOG_V(DEBUG, TAG, "%s starting encoding of %s resource.",
-        __func__, (OIC_SEC_ACL_V1 == aclVersion)?"v1 acl":"v2 acl2");
-
+    if(propertiesToInclude[ACL_ACELIST])
+    {
+        cborEncoderResult = cbor_encoder_create_map(&encoder, &aclMap, ACL_MAP_SIZE);
+        VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Creating ACL Map.");
+        OIC_LOG_V(DEBUG, TAG, "%s starting encoding of %s resource.",
+            __func__, (OIC_SEC_ACL_V1 == aclVersion)?"v1 acl":"v2 acl2");
+    
     // v1 uses "aclist" as the top-level tag, containing an "aces" object
     if (OIC_SEC_ACL_V1 == aclVersion)
     {
@@ -975,8 +989,10 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl,
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Closing aclist/aclist2 Map.");
         OIC_LOG_V(DEBUG, TAG, "%s closed v1/v2 aclist/aclist2 map.", __func__);
     }
+    }
 
     // Rownerid
+    if(propertiesToInclude[ACL_ROWNERUUID])
     {
         char *rowner = NULL;
         cborEncoderResult = cbor_encode_text_string(&aclMap, OIC_JSON_ROWNERID_NAME,
@@ -1040,7 +1056,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl,
 
     if (CborNoError == cborEncoderResult)
     {
-        OIC_LOG(DEBUG, TAG, "AclToCBORPayload Succeeded");
+        OIC_LOG(DEBUG, TAG, "AclToCBORPayloadPartial Succeeded");
         *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
         *payload = outPayload;
         ret = OC_STACK_OK;
@@ -1048,19 +1064,19 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl,
 exit:
     if (CborErrorOutOfMemory == cborEncoderResult)
     {
-        OIC_LOG(DEBUG, TAG, "AclToCBORPayload:CborErrorOutOfMemory : retry with more memory");
+        OIC_LOG(DEBUG, TAG, "AclToCBORPayloadPartial:CborErrorOutOfMemory : retry with more memory");
 
         // reallocate and try again!
         OICFree(outPayload);
         // Since the allocated initial memory failed, double the memory.
         cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
         cborEncoderResult = CborNoError;
-        ret = AclToCBORPayload(secAcl, aclVersion, payload, &cborLen);
+        ret = AclToCBORPayloadPartial(secAcl, aclVersion, payload, &cborLen, propertiesToInclude);
         *size = cborLen;
     }
     else if (cborEncoderResult != CborNoError)
     {
-        OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayload");
+        OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayloadPartial");
         OICFree(outPayload);
         outPayload = NULL;
         *size = 0;