X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Ftool%2Fjson2cbor.c;h=b6fa1aa8a6216e3c2a0856a3a4a58037defb0050;hb=7f00f942c39b7bc27c7eeecf213a239c3fe4173c;hp=03b971869ad600c985e97634281db647808eba62;hpb=edcfc3d2329da7b914771c0dcff5f42c9b74fd93;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/tool/json2cbor.c b/resource/csdk/security/tool/json2cbor.c index 03b9718..b6fa1aa 100644 --- a/resource/csdk/security/tool/json2cbor.c +++ b/resource/csdk/security/tool/json2cbor.c @@ -21,7 +21,11 @@ #include #include #include "utlist.h" +#if defined (__TIZENRT__) +#include +#else #include "cJSON.h" +#endif #include "base64.h" #include "cainterface.h" #include "ocstack.h" @@ -38,7 +42,6 @@ #include "doxmresource.h" #include "amaclresource.h" #include "credresource.h" -#include "svcresource.h" #include "security_internals.h" #define TAG "OIC_JSON2CBOR" @@ -49,7 +52,6 @@ static const size_t DB_FILE_SIZE_BLOCK = 1023; static OicSecPstat_t* JSONToPstatBin(const char * jsonStr); static OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr); static OicSecAcl_t *JSONToAclBin(const char * jsonStr); -static OicSecSvc_t* JSONToSvcBin(const char * jsonStr); static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr); static OicSecCred_t* JSONToCredBin(const char * jsonStr); @@ -85,7 +87,6 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName uint8_t *pstatCbor = NULL; uint8_t *doxmCbor = NULL; uint8_t *amaclCbor = NULL; - uint8_t *svcCbor = NULL; uint8_t *credCbor = NULL; cJSON *jsonRoot = NULL; OCStackResult ret = OC_STACK_ERROR; @@ -183,22 +184,6 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName printf("AMACL Cbor Size: %zd\n", amaclCborSize); DeleteAmaclList(amacl); } - value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME); - size_t svcCborSize = 0; - if (NULL != value) - { - OicSecSvc_t *svc = JSONToSvcBin(jsonStr); - VERIFY_NON_NULL(TAG, svc, FATAL); - ret = SVCToCBORPayload(svc, &svcCbor, &svcCborSize); - if(OC_STACK_OK != ret) - { - OIC_LOG (ERROR, TAG, "Failed converting Svc to Cbor Payload"); - DeleteSVCList(svc); - goto exit; - } - printf("SVC Cbor Size: %zd\n", svcCborSize); - DeleteSVCList(svc); - } value = cJSON_GetObjectItem(jsonRoot, OIC_JSON_CRED_NAME); //printf("CRED json : \n%s\n", cJSON_PrintUnformatted(value)); size_t credCborSize = 0; @@ -219,7 +204,7 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName } CborEncoder encoder; - size_t cborSize = aclCborSize + pstatCborSize + doxmCborSize + svcCborSize + credCborSize + amaclCborSize; + size_t cborSize = aclCborSize + pstatCborSize + doxmCborSize + credCborSize + amaclCborSize; printf("Total Cbor Size : %zd\n", cborSize); cborSize += 255; // buffer margin for adding map and byte string @@ -258,13 +243,6 @@ static void ConvertJsonToCBOR(const char *jsonFileName, const char *cborFileName cborEncoderResult = cbor_encode_byte_string(&map, amaclCbor, amaclCborSize); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding AMACL Value."); } - if (svcCborSize > 0) - { - cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_SVC_NAME, strlen(OIC_JSON_SVC_NAME)); - VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SVC Name."); - cborEncoderResult = cbor_encode_byte_string(&map, svcCbor, svcCborSize); - VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SVC Value."); - } if (credCborSize > 0) { cborEncoderResult = cbor_encode_text_string(&map, OIC_JSON_CRED_NAME, strlen(OIC_JSON_CRED_NAME)); @@ -301,7 +279,6 @@ exit: OICFree(doxmCbor); OICFree(pstatCbor); OICFree(amaclCbor); - OICFree(svcCbor); OICFree(credCbor); OICFree(jsonStr); return ; @@ -608,7 +585,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) doxm->owned = jsonObj->valueint; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //mom -- Not Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_MOM_NAME); if (jsonObj) @@ -618,7 +595,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) VERIFY_NON_NULL(TAG, doxm->mom, ERROR); doxm->mom->mode = (OicSecMomType_t)jsonObj->valueint; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //DeviceId -- Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVICE_ID_NAME); @@ -856,7 +833,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) { cJSON *jsonPriv = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME); VERIFY_NON_NULL(TAG, jsonPriv, ERROR); - jsonObjLen = strlen(jsonPriv->valuestring); + jsonObjLen = strlen(jsonPriv->valuestring) + 1; cred->privateData.data = (uint8_t *)OICCalloc(1, jsonObjLen); VERIFY_NON_NULL(TAG, (cred->privateData.data), ERROR); memcpy(cred->privateData.data, jsonPriv->valuestring, jsonObjLen); @@ -874,7 +851,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) { cJSON *jsonPub = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME); VERIFY_NON_NULL(TAG, jsonPub, ERROR); - jsonObjLen = strlen(jsonPub->valuestring); + jsonObjLen = strlen(jsonPub->valuestring) + 1; cred->publicData.data = (uint8_t *)OICCalloc(1, jsonObjLen); VERIFY_NON_NULL(TAG, (cred->publicData.data), ERROR); memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen); @@ -887,7 +864,7 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) { cJSON *jsonOpt = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME); VERIFY_NON_NULL(TAG, jsonOpt, ERROR); - jsonObjLen = strlen(jsonOpt->valuestring); + jsonObjLen = strlen(jsonOpt->valuestring) + 1; cred->optionalData.data = (uint8_t *)OICCalloc(1, jsonObjLen); VERIFY_NON_NULL(TAG, (cred->optionalData.data), ERROR); memcpy(cred->optionalData.data, jsonOpt->valuestring, jsonObjLen); @@ -896,6 +873,10 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr) cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME); VERIFY_NON_NULL(TAG, jsonEncoding, ERROR); cred->optionalData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring); + + cJSON *jsonRevstat = cJSON_GetObjectItem(jsonObj, OIC_JSON_REVOCATION_STATUS_NAME); + VERIFY_NON_NULL(TAG, jsonRevstat, ERROR); + cred->optionalData.revstat = jsonObj->valueint; } //CredUsage @@ -940,104 +921,6 @@ exit: return headCred; } -static OicSecSvc_t* JSONToSvcBin(const char * jsonStr) -{ - OCStackResult ret = OC_STACK_ERROR; - OicSecSvc_t * headSvc = NULL; - OicSecSvc_t * prevSvc = NULL; - cJSON *jsonRoot = NULL; - cJSON *jsonSvcArray = NULL; - - VERIFY_NON_NULL(TAG, jsonStr, ERROR); - - jsonRoot = cJSON_Parse(jsonStr); - VERIFY_NON_NULL(TAG, jsonRoot, ERROR); - - jsonSvcArray = cJSON_GetObjectItem(jsonRoot, OIC_JSON_SVC_NAME); - VERIFY_NON_NULL(TAG, jsonSvcArray, INFO); - - if (cJSON_Array == jsonSvcArray->type) - { - int numSvc = cJSON_GetArraySize(jsonSvcArray); - int idx = 0; - - VERIFY_SUCCESS(TAG, numSvc > 0, INFO); - do - { - cJSON *jsonSvc = cJSON_GetArrayItem(jsonSvcArray, idx); - VERIFY_NON_NULL(TAG, jsonSvc, ERROR); - - OicSecSvc_t *svc = (OicSecSvc_t*)OICCalloc(1, sizeof(OicSecSvc_t)); - VERIFY_NON_NULL(TAG, svc, ERROR); - - headSvc = (headSvc) ? headSvc : svc; - if (prevSvc) - { - prevSvc->next = svc; - } - - cJSON *jsonObj = NULL; - unsigned char base64Buff[sizeof(((OicUuid_t*)0)->id)] = {}; - uint32_t outLen = 0; - B64Result b64Ret = B64_OK; - - // Service Device Identity - jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_DEVICE_ID); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); - VERIFY_SUCCESS(TAG, cJSON_String == jsonObj->type, ERROR); - outLen = 0; - b64Ret = b64Decode(jsonObj->valuestring, strlen(jsonObj->valuestring), base64Buff, - sizeof(base64Buff), &outLen); - VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(svc->svcdid.id)), ERROR); - memcpy(svc->svcdid.id, base64Buff, outLen); - - // Service Type - jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_SERVICE_TYPE); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); - VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR); - svc->svct = (OicSecSvcType_t)jsonObj->valueint; - - // Resource Owners - jsonObj = cJSON_GetObjectItem(jsonSvc, OIC_JSON_OWNERS_NAME); - VERIFY_NON_NULL(TAG, jsonObj, ERROR); - VERIFY_SUCCESS(TAG, cJSON_Array == jsonObj->type, ERROR); - - svc->ownersLen = (size_t)cJSON_GetArraySize(jsonObj); - VERIFY_SUCCESS(TAG, svc->ownersLen > 0, ERROR); - svc->owners = (OicUuid_t*)OICCalloc(svc->ownersLen, sizeof(OicUuid_t)); - VERIFY_NON_NULL(TAG, (svc->owners), ERROR); - - size_t idxx = 0; - do - { - cJSON *jsonOwnr = cJSON_GetArrayItem(jsonObj, idxx); - VERIFY_NON_NULL(TAG, jsonOwnr, ERROR); - VERIFY_SUCCESS(TAG, cJSON_String == jsonOwnr->type, ERROR); - outLen = 0; - b64Ret = b64Decode(jsonOwnr->valuestring, strlen(jsonOwnr->valuestring), base64Buff, - sizeof(base64Buff), &outLen); - - VERIFY_SUCCESS(TAG, (b64Ret == B64_OK && outLen <= sizeof(svc->owners[idxx].id)), - ERROR); - memcpy(svc->owners[idxx].id, base64Buff, outLen); - } while ( ++idxx < svc->ownersLen); - - prevSvc = svc; - } while( ++idx < numSvc); - } - - ret = OC_STACK_OK; - -exit: - cJSON_Delete(jsonRoot); - if (OC_STACK_OK != ret) - { - DeleteSVCList(headSvc); - headSvc = NULL; - } - return headSvc; -} - static OicSecAmacl_t* JSONToAmaclBin(const char * jsonStr) { OCStackResult ret = OC_STACK_ERROR;