*/
OCStackResult AddCredential(OicSecCred_t * cred);
+/**
+ * Function to remove the credential from SVR DB.
+ *
+ * @param subject is the Credential Subject to be deleted.
+ *
+ * @return ::OC_STACK_OK for success, or errorcode otherwise.
+ */
+OCStackResult RemoveCredential(const OicUuid_t *subject);
+
/**
* Function to remove the credential from SVR DB.
*
*
* @return ::OC_STACK_OK for success, or errorcode otherwise.
*/
-OCStackResult RemoveCredential(const OicUuid_t *credId);
+OCStackResult RemoveCredentialByCredId(uint16_t credId);
#if defined(__WITH_DTLS__)
/**
int GetDtlsX509Credentials(CADtlsX509Creds_t *credInfo);
#endif /*__WITH_X509__*/
+/**
+ * Function to getting credential list
+ *
+ * @return ::credential list
+ */
+const OicSecCred_t* GetCredList();
+
/**
* Function to deallocate allocated memory to OicSecCred_t.
*
#include "base64.h"
#include "cJSON.h"
#include "global.h"
+#include "utlist.h"
#include "srmresourcestrings.h"
#include "doxmresource.h"
OICFree(b64Buf);
#endif //End of Test codes
+ //Finding previous ownerPSK.
+ const OicSecCred_t* credList = GetCredList();
+ OicSecCred_t* prevCred = NULL;
+ uint16_t credId = 0;
+ LL_FOREACH(credList, prevCred)
+ {
+ //OwnerPSK's type is SYMMETRIC_PAIR_WISE_KEY
+ if (SYMMETRIC_PAIR_WISE_KEY == prevCred->credType &&
+ 0 == memcmp(prevCred->subject.id, cred->subject.id, sizeof(cred->subject.id)))
+ {
+ credId = prevCred->credId;
+ break;
+ }
+ }
+
+ //If duplicate owner PSK is exists, remove it.
+ if(0 < credId)
+ {
+ OIC_LOG(WARNING, TAG, "Duplicate OwnerPSK was detected.");
+ OIC_LOG(WARNING, TAG, "[Subject] : ");
+ OIC_LOG_BUFFER(WARNING, TAG, prevCred->subject.id, sizeof(prevCred->subject.id));
+ OIC_LOG_V(WARNING, TAG, "[Encoding Type] : %d", prevCred->privateData.encoding);
+ OIC_LOG(WARNING, TAG, "[Private Data] : ");
+ OIC_LOG_BUFFER(WARNING, TAG, prevCred->privateData.data, prevCred->privateData.len);
+ OIC_LOG(WARNING, TAG, "Previous OwnerPSK will be removed.");
+
+ res = RemoveCredentialByCredId(credId);
+ if(OC_STACK_RESOURCE_DELETED != res)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to remove the previous OwnerPSK");
+ DeleteCredList(cred);
+ goto exit;
+ }
+ }
+
res = AddCredential(cred);
if(res != OC_STACK_OK)
{
}
+OCStackResult RemoveCredentialByCredId(uint16_t credId)
+{
+ OCStackResult ret = OC_STACK_ERROR;
+ OicSecCred_t *cred = NULL;
+ OicSecCred_t *tempCred = NULL;
+ bool deleteFlag = false;
+
+ OIC_LOG(INFO, TAG, "IN RemoveCredentialByCredId");
+
+ if ( 0 == credId)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+
+ LL_FOREACH_SAFE(gCred, cred, tempCred)
+ {
+ if (cred->credId == credId)
+ {
+ OIC_LOG_V(DEBUG, TAG, "Credential(ID=%d) will be removed.", credId);
+
+ LL_DELETE(gCred, cred);
+ FreeCred(cred);
+ deleteFlag = true;
+ }
+ }
+
+ if (deleteFlag)
+ {
+ if (UpdatePersistentStorage(gCred))
+ {
+ ret = OC_STACK_RESOURCE_DELETED;
+ }
+ }
+ OIC_LOG(INFO, TAG, "OUT RemoveCredentialByCredId");
+
+ return ret;
+
+}
+
/**
* Remove all credential data on credential resource and persistent storage
*
return NULL;
}
+const OicSecCred_t* GetCredList()
+{
+ return gCred;
+}
+
OicSecCred_t* GetCredResourceDataByCredId(const uint16_t credId)
{
OicSecCred_t *cred = NULL;