Commit 5fdb8a11 authored by akk0rd's avatar akk0rd Committed by Nathan Heldt-Sheller

[IOT-2826][IOT-2851]dat file with zero rownerid

Fixed false generating dat file, added wrapper functions with rowner parameter

Change-Id: Ia8badb9b0b78de5f620f8dbad6f070c1276ebf74
Signed-off-by: default avatarakk0rd <v.riznyk@samsung.com>
parent 89370a69
......@@ -72,7 +72,8 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId);
/**
* This function converts credential data into CBOR format.
* Caller needs to invoke 'free' when done using returned string.
* Caller needs to invoke 'OICFree' when done using returned string.
* Wrapper over the CredToCBORPayloadWithRowner.
*
* @param cred is the pointer to instance of OicSecCred_t structure.
* @param cborPayload is the CBOR converted value.
......@@ -84,6 +85,22 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId);
OCStackResult CredToCBORPayload(const OicSecCred_t* cred, uint8_t **cborPayload,
size_t *cborSize, int secureFlag);
/**
* This function converts credential data into CBOR format.
* Caller needs to invoke 'OICFree' when done using returned string.
*
* @param cred is the pointer to instance of OicSecCred_t structure.
* @param rownerId resource owner's UUID
* @param cborPayload is the CBOR converted value.
* @param cborSize is the size of the CBOR.
* @param secureFlag shows fill or not private key.
*
* @return ::OC_STACK_OK if conversion is successful, else ::OC_STACK_ERROR if unsuccessful.
*/
OCStackResult CredToCBORPayloadWithRowner(const OicSecCred_t *credS, const OicUuid_t *rownerId, uint8_t **cborPayload,
size_t *cborSize, int secureFlag);
#ifdef MULTIPLE_OWNER
/**
* Function to check the credential access of SubOwner
......
......@@ -655,7 +655,7 @@ static void logCredMetadata()
#endif
}
OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload,
OCStackResult CredToCBORPayloadWithRowner(const OicSecCred_t *credS, const OicUuid_t *rownerId, uint8_t **cborPayload,
size_t *cborSize, int secureFlag)
{
OIC_LOG_V(DEBUG, TAG, "IN %s:", __func__);
......@@ -890,7 +890,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload
cborEncoderResult = cbor_encode_text_string(&credRootMap, OIC_JSON_ROWNERID_NAME,
strlen(OIC_JSON_ROWNERID_NAME));
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Adding rownerid Name.");
ret = ConvertUuidToStr(&gRownerId, &rowner);
ret = ConvertUuidToStr(rownerId, &rowner);
VERIFY_SUCCESS(TAG, ret == OC_STACK_OK, ERROR);
cborEncoderResult = cbor_encode_text_string(&credRootMap, rowner, strlen(rowner));
VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, cborEncoderResult, "Failed Addding rownerid Value.");
......@@ -971,6 +971,13 @@ exit:
return ret;
}
OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload,
size_t *cborSize, int secureFlag)
{
return CredToCBORPayloadWithRowner(credS, &gRownerId, cborPayload, cborSize, secureFlag);
}
OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
OicSecCred_t **secCred, OicUuid_t **rownerid)
{
......@@ -1462,7 +1469,7 @@ static bool UpdatePersistentStorage(const OicSecCred_t *cred)
OIC_LOG_V(DEBUG, TAG, "cred size: %zu", size);
int secureFlag = 0;
OCStackResult res = CredToCBORPayload(cred, &payload, &size, secureFlag);
OCStackResult res = CredToCBORPayloadWithRowner(cred, &gRownerId, &payload, &size, secureFlag);
#ifdef HAVE_WINDOWS_H
/* On Windows, keep the credential resource encrypted on disk to protect symmetric and private keys. Only the
* current user on this system will be able to decrypt it later, to help prevent credential theft.
......@@ -2421,7 +2428,7 @@ static OCEntityHandlerResult HandleGetRequest (const OCEntityHandlerRequest * eh
// This added '256' is arbitrary value that is added to cover the name of the resource, map addition and ending
size = GetCredKeyDataSize(cred);
size += (256 * OicSecCredCount(cred));
OCStackResult res = CredToCBORPayload(cred, &payload, &size, secureFlag);
OCStackResult res = CredToCBORPayloadWithRowner(cred, &gRownerId, &payload, &size, secureFlag);
// A device should always have a default cred. Therefore, payload should never be NULL.
OCEntityHandlerResult ehRet = (res == OC_STACK_OK) ? OC_EH_OK : OC_EH_ERROR;
......
......@@ -54,7 +54,7 @@ static OicSecDoxm_t *JSONToDoxmBin(const char *jsonStr);
static OicSecAcl_t *JSONToAclBin(OicSecAclVersion_t *aclVersion,
const char *jsonStr);
static OicSecAmacl_t *JSONToAmaclBin(const char *jsonStr);
static OicSecCred_t *JSONToCredBin(const char *jsonStr);
static OicSecCred_t *JSONToCredBinWithRowner(const char *jsonStr,OicUuid_t *rownerId);
static OCDeviceProperties *JSONToDPBin(const char *jsonStr);
static size_t GetJSONFileSize(const char *jsonFileName)
......@@ -419,7 +419,8 @@ static OCStackResult ConvertOCJSONStringToCBORFile(const char *jsonStr, const ch
int secureFlag = 0;
if (NULL != value)
{
OicSecCred_t *cred = JSONToCredBin(jsonStr);
OicUuid_t rownerId;
OicSecCred_t *cred = JSONToCredBinWithRowner(jsonStr,&rownerId);
VERIFY_NOT_NULL(TAG, cred, FATAL);
// The source code line below is just a workaround for IOT-2407.
// It should be deleted when IOT-2407 gets fixed. There is no clear
......@@ -427,7 +428,7 @@ static OCStackResult ConvertOCJSONStringToCBORFile(const char *jsonStr, const ch
// CredToCBORPayload happens to work better when initializing
// credCborSize this way.
credCborSize = strlen(jsonStr);
ret = CredToCBORPayload(cred, &credCbor, &credCborSize, secureFlag);
ret = CredToCBORPayloadWithRowner(cred, &rownerId,&credCbor, &credCborSize, secureFlag);
if (OC_STACK_OK != ret)
{
OIC_LOG (ERROR, TAG, "Failed converting Cred to Cbor Payload");
......@@ -1165,7 +1166,7 @@ static OicEncodingType_t GetEncodingTypeFromStr(const char *encodingType)
return OIC_ENCODING_RAW;
}
OicSecCred_t *JSONToCredBin(const char *jsonStr)
static OicSecCred_t *JSONToCredBinWithRowner(const char *jsonStr,OicUuid_t *rownerId)
{
if (NULL == jsonStr)
{
......@@ -1357,13 +1358,13 @@ OicSecCred_t *JSONToCredBin(const char *jsonStr)
}
// rownerid
/* cJSON *jsonCredObj = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_ROWNERID_NAME);
cJSON *jsonCredObj = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_ROWNERID_NAME);
VERIFY_NOT_NULL(TAG, jsonCredObj, ERROR);
VERIFY_SUCCESS(TAG, cJSON_String == jsonCredObj->type, ERROR);
ret = ConvertStrToUuid(jsonCredObj->valuestring, &headCred->rownerID);
ret = ConvertStrToUuid(jsonCredObj->valuestring, rownerId);
VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
ret = OC_STACK_OK;
*/
exit:
cJSON_Delete(jsonRoot);
if (OC_STACK_OK != ret)
......
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