Workaround for CONPRO-1516 45/217945/1
authorVitalii Irkha <v.irkha@samsung.com>
Tue, 12 Nov 2019 14:21:42 +0000 (16:21 +0200)
committerSudipto Bal <sudipto.bal@samsung.com>
Mon, 18 Nov 2019 02:42:53 +0000 (11:42 +0900)
Added APIs for setting device ID in reset profile

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/602/commits/7ec27b13b5f7e14575f4c96000346ef4b18964dc
(cherry-picked from 7ec27b13b5f7e14575f4c96000346ef4b18964dc)

Change-Id: I815f3847727213fbefb5d4f930a3f08a1a7b9be0
Signed-off-by: Vitalii Irkha <v.irkha@samsung.com>
Signed-off-by: Sudipto Bal <sudipto.bal@samsung.com>
resource/csdk/security/include/internal/doxmresource.h
resource/csdk/security/src/doxmresource.c
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/src/ocstack.c

index 1000f86..f0d8022 100644 (file)
@@ -108,6 +108,12 @@ OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID);
  */
 OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID);
 
+/**
+ * This method sets the device ID for reset profile in PS.
+ * This workaround api related to issue with 0x0 starting Uuid details in [CONPRO-1516].
+ * @return ::OC_STACK_OK for Success, otherwise some error value.
+ */
+OCStackResult SetDoxmDeviceIDResetPF(const OicUuid_t *deviceID);
 
 /**
  * Gets the OicUuid_t value for the owner of this device.
index ee63ffd..c7362fb 100644 (file)
@@ -736,6 +736,156 @@ static bool UpdatePersistentStorage(OicSecDoxm_t * doxm)
     return bRet;
 }
 
+OCStackResult SetDoxmDeviceIDResetPF(const OicUuid_t *deviceID)
+{
+    OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+    OCStackResult res = OC_STACK_ERROR;
+    size_t dbSize = 0;
+    uint8_t *dbData = NULL;
+    uint8_t *aclCbor = NULL;
+    uint8_t *credCbor = NULL;
+    uint8_t *pstatCbor = NULL;
+    uint8_t *doxmCbor = NULL;
+    uint8_t *resetPfCbor = NULL;
+    int64_t cborEncoderResult = CborNoError;
+
+    if (NULL == deviceID)
+    {
+        OIC_LOG_V(ERROR, TAG, "%s - deviceID is NULL!", __func__);
+        return res;
+    }
+
+    res = GetSecureVirtualDatabaseFromPS(NULL, &dbData, &dbSize);
+    if (OC_STACK_OK != res)
+    {
+        OIC_LOG_V(ERROR, TAG, "GetSecureVirtualDatabaseFromPS() is failed(%d)", res);
+        return res;
+    }
+    if (dbData && dbSize)
+    {
+        size_t aclCborLen = 0;
+        size_t credCborLen = 0;
+        size_t pstatCborLen = 0;
+        size_t doxmCborLen = 0;
+        size_t resetPfCborLen = 0;
+        OicSecDoxm_t *tmpDoxm = NULL;
+
+        {
+            CborParser parser;
+            CborValue cbor;
+            cbor_parser_init(dbData, dbSize, 0, &parser, &cbor);
+            CborValue curVal = {0};
+            CborError cborFindResult = CborNoError;
+
+            // abort if reset profile doesn't exist
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_RESET_PF_NAME, &curVal);
+            if (CborNoError != cborFindResult || !cbor_value_is_byte_string(&curVal))
+            {
+                OIC_LOG(DEBUG, TAG, "Reset Profile doesn't exist!");
+                res=OC_STACK_ERROR;
+                goto exit;
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_ACL_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &aclCbor, &aclCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding ACL Name Value.");
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_CRED_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &credCbor, &credCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding CRED Name Value.");
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_PSTAT_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &pstatCbor, &pstatCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding PSTAT Name Value.");
+            }
+            cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_DOXM_NAME, &curVal);
+            if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+            {
+                cborFindResult = cbor_value_dup_byte_string(&curVal, &doxmCbor, &doxmCborLen, NULL);
+                VERIFY_CBOR_SUCCESS(TAG, cborFindResult,  "Failed Finding DOXM Name Value.");
+
+                res = CBORPayloadToDoxm(doxmCbor, doxmCborLen, &tmpDoxm);
+                if (OC_STACK_OK != res)
+                {
+                    OIC_LOG_V(ERROR, TAG, "%s - CBORPayloadToDoxm error : %d", __func__, res);
+                    goto exit;
+                }
+                VERIFY_NON_NULL(TAG, tmpDoxm, ERROR);
+                memcpy(tmpDoxm->deviceID.id, deviceID->id, sizeof(deviceID->id));
+                OICFree(doxmCbor);
+                doxmCbor = NULL;
+                doxmCborLen = 0;
+                res = DoxmToCBORPayload(tmpDoxm, &doxmCbor, &doxmCborLen, false);
+                if (OC_STACK_OK != res || 0 == doxmCborLen || NULL == doxmCbor)
+                {
+                    OIC_LOG_V(ERROR, TAG,"%s - DoxmToCBORPayload error : %d", __func__, res);
+                    goto exit;
+                }
+            }
+        }
+
+        {
+            size_t size = aclCborLen + credCborLen + pstatCborLen + doxmCborLen + 255;
+            resetPfCbor = (uint8_t *) OICCalloc(1, size);
+            VERIFY_NON_NULL(TAG, resetPfCbor, ERROR);
+            CborEncoder encoder;  // will be initialized in |cbor_parser_init|
+            cbor_encoder_init(&encoder, resetPfCbor, size, 0);
+            CborEncoder secRsrc;  // will be initialized in |cbor_encoder_create_map|
+            cborEncoderResult |= cbor_encoder_create_map(&encoder, &secRsrc, CborIndefiniteLength);
+
+            cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_ACL_NAME, strlen(OIC_JSON_ACL_NAME));
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Name.");
+            cborEncoderResult |= cbor_encode_byte_string(&secRsrc, aclCbor, aclCborLen);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Value.");
+
+            if (credCborLen)
+            {
+                cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_CRED_NAME, strlen(OIC_JSON_CRED_NAME));
+                VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Name.");
+                cborEncoderResult |= cbor_encode_byte_string(&secRsrc, credCbor, credCborLen);
+                VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Value.");
+            }
+
+            cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_PSTAT_NAME, strlen(OIC_JSON_PSTAT_NAME));
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Name.");
+            cborEncoderResult |= cbor_encode_byte_string(&secRsrc, pstatCbor, pstatCborLen);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Value.");
+
+            cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_DOXM_NAME, strlen(OIC_JSON_DOXM_NAME));
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Name.");
+            cborEncoderResult |= cbor_encode_byte_string(&secRsrc, doxmCbor, doxmCborLen);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Value.");
+
+            cborEncoderResult |= cbor_encoder_close_container(&encoder, &secRsrc);
+            VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Array.");
+            resetPfCborLen = cbor_encoder_get_buffer_size(&encoder, resetPfCbor);
+        }
+
+        res = UpdateSecureResourceInPS(OIC_JSON_RESET_PF_NAME, resetPfCbor, resetPfCborLen);
+        if (OC_STACK_OK != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "%s - Error in UpdateSecureResourceInPS", __func__);
+        }
+    }
+    OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+
+exit:
+    OICFree(dbData);
+    OICFree(aclCbor);
+    OICFree(credCbor);
+    OICFree(pstatCbor);
+    OICFree(doxmCbor);
+    OICFree(resetPfCbor);
+
+    return res;
+}
+
 static bool ValidateQuery(const char * query)
 {
     // Send doxm resource data if the state of doxm resource
index a1f5cd2..0ebe590 100755 (executable)
@@ -764,6 +764,14 @@ OCStackResult OCGetDeviceId(OCUUIdentity *deviceId);
  */
 OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId);
 
+/**
+ * sets the Doxm deviceId for ResetPF in PS
+ *
+ * @param deviceId pointer.
+ * @return Returns ::OC_STACK_OK if success.
+ */
+OCStackResult OCSetDeviceIdResetPF(const OCUUIdentity *deviceId);
+
  /**
  * Gets the bool state of "isOwned" property on the doxm resource.
  *
index 5f94a12..754756b 100644 (file)
@@ -5643,6 +5643,26 @@ OCStackResult OCSetDeviceId(const OCUUIdentity *deviceId)
     return ret;
 }
 
+OCStackResult OCSetDeviceIdResetPF(const OCUUIdentity *deviceId)
+{
+    OicUuid_t oicUuid;
+    OCStackResult ret = OC_STACK_ERROR;
+
+    memcpy(&oicUuid, deviceId, UUID_LENGTH);
+    char *strUuid = NULL;
+    if (OC_STACK_OK == ConvertUuidToStr(&oicUuid, &strUuid))
+    {
+        OIC_LOG_V(INFO, TAG, "%s: deviceId : %s" ,__func__, strUuid);
+        OICFree(strUuid);
+    }
+    else
+    {
+        OIC_LOG(DEBUG, TAG, "Can't convert  deviceId to string");
+    }
+    ret = SetDoxmDeviceIDResetPF(&oicUuid);
+    return ret;
+}
+
 OCStackResult OCGetDeviceOwnedState(bool *isOwned)
 {
     bool isDeviceOwned = true;