From: Mateusz Moscicki Date: Thu, 19 Jan 2023 14:43:33 +0000 (+0100) Subject: update-manager: Separation of delta checking into a separate function X-Git-Tag: accepted/tizen/unified/20230120.182103~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=520cf6da862147ebcf5743c2a5bb1a7b017ef689;p=platform%2Fcore%2Fsystem%2Fupdate-control.git update-manager: Separation of delta checking into a separate function Change-Id: I18db976595d920e1f4ab325e65791aa2e3b8762e --- diff --git a/update-manager/CMakeLists.txt b/update-manager/CMakeLists.txt index a76e12e..2d9d750 100644 --- a/update-manager/CMakeLists.txt +++ b/update-manager/CMakeLists.txt @@ -32,7 +32,7 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BASE} -Wall -fPIE") -INCLUDE_DIRECTORIES(${INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${INCLUDE_DIR} ${SOURCE_DIR}) FILE(GLOB SOURCE_FILES "${SOURCE_DIR}/*.h" "${SOURCE_DIR}/*.c" "${SOURCE_DIR}/*/*.h" "${SOURCE_DIR}/*/*.c" diff --git a/update-manager/fota/fota-common.c b/update-manager/fota/fota-common.c new file mode 100644 index 0000000..25208b3 --- /dev/null +++ b/update-manager/fota/fota-common.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common/common.h" +#include "fota-manager.h" + +int check_is_delta_appropriate(const char *delta_path, bool *checksum_available) +{ + int ret; + bool do_checksum = false; + char buf[MAX_BUFFER_SIZE] = {0, }; + + ret = util_file_untar(delta_path, FOTA_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME); + if (ret < 0) { + ret = -1; + goto exit; + } + + ret = util_file_untar(delta_path, FOTA_DIR, DELTA_VERIFIER_BIN); + if (ret < 0) { + ret = -1; + goto exit; + } + + ret = util_file_untar(delta_path, FOTA_DIR, FOTA_CHECKSUM_FILE); + if (ret < 0) { + _FLOGW("There is no %s in delta", FOTA_CHECKSUM_FILE); + } else { + do_checksum = true; + } + + if (checksum_available != NULL) + *checksum_available = do_checksum; + + if (do_checksum) { + if (verify_checksum(FOTA_CHECKSUM_PATH, DELTA_VERIFIER_PATH) == 0) { + _FLOGI("Checksum of %s is correct", DELTA_VERIFIER_PATH); + } else { + ret = -1; + _FLOGE("Failed checksum verification of %s", DELTA_VERIFIER_PATH); + goto exit; + } + } + + snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN_PATH, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH); + ret = system(buf); + if (ret < 0) { + _FLOGE("Delta verification failed due to an error [return code: %d].", ret); + } else if (ret > 0) { + _FLOGI("The delta at [%s] is not compatible with this device [return code: %d].", delta_path, ret); + } + +exit: + return ret; +} diff --git a/update-manager/fota/fota-installer.c b/update-manager/fota/fota-installer.c index 246cd0f..b0d7953 100644 --- a/update-manager/fota/fota-installer.c +++ b/update-manager/fota/fota-installer.c @@ -74,16 +74,15 @@ static char *find_delta_dir(const char *appid) int fota_installer_execute(pid_t sender_pid) { int ret = 0, status = 0, exec_status = 0; - char buf[MAX_BUFFER_SIZE] = {0, }; char *appid = NULL; gchar *client_delta_path = NULL; pid_t pid; bool check_sha = false; - /* 1. Check client have delta.tar */ + /* Check client have delta.tar */ appid = get_sender_appid(sender_pid); - /* 2. Find the delta file path */ + /* Find the delta file path */ client_delta_path = find_delta_dir(appid); if (appid != NULL) { free(appid); @@ -97,55 +96,20 @@ int fota_installer_execute(pid_t sender_pid) } _FLOGI("Delta found: %s", client_delta_path); - /* 3. Prepare fota dir */ + /* Prepare fota dir */ ret = util_file_mkdir(FOTA_DIR); if (ret < 0) { status = -1; goto execute_destroy; } - /* 4. Check client have appropriate delta */ - ret = util_file_untar(client_delta_path, FOTA_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME); - if (ret < 0) { - status = -1; - goto execute_destroy; - } - ret = util_file_untar(client_delta_path, FOTA_DIR, DELTA_VERIFIER_BIN); - if (ret < 0) { + /* Check client have appropriate delta */ + if (check_is_delta_appropriate(client_delta_path, &check_sha) != 0) { status = -1; goto execute_destroy; } - ret = util_file_untar(client_delta_path, FOTA_DIR, FOTA_CHECKSUM_FILE); - if (ret < 0) { - _FLOGW("There is no %s in delta", FOTA_CHECKSUM_FILE); - } else { - check_sha = true; - } - - if (check_sha) { - if (verify_checksum(FOTA_CHECKSUM_PATH, DELTA_VERIFIER_PATH) == 0) { - _FLOGI("Checksum of %s is correct", DELTA_VERIFIER_PATH); - } else { - status = -1; - _FLOGE("Failed checksum verification of %s", DELTA_VERIFIER_PATH); - goto execute_destroy; - } - } - - snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN_PATH, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH); - ret = system(buf); - if (ret < 0) { - _FLOGE("Delta verification failed due to an error [return code: %d].", ret); - status = -1; - goto execute_destroy; - } else if (ret > 0) { - _FLOGI("The delta of the caller is not compatible with this device [return code: %d].", ret); - status = -3; - goto execute_destroy; - } - - /* 5. Setup local update flag */ + /* Setup local update flag */ ret = util_file_mkdir(FOTA_STATUS_DIR); if (ret < 0) { status = -1; @@ -158,7 +122,7 @@ int fota_installer_execute(pid_t sender_pid) goto execute_destroy; } - /* 6. Trigger update */ + /* Trigger update */ ret = util_file_untar(client_delta_path, FOTA_DIR, FOTA_TRIGGER_FILE); if (ret < 0) { status = -1; diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h index acb6a20..9f271e1 100644 --- a/update-manager/fota/fota-manager.h +++ b/update-manager/fota/fota-manager.h @@ -52,5 +52,6 @@ int fota_installer_execute(pid_t pid); void fota_storage_checker_plug(int, const char *); void fota_storage_checker_unplug(int, const char *); +int check_is_delta_appropriate(const char *delta_path, bool *checksum_available); #endif /* __FOTA_MANAGER_H__ */ diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c index 168d593..d5c8fc7 100644 --- a/update-manager/fota/fota-storage-checker.c +++ b/update-manager/fota/fota-storage-checker.c @@ -8,10 +8,9 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name) { int ret = 0; bool is_appropriate = false; - char buf[MAX_BUFFER_SIZE] = {0, }; gchar *storage_delta_path = NULL; - /* 1. Check storage have delta.tar */ + /* Check storage have delta.tar */ storage_delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILENAME, NULL); if (!g_file_test(storage_delta_path, G_FILE_TEST_EXISTS)) { gchar *tmp_storage_delta_path = storage_delta_path; @@ -24,39 +23,15 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name) } } - /* 2. Prepare fota dir */ + /* Prepare fota dir */ ret = util_file_mkdir(FOTA_DIR); if (ret < 0) { goto verify_destroy; } - /* 2. Check storage have appropriate delta */ - ret = util_file_untar(storage_delta_path, FOTA_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME); - if (ret < 0) { - goto verify_destroy; - } - - ret = util_file_untar(storage_delta_path, FOTA_DIR, FOTA_CHECKSUM_FILE); - if (ret < 0) { - _FLOGW("There is no %s in delta", FOTA_CHECKSUM_FILE); - } else { - if (verify_checksum(FOTA_CHECKSUM_PATH, DELTA_VERIFIER_PATH) == 0) { - _FLOGI("Checksum of %s is correct", DELTA_VERIFIER_PATH); - } else { - ret = -1; - _FLOGE("Failed checksum verification of %s", DELTA_VERIFIER_PATH); - goto verify_destroy; - } - } - - snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN_PATH, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH); - ret = system(buf); - - if (ret < 0) { - _FLOGE("Delta verification failed due to an error [return code: %d].", ret); - goto verify_destroy; - } else if (ret > 0) { - _FLOGI("The delta at [%s] is not compatible with this device [return code: %d].", storage_delta_path, ret); + /* Check storage have appropriate delta */ + if (check_is_delta_appropriate(storage_delta_path, NULL) != 0) { + ret = -1; goto verify_destroy; }