Commit f849ddef authored by Joonghwan Lee's avatar Joonghwan Lee Committed by Randeep

Fix to get only single credential entry

Old function(GetCredResourceDataByCredId) return not only the indicated credential entry but also all linked entries.

Change-Id: I0466b4c25a21395f08664a11ecfa6fd51a94b258
Signed-off-by: default avatarJoonghwan Lee <jh05.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13547Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarKevin Kane <kkane@microsoft.com>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent 8f09f241
......@@ -57,14 +57,16 @@ OCStackResult DeInitCredResource();
OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
/**
* This method is used by SRM to retrieve credential for given credId.
* This method is used by SRM to retrieve credential entry for given credId.
*
* @note Caller needs to release this memory by calling DeleteCredList().
*
* @param credId for which credential is required.
*
* @return reference to @ref OicSecCred_t, if credential is found, else NULL, if credential
* not found.
*/
OicSecCred_t* GetCredResourceDataByCredId(const uint16_t credId);
OicSecCred_t* GetCredEntryByCredId(const uint16_t credId);
/**
* This function converts credential data into CBOR format.
......
......@@ -506,7 +506,7 @@ OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint1
return OC_STACK_INVALID_PARAM;
}
OicSecCred_t *trustCertChainCred = GetCredResourceDataByCredId(credId);
OicSecCred_t *trustCertChainCred = GetCredEntryByCredId(credId);
if(NULL == trustCertChainCred)
{
OIC_LOG(ERROR, TAG, "Can not find matched Trust Cert. Chain.");
......@@ -516,6 +516,7 @@ OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint1
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
DeleteCredList(trustCertChainCred);
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
......@@ -523,10 +524,12 @@ OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint1
int secureFlag = 0;
if(OC_STACK_OK != CredToCBORPayload(trustCertChainCred, &secPayload->securityData, &secPayload->payloadSize, secureFlag))
{
DeleteCredList(trustCertChainCred);
OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
DeleteCredList(trustCertChainCred);
OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
......
......@@ -38,6 +38,7 @@
#include "base64.h"
#include "ocserverrequest.h"
#include "oic_malloc.h"
#include "oic_string.h"
#include "ocpayload.h"
#include "utlist.h"
#include "credresource.h"
......@@ -2074,21 +2075,75 @@ const OicSecCred_t* GetCredList()
return gCred;
}
OicSecCred_t* GetCredResourceDataByCredId(const uint16_t credId)
OicSecCred_t* GetCredEntryByCredId(const uint16_t credId)
{
OicSecCred_t *cred = NULL;
if ( 1 > credId)
OicSecCred_t *tmpCred = NULL;
if ( 1 > credId)
{
return NULL;
}
LL_FOREACH(gCred, cred)
LL_FOREACH(gCred, tmpCred)
{
if(cred->credId == credId)
if(tmpCred->credId == credId)
{
cred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t));
VERIFY_NON_NULL(TAG, cred, ERROR);
// common
cred->next = NULL;
cred->credId = tmpCred->credId;
cred->credType = tmpCred->credType;
memcpy(cred->subject.id, tmpCred->subject.id , sizeof(cred->subject.id));
memcpy(cred->rownerID.id, tmpCred->rownerID.id , sizeof(cred->rownerID.id));
if (tmpCred->period)
{
cred->period = OICStrdup(tmpCred->period);
}
// key data
if (tmpCred->privateData.data)
{
cred->privateData.data = (uint8_t *)OICCalloc(1, tmpCred->privateData.len);
VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR);
memcpy(cred->privateData.data, tmpCred->privateData.data, tmpCred->privateData.len);
cred->privateData.len = tmpCred->privateData.len;
cred->privateData.encoding = tmpCred->privateData.encoding;
}
#if defined(__WITH_X509__) || defined(__WITH_TLS__)
else if (tmpCred->publicData.data)
{
cred->publicData.data = (uint8_t *)OICCalloc(1, tmpCred->publicData.len);
VERIFY_NON_NULL(TAG, cred->publicData.data, ERROR);
memcpy(cred->publicData.data, tmpCred->publicData.data, tmpCred->publicData.len);
cred->publicData.len = tmpCred->publicData.len;
}
else if (tmpCred->optionalData.data)
{
cred->optionalData.data = (uint8_t *)OICCalloc(1, tmpCred->optionalData.len);
VERIFY_NON_NULL(TAG, cred->optionalData.data, ERROR);
memcpy(cred->optionalData.data, tmpCred->optionalData.data, tmpCred->optionalData.len);
cred->optionalData.len = tmpCred->optionalData.len;
cred->optionalData.encoding = tmpCred->optionalData.encoding;
}
if (tmpCred->credUsage)
{
cred->credUsage = OICStrdup(tmpCred->credUsage);
}
#endif /* __WITH_X509__ or __WITH_TLS__*/
return cred;
}
}
exit:
FreeCred(cred);
return NULL;
}
......
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