From 4aa9919363f8b6f7e61ba9134fa1f9cd2875c94e Mon Sep 17 00:00:00 2001 From: yang1946 Date: Tue, 5 Mar 2024 11:33:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=AD=BE=E5=90=8D=E4=BB=93?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yang1946 --- services/local_code_sign/src/permission_utils.cpp | 6 +++--- test/unittest/multi_thread_local_sign_test.cpp | 8 ++++---- test/unittest/sign_and_enforce_test.cpp | 6 +++--- utils/src/fsverity_utils_helper.cpp | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/services/local_code_sign/src/permission_utils.cpp b/services/local_code_sign/src/permission_utils.cpp index ea98389..d5c485a 100644 --- a/services/local_code_sign/src/permission_utils.cpp +++ b/services/local_code_sign/src/permission_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -27,7 +27,7 @@ namespace CodeSign { const std::vector CERTIFICATE_CALLERS = {"key_enable"}; const std::vector SIGN_CALLERS = {"installs"}; constexpr int32_t VALUE_MAX_LEN = 32; -const char* g_accessTokenServiceInitKey = "accesstoken.permission.init"; +const char* ACCESS_TOKEN_SERVICE_INIT_KEY = "accesstoken.permission.init"; bool g_isAtmInited = false; bool PermissionUtils::IsValidCallerOfCert() @@ -53,7 +53,7 @@ bool PermissionUtils::IsValidCallerOfLocalCodeSign() bool PermissionUtils::HasATMInitilized() { char value[VALUE_MAX_LEN] = {0}; - int32_t ret = GetParameter(g_accessTokenServiceInitKey, "", value, VALUE_MAX_LEN - 1); + int32_t ret = GetParameter(ACCESS_TOKEN_SERVICE_INIT_KEY, "", value, VALUE_MAX_LEN - 1); if ((ret < 0) || (static_cast(std::atoll(value)) != 0)) { g_isAtmInited = true; return true; diff --git a/test/unittest/multi_thread_local_sign_test.cpp b/test/unittest/multi_thread_local_sign_test.cpp index bc30c6b..6d6b960 100644 --- a/test/unittest/multi_thread_local_sign_test.cpp +++ b/test/unittest/multi_thread_local_sign_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -39,7 +39,7 @@ static const std::string AN_BASE_PATH = "/data/local/ark-cache/tmp/multi_thread/ static const std::string ORIGIN_AN_FILE = AN_BASE_PATH + "demo.an"; static const std::string DemoWithownerID = AN_BASE_PATH + "demoWithownerID.an"; -static const char *g_validCaller = "installs"; +static const char *VALID_CALLER = "installs"; uint64_t GetFileSize(int32_t fd) { @@ -83,7 +83,7 @@ static bool DupFile(const std::string &path) void LocalCodeSignAndEnforce() { ByteBuffer sig; - uint64_t selfTokenId = NativeTokenSet(g_validCaller); + uint64_t selfTokenId = NativeTokenSet(VALID_CALLER); int ret = LocalCodeSignKit::SignLocalCode(ORIGIN_AN_FILE, sig); std::thread::id thisId = std::this_thread::get_id(); std::ostringstream oss; @@ -100,7 +100,7 @@ void LocalCodeSignAndEnforce() void LocalCodeSignAndEnforceWithOwnerID() { ByteBuffer sig; - uint64_t selfTokenId = NativeTokenSet(g_validCaller); + uint64_t selfTokenId = NativeTokenSet(VALID_CALLER); std::string ownerID = "AppName123"; int ret = LocalCodeSignKit::SignLocalCode(ownerID, DemoWithownerID, sig); std::thread::id thisId = std::this_thread::get_id(); diff --git a/test/unittest/sign_and_enforce_test.cpp b/test/unittest/sign_and_enforce_test.cpp index 207dd19..176c88a 100644 --- a/test/unittest/sign_and_enforce_test.cpp +++ b/test/unittest/sign_and_enforce_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -38,7 +38,7 @@ static const std::string AN_BASE_PATH = "/data/local/ark-cache/tmp/"; static const std::string DEMO_AN_PATH = AN_BASE_PATH + "demo.an"; static const std::string DEMO_TAMPER_AN_PATH = AN_BASE_PATH + "fake_demo.an"; -static const char *g_validCaller = "installs"; +static const char *VALID_CALLER = "installs"; static const std::string FAKE_SERIAL_NUMBER = "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; static const std::string FAKE_CONTENT = "FAKE"; @@ -138,7 +138,7 @@ static bool ModifyPkcs7SignerwithTargetFunc(ByteBuffer &src, ByteBuffer &dst, static void InvokeLocalCodeSign(const std::string &filePath, ByteBuffer &sig) { - uint64_t selfTokenId = NativeTokenSet(g_validCaller); + uint64_t selfTokenId = NativeTokenSet(VALID_CALLER); int ret = LocalCodeSignKit::SignLocalCode(filePath, sig); NativeTokenReset(selfTokenId); EXPECT_EQ(ret, CS_SUCCESS); diff --git a/utils/src/fsverity_utils_helper.cpp b/utils/src/fsverity_utils_helper.cpp index 924decc..bdfca31 100644 --- a/utils/src/fsverity_utils_helper.cpp +++ b/utils/src/fsverity_utils_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * 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 @@ -27,7 +27,7 @@ namespace Security { namespace CodeSign { static constexpr int MAX_DIGEST_SIZE = 64; // size of sha512 static constexpr int FSVERITY_HASH_PAGE_SIZE = 4096; -static const char *g_fsverityDigestMagic = "FSVerity"; +static const char *FSVERITY_DIGEST_MAGIC = "FSVerity"; static constexpr uint32_t FSVERITY_DIGEST_MAGIC_LENGTH = 8; FsverityUtilsHelper &FsverityUtilsHelper::GetInstance() @@ -56,7 +56,7 @@ void FsverityUtilsHelper::ErrorMsgLogCallback(const char *msg) bool FsverityUtilsHelper::FormatDigest(libfsverity_digest *digest, uint8_t *buffer) { struct fsverity_formatted_digest *ret = reinterpret_cast(buffer); - if (memcpy_s(ret->magic, FSVERITY_DIGEST_MAGIC_LENGTH, g_fsverityDigestMagic, + if (memcpy_s(ret->magic, FSVERITY_DIGEST_MAGIC_LENGTH, FSVERITY_DIGEST_MAGIC, FSVERITY_DIGEST_MAGIC_LENGTH) != EOK) { return false; } -- Gitee