@@ -381,7 +381,7 @@ crust_status_t id_verify_iasreport(char **IASReport, size_t size)
381381 uint8_t *p_account_id_u = hex_string_to_bytes (chain_account_id.c_str (), chain_account_id.size ());
382382 size_t account_id_u_len = chain_account_id.size () / 2 ;
383383 uint8_t *org_data, *p_org_data = NULL ;
384- size_t org_data_len = 0 ;
384+ uint32_t org_data_len = 0 ;
385385
386386
387387 // ----- Verify IAS signature ----- //
@@ -602,22 +602,26 @@ crust_status_t id_verify_iasreport(char **IASReport, size_t size)
602602
603603cleanup:
604604 if (pkey != NULL )
605- {
606605 EVP_PKEY_free (pkey);
607- }
606+
608607 cert_stack_free (stack);
609- free (certar);
608+
609+ if (certar != NULL )
610+ free (certar);
611+
610612 for (i = 0 ; i < count; ++i)
611613 {
612614 X509_free (certvec[i]);
613615 }
614616
615- free (sig);
616- free (iasQuote);
617+ if (sig != NULL )
618+ free (sig);
619+
620+ if (iasQuote != NULL )
621+ free (iasQuote);
622+
617623 if (ecc_state != NULL )
618- {
619624 sgx_ecc256_close_context (ecc_state);
620- }
621625
622626 if (p_org_data != NULL )
623627 free (p_org_data);
@@ -897,36 +901,31 @@ crust_status_t id_store_metadata()
897901 sgx_thread_mutex_lock (&g_metadata_mutex);
898902
899903 // Get original metadata
904+ Workload *wl = Workload::get_instance ();
900905 crust_status_t crust_status = CRUST_SUCCESS;
901- json::JSON meta_json;
902- size_t meta_len = 0 ;
903- uint8_t *p_meta = NULL ;
904906 std::string hex_id_key_str = hexstring_safe (&id_key_pair, sizeof (id_key_pair));
905- id_get_metadata (meta_json, false );
906907
907908 // ----- Store metadata ----- //
908- meta_json[ID_WORKLOAD] = Workload::get_instance ()->serialize_srd ();
909- meta_json[ID_KEY_PAIR] = hex_id_key_str;
910- meta_json[ID_REPORT_SLOG] = report_slot;
911- meta_json[ID_CHAIN_ACCOUNT_ID] = g_chain_account_id;
912- std::string meta_str = meta_json.dump ();
913- meta_len = meta_str.size () + strlen (TEE_PRIVATE_TAG);
914- p_meta = (uint8_t *)enc_malloc (meta_len);
915- if (p_meta == NULL )
916- {
917- crust_status = CRUST_MALLOC_FAILED;
918- goto cleanup;
919- }
920- memset (p_meta, 0 , meta_len);
921- memcpy (p_meta, TEE_PRIVATE_TAG, strlen (TEE_PRIVATE_TAG));
922- memcpy (p_meta + strlen (TEE_PRIVATE_TAG), meta_str.c_str (), meta_str.size ());
923- crust_status = persist_set (ID_METADATA, p_meta, meta_len);
924-
925-
926- cleanup:
927-
928- if (p_meta != NULL )
929- free (p_meta);
909+ std::string meta_str (TEE_PRIVATE_TAG);
910+ meta_str.append (" {" );
911+ // Append srd
912+ meta_str.append (" \" " ).append (ID_WORKLOAD).append (" \" :" )
913+ .append (wl->serialize_srd ()).append (" ," );
914+ // Append id key pair
915+ meta_str.append (" \" " ).append (ID_KEY_PAIR).append (" \" :" )
916+ .append (" \" " ).append (hex_id_key_str).append (" \" ," );
917+ // Append report slot
918+ meta_str.append (" \" " ).append (ID_REPORT_SLOT).append (" \" :" )
919+ .append (" \" " ).append (std::to_string (report_slot)).append (" \" ," );
920+ // Append chain account id
921+ meta_str.append (" \" " ).append (ID_CHAIN_ACCOUNT_ID).append (" \" :" )
922+ .append (" \" " ).append (g_chain_account_id).append (" \" ," );
923+ // Append files
924+ meta_str.append (" \" " ).append (ID_FILE).append (" \" :" )
925+ .append (wl->serialize_file ());
926+ meta_str.append (" }" );
927+
928+ crust_status = persist_set (ID_METADATA, reinterpret_cast <const uint8_t *>(meta_str.c_str ()), meta_str.size ());
930929
931930 sgx_thread_mutex_unlock (&g_metadata_mutex);
932931
@@ -996,7 +995,7 @@ crust_status_t id_restore_metadata()
996995 memcpy (&id_key_pair, p_id_key, sizeof (id_key_pair));
997996 free (p_id_key);
998997 // Restore report slot
999- report_slot = meta_json[ID_REPORT_SLOG ].ToInt ();
998+ report_slot = meta_json[ID_REPORT_SLOT ].ToInt ();
1000999 // Restore chain account id
10011000 g_chain_account_id = meta_json[ID_CHAIN_ACCOUNT_ID].ToString ();
10021001
@@ -1044,14 +1043,12 @@ crust_status_t id_set_chain_account_id(const char *account_id, size_t len)
10441043 return CRUST_DOUBLE_SET_VALUE;
10451044 }
10461045
1047- char *buffer = (char *)enc_malloc (len);
1048- if (buffer == NULL )
1046+ if (account_id == NULL )
10491047 {
1050- return CRUST_MALLOC_FAILED ;
1048+ return CRUST_UNEXPECTED_ERROR ;
10511049 }
1052- memset (buffer, 0 , len);
1053- memcpy (buffer, account_id, len);
1054- g_chain_account_id = string (buffer, len);
1050+
1051+ g_chain_account_id = string (account_id, len);
10551052 g_is_set_account_id = true ;
10561053
10571054 return CRUST_SUCCESS;
@@ -1082,7 +1079,6 @@ size_t id_get_report_slot()
10821079void id_set_report_slot (size_t new_report_slot)
10831080{
10841081 report_slot = new_report_slot;
1085- id_metadata_set_or_append (ID_REPORT_SLOG, std::to_string (report_slot));
10861082}
10871083
10881084/* *
0 commit comments