mirror of
https://github.com/openharmony/startup_syspara_lite.git
synced 2026-07-21 05:15:20 -04:00
@@ -32,7 +32,7 @@ static const char OHOS_SOFTWARE_MODEL[] = {"****"};
|
||||
static const char OHOS_HARDWARE_MODEL[] = {"****"};
|
||||
static const char OHOS_HARDWARE_PROFILE[] = {"****"};
|
||||
static const char DEF_OHOS_SERIAL[] = {"1234567890"};
|
||||
static const char SN_FILE[] = {"/sys/class/net/eth0/address"};
|
||||
static const char SN_FILE[] = {"/sys/block/mmcblk0/device/cid"};
|
||||
static const char OHOS_ABI_LIST[] = {"****"};
|
||||
static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
|
||||
static const int OHOS_FIRST_API_LEVEL = 1;
|
||||
|
||||
@@ -21,6 +21,7 @@ config("syspara_config") {
|
||||
"//utils/native/base/include",
|
||||
"//base/startup/syspara_lite/hals/parameter/include",
|
||||
"include",
|
||||
"//third_party/openssl/include/",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ ohos_shared_library("syspara") {
|
||||
deps = [
|
||||
"//base/startup/syspara_lite/hals/parameter:sysparam_hal",
|
||||
"//utils/native/base:utils",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
]
|
||||
subsystem_name = "startup"
|
||||
part_name = "startup_l2"
|
||||
|
||||
@@ -85,6 +85,7 @@ const char *GetBuildUser();
|
||||
const char *GetBuildHost();
|
||||
const char *GetBuildTime();
|
||||
int GetFirstApiVersion();
|
||||
int GetDevUdid(char *udid, int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <securec.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "parameter_hal.h"
|
||||
#include "sysparam_errno.h"
|
||||
#include "sysversion.h"
|
||||
@@ -30,6 +32,9 @@ static const int OHOS_SDK_API_LEVEL = 6;
|
||||
static const char OHOS_BUILD_ROOT_HASH[] = {"****"};
|
||||
static const char OHOS_SECURITY_PATCH_TAG[] = {"2020-09-01"};
|
||||
static const char OHOS_RELEASE_TYPE[] = {"Canary1"};
|
||||
static const int DEV_BUF_LENGTH = 3;
|
||||
static const int DEV_BUF_MAX_LENGTH = 1024;
|
||||
static const int DEV_UUID_LENGTH = 65;
|
||||
|
||||
static const char EMPTY_STR[] = {""};
|
||||
|
||||
@@ -223,4 +228,60 @@ const char *GetBuildRootHash()
|
||||
const char *GetOsReleaseType()
|
||||
{
|
||||
return OHOS_RELEASE_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
int GetSha256Value(const char *input, char *udid, int udidSize)
|
||||
{
|
||||
char buf[DEV_BUF_LENGTH] = {0};
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH] = {0};
|
||||
SHA256_CTX sha256;
|
||||
if ((SHA256_Init(&sha256) == 0) ||
|
||||
(SHA256_Update(&sha256, input, strlen(input)) == 0) ||
|
||||
(SHA256_Final(hash, &sha256) == 0)) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < SHA256_DIGEST_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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user