diff --git a/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp index cbd7f017bb6abe63e42101e07431c788fb017fa3..4c838e43394bb26725c903c55d7baa3e949927ae 100644 --- a/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp @@ -18,9 +18,8 @@ #include #include "signing_block.h" #include "sign_block_info.h" -using namespace OHOS::SignatureTools; - namespace OHOS { +namespace SignatureTools { bool SignBlockInfoObjectBuild(const uint8_t* data, size_t size) { SignBlockInfo object; @@ -36,14 +35,14 @@ bool SigningBlockObjectBuild(const uint8_t* data, size_t size) SigningBlock object(type, sig); return true; } - +} } /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::SignBlockInfoObjectBuild(data, size); - OHOS::SigningBlockObjectBuild(data, size); + OHOS::SignatureTools::SignBlockInfoObjectBuild(data, size); + OHOS::SignatureTools::SigningBlockObjectBuild(data, size); return 0; } \ No newline at end of file diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp index 8bfcebec300456b6d59bda016c711a912ae842b0..e78384057f446c8fa674e0bd44de155c0476be26 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp @@ -51,9 +51,9 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char keyPwd[] = "123456"; char ksPwd[] = "123456"; bool extKeyUsageCritical = true; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; std::string outFile = "/data/test/generateCA/single-app1.cer"; (*params)["keyPwd"] = keyPwd; (*params)["issuer"] = issuer; diff --git a/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp index c0360257e6515fc35d281fcfeb49fae4fb7b6997..e4e405b2489eb02e240719ee6602681f4f47e434 100644 --- a/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp @@ -19,9 +19,8 @@ #include "securec.h" #include "../profile_resources.h" -using namespace OHOS::SignatureTools; - namespace OHOS { +namespace SignatureTools { bool SignProfileTest001(const uint8_t* data, size_t size) { std::string content(data, data + size); @@ -147,11 +146,11 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) return true; } } - +} /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DoSomethingInterestingWithMyAPI(data, size); + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); return 0; } \ No newline at end of file diff --git a/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp index 1c7caf44ebe722b012ef73540bafb2c5794b3e5c..aa7ac7b95bd6acbb6d54497581116d6c81db778f 100644 --- a/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp @@ -19,7 +19,6 @@ #include "hap_signer_block_utils.h" -using namespace OHOS::SignatureTools; namespace OHOS { namespace SignatureTools { const std::string pathFile = "./zip/tmp.hap"; diff --git a/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp index 9d7afb6bc99497a2c475bedef7b28243f9a15122..ffb11d35595ea120c7fc778ee6461337d9c82f30 100644 --- a/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp @@ -24,7 +24,6 @@ #include "random_access_file_input.h" #include "random_access_file_output.h" -using namespace OHOS::SignatureTools; namespace OHOS { namespace SignatureTools { @@ -76,7 +75,7 @@ void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - (void)rename("./zip/unsigned.txt", UNSIGNED_HAP_FILE_PATH); + (void)rename("./zip/unsigned.txt", OHOS::SignatureTools::UNSIGNED_HAP_FILE_PATH); sync(); OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); return 0; diff --git a/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp index 31b060bdc6dff789b28ea5dd79b6eb4483371759..8e951464b1799c159054338845389071c0cc91ca 100644 --- a/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp @@ -22,7 +22,6 @@ #include "zip_signer.h" -using namespace OHOS::SignatureTools; namespace OHOS { namespace SignatureTools { static constexpr int ALIGNMENT = 4; @@ -203,9 +202,9 @@ void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - (void)rename("./zip/data_descriptor_hap.txt", DATA_DESC_HAP_FILE_PATH); - (void)rename("./zip/unsigned.txt", UNSIGNED_HAP_FILE_PATH); - (void)rename("./zip/signed.txt", SIGNED_HAP_FILE_PATH); + (void)rename("./zip/data_descriptor_hap.txt", OHOS::SignatureTools::DATA_DESC_HAP_FILE_PATH); + (void)rename("./zip/unsigned.txt", OHOS::SignatureTools::UNSIGNED_HAP_FILE_PATH); + (void)rename("./zip/signed.txt", OHOS::SignatureTools::SIGNED_HAP_FILE_PATH); sync(); OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); return 0; diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_header_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_header_test.cpp index b0c7b46d67ec219b85f0b4b5215dc017e39eee69..f9e3efe9fd9b7c0fa9ac739df586939abb0f21cd 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_header_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_header_test.cpp @@ -17,11 +17,8 @@ #include #include "code_sign_block_header.h" -using namespace OHOS::SignatureTools; - -/* -* 测试套件,固定写法 -*/ +namespace OHOS { +namespace SignatureTools { class CodeSignBlockHeaderTest : public testing::Test { public: static void SetUpTestCase(void) @@ -307,4 +304,6 @@ HWTEST_F(CodeSignBlockHeaderTest, toByteArray, testing::ext::TestSize.Level1) api->ToByteArray(byteArray); EXPECT_EQ(byteArray.size(), 32); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_test.cpp index b0264e8c9613685edff9db32e8754c7a2484c23c..db1c73d6b26cbe51dca6b7ef5928a4103c4bfd4a 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/code_sign_block_test.cpp @@ -21,8 +21,8 @@ #include "hap_info_segment.h" #include "sign_info.h" -using namespace OHOS::SignatureTools; - +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 */ @@ -425,4 +425,6 @@ HWTEST_F(CodeSignBlockTest, setSoInfoSegment, testing::ext::TestSize.Level1) api->SetSoInfoSegment(soSeg); EXPECT_EQ(true, 1); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/elf_sign_block_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/elf_sign_block_test.cpp index 032fd14759f7072fe0042a33f82ca5bbd85c74e6..cb4f45e90970227eb85db6c96f290fc7666e884a 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/elf_sign_block_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/elf_sign_block_test.cpp @@ -20,7 +20,8 @@ #include "elf_sign_block.h" #include "byte_buffer.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class ElfSignBlockTest : public testing::Test { public: @@ -73,4 +74,6 @@ HWTEST_F(ElfSignBlockTest, FromByteArray002, testing::ext::TestSize.Level1) bool flag = elfSignBlock.FromByteArray(arr, block); EXPECT_EQ(flag, false); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/extension_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/extension_test.cpp index 2458ef097cb8cd30759c8c3f045dd74a4ec5af67..40beae82670b1b13c0615d4dfe07d6298d27cdb4 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/extension_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/extension_test.cpp @@ -17,7 +17,8 @@ #include #include "extension.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -81,4 +82,6 @@ HWTEST_F(ExtensionTest, toByteArray, testing::ext::TestSize.Level1) api->ToByteArray(byteArray); EXPECT_EQ(byteArray.size(), 8); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/fs_verity_info_segment_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/fs_verity_info_segment_test.cpp index e2766c9ea9ec0a08a82026be8be6ec18fc046bcb..10bdb64f78ef05d59718782d45a61a993750d298 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/fs_verity_info_segment_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/fs_verity_info_segment_test.cpp @@ -17,7 +17,8 @@ #include #include "fs_verity_info_segment.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -242,4 +243,6 @@ HWTEST_F(FsVerityInfoSegmentTest, toByteArray, testing::ext::TestSize.Level1) api->ToByteArray(byteArray); EXPECT_EQ(byteArray.size(), 64); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/hap_info_segment_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/hap_info_segment_test.cpp index 59b48429b1a44dc8d2a9d5aa774d595ca4498423..6d4bf653e744602a855b4d74ca2027acd75f1a82 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/hap_info_segment_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/hap_info_segment_test.cpp @@ -17,7 +17,8 @@ #include #include "hap_info_segment.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -247,3 +248,5 @@ HWTEST_F(HapInfoSegmentTest, toByteArray, testing::ext::TestSize.Level1) EXPECT_EQ(byteArray.size(), 64); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/merkle_tree_extension_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/merkle_tree_extension_test.cpp index c002738ee09e7a9bef28ba6bdecee02181f0a16c..c951e7d8e52d0a7c9637fcd66bfb4a2717df0591 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/merkle_tree_extension_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/merkle_tree_extension_test.cpp @@ -17,7 +17,8 @@ #include #include "merkle_tree_extension.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -214,4 +215,6 @@ HWTEST_F(MerkleTreeExtensionTest, toByteArray, testing::ext::TestSize.Level1) api->ToByteArray(byteArray); EXPECT_EQ(byteArray.size(), 88); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/native_lib_info_segment_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/native_lib_info_segment_test.cpp index 2b8354cad208020569f1ed1ce2c397471cc8b2af..fd9341341b5034df0865af881cd4158bc7d3f564 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/native_lib_info_segment_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/native_lib_info_segment_test.cpp @@ -17,7 +17,8 @@ #include #include "native_lib_info_segment.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -305,12 +306,5 @@ HWTEST_F(NativeLibInfoSegmentTest, size, testing::ext::TestSize.Level1) EXPECT_NE(nativeLibInfoSegmentSize, 0); } - -// /** -// * @tc.name: toByteArray001 -// * @tc.desc: Test function of NativeLibInfoSegmentTest::GenerateCsr() interface for SUCCESS. -// * @tc.size: MEDIUM -// * @tc.type: FUNC -// * @tc.level Level 1 -// * @tc.require: SR000H63TL -// */ +} // namespace SignatureTools +} // namespace OHOS diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/segment_header_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/segment_header_test.cpp index 67d28ca8ff7aaa416ebed00fbf49937ea475a4af..da3a4a9535c0e043a4e16cc2a39cd64deb16acc4 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/segment_header_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/segment_header_test.cpp @@ -17,7 +17,8 @@ #include #include "segment_header.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -98,4 +99,6 @@ HWTEST_F(SegmentHeaderTest, FromByteArray003, testing::ext::TestSize.Level1) std::unique_ptr ptr = segmentHeader.FromByteArray(arr); EXPECT_NE(arr.size(), 0); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/sign_info_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/sign_info_test.cpp index 9c06b9667118d91224d425e154dd809ea2522167..90802898e6f5b451e0ab5dc91c15dee3288b5b4a 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/sign_info_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/sign_info_test.cpp @@ -18,7 +18,8 @@ #include "sign_info.h" #include "byte_buffer.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -180,3 +181,5 @@ HWTEST_F(SignInfoTest, toByteArray, testing::ext::TestSize.Level1) EXPECT_EQ(bytes.size(), 60); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/signed_file_pos_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/signed_file_pos_test.cpp index 7f3e07ce1c36e3f2b67108d6e97e62250961a278..e879d3598d3148160e7f8d20a9f261777714ea5f 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/datastructure/signed_file_pos_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/datastructure/signed_file_pos_test.cpp @@ -17,7 +17,8 @@ #include #include "signed_file_pos.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -152,3 +153,5 @@ HWTEST_F(SignedFilePosTest, increaseSignInfoOffset, testing::ext::TestSize.Level EXPECT_EQ(true, 1); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_test.cpp index 9dd64ff6c0a4de297be8e45c2b63073d3763ddc4..620afbf3afe0ba7571155314e0e6ff9688c7da98 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_test.cpp @@ -17,7 +17,8 @@ #include #include "fs_verity_descriptor.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class FsVerityDescriptorTest : public testing::Test { public: @@ -397,4 +398,6 @@ HWTEST_F(FsVerityDescriptorTest, WriteBytesWithSize, testing::ext::TestSize.Leve int32_t size = src.size(); EXPECT_EQ(size, 8); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_with_sign_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_with_sign_test.cpp index 3427baea0820046c354e199c601af5756290cbd2..8d16bdff7122e81dbb59db66844815989c56bd1e 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_with_sign_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_descriptor_with_sign_test.cpp @@ -19,7 +19,8 @@ #include "fs_verity_descriptor_with_sign.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class FsVerityDescriptorWithSignTest : public testing::Test { public: @@ -143,4 +144,6 @@ HWTEST_F(FsVerityDescriptorWithSignTest, GetSignature, testing::ext::TestSize.Le int32_t size = sig.size(); EXPECT_EQ(size, 4); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_digest_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_digest_test.cpp index c01cb3947db94e9ada203f2de41dd87b31e345ad..26d26af646b4f17a898ef99c1256dc72e22fd753 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_digest_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_digest_test.cpp @@ -17,7 +17,8 @@ #include #include -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class FsVerityDigestTest : public testing::Test { public: @@ -43,4 +44,6 @@ HWTEST_F(FsVerityDigestTest, GetFsVerityDigest, testing::ext::TestSize.Level1) FsVerityDigest::GetFsVerityDigest(1, digest, fsVerityDigest); EXPECT_EQ(digest.size(), 16); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_generator_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_generator_test.cpp index aa339f1eebbafbb047c63d139d9b2931c7cd4488..3d43a76426c738af37ee95ed687d59c5b48bdfcb 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_generator_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_generator_test.cpp @@ -18,7 +18,8 @@ #include #include "fs_verity_generator.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class FsVerityGeneratorTest : public testing::Test { public: @@ -182,4 +183,6 @@ HWTEST_F(FsVerityGeneratorTest, GetLog2BlockSize, testing::ext::TestSize.Level1) uint8_t blockSize = fsVerityGenerator.GetLog2BlockSize(); EXPECT_NE(blockSize, 0); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_hash_algorithm_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_hash_algorithm_test.cpp index 1c4f9615e87c7517b35d3923b3417bdb7b752adb..55ac00eb77863118c033b064b668ff160e964ae5 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_hash_algorithm_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/fs_verity_hash_algorithm_test.cpp @@ -17,7 +17,8 @@ #include #include "fs_verity_hash_algorithm.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class FsVerityHashAlgorithmTest : public testing::Test { public: @@ -70,4 +71,6 @@ HWTEST_F(FsVerityHashAlgorithmTest, GetOutputByteSize, testing::ext::TestSize.Le const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); EXPECT_EQ(SHA256.GetOutputByteSize(), 256 / 8); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/merkle_tree_builder_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/merkle_tree_builder_test.cpp index 5a1c70605a9b9bcd7393887dd91423c296d7548e..5526e2705c7757dec0dd14987596c9db929c743f 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/fsverity/merkle_tree_builder_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/fsverity/merkle_tree_builder_test.cpp @@ -18,7 +18,8 @@ #include #include "merkle_tree_builder.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class MerkleTreeBuilderTest : public testing::Test { public: @@ -88,4 +89,6 @@ HWTEST_F(MerkleTreeBuilderTest, GenerateMerkleTree003, testing::ext::TestSize.Le MerkleTree* merkleTree = builder.GenerateMerkleTree(inputStream, 0, SHA256); EXPECT_EQ(merkleTree, nullptr); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/sign/bc_signeddata_generator_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/sign/bc_signeddata_generator_test.cpp index 937aed156b49c2cf3f2ce1d280444062526f46c4..9a80263703621f87af723661cd132b4f3d915a71 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/sign/bc_signeddata_generator_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/sign/bc_signeddata_generator_test.cpp @@ -19,7 +19,8 @@ #include "code_signing.h" #include "options.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class BCSignedDataGeneratorTest : public testing::Test { public: @@ -340,3 +341,5 @@ HWTEST_F(BCSignedDataGeneratorTest, SetOwnerId, testing::ext::TestSize.Level1) api->SetOwnerId(ownerID); EXPECT_EQ(true, 1); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/sign/code_signing_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/sign/code_signing_test.cpp index e6378d56a2846ed67d7546783e980b2243473447..e94e148dc88e37f80ab6467fcb3279bff4a3f053 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/sign/code_signing_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/sign/code_signing_test.cpp @@ -22,7 +22,8 @@ #include "local_sign_provider.h" #include "unzip_handle_param.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class CodeSigningTest : public testing::Test { public: @@ -785,3 +786,5 @@ HWTEST_F(CodeSigningTest, GetElfCodeSignBlock004, testing::ext::TestSize.Level1) bool ret = codeSigning.GetElfCodeSignBlock(inputFile, offset, inForm, params.at("profileContent"), codesignData); EXPECT_EQ(ret, false); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/sign/verify_code_signature_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/sign/verify_code_signature_test.cpp index 627f10f2231b33d5a59e6da058d53584cd4a7618..859e84e9b7a2149798fde642fb8bdc7bc9e1576b 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/sign/verify_code_signature_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/sign/verify_code_signature_test.cpp @@ -18,8 +18,10 @@ #include #include "verify_code_signature.h" #include "verify_hap.h" +#include "hap_utils.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -489,13 +491,69 @@ HWTEST_F(VerifyCodeSignatureTest, VerifyNativeLib002, testing::ext::TestSize.Lev */ HWTEST_F(VerifyCodeSignatureTest, CheckCodeSign001, testing::ext::TestSize.Level1) { - Options options; - options.emplace(Options::IN_FILE, std::string("./codeSigning/hap_no_suffix_err")); - options.emplace(Options::OUT_CERT_CHAIN, std::string("./codeSigning/xx.cer")); - options.emplace(Options::OUT_PROFILE, std::string("./codeSigning/xx.p7b")); + std::string file = "hap"; + std::vector optionalBlocks; + OptionalBlock block; + block.optionalType = HapUtils::HAP_PROPERTY_BLOCK_ID; + ByteBuffer bf(8); + bf.PutByte('a'); + block.optionalBlockValue = bf; + optionalBlocks.push_back(block); + + VerifyHap hapVerify; + int32_t ret = hapVerify.CheckCodeSign(file, optionalBlocks); + + EXPECT_EQ(ret, 0); +} - VerifyHap hapVerifyV2; - int32_t ret = hapVerifyV2.Verify(options.GetString(Options::IN_FILE), &options); +/** + * @tc.name: CheckCodeSign002 + * @tc.desc: Test function of VerifyCodeSignatureTest::CheckCodeSign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, CheckCodeSign002, testing::ext::TestSize.Level1) +{ + std::string file = "test.hap"; + std::vector optionalBlocks; + OptionalBlock block; + block.optionalType = HapUtils::HAP_PROPERTY_BLOCK_ID; + ByteBuffer bf(8); + bf.PutByte('a'); + block.optionalBlockValue = bf; + optionalBlocks.push_back(block); + + VerifyHap hapVerify; + int32_t ret = hapVerify.CheckCodeSign(file, optionalBlocks); + + EXPECT_EQ(ret, 0); +} - EXPECT_NE(ret, 0); -} \ No newline at end of file +/** + * @tc.name: CheckCodeSign003 + * @tc.desc: Test function of VerifyCodeSignatureTest::CheckCodeSign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, CheckCodeSign003, testing::ext::TestSize.Level1) +{ + std::string file = "test.hap"; + std::vector optionalBlocks; + OptionalBlock block; + block.optionalType = HapUtils::HAP_PROPERTY_BLOCK_ID; + ByteBuffer bf(16); + bf.PutByte('a'); + block.optionalBlockValue = bf; + optionalBlocks.push_back(block); + + VerifyHap hapVerify; + int32_t ret = hapVerify.CheckCodeSign(file, optionalBlocks); + + EXPECT_EQ(ret, 0); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/codeSigning/utils/cms_utils_test.cpp b/hapsigntool_cpp_test/unittest/codeSigning/utils/cms_utils_test.cpp index b6774e523e937d46317342f5b2b51e8af77f4512..0de258d3664a929acbe53f9be0e79c139afa3037 100644 --- a/hapsigntool_cpp_test/unittest/codeSigning/utils/cms_utils_test.cpp +++ b/hapsigntool_cpp_test/unittest/codeSigning/utils/cms_utils_test.cpp @@ -18,7 +18,8 @@ #include "cms_utils.h" #include "verify_code_signature.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class CmsUtilsTest : public testing::Test { public: @@ -181,3 +182,5 @@ HWTEST_F(CmsUtilsTest, VerifySignDataWithUnsignedDataDigest, testing::ext::TestS EXPECT_EQ(flag, false); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/hap_utils_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/hap_utils_test.cpp index bf58e2a9056272468cd45ad042a6f2b60b0857c9..062b7aedf648388c509577022283052e3969d145 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/hap_utils_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/hap_utils_test.cpp @@ -20,7 +20,8 @@ #include "hap_utils.h" #include "byte_buffer.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class HapUtilsTest : public testing::Test { public: @@ -93,4 +94,6 @@ HWTEST_F(HapUtilsTest, ReadFileToByteBuffer, testing::ext::TestSize.Level1) bool result = HapUtils::ReadFileToByteBuffer(file, buffer); EXPECT_EQ(result, false); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/package/elf_signed_with_profile_json.txt b/hapsigntool_cpp_test/unittest/elfVerify/package/elf_signed_with_profile_json.txt new file mode 100644 index 0000000000000000000000000000000000000000..e971fb6fab6bbe7f417eff650b7c5d43484c8876 Binary files /dev/null and b/hapsigntool_cpp_test/unittest/elfVerify/package/elf_signed_with_profile_json.txt differ diff --git a/hapsigntool_cpp_test/unittest/elfVerify/sign_block_info_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/sign_block_info_test.cpp index 3527a7197f598994984ee7896f5a4ffd5b14c5ec..08270019193b5b0dec687b3c201fb75ad4f5c0d9 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/sign_block_info_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/sign_block_info_test.cpp @@ -19,7 +19,8 @@ #include "sign_block_info.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class SignBlockInfoTest : public testing::Test { public: @@ -131,3 +132,5 @@ HWTEST_F(SignBlockInfoTest, GetNeedGenerateDigest, testing::ext::TestSize.Level1 EXPECT_EQ(needGenerateDigest, true); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/sign_content_info_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/sign_content_info_test.cpp index 8a7f75b0b73e30e34e10e082016fc78ad8ef3668..1c8dcd762bf5d8edd09e00673cfbad793109abea 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/sign_content_info_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/sign_content_info_test.cpp @@ -19,7 +19,8 @@ #include "sign_content_info.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class SignContentInfoTest : public testing::Test { public: @@ -28,3 +29,5 @@ public: void SetUp() {}; void TearDown() {}; }; +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/signature_block_types_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/signature_block_types_test.cpp index 1d59a9cd4f8457b44c6a9c6d9f0d47c9685c5c15..2135303c5f75dfd9c6b1e6d78ad2380134adb8e1 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/signature_block_types_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/signature_block_types_test.cpp @@ -19,7 +19,8 @@ #include "signature_block_types.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class SignatureBlockTypesTest : public testing::Test { public: @@ -91,4 +92,6 @@ HWTEST_F(SignatureBlockTypesTest, GetProfileBlockTypes004, testing::ext::TestSiz bool flag = type == SignatureBlockTypes::PROFILE_NOSIGNED_BLOCK; EXPECT_EQ(flag, true); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/signing_block_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/signing_block_test.cpp index 6045cc1a84e96afce894341b33c4fe1798dc6d5a..4080dd682a213b826c6e3473db1d0b695f66d210 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/signing_block_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/signing_block_test.cpp @@ -19,7 +19,8 @@ #include "signing_block.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class SigningBlockTest : public testing::Test { public: @@ -79,4 +80,6 @@ HWTEST_F(SigningBlockTest, GetOffset, testing::ext::TestSize.Level1) int32_t offset = signingBlock.GetOffset(); EXPECT_EQ(offset, 0); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/verify_bin_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/verify_bin_test.cpp index 17061fec04c4f5b5aa3a89aea25486b5bd8f52e5..d4e441e1d566d7771485fa798180ddc41ab9ba02 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/verify_bin_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/verify_bin_test.cpp @@ -21,7 +21,8 @@ #include "sign_bin.h" #include "hash_utils.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class VerifyBinTest : public testing::Test { public: @@ -501,4 +502,6 @@ HWTEST_F(VerifyBinTest, GetDigestFromBytes002, testing::ext::TestSize.Level1) int size = dig.size(); EXPECT_EQ(size, 0); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/elfVerify/verify_elf_test.cpp b/hapsigntool_cpp_test/unittest/elfVerify/verify_elf_test.cpp index 4e96e584b46507e171b139e916e730c775a6d3ff..d08fd629819d40cdd00eae4ca9de53c68fcafe4b 100644 --- a/hapsigntool_cpp_test/unittest/elfVerify/verify_elf_test.cpp +++ b/hapsigntool_cpp_test/unittest/elfVerify/verify_elf_test.cpp @@ -22,7 +22,8 @@ #include "sign_provider.h" #include "verify_hap.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { class VerifyElfTest : public testing::Test { public: @@ -40,6 +41,7 @@ void VerifyElfTest::SetUpTestCase(void) (void)rename("./elfVerify/elf_signed_package.txt", "./elfVerify/elf_signed_package.elf"); (void)rename("./elfVerify/elf_unsigned_package.txt", "./elfVerify/elf_unsigned_package.elf"); (void)rename("./elfVerify/elf_check_file_err_package.txt", "./elfVerify/elf_check_file_err_package.elf"); + (void)rename("./elfVerify/elf_signed_with_profile_json.txt", "./elfVerify/elf_signed_with_profile_json.elf"); } void VerifyElfTest::TearDownTestCase(void) @@ -298,6 +300,27 @@ HWTEST_F(VerifyElfTest, Verify013, testing::ext::TestSize.Level1) EXPECT_EQ(flag, true); } +/** + * @tc.name: Verify014 + * @tc.desc: verify elf with unsigned profile + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify014, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_with_profile_json.elf")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyElf verifyElf; + bool flag = verifyElf.Verify(&options); + + EXPECT_EQ(flag, true); +} + /** * @tc.name: CheckParams * @tc.desc: Test function of VerifyElfTest::CheckParams() interface for SUCCESS. @@ -761,4 +784,6 @@ HWTEST_F(VerifyElfTest, WriteVerifyOutput002, testing::ext::TestSize.Level1) int32_t flag = hapVerifyV2.WriteVerifyOutput(pkcs7Context, profileVec, &options); EXPECT_NE(flag, 0); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/generateCA/generate_ca_test.cpp b/hapsigntool_cpp_test/unittest/generateCA/generate_ca_test.cpp index 8467dd0195dd5c84bb2b3352b2011613ad0e21d7..6a5455fc1b23806d3daab7f1404e6ca95fcd0740 100644 --- a/hapsigntool_cpp_test/unittest/generateCA/generate_ca_test.cpp +++ b/hapsigntool_cpp_test/unittest/generateCA/generate_ca_test.cpp @@ -1055,9 +1055,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_001, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; @@ -1106,9 +1106,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_002, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; @@ -1158,9 +1158,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_003, testing::ext::TestSize.Level1) std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; std::string keyUsage = "digitalSignature"; std::string outFile = "general.cer"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char keystorePwd[] = "123456"; @@ -1205,9 +1205,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_004, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; @@ -1253,9 +1253,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_005, testing::ext::TestSize.Level1) std::string subject = ""; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; @@ -1296,9 +1296,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_006, testing::ext::TestSize.Level1) std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; std::string keyUsage = "digitalSignature"; std::string outFile = "/datamsge/test/generateCA/general.cer"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char keystorePwd[] = "123456"; @@ -1335,9 +1335,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_007, testing::ext::TestSize.Level1) std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; std::string keyUsage = "digitalSignature"; std::string outFile = "general.cer"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char keystorePwd[] = "123456"; @@ -1377,9 +1377,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_008, testing::ext::TestSize.Level1) std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; std::string keyUsage = "digitalSignature"; std::string outFile = "general.cer"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char keystorePwd[] = "123456"; @@ -1419,9 +1419,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_009, testing::ext::TestSize.Level1) std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; std::string keyUsage = "digitalSignature"; std::string outFile = "/mjssngek/test/generateCA/general.cer"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char keystorePwd[] = "123456"; @@ -1445,7 +1445,7 @@ HWTEST_F(GenerateCaTest, generate_cert_test_009, testing::ext::TestSize.Level1) // general cert /** * @tc.name: generate_cert_test_010 - * @tc.desc: Test function of GenerateCert() FAILED to generate a certificate with a error keyalias. + * @tc.desc: Test function of GenerateCert() SUCCESS to generate a certificate. * @tc.type: FUNC * @tc.require: SR000H63TL */ @@ -1463,223 +1463,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_010, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; - bool keyUsageCritical = true; - char secret[] = "123456"; - char ksPwd[] = "123456"; - char isksPwd[] = "123456"; - (*params)["keyPwd"] = secret; - (*params)["keystorePwd"] = ksPwd; - (*params)["issuerKeystorePwd"] = isksPwd; - (*params)["keyAlias"] = keyAlias; - (*params)["keyPwd"] = keyPwd; - (*params)["keyAlg"] = keyAlg; - (*params)["keySize"] = keySize; - (*params)["keystoreFile"] = keystoreFile; - (*params)["keystorePwd"] = keystorePwd; - (*params)["signAlg"] = signAlg; - (*params)["subject"] = subject; - (*params)["issuer"] = issuer; - (*params)["issuerkeyAlias"] = issuerkeyAlias; - (*params)["keyUsage"] = keyUsage; - (*params)["basicConstraints"] = basicConstraints; - (*params)["basicConstraintsCritical"] = basicConstraintsCritical; - (*params)["basicConstraintsCa"] = basicConstraintsCa; - (*params)["keyUsageCritical"] = keyUsageCritical; - std::unique_ptr adaptePtr = std::make_unique(params.get()); - EVP_PKEY* keyPair = nullptr; - keyPair = adaptePtr->GetAliasKey(true); - X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); - X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); - EXPECT_EQ(cert, nullptr); -} - -/** - * @tc.name: generate_cert_test_011 - * @tc.desc: Test function of GenerateCert() FAILED to generate a certificate with a error issuer. - * @tc.type: FUNC - * @tc.require: SR000H63TL - */ -HWTEST_F(GenerateCaTest, generate_cert_test_011, testing::ext::TestSize.Level1) -{ - std::shared_ptr params = std::make_shared(); - std::string keyAlias = "alias"; - std::string issuerkeyAlias = "oh-app1-key-v1"; - char keyPwd[] = "123456"; - std::string keyAlg = "ECC"; - int keySize = 256; - std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; - char keystorePwd[] = "123456"; - std::string signAlg = "SHA384withECDSA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; - std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; - std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; - bool keyUsageCritical = false; - char secret[] = "123456"; - char ksPwd[] = "123456"; - char isksPwd[] = "123456"; - (*params)["keyPwd"] = secret; - (*params)["keystorePwd"] = ksPwd; - (*params)["issuerKeystorePwd"] = isksPwd; - (*params)["keyAlias"] = keyAlias; - (*params)["keyPwd"] = keyPwd; - (*params)["keyAlg"] = keyAlg; - (*params)["keySize"] = keySize; - (*params)["keystoreFile"] = keystoreFile; - (*params)["keystorePwd"] = keystorePwd; - (*params)["signAlg"] = signAlg; - (*params)["subject"] = subject; - (*params)["issuer"] = issuer; - (*params)["issuerkeyAlias"] = issuerkeyAlias; - (*params)["keyUsage"] = keyUsage; - (*params)["basicConstraints"] = basicConstraints; - (*params)["basicConstraintsCritical"] = basicConstraintsCritical; - (*params)["basicConstraintsCa"] = basicConstraintsCa; - (*params)["keyUsageCritical"] = keyUsageCritical; - std::unique_ptr adaptePtr = std::make_unique(params.get()); - EVP_PKEY* keyPair = nullptr; - keyPair = adaptePtr->GetAliasKey(true); - X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); - X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); - EXPECT_EQ(cert, nullptr); -} - - -/** - * @tc.name: generate_cert_test_012 - * @tc.desc: Test function of GenerateCert() FAILED to generate a certificate with a error basicConstraintsCa. - * @tc.type: FUNC - * @tc.require: SR000H63TL - */ -HWTEST_F(GenerateCaTest, generate_cert_test_012, testing::ext::TestSize.Level1) -{ - std::shared_ptr params = std::make_shared(); - std::string keyAlias = "alias"; - std::string issuerkeyAlias = "oh-app1-key-v1"; - char keyPwd[] = "123456"; - std::string keyAlg = "ECC"; - int keySize = 256; - std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; - char keystorePwd[] = "123456"; - std::string signAlg = "SHA384withECDSA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; - std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; - std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = false; - bool keyUsageCritical = true; - char secret[] = "123456"; - char ksPwd[] = "123456"; - char isksPwd[] = "123456"; - (*params)["keyPwd"] = secret; - (*params)["keystorePwd"] = ksPwd; - (*params)["issuerKeystorePwd"] = isksPwd; - (*params)["keyAlias"] = keyAlias; - (*params)["keyPwd"] = keyPwd; - (*params)["keyAlg"] = keyAlg; - (*params)["keySize"] = keySize; - (*params)["keystoreFile"] = keystoreFile; - (*params)["keystorePwd"] = keystorePwd; - (*params)["signAlg"] = signAlg; - (*params)["subject"] = subject; - (*params)["issuer"] = issuer; - (*params)["issuerkeyAlias"] = issuerkeyAlias; - (*params)["keyUsage"] = keyUsage; - (*params)["basicConstraints"] = basicConstraints; - (*params)["basicConstraintsCritical"] = basicConstraintsCritical; - (*params)["basicConstraintsCa"] = basicConstraintsCa; - (*params)["keyUsageCritical"] = keyUsageCritical; - std::unique_ptr adaptePtr = std::make_unique(params.get()); - EVP_PKEY* keyPair = nullptr; - keyPair = adaptePtr->GetAliasKey(true); - X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); - X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); - EXPECT_EQ(cert, nullptr); -} - - -/** - * @tc.name: generate_cert_test_013 - * @tc.desc: Test function of GenerateCert() FAILED to generate a certificate with a error basicConstraintsCritical. - * @tc.type: FUNC - * @tc.require: SR000H63TL - */ -HWTEST_F(GenerateCaTest, generate_cert_test_013, testing::ext::TestSize.Level1) -{ - std::shared_ptr params = std::make_shared(); - std::string keyAlias = "alias"; - std::string issuerkeyAlias = "oh-app1-key-v1"; - char keyPwd[] = "123456"; - std::string keyAlg = "ECC"; - int keySize = 256; - std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; - char keystorePwd[] = "123456"; - std::string signAlg = "SHA384withECDSA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; - std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; - std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = false; - bool basicConstraintsCa = false; - bool keyUsageCritical = true; - char secret[] = "123456"; - char ksPwd[] = "123456"; - char isksPwd[] = "123456"; - (*params)["keyPwd"] = secret; - (*params)["keystorePwd"] = ksPwd; - (*params)["issuerKeystorePwd"] = isksPwd; - (*params)["keyAlias"] = keyAlias; - (*params)["keyPwd"] = keyPwd; - (*params)["keyAlg"] = keyAlg; - (*params)["keySize"] = keySize; - (*params)["keystoreFile"] = keystoreFile; - (*params)["keystorePwd"] = keystorePwd; - (*params)["signAlg"] = signAlg; - (*params)["subject"] = subject; - (*params)["issuer"] = issuer; - (*params)["issuerkeyAlias"] = issuerkeyAlias; - (*params)["keyUsage"] = keyUsage; - (*params)["basicConstraints"] = basicConstraints; - (*params)["basicConstraintsCritical"] = basicConstraintsCritical; - (*params)["basicConstraintsCa"] = basicConstraintsCa; - (*params)["keyUsageCritical"] = keyUsageCritical; - std::unique_ptr adaptePtr = std::make_unique(params.get()); - EVP_PKEY* keyPair = nullptr; - keyPair = adaptePtr->GetAliasKey(true); - X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); - X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); - EXPECT_EQ(cert, nullptr); -} - -/** - * @tc.name: generate_cert_test_014 - * @tc.desc: Test function of GenerateCert() FAILED to generate a certificate with a error keyusagecritial. - * @tc.type: FUNC - * @tc.require: SR000H63TL - */ -HWTEST_F(GenerateCaTest, generate_cert_test_014, testing::ext::TestSize.Level1) -{ - std::shared_ptr params = std::make_shared(); - std::string keyAlias = "alias"; - std::string issuerkeyAlias = "oh-app1-key-v1"; - char keyPwd[] = "123456"; - std::string keyAlg = "ECC"; - int keySize = 256; - std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; - char keystorePwd[] = "123456"; - std::string signAlg = "SHA384withECDSA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; - std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; - std::string keyUsage = "digitalSignature"; - bool basicConstraints = false; - bool basicConstraintsCritical = false; - bool basicConstraintsCa = false; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char ksPwd[] = "123456"; @@ -1707,7 +1493,7 @@ HWTEST_F(GenerateCaTest, generate_cert_test_014, testing::ext::TestSize.Level1) keyPair = adaptePtr->GetAliasKey(true); X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); - EXPECT_EQ(cert, nullptr); + EXPECT_NE(cert, nullptr); } /** @@ -1730,9 +1516,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_015, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = false; - bool basicConstraintsCritical = false; - bool basicConstraintsCa = false; + std::string basicConstraints = "false"; + std::string basicConstraintsCritical = "false"; + std::string basicConstraintsCa = "false"; bool keyUsageCritical = true; char secret[] = "123456"; char ksPwd[] = "123456"; @@ -1781,9 +1567,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_016, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = false; - bool basicConstraintsCritical = false; - bool basicConstraintsCa = false; + std::string basicConstraints = "false"; + std::string basicConstraintsCritical = "false"; + std::string basicConstraintsCa = "false"; bool keyUsageCritical = true; char secret[] = "123456"; char ksPwd[] = "123456"; diff --git a/hapsigntool_cpp_test/unittest/generateCA/generate_general_ca_test.cpp b/hapsigntool_cpp_test/unittest/generateCA/generate_general_ca_test.cpp index d7db6e881c1acfcf51c04910be75313f33546b91..c7c4cbbe69226da1ba279004cd91be7980ab0ffc 100644 --- a/hapsigntool_cpp_test/unittest/generateCA/generate_general_ca_test.cpp +++ b/hapsigntool_cpp_test/unittest/generateCA/generate_general_ca_test.cpp @@ -31,20 +31,30 @@ namespace SignatureTools { class GenerateCaTest : public testing::Test { public: - static void SetUpTestCase() - { - }; - static void TearDownTestCase() - { - }; - void SetUp() - { - }; - void TearDown() - { - }; + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); }; +void GenerateCaTest::SetUpTestCase(void) +{ + (void)rename("./generateCA/phone-default-signed.txt", "./generateCA/phone-default-signed.hap"); + (void)rename("./generateCA/bin_signed_package.txt", "./generateCA/bin_signed_package.bin"); + (void)rename("./generateCA/elf_signed_package.txt", "./generateCA/elf_signed_package.elf"); +} + +void GenerateCaTest::TearDownTestCase(void) +{ +} + +void GenerateCaTest::SetUp() +{ +} + +void GenerateCaTest::TearDown() +{ +} /** * @tc.name: generate_cert_test_017 @@ -66,9 +76,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_017, testing::ext::TestSize.Level1) std::string subject = ""; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; @@ -115,9 +125,9 @@ HWTEST_F(GenerateCaTest, generate_cert_test_018, testing::ext::TestSize.Level1) std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; std::string keyUsage = "digitalSignature"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; @@ -1375,6 +1385,72 @@ HWTEST_F(GenerateCaTest, hap_verify_test_002, testing::ext::TestSize.Level1) EXPECT_EQ(result, false); } +/** + * @tc.name: hap_verify_test_003 + * @tc.desc: Test function of VerifyHapSigner() interface for verify hap SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, hap_verify_test_003, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string inFile = "./generateCA/phone-default-signed.hap"; + std::string outCertChain = "./generateCA/xxx.cer"; + std::string outProfile = "./generateCA/xxx.p7b"; + std::string inForm = "zip"; + params[Options::IN_FILE] = inFile; + params[Options::OUT_CERT_CHAIN] = outCertChain; + params[Options::OUT_PROFILE] = outProfile; + params[Options::INFORM] = inForm; + bool result = api.VerifyHapSigner(¶ms); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: hap_verify_test_004 + * @tc.desc: Test function of VerifyHapSigner() interface for verify elf SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, hap_verify_test_004, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string inFile = "./generateCA/elf_signed_package.elf"; + std::string outCertChain = "./generateCA/xxx.cer"; + std::string outProfile = "./generateCA/xxx.p7b"; + std::string inForm = "elf"; + params[Options::IN_FILE] = inFile; + params[Options::OUT_CERT_CHAIN] = outCertChain; + params[Options::OUT_PROFILE] = outProfile; + params[Options::INFORM] = inForm; + bool result = api.VerifyHapSigner(¶ms); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: hap_verify_test_005 + * @tc.desc: Test function of VerifyHapSigner() interface for verify bin SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, hap_verify_test_005, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string inFile = "./generateCA/bin_signed_package.bin"; + std::string outCertChain = "./generateCA/xxx.cer"; + std::string outProfile = "./generateCA/xxx.p7b"; + std::string inForm = "bin"; + params[Options::IN_FILE] = inFile; + params[Options::OUT_CERT_CHAIN] = outCertChain; + params[Options::OUT_PROFILE] = outProfile; + params[Options::INFORM] = inForm; + bool result = api.VerifyHapSigner(¶ms); + EXPECT_EQ(result, true); +} + /** * @tc.name: generate_key_pair_test_001 * @tc.desc: Test function of GetIssuerKeyByAlias() interface for generate key FAILED. @@ -1695,5 +1771,25 @@ HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_003, testing::ext::TestS bool ret = api->GenerateSubCertToFile(params.get(), keyPair); EXPECT_EQ(ret, true); } + +/** + * @tc.name: run_app_cert_err_test_001 + * @tc.desc: Test function of RunAppCert() interface for failed due to outFile is not exist. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, run_app_cert_err_test_001, testing::ext::TestSize.Level1) +{ + Options options; + SignToolServiceImpl service; + options[Options::ISSUER_KEY_STORE_FILE] = std::string("/data/test/generateCA/ohtest.p12"); + options[Options::CA_CERT_FILE] = std::string("/data/test/generateCA/root-ca1.cer"); + options[Options::SUB_CA_CERT_FILE] = std::string("/data/test/generateCA/app-sign-srv-ca1.cer"); + options[Options::KEY_STORE_FILE] = std::string("/data/test/generateCA/OpenHarmony.p12"); + + options[Options::OUT_FILE] = "./nohave/test.cer"; + bool ret = ParamsRunTool::RunAppCert(&options, service); + EXPECT_EQ(ret, false); +} } } \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/generateCA/package/bin_signed_package.txt b/hapsigntool_cpp_test/unittest/generateCA/package/bin_signed_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..3112a97020fe4921d663f5821dcd17756853f413 Binary files /dev/null and b/hapsigntool_cpp_test/unittest/generateCA/package/bin_signed_package.txt differ diff --git a/hapsigntool_cpp_test/unittest/generateCA/package/elf_signed_package.txt b/hapsigntool_cpp_test/unittest/generateCA/package/elf_signed_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..237bd8e7223b7240b2e4483920f8d0e8e50d16ef Binary files /dev/null and b/hapsigntool_cpp_test/unittest/generateCA/package/elf_signed_package.txt differ diff --git a/hapsigntool_cpp_test/unittest/generateCA/package/phone-default-signed.txt b/hapsigntool_cpp_test/unittest/generateCA/package/phone-default-signed.txt new file mode 100644 index 0000000000000000000000000000000000000000..33a705d43869eda0396cea3bf52747895e635d23 Binary files /dev/null and b/hapsigntool_cpp_test/unittest/generateCA/package/phone-default-signed.txt differ diff --git a/hapsigntool_cpp_test/unittest/generateKeyPair/hap_sign_tool_test.cpp b/hapsigntool_cpp_test/unittest/generateKeyPair/hap_sign_tool_test.cpp index 565bbbb04f604b39bba03b3ed9f3f34f5f7fcc59..825616d0c23b1e83508c121c86595d4122053f63 100644 --- a/hapsigntool_cpp_test/unittest/generateKeyPair/hap_sign_tool_test.cpp +++ b/hapsigntool_cpp_test/unittest/generateKeyPair/hap_sign_tool_test.cpp @@ -997,9 +997,9 @@ HWTEST_F(HapSignToolTest, hap_sign_tool_test_027, testing::ext::TestSize.Level1) std::string keyStoreFile = "./generateKeyPair/OpenHarmony.p12"; std::string keyUsage = "digitalSignature"; std::string outFile = "./generateKeyPair/general.cer"; - bool basicConstraints = true; - bool basicConstraintsCritical = true; - bool basicConstraintsCa = true; + std::string basicConstraints = "true"; + std::string basicConstraintsCritical = "true"; + std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; int keysize = 384; diff --git a/hapsigntool_cpp_test/unittest/hapSign/hw_block_data_test.cpp b/hapsigntool_cpp_test/unittest/hapSign/hw_block_data_test.cpp index a88bf7dd565f539d32d45d815ff7dfa6c11c3352..938fb777637d35dab75d10c578fd49ff242e99f0 100644 --- a/hapsigntool_cpp_test/unittest/hapSign/hw_block_data_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapSign/hw_block_data_test.cpp @@ -16,7 +16,8 @@ #include #include "hw_block_data.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -96,3 +97,5 @@ HWTEST_F(HwBlockDataTest, SetBlockStart, testing::ext::TestSize.Level1) api->SetBlockStart(1); EXPECT_EQ(true, 1); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/hapSign/hw_block_head_test.cpp b/hapsigntool_cpp_test/unittest/hapSign/hw_block_head_test.cpp index 097ce230be4d8870bcd655b54ad47b75e49f1625..489e3795b69f61ea4193f020978ceb5761c7f477 100644 --- a/hapsigntool_cpp_test/unittest/hapSign/hw_block_head_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapSign/hw_block_head_test.cpp @@ -16,7 +16,8 @@ #include #include "hw_block_head.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -111,3 +112,5 @@ HWTEST_F(HwBlockHeadTest, GetElfBlockLen, testing::ext::TestSize.Level1) int elfBlockLen = api->GetElfBlockLen(); EXPECT_EQ(elfBlockLen, 12); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/hapSign/hw_sign_head_test.cpp b/hapsigntool_cpp_test/unittest/hapSign/hw_sign_head_test.cpp index 891f0300833e5f6348ebd929d66677be0b146001..fa5c2c4c89a2e23f9e5cd07abd82593227b8e00b 100644 --- a/hapsigntool_cpp_test/unittest/hapSign/hw_sign_head_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapSign/hw_sign_head_test.cpp @@ -16,7 +16,8 @@ #include #include "hw_sign_head.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -66,3 +67,5 @@ HWTEST_F(HwSignHeadTest, getSignHeadLittleEndian, testing::ext::TestSize.Level1) std::vector signHeadLittleEndian = api->GetSignHeadLittleEndian(1024, 1); EXPECT_EQ(signHeadLittleEndian.size(), 32); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/hapSign/sign_block_data_test.cpp b/hapsigntool_cpp_test/unittest/hapSign/sign_block_data_test.cpp index 58ed9c602ef1af0c0d896b3e9352b56b690e1b38..94adaffdc8865446bfa7e92ae59d9f2062d3dbfc 100644 --- a/hapsigntool_cpp_test/unittest/hapSign/sign_block_data_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapSign/sign_block_data_test.cpp @@ -17,7 +17,8 @@ #include "hap_signer_block_utils.h" #include "sign_block_data.h" -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { /* * 测试套件,固定写法 @@ -165,4 +166,6 @@ HWTEST_F(SignBlockDataTest, GetOptionalBlockIndex, testing::ext::TestSize.Level1 int index = 0; bool flag = HapSignerBlockUtils::GetOptionalBlockIndex(optionBlocks, type, index); EXPECT_NE(flag, -1); -} \ No newline at end of file +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/hapSign/sign_elf_test.cpp b/hapsigntool_cpp_test/unittest/hapSign/sign_elf_test.cpp index 55545f490ad92d7f1b42f367c9a0cc4d5be54c18..7e2edb920c5551fae0bec152921c572e0fe3ea05 100644 --- a/hapsigntool_cpp_test/unittest/hapSign/sign_elf_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapSign/sign_elf_test.cpp @@ -38,7 +38,7 @@ public: }; }; -void SetParamsMap(std::map& params) +void SetElfParamsMap(std::map& params) { params["keyPwd"] = "123456"; params["mode"] = "localSign"; @@ -78,7 +78,7 @@ void SetParamsMap(std::map& params) params["profileContent"] = provision; } -void SetOptions(Options* options) +void SetElfOptions(Options* options) { std::string mode = "localSign"; std::string keyAlias = "oh-app1-key-v1"; @@ -122,7 +122,7 @@ HWTEST_F(SignElfTest, Sign001, testing::ext::TestSize.Level1) signerConfig.SetCompatibleVersion(9); std::map params; - SetParamsMap(params); + SetElfParamsMap(params); signerConfig.FillParameters(params); ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); @@ -134,7 +134,7 @@ HWTEST_F(SignElfTest, Sign001, testing::ext::TestSize.Level1) signerConfig.SetSignatureAlgorithms(signatureAlgorithms); std::shared_ptr options = std::make_shared(); - SetOptions(options.get()); + SetElfOptions(options.get()); signerConfig.SetOptions(options.get()); signerConfig.GetSigner(); @@ -156,7 +156,7 @@ HWTEST_F(SignElfTest, Sign002, testing::ext::TestSize.Level1) signerConfig.SetCompatibleVersion(9); std::map params; - SetParamsMap(params); + SetElfParamsMap(params); params["inFile"] = "./hapSign/unsigned-file-no.out"; signerConfig.FillParameters(params); @@ -169,7 +169,7 @@ HWTEST_F(SignElfTest, Sign002, testing::ext::TestSize.Level1) signerConfig.SetSignatureAlgorithms(signatureAlgorithms); std::shared_ptr options = std::make_shared(); - SetOptions(options.get()); + SetElfOptions(options.get()); (*options)["inFile"] = "./hapSign/unsigned-file-no.out"; signerConfig.SetOptions(options.get()); @@ -194,7 +194,7 @@ HWTEST_F(SignElfTest, Sign003, testing::ext::TestSize.Level1) signerConfig.SetCompatibleVersion(9); std::map params; - SetParamsMap(params); + SetElfParamsMap(params); params["profileFile"] = "./hapSign/signed-profile-no.p7b"; signerConfig.FillParameters(params); @@ -207,7 +207,7 @@ HWTEST_F(SignElfTest, Sign003, testing::ext::TestSize.Level1) signerConfig.SetSignatureAlgorithms(signatureAlgorithms); std::shared_ptr options = std::make_shared(); - SetOptions(options.get()); + SetElfOptions(options.get()); (*options)["profileFile"] = "./hapSign/signed-profile-no.p7b"; signerConfig.SetOptions(options.get()); @@ -231,7 +231,7 @@ HWTEST_F(SignElfTest, Sign004, testing::ext::TestSize.Level1) signerConfig.SetCompatibleVersion(9); std::map params; - SetParamsMap(params); + SetElfParamsMap(params); params["outFile"] = "./hapSign_test/entry-default-signed.elf"; signerConfig.FillParameters(params); @@ -244,7 +244,7 @@ HWTEST_F(SignElfTest, Sign004, testing::ext::TestSize.Level1) signerConfig.SetSignatureAlgorithms(signatureAlgorithms); std::shared_ptr options = std::make_shared(); - SetOptions(options.get()); + SetElfOptions(options.get()); (*options)["outFile"] = "./hapSign_test/entry-default-signed.elf"; signerConfig.SetOptions(options.get()); @@ -268,7 +268,7 @@ HWTEST_F(SignElfTest, Sign005, testing::ext::TestSize.Level1) signerConfig.SetCompatibleVersion(9); std::map params; - SetParamsMap(params); + SetElfParamsMap(params); params["signCode"] = "0"; signerConfig.FillParameters(params); @@ -281,7 +281,7 @@ HWTEST_F(SignElfTest, Sign005, testing::ext::TestSize.Level1) signerConfig.SetSignatureAlgorithms(signatureAlgorithms); std::shared_ptr options = std::make_shared(); - SetOptions(options.get()); + SetElfOptions(options.get()); (*options)["signCode"] = "0"; signerConfig.SetOptions(options.get()); @@ -310,6 +310,5 @@ HWTEST_F(SignElfTest, GetCodeSignBlock001, testing::ext::TestSize.Level1) bool flag = object.GetCodeSignBlock(input, offset, inForm, profileContent, zip, ret); EXPECT_EQ(flag, false); } - } } diff --git a/hapsigntool_cpp_test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.cpp b/hapsigntool_cpp_test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.cpp index 37a1d00072cdcb0aeb8704f8503020215d4c9a83..4f8f4a931c23c515282c35f7c64c3ce9fe46dcfb 100644 --- a/hapsigntool_cpp_test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.cpp @@ -24,144 +24,144 @@ #include "verify_cert_openssl_utils.h" using namespace testing::ext; -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { +class VerifyCertOpensslUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void); -namespace { - class VerifyCertOpensslUtilsTest : public testing::Test { - public: - static void SetUpTestCase(void); + static void TearDownTestCase(void); - static void TearDownTestCase(void); + void SetUp(); - void SetUp(); + void TearDown(); +}; - void TearDown(); - }; - - void VerifyCertOpensslUtilsTest::SetUpTestCase(void) - { - } +void VerifyCertOpensslUtilsTest::SetUpTestCase(void) +{ +} - void VerifyCertOpensslUtilsTest::TearDownTestCase(void) - { - } - void VerifyCertOpensslUtilsTest::SetUp() - { - } +void VerifyCertOpensslUtilsTest::TearDownTestCase(void) +{ +} +void VerifyCertOpensslUtilsTest::SetUp() +{ +} - void VerifyCertOpensslUtilsTest::TearDown() - { - } +void VerifyCertOpensslUtilsTest::TearDown() +{ +} - /** - * @tc.name: Test GetSubjectFromX509 and GetIssuerFromX509 functions. - * @tc.desc: The static function will return false due to invalid input; - * @tc.type: FUNC - */ - HWTEST_F(VerifyCertOpensslUtilsTest, GetIssuerAndSubjectTest001, TestSize.Level1) - { - /* - * @tc.steps: step1. Use nullptr as input to test GetSubjectFromX509. - * @tc.expected: step1. The return is false. - */ - std::string subject; - ASSERT_FALSE(VerifyCertOpensslUtils::GetSubjectFromX509(nullptr, subject)); - /* - * @tc.steps: step2. Use nullptr as input to test GetIssuerFromX509. - * @tc.expected: step2. The return is false. - */ - std::string issuer; - ASSERT_FALSE(VerifyCertOpensslUtils::GetIssuerFromX509(nullptr, issuer)); - } +/** + * @tc.name: Test GetSubjectFromX509 and GetIssuerFromX509 functions. + * @tc.desc: The static function will return false due to invalid input; + * @tc.type: FUNC + */ +HWTEST_F(VerifyCertOpensslUtilsTest, GetIssuerAndSubjectTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. Use nullptr as input to test GetSubjectFromX509. + * @tc.expected: step1. The return is false. + */ + std::string subject; + ASSERT_FALSE(VerifyCertOpensslUtils::GetSubjectFromX509(nullptr, subject)); + /* + * @tc.steps: step2. Use nullptr as input to test GetIssuerFromX509. + * @tc.expected: step2. The return is false. + */ + std::string issuer; + ASSERT_FALSE(VerifyCertOpensslUtils::GetIssuerFromX509(nullptr, issuer)); +} - /** - * @tc.name: Test VerifyCertChainPeriodOfValidity function. - * @tc.desc: Verify whether the VerifyCertChainPeriodOfValidity function can verify validity - * period of a certificate chain. - * @tc.type: FUNC - */ - HWTEST_F(VerifyCertOpensslUtilsTest, VerifyCertChainPeriodOfValidityTest001, TestSize.Level1) - { - /* - * @tc.steps: step1. Input an empty certChain. - * @tc.expected: step1. The return is false. - */ - CertChain certsChain; - ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCertChainPeriodOfValidity(certsChain, nullptr)); - /* - * @tc.steps: step3. Input a signTime which out of period of validity. - * @tc.expected: step3. The return is false. - */ - ASN1_OCTET_STRING* asnString = ASN1_OCTET_STRING_new(); - ASSERT_TRUE(asnString != nullptr); - ASSERT_TRUE(ASN1_OCTET_STRING_set(asnString, reinterpret_cast(TEST_ANS_TIME.c_str()), - static_cast(TEST_ANS_TIME.size()))); - ASN1_TYPE* time = ASN1_TYPE_new(); - ASSERT_TRUE(time != nullptr); - ASN1_TYPE_set(time, V_ASN1_UTCTIME, asnString); - ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCertChainPeriodOfValidity(certsChain, time)); - /* - * @tc.steps: step4. Input a certChain with two nullptr. - * @tc.expected: step4. The return iis false. - */ - certsChain.clear(); - certsChain.push_back(nullptr); - certsChain.push_back(nullptr); - ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCertChainPeriodOfValidity(certsChain, time)); - ASN1_TYPE_free(time); - } +/** + * @tc.name: Test VerifyCertChainPeriodOfValidity function. + * @tc.desc: Verify whether the VerifyCertChainPeriodOfValidity function can verify validity + * period of a certificate chain. + * @tc.type: FUNC + */ +HWTEST_F(VerifyCertOpensslUtilsTest, VerifyCertChainPeriodOfValidityTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. Input an empty certChain. + * @tc.expected: step1. The return is false. + */ + CertChain certsChain; + ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCertChainPeriodOfValidity(certsChain, nullptr)); + /* + * @tc.steps: step3. Input a signTime which out of period of validity. + * @tc.expected: step3. The return is false. + */ + ASN1_OCTET_STRING* asnString = ASN1_OCTET_STRING_new(); + ASSERT_TRUE(asnString != nullptr); + ASSERT_TRUE(ASN1_OCTET_STRING_set(asnString, reinterpret_cast(TEST_ANS_TIME.c_str()), + static_cast(TEST_ANS_TIME.size()))); + ASN1_TYPE* time = ASN1_TYPE_new(); + ASSERT_TRUE(time != nullptr); + ASN1_TYPE_set(time, V_ASN1_UTCTIME, asnString); + ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCertChainPeriodOfValidity(certsChain, time)); + /* + * @tc.steps: step4. Input a certChain with two nullptr. + * @tc.expected: step4. The return iis false. + */ + certsChain.clear(); + certsChain.push_back(nullptr); + certsChain.push_back(nullptr); + ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCertChainPeriodOfValidity(certsChain, time)); + ASN1_TYPE_free(time); +} - /** - * @tc.name: Test VerifyCrl function. - * @tc.desc: Verify whether the VerifyCrl function can verify a crl. - * @tc.type: FUNC - */ - HWTEST_F(VerifyCertOpensslUtilsTest, VerifyCrlTest001, TestSize.Level1) - { - /* - * @tc.steps: step1. Input an empty certChain. - * @tc.expected: step1. The return is false. - */ - CertChain certsChain; - Pkcs7Context pkcs7Context; - VerifyCertOpensslUtils::VerifyCrl(certsChain, nullptr, pkcs7Context); - /* - * @tc.steps: step2. Input a certChain with two nullptr. - * @tc.expected: step2. the return is false. - */ - STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); - certsChain.push_back(nullptr); - certsChain.push_back(nullptr); - VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context); - /* - * @tc.steps: step5. Input right certChain and crls. - * @tc.expected: step5. The return is true. - */ - certsChain.clear(); - ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context)); - sk_X509_CRL_pop_free(crls, X509_CRL_free); - } +/** + * @tc.name: Test VerifyCrl function. + * @tc.desc: Verify whether the VerifyCrl function can verify a crl. + * @tc.type: FUNC + */ +HWTEST_F(VerifyCertOpensslUtilsTest, VerifyCrlTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. Input an empty certChain. + * @tc.expected: step1. The return is false. + */ + CertChain certsChain; + Pkcs7Context pkcs7Context; + VerifyCertOpensslUtils::VerifyCrl(certsChain, nullptr, pkcs7Context); + /* + * @tc.steps: step2. Input a certChain with two nullptr. + * @tc.expected: step2. the return is false. + */ + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + certsChain.push_back(nullptr); + certsChain.push_back(nullptr); + VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context); + /* + * @tc.steps: step5. Input right certChain and crls. + * @tc.expected: step5. The return is true. + */ + certsChain.clear(); + ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context)); + sk_X509_CRL_pop_free(crls, X509_CRL_free); +} - /** - * @tc.name: Test private function - * @tc.desc: The static function will return result of invalid input; - * @tc.type: FUNC - */ - HWTEST_F(VerifyCertOpensslUtilsTest, PrivateFuncInvalidInputTest001, TestSize.Level1) - { - /* - * @tc.steps: step1. Use invalid input. - * @tc.expected: step1. The return is false. - */ - CertSign certVisitSign; - VerifyCertOpensslUtils::GenerateCertSignFromCertStack(nullptr, certVisitSign); - ASSERT_TRUE(VerifyCertOpensslUtils::FindCertOfIssuer(nullptr, certVisitSign) == nullptr); - std::string str = VerifyCertOpensslUtils::GetDnToString(nullptr); - ASSERT_FALSE(str.size() > 0); - ASSERT_TRUE(VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(nullptr, nullptr) == nullptr); - ASSERT_FALSE(VerifyCertOpensslUtils::X509NameCompare(nullptr, nullptr)); - ASSERT_FALSE(VerifyCertOpensslUtils::CheckSignTimeInValidPeriod(nullptr, nullptr, nullptr)); - ASSERT_FALSE(VerifyCertOpensslUtils::CheckAsn1TimeIsValid(nullptr)); - ASSERT_FALSE(VerifyCertOpensslUtils::CheckAsn1TypeIsValid(nullptr)); - } +/** + * @tc.name: Test private function + * @tc.desc: The static function will return result of invalid input; + * @tc.type: FUNC + */ +HWTEST_F(VerifyCertOpensslUtilsTest, PrivateFuncInvalidInputTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. Use invalid input. + * @tc.expected: step1. The return is false. + */ + CertSign certVisitSign; + VerifyCertOpensslUtils::GenerateCertSignFromCertStack(nullptr, certVisitSign); + ASSERT_TRUE(VerifyCertOpensslUtils::FindCertOfIssuer(nullptr, certVisitSign) == nullptr); + std::string str = VerifyCertOpensslUtils::GetDnToString(nullptr); + ASSERT_FALSE(str.size() > 0); + ASSERT_TRUE(VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(nullptr, nullptr) == nullptr); + ASSERT_FALSE(VerifyCertOpensslUtils::X509NameCompare(nullptr, nullptr)); + ASSERT_FALSE(VerifyCertOpensslUtils::CheckSignTimeInValidPeriod(nullptr, nullptr, nullptr)); + ASSERT_FALSE(VerifyCertOpensslUtils::CheckAsn1TimeIsValid(nullptr)); + ASSERT_FALSE(VerifyCertOpensslUtils::CheckAsn1TypeIsValid(nullptr)); } +} // namespace SignatureTools +} // namespace OHOS diff --git a/hapsigntool_cpp_test/unittest/hapVerify/hap_signer_block_utils_test.cpp b/hapsigntool_cpp_test/unittest/hapVerify/hap_signer_block_utils_test.cpp index 01c76b1a77f6fbc12e4ee9804db6eb497c7213f0..afdbbde47d97750b517e3666f2d90487c02f36e7 100644 --- a/hapsigntool_cpp_test/unittest/hapVerify/hap_signer_block_utils_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapVerify/hap_signer_block_utils_test.cpp @@ -24,7 +24,6 @@ #include "hap_signer_block_utils_test.h" using namespace testing::ext; -using namespace OHOS::SignatureTools; namespace OHOS { namespace SignatureTools { @@ -96,10 +95,45 @@ int64_t CreatTestZipFile(const std::string& pathFile, SignatureInfo& signInfo) sizeof(centralDirOffset) + sizeof(magic) + sizeof(eocdCommentLen); return sumLen; } -} // namespace SignatureTools -} // namespace OHOS -namespace { +int SetTestSignerInfoSignAlgor(PKCS7_SIGNER_INFO* info) +{ + int signNid = 0; + int hashNid = 0; + X509_ALGOR* dig; + X509_ALGOR* sig; + PKCS7_SIGNER_INFO_get0_algs(info, NULL, &dig, &sig); + if (dig == NULL || dig->algorithm == NULL || + (hashNid = OBJ_obj2nid(dig->algorithm)) == NID_undef || + !OBJ_find_sigid_by_algs(&signNid, hashNid, NID_X9_62_id_ecPublicKey) || + X509_ALGOR_set0(sig, OBJ_nid2obj(signNid), V_ASN1_UNDEF, 0) != 1) { + return 0; + } + return 1; +} + +int Pkcs7TestSetSignerInfo(PKCS7_SIGNER_INFO* info, X509* cert, const EVP_MD* hash) +{ + if (!ASN1_INTEGER_set(info->version, 1) || + !X509_NAME_set(&info->issuer_and_serial->issuer, X509_get_issuer_name(cert))) { + return 0; + } + + ASN1_INTEGER_free(info->issuer_and_serial->serial); + if (!(info->issuer_and_serial->serial = + ASN1_INTEGER_dup(X509_get_serialNumber(cert)))) { + return 0; + } + + X509_ALGOR_set0(info->digest_alg, OBJ_nid2obj(EVP_MD_type(hash)), + V_ASN1_NULL, NULL); + + if (!SetTestSignerInfoSignAlgor(info)) { + return 0; + } + return 1; +} + const std::string HAP_VERIFY_V2_PATH = "./hapVerify/hap_verify_v2.hap"; const std::string HAP_VERIFY_V3_PATH = "./hapVerify/hap_verify_v3.hap"; class HapSignerBlockUtilsTest : public testing::Test { @@ -521,4 +555,89 @@ HWTEST_F(HapSignerBlockUtilsTest, VerifyHapIntegrityTest001, TestSize.Level1) ASSERT_FALSE(HapSignerBlockUtils::VerifyHapIntegrity(digestInfo, hapTestFile, signInfo)); } -} // namespace \ No newline at end of file + +/** + * @tc.name: VerifyHapError001 + * @tc.desc: This function tests failure for interface GetCertsChain due to PKCS7_SIGNER_INFO have not cert + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, VerifyHapError001, TestSize.Level1) +{ + PKCS7* pkcs7 = PKCS7_new(); + X509* cert = X509_new(); + PKCS7_set_type(pkcs7, NID_pkcs7_signed); + PKCS7_content_new(pkcs7, NID_pkcs7_data); + const EVP_MD* md = EVP_sha384(); + PKCS7_SIGNER_INFO* info = PKCS7_SIGNER_INFO_new(); + Pkcs7TestSetSignerInfo(info, cert, md); + PKCS7_add_signer(pkcs7, info); + Pkcs7Context pkcs7Context; + bool ret = VerifyHapOpensslUtils::GetCertChains(pkcs7, pkcs7Context); + EXPECT_EQ(ret, false); + PKCS7_free(pkcs7); + X509_free(cert); +} + +/** + * @tc.name: VerifyHapError002 + * @tc.desc: This function tests failure for interface GetCrlStack due to pkcs7 not init + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, VerifyHapError002, TestSize.Level1) +{ + PKCS7* pkcs7 = PKCS7_new(); + bool ret = VerifyHapOpensslUtils::GetCrlStack(pkcs7, nullptr); + EXPECT_EQ(ret, false); + PKCS7_free(pkcs7); +} + +/** + * @tc.name: VerifyHapError003 + * @tc.desc: This function tests failure for interface VerifyPkcs7 due to cert1 not init + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, VerifyHapError003, TestSize.Level1) +{ + PKCS7* pkcs7 = PKCS7_new(); + X509* cert = X509_new(); + PKCS7_set_type(pkcs7, NID_pkcs7_signed); + PKCS7_content_new(pkcs7, NID_pkcs7_data); + const EVP_MD* md = EVP_sha384(); + PKCS7_SIGNER_INFO* info = PKCS7_SIGNER_INFO_new(); + Pkcs7TestSetSignerInfo(info, cert, md); + char* t = new char[2]; + t[0] = 1; + t[1] = 2; + ASN1_STRING_set0(info->enc_digest, t, 2); + PKCS7_add_signer(pkcs7, info); + Pkcs7Context pkcs7Context; + pkcs7Context.p7 = pkcs7; + CertChain certs; + X509* cert1 = X509_new(); + certs.push_back(cert1); + pkcs7Context.certChain.push_back(certs); + bool ret = VerifyHapOpensslUtils::VerifyPkcs7(pkcs7Context); + EXPECT_EQ(ret, false); + X509_free(cert); + X509_free(cert1); +} + +/** + * @tc.name: VerifyHapError004 + * @tc.desc: This function tests failure for interface ParsePkcs7Package due to cert1 not init + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, VerifyHapError004, TestSize.Level1) +{ + PKCS7* pkcs7 = PKCS7_new(); + PKCS7_set_type(pkcs7, NID_pkcs7_signed); + PKCS7_content_new(pkcs7, NID_pkcs7_data); + unsigned char* p = nullptr; + int len = i2d_PKCS7(pkcs7, &p); + Pkcs7Context pkcs7Context; + bool ret = VerifyHapOpensslUtils::ParsePkcs7Package(p, len, pkcs7Context); + EXPECT_EQ(ret, false); + PKCS7_free(pkcs7); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/hapVerify/hap_verify_test.cpp b/hapsigntool_cpp_test/unittest/hapVerify/hap_verify_test.cpp index 2d85dce2f9953d22f7dc52b6a2b06104fd1a8977..ee6e9b91f0e22876120fc942831be1e743e1caa7 100644 --- a/hapsigntool_cpp_test/unittest/hapVerify/hap_verify_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapVerify/hap_verify_test.cpp @@ -32,6 +32,8 @@ #include "options.h" #include "signature_tools_errno.h" #include "hap_utils.h" +#include "cert_dn_utils.h" +#include "signer_config.h" using namespace testing::ext; @@ -909,5 +911,160 @@ HWTEST_F(VerifyHapTest, VerifyHapError019, TestSize.Level0) EXPECT_EQ(ret, ""); } + +/** + * @tc.name: VerifyHapError021 + * @tc.desc: This function tests failure for interface GetCertsChain due to certsChain and certVisitSign are empty + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError021, TestSize.Level0) +{ + CertSign certVisitSign; + CertChain certsChain; + STACK_OF(X509)* certs = sk_X509_new_null(); + sk_X509_push(certs, nullptr); + CertSign certVisitSign1; + VerifyCertOpensslUtils::GenerateCertSignFromCertStack(certs, certVisitSign1); + sk_X509_pop_free(certs, X509_free); + bool ret = VerifyCertOpensslUtils::GetCertsChain(certsChain, certVisitSign); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapError022 + * @tc.desc: This function tests failure for interface GetCertsChain due to certVisitSign is empty + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError022, TestSize.Level0) +{ + CertSign certVisitSign; + CertChain certsChain; + certsChain.push_back(nullptr); + bool ret = VerifyCertOpensslUtils::GetCertsChain(certsChain, certVisitSign); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapError023 + * @tc.desc: This function tests failure for interface GetCrlBySignedCertIssuer due to crls is empty + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError023, TestSize.Level0) +{ + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + X509* cert = X509_new(); + X509_CRL* ret = VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(crls, cert); + EXPECT_EQ(ret, nullptr); + sk_X509_CRL_pop_free(crls, X509_CRL_free); + X509_free(cert); +} + +/** + * @tc.name: VerifyHapError024 + * @tc.desc: This function tests failure for interface GetCrlBySignedCertIssuer due to crls all empty element + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError024, TestSize.Level0) +{ + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + sk_X509_CRL_push(crls, nullptr); + X509* cert = X509_new(); + X509_CRL* ret = VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(crls, cert); + EXPECT_EQ(ret, nullptr); + sk_X509_CRL_pop_free(crls, X509_CRL_free); + X509_free(cert); +} + +/** + * @tc.name: VerifyHapError025 + * @tc.desc: This function tests success for interface GetCrlBySignedCertIssuer + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError025, TestSize.Level0) +{ + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + sk_X509_CRL_push(crls, X509_CRL_new()); + X509* cert = X509_new(); + X509_CRL* ret = VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(crls, cert); + EXPECT_NE(ret, nullptr); + sk_X509_CRL_pop_free(crls, X509_CRL_free); + X509_free(cert); +} + +/** + * @tc.name: VerifyHapError026 + * @tc.desc: This function tests failed for interface GetCrlBySignedCertIssuer dut issuer name different + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError026, TestSize.Level0) +{ + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + sk_X509_CRL_push(crls, X509_CRL_new()); + X509* cert = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_issuer_name(cert, subName); + X509_CRL* ret = VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(crls, cert); + EXPECT_EQ(ret, nullptr); + sk_X509_CRL_pop_free(crls, X509_CRL_free); + X509_free(cert); +} + +/** + * @tc.name: VerifyHapError027 + * @tc.desc: This function tests failed for interface VerifyCrl dut certsChain no have public key + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError027, TestSize.Level0) +{ + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + sk_X509_CRL_push(crls, X509_CRL_new()); + X509* cert = X509_new(); + X509* cert1 = X509_new(); + CertChain certsChain; + certsChain.push_back(cert); + certsChain.push_back(cert1); + Pkcs7Context pkcs7Context; + bool ret = VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context); + EXPECT_EQ(ret, false); + SignerConfig config; + config.SetX509CRLs(crls); + X509_free(cert); + X509_free(cert1); +} + +/** + * @tc.name: VerifyHapError028 + * @tc.desc: This function tests failed for interface outputOptionalBlocks dut errorfile is not exit + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError028, TestSize.Level0) +{ + std::string outputProfileFile = "outputProfileFile.txt"; + std::string outputProofFile = "outputProfileFile.txt"; + std::string outputPropertyFile = "outputProfileFile.txt"; + std::string errorfile = "./nohave/path.txt"; + ByteBuffer bf1("123456789", 9); + ByteBuffer bf2("123456789", 9); + ByteBuffer bf3("123456789", 9); + std::vector optionBlocks; + optionBlocks.push_back({ HapUtils::HAP_PROFILE_BLOCK_ID, bf1 }); + optionBlocks.push_back({ HapUtils::HAP_PROPERTY_BLOCK_ID, bf2 }); + optionBlocks.push_back({ HapUtils::HAP_PROOF_OF_ROTATION_BLOCK_ID, bf3 }); + ProfileInfo info1; + ProfileInfo info2(info1); + ProfileInfo info3; + info1.profileBlockLength = 1; + info1.profileBlock = std::make_unique(2); + info3 = info1; + VerifyHap verify; + bool resultCode = verify.outputOptionalBlocks(errorfile, outputProofFile, outputPropertyFile, optionBlocks); + EXPECT_EQ(resultCode, false); + resultCode = verify.outputOptionalBlocks(outputProfileFile, errorfile, outputPropertyFile, optionBlocks); + EXPECT_EQ(resultCode, false); + resultCode = verify.outputOptionalBlocks(outputProfileFile, outputProofFile, errorfile, optionBlocks); + EXPECT_EQ(resultCode, false); +} } } diff --git a/hapsigntool_cpp_test/unittest/hapVerify/provision_verify_test.cpp b/hapsigntool_cpp_test/unittest/hapVerify/provision_verify_test.cpp index 22da37231feda59059cb97886c93a368c9d21a7a..f3c0723b2e7f9f32ca99d924ef9d1aa5d64e5baa 100644 --- a/hapsigntool_cpp_test/unittest/hapVerify/provision_verify_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapVerify/provision_verify_test.cpp @@ -18,267 +18,266 @@ #include "profile_verify.h" using namespace testing::ext; -using namespace OHOS::SignatureTools; - -namespace { - const std::string INVALID_PROVISION_1 = R"( - { - "version-name": "1.0.0", - "issuer": "App Gallery" - })"; - const std::string INVALID_PROVISION_2 = R"( - { - "version-code": 2, - "version-name": "1.1.0", - "uuid": "uuid_1_1", - "type": "release", - "app-distribution-type": "os_integration", - "validity": { - "not-before": 1262275201, - "not-after": 2524579301 - }, - "bundle-info": { - "developer-id": "developer_id_1_1", - "development-certificate": "ABCD", - "distribution-certificate": "1234", - "bundle-name": "com.test1_1", - "apl": "normal", - "app-feature": "hos_normal_app" - } - }})"; // brackets mismatching - const std::string INVALID_PROVISION_3 = R"( - { - "version-code": 2, - "version-name": "2.0.0", - "uuid": "uuid_2", - "type": "release", - "app-distribution-type": "os_integration", - "validity": { - "not-before": 1262275200, - "not-after": 2524579300 - }, - "bundle-info": { - "developer-id": "developer_id_2", - "development-certificate": "ABCDEFG", - "distribution-certificate": "123456789", - "bundle-name": "com.test2", - "app-feature": "hos_normal_app" - } - })"; // apl not exist - /* validity: 2010 - 2030 */ - const std::string VALID_PROVISION = R"( - { - "version-code": 2, - "version-name": "2.0.0", - "uuid": "uuid_2", - "type": "release", - "app-distribution-type": "os_integration", - "validity": { - "not-before": 1262275200, - "not-after": 2524579300 - }, - "bundle-info": { - "developer-id": "developer_id_2", - "development-certificate": "ABCDEFG", - "distribution-certificate": "123456789", - "bundle-name": "com.test2", - "apl": "normal", - "app-feature": "hos_normal_app" - } - })"; - const std::string VALID_PROVISION_PERMISSION = R"( - { - "version-code": 3, - "version-name": "3.0.0", - "uuid": "uuid_3", - "type": "release", - "app-distribution-type": "app_gallery", - "validity": { - "not-before": 1262275300, - "not-after": 2524579300 - }, - "bundle-info": { - "developer-id": "developer_id_3", - "development-certificate": "ABCDEFGH", - "distribution-certificate": "1234567890", - "bundle-name": "com.test3", - "apl": "normal", - "app-feature": "hos_normal_app" - }, - "permissions" : { - "restricted-permissions" : ["ohos.permission.GET_PHONE_STATE", - "ohos.permission.GET_APP_ACCOUNTS"], - "restricted-capabilities" : ["ohos.permission.test"] - }, - "issuer": "App Gallery" - })"; - const std::string UNAUTHORIZED_DEVICE_EMPTY_DEVICE_LIST_PROVISION = R"( - { - "version-code": 6, - "version-name": "6.0.0", - "uuid": "uuid_6", - "type": "debug", - "validity": { - "not-before": 1262275600, - "not-after": 2524579300 - }, - "bundle-info": { - "developer-id": "developer_id_6", - "development-certificate": "ABCDEFGHIJ", - "distribution-certificate": "1234567890123", - "bundle-name": "com.test6", - "apl": "normal", - "app-feature": "hos_normal_app" - }, - "debug-info": { - "device-id-type": "udid" - }, - "issuer": "App Gallery" - })"; - const std::string UNSUPPORTED_DEVICE_TYPE_PROVISION = R"( - { - "version-code": 7, - "version-name": "7.0.0", - "uuid": "uuid_7", - "type": "debug", - "validity": { - "not-before": 1262275600, - "not-after": 2524579300 - }, - "bundle-info": { - "developer-id": "developer_id_7", - "development-certificate": "ABCDEFGHIJM", - "distribution-certificate": "12345678901231", - "bundle-name": "com.test7", - "apl": "normal", - "app-feature": "hos_normal_app" - }, - "debug-info": { - "device-id-type": "unknownType", - "device-ids" : ["1234ABCD"] - }, - "issuer": "App Gallery" - })"; - const std::string DEVICE_UNAUTH_PROVISION = R"( - { - "version-code": 8, - "version-name": "8.0.0", - "uuid": "uuid_8", - "type": "debug", - "validity": { - "not-before": 1262275700, - "not-after": 2524579300 - }, - "bundle-info": { - "developer-id": "developer_id_8", - "development-certificate": "ABCDEFGHIJK", - "distribution-certificate": "12345678901234", - "bundle-name": "com.test8", - "apl": "normal", - "app-feature": "hos_normal_app" - }, - "debug-info": { - "device-id-type": "udid", - "device-ids" : ["1234ABCD"] - }, - "issuer": "App Gallery" - })"; +namespace OHOS { +namespace SignatureTools { +const std::string INVALID_PROVISION_1 = R"( +{ + "version-name": "1.0.0", + "issuer": "App Gallery" +})"; +const std::string INVALID_PROVISION_2 = R"( +{ + "version-code": 2, + "version-name": "1.1.0", + "uuid": "uuid_1_1", + "type": "release", + "app-distribution-type": "os_integration", + "validity": { + "not-before": 1262275201, + "not-after": 2524579301 + }, + "bundle-info": { + "developer-id": "developer_id_1_1", + "development-certificate": "ABCD", + "distribution-certificate": "1234", + "bundle-name": "com.test1_1", + "apl": "normal", + "app-feature": "hos_normal_app" + } +}})"; // brackets mismatching +const std::string INVALID_PROVISION_3 = R"( +{ + "version-code": 2, + "version-name": "2.0.0", + "uuid": "uuid_2", + "type": "release", + "app-distribution-type": "os_integration", + "validity": { + "not-before": 1262275200, + "not-after": 2524579300 + }, + "bundle-info": { + "developer-id": "developer_id_2", + "development-certificate": "ABCDEFG", + "distribution-certificate": "123456789", + "bundle-name": "com.test2", + "app-feature": "hos_normal_app" + } +})"; // apl not exist +/* validity: 2010 - 2030 */ +const std::string VALID_PROVISION = R"( +{ + "version-code": 2, + "version-name": "2.0.0", + "uuid": "uuid_2", + "type": "release", + "app-distribution-type": "os_integration", + "validity": { + "not-before": 1262275200, + "not-after": 2524579300 + }, + "bundle-info": { + "developer-id": "developer_id_2", + "development-certificate": "ABCDEFG", + "distribution-certificate": "123456789", + "bundle-name": "com.test2", + "apl": "normal", + "app-feature": "hos_normal_app" + } +})"; +const std::string VALID_PROVISION_PERMISSION = R"( +{ + "version-code": 3, + "version-name": "3.0.0", + "uuid": "uuid_3", + "type": "release", + "app-distribution-type": "app_gallery", + "validity": { + "not-before": 1262275300, + "not-after": 2524579300 + }, + "bundle-info": { + "developer-id": "developer_id_3", + "development-certificate": "ABCDEFGH", + "distribution-certificate": "1234567890", + "bundle-name": "com.test3", + "apl": "normal", + "app-feature": "hos_normal_app" + }, + "permissions" : { + "restricted-permissions" : ["ohos.permission.GET_PHONE_STATE", + "ohos.permission.GET_APP_ACCOUNTS"], + "restricted-capabilities" : ["ohos.permission.test"] + }, + "issuer": "App Gallery" +})"; +const std::string UNAUTHORIZED_DEVICE_EMPTY_DEVICE_LIST_PROVISION = R"( +{ + "version-code": 6, + "version-name": "6.0.0", + "uuid": "uuid_6", + "type": "debug", + "validity": { + "not-before": 1262275600, + "not-after": 2524579300 + }, + "bundle-info": { + "developer-id": "developer_id_6", + "development-certificate": "ABCDEFGHIJ", + "distribution-certificate": "1234567890123", + "bundle-name": "com.test6", + "apl": "normal", + "app-feature": "hos_normal_app" + }, + "debug-info": { + "device-id-type": "udid" + }, + "issuer": "App Gallery" +})"; +const std::string UNSUPPORTED_DEVICE_TYPE_PROVISION = R"( +{ + "version-code": 7, + "version-name": "7.0.0", + "uuid": "uuid_7", + "type": "debug", + "validity": { + "not-before": 1262275600, + "not-after": 2524579300 + }, + "bundle-info": { + "developer-id": "developer_id_7", + "development-certificate": "ABCDEFGHIJM", + "distribution-certificate": "12345678901231", + "bundle-name": "com.test7", + "apl": "normal", + "app-feature": "hos_normal_app" + }, + "debug-info": { + "device-id-type": "unknownType", + "device-ids" : ["1234ABCD"] + }, + "issuer": "App Gallery" +})"; +const std::string DEVICE_UNAUTH_PROVISION = R"( +{ + "version-code": 8, + "version-name": "8.0.0", + "uuid": "uuid_8", + "type": "debug", + "validity": { + "not-before": 1262275700, + "not-after": 2524579300 + }, + "bundle-info": { + "developer-id": "developer_id_8", + "development-certificate": "ABCDEFGHIJK", + "distribution-certificate": "12345678901234", + "bundle-name": "com.test8", + "apl": "normal", + "app-feature": "hos_normal_app" + }, + "debug-info": { + "device-id-type": "udid", + "device-ids" : ["1234ABCD"] + }, + "issuer": "App Gallery" +})"; - class ProvisionVerifyTest : public testing::Test { - public: - static void SetUpTestCase(void); +class ProvisionVerifyTest : public testing::Test { +public: + static void SetUpTestCase(void); - static void TearDownTestCase(void); + static void TearDownTestCase(void); - void SetUp(); + void SetUp(); - void TearDown(); - }; + void TearDown(); +}; - void ProvisionVerifyTest::SetUpTestCase(void) - { - } +void ProvisionVerifyTest::SetUpTestCase(void) +{ +} - void ProvisionVerifyTest::TearDownTestCase(void) - { - } +void ProvisionVerifyTest::TearDownTestCase(void) +{ +} - void ProvisionVerifyTest::SetUp() - { - } +void ProvisionVerifyTest::SetUp() +{ +} - void ProvisionVerifyTest::TearDown() - { - } +void ProvisionVerifyTest::TearDown() +{ +} - /** - * @tc.name: Test HarmonyAppProvision ProvisionVerify001 function - * @tc.desc: The static function will return verify result; - * @tc.type: FUNC - */ - HWTEST_F(ProvisionVerifyTest, ProvisionVerify001, TestSize.Level1) - { - /* - * @tc.steps: step1. input a invalid HarmonyAppProvision - * and run ParseAndVerify function. - * @tc.expected: step1. return code will be PROVISION_INVALID. - */ - ProfileInfo info; - int32_t ret = ParseAndVerify(INVALID_PROVISION_1, info); - ASSERT_NE(ret, AppProvisionVerifyResult::PROVISION_OK); - ret = ParseAndVerify(INVALID_PROVISION_2, info); - ASSERT_NE(ret, AppProvisionVerifyResult::PROVISION_OK); - ret = ParseAndVerify(INVALID_PROVISION_3, info); - ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); - } - - /** - * @tc.name: Test HarmonyAppProvision ProvisionVerify002 function - * @tc.desc: The static function will return verify result; - * @tc.type: FUNC - */ - HWTEST_F(ProvisionVerifyTest, ProvisionVerify002, TestSize.Level1) - { - /* - * @tc.steps: step2. input a valid HarmonyAppProvision (without permission info) - * and run ParseAndVerify function. - * @tc.expected: step2. return code will be PROVISION_OK. - */ - ProfileInfo info; - int32_t ret = ParseAndVerify(VALID_PROVISION, info); - ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); - ASSERT_EQ(info.versionCode, 2); // version code is 2 - ASSERT_EQ(info.versionName, "2.0.0"); - ASSERT_EQ(info.uuid, "uuid_2"); - ASSERT_EQ(info.type, ProvisionType::RELEASE); - ASSERT_TRUE(info.permissions.restrictedPermissions.empty()); - ASSERT_TRUE(info.permissions.restrictedCapabilities.empty()); - } +/** + * @tc.name: Test HarmonyAppProvision ProvisionVerify001 function + * @tc.desc: The static function will return verify result; + * @tc.type: FUNC + */ +HWTEST_F(ProvisionVerifyTest, ProvisionVerify001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input a invalid HarmonyAppProvision + * and run ParseAndVerify function. + * @tc.expected: step1. return code will be PROVISION_INVALID. + */ + ProfileInfo info; + int32_t ret = ParseAndVerify(INVALID_PROVISION_1, info); + ASSERT_NE(ret, AppProvisionVerifyResult::PROVISION_OK); + ret = ParseAndVerify(INVALID_PROVISION_2, info); + ASSERT_NE(ret, AppProvisionVerifyResult::PROVISION_OK); + ret = ParseAndVerify(INVALID_PROVISION_3, info); + ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); +} - /** - * @tc.name: Test HarmonyAppProvision ProvisionVerify003 function - * @tc.desc: The static function will return verify result; - * @tc.type: FUNC - */ - HWTEST_F(ProvisionVerifyTest, ProvisionVerify003, TestSize.Level1) - { - /* - * @tc.steps: step3. input a valid HarmonyAppProvision (with permission info) - * and run ParseAndVerify function. - * @tc.expected: step3. return code will be PROVISION_OK. - */ - ProfileInfo info; - int32_t ret = ParseAndVerify(VALID_PROVISION_PERMISSION, info); - ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); - ASSERT_EQ(info.versionCode, 3); // version code is 3 - ASSERT_EQ(info.versionName, "3.0.0"); - ASSERT_EQ(info.uuid, "uuid_3"); - ASSERT_EQ(info.type, ProvisionType::RELEASE); - ASSERT_EQ(info.distributionType, AppDistType::APP_GALLERY); - ASSERT_TRUE(info.permissions.restrictedPermissions.size() == 2); // 2 restricted permissions - ASSERT_EQ(info.permissions.restrictedPermissions[0], "ohos.permission.GET_PHONE_STATE"); - ASSERT_TRUE(info.permissions.restrictedCapabilities.size() == 1); // 1 restricted capabilities - ASSERT_EQ(info.permissions.restrictedCapabilities[0], "ohos.permission.test"); - } +/** + * @tc.name: Test HarmonyAppProvision ProvisionVerify002 function + * @tc.desc: The static function will return verify result; + * @tc.type: FUNC + */ +HWTEST_F(ProvisionVerifyTest, ProvisionVerify002, TestSize.Level1) +{ + /* + * @tc.steps: step2. input a valid HarmonyAppProvision (without permission info) + * and run ParseAndVerify function. + * @tc.expected: step2. return code will be PROVISION_OK. + */ + ProfileInfo info; + int32_t ret = ParseAndVerify(VALID_PROVISION, info); + ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); + ASSERT_EQ(info.versionCode, 2); // version code is 2 + ASSERT_EQ(info.versionName, "2.0.0"); + ASSERT_EQ(info.uuid, "uuid_2"); + ASSERT_EQ(info.type, ProvisionType::RELEASE); + ASSERT_TRUE(info.permissions.restrictedPermissions.empty()); + ASSERT_TRUE(info.permissions.restrictedCapabilities.empty()); +} -} // namespace +/** + * @tc.name: Test HarmonyAppProvision ProvisionVerify003 function + * @tc.desc: The static function will return verify result; + * @tc.type: FUNC + */ +HWTEST_F(ProvisionVerifyTest, ProvisionVerify003, TestSize.Level1) +{ + /* + * @tc.steps: step3. input a valid HarmonyAppProvision (with permission info) + * and run ParseAndVerify function. + * @tc.expected: step3. return code will be PROVISION_OK. + */ + ProfileInfo info; + int32_t ret = ParseAndVerify(VALID_PROVISION_PERMISSION, info); + ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); + ASSERT_EQ(info.versionCode, 3); // version code is 3 + ASSERT_EQ(info.versionName, "3.0.0"); + ASSERT_EQ(info.uuid, "uuid_3"); + ASSERT_EQ(info.type, ProvisionType::RELEASE); + ASSERT_EQ(info.distributionType, AppDistType::APP_GALLERY); + ASSERT_TRUE(info.permissions.restrictedPermissions.size() == 2); // 2 restricted permissions + ASSERT_EQ(info.permissions.restrictedPermissions[0], "ohos.permission.GET_PHONE_STATE"); + ASSERT_TRUE(info.permissions.restrictedCapabilities.size() == 1); // 1 restricted capabilities + ASSERT_EQ(info.permissions.restrictedCapabilities[0], "ohos.permission.test"); +} +} // namespace SignatureTools +} // namespace OHOS diff --git a/hapsigntool_cpp_test/unittest/hapVerify/random_access_file_test.cpp b/hapsigntool_cpp_test/unittest/hapVerify/random_access_file_test.cpp index 0bddfff95491ecfe0ded6dbb77154a3304b00ea8..9cf65cb2e7eb0d41ffaa53d0d3513da36ce8312b 100644 --- a/hapsigntool_cpp_test/unittest/hapVerify/random_access_file_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapVerify/random_access_file_test.cpp @@ -27,96 +27,96 @@ #include "test_const.h" using namespace testing::ext; -using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { +class RandomAccessFileTest : public testing::Test { +public: + static void SetUpTestCase(void); -namespace { - class RandomAccessFileTest : public testing::Test { - public: - static void SetUpTestCase(void); + static void TearDownTestCase(void); - static void TearDownTestCase(void); + void SetUp(); - void SetUp(); + void TearDown(); +}; - void TearDown(); - }; - - void RandomAccessFileTest::SetUpTestCase(void) - { - } +void RandomAccessFileTest::SetUpTestCase(void) +{ +} - void RandomAccessFileTest::TearDownTestCase(void) - { - } +void RandomAccessFileTest::TearDownTestCase(void) +{ +} - void RandomAccessFileTest::SetUp() - { - } +void RandomAccessFileTest::SetUp() +{ +} - void RandomAccessFileTest::TearDown() - { - } +void RandomAccessFileTest::TearDown() +{ +} - /** - * @tc.name: Test ReadFileFullyFromOffset function - * @tc.desc: The static function will return each reading result; - * @tc.type: FUNC - */ - HWTEST_F(RandomAccessFileTest, ReadFileFullyFromOffsetTest001, TestSize.Level1) - { - /* - * @tc.steps: step1. use null buffer to ReadFileFullyFromOffset . - * @tc.expected: step1. the return will be DEST_BUFFER_IS_NULL. - */ - std::string filePath = "./hapVerify/test_hapverify.zip"; - SignatureInfo si0; - int64_t sumLen = HapSignerBlockUtils::CreatTestZipFile(filePath, si0); - RandomAccessFile hapTestFile1; - bool initRet = hapTestFile1.Init(filePath); - ASSERT_TRUE(initRet); - ASSERT_TRUE(hapTestFile1.GetLength() == sumLen); - ReadFileErrorCode targetCode = DEST_BUFFER_IS_NULL; - int32_t ret = hapTestFile1.ReadFileFullyFromOffset(nullptr, 0, 0); - ASSERT_TRUE(ret == targetCode); - ByteBuffer nullBuffer; - ret = hapTestFile1.ReadFileFullyFromOffset(nullBuffer, 0); - ASSERT_TRUE(ret == targetCode); - /* - * @tc.steps: step2. use a buffer to read a null file. - * @tc.expected: step2. the return will be FILE_IS_CLOSE. - */ - filePath = "./hapVerify/test_hapverify1.zip"; - RandomAccessFile nullTestFile; - initRet = nullTestFile.Init(filePath); - ASSERT_FALSE(initRet); - std::unique_ptr buffer = std::make_unique(TEST_RANDOMREAD_LENGTH); - ASSERT_TRUE(buffer != nullptr); - ret = nullTestFile.ReadFileFullyFromOffset(buffer.get(), 0, TEST_RANDOMREAD_LENGTH); - ASSERT_EQ(ret, FILE_IS_CLOSE); - /* - * @tc.steps: step3. use a large buffer to read a mini file. - * @tc.expected: step3. the return will be READ_DATA_NOT_ENOUGH. - */ - std::string testFile = "./hapVerify/test_hapverify.txt"; - SignatureInfo si; - sumLen = HapSignerBlockUtils::CreatTestZipFile(testFile, si); - RandomAccessFile hapTestFile2; - initRet = hapTestFile2.Init(testFile); - ASSERT_TRUE(initRet); - ASSERT_TRUE(hapTestFile2.GetLength() == sumLen); - ret = hapTestFile2.ReadFileFullyFromOffset(buffer.get(), 0, TEST_RANDOMREAD_LENGTH); - ASSERT_EQ(ret, READ_OFFSET_OUT_OF_RANGE); - ByteBuffer hapBuffer(TEST_RANDOMREAD_LENGTH); - ret = hapTestFile2.ReadFileFullyFromOffset(hapBuffer, 0); - ASSERT_EQ(ret, READ_OFFSET_OUT_OF_RANGE); - /* - * @tc.steps: step4. use a negative offset to read a file. - * @tc.expected: step4. the return will be READ_OFFSET_OUT_OF_RANGE. - */ - ret = hapTestFile2.ReadFileFullyFromOffset(hapBuffer, -1); - ASSERT_TRUE(ret == READ_OFFSET_OUT_OF_RANGE); - ret = hapTestFile2.ReadFileFullyFromOffset(buffer.get(), -1, TEST_RANDOMREAD_LENGTH); - ASSERT_TRUE(ret == READ_OFFSET_OUT_OF_RANGE); - buffer.reset(nullptr); - } +/** + * @tc.name: Test ReadFileFullyFromOffset function + * @tc.desc: The static function will return each reading result; + * @tc.type: FUNC + */ +HWTEST_F(RandomAccessFileTest, ReadFileFullyFromOffsetTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. use null buffer to ReadFileFullyFromOffset . + * @tc.expected: step1. the return will be DEST_BUFFER_IS_NULL. + */ + std::string filePath = "./hapVerify/test_hapverify.zip"; + SignatureInfo si0; + int64_t sumLen = HapSignerBlockUtils::CreatTestZipFile(filePath, si0); + RandomAccessFile hapTestFile1; + bool initRet = hapTestFile1.Init(filePath); + ASSERT_TRUE(initRet); + ASSERT_TRUE(hapTestFile1.GetLength() == sumLen); + ReadFileErrorCode targetCode = DEST_BUFFER_IS_NULL; + int32_t ret = hapTestFile1.ReadFileFullyFromOffset(nullptr, 0, 0); + ASSERT_TRUE(ret == targetCode); + ByteBuffer nullBuffer; + ret = hapTestFile1.ReadFileFullyFromOffset(nullBuffer, 0); + ASSERT_TRUE(ret == targetCode); + /* + * @tc.steps: step2. use a buffer to read a null file. + * @tc.expected: step2. the return will be FILE_IS_CLOSE. + */ + filePath = "./hapVerify/test_hapverify1.zip"; + RandomAccessFile nullTestFile; + initRet = nullTestFile.Init(filePath); + ASSERT_FALSE(initRet); + std::unique_ptr buffer = std::make_unique(TEST_RANDOMREAD_LENGTH); + ASSERT_TRUE(buffer != nullptr); + ret = nullTestFile.ReadFileFullyFromOffset(buffer.get(), 0, TEST_RANDOMREAD_LENGTH); + ASSERT_EQ(ret, FILE_IS_CLOSE); + /* + * @tc.steps: step3. use a large buffer to read a mini file. + * @tc.expected: step3. the return will be READ_DATA_NOT_ENOUGH. + */ + std::string testFile = "./hapVerify/test_hapverify.txt"; + SignatureInfo si; + sumLen = HapSignerBlockUtils::CreatTestZipFile(testFile, si); + RandomAccessFile hapTestFile2; + initRet = hapTestFile2.Init(testFile); + ASSERT_TRUE(initRet); + ASSERT_TRUE(hapTestFile2.GetLength() == sumLen); + ret = hapTestFile2.ReadFileFullyFromOffset(buffer.get(), 0, TEST_RANDOMREAD_LENGTH); + ASSERT_EQ(ret, READ_OFFSET_OUT_OF_RANGE); + ByteBuffer hapBuffer(TEST_RANDOMREAD_LENGTH); + ret = hapTestFile2.ReadFileFullyFromOffset(hapBuffer, 0); + ASSERT_EQ(ret, READ_OFFSET_OUT_OF_RANGE); + /* + * @tc.steps: step4. use a negative offset to read a file. + * @tc.expected: step4. the return will be READ_OFFSET_OUT_OF_RANGE. + */ + ret = hapTestFile2.ReadFileFullyFromOffset(hapBuffer, -1); + ASSERT_TRUE(ret == READ_OFFSET_OUT_OF_RANGE); + ret = hapTestFile2.ReadFileFullyFromOffset(buffer.get(), -1, TEST_RANDOMREAD_LENGTH); + ASSERT_TRUE(ret == READ_OFFSET_OUT_OF_RANGE); + buffer.reset(nullptr); } +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp_test/unittest/ohos_test.xml b/hapsigntool_cpp_test/unittest/ohos_test.xml index f69f0e4f87cee15a8259408de10d804fe545f7c9..d3f1ad0fe7b0358570c3486e4d08d2f81c76d152 100644 --- a/hapsigntool_cpp_test/unittest/ohos_test.xml +++ b/hapsigntool_cpp_test/unittest/ohos_test.xml @@ -124,6 +124,11 @@