From 1cd674fc2f43bae00b5e791b88a333754845eedf Mon Sep 17 00:00:00 2001
From: "ol.beketov"
Date: Fri, 2 Jun 2017 17:14:47 +0300
Subject: [PATCH] [IOT-2392] Fix json2cbor
json2cbor failed to convert cred field of oic_svr_db_server_mfg.json
and oic_svr_db_client.json
Bug: https://jira.iotivity.org/browse/IOT-2392
Change-Id: Ib5a4c3bdc83a7156b63d899bc109bdf2dc58fb5a
Signed-off-by: ol.beketov
Reviewed-on: https://gerrit.iotivity.org/gerrit/20539
Tested-by: jenkins-iotivity
Reviewed-by: Dan Mihai
---
resource/csdk/security/tool/json2cbor.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/resource/csdk/security/tool/json2cbor.c b/resource/csdk/security/tool/json2cbor.c
index d654a7c..c36c94e 100644
--- a/resource/csdk/security/tool/json2cbor.c
+++ b/resource/csdk/security/tool/json2cbor.c
@@ -421,6 +421,12 @@ static OCStackResult ConvertOCJSONStringToCBORFile(const char *jsonStr, const ch
{
OicSecCred_t *cred = JSONToCredBin(jsonStr);
VERIFY_NOT_NULL(TAG, cred, FATAL);
+ // The source code line below is just a workaround for IOT-2407.
+ // It should be deleted when IOT-2407 gets fixed. There is no clear
+ // correlation between strlen(jsonStr) and the CBOR size, but
+ // CredToCBORPayload happens to work better when initializing
+ // credCborSize this way.
+ credCborSize = strlen(jsonStr);
ret = CredToCBORPayload(cred, &credCbor, &credCborSize, secureFlag);
if (OC_STACK_OK != ret)
{
@@ -1154,7 +1160,7 @@ static OicEncodingType_t GetEncodingTypeFromStr(const char *encodingType)
{
return OIC_ENCODING_DER;
}
- OIC_LOG(WARNING, TAG, "Unknow encoding type dectected!");
+ OIC_LOG(WARNING, TAG, "Unknown encoding type dectected!");
OIC_LOG(WARNING, TAG, "json2cbor will use \"oic.sec.encoding.raw\" as default encoding type.");
return OIC_ENCODING_RAW;
}
@@ -1271,6 +1277,10 @@ OicSecCred_t *JSONToCredBin(const char *jsonStr)
VERIFY_NOT_NULL(TAG, (cred->publicData.data), ERROR);
memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen);
cred->publicData.len = jsonObjLen;
+
+ cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
+ VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
+ cred->publicData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
}
//Optional Data
@@ -1288,7 +1298,6 @@ OicSecCred_t *JSONToCredBin(const char *jsonStr)
cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
cred->optionalData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
-
cJSON *jsonRevstat = cJSON_GetObjectItem(jsonObj, OIC_JSON_REVOCATION_STATUS_NAME);
VERIFY_NOT_NULL(TAG, jsonRevstat, ERROR);
cred->optionalData.revstat = jsonObj->valueint;
--
2.7.4