Commit 7739d42c authored by Ashwini Kumar's avatar Ashwini Kumar Committed by Randeep

Security CBOR cleanup

 - removed duplicate changes introduced for Security CBOR conversion
 - Fixed pstat double free error
 - Fixed crl double free
 - Addressed review comments from Habib, Saurabh
 - Addressed review commenst from Chul and removed compile warnings for CRL
   oxm manager
 - Fixed unittests, C++ examples to use .dat files for SVRs
 - modified tizen .spec to install .dat files
 - fixed svace static analysis issues

Change-Id: I638a247875c2b01f0207557fade3893dc363df5b
Signed-off-by: default avatarAshwini Kumar <k.ashwini@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7395Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarChul Lee <chuls.lee@samsung.com>
Reviewed-by: default avatarYonggoo Kang <ygace.kang@samsung.com>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent 5158e505
......@@ -49,10 +49,11 @@ OCStackResult DestroySecureResources();
* @param ehRequest pointer to entity handler request data structure.
* @param ehRet result code from entity handler.
* @param cborPayload response payload.
* @param size is the cborpayload size
*
* @return ::OC_STACK_OK for Success, otherwise some error value.
*/
OCStackResult SendSRMCBORResponse(const OCEntityHandlerRequest *ehRequest,
OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
OCEntityHandlerResult ehRet, uint8_t *cborPayload, size_t size);
#ifdef __cplusplus
......
......@@ -68,12 +68,6 @@
*/
static OTMCallbackData_t g_OTMDatas[OIC_OXM_COUNT];
/**
* Number of supported provisioning methods
* current version supports only one.
*/
static size_t gNumOfProvisioningMethodsPT = 1;
/**
* Variables for pointing the OTMContext to be used in the DTLS handshake result callback.
*/
......@@ -521,10 +515,10 @@ static OCStackApplicationResult ListMethodsHandler(void *ctx, OCDoHandle UNUSED,
}
OicSecPstat_t* pstat = NULL;
OCStackResult result = CBORPayloadToPstat(
((OCSecurityPayload*)clientResponse->payload)->securityData1,
((OCSecurityPayload*)clientResponse->payload)->securityData,
((OCSecurityPayload*)clientResponse->payload)->payloadSize,
&pstat);
if(NULL == pstat && result != OC_STACK_OK)
if(NULL == pstat || result != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "Error while converting cbor to pstat.");
SetResult(otmCtx, OC_STACK_ERROR);
......@@ -941,7 +935,7 @@ static OCStackResult PutOwnerCredential(OTMContext_t* otmCtx)
//Generate owner credential for new device
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OicSecCred_t* ownerCredential = GetCredResourceData(&(deviceInfo->doxm->deviceID));
const OicSecCred_t* ownerCredential = GetCredResourceData(&(deviceInfo->doxm->deviceID));
if(!ownerCredential)
{
OIC_LOG(ERROR, TAG, "Can not find OwnerPSK.");
......@@ -967,13 +961,14 @@ static OCStackResult PutOwnerCredential(OTMContext_t* otmCtx)
#endif
//Send owner credential to new device : PUT /oic/sec/cred [ owner credential ]
if (OC_STACK_OK != CredToCBORPayload(&newCredential, &secPayload->securityData1, &secPayload->payloadSize))
if (OC_STACK_OK != CredToCBORPayload(&newCredential, &secPayload->securityData, &secPayload->payloadSize))
{
OICFree(secPayload);
OIC_LOG(ERROR, TAG, "Error while converting bin to cbor.");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Payload : %s", secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Cred Payload:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
OCCallbackData cbData;
cbData.cb = &OwnerCredentialHandler;
......@@ -1029,8 +1024,8 @@ static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = g_OTMDatas[selectedOxm].createSelectOxmPayloadCB(otmCtx,
&secPayload->securityData1, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData1)
&secPayload->securityData, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Error while converting bin to cbor");
......@@ -1123,14 +1118,14 @@ static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = g_OTMDatas[deviceInfo->doxm->oxmSel].createOwnerTransferPayloadCB(
otmCtx, &secPayload->securityData1, &secPayload->payloadSize);
if (NULL == secPayload->securityData1)
otmCtx, &secPayload->securityData, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Error while converting doxm bin to cbor.");
return OC_STACK_INVALID_PARAM;
}
OIC_LOG_V(DEBUG, TAG, "Payload : %s", secPayload->securityData1);
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
OCCallbackData cbData;
cbData.cb = &OwnerUuidUpdateHandler;
......@@ -1183,8 +1178,8 @@ static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx)
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm,
&secPayload->securityData1, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData1)
&secPayload->securityData, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Error while converting doxm bin to json");
......@@ -1236,7 +1231,7 @@ static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx)
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = PstatToCBORPayload(deviceInfo->pstat, &secPayload->securityData1,
OCStackResult res = PstatToCBORPayload(deviceInfo->pstat, &secPayload->securityData,
&secPayload->payloadSize);
if (OC_STACK_OK != res)
{
......@@ -1407,122 +1402,6 @@ error:
return res;
}
/**
* Callback handler of SRPFinalizeProvisioning.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult FinalizeProvisioningCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "IN FinalizeProvisioningCB.");
VERIFY_NON_NULL(TAG, clientResponse, ERROR);
VERIFY_NON_NULL(TAG, ctx, ERROR);
OTMContext_t* otmCtx = (OTMContext_t*)ctx;
(void)UNUSED;
if(OC_STACK_OK == clientResponse->result)
{
OCStackResult res = PDMAddDevice(&otmCtx->selectedDeviceInfo->doxm->deviceID);
if (OC_STACK_OK == res)
{
OIC_LOG_V(INFO, TAG, "Add device's UUID in PDM_DB");
SetResult(otmCtx, OC_STACK_OK);
return OC_STACK_DELETE_TRANSACTION;
}
else
{
OIC_LOG(ERROR, TAG, "Ownership transfer is complete but adding information to DB is failed.");
}
}
exit:
return OC_STACK_DELETE_TRANSACTION;
}
/**
* Callback handler of default ACL provisioning.
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @param[in] clientResponse Response from queries to remote servers.
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
static OCStackApplicationResult ProvisionDefaultACLCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
OIC_LOG_V(INFO, TAG, "IN ProvisionDefaultACLCB.");
VERIFY_NON_NULL(TAG, clientResponse, ERROR);
VERIFY_NON_NULL(TAG, ctx, ERROR);
OTMContext_t* otmCtx = (OTMContext_t*) ctx;
(void)UNUSED;
if (OC_STACK_RESOURCE_CREATED == clientResponse->result)
{
OIC_LOG_V(INFO, TAG, "Staring commit hash task.");
// TODO hash currently have fixed value 0.
uint16_t aclHash = 0;
otmCtx->selectedDeviceInfo->pstat->commitHash = aclHash;
otmCtx->selectedDeviceInfo->pstat->tm = NORMAL;
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData1, &secPayload->payloadSize);
if (OC_STACK_OK != res || NULL == secPayload->securityData1)
{
OICFree(secPayload);
SetResult(otmCtx, OC_STACK_INVALID_JSON);
return OC_STACK_DELETE_TRANSACTION;
}
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
otmCtx->selectedDeviceInfo->endpoint.addr,
otmCtx->selectedDeviceInfo->securePort,
otmCtx->selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
OIC_LOG(ERROR, TAG, "ProvisionDefaultACLCB : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &FinalizeProvisioningCB;
cbData.context = (void*)otmCtx;
cbData.cd = NULL;
OCStackResult ret = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
if (ret != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
SetResult(otmCtx, ret);
}
}
else
{
OIC_LOG_V(INFO, TAG, "Error occured in provisionDefaultACLCB :: %d\n",
clientResponse->result);
SetResult(otmCtx, clientResponse->result);
}
exit:
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
{
OIC_LOG(INFO, TAG, "IN PutProvisioningStatus");
......@@ -1544,12 +1423,13 @@ OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData1, &secPayload->payloadSize))
&secPayload->securityData, &secPayload->payloadSize))
{
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON;
}
OIC_LOG_V(INFO, TAG, "Created payload for chage to Provisiong state : %s",secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Created payload for chage to Provisiong state");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
......@@ -1601,12 +1481,13 @@ OCStackResult PutNormalOperationStatus(OTMContext_t* otmCtx)
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
&secPayload->securityData1, &secPayload->payloadSize))
&secPayload->securityData, &secPayload->payloadSize))
{
OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON;
}
OIC_LOG_V(INFO, TAG, "Created payload for chage to Provisiong state: %s",secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Created payload for chage to Provisiong state");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
......
......@@ -515,8 +515,9 @@ static OCStackApplicationResult SecurityVersionDiscoveryHandler(void *ctx, OCDoH
}
OicSecVer_t *ptrVer = NULL;
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData1;
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
OCStackResult res = CBORPayloadToVer(payload, size, &ptrVer);
if ((NULL == ptrVer) && (OC_STACK_OK != res))
{
......@@ -653,10 +654,11 @@ static OCStackApplicationResult DeviceDiscoveryHandler(void *ctx, OCDoHandle UNU
}
OicSecDoxm_t *ptrDoxm = NULL;
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData1;
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
OCStackResult res = CBORPayloadToDoxm(payload, size, &ptrDoxm);
if ((NULL == ptrDoxm) && (OC_STACK_OK != res))
if ((NULL == ptrDoxm) || (OC_STACK_OK != res))
{
OIC_LOG(INFO, TAG, "Ignoring malformed CBOR");
return OC_STACK_KEEP_TRANSACTION;
......
......@@ -304,15 +304,16 @@ static OCStackResult provisionCredentials(const OicSecCred_t *cred,
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData1, &secPayload->payloadSize);
if((OC_STACK_OK != res) && (NULL == secPayload->securityData1))
OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData, &secPayload->payloadSize);
if((OC_STACK_OK != res) && (NULL == secPayload->securityData))
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
OIC_LOG_V(INFO, TAG, "Credential for provisioning : %s",secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
deviceInfo->endpoint.addr,
......@@ -456,14 +457,15 @@ OCStackResult SRPProvisionCRL(void *ctx, const OCProvisionDev_t *selectedDeviceI
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = CrlToCBORPayload(crl, &secPayload->securityData1, &secPayload->payloadSize);
if((OC_STACK_OK != res) && (NULL == secPayload->securityData1))
OCStackResult res = CrlToCBORPayload(crl, &secPayload->securityData, &secPayload->payloadSize);
if((OC_STACK_OK != res) && (NULL == secPayload->securityData))
{
OICFree(secPayload);
OIC_LOG(ERROR, TAG, "Failed to BinToCrlJSON");
return OC_STACK_NO_MEMORY;
}
OIC_LOG_V(INFO, TAG, "CRL : %s", secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Created payload for CRL:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
......@@ -539,17 +541,18 @@ static OCStackResult provisionCertCred(const OicSecCred_t *cred,
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData1,
OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData,
&secPayload->payloadSize);
if ((OC_STACK_OK != res) || (NULL == secPayload->securityData1))
if ((OC_STACK_OK != res) || (NULL == secPayload->securityData))
{
OICFree(secPayload);
OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
OIC_LOG_V(INFO, TAG, "Credential for provisioning : %s",secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
deviceInfo->endpoint.addr,
......@@ -856,7 +859,7 @@ OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceI
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if(OC_STACK_OK != AclToCBORPayload(acl, &secPayload->securityData1, &secPayload->payloadSize))
if(OC_STACK_OK != AclToCBORPayload(acl, &secPayload->securityData, &secPayload->payloadSize))
{
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayload");
......@@ -999,14 +1002,16 @@ OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selec
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
if (OC_STACK_OK != PconfToCBORPayload(pconf, &(secPayload->securityData1),
if (OC_STACK_OK != PconfToCBORPayload(pconf, &(secPayload->securityData),
&(secPayload->payloadSize)))
{
OCPayloadDestroy((OCPayload*)secPayload);
OIC_LOG(ERROR, TAG, "Failed to PconfToCborPayload");
return OC_STACK_NO_MEMORY;
}
OIC_LOG_V(INFO, TAG, "PCONF : %s", secPayload->securityData1);
OIC_LOG(DEBUG, TAG, "Created payload for pconf set");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
......
......@@ -48,6 +48,7 @@ sptest_env.AppendUnique(LIBS = ['-lpthread','-ldl'])
sptest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
sptest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
sptest_env.PrependUnique(LIBS = [ 'ocpmapi',
'oc',
'ocsrm',
'octbstack',
'oc_logger',
......
......@@ -399,7 +399,7 @@ exit:
// note: This function is used in unit test hence not declared static,
OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
{
if (NULL == cborPayload)
if (NULL == cborPayload || 0 == size)
{
return NULL;
}
......@@ -950,7 +950,12 @@ exit:
ehRet = (payload ? OC_EH_OK : OC_EH_ERROR);
// Send response payload to request originator
SendSRMCBORResponse(ehRequest, ehRet, payload, size);
if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
{
ehRet = OC_EH_ERROR;
OIC_LOG(ERROR, TAG, "SendSRMResponse failed for HandleACLGetRequest");
}
OICFree(payload);
OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
return ehRet;
......@@ -962,7 +967,7 @@ static OCEntityHandlerResult HandleACLPostRequest(const OCEntityHandlerRequest *
OCEntityHandlerResult ehRet = OC_EH_ERROR;
// Convert CBOR into ACL data and update to SVR buffers. This will also validate the ACL data received.
uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData1;
uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
if (payload)
{
......@@ -994,7 +999,11 @@ static OCEntityHandlerResult HandleACLPostRequest(const OCEntityHandlerRequest *
}
// Send payload to request originator
SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
{
ehRet = OC_EH_ERROR;
OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleACLPostRequest");
}
OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__, ehRet);
return ehRet;
......@@ -1021,7 +1030,11 @@ static OCEntityHandlerResult HandleACLDeleteRequest(const OCEntityHandlerRequest
exit:
// Send payload to request originator
SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
{
ehRet = OC_EH_ERROR;
OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleACLDeleteRequest");
}
return ehRet;
}
......@@ -1058,7 +1071,7 @@ OCEntityHandlerResult ACLEntityHandler(OCEntityHandlerFlag flag, OCEntityHandler
default:
ehRet = OC_EH_ERROR;
SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
SendSRMResponse(ehRequest, ehRet, NULL, 0);
}
}
......
......@@ -249,7 +249,7 @@ exit:
OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
OicSecAmacl_t **secAmacl)
{
if (NULL == cborPayload || NULL == secAmacl || NULL != *secAmacl)
if (NULL == cborPayload || NULL == secAmacl || NULL != *secAmacl || 0 == size)
{
return OC_STACK_INVALID_PARAM;
}
......@@ -261,13 +261,8 @@ OCStackResult CBORPayloadToAmacl(const uint8_t *cborPayload, size_t size,
CborValue amaclCbor = { .parser = NULL };
CborParser parser = { .end = NULL };
CborError cborFindResult = CborNoError;
int cborLen = size;
if (0 == size)
{
cborLen = CBOR_SIZE;
}
cbor_parser_init(cborPayload, cborLen, 0, &parser, &amaclCbor);
cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t));
CborValue amaclMap = { .parser = NULL };
......@@ -460,8 +455,11 @@ static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest
OCEntityHandlerResult ehRet = (res == OC_STACK_OK) ? OC_EH_OK : OC_EH_ERROR;
// Send response payload to request originator
SendSRMCBORResponse(ehRequest, ehRet, cborPayload, size);
if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, cborPayload, size))
{
ehRet = OC_EH_ERROR;
OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleAmaclGetRequest");
}
OICFree(cborPayload);
OIC_LOG_V (DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
......@@ -473,7 +471,7 @@ static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerReques
OCEntityHandlerResult ehRet = OC_EH_ERROR;
// Convert CBOR Amacl data into binary. This will also validate the Amacl data received.
uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData1;
uint8_t *payload = ((OCSecurityPayload *) ehRequest->payload)->securityData;
size_t size = ((OCSecurityPayload *) ehRequest->payload)->payloadSize;
if (payload)
{
......@@ -498,7 +496,11 @@ static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerReques
}
// Send payload to request originator
SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0))
{
ehRet = OC_EH_ERROR;
OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleAmaclPostRequest");
}
OIC_LOG_V(DEBUG, TAG, "%s RetVal %d", __func__ , ehRet);
return ehRet;
......@@ -535,7 +537,7 @@ static OCEntityHandlerResult AmaclEntityHandler (OCEntityHandlerFlag flag,
default:
ehRet = OC_EH_ERROR;
SendSRMCBORResponse(ehRequest, ehRet, NULL, 0);
SendSRMResponse(ehRequest, ehRet, NULL, 0);
}
}
......
......@@ -108,8 +108,8 @@ static OCStackApplicationResult AmsMgrDiscoveryCallback(void *ctx, OCDoHandle ha
OicSecDoxm_t *doxm = NULL;
OIC_LOG_V(INFO, TAG, "Doxm DeviceId Discovery response = %s\n",
((OCSecurityPayload*)clientResponse->payload)->securityData1);
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData1;
((OCSecurityPayload*)clientResponse->payload)->securityData);
uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
//As doxm is NULL amsmgr can't test if response from trusted AMS service
......@@ -303,7 +303,7 @@ static OCStackApplicationResult AmsMgrAclReqCallback(void *ctx, OCDoHandle handl
{
size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
OCStackResult ret =
InstallNewACL(((OCSecurityPayload*)clientResponse->payload)->securityData1, size);
InstallNewACL(((OCSecurityPayload*)clientResponse->payload)->securityData, size);
VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
OIC_LOG_V(INFO, TAG, "%s : Calling checkPermission", __func__);
......
......@@ -352,7 +352,7 @@ exit:
OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
OicSecCred_t **secCred)
{
if (NULL == cborPayload || NULL == secCred || NULL != *secCred)
if (NULL == cborPayload || NULL == secCred || NULL != *secCred || 0 == size)
{
return OC_STACK_INVALID_PARAM;
}
......@@ -871,7 +871,7 @@ static OCEntityHandlerResult HandlePutRequest(const OCEntityHandlerRequest * ehR
//Get binary representation of cbor
OicSecCred_t *cred = NULL;
uint8_t *payload = (((OCSecurityPayload*)ehRequest->payload)->securityData1);
uint8_t *payload = (((OCSecurityPayload*)ehRequest->payload)->securityData);
size_t size = (((OCSecurityPayload*)ehRequest->payload)->payloadSize);
OCStackResult res = CBORPayloadToCred(payload, size, &cred);
if (res == OC_STACK_OK)
......@@ -1018,7 +1018,7 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh
//Get binary representation of CBOR
OicSecCred_t *cred = NULL;
uint8_t *payload = ((OCSecurityPayload*)ehRequest->payload)->securityData1;
uint8_t *payload = ((OCSecurityPayload*)ehRequest->payload)->securityData;
size_t size = ((OCSecurityPayload*)ehRequest->payload)->payloadSize;
OCStackResult res = CBORPayloadToCred(payload, size, &cred);
if ((OC_STACK_OK == res) && cred)
......@@ -1104,7 +1104,7 @@ OCEntityHandlerResult CredEntityHandler(OCEntityHandlerFlag flag,
}
//Send payload to request originator
ret = (SendSRMCBORResponse(ehRequest, ret, NULL, 0) == OC_STACK_OK) ?
ret = (SendSRMResponse(ehRequest, ret, NULL, 0) == OC_STACK_OK) ?
ret : OC_EH_ERROR;
return ret;
......
......@@ -102,33 +102,33 @@ OCStackResult CrlToCBORPayload(const OicSecCrl_t *crl, uint8_t **payload, size_t
cbor_encoder_init(&encoder, outPayload, cborLen, 0);
cborEncoderResult = cbor_encoder_create_map(&encoder, &crlMap, CRL_MAP_SIZE);
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, ERROR);
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to create CRL Map");
//CRLId -- Mandatory
cborEncoderResult = cbor_encode_text_string(&crlMap, OIC_CBOR_CRL_ID,
strlen(OIC_CBOR_CRL_ID));
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, ERROR);
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add CRL ID");
cborEncoderResult = cbor_encode_int(&crlMap, crl->CrlId);
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, ERROR);
VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed to add CRL Id value");