From 450a89962acebc5a59ca4c6c6f0b8083480f07ff Mon Sep 17 00:00:00 2001 From: x00405909 Date: Sat, 17 Jul 2021 14:50:21 +0800 Subject: [PATCH 1/2] add L0L1 udid interface Signed-off-by: x00405909 Change-Id: I928926ee52a1f670134e5a2f017e01e364a89f2b --- frameworks/parameter/src/BUILD.gn | 8 ++- frameworks/parameter/src/parameter_common.c | 64 +++++++++++++++++++++ interfaces/kits/parameter.h | 12 ++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/frameworks/parameter/src/BUILD.gn b/frameworks/parameter/src/BUILD.gn index f2ef159..d2f0f7d 100644 --- a/frameworks/parameter/src/BUILD.gn +++ b/frameworks/parameter/src/BUILD.gn @@ -18,12 +18,16 @@ if (ohos_kernel_type == "liteos_m") { "//utils/native/lite/include", "//base/startup/syspara_lite/frameworks/parameter/src", "//base/startup/syspara_lite/hals", + "//third_party/mbedtls/include", ] sources = [ "param_impl_hal/param_impl_hal.c", "parameter_common.c", ] - deps = [ "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam" ] + deps = [ + "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam", + "//third_party/mbedtls:mbedtls", + ] defines = [ "INCREMENTAL_VERSION=\"${ohos_version}\"", "BUILD_TYPE=\"${ohos_build_type}\"", @@ -50,7 +54,9 @@ if (ohos_kernel_type == "liteos_m") { "//third_party/bounds_checking_function/include", "//base/startup/syspara_lite/frameworks/parameter/src", "//base/startup/syspara_lite/hals", + "//third_party/mbedtls/include", ] + deps = [ "//third_party/mbedtls:mbedtls" ] defines = [ "INCREMENTAL_VERSION=\"${ohos_version}\"", "BUILD_TYPE=\"${ohos_build_type}\"", diff --git a/frameworks/parameter/src/parameter_common.c b/frameworks/parameter/src/parameter_common.c index cdce167..e0eade6 100644 --- a/frameworks/parameter/src/parameter_common.c +++ b/frameworks/parameter/src/parameter_common.c @@ -18,10 +18,15 @@ #include "hal_sys_param.h" #include "ohos_errno.h" #include "param_adaptor.h" +#include "mbedtls/sha256.h" #define FILE_RO "ro." #define OS_FULL_NAME_LEN 128 #define VERSION_ID_LEN 256 +#define HASH_LENGTH 32 +#define DEV_BUF_LENGTH 3 +#define DEV_BUF_MAX_LENGTH 1024 +#define DEV_UUID_LENGTH 65 static const char OHOS_OS_NAME[] = {"OpenHarmony"}; static const int OHOS_SDK_API_VERSION = 6; @@ -252,4 +257,63 @@ const char* GetBuildRootHash(void) const char* GetOsReleaseType(void) { return OHOS_RELEASE_TYPE; +} + +static int GetSha256Value(const char *input, char *udid, int udidSize) +{ + if (input == NULL) { + return EC_FAILURE; + } + char buf[DEV_BUF_LENGTH] = {0}; + unsigned char hash[HASH_LENGTH] = {0}; + + mbedtls_sha256_context context; + mbedtls_sha256_init(&context); + mbedtls_sha256_starts_ret(&context, 0); + mbedtls_sha256_update_ret(&context, input, strlen(input)); + mbedtls_sha256_finish_ret(&context, hash); + + for (size_t i = 0; i < HASH_LENGTH; i++) { + char value = hash[i]; + memset_s(buf, DEV_BUF_LENGTH, 0, DEV_BUF_LENGTH); + sprintf_s(buf, sizeof(buf), "%02X", value); + if (strcat_s(udid, udidSize, buf) != 0) { + return EC_FAILURE; + } + } + return EC_SUCCESS; +} + +int GetDevUdid(char *udid, int size) +{ + if (size < DEV_UUID_LENGTH) { + return EC_FAILURE; + } + + const char *manufacture = GetManufacture(); + const char *model = GetHardwareModel(); + const char *sn = GetSerial(); + if (manufacture == NULL || model == NULL || sn == NULL) { + return EC_FAILURE; + } + int tmpSize = strlen(manufacture) + strlen(model) + strlen(sn) + 1; + if (tmpSize <= 0 || tmpSize > DEV_BUF_MAX_LENGTH) { + return EC_FAILURE; + } + char *tmp = malloc(tmpSize); + if (tmp == NULL) { + return EC_FAILURE; + } + + memset_s(tmp, tmpSize, 0, tmpSize); + if ((strcat_s(tmp, strlen(tmp), manufacture) != 0) || + (strcat_s(tmp, strlen(tmp), model) != 0) || + (strcat_s(tmp, strlen(tmp), sn) != 0)) { + free(tmp); + return EC_FAILURE; + } + + int ret = GetSha256Value(tmp, udid, size); + free(tmp); + return ret; } \ No newline at end of file diff --git a/interfaces/kits/parameter.h b/interfaces/kits/parameter.h index 026e947..02fe0da 100644 --- a/interfaces/kits/parameter.h +++ b/interfaces/kits/parameter.h @@ -372,6 +372,18 @@ const char* GetBuildRootHash(void); */ const char* GetOsReleaseType(void); +/** + * @brief Obtains the device udid. + * + * The OS release category can be Release, Beta, Canary. + * The specific release type may be Release, Beta1, or others alike.\n + * + * @return Return 0 if a result is found; return fail label otherwise. + * @since 1.0 + * @version 1.0 + */ +int GetDevUdid(char *udid, int size); + #ifdef __cplusplus #if __cplusplus } -- Gitee From b6b677928e814897c915ec12c70a6e7d7dc8d6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E7=A3=8A?= Date: Tue, 20 Jul 2021 02:22:19 +0000 Subject: [PATCH 2/2] Signed-off-by: xionglei xionglei6@huawei.com --- frameworks/parameter/src/BUILD.gn | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frameworks/parameter/src/BUILD.gn b/frameworks/parameter/src/BUILD.gn index d2f0f7d..fd4650c 100644 --- a/frameworks/parameter/src/BUILD.gn +++ b/frameworks/parameter/src/BUILD.gn @@ -24,10 +24,7 @@ if (ohos_kernel_type == "liteos_m") { "param_impl_hal/param_impl_hal.c", "parameter_common.c", ] - deps = [ - "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam", - "//third_party/mbedtls:mbedtls", - ] + deps = [ "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam" ] defines = [ "INCREMENTAL_VERSION=\"${ohos_version}\"", "BUILD_TYPE=\"${ohos_build_type}\"", -- Gitee