Mfg crash 35/22535/6
authorVadym Riznyk <v.riznyk@samsung.com>
Wed, 20 Sep 2017 18:02:29 +0000 (21:02 +0300)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 4 Oct 2017 15:08:27 +0000 (15:08 +0000)
1. Added generations certificates for mfg
2. deleted compilations warning

Change-Id: Idfca6974f2436a06d2d5d7676b8b11396cf1803b
Signed-off-by: Vadym Riznyk <v.riznyk@samsung.com>
resource/csdk/security/tool/json2cbor.c

index a0c24f4..229d1b5 100644 (file)
@@ -149,7 +149,7 @@ static OCStackResult WriteBufferToFile(const char *fileName, uint8_t *buffer, si
         }
         else
         {
-            OIC_LOG_V(ERROR, TAG, "Failed writing %" PRIuPTR " bytes - Error: %" PRIi64,
+            OIC_LOG_V(ERROR, TAG, "Failed writing %" PRIuPTR " bytes - Error: %d",
                       size, ferror(fp));
         }
         if (0 != fclose(fp))
@@ -1255,10 +1255,20 @@ OicSecCred_t *JSONToCredBin(const char *jsonStr)
                 cJSON *jsonPriv = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
                 VERIFY_NOT_NULL(TAG, jsonPriv, ERROR);
                 jsonObjLen = strlen(jsonPriv->valuestring);
-                cred->privateData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
+
+                ret = (jsonObjLen % 2 == 0) ? ret : OC_STACK_ERROR;
+
+                char tmp[2];
+                char *buf = (char *)OICCalloc(1, jsonObjLen/2);
+                for(size_t i = 0, p = 0 ; i < jsonObjLen; i+=2, ++p)
+                {
+                    sprintf(tmp, "%c%c", jsonPriv->valuestring[i], jsonPriv->valuestring[i+1]);
+                    buf[p] = (char)strtol(tmp, NULL, 16);
+                }
+                cred->privateData.len = jsonObjLen/2;
+                cred->privateData.data = (uint8_t *)OICCalloc(1, cred->privateData.len);
                 VERIFY_NOT_NULL(TAG, (cred->privateData.data), ERROR);
-                memcpy(cred->privateData.data, jsonPriv->valuestring, jsonObjLen);
-                cred->privateData.len = jsonObjLen;
+                memcpy(cred->privateData.data, buf, cred->privateData.len);
 
                 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                 VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
@@ -1267,18 +1277,28 @@ OicSecCred_t *JSONToCredBin(const char *jsonStr)
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
             //PublicData is mandatory only for SIGNED_ASYMMETRIC_KEY credentials type.
             jsonObj = cJSON_GetObjectItem(jsonCred, OIC_JSON_PUBLICDATA_NAME);
-
             if (NULL != jsonObj)
             {
                 cJSON *jsonPub = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
                 VERIFY_NOT_NULL(TAG, jsonPub, ERROR);
                 jsonObjLen = strlen(jsonPub->valuestring);
-                cred->publicData.data = (uint8_t *)OICCalloc(1, jsonObjLen);
+
+                ret = (jsonObjLen % 2 == 0) ? ret : OC_STACK_ERROR;
+
+                char tmp[2];
+                char *buf = (char *)OICCalloc(1, jsonObjLen/2);
+                for(size_t i = 0, p = 0 ; i < jsonObjLen; i+=2, ++p)
+                {
+                    sprintf(tmp, "%c%c", jsonPub->valuestring[i], jsonPub->valuestring[i+1]);
+                    buf[p] = (char)strtol(tmp, NULL, 16);
+                }
+                cred->publicData.len = jsonObjLen/2;
+                cred->publicData.data = (uint8_t *)OICCalloc(1, cred->publicData.len);
                 VERIFY_NOT_NULL(TAG, (cred->publicData.data), ERROR);
-                memcpy(cred->publicData.data, jsonPub->valuestring, jsonObjLen);
-                cred->publicData.len = jsonObjLen;
+                memcpy(cred->publicData.data, buf, cred->publicData.len);
 
                 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
+
                 VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
                 cred->publicData.encoding = GetEncodingTypeFromStr(jsonEncoding->valuestring);
             }
@@ -1290,10 +1310,20 @@ OicSecCred_t *JSONToCredBin(const char *jsonStr)
                 cJSON *jsonOpt = cJSON_GetObjectItem(jsonObj, OIC_JSON_DATA_NAME);
                 VERIFY_NOT_NULL(TAG, jsonOpt, ERROR);
                 jsonObjLen = strlen(jsonOpt->valuestring);
-                cred->optionalData.data =  (uint8_t *)OICCalloc(1, jsonObjLen);
+
+                ret = (jsonObjLen % 2 == 0) ? ret : OC_STACK_ERROR;
+                char tmp[2];
+                char *buf = (char *)OICCalloc(1, jsonObjLen/2);
+                for(size_t i = 0, p = 0; i < jsonObjLen; i+=2, ++p)
+                {
+                    sprintf(tmp, "%c%c", jsonOpt->valuestring[i], jsonOpt->valuestring[i+1]);
+                    buf[p] = (char)strtol(tmp, NULL, 16);
+                }
+                cred->optionalData.len = jsonObjLen/2;
+
+                cred->optionalData.data =  (uint8_t *)OICCalloc(1, cred->optionalData.len);
                 VERIFY_NOT_NULL(TAG, (cred->optionalData.data), ERROR);
-                memcpy(cred->optionalData.data, jsonOpt->valuestring, jsonObjLen);
-                cred->optionalData.len = jsonObjLen;
+                memcpy(cred->optionalData.data, buf, cred->optionalData.len);
 
                 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                 VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);