Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
fcc_output_info_handler.c
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // Licensed under the Apache License, Version 2.0 (the "License"); 00005 // you may not use this file except in compliance with the License. 00006 // You may obtain a copy of the License at 00007 // 00008 // http://www.apache.org/licenses/LICENSE-2.0 00009 // 00010 // Unless required by applicable law or agreed to in writing, software 00011 // distributed under the License is distributed on an "AS IS" BASIS, 00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 // See the License for the specific language governing permissions and 00014 // limitations under the License. 00015 // ---------------------------------------------------------------------------- 00016 00017 #include <stdlib.h> 00018 #include "pv_error_handling.h" 00019 #include "fcc_status.h" 00020 #include "fcc_output_info_handler.h" 00021 #include "fcc_malloc.h" 00022 #include "kcm_defs.h" 00023 00024 // Macros for stringizing defines 00025 #define xstr(a) str(a) 00026 #define str(a) #a 00027 00028 00029 //General error string 00030 const char g_fcc_general_status_error_str[] = "General error:"; 00031 00032 //fcc error strings 00033 const char g_fcc_ca_error_str[] = "CA error:"; 00034 const char g_fcc_rot_error_str[] = "Root of trust error:"; 00035 const char g_fcc_entropy_error_str[] = "Entropy error:"; 00036 const char g_fcc_disabled_error_str[] = "Factory disabled error:"; 00037 const char g_fcc_invalid_certificate_error_str[] = "Certificate invalid:"; 00038 const char g_fcc_item_not_exists_error_str[] = "Item does not exist:"; 00039 const char g_fcc_meta_data_not_exists_error_str[] = "Meta data does not exist:"; 00040 const char g_fcc_meta_data_size_error_str[] = "Meta data does not exist:"; 00041 const char g_fcc_wrong_item_size_error_str[] = "Item size is wrong:"; 00042 const char g_fcc_empty_item_error_str[] = "Item empty:"; 00043 const char g_fcc_uri_wrong_format_error_str[] = "URI format incorrect:"; 00044 const char g_fcc_first_to_claim_not_allowed_error_str[] = "first to claim not allowed:"; 00045 const char g_fcc_wrong_utc_offset_value_error_str[] = "UTC offset incorrect:"; 00046 const char g_fcc_wrong_bootstrap_use_value_error_str[] = "Bootstrap mode value incorrect:"; 00047 const char g_fcc_not_permitted_error_str[] = "Operation not permitted:"; 00048 const char g_fcc_wrong_ca_certificate_error_str[] = "Validation of CA certificate failed:"; 00049 const char g_fcc_invalid_cn_certificate_error_str[] = "Certificate CN attribute invalid:"; 00050 const char g_fcc_crypto_public_key_correlation_error_str[] = "Certificate public key validation failed:"; 00051 const char g_fcc_internal_storage_error_str[] = "Internal storage error:"; 00052 const char g_fcc_csr_requests_too_many[] = "Too many CSR requests. Maximum CSR requests supported is " xstr(CSR_MAX_NUMBER_OF_CSRS); 00053 //kcm crypto error strings 00054 const char g_fcc_kcm_file_error_str[] = "File operation general error:"; 00055 const char g_fcc_kcm_invalid_file_version_str[] = "File version invalid:"; 00056 const char g_fcc_kcm_file_data_corrupted_str[] = "File data corrupted:"; 00057 const char g_fcc_kcm_file_name_corrupted_str[] = "File name corrupted:"; 00058 const char g_fcc_kcm_file_name_invalid_str[] = "File name invalid:"; 00059 const char g_fcc_kcm_not_initialized_str[] = "KCM not initialized:"; 00060 const char g_fcc_kcm_close_incomplete_chain_str[] = "Closing incomplete KCM chain:"; 00061 const char g_fcc_kcm_invalid_chain_str[] = "Corrupted certificate chain file:"; 00062 const char g_fcc_kcm_invalid_num_of_cert_in_chain_str[] = "Maximum chain length supported is " xstr(KCM_MAX_NUMBER_OF_CERTITICATES_IN_CHAIN) ". Chain length of the item is invalid:"; 00063 const char g_fcc_kcm_file_exist_error_str[] = "Data already exists:"; 00064 const char g_fcc_kcm_key_exist_error_str[] = "Desired generated key name already exists:"; 00065 const char g_fcc_kcm_file_name_too_long_error_str[] = "File name too long:"; 00066 const char g_fcc_crypto_kcm_error_str[] = "KCM crypto error:"; 00067 const char g_fcc_crypto_empty_item_error_str[] = "Item data empty:"; 00068 const char g_fcc_crypto_unsupported_hash_mode_error_str[] = "Hash mode unsupported:"; 00069 const char g_fcc_crypto_parsing_der_pivate_key_error_str[] = "Private key parse failed:"; 00070 const char g_fcc_crypto_parsing_der_public_key_error_str[] = "Public key parse failed:"; 00071 const char g_fcc_crypto_verify_private_key_error_str[] = "Private key verification failed:"; 00072 const char g_fcc_crypto_verify_public_key_error_str[] = "Public key verification failed:"; 00073 const char g_fcc_crypto_unsupported_curve_error_str[] = "Curve unsupported:"; 00074 const char g_fcc_crypto_parsing_der_cert_error_str[] = "Certificate parse failed:"; 00075 const char g_fcc_crypto_cert_expired_error_str[] = "Certificate expired:"; 00076 const char g_fcc_crypto_cert_future_error_str[] = "Certificate will be valid in the future:"; 00077 const char g_fcc_crypto_cert_md_alg_error_str[] = "Certificate MD algorithm error:"; 00078 const char g_fcc_crypto_cert_public_key_type_error_str[] = "Certificate public key type error:"; 00079 const char g_fcc_crypto_cert_public_key_error_str[] = "Certificate public key error:"; 00080 const char g_fcc_crypto_cert_not_trusted_error_str[] = "Certificate not trusted:"; 00081 const char g_fcc_crypto_invalid_x509_attr_error_str[] = "X509 attribute invalid:"; 00082 const char g_fcc_crypto_invalid_x509_extension_error_str[] = "X509 extension invalid:"; 00083 const char g_fcc_crypto_invalid_pk_key_format_error_str[] = "Public key format invalid:"; 00084 const char g_fcc_crypto_invalid_public_key_error_str[] = "Public key invalid:"; 00085 const char g_fcc_crypto_ecp_invalid_key_error_str[] = "EC key invalid:"; 00086 const char g_fcc_crypto_pk_key_invalid_version_error_str[] = "Public key version invalid:"; 00087 const char g_fcc_crypto_pk_password_requerd_error_str[] = "Public key password required:"; 00088 const char g_fcc_crypto_unknown_pk_algorithm_error_str[] = "Public key algorithm unknown:"; 00089 const char g_fcc_crypto_chain_validation_error_str[] = "Chain validation error:"; 00090 const char g_fcc_self_generated_certificate_validation_error_str[] = "Self-generated certificate validation failed:"; 00091 //warning strings 00092 const char g_fcc_item_not_set_warning_str[] = "Item not set:"; 00093 00094 const char g_fcc_bootstrap_mode_false_warning_str[] = "Bootstrap mode not activated:"; 00095 const char g_fcc_self_signed_warning_str[] = "Certificate is self signed:"; 00096 const char g_fcc_item_is_empty_warning_str[] = "Item empty:"; 00097 const char g_fcc_redundant_item_warning_str[] = "Item redundant:"; 00098 const char g_fcc_cert_time_validity_warning_str[] = "Certificate validity cannot be checked:"; 00099 const char g_fcc_cert_validity_less_10_years_warning_str[] = "Certificate validity is less than 10 years:"; 00100 const char g_fcc_ca_identifier_warning_str[] = "CA identifier wasn't set properly:"; 00101 00102 fcc_output_info_s g_output_info; 00103 00104 00105 /** The function frees all allocated buffers 00106 * @param output_warning_info[in] The pointer to created fcc_warning_info_s structure 00107 */ 00108 static void fcc_free_list_of_warnings(fcc_warning_info_s *output_warning_info) 00109 { 00110 fcc_warning_info_s *current_node = output_warning_info; 00111 fcc_warning_info_s *next_node = output_warning_info->next; 00112 00113 while (current_node != NULL) { 00114 if (current_node->warning_info_string != NULL) { 00115 fcc_free(current_node->warning_info_string); 00116 } 00117 fcc_free(current_node); 00118 current_node = next_node; 00119 if (current_node != NULL) { 00120 next_node = current_node->next; 00121 } 00122 } 00123 } 00124 /** The function combines message string info and failed item, and sets it to passed pointer. 00125 * @param message_string[in] The message string - error or warning 00126 * @param failed_item_name[in] The name of item. 00127 * @param failed_item_name_size[in] The size of item's name. 00128 * @param out_string[in/out] The output string where the combined message should be copied. 00129 */ 00130 static fcc_status_e fcc_set_output_string_info(const char *message_string, const uint8_t *failed_item_name, size_t failed_item_name_size, char **out_string) 00131 { 00132 fcc_status_e fcc_status = FCC_STATUS_SUCCESS; 00133 00134 SA_PV_LOG_TRACE_FUNC_ENTER_NO_ARGS(); 00135 00136 //Allocate memory for error info 00137 *out_string = fcc_malloc(strlen(message_string) + failed_item_name_size + 1); // 1 char for '\0' 00138 SA_PV_ERR_RECOVERABLE_RETURN_IF((out_string == NULL), fcc_status = FCC_STATUS_MEMORY_OUT, "Failed to allocate buffer for output info"); 00139 00140 //Copy to the global structure error string info 00141 strcpy((*out_string), message_string); 00142 00143 //Copy to the global structure the name of failed item if it exists. 00144 if (failed_item_name != NULL) { 00145 memcpy((uint8_t*)(*out_string) + strlen(message_string), failed_item_name, failed_item_name_size); 00146 //Set '\0' in the end of error string info 00147 (*out_string)[strlen(message_string) + failed_item_name_size] = '\0'; 00148 } 00149 00150 00151 SA_PV_LOG_TRACE_FUNC_EXIT_NO_ARGS(); 00152 return fcc_status; 00153 } 00154 00155 static size_t fcc_get_size_of_all_warning_strings() 00156 { 00157 fcc_warning_info_s *current_node = g_output_info.head_of_warning_list; 00158 size_t size_of_all_warning_strings = 0; 00159 00160 SA_PV_LOG_INFO_FUNC_ENTER_NO_ARGS(); 00161 00162 while (current_node != NULL) { 00163 size_of_all_warning_strings += strlen(current_node->warning_info_string); 00164 current_node = current_node->next; 00165 } 00166 00167 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00168 return size_of_all_warning_strings; 00169 } 00170 00171 static bool copy_all_warning_to_buffer(char *out_warning_string, size_t size_of_out_warning_string) 00172 { 00173 fcc_warning_info_s *current_node = g_output_info.head_of_warning_list; 00174 size_t length_of_iterated_strings = 0; 00175 00176 memset(out_warning_string, 0, size_of_out_warning_string); 00177 00178 while (current_node != NULL) { 00179 //Calculate size of current warning 00180 if (length_of_iterated_strings + strlen(current_node->warning_info_string) + 1 > size_of_out_warning_string) { 00181 return false; 00182 } 00183 strcpy(out_warning_string + length_of_iterated_strings, current_node->warning_info_string); 00184 //Set '\n' in the end of warning string info 00185 (out_warning_string)[length_of_iterated_strings + strlen(current_node->warning_info_string)] = '\n'; 00186 length_of_iterated_strings += strlen(current_node->warning_info_string) + 1; 00187 current_node = current_node->next; 00188 } 00189 //Increase the size for '\0' 00190 if (length_of_iterated_strings >= size_of_out_warning_string) { 00191 return false; 00192 } 00193 (out_warning_string)[length_of_iterated_strings] = '\0'; 00194 00195 return true; 00196 } 00197 /** The function returns error string according to passed fcc_status. 00198 * @param fcc_status[in] The fcc_status 00199 * 00200 */ 00201 00202 char* fcc_get_fcc_error_string(fcc_status_e fcc_status) 00203 { 00204 SA_PV_LOG_TRACE_FUNC_ENTER("fcc_status is %d", fcc_status); 00205 char *fcc_error_string = NULL; 00206 00207 switch (fcc_status) { 00208 case FCC_STATUS_ERROR: 00209 case FCC_STATUS_MEMORY_OUT: 00210 case FCC_STATUS_INVALID_PARAMETER: 00211 case FCC_STATUS_KCM_ERROR: 00212 case FCC_STATUS_BUNDLE_ERROR: 00213 case FCC_STATUS_BUNDLE_RESPONSE_ERROR: 00214 case FCC_STATUS_BUNDLE_UNSUPPORTED_GROUP: 00215 case FCC_STATUS_BUNDLE_INVALID_SCHEME: 00216 case FCC_STATUS_BUNDLE_INVALID_KEEP_ALIVE_SESSION_STATUS: 00217 case FCC_STATUS_BUNDLE_INVALID_GROUP: 00218 case FCC_STATUS_KCM_STORAGE_ERROR: 00219 case FCC_STATUS_KCM_FILE_EXIST_ERROR: 00220 case FCC_STATUS_NOT_INITIALIZED: 00221 case FCC_STATUS_OUTPUT_INFO_ERROR: 00222 case FCC_STATUS_WARNING_CREATE_ERROR: 00223 case FCC_STATUS_INVALID_CERT_ATTRIBUTE: 00224 case FCC_STATUS_INTERNAL_ITEM_ALREADY_EXIST: 00225 case FCC_STATUS_NOT_SUPPORTED: 00226 fcc_error_string = (char*)g_fcc_general_status_error_str; 00227 break; 00228 case FCC_STATUS_CA_ERROR: 00229 fcc_error_string = (char*)g_fcc_ca_error_str; 00230 break; 00231 case FCC_STATUS_ROT_ERROR: 00232 fcc_error_string = (char*)g_fcc_rot_error_str; 00233 break; 00234 case FCC_STATUS_STORE_ERROR: 00235 fcc_error_string = (char*)g_fcc_internal_storage_error_str; 00236 break; 00237 case FCC_STATUS_KCM_CRYPTO_ERROR: 00238 fcc_error_string = (char*)g_fcc_crypto_kcm_error_str; 00239 break; 00240 case FCC_STATUS_INVALID_CERTIFICATE: 00241 fcc_error_string = (char*)g_fcc_invalid_certificate_error_str; 00242 break; 00243 case FCC_STATUS_INVALID_LWM2M_CN_ATTR: 00244 fcc_error_string = (char*)g_fcc_invalid_cn_certificate_error_str; 00245 break; 00246 case FCC_STATUS_ENTROPY_ERROR: 00247 fcc_error_string = (char*)g_fcc_entropy_error_str; 00248 break; 00249 case FCC_STATUS_FACTORY_DISABLED_ERROR: 00250 fcc_error_string = (char*)g_fcc_disabled_error_str; 00251 break; 00252 case FCC_STATUS_ITEM_NOT_EXIST: 00253 fcc_error_string = (char*)g_fcc_item_not_exists_error_str; 00254 break; 00255 case FCC_STATUS_WRONG_ITEM_DATA_SIZE: 00256 fcc_error_string = (char*)g_fcc_wrong_item_size_error_str; 00257 break; 00258 case FCC_STATUS_EMPTY_ITEM: 00259 fcc_error_string = (char*)g_fcc_empty_item_error_str; 00260 break; 00261 case FCC_STATUS_URI_WRONG_FORMAT: 00262 fcc_error_string = (char*)g_fcc_uri_wrong_format_error_str; 00263 break; 00264 case FCC_STATUS_FIRST_TO_CLAIM_NOT_ALLOWED: 00265 fcc_error_string = (char*)g_fcc_first_to_claim_not_allowed_error_str; 00266 break; 00267 case FCC_STATUS_BOOTSTRAP_MODE_ERROR: 00268 fcc_error_string = (char*)g_fcc_wrong_bootstrap_use_value_error_str; 00269 break; 00270 case FCC_STATUS_UTC_OFFSET_WRONG_FORMAT: 00271 fcc_error_string = (char*)g_fcc_wrong_utc_offset_value_error_str; 00272 break; 00273 case FCC_STATUS_INVALID_CA_CERT_SIGNATURE: 00274 fcc_error_string = (char*)g_fcc_wrong_ca_certificate_error_str; 00275 break; 00276 case FCC_STATUS_EXPIRED_CERTIFICATE: 00277 fcc_error_string = (char*)g_fcc_crypto_cert_expired_error_str; 00278 break; 00279 case FCC_STATUS_CERTIFICATE_PUBLIC_KEY_CORRELATION_ERROR: 00280 fcc_error_string = (char*)g_fcc_crypto_public_key_correlation_error_str; 00281 break; 00282 case FCC_STATUS_TOO_MANY_CSR_REQUESTS: 00283 fcc_error_string = (char*)g_fcc_csr_requests_too_many; 00284 break; 00285 case FCC_STATUS_SUCCESS: 00286 case FCC_MAX_STATUS: 00287 return fcc_error_string; 00288 00289 } 00290 if (fcc_error_string != NULL) { 00291 SA_PV_LOG_TRACE_FUNC_EXIT("fcc_error_string is %s", fcc_error_string); 00292 } 00293 return fcc_error_string; 00294 } 00295 00296 /** The function returns error string according to passed kcm_status. 00297 * @param kcm_status[in] The kcm_status 00298 * 00299 */ 00300 00301 char* fcc_get_kcm_error_string(kcm_status_e kcm_status) 00302 { 00303 SA_PV_LOG_TRACE_FUNC_ENTER("kcm_status is %d", kcm_status); 00304 00305 char *kcm_error_string = NULL; 00306 00307 switch (kcm_status) { 00308 case KCM_STATUS_ERROR: 00309 case KCM_STATUS_INVALID_PARAMETER: 00310 case KCM_STATUS_INSUFFICIENT_BUFFER: 00311 case KCM_STATUS_OUT_OF_MEMORY: 00312 case KCM_STATUS_INVALID_FILE_ACCESS_MODE: 00313 case KCM_STATUS_UNKNOWN_STORAGE_ERROR: 00314 case KCM_CRYPTO_STATUS_INVALID_MD_TYPE: 00315 case KCM_CRYPTO_STATUS_FAILED_TO_WRITE_SIGNATURE: 00316 case KCM_CRYPTO_STATUS_VERIFY_SIGNATURE_FAILED: 00317 case KCM_CRYPTO_STATUS_FAILED_TO_WRITE_PRIVATE_KEY: 00318 case KCM_CRYPTO_STATUS_FAILED_TO_WRITE_PUBLIC_KEY: 00319 case KCM_CRYPTO_STATUS_FAILED_TO_WRITE_CSR: 00320 case KCM_CRYPTO_STATUS_INVALID_OID: 00321 case KCM_CRYPTO_STATUS_INVALID_NAME_FORMAT: 00322 case KCM_STATUS_RBP_ERROR: 00323 kcm_error_string = (char*)g_fcc_general_status_error_str; 00324 break; 00325 case KCM_STATUS_SELF_GENERATED_CERTIFICATE_VERIFICATION_ERROR: 00326 kcm_error_string = (char*)g_fcc_self_generated_certificate_validation_error_str; 00327 break; 00328 case KCM_STATUS_STORAGE_ERROR: 00329 kcm_error_string = (char*)g_fcc_kcm_file_error_str; 00330 break; 00331 case KCM_STATUS_INVALID_FILE_VERSION: 00332 kcm_error_string = (char*)g_fcc_kcm_invalid_file_version_str; 00333 break; 00334 case KCM_STATUS_FILE_CORRUPTED: 00335 kcm_error_string = (char*)g_fcc_kcm_file_data_corrupted_str; 00336 break; 00337 case KCM_STATUS_NOT_INITIALIZED: 00338 kcm_error_string = (char*)g_fcc_kcm_not_initialized_str; 00339 break; 00340 case KCM_STATUS_CLOSE_INCOMPLETE_CHAIN: 00341 kcm_error_string = (char*)g_fcc_kcm_close_incomplete_chain_str; 00342 break; 00343 case KCM_STATUS_CORRUPTED_CHAIN_FILE: 00344 kcm_error_string = (char*)g_fcc_kcm_invalid_chain_str; 00345 break; 00346 case KCM_STATUS_INVALID_NUM_OF_CERT_IN_CHAIN: 00347 kcm_error_string = (char*)g_fcc_kcm_invalid_num_of_cert_in_chain_str; 00348 break; 00349 case KCM_STATUS_CERTIFICATE_CHAIN_VERIFICATION_FAILED: 00350 kcm_error_string = (char*)g_fcc_crypto_chain_validation_error_str; 00351 break; 00352 case KCM_STATUS_ITEM_NOT_FOUND: 00353 kcm_error_string = (char*)g_fcc_item_not_exists_error_str; 00354 break; 00355 case KCM_STATUS_META_DATA_NOT_FOUND: 00356 kcm_error_string = (char*)g_fcc_meta_data_not_exists_error_str; 00357 break; 00358 case KCM_STATUS_META_DATA_SIZE_ERROR: 00359 kcm_error_string = (char*)g_fcc_meta_data_size_error_str; 00360 break; 00361 case KCM_STATUS_NOT_PERMITTED: 00362 kcm_error_string = (char*)g_fcc_not_permitted_error_str; 00363 break; 00364 case KCM_STATUS_FILE_EXIST: 00365 kcm_error_string = (char*)g_fcc_kcm_file_exist_error_str; 00366 break; 00367 case KCM_STATUS_KEY_EXIST: 00368 kcm_error_string = (char*)g_fcc_kcm_key_exist_error_str; 00369 break; 00370 case KCM_STATUS_FILE_NAME_CORRUPTED: 00371 kcm_error_string = (char*)g_fcc_kcm_file_name_corrupted_str; 00372 break; 00373 case KCM_STATUS_FILE_NAME_INVALID: 00374 kcm_error_string = (char*)g_fcc_kcm_file_name_invalid_str; 00375 break; 00376 case KCM_STATUS_ITEM_IS_EMPTY: 00377 kcm_error_string = (char*)g_fcc_crypto_empty_item_error_str; 00378 break; 00379 case KCM_STATUS_FILE_NAME_TOO_LONG: 00380 kcm_error_string = (char*)g_fcc_kcm_file_name_too_long_error_str; 00381 break; 00382 case KCM_CRYPTO_STATUS_UNSUPPORTED_HASH_MODE: 00383 kcm_error_string = (char*)g_fcc_crypto_unsupported_hash_mode_error_str; 00384 break; 00385 case KCM_CRYPTO_STATUS_PARSING_DER_PRIVATE_KEY: 00386 kcm_error_string = (char*)g_fcc_crypto_parsing_der_pivate_key_error_str; 00387 break; 00388 case KCM_CRYPTO_STATUS_PARSING_DER_PUBLIC_KEY: 00389 kcm_error_string = (char*)g_fcc_crypto_parsing_der_public_key_error_str; 00390 break; 00391 case KCM_CRYPTO_STATUS_PRIVATE_KEY_VERIFICATION_FAILED: 00392 kcm_error_string = (char*)g_fcc_crypto_verify_private_key_error_str; 00393 break; 00394 case KCM_CRYPTO_STATUS_PUBLIC_KEY_VERIFICATION_FAILED: 00395 kcm_error_string = (char*)g_fcc_crypto_verify_public_key_error_str; 00396 break; 00397 case KCM_CRYPTO_STATUS_UNSUPPORTED_CURVE: 00398 kcm_error_string = (char*)g_fcc_crypto_unsupported_curve_error_str; 00399 break; 00400 case KCM_CRYPTO_STATUS_PARSING_DER_CERT: 00401 kcm_error_string = (char*)g_fcc_crypto_parsing_der_cert_error_str; 00402 break; 00403 case KCM_CRYPTO_STATUS_CERT_EXPIRED: 00404 kcm_error_string = (char*)g_fcc_crypto_cert_expired_error_str; 00405 break; 00406 case KCM_CRYPTO_STATUS_CERT_FUTURE: 00407 kcm_error_string = (char*)g_fcc_crypto_cert_future_error_str; 00408 break; 00409 case KCM_CRYPTO_STATUS_CERT_MD_ALG: 00410 kcm_error_string = (char*)g_fcc_crypto_cert_md_alg_error_str; 00411 break; 00412 case KCM_CRYPTO_STATUS_CERT_PUB_KEY_TYPE: 00413 kcm_error_string = (char*)g_fcc_crypto_cert_public_key_type_error_str; 00414 break; 00415 case KCM_CRYPTO_STATUS_CERT_PUB_KEY: 00416 kcm_error_string = (char*)g_fcc_crypto_cert_public_key_error_str; 00417 break; 00418 case KCM_CRYPTO_STATUS_CERT_NOT_TRUSTED: 00419 kcm_error_string = (char*)g_fcc_crypto_cert_not_trusted_error_str; 00420 break; 00421 case KCM_CRYPTO_STATUS_INVALID_X509_ATTR: 00422 kcm_error_string = (char*)g_fcc_crypto_invalid_x509_attr_error_str; 00423 break; 00424 case KCM_CRYPTO_STATUS_PK_KEY_INVALID_FORMAT: 00425 kcm_error_string = (char*)g_fcc_crypto_invalid_pk_key_format_error_str; 00426 break; 00427 case KCM_CRYPTO_STATUS_INVALID_PK_PUBKEY: 00428 kcm_error_string = (char*)g_fcc_crypto_invalid_public_key_error_str; 00429 break; 00430 case KCM_CRYPTO_STATUS_ECP_INVALID_KEY: 00431 kcm_error_string = (char*)g_fcc_crypto_ecp_invalid_key_error_str; 00432 break; 00433 case KCM_CRYPTO_STATUS_PK_KEY_INVALID_VERSION: 00434 kcm_error_string = (char*)g_fcc_crypto_pk_key_invalid_version_error_str; 00435 break; 00436 case KCM_CRYPTO_STATUS_PK_PASSWORD_REQUIRED: 00437 kcm_error_string = (char*)g_fcc_crypto_pk_password_requerd_error_str; 00438 break; 00439 case KCM_CRYPTO_STATUS_PK_UNKNOWN_PK_ALG: 00440 kcm_error_string = (char*)g_fcc_crypto_unknown_pk_algorithm_error_str; 00441 break; 00442 case KCM_CRYPTO_STATUS_SET_EXTENSION_FAILED: 00443 kcm_error_string = (char*)g_fcc_crypto_invalid_x509_attr_error_str; 00444 break; 00445 case KCM_STATUS_SUCCESS: 00446 case KCM_MAX_STATUS: 00447 return kcm_error_string; 00448 } 00449 00450 if (kcm_error_string != NULL) { 00451 SA_PV_LOG_TRACE_FUNC_EXIT("kcm_error_string is %s", kcm_error_string); 00452 } 00453 return kcm_error_string; 00454 } 00455 00456 fcc_output_info_s* get_output_info(void) 00457 { 00458 return &g_output_info; 00459 } 00460 00461 void fcc_init_output_info_handler() 00462 { 00463 SA_PV_LOG_INFO_FUNC_ENTER_NO_ARGS(); 00464 00465 g_output_info.error_string_info = NULL; 00466 g_output_info.head_of_warning_list = NULL; 00467 g_output_info.tail_of_warning_list = NULL; 00468 g_output_info.size_of_warning_info_list = 0; 00469 00470 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00471 } 00472 00473 void fcc_clean_output_info_handler() 00474 { 00475 SA_PV_LOG_INFO_FUNC_ENTER_NO_ARGS(); 00476 00477 fcc_free(g_output_info.error_string_info); 00478 g_output_info.error_string_info = NULL; 00479 00480 if (g_output_info.head_of_warning_list != NULL) { 00481 fcc_free_list_of_warnings(g_output_info.head_of_warning_list); 00482 } 00483 g_output_info.size_of_warning_info_list = 0; 00484 g_output_info.tail_of_warning_list = NULL; 00485 g_output_info.head_of_warning_list = NULL; 00486 00487 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00488 } 00489 00490 fcc_status_e fcc_store_warning_info(const uint8_t *failed_item_name, size_t failed_item_name_size, const char *warning_string) 00491 { 00492 fcc_status_e fcc_status = FCC_STATUS_SUCCESS; 00493 fcc_warning_info_s *new_node = NULL; 00494 00495 SA_PV_ERR_RECOVERABLE_RETURN_IF((warning_string == NULL), fcc_status = FCC_STATUS_INVALID_PARAMETER, "Warning string is empty"); 00496 SA_PV_LOG_INFO_FUNC_ENTER("warning_string is %s", warning_string); 00497 //Check parameters (failed_item_name can be NULL) 00498 SA_PV_ERR_RECOVERABLE_RETURN_IF((failed_item_name != NULL && failed_item_name_size == 0), fcc_status = FCC_STATUS_INVALID_PARAMETER, "Wrong failed item name parameters"); 00499 00500 //Allocate new node 00501 new_node = (fcc_warning_info_s*)fcc_malloc(sizeof(fcc_warning_info_s)); 00502 SA_PV_ERR_RECOVERABLE_RETURN_IF((new_node == NULL), fcc_status = FCC_STATUS_MEMORY_OUT, "Failed to allocate memory for new warning list"); 00503 00504 //Set the new node with warning info (message and item name) 00505 fcc_status = fcc_set_output_string_info(warning_string, failed_item_name, failed_item_name_size, &(new_node->warning_info_string)); 00506 SA_PV_ERR_RECOVERABLE_GOTO_IF((fcc_status != FCC_STATUS_SUCCESS), fcc_status = FCC_STATUS_ERROR, exit_with_error, "Failed to set warning string info\n"); 00507 00508 //Update the list 00509 if (g_output_info.head_of_warning_list == NULL) { 00510 //In case this is the first node 00511 g_output_info.head_of_warning_list = g_output_info.tail_of_warning_list = new_node; 00512 } else { 00513 //In case this is an additional node 00514 g_output_info.tail_of_warning_list->next = new_node; 00515 g_output_info.tail_of_warning_list = new_node; 00516 } 00517 g_output_info.tail_of_warning_list->next = NULL; 00518 g_output_info.size_of_warning_info_list++; 00519 00520 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00521 return fcc_status; 00522 00523 exit_with_error: 00524 fcc_free(new_node); 00525 return fcc_status; 00526 } 00527 00528 fcc_status_e fcc_bundle_store_error_info(const uint8_t *failed_item_name, size_t failed_item_name_size, kcm_status_e kcm_status) 00529 { 00530 fcc_status_e fcc_status = FCC_STATUS_SUCCESS; 00531 char *error_string_info = NULL; 00532 00533 SA_PV_LOG_INFO_FUNC_ENTER("kcm_status is %d", kcm_status); 00534 00535 //Check parameters (failed_item_name can be NULL) 00536 SA_PV_ERR_RECOVERABLE_RETURN_IF((kcm_status == KCM_STATUS_SUCCESS), fcc_status = FCC_STATUS_INVALID_PARAMETER, "The fcc_bundle_store_error_info should not be called with success status"); 00537 SA_PV_ERR_RECOVERABLE_RETURN_IF((failed_item_name != NULL && failed_item_name_size == 0), fcc_status = FCC_STATUS_INVALID_PARAMETER, "Wrong failed item name parameters"); 00538 00539 //Get kcm error string 00540 error_string_info = fcc_get_kcm_error_string(kcm_status); 00541 SA_PV_ERR_RECOVERABLE_RETURN_IF((error_string_info == NULL), fcc_status = FCC_STATUS_ERROR, "Failed to get kcm error string"); 00542 00543 //Store kcm error string with item name 00544 fcc_status = fcc_set_output_string_info(error_string_info, failed_item_name, failed_item_name_size, &(g_output_info.error_string_info)); 00545 SA_PV_ERR_RECOVERABLE_RETURN_IF((fcc_status != FCC_STATUS_SUCCESS), fcc_status = FCC_STATUS_ERROR, "Failed to set error string info "); 00546 00547 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00548 return fcc_status; 00549 } 00550 00551 fcc_status_e fcc_store_error_info(const uint8_t *failed_item_name, size_t failed_item_name_size, fcc_status_e fcc_status) 00552 { 00553 fcc_status_e fcc_result = FCC_STATUS_SUCCESS; 00554 char *error_string_info = NULL; 00555 00556 SA_PV_LOG_INFO_FUNC_ENTER("fcc_status is %d", fcc_status); 00557 //Check parameters (failed_item_name can be NULL) 00558 SA_PV_ERR_RECOVERABLE_RETURN_IF((fcc_status == FCC_STATUS_SUCCESS), FCC_STATUS_INVALID_PARAMETER, "The fcc_store_error_info should not be called with success status"); 00559 SA_PV_ERR_RECOVERABLE_RETURN_IF((failed_item_name != NULL && failed_item_name_size == 0), FCC_STATUS_INVALID_PARAMETER, "Wrong failed item name parameters"); 00560 00561 //Get fcc error string 00562 error_string_info = fcc_get_fcc_error_string(fcc_status); 00563 SA_PV_ERR_RECOVERABLE_RETURN_IF((error_string_info == NULL), FCC_STATUS_ERROR, "Failed to get fcc error string"); 00564 00565 if (g_output_info.error_string_info == NULL) { 00566 //Store fcc error string with item name 00567 fcc_result = fcc_set_output_string_info(error_string_info, failed_item_name, failed_item_name_size, &(g_output_info.error_string_info)); 00568 SA_PV_ERR_RECOVERABLE_RETURN_IF((fcc_result != FCC_STATUS_SUCCESS), FCC_STATUS_ERROR, "Failed to set error string info "); 00569 } 00570 00571 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00572 return fcc_result; 00573 } 00574 00575 char* fcc_get_output_error_info() 00576 { 00577 char *error_info = NULL; 00578 00579 SA_PV_LOG_INFO_FUNC_ENTER_NO_ARGS(); 00580 00581 if (g_output_info.error_string_info != NULL) { 00582 error_info = g_output_info.error_string_info; 00583 } 00584 00585 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00586 return error_info; 00587 } 00588 00589 00590 char* fcc_get_output_warning_info() 00591 { 00592 char *warrning_string_collection = NULL; 00593 size_t size_of_warning_string_collection = 0; 00594 size_t total_size_of_strings_with_delimeters = 0; 00595 bool status = false; 00596 00597 SA_PV_LOG_INFO_FUNC_ENTER_NO_ARGS(); 00598 00599 if (g_output_info.head_of_warning_list == NULL || g_output_info.size_of_warning_info_list == 0) { 00600 return NULL; 00601 } else { 00602 //Get size of all warning 00603 size_of_warning_string_collection = fcc_get_size_of_all_warning_strings(); 00604 00605 //total_size_of_strings_with_delimeters -size_of_warning_string_collection +add '\n' - as delimiter between the warnings and '\0' in the end 00606 total_size_of_strings_with_delimeters = size_of_warning_string_collection + g_output_info.size_of_warning_info_list + 1; 00607 00608 //Allocate memory buffer for all warnings 00609 warrning_string_collection = fcc_malloc(total_size_of_strings_with_delimeters); 00610 if (warrning_string_collection == NULL) { 00611 SA_PV_LOG_INFO("Failed to allocate memory for warning strings"); 00612 return warrning_string_collection; 00613 } 00614 status = copy_all_warning_to_buffer(warrning_string_collection, total_size_of_strings_with_delimeters); 00615 if (status != true) { 00616 fcc_free(warrning_string_collection); 00617 return NULL; 00618 } 00619 } 00620 00621 SA_PV_LOG_INFO_FUNC_EXIT_NO_ARGS(); 00622 return warrning_string_collection; 00623 } 00624 00625 bool fcc_get_warning_status() 00626 { 00627 if (g_output_info.head_of_warning_list != NULL) { 00628 return true; 00629 } else { 00630 return false; 00631 } 00632 }
Generated on Tue Jul 12 2022 20:20:59 by
