From f2327bd3cbc4b5db0e040e10bcb18f27927b4e29 Mon Sep 17 00:00:00 2001 From: Antoni Adaszkiewicz Date: Mon, 31 Oct 2022 16:13:29 +0100 Subject: [PATCH] Drop build_string.txt comparisons used to verify delta-device comaptibility and use delta-verifier binary to perform said verification Change-Id: Iffff84cbeae8373308ea59aee43eefb67cf16265 --- update-manager/fota/fota-info-checker.c | 34 ------------------- update-manager/fota/fota-installer.c | 26 ++++----------- update-manager/fota/fota-manager.h | 15 ++++----- update-manager/fota/fota-storage-checker.c | 38 +++++++--------------- update-manager/main.c | 10 ------ 5 files changed, 25 insertions(+), 98 deletions(-) delete mode 100644 update-manager/fota/fota-info-checker.c diff --git a/update-manager/fota/fota-info-checker.c b/update-manager/fota/fota-info-checker.c deleted file mode 100644 index 8957c97..0000000 --- a/update-manager/fota/fota-info-checker.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "../common/common.h" -#include "fota-manager.h" - -#define SYSTEM_INFO_BUILD_STRING "tizen.org/system/build.date" - -static char *build_string = NULL; - -char *fota_info_get_build_string() -{ - return build_string; -} - -int fota_info_checker_init() -{ - int ret = 0; - - _FLOGI("Start process to get fota information"); - ret = system_info_get_platform_string(SYSTEM_INFO_BUILD_STRING, &build_string); - if (ret != SYSTEM_INFO_ERROR_NONE) { - _FLOGE("system_info_get_platform_string failed : %d", ret); - return -1; - } - - _FLOGI("Success to get fota information, build_string : %s", build_string); - return 0; -} - -int fota_info_checker_fini() -{ - if (build_string) - free(build_string); - - return 0; -} diff --git a/update-manager/fota/fota-installer.c b/update-manager/fota/fota-installer.c index cb68ec2..c94f38d 100644 --- a/update-manager/fota/fota-installer.c +++ b/update-manager/fota/fota-installer.c @@ -78,7 +78,7 @@ 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, *old_build_string = NULL; + char *appid = NULL; gchar *client_delta_path = NULL; pid_t pid; @@ -100,29 +100,19 @@ int fota_installer_execute(pid_t sender_pid) _FLOGI("Delta found: %s", client_delta_path); /* 3. Check client have appropriate delta */ - ret = util_file_untar(client_delta_path, FOTA_DELTA_BUILD_STRING_DIR, FOTA_DELTA_BUILD_STRING_FILENAME); + ret = util_file_untar(client_delta_path, FOTA_DELTA_UPDATE_INFO_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME); if (ret < 0) { status = -1; goto execute_destroy; } - - ret = util_file_read_single_line(FOTA_DELTA_BUILD_STRING_PATH, buf); + snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN, 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; - } - - old_build_string = fota_info_get_build_string(); - if(old_build_string == NULL) { - _FLOGE("Failed to get current image build string"); - status = -1; - goto execute_destroy; - } - - if (!g_str_has_prefix(buf, FOTA_DELTA_BUILD_STRING_FULL_DELTA_PREFIX) && - !g_str_has_prefix(buf, old_build_string)) { - _FLOGI("The caller doesn't have appropriate delta(%s), delta build string(%s)", - old_build_string, buf); + } 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; } @@ -206,8 +196,6 @@ int fota_installer_execute(pid_t sender_pid) } execute_destroy: - util_file_remove(FOTA_DELTA_BUILD_STRING_PATH); - if (client_delta_path) free(client_delta_path); diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h index 72d8d9d..60a1fc6 100644 --- a/update-manager/fota/fota-manager.h +++ b/update-manager/fota/fota-manager.h @@ -18,14 +18,15 @@ #define FOTA_DELTA_FILENAME "delta.tar" #define FOTA_DELTA_COMPRESSED_FILENAME "delta.tar.gz" -#define FOTA_DELTA_BUILD_STRING_DIR "/tmp" -#define FOTA_DELTA_BUILD_STRING_FILENAME "build_string.txt" -#define FOTA_DELTA_BUILD_STRING_PATH FOTA_DELTA_BUILD_STRING_DIR "/" FOTA_DELTA_BUILD_STRING_FILENAME -#define FOTA_DELTA_BUILD_STRING_FULL_DELTA_PREFIX "0.0@" - #define FOTA_STATUS_DIR "/opt/data/update" #define FOTA_STATUS_FLAG_PATH FOTA_STATUS_DIR "/is-first-boot-after-fota" +#define FOTA_DELTA_UPDATE_INFO_DIR "/tmp" +#define FOTA_DELTA_UPDATE_INFO_FILENAME "update-info.ini" +#define FOTA_DELTA_UPDATE_INFO_PATH FOTA_DELTA_UPDATE_INFO_DIR "/" FOTA_DELTA_UPDATE_INFO_FILENAME +#define DELTA_VERIFIER_BIN "/usr/bin/delta-verifier" +#define DELTA_VERIFIER_BIN_LONG_ARG "--update_info_path" + #define FOTA_EVENT_SIZE 3 /* Enum */ @@ -43,10 +44,6 @@ int fota_client_info_checker_init(void); int fota_client_info_checker_fini(void); char *fota_client_info_get_appid(void); -int fota_info_checker_init(void); -int fota_info_checker_fini(void); -char *fota_info_get_build_string(void); - int fota_installer_execute(pid_t pid); void fota_storage_checker_plug(int, const char *); diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c index ca50249..9eed6a3 100644 --- a/update-manager/fota/fota-storage-checker.c +++ b/update-manager/fota/fota-storage-checker.c @@ -9,23 +9,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, }; - char *old_build_string = NULL; gchar *storage_delta_path = NULL; - /* 1. Check storage support current image */ - old_build_string = fota_info_get_build_string(); - if (old_build_string == NULL) { - _FLOGE("Failed to get current image build string"); - goto verify_destroy; - } - - if (g_str_has_prefix(folder_name, old_build_string) != TRUE) { - _FLOGI("Storage doesn't support current image(%s), folder name(%s)", - old_build_string, folder_name); - goto verify_destroy; - } - - /* 2. Check storage have delta.tar */ + /* 1. 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; @@ -38,18 +24,20 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name) } } - /* 3. Check storage have appropriate delta */ - ret = util_file_untar(storage_delta_path, FOTA_DELTA_BUILD_STRING_DIR, FOTA_DELTA_BUILD_STRING_FILENAME); - if (ret < 0) + /* 2. Check storage have appropriate delta */ + ret = util_file_untar(storage_delta_path, FOTA_DELTA_UPDATE_INFO_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME); + if (ret < 0) { goto verify_destroy; + } - ret = util_file_read_single_line(FOTA_DELTA_BUILD_STRING_PATH, buf); - if (ret < 0) - goto verify_destroy; + snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH); + ret = system(buf); - if (g_str_equal(folder_name, buf) != TRUE) { - _FLOGI("Storage doesn't have appropriate delta(%s), delta build string(%s)", - folder_name, 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); goto verify_destroy; } @@ -57,8 +45,6 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name) is_appropriate = true; verify_destroy: - util_file_remove(FOTA_DELTA_BUILD_STRING_PATH); - if (!is_appropriate && storage_delta_path) { free(storage_delta_path); storage_delta_path = NULL; diff --git a/update-manager/main.c b/update-manager/main.c index efd1727..b17aa13 100644 --- a/update-manager/main.c +++ b/update-manager/main.c @@ -40,12 +40,6 @@ int main(int argc, char *argv[]) goto main_destroy; } - ret = fota_info_checker_init(); - if (ret < 0) { - _CLOGE("Failed to initialize fota info checker : %d", ret); - goto main_destroy; - } - /* Dbus */ ret = dbus_manager_init(); if (ret < 0) { @@ -75,10 +69,6 @@ main_destroy: if (ret < 0) _CLOGW("Failed to finalize fota client info checker : %d", ret); - ret = fota_info_checker_fini(); - if (ret < 0) - _CLOGW("Failed to finalize fota info checker : %d", ret); - /* Dbus */ ret = dbus_manager_fini(); if (ret < 0) -- 2.34.1