according to spec B.
* NOTE : https://gerrit.iotivity.org/gerrit/#/c/4733/ required,
in order to provisioning tool works in debug mode.
1. Change the security resource name according to spec B.
2. Remove unnecessary security resource according to spec B.
3. Remove the entity of resource name from coap/coaps payload as follows :
[Before]
{
"doxm":
{
"oxm":[0],
"oxmsel":0,
"sct":1,
"owned":true,
"deviceid":"anVzdHdvcmtzRGV2VVVJRA==",
"devowner":"YWRtaW5EZXZpY2VVVUlEMA==",
"rowner":"YWRtaW5EZXZpY2VVVUlEMA=="
}
}
[After]
{
"oxm":[0],
"oxmsel":0,
"sct":1,
"owned":true,
"deviceid":"anVzdHdvcmtzRGV2VVVJRA==",
"devowner":"YWRtaW5EZXZpY2VVVUlEMA==",
"rowner":"YWRtaW5EZXZpY2VVVUlEMA=="
}
4. Modify the sample SVR DB(.json) according to above modifications.
5. Modify the unittest according to above modifications.
[Patch #1] Initial upload
[Patch #2] Update commit message
[Patch #3] Retrigger
[Patch #4] Upload missing file.
[Patch #5,#6] Modify according to comments.
[Patch #7,#8] Update commit message.
Change-Id: Ic6842af77c7098f30e7823597f807bb8a55d4541
Signed-off-by: leechul <chuls.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4725
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: sangsu choi <sangsu.choi@samsung.com>
Reviewed-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
* Caller needs to invoke 'free' when done using
* returned string.
* @param acl instance of OicSecAcl_t structure.
+ * @param isIncResName decide whether or not to include the resource name in output.
*
* @retval pointer to ACL in json format.
*/
-char* BinToAclJSON(const OicSecAcl_t * acl);
+char* BinToAclJSON(const OicSecAcl_t * acl, const bool isIncResName);
/**
/**
* This function installs a new ACL.
* @param newJsonStr JSON string representing a new ACL.
+ * @param isIncResName if resource name is included into payload, it is true.
*
* @retval OC_STACK_OK for Success, otherwise some error value
*/
-OCStackResult InstallNewACL(const char* newJsonStr);
+OCStackResult InstallNewACL(const char* newJsonStr, const bool isIncResName);
#ifdef __cplusplus
* Caller needs to invoke 'free' when done using
* returned string.
* @param Amacl instance of OicSecAmacl_t structure.
+ * @param isIncResName Decide whether or not to include the name of the resource in output.
*
* @retval pointer to Amacl in json format.
*/
-char* BinToAmaclJSON(const OicSecAmacl_t * amacl);
+char* BinToAmaclJSON(const OicSecAmacl_t * amacl, const bool isIncResName);
#ifdef __cplusplus
}
* Caller needs to invoke 'free' when done using
* returned string.
* @param cred pointer to instance of OicSecCred_t structure.
+ * @param isIncResName Decide whether or not to include the resource name in output.
*
* @retval
* pointer to JSON credential representation - if credential for subjectId found
* NULL - if credential for subjectId not found
*/
-char* BinToCredJSON(const OicSecCred_t* cred);
+char* BinToCredJSON(const OicSecCred_t* cred, const bool isIncResName);
/**
* This function generates the bin credential data.
void GetDerCrl(ByteArray crlArray);
/**
- * This function get CRL from SRM
+ * This method converts JSON CRL into binary CRL.
+ * The JSON CRL can be from persistent database or received as PUT/POST request.
*
- * @param crl [out] - pointer to buffer that contains crl. Shoul be not NULL. Buffer
- * will be allocated by the function and content of *crl will be ignored.
- * @param outlen [out] - pointer to length of the CRL buffer. Shoul be not NULL.
+ * @param[in] jsonStr CRL data in json string.
+ * @param[in] isIncResName if resource name is included into payload, it is true.
+ * @return pointer to OicSecCrl_t.
*
- * @returns OC_STACK_OK if success and errorcode otherwise.
- * @note Caller responsible for crl buffer memory (use OICFree to free it)
+ * @note Caller needs to invoke OCFree after done using the return pointer
*/
-OicSecCrl_t * JSONToCrlBin(const char * jsonStr);
+OicSecCrl_t * JSONToCrlBin(const char * jsonStr, const bool isIncResName);
/**
* Initialize CLR resource by loading data from persistent storage.
* or received as PUT/POST request.
*
* @param[in] jsonStr doxm data in json string.
+ * @param[in] isIncResName if resource name is included into payload, it is true.
* @return pointer to OicSecDoxm_t.
*
* @note Caller needs to invoke OCFree after done
* using the return pointer
*/
-OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr);
+OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr, const bool isIncResName);
/**
* This method converts DOXM data into JSON format.
* return string
*
* @param[in] doxm Pointer to OicSecDoxm_t.
+ * @param[in] isIncResName Decide whether or not to include the resource name in output.
* @return pointer to json string.
*
* @note Caller needs to invoke OCFree after done
* using the return pointer
*/
-char * BinToDoxmJSON(const OicSecDoxm_t * doxm);
+char * BinToDoxmJSON(const OicSecDoxm_t * doxm, const bool isIncResName);
/**
* This method returns the SRM device ID for this device.
* This method converts JSON PSTAT into binary PSTAT.
*
* @param[in] jsonStr pstat data in json string.
+ * @param[in] isIncResName if resource name is included into payload, it is true.
* @return pointer to OicSecPstat_t.
*/
-OicSecPstat_t * JSONToPstatBin(const char * jsonStr);
+OicSecPstat_t * JSONToPstatBin(const char * jsonStr, const bool isIncResName);
/**
* This method converts pstat data into JSON format.
*
* @param[in] pstat pstat data in binary format.
+ * @param[in] isIncResName Decide whether or not to include the resource name in output.
* @return pointer to pstat json string.
*/
-char * BinToPstatJSON(const OicSecPstat_t * pstat);
+char * BinToPstatJSON(const OicSecPstat_t * pstat, const bool isIncResName);
/** This function deallocates the memory for OicSecPstat_t.
*
extern const char * OIC_JSON_PERMISSION_NAME;
extern const char * OIC_JSON_OWNERS_NAME;
extern const char * OIC_JSON_OWNER_NAME;
+extern const char * OIC_JSON_DEV_OWNER_NAME;
extern const char * OIC_JSON_OWNED_NAME;
extern const char * OIC_JSON_OXM_NAME;
extern const char * OIC_JSON_OXM_TYPE_NAME;
extern const char * OIC_JSON_OXM_SEL_NAME;
extern const char * OIC_JSON_DEVICE_ID_FORMAT_NAME;
extern const char * OIC_JSON_CREDID_NAME;
+extern const char * OIC_JSON_SUBJECTID_NAME;
extern const char * OIC_JSON_ROLEIDS_NAME;
extern const char * OIC_JSON_CREDTYPE_NAME;
extern const char * OIC_JSON_PUBLICDATA_NAME;
* Caller needs to invoke 'free' when done using
* returned string.
* @param svc instance of OicSecSvc_t structure.
+ * @param isIncResName Decide whether or not to include the resource name in output.
*
* @retval pointer to SVC in json format.
*/
-char* BinToSvcJSON(const OicSecSvc_t * svc);
+char* BinToSvcJSON(const OicSecSvc_t * svc, const bool isIncResName);
#ifdef __cplusplus
}
struct OicSecDoxm
{
// <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
- OicUrn_t *oxmType; // 0:R:M:N:URN
- size_t oxmTypeLen; // the number of elts in OxmType
OicSecOxm_t *oxm; // 1:R:M:N:UINT16
size_t oxmLen; // the number of elts in Oxm
OicSecOxm_t oxmSel; // 2:R/W:S:Y:UINT16
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/res/d",
"/oic/res/types/d",
"/oic/presence"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"ZG9vckRldmljZVVVSUQwMA=="
]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/crl",
"/oic/sec/cred"
],
- "perms": 6,
- "ownrs" : [
+ "permission": 6,
+ "rowners" : [
"ZG9vckRldmljZVVVSUQwMA=="
]
}
"pstat": {
"isop": false,
"deviceid": "ZG9vckRldmljZVVVSUQwMA==",
- "commithash": 0,
+ "ch": 0,
"cm": 0,
"tm": 0,
"om": 3,
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/res/d",
"/oic/res/types/d",
"/oic/presence"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"bGlnaHREZXZpY2VVVUlEMA=="
]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/crl",
"/oic/sec/cred"
],
- "perms": 6,
- "ownrs" : [
+ "permission": 6,
+ "rowners" : [
"bGlnaHREZXZpY2VVVUlEMA=="
]
}
"pstat": {
"isop": false,
"deviceid": "bGlnaHREZXZpY2VVVUlEMA==",
- "commithash": 0,
+ "ch": 0,
"cm": 0,
"tm": 0,
"om": 3,
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/res/types/d",
"/oic/ad"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/cred"
],
- "perms": 7,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
+ "permission": 7,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
}
],
"pstat": {
"sct": 1,
"owned": true,
"deviceid": "YWRtaW5EZXZpY2VVVUlEMA==",
- "ownr": "YWRtaW5EZXZpY2VVVUlEMA=="
+ "devowner": "YWRtaW5EZXZpY2VVVUlEMA=="
}
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/res/types/d",
"/oic/ad"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlE"]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlE"]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/cred"
],
- "perms": 7,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlE"]
+ "permission": 7,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlE"]
}
],
"crl": {
"oxmsel": 0,
"owned": true,
"deviceid": "YWRtaW5EZXZpY2VVVUlE",
- "ownr": "YWRtaW5EZXZpY2VVVUlE"
+ "devowner": "YWRtaW5EZXZpY2VVVUlE"
}
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/ad",
"/oic/sec/amacl"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
}
],
"pstat": {
"sct": 1,
"owned": true,
"deviceid": "YWRtaW5EZXZpY2VVVUlEMA==",
- "ownr": "YWRtaW5EZXZpY2VVVUlEMA=="
+ "devowner": "YWRtaW5EZXZpY2VVVUlEMA=="
}
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/res/types/d",
"/oic/ad"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlE"]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlE"]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/cred"
],
- "perms": 7,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlE"]
+ "permission": 7,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlE"]
}
],
"pstat": {
"sct": 1,
"owned": true,
"deviceid": "YWRtaW5EZXZpY2VVVUlE",
- "ownr": "YWRtaW5EZXZpY2VVVUlE"
+ "devowner": "YWRtaW5EZXZpY2VVVUlE"
}
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/res/d",
"/oic/res/types/d",
"/oic/presence"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"anVzdHdvcmtzRGV2VVVJRA=="
]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/cred"
],
- "perms": 6,
- "ownrs" : [
+ "permission": 6,
+ "rowners" : [
"anVzdHdvcmtzRGV2VVVJRA=="
]
}
"pstat": {
"isop": false,
"deviceid": "anVzdHdvcmtzRGV2VVVJRA==",
- "commithash": 0,
+ "ch": 0,
"cm": 0,
"tm": 0,
"om": 3,
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/res/d",
"/oic/res/types/d",
"/oic/presence"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"cmFuZG9tUGluRGV2VVVJRA=="
]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl",
"/oic/sec/cred"
],
- "perms": 6,
- "ownrs" : [
+ "permission": 6,
+ "rowners" : [
"cmFuZG9tUGluRGV2VVVJRA=="
]
}
"pstat": {
"isop": false,
"deviceid": "cmFuZG9tUGluRGV2VVVJRA==",
- "commithash": 0,
+ "ch": 0,
"cm": 0,
"tm": 0,
"om": 3,
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/sec/svc",
"/oic/sec/amacl"
],
- "perms": 2,
- "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+ "permission": 2,
+ "rowners" : ["MTExMTExMTExMTExMTExMQ=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 6,
- "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+ "permission": 6,
+ "rowners" : ["MTExMTExMTExMTExMTExMQ=="]
}
],
"pstat": {
}
OicSecPstat_t* pstat = JSONToPstatBin(
- ((OCSecurityPayload*)clientResponse->payload)->securityData);
+ ((OCSecurityPayload*)clientResponse->payload)->securityData, false);
if(NULL == pstat)
{
OC_LOG(ERROR, TAG, "Error while converting json to pstat bin");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToPstatJSON(deviceInfo->pstat);
+ secPayload->securityData = BinToPstatJSON(deviceInfo->pstat, false);
if (NULL == secPayload->securityData)
{
OICFree(secPayload);
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToPstatJSON(otmCtx->selectedDeviceInfo->pstat);
+ secPayload->securityData = BinToPstatJSON(otmCtx->selectedDeviceInfo->pstat, false);
if (NULL == secPayload->securityData)
{
OICFree(secPayload);
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToAclJSON(&defaultAcl);
+ secPayload->securityData = BinToAclJSON(&defaultAcl, false);
OICFree(defaultAcl.owners);
if(!secPayload->securityData)
{
}
otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_JUST_WORKS;
- return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm);
+ return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm, false);
}
char* CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx)
memcpy(otmCtx->selectedDeviceInfo->doxm->owner.id, uuidPT.id , UUID_LENGTH);
otmCtx->selectedDeviceInfo->doxm->owned = true;
- return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm);
+ return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm, false);
}
OCStackResult LoadSecretJustWorksCallback(OTMContext_t* UNUSED_PARAM)
}
memcpy(otmCtx->selectedDeviceInfo->doxm->owner.id, uuidPT.id, UUID_LENGTH);
- return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm);
+ return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm, false);
}
char* CreatePinBasedOwnerTransferPayload(OTMContext_t* otmCtx)
memcpy(otmCtx->selectedDeviceInfo->doxm->owner.id, uuidPT.id , UUID_LENGTH);
otmCtx->selectedDeviceInfo->doxm->owned = true;
- return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm);
+ return BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm, false);
}
OCStackResult InputPinCodeCallback(OTMContext_t* otmCtx)
#include "cJSON.h"
#include "utlist.h"
#include "ocpayload.h"
+#include "payload_logging.h"
#include "securevirtualresourcetypes.h"
#include "srmresourcestrings.h" //@note: SRM's internal header
memcpy(newDev->doxm, src->doxm, sizeof(OicSecDoxm_t));
// We have to assign NULL for not necessary information to prevent memory corruption.
- newDev->doxm->oxmType = NULL;
newDev->doxm->oxm = NULL;
}
}
else
{
+ OC_LOG_PAYLOAD(DEBUG, clientResponse->payload);
+
if (PAYLOAD_TYPE_DISCOVERY != clientResponse->payload->type)
{
OC_LOG(INFO, TAG, "Wrong payload type");
}
else
{
+ OC_LOG_PAYLOAD(DEBUG, clientResponse->payload);
+
if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
{
OC_LOG(INFO, TAG, "Unknown payload type");
return OC_STACK_KEEP_TRANSACTION;
}
OicSecDoxm_t *ptrDoxm = JSONToDoxmBin(
- ((OCSecurityPayload*)clientResponse->payload)->securityData);
+ ((OCSecurityPayload*)clientResponse->payload)->securityData, false);
if (NULL == ptrDoxm)
{
OC_LOG(INFO, TAG, "Ignoring malformed JSON");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToCredJSON(cred);
+ secPayload->securityData = BinToCredJSON(cred, false);
if(NULL == secPayload->securityData)
{
OICFree(secPayload);
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToCrlJSON(crl);
+ secPayload->securityData = BinToCrlJSON(crl, false);
if (NULL == secPayload->securityData)
{
OICFree(secPayload);
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToCredJSON(cred);
+ secPayload->securityData = BinToCredJSON(cred, false);
if (NULL == secPayload->securityData)
{
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToAclJSON(acl);
+ secPayload->securityData = BinToAclJSON(acl, false);
if(NULL == secPayload->securityData)
{
OICFree(secPayload);
* Note: Caller needs to invoke 'free' when finished done using
* return string.
*/
-char * BinToAclJSON(const OicSecAcl_t * acl)
+char * BinToAclJSON(const OicSecAcl_t * acl, const bool isIncResName)
{
cJSON *jsonRoot = NULL;
char *jsonStr = NULL;
if (acl)
{
- jsonRoot = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
-
cJSON *jsonAclArray = NULL;
- cJSON_AddItemToObject (jsonRoot, OIC_JSON_ACL_NAME, jsonAclArray = cJSON_CreateArray());
+ if(isIncResName)
+ {
+ jsonRoot = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
+ cJSON_AddItemToObject (jsonRoot, OIC_JSON_ACL_NAME, jsonAclArray=cJSON_CreateArray());
+ }
+ else
+ {
+ jsonAclArray = cJSON_CreateArray();
+ jsonRoot = jsonAclArray;
+ }
VERIFY_NON_NULL(TAG, jsonAclArray, ERROR);
while(acl)
/*
* This internal method converts JSON ACL into binary ACL.
*/
-OicSecAcl_t * JSONToAclBin(const char * jsonStr)
+OicSecAcl_t * JSONToAclBin(const char * jsonStr, const bool isIncResName)
{
OCStackResult ret = OC_STACK_ERROR;
OicSecAcl_t * headAcl = NULL;
jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonAclArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME);
+ if(isIncResName)
+ {
+ jsonAclArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME);
+ }
+ else
+ {
+ jsonAclArray = jsonRoot;
+ }
VERIFY_NON_NULL(TAG, jsonAclArray, ERROR);
if (cJSON_Array == jsonAclArray->type)
static bool UpdatePersistentStorage(const OicSecAcl_t *acl)
{
// Convert ACL data into JSON for update to persistent storage
- char *jsonStr = BinToAclJSON(acl);
+ char *jsonStr = BinToAclJSON(acl, true);
if (jsonStr)
{
cJSON *jsonAcl = cJSON_Parse(jsonStr);
0 == strcmp(WILDCARD_RESOURCE_URI, currentAce->resources[n])))
{
// Convert ACL data into JSON for transmission
- jsonStr = BinToAclJSON(currentAce);
+ jsonStr = BinToAclJSON(currentAce, false);
goto exit;
}
}
else
{
// Convert ACL data into JSON for transmission
- jsonStr = BinToAclJSON(currentAce);
+ jsonStr = BinToAclJSON(currentAce, false);
goto exit;
}
}
else
{
// Convert ACL data into JSON for transmission
- jsonStr = BinToAclJSON(gAcl);
+ jsonStr = BinToAclJSON(gAcl, false);
}
exit:
OCEntityHandlerResult ehRet = OC_EH_ERROR;
// Convert JSON ACL data into binary. This will also validate the ACL data received.
- OicSecAcl_t* newAcl = JSONToAclBin(((OCSecurityPayload*)ehRequest->payload)->securityData);
+ OicSecAcl_t* newAcl = JSONToAclBin(((OCSecurityPayload*)ehRequest->payload)->securityData, false);
if (newAcl)
{
if (jsonSVRDatabase)
{
// Convert JSON ACL into binary format
- gAcl = JSONToAclBin(jsonSVRDatabase);
+ gAcl = JSONToAclBin(jsonSVRDatabase, true);
OICFree(jsonSVRDatabase);
}
/*
}
-OCStackResult InstallNewACL(const char* newJsonStr)
+OCStackResult InstallNewACL(const char* newJsonStr, const bool isIncResName)
{
OCStackResult ret = OC_STACK_ERROR;
// Convert JSON ACL data into binary. This will also validate the ACL data received.
- OicSecAcl_t* newAcl = JSONToAclBin(newJsonStr);
+ OicSecAcl_t* newAcl = JSONToAclBin(newJsonStr, isIncResName);
if (newAcl)
{
LL_APPEND(gAcl, newAcl);
// Convert ACL data into JSON for update to persistent storage
- char *jsonStr = BinToAclJSON(gAcl);
+ char *jsonStr = BinToAclJSON(gAcl, true);
if (jsonStr)
{
cJSON *jsonAcl = cJSON_Parse(jsonStr);
*
* Note: Caller needs to invoke 'free' when finished using the return string.
*/
-char * BinToAmaclJSON(const OicSecAmacl_t * amacl)
+char * BinToAmaclJSON(const OicSecAmacl_t * amacl, const bool isIncResName)
{
cJSON *jsonRoot = NULL;
char *jsonStr = NULL;
if (amacl)
{
- jsonRoot = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
-
cJSON *jsonAmaclArray = NULL;
- cJSON_AddItemToObject (jsonRoot, OIC_JSON_AMACL_NAME, jsonAmaclArray = cJSON_CreateArray());
+ if(isIncResName)
+ {
+ jsonRoot = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
+ cJSON_AddItemToObject(jsonRoot, OIC_JSON_AMACL_NAME,
+ jsonAmaclArray = cJSON_CreateArray());
+ }
+ else
+ {
+ jsonAmaclArray = cJSON_CreateArray();
+ jsonRoot = jsonAmaclArray;
+ }
VERIFY_NON_NULL(TAG, jsonAmaclArray, ERROR);
while(amacl)
/*
* This internal method converts JSON AMACL into binary AMACL.
*/
-OicSecAmacl_t * JSONToAmaclBin(const char * jsonStr)
+OicSecAmacl_t * JSONToAmaclBin(const char * jsonStr, const bool isIncResName)
{
OCStackResult ret = OC_STACK_ERROR;
OicSecAmacl_t * headAmacl = NULL;
jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonAmaclArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME);
+ if(isIncResName)
+ {
+ jsonAmaclArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME);
+ }
+ else
+ {
+ jsonAmaclArray = jsonRoot;
+ }
VERIFY_NON_NULL(TAG, jsonAmaclArray, INFO);
if (cJSON_Array == jsonAmaclArray->type)
static OCEntityHandlerResult HandleAmaclGetRequest (const OCEntityHandlerRequest * ehRequest)
{
// Convert Amacl data into JSON for transmission
- char* jsonStr = BinToAmaclJSON(gAmacl);
+ char* jsonStr = BinToAmaclJSON(gAmacl, false);
OCEntityHandlerResult ehRet = (jsonStr ? OC_EH_OK : OC_EH_ERROR);
OCEntityHandlerResult ehRet = OC_EH_ERROR;
// Convert JSON Amacl data into binary. This will also validate the Amacl data received.
- OicSecAmacl_t* newAmacl = JSONToAmaclBin(((OCSecurityPayload*)ehRequest->payload)->securityData);
+ OicSecAmacl_t* newAmacl = JSONToAmaclBin(((OCSecurityPayload*)ehRequest->payload)->securityData, false);
if (newAmacl)
{
LL_APPEND(gAmacl, newAmacl);
// Convert Amacl data into JSON for update to persistent storage
- char *jsonStr = BinToAmaclJSON(gAmacl);
+ char *jsonStr = BinToAmaclJSON(gAmacl, true);
if (jsonStr)
{
cJSON *jsonAmacl = cJSON_Parse(jsonStr);
if (jsonSVRDatabase)
{
// Convert JSON Amacl into binary format
- gAmacl = JSONToAmaclBin(jsonSVRDatabase);
+ gAmacl = JSONToAmaclBin(jsonSVRDatabase, true);
OICFree(jsonSVRDatabase);
}
OicSecDoxm_t *doxm = NULL;
OC_LOG_V(INFO, TAG, "Doxm DeviceId Discovery response = %s\n",
((OCSecurityPayload*)clientResponse->payload)->securityData);
- doxm = JSONToDoxmBin(((OCSecurityPayload*)clientResponse->payload)->securityData);
+ doxm = JSONToDoxmBin(((OCSecurityPayload*)clientResponse->payload)->securityData, false);
//As doxm is NULL amsmgr can't test if response from trusted AMS service
//so keep the transaction.
sizeof(context->amsMgrContext->amsDeviceId.id)) == 0)
{
OCStackResult ret =
- InstallNewACL(((OCSecurityPayload*)clientResponse->payload)->securityData);
+ InstallNewACL(((OCSecurityPayload*)clientResponse->payload)->securityData, false);
VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
OC_LOG_V(INFO, TAG, "%s : Calling checkPermission", __func__);
* Caller needs to invoke 'free' when done using
* returned string.
* @param cred pointer to instance of OicSecCred_t structure.
+ * @param isIncResName Decide whether or not to include the resource name in output.
*
* @retval
* pointer to JSON credential representation - if credential for subjectId found
* NULL - if credential for subjectId not found
*/
-char * BinToCredJSON(const OicSecCred_t * cred)
+char * BinToCredJSON(const OicSecCred_t * cred, const bool isIncResName)
{
cJSON *jsonRoot = NULL;
char *jsonStr = NULL;
char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*)0)->id)) + 1] = {};
uint32_t outLen = 0;
B64Result b64Ret = B64_OK;
-
- jsonRoot = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
-
cJSON *jsonCredArray = NULL;
- cJSON_AddItemToObject(jsonRoot, OIC_JSON_CRED_NAME,
- jsonCredArray = cJSON_CreateArray());
+
+ if(isIncResName)
+ {
+ jsonRoot = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
+ cJSON_AddItemToObject(jsonRoot, OIC_JSON_CRED_NAME,
+ jsonCredArray = cJSON_CreateArray());
+ }
+ else
+ {
+ jsonCredArray = cJSON_CreateArray();
+ jsonRoot = jsonCredArray;
+ }
VERIFY_NON_NULL(TAG, jsonCredArray, ERROR);
while(cred)
b64Ret = b64Encode(cred->subject.id, sizeof(cred->subject.id), base64Buff,
sizeof(base64Buff), &outLen);
VERIFY_SUCCESS(TAG, b64Ret == B64_OK, ERROR);
- cJSON_AddStringToObject(jsonCred, OIC_JSON_SUBJECT_NAME, base64Buff);
+ cJSON_AddStringToObject(jsonCred, OIC_JSON_SUBJECTID_NAME, base64Buff);
//Note: Need further clarification on roleID data type
#if 0
/*
* This internal method converts JSON cred into binary cred.
*/
-OicSecCred_t * JSONToCredBin(const char * jsonStr)
+OicSecCred_t * JSONToCredBin(const char * jsonStr, const bool isIncResName)
{
OCStackResult ret = OC_STACK_ERROR;
OicSecCred_t * headCred = NULL;
cJSON *jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonCredArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME);
+ if(isIncResName)
+ {
+ jsonCredArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME);
+ }
+ else
+ {
+ jsonCredArray = jsonRoot;
+ }
VERIFY_NON_NULL(TAG, jsonCredArray, ERROR);
+
if (cJSON_Array == jsonCredArray->type)
{
int numCred = cJSON_GetArraySize(jsonCredArray);
}
//subject -- Mandatory
- jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_SUBJECT_NAME);
+ jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_SUBJECTID_NAME);
VERIFY_NON_NULL(TAG, jsonObj, ERROR);
VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
outLen = 0;
bool ret = false;
// Convert Cred data into JSON for update to persistent storage
- char *jsonStr = BinToCredJSON(cred);
+ char *jsonStr = BinToCredJSON(cred, true);
if (jsonStr)
{
cJSON *jsonCred = cJSON_Parse(jsonStr);
OCEntityHandlerResult ret = OC_EH_ERROR;
//Get binary representation of json
- OicSecCred_t * cred = JSONToCredBin(((OCSecurityPayload*)ehRequest->payload)->securityData);
+ OicSecCred_t * cred = JSONToCredBin(((OCSecurityPayload*)ehRequest->payload)->securityData, false);
if(cred)
{
ParseQueryIterInit((unsigned char *)ehRequest->query, &parseIter);
while(GetNextQuery(&parseIter))
{
- if(strncasecmp((char *)parseIter.attrPos, OIC_JSON_SUBJECT_NAME,
+ if(strncasecmp((char *)parseIter.attrPos, OIC_JSON_SUBJECTID_NAME,
parseIter.attrLen) == 0)
{
unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {};
if (jsonSVRDatabase)
{
//Convert JSON Cred into binary format
- gCred = JSONToCredBin(jsonSVRDatabase);
+ gCred = JSONToCredBin(jsonSVRDatabase, true);
}
/*
* If SVR database in persistent storage got corrupted or
}
}
-char *BinToCrlJSON(const OicSecCrl_t *crl)
+char *BinToCrlJSON(const OicSecCrl_t *crl, const bool isIncResName)
{
if (NULL == crl)
{
uint32_t base64CRLLen = 0;
B64Result b64Ret = B64_OK;
char *jsonStr = NULL;
+
cJSON *jsonRoot = cJSON_CreateObject();
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- cJSON *jsonCrl = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonCrl, ERROR);
- cJSON_AddItemToObject(jsonRoot, OIC_JSON_CRL_NAME, jsonCrl);
+ cJSON *jsonCrl = NULL;
+ if(isIncResName)
+ {
+ jsonCrl = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonCrl, ERROR);
+ cJSON_AddItemToObject(jsonRoot, OIC_JSON_CRL_NAME, jsonCrl);
+ }
+ else
+ {
+ jsonCrl = jsonRoot;
+ }
//CRLId -- Mandatory
cJSON_AddNumberToObject(jsonCrl, OIC_JSON_CRL_ID, (int)crl->CrlId);
return jsonStr;
}
-OicSecCrl_t *JSONToCrlBin(const char * jsonStr)
+OicSecCrl_t *JSONToCrlBin(const char * jsonStr, const bool isIncResName)
{
if (NULL == jsonStr)
{
cJSON *jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonCrl = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRL_NAME);
+ if(isIncResName)
+ {
+ jsonCrl = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRL_NAME);
+ }
+ else
+ {
+ jsonCrl = jsonRoot;
+ }
VERIFY_NON_NULL(TAG, jsonCrl, ERROR);
+
crl = (OicSecCrl_t *)OICCalloc(1, sizeof(OicSecCrl_t));
VERIFY_NON_NULL(TAG, crl, ERROR);
char *jsonStr = NULL;
OCStackResult res = OC_STACK_ERROR;
- jsonStr = BinToCrlJSON((OicSecCrl_t *) crl);
+ jsonStr = BinToCrlJSON((OicSecCrl_t *) crl, true);
if (!jsonStr)
{
return OC_STACK_ERROR;
cJSON *jsonObj = cJSON_Parse(jsonCRL);
OicSecCrl_t *crl = NULL;
- crl = JSONToCrlBin(jsonCRL);
+ crl = JSONToCrlBin(jsonCRL, false);
if (!crl)
{
OC_LOG(ERROR, TAG, "Error JSONToCrlBin");
if (jsonSVRDatabase)
{
//Convert JSON CRL into binary format
- gCrl = JSONToCrlBin(jsonSVRDatabase);
+ gCrl = JSONToCrlBin(jsonSVRDatabase, true);
}
/*
* If SVR database in persistent storage got corrupted or
if (jsonSVRDatabase)
{
//Convert JSON CRL into binary format
- crl = JSONToCrlBin(jsonSVRDatabase);
+ crl = JSONToCrlBin(jsonSVRDatabase, true);
}
/*
* If SVR database in persistent storage got corrupted or
static OicSecOxm_t gOicSecDoxmJustWorks = OIC_JUST_WORKS;
static OicSecDoxm_t gDefaultDoxm =
{
- NULL, /* OicUrn_t *oxmType */
- 0, /* size_t oxmTypeLen */
&gOicSecDoxmJustWorks, /* uint16_t *oxm */
1, /* size_t oxmLen */
OIC_JUST_WORKS, /* uint16_t oxmSel */
{
if (doxm)
{
- //Clean oxmType
- for (size_t i = 0; i < doxm->oxmTypeLen; i++)
- {
- OICFree(doxm->oxmType[i]);
- }
- OICFree(doxm->oxmType);
-
//clean oxm
OICFree(doxm->oxm);
}
}
-char * BinToDoxmJSON(const OicSecDoxm_t * doxm)
+char * BinToDoxmJSON(const OicSecDoxm_t * doxm, const bool isIncResName)
{
if (NULL == doxm)
{
cJSON *jsonRoot = cJSON_CreateObject();
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonDoxm = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
- cJSON_AddItemToObject(jsonRoot, OIC_JSON_DOXM_NAME, jsonDoxm );
-
- //OxmType -- Not Mandatory
- if(doxm->oxmTypeLen > 0)
+ if(isIncResName)
{
- cJSON *jsonOxmTyArray = cJSON_CreateArray();
- VERIFY_NON_NULL(TAG, jsonOxmTyArray, ERROR);
- cJSON_AddItemToObject (jsonDoxm, OIC_JSON_OXM_TYPE_NAME, jsonOxmTyArray );
- for (size_t i = 0; i < doxm->oxmTypeLen; i++)
- {
- cJSON_AddItemToArray (jsonOxmTyArray, cJSON_CreateString(doxm->oxmType[i]));
- }
+ jsonDoxm = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
+ cJSON_AddItemToObject(jsonRoot, OIC_JSON_DOXM_NAME, jsonDoxm );
+ }
+ else
+ {
+ jsonDoxm = jsonRoot;
}
//Oxm -- Not Mandatory
b64Ret = b64Encode(doxm->owner.id, sizeof(doxm->owner.id), base64Buff,
sizeof(base64Buff), &outLen);
VERIFY_SUCCESS(TAG, b64Ret == B64_OK, ERROR);
+ cJSON_AddStringToObject(jsonDoxm, OIC_JSON_DEV_OWNER_NAME, base64Buff);
+
+ outLen = 0;
+ b64Ret = b64Encode(doxm->owner.id, sizeof(doxm->owner.id), base64Buff,
+ sizeof(base64Buff), &outLen);
+ VERIFY_SUCCESS(TAG, b64Ret == B64_OK, ERROR);
+
+ //Rowner -- Mandatory
cJSON_AddStringToObject(jsonDoxm, OIC_JSON_OWNER_NAME, base64Buff);
jsonStr = cJSON_PrintUnformatted(jsonRoot);
return jsonStr;
}
-OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr)
+OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr, const bool isIncResName)
{
if (NULL == jsonStr)
cJSON *jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonDoxm = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME);
- VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
+ if(isIncResName)
+ {
+ jsonDoxm = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME);
+ VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
+ }
+ else
+ {
+ jsonDoxm = jsonRoot;
+ }
doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
VERIFY_NON_NULL(TAG, doxm, ERROR);
- //OxmType -- not Mandatory
- jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_TYPE_NAME);
- if ((jsonObj) && (cJSON_Array == jsonObj->type))
- {
- doxm->oxmTypeLen = cJSON_GetArraySize(jsonObj);
- VERIFY_SUCCESS(TAG, doxm->oxmTypeLen > 0, ERROR);
-
- doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(char *));
- VERIFY_NON_NULL(TAG, (doxm->oxmType), ERROR);
-
- for (size_t i = 0; i < doxm->oxmTypeLen ; i++)
- {
- cJSON *jsonOxmTy = cJSON_GetArrayItem(jsonObj, i);
- VERIFY_NON_NULL(TAG, jsonOxmTy, ERROR);
-
- jsonObjLen = strlen(jsonOxmTy->valuestring) + 1;
- doxm->oxmType[i] = (char*)OICMalloc(jsonObjLen);
- VERIFY_NON_NULL(TAG, doxm->oxmType[i], ERROR);
- strncpy((char *)doxm->oxmType[i], (char *)jsonOxmTy->valuestring, jsonObjLen);
- }
- }
-
//Oxm -- not Mandatory
jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_NAME);
if (jsonObj && cJSON_Array == jsonObj->type)
}
//Owner -- will be empty when device status is unowned.
- jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OWNER_NAME);
+ jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEV_OWNER_NAME);
if(true == doxm->owned)
{
VERIFY_NON_NULL(TAG, jsonObj, ERROR);
if (NULL != doxm)
{
// Convert Doxm data into JSON for update to persistent storage
- char *jsonStr = BinToDoxmJSON(doxm);
+ char *jsonStr = BinToDoxmJSON(doxm, true);
if (jsonStr)
{
cJSON *jsonDoxm = cJSON_Parse(jsonStr);
* return valid doxm resource json.
*/
- jsonStr = (ehRet == OC_EH_OK) ? BinToDoxmJSON(gDoxm) : NULL;
+ jsonStr = (ehRet == OC_EH_OK) ? BinToDoxmJSON(gDoxm, false) : NULL;
// Send response payload to request originator
if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, jsonStr))
* Convert JSON Doxm data into binary. This will also validate
* the Doxm data received.
*/
- OicSecDoxm_t* newDoxm = JSONToDoxmBin(((OCSecurityPayload*)ehRequest->payload)->securityData);
+ OicSecDoxm_t* newDoxm = JSONToDoxmBin(((OCSecurityPayload*)ehRequest->payload)->securityData, false);
if (newDoxm)
{
if(jsonSVRDatabase)
{
//Convert JSON DOXM into binary format
- gDoxm = JSONToDoxmBin(jsonSVRDatabase);
+ gDoxm = JSONToDoxmBin(jsonSVRDatabase, true);
}
/*
* If SVR database in persistent storage got corrupted or
}
}
-char * BinToPstatJSON(const OicSecPstat_t * pstat)
+char * BinToPstatJSON(const OicSecPstat_t * pstat, const bool isIncResName)
{
if(NULL == pstat)
{
char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*) 0)->id)) + 1] = {};
uint32_t outLen = 0;
B64Result b64Ret = B64_OK;
+ cJSON *jsonRoot = NULL;
- cJSON *jsonRoot = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonRoot, INFO);
+ if(isIncResName)
+ {
+ jsonRoot = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonRoot, INFO);
+ cJSON_AddItemToObject(jsonRoot, OIC_JSON_PSTAT_NAME, jsonPstat = cJSON_CreateObject());
+ }
+ else
+ {
+ jsonPstat = cJSON_CreateObject();
+ jsonRoot = jsonPstat;
+ }
+ VERIFY_NON_NULL(TAG, jsonPstat, INFO);
- cJSON_AddItemToObject(jsonRoot, OIC_JSON_PSTAT_NAME, jsonPstat=cJSON_CreateObject());
cJSON_AddBoolToObject(jsonPstat, OIC_JSON_ISOP_NAME, pstat->isOp);
b64Ret = b64Encode(pstat->deviceID.id,
return jsonStr;
}
-OicSecPstat_t * JSONToPstatBin(const char * jsonStr)
+OicSecPstat_t * JSONToPstatBin(const char * jsonStr, const bool isIncResName)
{
if(NULL == jsonStr)
{
cJSON *jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, INFO);
- jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
+ if(isIncResName)
+ {
+ jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
+ }
+ else
+ {
+ jsonPstat = jsonRoot;
+ }
VERIFY_NON_NULL(TAG, jsonPstat, INFO);
pstat = (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
{
OC_LOG (INFO, TAG, "HandlePstatGetRequest processing GET request");
// Convert ACL data into JSON for transmission
- char* jsonStr = BinToPstatJSON(gPstat);
+ char* jsonStr = BinToPstatJSON(gPstat, false);
// A device should always have a default pstat. Therefore, jsonStr should never be NULL.
OCEntityHandlerResult ehRet = (jsonStr ? OC_EH_OK : OC_EH_ERROR);
{
postJson = cJSON_Parse(((OCSecurityPayload*)ehRequest->payload)->securityData);
VERIFY_NON_NULL(TAG, postJson, INFO);
- cJSON *jsonPstat = cJSON_GetObjectItem(postJson, OIC_JSON_PSTAT_NAME);
- VERIFY_NON_NULL(TAG, jsonPstat, INFO);
- cJSON *commitHashJson = cJSON_GetObjectItem(jsonPstat, OIC_JSON_COMMIT_HASH_NAME);
+
+ cJSON *commitHashJson = cJSON_GetObjectItem(postJson, OIC_JSON_COMMIT_HASH_NAME);
uint16_t commitHash = 0;
if (commitHashJson)
{
commitHash = commitHashJson->valueint;
}
- cJSON *tmJson = cJSON_GetObjectItem(jsonPstat, OIC_JSON_TM_NAME);
+ cJSON *tmJson = cJSON_GetObjectItem(postJson, OIC_JSON_TM_NAME);
if (tmJson && gPstat)
{
gPstat->tm = (OicSecDpm_t)tmJson->valueint;
OC_LOG (INFO, TAG, "CommitHash is not valid");
}
}
- cJSON *omJson = cJSON_GetObjectItem(jsonPstat, OIC_JSON_OM_NAME);
+ cJSON *omJson = cJSON_GetObjectItem(postJson, OIC_JSON_OM_NAME);
if (omJson && gPstat)
{
/*
}
}
// Convert pstat data into JSON for update to persistent storage
- char *jsonStr = BinToPstatJSON(gPstat);
+ char *jsonStr = BinToPstatJSON(gPstat, true);
if (jsonStr)
{
cJSON *jsonPstat = cJSON_Parse(jsonStr);
if (jsonSVRDatabase)
{
// Convert JSON Pstat into binary format
- gPstat = JSONToPstatBin(jsonSVRDatabase);
+ gPstat = JSONToPstatBin(jsonSVRDatabase, true);
}
/*
* If SVR database in persistent storage got corrupted or
const char * OIC_RSRC_SVC_URI = "/oic/sec/svc";
const char * OIC_JSON_SVC_NAME = "svc";
-
-const char * OIC_JSON_SUBJECT_NAME = "sub";
-const char * OIC_JSON_RESOURCES_NAME = "rsrc";
+const char * OIC_JSON_SUBJECT_NAME = "subject";
+const char * OIC_JSON_RESOURCES_NAME = "resources";
const char * OIC_JSON_AMSS_NAME = "amss";
-const char * OIC_JSON_PERMISSION_NAME = "perms";
-const char * OIC_JSON_OWNERS_NAME = "ownrs";
-const char * OIC_JSON_OWNER_NAME = "ownr";
+const char * OIC_JSON_PERMISSION_NAME = "permission";
+const char * OIC_JSON_OWNER_NAME = "rowner";
+const char * OIC_JSON_OWNERS_NAME = "rowners";
+const char * OIC_JSON_DEV_OWNER_NAME = "devowner";
const char * OIC_JSON_OWNED_NAME = "owned";
const char * OIC_JSON_OXM_NAME = "oxm";
-const char * OIC_JSON_OXM_TYPE_NAME = "oxmtype";
const char * OIC_JSON_OXM_SEL_NAME = "oxmsel";
-const char * OIC_JSON_DEVICE_ID_FORMAT_NAME = "dvcidfrmt";
+const char * OIC_JSON_DEVICE_ID_FORMAT_NAME = "didformat";
const char * OIC_JSON_ISOP_NAME = "isop";
const char * OIC_JSON_COMMIT_HASH_NAME = "ch";
const char * OIC_JSON_DEVICE_ID_NAME = "deviceid";
const char * OIC_JSON_OM_NAME = "om";
const char * OIC_JSON_SM_NAME = "sm";
const char * OIC_JSON_CREDID_NAME = "credid";
-const char * OIC_JSON_SUBJECTID_NAME = "subid";
+const char * OIC_JSON_SUBJECTID_NAME = "subjectid";
const char * OIC_JSON_ROLEIDS_NAME = "roleid";
-const char * OIC_JSON_CREDTYPE_NAME = "credtyp";
-const char * OIC_JSON_PUBLICDATA_NAME = "pbdata";
-const char * OIC_JSON_PRIVATEDATA_NAME = "pvdata";
-const char * OIC_JSON_SERVICE_DEVICE_ID = "svcdid";
+const char * OIC_JSON_CREDTYPE_NAME = "credtype";
+const char * OIC_JSON_PUBLICDATA_NAME = "publicdata";
+const char * OIC_JSON_PRIVATEDATA_NAME = "privatedata";
+const char * OIC_JSON_SERVICE_DEVICE_ID = "svcid";
const char * OIC_JSON_SERVICE_TYPE = "svct";
-const char * OIC_JSON_PERIOD_NAME = "prd";
-const char * OIC_JSON_PERIODS_NAME = "prds";
-const char * OIC_JSON_RECURRENCES_NAME = "recurs";
+const char * OIC_JSON_PERIOD_NAME = "period";
+const char * OIC_JSON_PERIODS_NAME = "periods";
+const char * OIC_JSON_RECURRENCES_NAME = "recurrence";
const char * OIC_JSON_SUPPORTED_CRED_TYPE_NAME = "sct";
OicUuid_t WILDCARD_SUBJECT_ID = {"*"};
* Note: Caller needs to invoke 'free' when finished done using
* return string.
*/
-char * BinToSvcJSON(const OicSecSvc_t * svc)
+char * BinToSvcJSON(const OicSecSvc_t * svc, const bool isIncResName)
{
cJSON *jsonRoot = NULL;
char *jsonStr = NULL;
if (svc)
{
- jsonRoot = cJSON_CreateObject();
- VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
-
cJSON *jsonSvcArray = NULL;
- cJSON_AddItemToObject (jsonRoot, OIC_JSON_SVC_NAME, jsonSvcArray = cJSON_CreateArray());
+ if(isIncResName)
+ {
+ jsonRoot = cJSON_CreateObject();
+ VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
+
+ cJSON_AddItemToObject (jsonRoot, OIC_JSON_SVC_NAME, jsonSvcArray = cJSON_CreateArray());
+ }
+ else
+ {
+ jsonSvcArray = cJSON_CreateArray();
+ jsonRoot = jsonSvcArray;
+ }
VERIFY_NON_NULL(TAG, jsonSvcArray, ERROR);
while(svc)
/*
* This internal method converts JSON SVC into binary SVC.
*/
-OicSecSvc_t * JSONToSvcBin(const char * jsonStr)
+OicSecSvc_t * JSONToSvcBin(const char * jsonStr, const bool isIncResName)
{
OCStackResult ret = OC_STACK_ERROR;
OicSecSvc_t * headSvc = NULL;
jsonRoot = cJSON_Parse(jsonStr);
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
- jsonSvcArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME);
+ if(isIncResName)
+ {
+ jsonSvcArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME);
+ }
+ else
+ {
+ jsonSvcArray = jsonRoot;
+ }
VERIFY_NON_NULL(TAG, jsonSvcArray, INFO);
if (cJSON_Array == jsonSvcArray->type)
static OCEntityHandlerResult HandleSVCGetRequest (const OCEntityHandlerRequest * ehRequest)
{
// Convert SVC data into JSON for transmission
- char* jsonStr = BinToSvcJSON(gSvc);
+ char* jsonStr = BinToSvcJSON(gSvc, false);
OCEntityHandlerResult ehRet = (jsonStr ? OC_EH_OK : OC_EH_ERROR);
OCEntityHandlerResult ehRet = OC_EH_ERROR;
// Convert JSON SVC data into binary. This will also validate the SVC data received.
- OicSecSvc_t* newSvc = JSONToSvcBin(((OCSecurityPayload*)ehRequest->payload)->securityData);
+ OicSecSvc_t* newSvc = JSONToSvcBin(((OCSecurityPayload*)ehRequest->payload)->securityData, false);
if (newSvc)
{
LL_APPEND(gSvc, newSvc);
// Convert SVC data into JSON for update to persistent storage
- char *jsonStr = BinToSvcJSON(gSvc);
+ char *jsonStr = BinToSvcJSON(gSvc, true);
if (jsonStr)
{
cJSON *jsonSvc = cJSON_Parse(jsonStr);
if (jsonSVRDatabase)
{
// Convert JSON SVC into binary format
- gSvc = JSONToSvcBin(jsonSVRDatabase);
+ gSvc = JSONToSvcBin(jsonSVRDatabase, true);
OICFree(jsonSVRDatabase);
}
unittest_src_dir + 'oic_unittest.json'))
srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
unittest_src_dir + 'oic_unittest_acl1.json'))
+srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
+ unittest_src_dir + 'oic_unittest_acl_payload.json'))
srmtest_env.Alias("install", srmtest_env.Install( unittest_build_dir,
unittest_src_dir + 'oic_unittest_default_acl.json'))
extern "C" {
#endif
-extern char * BinToAclJSON(const OicSecAcl_t * acl);
-extern OicSecAcl_t * JSONToAclBin(const char * jsonStr);
+extern char * BinToAclJSON(const OicSecAcl_t * acl, const bool isIncResName);
+extern OicSecAcl_t * JSONToAclBin(const char * jsonStr, const bool isIncResName);
extern void DeleteACLList(OicSecAcl_t* acl);
OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl);
OCEntityHandlerResult ACLEntityHandler (OCEntityHandlerFlag flag,
const char* JSON_FILE_NAME = "oic_unittest.json";
const char* DEFAULT_ACL_JSON_FILE_NAME = "oic_unittest_default_acl.json";
const char* ACL1_JSON_FILE_NAME = "oic_unittest_acl1.json";
+const char* ACL_JSON_PAYLOAD_FILE_NAME = "oic_unittest_acl_payload.json";
+
#define NUM_ACE_FOR_WILDCARD_IN_ACL1_JSON (2)
}
jsonStr1[len + 1] = 0;
- OicSecAcl_t * acl = JSONToAclBin(jsonStr1);
+ OicSecAcl_t * acl = JSONToAclBin(jsonStr1, true);
EXPECT_TRUE(NULL != acl);
- char * jsonStr2 = BinToAclJSON(acl);
+ char * jsonStr2 = BinToAclJSON(acl, true);
EXPECT_TRUE(NULL != jsonStr2);
EXPECT_STREQ(jsonStr1, jsonStr2);
char *jsonStr = ReadFile(DEFAULT_ACL_JSON_FILE_NAME);
if (jsonStr)
{
- OicSecAcl_t * acl = JSONToAclBin(jsonStr);
+ OicSecAcl_t * acl = JSONToAclBin(jsonStr, true);
EXPECT_TRUE(NULL != acl);
// Invoke API to generate default ACL
OCEntityHandlerRequest ehReq = OCEntityHandlerRequest();
// Read an ACL from the file
- char *jsonStr = ReadFile(ACL1_JSON_FILE_NAME);
+ char *jsonStr = ReadFile(ACL_JSON_PAYLOAD_FILE_NAME);
if (jsonStr)
{
static OCPersistentStorage ps = OCPersistentStorage();
EXPECT_TRUE(OC_EH_ERROR == ehRet);
// Convert JSON into OicSecAcl_t for verification
- OicSecAcl_t * acl = JSONToAclBin(jsonStr);
+ OicSecAcl_t * acl = JSONToAclBin(jsonStr, false);
EXPECT_TRUE(NULL != acl);
// Verify if SRM contains ACL for the subject
extern OicSecAcl_t *gAcl;
// Read an ACL from the file
- char *jsonStr = ReadFile(ACL1_JSON_FILE_NAME);
+ char *jsonStr = ReadFile(ACL_JSON_PAYLOAD_FILE_NAME);
if (jsonStr)
{
- gAcl = JSONToAclBin(jsonStr);
+ gAcl = JSONToAclBin(jsonStr, false);
EXPECT_TRUE(NULL != gAcl);
// Verify that ACL file contains 2 ACE entries for 'WILDCARD' subject
VERIFY_SUCCESS(TAG, (OC_STACK_OK == populateAcl(&acl, 1)), ERROR);
//GET json POST payload
- jsonStr = BinToAclJSON(&acl);
+ jsonStr = BinToAclJSON(&acl, false);
VERIFY_NON_NULL(TAG, jsonStr, ERROR);
// Create Entity Handler POST request payload
VERIFY_SUCCESS(TAG, (OC_STACK_OK == populateAcl(&acl, 2)), ERROR);
//GET json POST payload
- jsonStr = BinToAclJSON(&acl);
+ jsonStr = BinToAclJSON(&acl, false);
VERIFY_NON_NULL(TAG, jsonStr, ERROR);
// Create Entity Handler POST request payload
ehRet = ACLEntityHandler(OC_REQUEST_FLAG, &ehReq);
EXPECT_TRUE(OC_EH_ERROR == ehRet);
- // Verify if SRM contains ACL for the subject but only with one resource
- savePtr = NULL;
- subjectAcl2 = GetACLResourceData(&acl.subject, &savePtr);
- EXPECT_TRUE(NULL != subjectAcl2);
- EXPECT_TRUE(subjectAcl2->resourcesLen == 1);
-
exit:
// Perform cleanup
if(NULL != subjectAcl1)
VERIFY_SUCCESS(TAG, (OC_STACK_OK == populateAcl(&acl, 1)), ERROR);
//GET json POST payload
- jsonStr = BinToAclJSON(&acl);
+ jsonStr = BinToAclJSON(&acl, false);
VERIFY_NON_NULL(TAG, jsonStr, ERROR);
//Create Entity Handler POST request payload
OCStackResult CreateCredResource();
OCEntityHandlerResult CredEntityHandler (OCEntityHandlerFlag flag,
OCEntityHandlerRequest * ehRequest);
-char * BinToCredJSON(const OicSecCred_t * pstat);
-OicSecCred_t * JSONToCredBin(const char * jsonStr);
+char * BinToCredJSON(const OicSecCred_t * pstat, const bool isIncResName);
+OicSecCred_t * JSONToCredBin(const char * jsonStr, const bool isIncResName);
void InitSecCredInstance(OicSecCred_t * cred);
void DeleteCredList(OicSecCred_t* cred);
const OicSecCred_t* GetCredResourceData(const OicUuid_t* subject);
OicSecCred_t *cred = getCredList();
VERIFY_NON_NULL(TAG, cred, ERROR);
- jsonStr = BinToCredJSON(cred);
+ jsonStr = BinToCredJSON(cred, false);
VERIFY_NON_NULL(TAG, jsonStr, ERROR);
// Create Entity Handler POST request payload
//BinToCredJSON Tests
TEST(BinToCredJSONTest, BinToCredJSONNullCred)
{
- char* value = BinToCredJSON(NULL);
+ char* value = BinToCredJSON(NULL, true);
EXPECT_TRUE(value == NULL);
}
char* json = NULL;
OicSecCred_t * cred = getCredList();
- json = BinToCredJSON(cred);
+ json = BinToCredJSON(cred, true);
OC_LOG_V(INFO, TAG, "BinToCredJSON:%s\n", json);
EXPECT_TRUE(json != NULL);
TEST(JSONToCredBinTest, JSONToCredBinValidJSON)
{
OicSecCred_t* cred1 = getCredList();
- char* json = BinToCredJSON(cred1);
+ char* json = BinToCredJSON(cred1, true);
EXPECT_TRUE(json != NULL);
- OicSecCred_t *cred2 = JSONToCredBin(json);
+ OicSecCred_t *cred2 = JSONToCredBin(json, true);
EXPECT_TRUE(cred2 != NULL);
DeleteCredList(cred1);
DeleteCredList(cred2);
TEST(JSONToCredBinTest, JSONToCredBinNullJSON)
{
- OicSecCred_t *cred = JSONToCredBin(NULL);
+ OicSecCred_t *cred = JSONToCredBin(NULL, true);
EXPECT_TRUE(cred == NULL);
}
OCStackResult CreateDoxmResource();
OCEntityHandlerResult DoxmEntityHandler (OCEntityHandlerFlag flag,
OCEntityHandlerRequest * ehRequest);
-char * BinToDoxmJSON(const OicSecDoxm_t * doxm);
-OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr);
+char * BinToDoxmJSON(const OicSecDoxm_t * doxm, const bool isIncResName);
+OicSecDoxm_t * JSONToDoxmBin(const char * jsonStr, const bool isIncResName);
void InitSecDoxmInstance(OicSecDoxm_t * doxm);
OCEntityHandlerResult HandleDoxmPostRequest (const OCEntityHandlerRequest * ehRequest);
void DeleteDoxmBinData(OicSecDoxm_t* doxm);
{
return NULL;
}
- doxm->oxmTypeLen = 1;
- doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(char *));
- if(!doxm->oxmType)
- {
- OICFree(doxm);
- return NULL;
- }
- doxm->oxmType[0] = (char*)OICMalloc(strlen(OXM_JUST_WORKS) + 1);
- if(!doxm->oxmType[0])
- {
- OICFree(doxm->oxmType);
- OICFree(doxm);
- return NULL;
- }
-
- strcpy(doxm->oxmType[0], OXM_JUST_WORKS);
- doxm->oxmLen = 1;
+ doxm->oxmLen = 1;
doxm->oxm = (OicSecOxm_t *)OICCalloc(doxm->oxmLen, sizeof(OicSecOxm_t));
if(!doxm->oxm)
{
- OICFree(doxm->oxmType[0]);
- OICFree(doxm->oxmType);
OICFree(doxm);
return NULL;
}
//BinToDoxmJSON Tests
TEST(BinToDoxmJSONTest, BinToDoxmJSONNullDoxm)
{
- char* value = BinToDoxmJSON(NULL);
+ char* value = BinToDoxmJSON(NULL, true);
EXPECT_TRUE(value == NULL);
}
{
OicSecDoxm_t * doxm = getBinDoxm();
- char * json = BinToDoxmJSON(doxm);
+ char * json = BinToDoxmJSON(doxm, true);
OC_LOG_V(INFO, TAG, "BinToDoxmJSON:%s", json);
EXPECT_TRUE(json != NULL);
TEST(JSONToDoxmBinTest, JSONToDoxmBinValidJSON)
{
OicSecDoxm_t * doxm1 = getBinDoxm();
- char * json = BinToDoxmJSON(doxm1);
+ char * json = BinToDoxmJSON(doxm1, true);
EXPECT_TRUE(json != NULL);
- OicSecDoxm_t *doxm2 = JSONToDoxmBin(json);
+ OicSecDoxm_t *doxm2 = JSONToDoxmBin(json, true);
EXPECT_TRUE(doxm2 != NULL);
DeleteDoxmBinData(doxm1);
TEST(JSONToDoxmBinTest, JSONToDoxmBinNullJSON)
{
- OicSecDoxm_t *doxm = JSONToDoxmBin(NULL);
+ OicSecDoxm_t *doxm = JSONToDoxmBin(NULL, true);
EXPECT_TRUE(doxm == NULL);
}
svRequest.addressInfo.IP.port = 2345;
svRequest.connectivityType = CA_ETHERNET;
- ehRequest.reqJSONPayload = (unsigned char *) BinToDoxmJSON(doxm);
+ ehRequest.reqJSONPayload = (unsigned char *) BinToDoxmJSON(doxm, true);
ehRequest.requestHandle = (OCRequestHandle) &svRequest;
EXPECT_EQ(OC_EH_ERROR, HandleDoxmPostRequest(&ehRequest));
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/res/types/d",
"/oic/ad"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat",
"/oic/sec/acl"
],
- "perms": 6,
- "ownrs" : [
+ "permission": 6,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
}
{
"acl": [
{
- "sub": "MTExMTExMTExMTExMTExMQ==",
- "rsrc": [
+ "subject": "MTExMTExMTExMTExMTExMQ==",
+ "resources": [
"/oic/light",
"/oic/fan"
],
- "perms": 255,
- "ownrs" : [
+ "permission": 255,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
},
{
- "sub": "MzMzMzMzMzMzMzMzMzMzMw==",
- "rsrc": [
+ "subject": "MzMzMzMzMzMzMzMzMzMzMw==",
+ "resources": [
"/oic/light",
"/oic/garage"
],
- "perms": 255,
- "ownrs" : [
+ "permission": 255,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg==",
"NDQ0NDQ0NDQ0NDQ0NDQ0NA=="
]
"amacl": [
{
- "rsrc": ["/a/led", "/a/fan"],
+ "resources": ["/a/led", "/a/fan"],
"amss": [
"NTU1NTU1NTU1NTU1NTU1NQ==",
"NjY2NjY2NjY2NjY2NjY2Ng=="
],
- "ownrs" : [
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
},
{
- "rsrc": ["/b/led", "/b/fan"],
+ "resources": ["/b/led", "/b/fan"],
"amss": [
"NTU1NTU1NTU1NTU1NTU1NQ==",
"NjY2NjY2NjY2NjY2NjY2Ng=="
],
- "ownrs" : [
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
}
"svc": [
{
- "svcdid": "NTU1NTU1NTU1NTU1NTU1NQ==",
+ "svcid": "NTU1NTU1NTU1NTU1NTU1NQ==",
"svct": 1,
- "ownrs" : [
+ "rowners" : [
"OTk5OTk5OTk5OTk5OTk5OQ=="
]
},
{
- "svcdid": "NjY2NjY2NjY2NjY2NjY2Ng==",
+ "svcid": "NjY2NjY2NjY2NjY2NjY2Ng==",
"svct": 1,
- "ownrs" : [
+ "rowners" : [
"OTk5OTk5OTk5OTk5OTk5OQ=="
]
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/ad",
"/oic/sec/acl"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 6,
- "ownrs" : [
+ "permission": 6,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
},
{
- "sub": "MTExMTExMTExMTExMTExMQ==",
- "rsrc": [
+ "subject": "MTExMTExMTExMTExMTExMQ==",
+ "resources": [
"/oic/light",
"/oic/fan"
],
- "perms": 255,
- "ownrs" : [
+ "permission": 255,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
},
{
- "sub": "MzMzMzMzMzMzMzMzMzMzMw==",
- "rsrc": [
+ "subject": "MzMzMzMzMzMzMzMzMzMzMw==",
+ "resources": [
"/oic/light",
"/oic/garage"
],
- "perms": 255,
- "ownrs" : [
+ "permission": 255,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg==",
"NDQ0NDQ0NDQ0NDQ0NDQ0NA=="
]
--- /dev/null
+[
+ {
+ "subject": "Kg==",
+ "resources": [
+ "/oic/res",
+ "/oic/d",
+ "/oic/p",
+ "/oic/res/types/d",
+ "/oic/ad",
+ "/oic/sec/acl"
+ ],
+ "permission": 2,
+ "rowners" : [
+ "MjIyMjIyMjIyMjIyMjIyMg=="
+ ]
+ },
+ {
+ "subject": "Kg==",
+ "resources": [
+ "/oic/sec/doxm",
+ "/oic/sec/pstat"
+ ],
+ "permission": 6,
+ "rowners" : [
+ "MjIyMjIyMjIyMjIyMjIyMg=="
+ ]
+ },
+ {
+ "subject": "MTExMTExMTExMTExMTExMQ==",
+ "resources": [
+ "/oic/light",
+ "/oic/fan"
+ ],
+ "permission": 255,
+ "rowners" : [
+ "MjIyMjIyMjIyMjIyMjIyMg=="
+ ]
+ },
+ {
+ "subject": "MzMzMzMzMzMzMzMzMzMzMw==",
+ "resources": [
+ "/oic/light",
+ "/oic/garage"
+ ],
+ "permission": 255,
+ "rowners" : [
+ "MjIyMjIyMjIyMjIyMjIyMg==",
+ "NDQ0NDQ0NDQ0NDQ0NDQ0NA=="
+ ]
+ }
+]
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 2,
- "ownrs" : [
+ "permission": 2,
+ "rowners" : [
"MjIyMjIyMjIyMjIyMjIyMg=="
]
}
OCStackResult CreatePstatResource();
OCEntityHandlerResult PstatEntityHandler (OCEntityHandlerFlag flag,
OCEntityHandlerRequest * ehRequest);
-char * BinToPstatJSON(const OicSecPstat_t * pstat);
-OicSecPstat_t * JSONToPstatBin(const char * jsonStr);
+char * BinToPstatJSON(const OicSecPstat_t * pstat, const bool isIncResName);
+OicSecPstat_t * JSONToPstatBin(const char * jsonStr, const bool isIncResName);
const char* UNIT_TEST_JSON_FILE_NAME = "oic_unittest.json";
#ifdef __cplusplus
}
//BinToJSON Tests
TEST(BinToJSONTest, BinToNullJSON)
{
- char* value = BinToPstatJSON(NULL);
+ char* value = BinToPstatJSON(NULL, true);
EXPECT_TRUE(value == NULL);
}
TEST(JSONToBinTest, NullJSONToBin)
{
- OicSecPstat_t *pstat1 = JSONToPstatBin(NULL);
+ OicSecPstat_t *pstat1 = JSONToPstatBin(NULL, true);
EXPECT_TRUE(pstat1 == NULL);
}
}
pstat.sm[0] = SINGLE_SERVICE_CLIENT_DRIVEN;
pstat.sm[1] = SINGLE_SERVICE_SERVER_DRIVEN;
- char* jsonPstat = BinToPstatJSON(&pstat);
+ char* jsonPstat = BinToPstatJSON(&pstat, true);
if(!jsonPstat)
{
OICFree(pstat.sm);
}
printf("BinToJSON Dump:\n%s\n\n", jsonPstat);
EXPECT_TRUE(jsonPstat != NULL);
- OicSecPstat_t *pstat1 = JSONToPstatBin(jsonPstat);
+ OicSecPstat_t *pstat1 = JSONToPstatBin(jsonPstat, true);
EXPECT_TRUE(pstat1 != NULL);
if(pstat1)
{
}
jsonStr1[len + 1] = 0;
- OicSecPstat_t* pstat = JSONToPstatBin(jsonStr1);
+ OicSecPstat_t* pstat = JSONToPstatBin(jsonStr1, true);
EXPECT_TRUE(NULL != pstat);
- char* jsonStr2 = BinToPstatJSON(pstat);
+ char* jsonStr2 = BinToPstatJSON(pstat, true);
EXPECT_STRNE(jsonStr1, jsonStr2);
OICFree(jsonStr1);
#ifdef __cplusplus
extern "C" {
#endif
-extern char * BinToSvcJSON(const OicSecSvc_t * svc);
-extern OicSecSvc_t * JSONToSvcBin(const char * jsonStr);
+extern char * BinToSvcJSON(const OicSecSvc_t * svc, const bool isIncResName);
+extern OicSecSvc_t * JSONToSvcBin(const char * jsonStr, const bool isIncResName);
extern void DeleteSVCList(OicSecSvc_t* svc);
#ifdef __cplusplus
}
char *jsonStr1 = ReadFile(JSON_FILE_NAME);
if (jsonStr1)
{
- OicSecSvc_t * svc = JSONToSvcBin(jsonStr1);
+ OicSecSvc_t * svc = JSONToSvcBin(jsonStr1, true);
EXPECT_TRUE(NULL != svc);
int cnt = 0;
}
EXPECT_EQ(cnt, NUM_SVC_IN_JSON_DB);
- char * jsonStr2 = BinToSvcJSON(svc);
+ char * jsonStr2 = BinToSvcJSON(svc, true);
EXPECT_TRUE(NULL != jsonStr2);
OICFree(jsonStr1);
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/sec/acl",
"/oic/sec/amacl"
],
- "perms": 2,
- "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+ "permission": 2,
+ "rowners" : ["MTExMTExMTExMTExMTExMQ=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 2,
- "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+ "permission": 2,
+ "rowners" : ["MTExMTExMTExMTExMTExMQ=="]
},
{
- "sub": "MjIyMjIyMjIyMjIyMjIyMg==",
- "rsrc": ["/oic/sec/acl",
+ "subject": "MjIyMjIyMjIyMjIyMjIyMg==",
+ "resources": ["/oic/sec/acl",
"/oic/sec/cred"],
- "perms": 8,
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "permission": 8,
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
- "sub": "NDQ0NDMzMzMyMjIyMTExMQ==",
- "rsrc": ["/a/led"],
- "perms": 6,
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subject": "NDQ0NDMzMzMyMjIyMTExMQ==",
+ "resources": ["/a/led"],
+ "permission": 6,
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}
],
"pstat": {
"sct": 1,
"owned": true,
"deviceid": "MTkxOTE5MTkxOTE5MTkxOQ==",
- "ownr": "YWRtaW5EZXZpY2VVVUlEAA=="
+ "devowner": "YWRtaW5EZXZpY2VVVUlEAA=="
},
"cred": [{
"credid": 1,
- "sub": "MTExMTExMTExMTExMTExMQ==",
- "credtyp": 1,
- "pvdata": "QkJCQkJCQkJCQkJCQkJCQg==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "MTExMTExMTExMTExMTExMQ==",
+ "credtype": 1,
+ "privatedata": "QkJCQkJCQkJCQkJCQkJCQg==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}]
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/sec/acl",
"/oic/sec/amacl"
],
- "perms": 2,
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "permission": 2,
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 2,
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "permission": 2,
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}
],
"pstat": {
"sct": 1,
"owned": true,
"deviceid": "MjIyMjIyMjIyMjIyMjIyMg==",
- "ownr": "MjIyMjIyMjIyMjIyMjIyMg=="
+ "devowner": "MjIyMjIyMjIyMjIyMjIyMg=="
},
"cred": [{
"credid": 1,
- "sub": "MTExMTExMTExMTExMTExMQ==",
- "credtyp": 1,
- "prd": "20150630T060000/20990920T220000",
- "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "MTExMTExMTExMTExMTExMQ==",
+ "credtype": 1,
+ "period": "20150630T060000/20990920T220000",
+ "privatedata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}]
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/sec/acl",
"/oic/sec/amacl"
],
- "perms": 2,
- "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+ "permission": 2,
+ "rowners" : ["MTExMTExMTExMTExMTExMQ=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 2,
- "ownrs" : ["MTExMTExMTExMTExMTExMQ=="]
+ "permission": 2,
+ "rowners" : ["MTExMTExMTExMTExMTExMQ=="]
},
{
- "sub": "MjIyMjIyMjIyMjIyMjIyMg==",
- "rsrc": ["/oic/sec/acl",
+ "subject": "MjIyMjIyMjIyMjIyMjIyMg==",
+ "resources": ["/oic/sec/acl",
"/oic/sec/cred"],
- "perms": 8,
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "permission": 8,
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
- "sub": "MjIyMjIyMjIyMjIyMjIyMg==",
- "rsrc": ["/a/led"],
- "perms": 6,
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subject": "MjIyMjIyMjIyMjIyMjIyMg==",
+ "resources": ["/a/led"],
+ "permission": 6,
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
- "sub": "MTExMTIyMjIzMzMzNDQ0NA==",
- "rsrc": ["/a/led"],
- "perms": 6,
- "prds" : ["20150630T060000/20150630T220000", "20150630T060000/20150630T200000"],
- "recurs" : ["FREQ=DAILY; BYDAY=MO, WE, FR", "FREQ=DAILY; BYDAY=TU, TH; UNTIL=20160630"],
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subject": "MTExMTIyMjIzMzMzNDQ0NA==",
+ "resources": ["/a/led"],
+ "permission": 6,
+ "periods" : ["20150630T060000/20150630T220000", "20150630T060000/20150630T200000"],
+ "recurrence" : ["FREQ=DAILY; BYDAY=MO, WE, FR", "FREQ=DAILY; BYDAY=TU, TH; UNTIL=20160630"],
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
- "sub": "Nzc3Nzc3Nzc3Nzc3Nzc3Nw==",
- "rsrc": ["/a/led"],
- "perms": 6,
- "prds" : ["20150630T060000/20150630T220000"],
- "recurs" : ["FREQ=DAILY; UNTIL=20150630"],
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subject": "Nzc3Nzc3Nzc3Nzc3Nzc3Nw==",
+ "resources": ["/a/led"],
+ "permission": 6,
+ "periods" : ["20150630T060000/20150630T220000"],
+ "recurrence" : ["FREQ=DAILY; UNTIL=20150630"],
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}
],
"amacl": [{
- "rsrc" : ["/a/led"],
+ "resources" : ["/a/led"],
"amss" : ["MTkxOTE5MTkxOTE5MTkxOQ=="],
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}],
"pstat": {
"isop": true,
"sct": 1,
"owned": true,
"deviceid": "MTExMTExMTExMTExMTExMQ==",
- "ownr": "YWRtaW5EZXZpY2VVVUlEAA=="
+ "devowner": "YWRtaW5EZXZpY2VVVUlEAA=="
},
"cred": [{
"credid": 1,
- "sub": "MjIyMjIyMjIyMjIyMjIyMg==",
- "credtyp": 1,
- "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "MjIyMjIyMjIyMjIyMjIyMg==",
+ "credtype": 1,
+ "privatedata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
"credid": 2,
- "sub": "MTExMTIyMjIzMzMzNDQ0NA==",
- "credtyp": 1,
- "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "MTExMTIyMjIzMzMzNDQ0NA==",
+ "credtype": 1,
+ "privatedata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
"credid": 3,
- "sub": "Nzc3Nzc3Nzc3Nzc3Nzc3Nw==",
- "credtyp": 1,
- "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "Nzc3Nzc3Nzc3Nzc3Nzc3Nw==",
+ "credtype": 1,
+ "privatedata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
"credid": 4,
- "sub": "NDQ0NDMzMzMyMjIyMTExMQ==",
- "credtyp": 1,
- "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "NDQ0NDMzMzMyMjIyMTExMQ==",
+ "credtype": 1,
+ "privatedata": "QUFBQUFBQUFBQUFBQUFBQQ==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
},
{
"credid": 5,
- "sub": "MTkxOTE5MTkxOTE5MTkxOQ==",
- "credtyp": 1,
- "pvdata": "QkJCQkJCQkJCQkJCQkJCQg==",
- "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
+ "subjectid": "MTkxOTE5MTkxOTE5MTkxOQ==",
+ "credtype": 1,
+ "privatedata": "QkJCQkJCQkJCQkJCQkJCQg==",
+ "rowners" : ["MjIyMjIyMjIyMjIyMjIyMg=="]
}]
}
{
"acl": [
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/res",
"/oic/d",
"/oic/p",
"/oic/ad",
"/oic/sec/amacl"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
},
{
- "sub": "Kg==",
- "rsrc": [
+ "subject": "Kg==",
+ "resources": [
"/oic/sec/doxm",
"/oic/sec/pstat"
],
- "perms": 2,
- "ownrs" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
+ "permission": 2,
+ "rowners" : ["YWRtaW5EZXZpY2VVVUlEMA=="]
}
],
"pstat": {
"sct": 1,
"owned": true,
"deviceid": "YWRtaW5EZXZpY2VVVUlEMA==",
- "ownr": "YWRtaW5EZXZpY2VVVUlEMA=="
+ "devowner": "YWRtaW5EZXZpY2VVVUlEMA=="
}
}