Commit 9b4bfc9c authored by Randeep's avatar Randeep

Fixed to prevent a UPDATE request on read-only property

Fix doxm and pstat resource handler in order to prevent the modification on read-only properties.

Patch #1: Initial patch
Patch #2: Fix Ownership Transfer fail
Patch #4: Rebased to latest 1.1-rel
Patch #5: Rebase
Patch #6: Fix on CT fail during Ownership Transfering as well as gerrit comments
Patch #7: Fix on CT fail
Patch #8: Fixed arduino build error

- CAUTION - : DO NOT Merge this patch before completing tests.

Change-Id: Ie709ac0023aeec979de0de545a10ec165c0b5278
Signed-off-by: default avatarJongmin Choi <jminl.choi@samsung.com>
Signed-off-by: default avatarChul Lee <chuls.lee@samsung.com>
Signed-off-by: default avatarJoonghwan Lee <jh05.lee@samsung.com>
Signed-off-by: default avatarJongmin Choi <jminl.choi@samsung.com>
Signed-off-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9249
parent ccde381b
......@@ -72,11 +72,12 @@ OCStackResult CBORPayloadToDoxm(const uint8_t *cborPayload, size_t size,
* @note Caller needs to invoke OCFree after done using the return pointer.
* @param cborPayload is the payload of the cbor.
* @param cborSize is the size of the cbor payload. Passed parameter should not be NULL.
* @param rwOnly indicates whether convertingpayload has all properties or read-write properties only.
*
* @return ::OC_STACK_OK for Success, otherwise some error value.
*/
OCStackResult DoxmToCBORPayload(const OicSecDoxm_t * doxm, uint8_t **cborPayload,
size_t *cborSize);
size_t *cborSize, bool rwOnly);
/**
* This method returns the SRM device ID for this device.
......
......@@ -50,7 +50,7 @@ OCStackResult DeInitPstatResource();
* @return ::OC_STACK_OK for Success, otherwise some error value.
*/
OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat, uint8_t **cborPayload,
size_t *cborSize);
size_t *cborSize, bool writableOnly);
/**
* This method converts cbor into PSTAT data.
......
......@@ -1202,7 +1202,7 @@ static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm,
&secPayload->securityData, &secPayload->payloadSize);
&secPayload->securityData, &secPayload->payloadSize, true);
if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
OCPayloadDestroy((OCPayload *)secPayload);
......@@ -1256,7 +1256,7 @@ static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = PstatToCBORPayload(deviceInfo->pstat, &secPayload->securityData,
&secPayload->payloadSize);
&secPayload->payloadSize, true);
if (OC_STACK_OK != res)
{
OCPayloadDestroy((OCPayload *)secPayload);
......@@ -1447,7 +1447,7 @@ OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData, &secPayload->payloadSize))
&secPayload->securityData, &secPayload->payloadSize, true))
{
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON;
......@@ -1505,7 +1505,7 @@ OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData, &secPayload->payloadSize))
&secPayload->securityData, &secPayload->payloadSize, true))
{
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON;
......
......@@ -43,7 +43,7 @@ OCStackResult CreateJustWorksSelectOxmPayload(OTMContext_t *otmCtx, uint8_t **pa
*payload = NULL;
*size = 0;
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size);
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size, true);
}
OCStackResult CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx, uint8_t **payload, size_t *size)
......@@ -65,7 +65,7 @@ OCStackResult CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx, uint8_t
*payload = NULL;
*size = 0;
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size);
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size, true);
}
OCStackResult LoadSecretJustWorksCallback(OTMContext_t* UNUSED_PARAM)
......
......@@ -47,7 +47,7 @@ OCStackResult CreatePinBasedSelectOxmPayload(OTMContext_t* otmCtx, uint8_t **pay
otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_RANDOM_DEVICE_PIN;
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size);
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size, true);
}
OCStackResult CreatePinBasedOwnerTransferPayload(OTMContext_t* otmCtx, uint8_t **payload, size_t *size)
......@@ -68,7 +68,7 @@ OCStackResult CreatePinBasedOwnerTransferPayload(OTMContext_t* otmCtx, uint8_t *
}
memcpy(otmCtx->selectedDeviceInfo->doxm->owner.id, uuidPT.id , UUID_LENGTH);
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size);
return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size, true);
}
OCStackResult InputPinCodeCallback(OTMContext_t *otmCtx)
......
This diff is collapsed.
......@@ -126,11 +126,19 @@ static bool IsRequestFromDevOwner(PEContext_t *context)
return retVal;
}
/*
if(OC_STACK_OK == GetDoxmDevOwnerId(&ownerid))
{
retVal = UuidCmp(&context->subject, &ownerid);
}
*/
// TODO: Added as workaround for CTT
OicSecDoxm_t* doxm = (OicSecDoxm_t*) GetDoxmResourceData();
if (doxm)
{
retVal = UuidCmp(&doxm->owner, &context->subject);
}
return retVal;
}
......
This diff is collapsed.
......@@ -141,7 +141,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName
{
OicSecPstat_t *pstat = JSONToPstatBin(jsonStr);
VERIFY_NON_NULL(TAG, pstat, FATAL);
ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize);
ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize, false);
if(OC_STACK_OK != ret)
{
OIC_LOG (ERROR, TAG, "Failed converting Pstat to Cbor Payload");
......@@ -157,7 +157,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName
{
OicSecDoxm_t *doxm = JSONToDoxmBin(jsonStr);
VERIFY_NON_NULL(TAG, doxm, FATAL);
ret = DoxmToCBORPayload(doxm, &doxmCbor, &doxmCborSize);
ret = DoxmToCBORPayload(doxm, &doxmCbor, &doxmCborSize, false);
if(OC_STACK_OK != ret)
{
OIC_LOG (ERROR, TAG, "Failed converting Doxm to Cbor Payload");
......
......@@ -143,10 +143,10 @@ TEST(DoxmResourceTest, DoxmToCBORPayloadNULL)
OicSecDoxm_t *doxm = getBinDoxm();
size_t size = 10;
uint8_t *payload = NULL;
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(NULL, NULL, 0));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(doxm, NULL, &size));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(doxm, &payload, 0));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(NULL, &payload, &size));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(NULL, NULL, 0, false));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(doxm, NULL, &size, false));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(doxm, &payload, 0, false));
EXPECT_EQ(OC_STACK_INVALID_PARAM, DoxmToCBORPayload(NULL, &payload, &size, false));
DeleteDoxmBinData(doxm);
}
......@@ -156,7 +156,7 @@ TEST(DoxmResourceTest, DoxmToCBORPayloadVALID)
uint8_t *payload = NULL;
size_t size = 0;
EXPECT_EQ(OC_STACK_OK, DoxmToCBORPayload(doxm, &payload, &size));
EXPECT_EQ(OC_STACK_OK, DoxmToCBORPayload(doxm, &payload, &size, false));
EXPECT_TRUE(payload != NULL);
DeleteDoxmBinData(doxm);
......@@ -181,7 +181,7 @@ TEST(DoxmResourceTest, CBORPayloadToDoxmVALID)
OicSecDoxm_t *doxm = getBinDoxm();
uint8_t *payload = NULL;
size_t size = 0;
EXPECT_EQ(OC_STACK_OK, DoxmToCBORPayload(doxm, &payload, &size));
EXPECT_EQ(OC_STACK_OK, DoxmToCBORPayload(doxm, &payload, &size, false));
EXPECT_TRUE(payload != NULL);
OicSecDoxm_t *doxmSec = NULL;
......
......@@ -74,7 +74,7 @@ TEST(PstatResourceTest, PstatEntityHandlerWithPostRequest)
defaultPstat->sm[0] = (OicSecDpom_t) 3;
size_t size = 0;
uint8_t *cbor = NULL;
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(defaultPstat, &cbor, &size));
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(defaultPstat, &cbor, &size, true));
DeletePstatBinData(defaultPstat);
ASSERT_TRUE(cbor != NULL);
......@@ -93,20 +93,20 @@ TEST(PstatResourceTest, PstatEntityHandlerInvalidRequest)
TEST(PstatResourceTest, PstatToCBORPayloadNULL)
{
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, NULL, 0));
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, NULL, 0, false));
// Case when cbor payload is NULL
OicSecPstat_t pstat;
size_t size = 10;
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, NULL, &size));
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, NULL, &size, false));
uint8_t *cborPayload = (uint8_t *) OICCalloc(1, size);
ASSERT_TRUE(NULL != cborPayload);
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, &size));
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, &size, false));
OICFree(cborPayload);
cborPayload = NULL;
// Case when pstat is zero.
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, &cborPayload, &size));
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(NULL, &cborPayload, &size, false));
// Case when size is 0.
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, 0));
EXPECT_EQ(OC_STACK_INVALID_PARAM, PstatToCBORPayload(&pstat, &cborPayload, 0, false));
OICFree(cborPayload);
}
......@@ -133,7 +133,7 @@ TEST(PstatResourceTest, PstatToCBORPayloadAndCBORPayloadToPstat)
size_t size = 0;
uint8_t *cbor = NULL;
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(&pstat, &cbor, &size));
EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(&pstat, &cbor, &size, false));
if (!cbor)
{
OICFree(pstat.sm);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment