From 37dac8a98a485295d501f0ea23cad8f58813f76e Mon Sep 17 00:00:00 2001 From: junyi233 Date: Tue, 2 Jan 2024 12:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: junyi233 --- .../include/common/hap_byte_buffer.h | 7 ++--- .../include/common/random_access_file.h | 6 ++-- .../include/init/trusted_source_manager.h | 2 +- .../include/init/trusted_ticket_manager.h | 2 +- .../include/interfaces/hap_verify_result.h | 4 +-- .../include/provision/provision_info.h | 4 +-- .../include/util/hap_signing_block_utils.h | 10 +++--- .../appverify/include/util/pkcs7_context.h | 2 +- .../appverify/include/util/signature_info.h | 2 +- .../appverify/src/common/hap_byte_buffer.cpp | 22 ------------- .../appverify/src/init/json_parser_utils.cpp | 2 +- .../src/provision/provision_verify.cpp | 4 +-- .../unittest/include/hap_byte_buffer_test.h | 1 - .../unittest/src/hap_byte_buffer_test.cpp | 31 ------------------- 14 files changed, 22 insertions(+), 77 deletions(-) diff --git a/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h b/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h index 44ec9a5..77b141b 100644 --- a/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h +++ b/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h @@ -59,7 +59,6 @@ public: DLL_EXPORT void Slice(); DLL_EXPORT int32_t Remaining() const; DLL_EXPORT bool HasRemaining() const; - DLL_EXPORT bool CopyPartialBuffer(const HapByteBuffer& other, int32_t len); DLL_EXPORT void Clear(); DLL_EXPORT bool IsEqual(const HapByteBuffer& other); DLL_EXPORT bool IsEqual(const std::string& other); @@ -72,9 +71,9 @@ private: static const int32_t MAX_PRINT_LENGTH; static const int32_t HEX_PRINT_LENGTH; std::unique_ptr buffer; - int32_t position; - int32_t limit; - int32_t capacity; + int32_t position = 0; + int32_t limit = 0; + int32_t capacity = 0; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/common/random_access_file.h b/interfaces/innerkits/appverify/include/common/random_access_file.h index ada93b2..8e67076 100644 --- a/interfaces/innerkits/appverify/include/common/random_access_file.h +++ b/interfaces/innerkits/appverify/include/common/random_access_file.h @@ -24,8 +24,8 @@ namespace Security { namespace Verify { struct MmapInfo { long long mmapPosition; - int32_t readMoreLen; - int32_t mmapSize; + int32_t readMoreLen = 0; + int32_t mmapSize = 0; char* mapAddr; }; @@ -44,7 +44,7 @@ private: bool CheckLittleEndian(); static const int32_t FILE_OPEN_FAIL_ERROR_NUM; static int32_t memoryPageSize; - int32_t fd; + int32_t fd = 0; long long fileLength; }; } // namespace Verify diff --git a/interfaces/innerkits/appverify/include/init/trusted_source_manager.h b/interfaces/innerkits/appverify/include/init/trusted_source_manager.h index ee5aa18..22f693f 100644 --- a/interfaces/innerkits/appverify/include/init/trusted_source_manager.h +++ b/interfaces/innerkits/appverify/include/init/trusted_source_manager.h @@ -33,7 +33,7 @@ struct HapAppSourceInfo { std::string profileSigningCertificate; std::string profileDebugSigningCertificate; std::string issuer; - int32_t maxCertsPath; + int32_t maxCertsPath = 0; StringVec critialcalCertExtension; }; diff --git a/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h b/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h index d77da42..b09b5cf 100644 --- a/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h +++ b/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h @@ -30,7 +30,7 @@ struct HapTicketSourceInfo { std::string sourceName; std::string ticketSigningCert; std::string issuer; - int32_t maxCertsPath; + int32_t maxCertsPath = 0; StringVec critialcalCertExtension; }; diff --git a/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h b/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h index 193f401..b793e83 100644 --- a/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h +++ b/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h @@ -55,7 +55,7 @@ enum GetOptionalBlockResultCode { }; struct OptionalBlock { - int32_t optionalType; + int32_t optionalType = 0; HapByteBuffer optionalBlockValue; }; @@ -80,7 +80,7 @@ private: DLL_EXPORT int32_t GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const; private: - int32_t version; + int32_t version = 0; std::vector publicKeys; std::vector signatures; HapByteBuffer pkcs7SignBlock; diff --git a/interfaces/innerkits/appverify/include/provision/provision_info.h b/interfaces/innerkits/appverify/include/provision/provision_info.h index f55798f..1ddcd08 100644 --- a/interfaces/innerkits/appverify/include/provision/provision_info.h +++ b/interfaces/innerkits/appverify/include/provision/provision_info.h @@ -64,8 +64,8 @@ struct DebugInfo { }; struct Validity { - int64_t notBefore; - int64_t notAfter; + int64_t notBefore = 0; + int64_t notAfter = 0; }; struct Metadata { diff --git a/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h b/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h index 8b3d156..13ed7e8 100644 --- a/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h +++ b/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h @@ -40,17 +40,17 @@ enum HapBlobType { }; struct HapSignBlockHead { - int32_t version; - int32_t blockCount; + int32_t version = 0; + int32_t blockCount = 0; long long hapSignBlockSize; long long hapSignBlockMagicLo; long long hapSignBlockMagicHi; }; struct HapSubSignBlockHead { - uint32_t type; - uint32_t length; - uint32_t offset; + uint32_t type = 0; + uint32_t length = 0; + uint32_t offset = 0; }; class HapSigningBlockUtils { diff --git a/interfaces/innerkits/appverify/include/util/pkcs7_context.h b/interfaces/innerkits/appverify/include/util/pkcs7_context.h index ce86b38..5b26d52 100644 --- a/interfaces/innerkits/appverify/include/util/pkcs7_context.h +++ b/interfaces/innerkits/appverify/include/util/pkcs7_context.h @@ -32,7 +32,7 @@ using Pkcs7CertChains = std::vector; struct Pkcs7Context { bool needWriteCrl; - int32_t digestAlgorithm; + int32_t digestAlgorithm = 0; MatchingResult matchResult; std::string certIssuer; PKCS7* p7; diff --git a/interfaces/innerkits/appverify/include/util/signature_info.h b/interfaces/innerkits/appverify/include/util/signature_info.h index d35de7d..0ebfd01 100644 --- a/interfaces/innerkits/appverify/include/util/signature_info.h +++ b/interfaces/innerkits/appverify/include/util/signature_info.h @@ -30,7 +30,7 @@ struct SignatureInfo { long long hapEocdOffset; HapByteBuffer hapEocd; std::vector optionBlocks; - int32_t version; + int32_t version = 0; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp b/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp index 9ff07f8..aa37b82 100644 --- a/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp +++ b/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp @@ -279,28 +279,6 @@ bool HapByteBuffer::HasRemaining() const return position < limit; } -bool HapByteBuffer::CopyPartialBuffer(const HapByteBuffer& other, int32_t len) -{ - int32_t readableDataLen = other.Remaining(); - if (readableDataLen < len) { - HAPVERIFY_LOG_ERROR(LABEL, "readableDataLen %{public}d less than len %{public}d", readableDataLen, len); - return false; - } - - buffer.reset(nullptr); - buffer = std::make_unique(len); - if (buffer != nullptr && other.GetBufferPtr() != nullptr) { - capacity = len; - limit = capacity; - if (memcpy_s(buffer.get(), capacity, (other.GetBufferPtr() + other.GetPosition()), len) != EOK) { - HAPVERIFY_LOG_ERROR(LABEL, "memcpy_s failed"); - return false; - } - } - position = 0; - return true; -} - void HapByteBuffer::Clear() { position = 0; diff --git a/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp b/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp index ec3352d..e0b5e31 100644 --- a/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp +++ b/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp @@ -41,7 +41,7 @@ bool JsonParserUtils::ReadTrustedRootCAFromJson(nlohmann::json& jsonObj, std::string jsonStr = buf.str(); jsonObj = nlohmann::json::parse(jsonStr, nullptr, false); - if (!jsonObj.is_structured()) { + if (jsonObj.is_discarded() || (!jsonObj.is_structured())) { error += "parse jsonStr failed"; return false; } diff --git a/interfaces/innerkits/appverify/src/provision/provision_verify.cpp b/interfaces/innerkits/appverify/src/provision/provision_verify.cpp index 8f1cd82..df34c51 100644 --- a/interfaces/innerkits/appverify/src/provision/provision_verify.cpp +++ b/interfaces/innerkits/appverify/src/provision/provision_verify.cpp @@ -250,7 +250,7 @@ void from_json(const json& obj, ProvisionInfo& out) AppProvisionVerifyResult ParseProvision(const string& appProvision, ProvisionInfo& info) { json obj = json::parse(appProvision, nullptr, false); - if (!obj.is_structured()) { + if (obj.is_discarded() || (!obj.is_structured())) { HAPVERIFY_LOG_ERROR(LABEL, "Parsing appProvision failed. json: %{public}s", appProvision.c_str()); return PROVISION_INVALID; } @@ -369,7 +369,7 @@ AppProvisionVerifyResult ParseAndVerify(const string& appProvision, ProvisionInf AppProvisionVerifyResult ParseProfile(const std::string& appProvision, ProvisionInfo& info) { json obj = json::parse(appProvision, nullptr, false); - if (!obj.is_structured()) { + if (obj.is_discarded() || (!obj.is_structured())) { HAPVERIFY_LOG_ERROR(LABEL, "Parsing appProvision failed. json: %{public}s", appProvision.c_str()); return PROVISION_INVALID; } diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h index a527bf3..c274694 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h @@ -21,7 +21,6 @@ int32_t HapByteBuffer001(void); int32_t GetIntAndPutOperation001(void); int32_t Slice001(void); -int32_t CopyPartialBuffer001(void); int32_t IsEqual001(void); int32_t IsEqual002(void); #endif // HAP_BYTE_BUFFER_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp index 832b6cd..d2b7852 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp @@ -185,37 +185,6 @@ HWTEST_F (HapByteBufferTest, Slice001, TestSize.Level1) ASSERT_TRUE(buffer1.HasRemaining()); } -/** - * @tc.name: Test HapByteBuffer function of CopyPartialBuffer - * @tc.desc: The static function will copy data from an object, detect the data is right; - * @tc.type: FUNC - */ -HWTEST_F (HapByteBufferTest, CopyPartialBuffer001, TestSize.Level1) -{ - /* - * @tc.steps: step1. Copy 8 bytes data from 10st-position in a 15 bytes length buffer. - * @tc.expected: step1. The return result is false. - */ - HapByteBuffer buffer1(TEST_HAPBYTEBUFFER_LENGTH); - buffer1.PutInt32(0, TEST_HAPBYTEBUFFER_INT32_DATA); - buffer1.PutInt32(sizeof(int), TEST_HAPBYTEBUFFER_INT32_DATA_2); - HapByteBuffer buffer2(TEST_HAPBYTEBUFFER_LENGTH); - buffer1.SetPosition(TEST_HAPBYTEBUFFER_POSITION); - ASSERT_FALSE(buffer2.CopyPartialBuffer(buffer1, TEST_HAPBYTEBUFFER_LENGTH_2)); - /* - * @tc.steps: step2. Copy 8 bytes data from first-position in a 15 bytes length buffer. - * @tc.expected: step2. Buffer2 return is targeted value. - */ - buffer1.Clear(); - buffer2.CopyPartialBuffer(buffer1, TEST_HAPBYTEBUFFER_LENGTH_2); - int32_t target1; - ASSERT_TRUE(buffer2.GetInt32(target1)); - ASSERT_EQ(target1, TEST_HAPBYTEBUFFER_INT32_DATA); - int32_t target2; - ASSERT_TRUE(buffer2.GetInt32(target2)); - ASSERT_EQ(target2, TEST_HAPBYTEBUFFER_INT32_DATA_2); -} - /** * @tc.name: Test HapByteBuffer function of IsEqual001 * @tc.desc: The static function will return two object whether is equal. -- Gitee