1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 #include "cainterface.h"
28 #include "oic_malloc.h"
29 #include "oic_string.h"
30 #include "ocpayload.h"
31 #include "ocpayloadcbor.h"
32 #include "payload_logging.h"
33 #include "secureresourcemanager.h"
34 #include "srmresourcestrings.h"
35 #include "srmutility.h"
36 #include "aclresource.h"
37 #include "pstatresource.h"
38 #include "doxmresource.h"
39 #include "amaclresource.h"
40 #include "credresource.h"
41 #include "svcresource.h"
42 #include "security_internals.h"
44 #define TAG "OIC_JSON2CBOR"
45 #define MAX_RANGE ((size_t)-1)
46 //SVR database buffer block size
47 static const size_t DB_FILE_SIZE_BLOCK = 1023;
49 static OicSecPstat_t* JSONToPstatBin(const char * jsonStr);
50 static OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr);
51 static OicSecAcl_t *JSONToAclBin(const char * jsonStr);
52 static OicSecSvc_t* JSONToSvcBin(const char * jsonStr);
53 static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr);
54 static OicSecCred_t* JSONToCredBin(const char * jsonStr);
56 static size_t GetJSONFileSize(const char *jsonFileName)
60 char buffer[DB_FILE_SIZE_BLOCK];
61 FILE* fp = fopen(jsonFileName, "r");
66 bytesRead = fread(buffer, 1, DB_FILE_SIZE_BLOCK, fp);
67 if (bytesRead >=(MAX_RANGE - size))
73 } while (bytesRead > 0);
79 static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName)
84 uint8_t *aclCbor = NULL;
85 uint8_t *pstatCbor = NULL;
86 uint8_t *doxmCbor = NULL;
87 uint8_t *amaclCbor = NULL;
88 uint8_t *svcCbor = NULL;
89 uint8_t *credCbor = NULL;
90 cJSON *jsonRoot = NULL;
91 OCStackResult ret = OC_STACK_ERROR;
92 size_t size = GetJSONFileSize(jsonFileName);
95 OIC_LOG (ERROR, TAG, "Failed converting to JSON");
99 jsonStr = (char *)OICMalloc(size + 1);
100 VERIFY_NON_NULL(TAG, jsonStr, FATAL);
102 fp = fopen(jsonFileName, "r");
105 size_t bytesRead = fread(jsonStr, 1, size, fp);
106 jsonStr[bytesRead] = '\0';
108 OIC_LOG_V(DEBUG, TAG, "Read %zu bytes", bytesRead);
114 OIC_LOG (ERROR, TAG, "Unable to open JSON file!!");
118 jsonRoot = cJSON_Parse(jsonStr);
120 cJSON *value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME);
121 //printf("ACL json : \n%s\n", cJSON_PrintUnformatted(value));
122 size_t aclCborSize = 0;
125 OicSecAcl_t *acl = JSONToAclBin(jsonStr);
126 VERIFY_NON_NULL(TAG, acl, FATAL);
127 ret = AclToCBORPayload(acl, &aclCbor, &aclCborSize);
128 if(OC_STACK_OK != ret)
130 OIC_LOG (ERROR, TAG, "Failed converting Acl to Cbor Payload");
134 printf("ACL Cbor Size: %zd\n", aclCborSize);
138 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
139 size_t pstatCborSize = 0;
142 OicSecPstat_t *pstat = JSONToPstatBin(jsonStr);
143 VERIFY_NON_NULL(TAG, pstat, FATAL);
144 ret = PstatToCBORPayload(pstat, &pstatCbor, &pstatCborSize, false);
145 if(OC_STACK_OK != ret)
147 OIC_LOG (ERROR, TAG, "Failed converting Pstat to Cbor Payload");
148 DeletePstatBinData(pstat);
151 printf("PSTAT Cbor Size: %zd\n", pstatCborSize);
152 DeletePstatBinData(pstat);
154 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME);
155 size_t doxmCborSize = 0;
158 OicSecDoxm_t *doxm = JSONToDoxmBin(jsonStr);
159 VERIFY_NON_NULL(TAG, doxm, FATAL);
160 ret = DoxmToCBORPayload(doxm, &doxmCbor, &doxmCborSize, false);
161 if(OC_STACK_OK != ret)
163 OIC_LOG (ERROR, TAG, "Failed converting Doxm to Cbor Payload");
164 DeleteDoxmBinData(doxm);
167 printf("DOXM Cbor Size: %zd\n", doxmCborSize);
168 DeleteDoxmBinData(doxm);
170 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME);
171 size_t amaclCborSize = 0;
174 OicSecAmacl_t *amacl = JSONToAmaclBin(jsonStr);
175 VERIFY_NON_NULL(TAG, amacl, FATAL);
176 ret = AmaclToCBORPayload(amacl, &amaclCbor, &amaclCborSize);
177 if(OC_STACK_OK != ret)
179 OIC_LOG (ERROR, TAG, "Failed converting Amacl to Cbor Payload");
180 DeleteAmaclList(amacl);
183 printf("AMACL Cbor Size: %zd\n", amaclCborSize);
184 DeleteAmaclList(amacl);
186 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME);
187 size_t svcCborSize = 0;
190 OicSecSvc_t *svc = JSONToSvcBin(jsonStr);
191 VERIFY_NON_NULL(TAG, svc, FATAL);
192 ret = SVCToCBORPayload(svc, &svcCbor, &svcCborSize);
193 if(OC_STACK_OK != ret)
195 OIC_LOG (ERROR, TAG, "Failed converting Svc to Cbor Payload");
199 printf("SVC Cbor Size: %zd\n", svcCborSize);
202 value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME);
203 //printf("CRED json : \n%s\n", cJSON_PrintUnformatted(value));
204 size_t credCborSize = 0;
208 OicSecCred_t *cred = JSONToCredBin(jsonStr);
209 VERIFY_NON_NULL(TAG, cred, FATAL);
210 ret = CredToCBORPayload(cred, &credCbor, &credCborSize, secureFlag);
211 if(OC_STACK_OK != ret)
213 OIC_LOG (ERROR, TAG, "Failed converting Cred to Cbor Payload");
214 DeleteCredList(cred);
217 printf("CRED Cbor Size: %zd\n", credCborSize);
218 DeleteCredList(cred);
222 size_t cborSize = aclCborSize + pstatCborSize + doxmCborSize + svcCborSize + credCborSize + amaclCborSize;
224 printf("Total Cbor Size : %zd\n", cborSize);
225 cborSize += 255; // buffer margin for adding map and byte string
226 uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborSize);
227 VERIFY_NON_NULL(TAG, outPayload, ERROR);
228 cbor_encoder_init(&encoder, outPayload, cborSize, 0);
230 CborError cborEncoderResult = cbor_encoder_create_map(&encoder, &map, CborIndefiniteLength);
231 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Creating Main Map.");
234 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_ACL_NAME, strlen(OIC_JSON_ACL_NAME));
235 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Name.");
236 cborEncoderResult = cbor_encode_byte_string(&map, aclCbor, aclCborSize);
237 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Value.");
240 if (pstatCborSize > 0)
242 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_PSTAT_NAME, strlen(OIC_JSON_PSTAT_NAME));
243 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Name.");
244 cborEncoderResult = cbor_encode_byte_string(&map, pstatCbor, pstatCborSize);
245 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Value.");
247 if (doxmCborSize > 0)
249 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_DOXM_NAME, strlen(OIC_JSON_DOXM_NAME));
250 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding DOXM Name.");
251 cborEncoderResult = cbor_encode_byte_string(&map, doxmCbor, doxmCborSize);
252 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding DOXM Value.");
254 if (amaclCborSize > 0)
256 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_AMACL_NAME, strlen(OIC_JSON_AMACL_NAME));
257 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding AMACL Name.");
258 cborEncoderResult = cbor_encode_byte_string(&map, amaclCbor, amaclCborSize);
259 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding AMACL Value.");
263 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_SVC_NAME, strlen(OIC_JSON_SVC_NAME));
264 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SVC Name.");
265 cborEncoderResult = cbor_encode_byte_string(&map, svcCbor, svcCborSize);
266 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SVC Value.");
268 if (credCborSize > 0)
270 cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_CRED_NAME, strlen(OIC_JSON_CRED_NAME));
271 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Name.");
272 cborEncoderResult = cbor_encode_byte_string(&map, credCbor, credCborSize);
273 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Value.");
276 cborEncoderResult = cbor_encoder_close_container(&encoder, &map);
277 VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Container.");
279 size_t s = cbor_encoder_get_buffer_size(&encoder, outPayload);
280 OIC_LOG_V(DEBUG, TAG, "Payload size %zu", s);
282 fp1 = fopen(cborFileName, "w");
285 size_t bytesWritten = fwrite(outPayload, 1, s, fp1);
286 if (bytesWritten == s)
288 OIC_LOG_V(DEBUG, TAG, "Written %zu bytes", bytesWritten);
292 OIC_LOG_V(ERROR, TAG, "Failed writing %zu bytes", s);
299 cJSON_Delete(jsonRoot);
310 OicSecAcl_t* JSONToAclBin(const char * jsonStr)
312 OCStackResult ret = OC_STACK_ERROR;
313 OicSecAcl_t * headAcl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
314 cJSON *jsonRoot = NULL;
316 VERIFY_NON_NULL(TAG, jsonStr, ERROR);
318 jsonRoot = cJSON_Parse(jsonStr);
319 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
321 cJSON *jsonAclMap = cJSON_GetObjectItem(jsonRoot, OIC_JSON_ACL_NAME);
322 VERIFY_NON_NULL(TAG, jsonAclMap, ERROR);
324 cJSON *jsonAclObj = NULL;
327 jsonAclObj = cJSON_GetObjectItem(jsonAclMap, OIC_JSON_ACLIST_NAME);
328 VERIFY_NON_NULL(TAG, jsonAclObj, ERROR);
331 cJSON *jsonAclArray = NULL;
332 jsonAclArray = cJSON_GetObjectItem(jsonAclObj, OIC_JSON_ACES_NAME);
333 VERIFY_NON_NULL(TAG, jsonAclArray, ERROR);
335 if (cJSON_Array == jsonAclArray->type)
338 int numAcl = cJSON_GetArraySize(jsonAclArray);
341 VERIFY_SUCCESS(TAG, numAcl > 0, INFO);
344 cJSON *jsonAcl = cJSON_GetArrayItem(jsonAclArray, idx);
345 VERIFY_NON_NULL(TAG, jsonAcl, ERROR);
347 OicSecAce_t *ace = (OicSecAce_t*)OICCalloc(1, sizeof(OicSecAce_t));
348 VERIFY_NON_NULL(TAG, ace, ERROR);
349 LL_APPEND(headAcl->aces, ace);
351 size_t jsonObjLen = 0;
352 cJSON *jsonObj = NULL;
353 jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_SUBJECTID_NAME);
354 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
355 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
356 if(strcmp(jsonObj->valuestring, WILDCARD_RESOURCE_URI) == 0)
358 ace->subjectuuid.id[0] = '*';
362 ret = ConvertStrToUuid(jsonObj->valuestring, &ace->subjectuuid);
363 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
365 // Resources -- Mandatory
366 jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_RESOURCES_NAME);
367 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
368 VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR);
370 size_t resourcesLen = (size_t)cJSON_GetArraySize(jsonObj);
371 VERIFY_SUCCESS(TAG, resourcesLen > 0, ERROR);
373 for(size_t idxx = 0; idxx < resourcesLen; idxx++)
375 OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
376 VERIFY_NON_NULL(TAG, rsrc, ERROR);
378 cJSON *jsonRsrc = cJSON_GetArrayItem(jsonObj, idxx);
379 VERIFY_NON_NULL(TAG, jsonRsrc, ERROR);
382 size_t jsonRsrcObjLen = 0;
383 cJSON *jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_HREF_NAME);
384 VERIFY_NON_NULL(TAG, jsonRsrcObj, ERROR);
385 VERIFY_SUCCESS(TAG, cJSON_String == jsonRsrcObj->type, ERROR);
387 jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1;
388 rsrc->href = (char*)OICMalloc(jsonRsrcObjLen);
389 VERIFY_NON_NULL(TAG, (rsrc->href), ERROR);
390 OICStrcpy(rsrc->href, jsonRsrcObjLen, jsonRsrcObj->valuestring);
393 jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_REL_NAME);
396 jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1;
397 rsrc->rel = (char*)OICMalloc(jsonRsrcObjLen);
398 VERIFY_NON_NULL(TAG, (rsrc->rel), ERROR);
399 OICStrcpy(rsrc->rel, jsonRsrcObjLen, jsonRsrcObj->valuestring);
403 jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_RT_NAME);
404 if(jsonRsrcObj && cJSON_Array == jsonRsrcObj->type)
406 rsrc->typeLen = (size_t)cJSON_GetArraySize(jsonRsrcObj);
407 VERIFY_SUCCESS(TAG, (0 < rsrc->typeLen), ERROR);
408 rsrc->types = (char**)OICCalloc(rsrc->typeLen, sizeof(char*));
409 VERIFY_NON_NULL(TAG, (rsrc->types), ERROR);
410 for(size_t i = 0; i < rsrc->typeLen; i++)
412 cJSON *jsonRsrcType = cJSON_GetArrayItem(jsonRsrcObj, i);
413 VERIFY_NON_NULL(TAG, jsonRsrcType, ERROR);
414 rsrc->types[i] = OICStrdup(jsonRsrcType->valuestring);
415 VERIFY_NON_NULL(TAG, (rsrc->types[i]), ERROR);
420 jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_IF_NAME);
421 if(jsonRsrcObj && cJSON_Array == jsonRsrcObj->type)
423 rsrc->interfaceLen = (size_t)cJSON_GetArraySize(jsonRsrcObj);
424 VERIFY_SUCCESS(TAG, (0 < rsrc->interfaceLen), ERROR);
425 rsrc->interfaces = (char**)OICCalloc(rsrc->interfaceLen, sizeof(char*));
426 VERIFY_NON_NULL(TAG, (rsrc->interfaces), ERROR);
427 for(size_t i = 0; i < rsrc->interfaceLen; i++)
429 cJSON *jsonInterface = cJSON_GetArrayItem(jsonRsrcObj, i);
430 VERIFY_NON_NULL(TAG, jsonInterface, ERROR);
431 rsrc->interfaces[i] = OICStrdup(jsonInterface->valuestring);
432 VERIFY_NON_NULL(TAG, (rsrc->interfaces[i]), ERROR);
436 LL_APPEND(ace->resources, rsrc);
439 // Permissions -- Mandatory
440 jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_PERMISSION_NAME);
441 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
442 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
443 ace->permission = jsonObj->valueint;
445 //Validity -- Not Mandatory
446 cJSON *jsonValidityObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_VALIDITY_NAME);
449 VERIFY_SUCCESS(TAG, cJSON_Array == jsonValidityObj->type, ERROR);
450 size_t validityLen = (size_t) cJSON_GetArraySize(jsonValidityObj);
451 VERIFY_SUCCESS(TAG, (0 < validityLen), ERROR);
453 cJSON *jsonValidity = NULL;
454 for(size_t i = 0; i < validityLen; i++)
456 jsonValidity = cJSON_GetArrayItem(jsonValidityObj, i);
457 VERIFY_NON_NULL(TAG, jsonValidity, ERROR);
458 VERIFY_SUCCESS(TAG, (jsonValidity->type == cJSON_Array), ERROR);
460 OicSecValidity_t* validity = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t));
461 VERIFY_NON_NULL(TAG, validity, ERROR);
462 LL_APPEND(ace->validities, validity);
465 cJSON* jsonPeriod = cJSON_GetArrayItem(jsonValidity, 0);
468 VERIFY_SUCCESS(TAG, (cJSON_String == jsonPeriod->type), ERROR);
470 jsonObjLen = strlen(jsonPeriod->valuestring) + 1;
471 validity->period = (char*)OICMalloc(jsonObjLen);
472 VERIFY_NON_NULL(TAG, validity->period, ERROR);
473 OICStrcpy(validity->period, jsonObjLen, jsonPeriod->valuestring);
477 cJSON* jsonRecurObj = cJSON_GetArrayItem(jsonValidity, 1);
480 VERIFY_SUCCESS(TAG, (cJSON_Array == jsonRecurObj->type), ERROR);
481 validity->recurrenceLen = (size_t) cJSON_GetArraySize(jsonRecurObj);
482 VERIFY_SUCCESS(TAG, (0 < validity->recurrenceLen), ERROR);
484 validity->recurrences = (char**)OICCalloc(validity->recurrenceLen, sizeof(char*));
485 VERIFY_NON_NULL(TAG, validity->recurrences, ERROR);
487 cJSON *jsonRecur = NULL;
488 for(size_t i = 0; i < validity->recurrenceLen; i++)
490 jsonRecur = cJSON_GetArrayItem(jsonRecurObj, i);
491 VERIFY_NON_NULL(TAG, jsonRecur, ERROR);
492 jsonObjLen = strlen(jsonRecur->valuestring) + 1;
493 validity->recurrences[i] = (char*)OICMalloc(jsonObjLen);
494 VERIFY_NON_NULL(TAG, validity->recurrences[i], ERROR);
495 OICStrcpy(validity->recurrences[i], jsonObjLen, jsonRecur->valuestring);
500 } while( ++idx < numAcl);
505 jsonAclObj = cJSON_GetObjectItem(jsonAclMap, OIC_JSON_ROWNERID_NAME);
506 VERIFY_NON_NULL(TAG, jsonAclObj, ERROR);
507 VERIFY_SUCCESS(TAG, cJSON_String == jsonAclObj->type, ERROR);
508 ret = ConvertStrToUuid(jsonAclObj->valuestring, &headAcl->rownerID);
509 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
514 cJSON_Delete(jsonRoot);
515 if (OC_STACK_OK != ret)
517 DeleteACLList(headAcl);
523 OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr)
525 printf("IN JSONToDoxmBin\n");
531 OCStackResult ret = OC_STACK_ERROR;
532 OicSecDoxm_t *doxm = NULL;
533 cJSON *jsonDoxm = NULL;
534 cJSON *jsonObj = NULL;
536 size_t jsonObjLen = 0;
538 cJSON *jsonRoot = cJSON_Parse(jsonStr);
539 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
541 jsonDoxm = cJSON_GetObjectItem(jsonRoot, OIC_JSON_DOXM_NAME);
542 VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
544 doxm = (OicSecDoxm_t *)OICCalloc(1, sizeof(OicSecDoxm_t));
545 VERIFY_NON_NULL(TAG, doxm, ERROR);
547 //OxmType -- not Mandatory
548 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_TYPE_NAME);
549 if ((jsonObj) && (cJSON_Array == jsonObj->type))
551 doxm->oxmTypeLen = (size_t)cJSON_GetArraySize(jsonObj);
552 VERIFY_SUCCESS(TAG, doxm->oxmTypeLen > 0, ERROR);
554 doxm->oxmType = (OicUrn_t *)OICCalloc(doxm->oxmTypeLen, sizeof(char *));
555 VERIFY_NON_NULL(TAG, (doxm->oxmType), ERROR);
557 for (size_t i = 0; i < doxm->oxmTypeLen ; i++)
559 cJSON *jsonOxmTy = cJSON_GetArrayItem(jsonObj, i);
560 VERIFY_NON_NULL(TAG, jsonOxmTy, ERROR);
562 jsonObjLen = strlen(jsonOxmTy->valuestring) + 1;
563 doxm->oxmType[i] = (char*)OICMalloc(jsonObjLen);
564 VERIFY_NON_NULL(TAG, doxm->oxmType[i], ERROR);
565 strncpy((char *)doxm->oxmType[i], (char *)jsonOxmTy->valuestring, jsonObjLen);
569 //Oxm -- not Mandatory
570 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXMS_NAME);
571 if (jsonObj && cJSON_Array == jsonObj->type)
573 doxm->oxmLen = (size_t)cJSON_GetArraySize(jsonObj);
574 VERIFY_SUCCESS(TAG, doxm->oxmLen > 0, ERROR);
576 doxm->oxm = (OicSecOxm_t*)OICCalloc(doxm->oxmLen, sizeof(OicSecOxm_t));
577 VERIFY_NON_NULL(TAG, doxm->oxm, ERROR);
579 for (size_t i = 0; i < doxm->oxmLen ; i++)
581 cJSON *jsonOxm = cJSON_GetArrayItem(jsonObj, i);
582 VERIFY_NON_NULL(TAG, jsonOxm, ERROR);
583 doxm->oxm[i] = (OicSecOxm_t)jsonOxm->valueint;
587 //OxmSel -- Mandatory
588 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OXM_SEL_NAME);
591 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
592 doxm->oxmSel = (OicSecOxm_t)jsonObj->valueint;
596 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_SUPPORTED_CRED_TYPE_NAME);
599 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
600 doxm->sct = (OicSecCredType_t)jsonObj->valueint;
604 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_OWNED_NAME);
607 VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type), ERROR);
608 doxm->owned = jsonObj->valueint;
611 #ifdef _ENABLE_MULTIPLE_OWNER_
612 //mom -- Not Mandatory
613 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_MOM_NAME);
616 VERIFY_SUCCESS(TAG, (cJSON_Number == jsonObj->type), ERROR);
617 doxm->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t));
618 VERIFY_NON_NULL(TAG, doxm->mom, ERROR);
619 doxm->mom->mode = (OicSecMomType_t)jsonObj->valueint;
621 #endif //_ENABLE_MULTIPLE_OWNER_
623 //DeviceId -- Mandatory
624 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVICE_ID_NAME);
627 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
628 if (cJSON_String == jsonObj->type)
630 //Check for empty string, in case DeviceId field has not been set yet
631 if (jsonObj->valuestring[0])
633 ret = ConvertStrToUuid(jsonObj->valuestring, &doxm->deviceID);
634 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
639 //rowner -- Mandatory
640 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_ROWNERID_NAME);
641 if (true == doxm->owned)
643 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
647 ret = ConvertStrToUuid(jsonObj->valuestring, &doxm->rownerID);
648 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
651 //Owner -- will be empty when device status is unowned.
652 jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVOWNERID_NAME);
653 if (true == doxm->owned)
655 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
659 ret = ConvertStrToUuid(jsonObj->valuestring, &doxm->owner);
660 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
666 cJSON_Delete(jsonRoot);
667 if (OC_STACK_OK != ret)
669 DeleteDoxmBinData(doxm);
672 printf("OUT JSONToDoxmBin\n");
676 OicSecPstat_t* JSONToPstatBin(const char * jsonStr)
678 printf("IN JSONToPstatBin\n");
684 OCStackResult ret = OC_STACK_ERROR;
685 OicSecPstat_t *pstat = NULL;
686 cJSON *jsonPstat = NULL;
687 cJSON *jsonObj = NULL;
689 cJSON *jsonRoot = cJSON_Parse(jsonStr);
690 VERIFY_NON_NULL(TAG, jsonRoot, INFO);
692 jsonPstat = cJSON_GetObjectItem(jsonRoot, OIC_JSON_PSTAT_NAME);
693 VERIFY_NON_NULL(TAG, jsonPstat, INFO);
695 pstat = (OicSecPstat_t*)OICCalloc(1, sizeof(OicSecPstat_t));
696 VERIFY_NON_NULL(TAG, pstat, INFO);
697 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ISOP_NAME);
698 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
699 VERIFY_SUCCESS(TAG, (cJSON_True == jsonObj->type || cJSON_False == jsonObj->type) , ERROR);
700 pstat->isOp = jsonObj->valueint;
702 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_DEVICE_ID_NAME);
703 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
704 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
705 ret = ConvertStrToUuid(jsonObj->valuestring, &pstat->deviceID);
706 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
708 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_ROWNERID_NAME);
709 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
710 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
711 ret = ConvertStrToUuid(jsonObj->valuestring, &pstat->rownerID);
712 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
714 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_CM_NAME);
715 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
716 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
717 pstat->cm = (OicSecDpm_t)jsonObj->valueint;
719 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_TM_NAME);
720 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
721 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
722 pstat->tm = (OicSecDpm_t)jsonObj->valueint;
724 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_OM_NAME);
725 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
726 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
727 pstat->om = (OicSecDpom_t)jsonObj->valueint;
729 jsonObj = cJSON_GetObjectItem(jsonPstat, OIC_JSON_SM_NAME);
730 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
731 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
733 pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
734 pstat->sm[0] = (OicSecDpom_t)jsonObj->valueint;
739 cJSON_Delete(jsonRoot);
740 if (OC_STACK_OK != ret)
742 OIC_LOG(ERROR, TAG, "JSONToPstatBin failed");
744 printf("OUT JSONToPstatBin\n");
748 static OicEncodingType_t GetEncodingTypeFromStr(const char* encodingType)
750 if (strcmp(OIC_SEC_ENCODING_RAW, encodingType) == 0)
752 return OIC_ENCODING_RAW;
754 if (strcmp(OIC_SEC_ENCODING_BASE64, encodingType) == 0)
756 return OIC_ENCODING_BASE64;
758 if (strcmp(OIC_SEC_ENCODING_PEM, encodingType) == 0)
760 return OIC_ENCODING_PEM;
762 if (strcmp(OIC_SEC_ENCODING_DER, encodingType) == 0)
764 return OIC_ENCODING_DER;
766 OIC_LOG(WARNING, TAG, "Unknow encoding type dectected!");
767 OIC_LOG(WARNING, TAG, "json2cbor will use \"oic.sec.encoding.raw\" as default encoding type.");
768 return OIC_ENCODING_RAW;
771 OicSecCred_t * JSONToCredBin(const char * jsonStr)
775 OIC_LOG(ERROR, TAG,"JSONToCredBin jsonStr in NULL");
779 OicSecCred_t *headCred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t));
780 OCStackResult ret = OC_STACK_ERROR;
781 cJSON *jsonRoot = NULL;
782 VERIFY_NON_NULL(TAG, headCred, ERROR);
784 jsonRoot = cJSON_Parse(jsonStr);
785 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
787 cJSON *jsonCredMap = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME);
788 VERIFY_NON_NULL(TAG, jsonCredMap, ERROR);
791 cJSON *jsonCredArray = NULL;
792 jsonCredArray = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_CREDS_NAME);
793 VERIFY_NON_NULL(TAG, jsonCredArray, ERROR);
795 if (cJSON_Array == jsonCredArray->type)
797 int numCred = cJSON_GetArraySize(jsonCredArray);
798 VERIFY_SUCCESS(TAG, numCred > 0, ERROR);
802 cJSON *jsonCred = cJSON_GetArrayItem(jsonCredArray, idx);
803 VERIFY_NON_NULL(TAG, jsonCred, ERROR);
805 OicSecCred_t *cred = NULL;
812 cred = (OicSecCred_t*)OICCalloc(1, sizeof(OicSecCred_t));
813 OicSecCred_t *temp = headCred;
820 VERIFY_NON_NULL(TAG, cred, ERROR);
822 size_t jsonObjLen = 0;
823 cJSON *jsonObj = NULL;
825 //CredId -- Mandatory
826 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDID_NAME);
829 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
830 cred->credId = jsonObj->valueint;
833 //subject -- Mandatory
834 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_SUBJECTID_NAME);
835 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
836 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
837 if(strcmp(jsonObj->valuestring, WILDCARD_RESOURCE_URI) == 0)
839 cred->subject.id[0] = '*';
843 ret = ConvertStrToUuid(jsonObj->valuestring, &cred->subject);
844 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
847 //CredType -- Mandatory
848 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDTYPE_NAME);
849 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
850 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
851 cred->credType = (OicSecCredType_t)jsonObj->valueint;
852 //PrivateData is mandatory for some of the credential types listed below.
853 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PRIVATEDATA_NAME);
857 cJSON *jsonPriv = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
858 VERIFY_NON_NULL(TAG, jsonPriv, ERROR);
859 jsonObjLen = strlen(jsonPriv->valuestring);
860 cred->privateData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
861 VERIFY_NON_NULL(TAG, (cred->privateData.data), ERROR);
862 memcpy(cred->privateData.data, jsonPriv->valuestring, jsonObjLen);
863 cred->privateData.len = jsonObjLen;
865 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
866 VERIFY_NON_NULL(TAG, jsonEncoding, ERROR);
867 cred->privateData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
869 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
870 //PublicData is mandatory only for SIGNED_ASYMMETRIC_KEY credentials type.
871 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PUBLICDATA_NAME);
875 cJSON *jsonPub = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
876 VERIFY_NON_NULL(TAG, jsonPub, ERROR);
877 jsonObjLen = strlen(jsonPub->valuestring);
878 cred->publicData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
879 VERIFY_NON_NULL(TAG, (cred->publicData.data), ERROR);
880 memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen);
881 cred->publicData.len = jsonObjLen;
885 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_OPTDATA_NAME);
888 cJSON *jsonOpt = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
889 VERIFY_NON_NULL(TAG, jsonOpt, ERROR);
890 jsonObjLen = strlen(jsonOpt->valuestring);
891 cred->optionalData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
892 VERIFY_NON_NULL(TAG, (cred->optionalData.data), ERROR);
893 memcpy(cred->optionalData.data, jsonOpt->valuestring, jsonObjLen);
894 cred->optionalData.len = jsonObjLen;
896 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
897 VERIFY_NON_NULL(TAG, jsonEncoding, ERROR);
898 cred->optionalData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
902 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_CREDUSAGE_NAME);
905 jsonObjLen = strlen(jsonObj->valuestring);
906 cred->credUsage = OICStrdup(jsonObj->valuestring);
907 VERIFY_NON_NULL(TAG, (cred->credUsage), ERROR);
910 #endif // defined(__WITH_DTLS__) || defined(__WITH_TLS__)
912 //Period -- Not Mandatory
913 jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PERIOD_NAME);
914 if(jsonObj && cJSON_String == jsonObj->type)
916 jsonObjLen = strlen(jsonObj->valuestring) + 1;
917 cred->period = (char *)OICMalloc(jsonObjLen);
918 VERIFY_NON_NULL(TAG, cred->period, ERROR);
919 strncpy(cred->period, jsonObj->valuestring, jsonObjLen);
922 } while( ++idx < numCred);
926 cJSON *jsonCredObj = cJSON_GetObjectItem(jsonCredMap, OIC_JSON_ROWNERID_NAME);
927 VERIFY_NON_NULL(TAG, jsonCredObj, ERROR);
928 VERIFY_SUCCESS(TAG, cJSON_String == jsonCredObj->type, ERROR);
929 ret = ConvertStrToUuid(jsonCredObj->valuestring, &headCred->rownerID);
930 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
934 cJSON_Delete(jsonRoot);
935 if (OC_STACK_OK != ret)
937 DeleteCredList(headCred);
943 static OicSecSvc_t* JSONToSvcBin(const char * jsonStr)
945 OCStackResult ret = OC_STACK_ERROR;
946 OicSecSvc_t * headSvc = NULL;
947 OicSecSvc_t * prevSvc = NULL;
948 cJSON *jsonRoot = NULL;
949 cJSON *jsonSvcArray = NULL;
951 VERIFY_NON_NULL(TAG, jsonStr, ERROR);
953 jsonRoot = cJSON_Parse(jsonStr);
954 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
956 jsonSvcArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME);
957 VERIFY_NON_NULL(TAG, jsonSvcArray, INFO);
959 if (cJSON_Array == jsonSvcArray->type)
961 int numSvc = cJSON_GetArraySize(jsonSvcArray);
964 VERIFY_SUCCESS(TAG, numSvc > 0, INFO);
967 cJSON *jsonSvc = cJSON_GetArrayItem(jsonSvcArray, idx);
968 VERIFY_NON_NULL(TAG, jsonSvc, ERROR);
970 OicSecSvc_t *svc = (OicSecSvc_t*)OICCalloc(1, sizeof(OicSecSvc_t));
971 VERIFY_NON_NULL(TAG, svc, ERROR);
973 headSvc = (headSvc) ? headSvc : svc;
979 cJSON *jsonObj = NULL;
980 unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {};
982 B64Result b64Ret = B64_OK;
984 // Service Device Identity
985 jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_DEVICE_ID);
986 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
987 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
989 b64Ret = b64Decode(jsonObj->valuestring, strlen(jsonObj->valuestring), base64Buff,
990 sizeof(base64Buff), &outLen);
991 VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(svc->svcdid.id)), ERROR);
992 memcpy(svc->svcdid.id, base64Buff, outLen);
995 jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_TYPE);
996 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
997 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
998 svc->svct = (OicSecSvcType_t)jsonObj->valueint;
1001 jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_OWNERS_NAME);
1002 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1003 VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR);
1005 svc->ownersLen = (size_t)cJSON_GetArraySize(jsonObj);
1006 VERIFY_SUCCESS(TAG, svc->ownersLen > 0, ERROR);
1007 svc->owners = (OicUuid_t*)OICCalloc(svc->ownersLen, sizeof(OicUuid_t));
1008 VERIFY_NON_NULL(TAG, (svc->owners), ERROR);
1013 cJSON *jsonOwnr = cJSON_GetArrayItem(jsonObj, idxx);
1014 VERIFY_NON_NULL(TAG, jsonOwnr, ERROR);
1015 VERIFY_SUCCESS(TAG, cJSON_String == jsonOwnr->type, ERROR);
1017 b64Ret = b64Decode(jsonOwnr->valuestring, strlen(jsonOwnr->valuestring), base64Buff,
1018 sizeof(base64Buff), &outLen);
1020 VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(svc->owners[idxx].id)),
1022 memcpy(svc->owners[idxx].id, base64Buff, outLen);
1023 } while ( ++idxx < svc->ownersLen);
1026 } while( ++idx < numSvc);
1032 cJSON_Delete(jsonRoot);
1033 if (OC_STACK_OK != ret)
1035 DeleteSVCList(headSvc);
1041 static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr)
1043 OCStackResult ret = OC_STACK_ERROR;
1044 OicSecAmacl_t * headAmacl = (OicSecAmacl_t*)OICCalloc(1, sizeof(OicSecAmacl_t));
1046 cJSON *jsonRoot = NULL;
1047 cJSON *jsonAmacl = NULL;
1049 VERIFY_NON_NULL(TAG, jsonStr, ERROR);
1051 jsonRoot = cJSON_Parse(jsonStr);
1052 VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
1054 jsonAmacl = cJSON_GetObjectItem(jsonRoot, OIC_JSON_AMACL_NAME);
1055 VERIFY_NON_NULL(TAG, jsonAmacl, INFO);
1057 cJSON *jsonObj = NULL;
1059 // Resources -- Mandatory
1060 jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_RESOURCES_NAME);
1061 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1064 cJSON *jsonRlistArray = cJSON_GetObjectItem(jsonObj, OIC_JSON_RLIST_NAME);
1065 VERIFY_NON_NULL(TAG, jsonRlistArray, ERROR);
1066 VERIFY_SUCCESS(TAG, cJSON_Array == jsonRlistArray->type, ERROR);
1068 headAmacl->resourcesLen = (size_t)cJSON_GetArraySize(jsonRlistArray);
1069 headAmacl->resources = (char**)OICCalloc(headAmacl->resourcesLen, sizeof(char*));
1073 cJSON *jsonRsrc = cJSON_GetArrayItem(jsonRlistArray, idxx);
1074 VERIFY_NON_NULL(TAG, jsonRsrc, ERROR);
1076 cJSON *jsonRsrcObj = cJSON_GetObjectItem(jsonRsrc, OIC_JSON_HREF_NAME);
1077 VERIFY_NON_NULL(TAG, jsonRsrcObj, ERROR);
1078 VERIFY_SUCCESS(TAG, cJSON_String == jsonRsrcObj->type, ERROR);
1080 size_t jsonRsrcObjLen = 0;
1081 jsonRsrcObjLen = strlen(jsonRsrcObj->valuestring) + 1;
1082 headAmacl->resources[idxx] = (char*)OICMalloc(jsonRsrcObjLen);
1083 VERIFY_NON_NULL(TAG, (headAmacl->resources[idxx]), ERROR);
1084 OICStrcpy(headAmacl->resources[idxx], jsonRsrcObjLen, jsonRsrcObj->valuestring);
1086 } while ( ++idxx < headAmacl->resourcesLen);
1089 jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_AMS_NAME);
1090 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1091 VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR);
1093 headAmacl->amssLen = (size_t)cJSON_GetArraySize(jsonObj);
1094 VERIFY_SUCCESS(TAG, headAmacl->amssLen > 0, ERROR);
1095 headAmacl->amss = (OicUuid_t*)OICCalloc(headAmacl->amssLen, sizeof(OicUuid_t));
1096 VERIFY_NON_NULL(TAG, headAmacl->amss, ERROR);
1101 cJSON *jsonAms = cJSON_GetArrayItem(jsonObj, idxx);
1102 VERIFY_NON_NULL(TAG, jsonAms, ERROR);
1103 VERIFY_SUCCESS(TAG, cJSON_String == jsonAms->type, ERROR);
1105 memcpy(headAmacl->amss[idxx].id, (OicUuid_t *)jsonAms->valuestring, strlen(jsonAms->valuestring));
1107 } while ( ++idxx < headAmacl->amssLen);
1110 // Rowner -- Mandatory
1111 jsonObj = cJSON_GetObjectItem(jsonAmacl, OIC_JSON_ROWNERID_NAME);
1112 VERIFY_NON_NULL(TAG, jsonObj, ERROR);
1113 VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR);
1115 ret = ConvertStrToUuid(jsonObj->valuestring, &headAmacl->rownerID);
1116 VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
1121 cJSON_Delete(jsonRoot);
1122 if (OC_STACK_OK != ret)
1124 DeleteAmaclList(headAmacl);
1130 int main(int argc, char* argv[])
1134 printf("JSON File Name: %s\n CBOR File Name: %s \n", argv[1], argv[2]);
1135 ConvertJsonToCBOR(argv[1], argv[2]);
1139 printf("This program requires two inputs:\n");
1140 printf("1. First input is a json file tha will be converted to cbor. \n");
1141 printf("2. Second input is a resulting cbor file that will store converted cbor. \n");
1142 printf("\t json2cbor <json_file_name> <cbor_file_name>. \n");