diff --git a/hapsigntool_cpp/bundle.json b/hapsigntool_cpp/bundle.json index decf68af895587a4a21559bb48f55ac9368a1ac9..d9c5bf2cddaeb59ed057e2ac552e27909c546526 100644 --- a/hapsigntool_cpp/bundle.json +++ b/hapsigntool_cpp/bundle.json @@ -47,6 +47,8 @@ ], "inner_kits": [], "test": [ + "//developtools/hapsigner/hapsigntool_cpp/test/unittest:hapsigntool_pc_unittest", + "//developtools/hapsigner/hapsigntool_cpp/test/fuzztest:hapsigntool_pc_fuzztest" ] } } diff --git a/hapsigntool_cpp/test/.gitignore b/hapsigntool_cpp/test/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..259148fa18f9fb7ef58563f4ff15fc7b172339fb --- /dev/null +++ b/hapsigntool_cpp/test/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/hapsigntool_cpp/test/BUILD.gn b/hapsigntool_cpp/test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..39a731cdaa277cd0727d2ede092377259933f28d --- /dev/null +++ b/hapsigntool_cpp/test/BUILD.gn @@ -0,0 +1,101 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("../cmd/signature_tools_cmd.gni") +import("../codesigning/signature_tools_codesigning.gni") +import("../common/signature_tools_common.gni") +import("../hap/signature_tools_hap.gni") +import("../profile/signature_tools_profile.gni") +import("../utils/signature_tools_utils.gni") +import("../zip/signature_tools_zip.gni") +import("../signature_tools.gni") + +import("//build/ohos.gni") + +config("service_include") { + visibility = [ "*" ] + + include_dirs = [ + "//third_party/openssl/include", + "//third_party/openssl/crypto/pkcs12", + "${signature_tools_api}/include", + "${signature_tools_signer}/include", + ] + + include_dirs += signature_tools_utils_include + include_dirs += signature_tools_zip_include + include_dirs += signature_tools_codesigning_include + include_dirs += signature_tools_common_include + include_dirs += signature_tools_hap_include + include_dirs += signature_tools_profile_include + include_dirs += signature_tools_cmd_include + + defines = [ + "HI_LOG_ENABLE", + "SIGNATURE_LOG_TAG=\"Signature_Tools\"", + "LOG_DOMAIN=0xD004100", + ] + + cflags = [ "--coverage" ] + + cflags_cc = [ + "-std=c++17", + "--coverage", + ] + + ldflags = [ + "-fPIC", + "-Wl,-E", + "--coverage", + ] +} + +ohos_source_set("service_target") { + sources_obj = [ + "${signature_tools_api}/src/sign_tool_service_impl.cpp", + "${signature_tools_api}/src/localization_adapter.cpp", + "${signature_tools_api}/src/cert_tools.cpp", + "${signature_tools_signer}/src/signer_factory.cpp", + "${signature_tools_signer}/src/local_signer.cpp", + ] + + sources_obj += signature_tools_utils_src + sources_obj += signature_tools_zip_src + sources_obj += signature_tools_codesigning_src + sources_obj += signature_tools_common_src + sources_obj += signature_tools_hap_src + sources_obj += signature_tools_profile_src + sources_obj += signature_tools_cmd_src + + sources = sources_obj + + configs = [ ":service_include" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] + + public_deps = [ + "//third_party/bzip2:libbz2", + "//third_party/openssl:libcrypto_shared", + "//third_party/openssl:libssl_shared", + "//third_party/zlib:shared_libz", + ] + + public_external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "json:nlohmann_json_static", + ] + + part_name = "hapsigner" + subsystem_name = "developtools" +} diff --git a/hapsigntool_cpp/test/fuzztest/.gitignore b/hapsigntool_cpp/test/fuzztest/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..259148fa18f9fb7ef58563f4ff15fc7b172339fb --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/hapsigntool_cpp/test/fuzztest/BUILD.gn b/hapsigntool_cpp/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f75c18d61ad21a56cfc2b036094ffe8f813d5502 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("../../signature_tools.gni") +group("hapsigntool_pc_fuzztest") { + testonly = true + deps = [ + "${signature_tools_test}/fuzztest/codesigning:codesigning_fuzztest", + "${signature_tools_test}/fuzztest/common:common_fuzztest", + "${signature_tools_test}/fuzztest/generate_ca:generate_ca_fuzztest", + "${signature_tools_test}/fuzztest/generate_csr:generate_csr_fuzztest", + "${signature_tools_test}/fuzztest/hapsign:hapsign_fuzzer_fuzztest", + "${signature_tools_test}/fuzztest/process_cmd:process_cmd_fuzztest", + "${signature_tools_test}/fuzztest/profile:profile_fuzztest", + "${signature_tools_test}/fuzztest/remotesigner_fuzzer:remote_signer_fuzztest", + "${signature_tools_test}/fuzztest/utils:utils_fuzztest", + "${signature_tools_test}/fuzztest/zip:zip_fuzztest", + ] +} diff --git a/hapsigntool_cpp/test/fuzztest/codesigning/BUILD.gn b/hapsigntool_cpp/test/fuzztest/codesigning/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..daf9189fed46a794e9370b556e417c195b4a225c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/codesigning/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("codesigning_fuzztest") { + testonly = true + deps = [ "./codesigning_fuzzer:CodeSigningFuzzTest" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f138dc8cbd45a845e3f486986a8c3b173a60e06f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("CodeSigningFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "codesigning_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cbd7f017bb6abe63e42101e07431c788fb017fa3 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "signing_block.h" +#include "sign_block_info.h" +using namespace OHOS::SignatureTools; + +namespace OHOS { +bool SignBlockInfoObjectBuild(const uint8_t* data, size_t size) +{ + SignBlockInfo object; + std::vector sig{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, 1 }; + object.SetFileDigest(sig); + return true; +} + +bool SigningBlockObjectBuild(const uint8_t* data, size_t size) +{ + int32_t type = 1; + std::vector sig{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, 1 }; + 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); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/codesigning/codesigning_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/common/BUILD.gn b/hapsigntool_cpp/test/fuzztest/common/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6b61f62f6e9adeaffd4b09fd0c2bc5f77bb2da77 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("common_fuzztest") { + testonly = true + deps = [ + "./bytebuffer/bytebufferinit_fuzzer:ByteBufferInitFuzzTest", + "./digestparameter/digestparameterbuild_fuzzer:DigestParameterBuildFuzzTest", + ] +} diff --git a/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1a33007d56a0d213762b9aa412dceddbda45af4a --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ByteBufferInitFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "bytebufferinit_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60263f990508a49a8aa98711d0b69f5a92cdb496 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +#include "byte_buffer.h" + +namespace OHOS { +namespace SignatureTools { + +void ByteBufferTest001(const uint8_t* data, size_t size) +{ + int32_t offset = 32; + int32_t type = 4; + int32_t len = 100; + int16_t value = 6; + uint8_t vValue = 16; + const char dataTest[] = "hello world!"; + + ByteBuffer bytebuffer; + bytebuffer.GetUInt8(vValue); + bytebuffer.GetUInt8(offset, vValue); + bytebuffer.PutInt16(offset, value); + bytebuffer.PutData(offset, dataTest, len, type); + bytebuffer.PutUInt8(vValue); + bytebuffer.GetData(len); + + bytebuffer.ClearData(); + bytebuffer.IsEqual(dataTest); +} + +} +} +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::ByteBufferTest001(data, size); + return 0; +} diff --git a/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..1e7147c2d00df52ac9151fa84530d326d4dfa93c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 2 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0e840e95f8293e9577b6b0bb77171bdd711c948f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("DigestParameterBuildFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "digestparameterbuild_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/digestparameterbuild_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/digestparameterbuild_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc02a7a9f960a3a4066b180ce391f1e3e6364da5 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/digestparameterbuild_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include "digest_parameter.h" +namespace OHOS { +namespace SignatureTools { + +void DigestParameterTest(const uint8_t* data, size_t size) +{ + DigestParameter digest; + DigestParameter object(digest); + digest = object; +} +} +} +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DigestParameterTest(data, size); + return 0; +} diff --git a/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba213980b3a437ab1ae6b8c1373389769805a7cd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/common/digestparameter/digestparameterbuild_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5e8e70824d2510930b77e920c63effb40c9bce07 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("generate_ca_fuzztest") { + testonly = true + deps = [ + "./generateca001_fuzzer:GenerateCa001FuzzTest", + "./generateca002_fuzzer:GenerateCa002FuzzTest", + "./generateca003_fuzzer:GenerateCa003FuzzTest", + "./generateca004_fuzzer:GenerateCa004FuzzTest", + "./generateca005_fuzzer:GenerateCa005FuzzTest", + "./generateca006_fuzzer:GenerateCa006FuzzTest", + "./generateca007_fuzzer:GenerateCa007FuzzTest", + "./generateca008_fuzzer:GenerateCa008FuzzTest", + "./generateca009_fuzzer:GenerateCa009FuzzTest", + "./generateca010_fuzzer:GenerateCa010FuzzTest", + "./generateca011_fuzzer:GenerateCa011FuzzTest", + "./generateca012_fuzzer:GenerateCa012FuzzTest", + ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b2dec3119dd7ff4824f6cbb181da90745f92c21a --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa001FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca001_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ 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 new file mode 100644 index 0000000000000000000000000000000000000000..8bfcebec300456b6d59bda016c711a912ae842b0 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string keyUsage = "digitalSignature"; + std::string extKeyUsage = "codeSignature"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string signAlg = "SHA256withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + int validity = 365; + int keySize = 384; + char keyPwd[] = "123456"; + char ksPwd[] = "123456"; + bool extKeyUsageCritical = true; + bool basicConstraints = true; + bool basicConstraintsCritical = true; + bool basicConstraintsCa = true; + std::string outFile = "/data/test/generateCA/single-app1.cer"; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["keyUsage"] = keyUsage; + (*params)["extKeyUsage"] = extKeyUsage; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["extKeyUsageCritical"] = extKeyUsageCritical; + return api->GenerateCert(params.get()); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..678eff069a02fe25fd0fa91ea3acf985ee66972c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa002FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca002_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f74aa6535c3e23c79ba0b0a75e98c4a1c252187 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::string path = "/data/test/generateCA/root-ca1.cer"; + CertTools::ReadfileToX509(path); + return true; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca002_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a1061f2b85e361e154295227e7bba3679f403f32 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa003FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca003_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/generateca003_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/generateca003_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c69de8b75b7e45c08ac34ad129c3cd8ccdafa58 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/generateca003_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + LocalizationAdapter adapter; + adapter.GetOptions(); + return true; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca003_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..528d670ee5e62b13c2f3e2dac824a57750064c51 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa004FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca004_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd80863fca675b63f727fc2b13e4eb134ddd31ee --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string rootCaCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/app-sign-srv-ca1.cer"; + std::string outFile = "/data/test/generateCA/app-release1.pem"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + int validity = 365; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::CA_CERT_FILE] = rootCaCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + return api.GenerateAppCert(¶ms); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca004_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e7fb10cff77f36a7efe6e6e1c5b876eb771026b5 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa005FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca005_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0ebd715ab108b236a82ec47ae6b16952673242e --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-root-ca-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + int validity = 365; + int keySize = 384; + char keyPwd[] = "123456"; + char ksPwd[] = "123456"; + std::string outFile = "/data/test/generateCA/root-ca1.cer"; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + + return api->GenerateCA(params.get()); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca005_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..54ad560ab29dc849ca594189d90cdcfdb158a508 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa006FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca006_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1de804792c1bbd5d9340c359d6715dc64eeb71d3 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string issuerKeyAlias = "oh-root-ca-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keyAlg = "ECC"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + int validity = 365; + int keySize = 384; + char keyPwd[] = "123456"; + char ksPwd[] = "123456"; + char issuerkeyPwd[] = "123456"; + std::string outFile = "/data/test/generateCA/app-sign-srv-ca1.cer"; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyPwd"] = issuerkeyPwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["keyAlg"] = keyAlg; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + return api->GenerateCA(params.get()); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca006_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..59ad6149234c78fc7e63f0c6802cc4f231e32d6e --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa007FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca007_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22be79f9a8e9598b57670f49a58040f5da1b11c2 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA256withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char keyPwd[] = "123456"; + char ksPwd[] = "123456"; + std::string outFile = "/data/test/generateCA/oh-app1-key-v1.csr"; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + return api->GenerateCsr(params.get()); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca007_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..def84586d4e715c6a2a5dad13b31da0a0b0c5c05 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa008FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca008_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ddf13794e61b1baa0cd01b23de983f897b7059b --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::shared_ptr api = std::make_shared(); + X509* cert = X509_new(); + const std::string path = "/data/test/generateCA/cer"; + return api->OutPutCert(cert, path); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca008_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ccf19eea18302ee6effb09fe1dfd32b2ba5497b4 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa009FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca009_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..addc0561c642974560f02ac675f2a5b5a42d89ad --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::shared_ptr api = std::make_shared(); + return api->OutputString("hello world", "/data/test/tmp.data"); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca009_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..82595ad2311bc7ea5d1a004de8adff7de288bd87 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa010FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca010_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a14a2c231130e0b6dcd9c715987b7db334f1baee --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::shared_ptr params = std::make_shared(); + std::string signAlg = "SHA256withECDSA"; + (*params)["signAlg"] = signAlg; + X509* cert = X509_new(); + CertTools::SignForSubCert(cert, nullptr, nullptr, nullptr, params.get()); + return false; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca010_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c8183086fc4bcbd1b22823b42a42ffd4d54b9b70 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa011FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca011_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af23f9c57575de7570c1aca6d69d83854a94024c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string issuerkeyAlias = "oh-root-ca-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char issuerKeyPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeyPwd"] = issuerKeyPwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = adaptePtr->GetAliasKey(true); + X509_REQ* rootcsr = CertTools::GenerateCsr(keyPair, signAlg, subject); + X509_REQ* subcsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + CertTools::SignCsrGenerateCert(rootcsr, subcsr, keyPair, params.get()); + return false; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca011_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b88561df6abc52f544f303beb9202f880f18e325 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCa012FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generateca012_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eeaf9e9b09beca10a8f5ed030472ab4f86296760 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include +#include "options.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" + + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string issuerkeyAlias = "oh-root-ca-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char issuerKeyPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeyPwd"] = issuerKeyPwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = adaptePtr->GetAliasKey(true); + X509_REQ* rootcsr = CertTools::GenerateCsr(keyPair, signAlg, subject); + CertTools::GenerateSubCert(keyPair, rootcsr, params.get()); + return false; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_ca/generateca012_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/generate_csr/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_csr/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..35517b3726e2045f4d028df912d69bf2ed138bc1 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_csr/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("generate_csr_fuzztest") { + testonly = true + deps = [ "./generatecsr001_fuzzer:GenerateCsr001FuzzTest" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b11af284719866cbd39e81cb3dc2ed1c652f1775 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("GenerateCsr001FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "generatecsr001_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..69878dec001c0e4f7b666b02d376d8a491428508 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +/data/local/ark-cache/tmp/demo.an \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..778e0df3858778a232c739f5381cc9c8b598e069 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "key_store_helper.h" +#include "cert_tools.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + int keySize = 256; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + KeyStoreHelper keyStoreHelper; + EVP_PKEY* keyPair = keyStoreHelper.GenerateKeyPair(algorithm, keySize); + if (!keyPair) { + return false; + } + + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + std::string csrStr; + if (csr) { + csrStr = CertTools::CsrToString(csr); + X509_REQ_free(csr); + } + if (keyPair) { + EVP_PKEY_free(keyPair); + } + return csrStr.size() != 0; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..b7a26b6c3ea5674604e14fe6a5a9ef4129dfc34c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/generate_csr/generatecsr001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/hapsign/BUILD.gn b/hapsigntool_cpp/test/fuzztest/hapsign/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..216417138d946cf145453e16dffff4f197b3c454 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/hapsign/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("hapsign_fuzzer_fuzztest") { + testonly = true + deps = [ "./hapsign001_fuzzer:HapSign001FuzzTest" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e0af67f2fb1d3ee7a2321d590ddc8ee94fbe3ee3 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("HapSign001FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "hapsign001_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09a0385cc9e9685d90ca85e550b61563c7440086 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp @@ -0,0 +1,320 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "sign_tool_service_impl.h" +#include "options.h" +#include "sign_provider.h" +#include "local_sign_provider.h" +#include "hap_verify_result.h" +#include "hap_signer_block_utils.h" +#include "remote_sign_provider.h" +#include "verify_hap.h" + +namespace OHOS { +namespace SignatureTools { +bool HapSignTest001(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256w"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + SignerConfig signerConfig; + signerConfig.SetOptions(params.get()); + signerConfig.GetOptions(); + + signerConfig.SetCertificates(nullptr); + signerConfig.GetCertificates(); + + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + signerConfig.SetX509CRLs(crls); + signerConfig.GetX509CRLs(); + + signerConfig.GetSignParamMap(); + return true; +} + +bool HapSignTest002(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::ECDSA_WITH_SHA256); + SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::ECDSA_WITH_SHA384); + SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::DSA_WITH_SHA256); + + ContentDigestAlgorithm alg_tmp; + alg_tmp.GetDigestOutputByteSize(); + DigestParameter digestParam; + DigestParameter digestParam1; + DigestParameter digestParam2(digestParam); + digestParam = digestParam1; + digestParam2 = digestParam; + return true; +} + +bool HapSignTest003(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* issName = BuildDN(issuername, issuerReq); + CertTools::SetCertIssuerName(cert, issName); + CertTools::SetCertIssuerName(cert1, issName); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + KeyStoreHelper stroe; + EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256); + EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256); + + X509_set_pubkey(cert, key1); + X509_set_pubkey(cert1, key2); + + signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + EVP_PKEY_free(key1); + EVP_PKEY_free(key2); + return true; +} +bool HapSignTest004(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + signProvider->CheckInputCertMatchWithProfile(nullptr, nullptr); + signProvider->GetCrl(); + bool ret = signProvider->Sign(params.get()); + return ret; +} + +bool HapSignTest005(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + AppDistType type = APP_GALLERY; + ProfileInfo provisionInfo; + VerifyHap verify; + bool ret = verify.IsAppDistributedTypeAllowInstall(type, provisionInfo); + int capacity = 120; + + HapVerifyResult hapVerifyResult; + hapVerifyResult.SetVersion(1); + hapVerifyResult.GetVersion(); + hapVerifyResult.GetPublicKey(); + hapVerifyResult.GetSignature(); + + std::vector option; + OptionalBlock testblock; + testblock.optionalType = PROPERTY_BLOB; + testblock.optionalBlockValue.SetCapacity(capacity); + option.push_back(testblock); + hapVerifyResult.SetOptionalBlocks(option); + + std::string getProfile; + hapVerifyResult.GetBlockFromOptionalBlocks(PROFILE_BLOB, getProfile); + + std::string getProperty; + hapVerifyResult.GetProperty(getProperty); + std::vector profile; + + hapVerifyResult.SetProfile(profile); + hapVerifyResult.GetProfile(); + hapVerifyResult.GetProvisionInfo(); + return ret; +} + +bool HapSignTest006(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12"; + std::string compatibleVersion = "8"; + std::string signerPlugin = "/mnt/d/libRemoteSigner.so"; + std::string signServer = "/mnt/d/testcpuls/app-release1.pem"; + std::string username = "test"; + char userPwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + (*params)["onlineAuthMode"] = onlineAuthMode; + (*params)["compatibleVersion"] = compatibleVersion; + (*params)["signerPlugin"] = signerPlugin; + (*params)["signServer"] = signServer; + (*params)["username"] = username; + (*params)["userPwd"] = userPwd; + + signProvider->CheckParams(params.get()); + return true; +} + +bool HapSignTest007(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + signProvider->GetCrl(); + return true; +} + +void GenUnvaildFuzzHap(const std::string& path) +{ + std::ofstream outfile(path); + if (!outfile) { + SIGNATURE_TOOLS_LOGE("Unable to open file: %s", path.c_str()); + return; + } + outfile << "Hello, this is a Unvaild fuzz Hap.\n"; + outfile.flush(); + outfile.close(); + return; +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::SignatureTools::GenUnvaildFuzzHap("./hapSign/unsigned_with_cd_and_eocd.hap"); + OHOS::SignatureTools::GenUnvaildFuzzHap("./hapSign/phone-default-unsigned"); + OHOS::SignatureTools::GenUnvaildFuzzHap("./hapSign/phone-default-unsigned.hap"); + sync(); + /* Run your code on data */ + OHOS::SignatureTools::HapSignTest001(data, size); + OHOS::SignatureTools::HapSignTest002(data, size); + OHOS::SignatureTools::HapSignTest003(data, size); + OHOS::SignatureTools::HapSignTest004(data, size); + OHOS::SignatureTools::HapSignTest005(data, size); + OHOS::SignatureTools::HapSignTest006(data, size); + OHOS::SignatureTools::HapSignTest007(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8ec24570500e8357b97a5ab36b524416ca94ca9f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/hapsign/hapsign001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..130950c1bf31375809618834f52dbbfe5bf6bc06 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("process_cmd_fuzztest") { + testonly = true + deps = [ + "./processcmd001_fuzzer:ProcessCmd001FuzzTest", + "./processcmd002_fuzzer:ProcessCmd002FuzzTest", + "./processcmd003_fuzzer:ProcessCmd003FuzzTest", + "./processcmd004_fuzzer:ProcessCmd004FuzzTest", + "./processcmd005_fuzzer:ProcessCmd005FuzzTest", + "./processcmd006_fuzzer:ProcessCmd006FuzzTest", + "./processcmd007_fuzzer:ProcessCmd007FuzzTest", + "./processcmd008_fuzzer:ProcessCmd008FuzzTest", + "./processcmd009_fuzzer:ProcessCmd009FuzzTest", + "./processcmd010_fuzzer:ProcessCmd010FuzzTest", + "./processcmd011_fuzzer:ProcessCmd011FuzzTest", + "./processcmd012_fuzzer:ProcessCmd012FuzzTest", + "./processcmd013_fuzzer:ProcessCmd013FuzzTest", + "./processcmd014_fuzzer:ProcessCmd014FuzzTest", + "./processcmd015_fuzzer:ProcessCmd015FuzzTest", + "./processcmd016_fuzzer:ProcessCmd016FuzzTest", + "./processcmd017_fuzzer:ProcessCmd017FuzzTest", + "./processcmd018_fuzzer:ProcessCmd018FuzzTest", + "./processcmd019_fuzzer:ProcessCmd019FuzzTest", + "./processcmd020_fuzzer:ProcessCmd020FuzzTest", + "./processcmd021_fuzzer:ProcessCmd021FuzzTest", + "./processcmd022_fuzzer:ProcessCmd022FuzzTest", + "./processcmd023_fuzzer:ProcessCmd023FuzzTest", + "./processcmd024_fuzzer:ProcessCmd024FuzzTest", + ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0460a1294e04f6bd9e2884239a81e4547f099a59 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd001FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd001_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/processcmd001_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/processcmd001_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f8ada7b2e9c77af5c34faef7467149a388768d0 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/processcmd001_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char* argv[] = { arg0 }; + + int argc = 1; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba213980b3a437ab1ae6b8c1373389769805a7cd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7fb83d7959d142b64fe8426f6f3934d0e5640ff0 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd002FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd002_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/processcmd002_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/processcmd002_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6dafcfcdb9a1f2ae693980b5fd5e89c680430574 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/processcmd002_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + int argc = 5; + + bool ret = ParamsRunTool::ProcessCmd(nullptr, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba213980b3a437ab1ae6b8c1373389769805a7cd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd002_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4a1ebe351469bc20fa38996d2dabaf3af10a0277 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd003FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd003_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/processcmd003_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/processcmd003_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f06af70bf13ca5b934dc182ad6c22567852c27c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/processcmd003_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "-h"; + char* argv[] = { arg0, arg1 }; + + int argc = 2; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba213980b3a437ab1ae6b8c1373389769805a7cd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd003_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..690339f3c4bc2408531e5664b4693aa2eb43df55 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd004FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd004_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/processcmd004_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/processcmd004_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca7e178e4d5d1d723ce41d6195fe391ce7f91d9e --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/processcmd004_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "-help"; + char* argv[] = { arg0, arg1 }; + + int argc = 2; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba213980b3a437ab1ae6b8c1373389769805a7cd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd004_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6791ce61f2f5ec4af0347167ef913b7b72383b6a --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd005FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd005_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/processcmd005_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/processcmd005_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..463c0b1f3c75e85d5b2386dddf6891f813725b17 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/processcmd005_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "-v"; + char* argv[] = {arg0, arg1}; + + int argc = 2; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd005_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8b04c8a863a3e9a6d0400fccb606b97af0118dbb --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd006FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd006_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/processcmd006_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/processcmd006_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9d2de2681f67b7e70bb973943b4ff4d2e554e52 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/processcmd006_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "-version"; + char* argv[] = {arg0, arg1}; + + int argc = 2; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd006_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b98a1c5262a6be28779f22dd61742894d1860eb5 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd007FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd007_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd1f4c6f8cfc8cc2b0fc4d6636c8b5a7625ccbba --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-384"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + + int argc = 14; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd007_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6c2b45ec4b0b5fe87fa07a3cfa7957cdc0dafad7 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd008FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd008_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08f718f1c536e9ca8d63ada21a84319c64b85fbc --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-384"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmonyTest.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13}; + + int argc = 14; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba213980b3a437ab1ae6b8c1373389769805a7cd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd008_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 1 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9ed0fa3a085b9641880b4af7298ce2c2855730a8 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd009FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd009_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7de94b6277860087b2594e6c066df3c0537b6753 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-csr"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA256withECDSA"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char arg14[] = "-outFile"; + char arg15[] = "./generateKeyPair/oh-app1-key-v1.csr"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, + arg10, arg11, arg12, arg13, arg14, arg15 }; + + int argc = 16; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd009_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..711c7bf320d2ae0ee2f31711e39c2dffaadb5b2f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd010FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd010_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3748eab8d54846f0563fddac87763b9cbac86677 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21 }; + int argc = 22; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd010_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b73bf11a54002bc82ee443fb0782fdc36e2a937b --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd011FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd011_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a0e6ddcc2adea40cfeb3ba55902f9d4b7a4cc3d2 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app-sign-srv-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Root CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-root-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN= Application Signature Service CA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg18[] = "-validity"; + char arg19[] = "365"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-keyAlg"; + char arg23[] = "ECC"; + char arg24[] = "-signAlg"; + char arg25[] = "SHA384withECDSA"; + char arg26[] = "-issuerKeyPwd"; + char arg27[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, + arg21, arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd011_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..39d6d4fc42dd6534deed78c2a29a6e989337f726 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd012FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd012_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa43c1052c26c48c1e14f60c49783dfad5ebb7b3 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile-sign-srv-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Root CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-root-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN= Application Signature Service CA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/profile-sign-srv-ca1.cer"; + char arg18[] = "-validity"; + char arg19[] = "365"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-keyAlg"; + char arg23[] = "ECC"; + char arg24[] = "-signAlg"; + char arg25[] = "SHA384withECDSA"; + char arg26[] = "-issuerKeyPwd"; + char arg27[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, + arg20, arg21, arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd012_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..61fa689b884153ad2789d633407bba3c8609cea1 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd013FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd013_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3e9966cdc696274a4baa14224bddc04a6c1c75a0 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char arg28[] = "-issuerKeyPwd"; + char arg29[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29 }; + int argc = 30; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd013_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..84bff125248faa3afb683875b877afaa8cc63b6a --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd014FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd014_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a239378b15fb3bfa62d7cff672675164b7fbc295 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char arg28[] = "-issuerKeyPwd"; + char arg29[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29 }; + int argc = 30; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd014_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cedf6dd2e0208e3e4d5b345b6e7619a26f5e6baf --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd015FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd015_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb713a18ee9d4e3cae47d211d08de7ea8cf33871 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU = OpenHarmony Community; CN = App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsage"; + char arg23[] = "digitalSignature"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd015_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..56fdcc5ca09f3fe222657bf5c968a3b67c57a504 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd016FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd016_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb790fc53be3f679c62a1c07244d61065ffa5355 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "sign-profile"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA384withECDSA"; + char arg10[] = "-inFile"; + char arg11[] = "./generateKeyPair/profile.json"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/signed-profile.p7b"; + char arg18[] = "-profileCertFile"; + char arg19[] = "./generateKeyPair/profile-release1.pem"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19 }; + int argc = 20; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd016_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7f3e7ce269b82bad15eef177f89af435cccfceaa --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd017FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd017_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..36ddd6015da88779cf8baee4330fab4fa0248f87 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "verify-profile"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/signed-profile.p7b"; + char arg4[] = "-outFile"; + char arg5[] = "./generateKeyPair/VerifyResult.json"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5 }; + int argc = 6; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd017_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8f21b1006b635f1c891b35d47a18b3b14601d137 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd018FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ + "processcmd018_fuzzer.cpp", + ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..338552bc304b74a6f6ee0557eb1485eea9d27237 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "params_run_tool.h" +#include "code_signing.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signCode"; + char arg9[] = "1"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA256withECDSA"; + char arg12[] = "-appCertFile"; + char arg13[] = "./generateKeyPair/app-release1.pem"; + char arg14[] = "-profileFile"; + char arg15[] = "./generateKeyPair/signed-profile.p7b"; + char arg16[] = "-inFile"; + char arg17[] = "./generateKeyPair/entry-default-unsigned-so.hap"; + char arg18[] = "-keystoreFile"; + char arg19[] = "./generateKeyPair/OpenHarmony.p12"; + char arg20[] = "-keystorePwd"; + char arg21[] = "123456"; + char arg22[] = "-outFile"; + char arg23[] = "./generateKeyPair/entry-default-signed-so.hap"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23}; + int argc = 24; + CodeSigning obj; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} + +bool SignElf(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signCode"; + char arg9[] = "1"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA256withECDSA"; + char arg12[] = "-appCertFile"; + char arg13[] = "./generateKeyPair/app-release1.pem"; + char arg14[] = "-profileFile"; + char arg15[] = "./generateKeyPair/signed-profile.p7b"; + char arg16[] = "-inFile"; + char arg17[] = "./generateKeyPair/entry-default-unsigned-so.hap"; + char arg18[] = "-keystoreFile"; + char arg19[] = "./generateKeyPair/OpenHarmony.p12"; + char arg20[] = "-keystorePwd"; + char arg21[] = "123456"; + char arg22[] = "-outFile"; + char arg23[] = "./generateKeyPair/entry-default-signed-so.elf"; + char arg24[] = "-inForm"; + char arg25[] = "elf"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25}; + int argc = 26; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} + +bool SignBin(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signCode"; + char arg9[] = "1"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA256withECDSA"; + char arg12[] = "-appCertFile"; + char arg13[] = "./generateKeyPair/app-release1.pem"; + char arg14[] = "-profileFile"; + char arg15[] = "./generateKeyPair/signed-profile.p7b"; + char arg16[] = "-inFile"; + char arg17[] = "./generateKeyPair/entry-default-unsigned-so.hap"; + char arg18[] = "-keystoreFile"; + char arg19[] = "./generateKeyPair/OpenHarmony.p12"; + char arg20[] = "-keystorePwd"; + char arg21[] = "123456"; + char arg22[] = "-outFile"; + char arg23[] = "./generateKeyPair/entry-default-signed-so.bin"; + char arg24[] = "-inForm"; + char arg25[] = "bin"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25}; + int argc = 26; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + (void)rename("./generateKeyPair/phone-default-unsigned.txt", "./generateKeyPair/entry-default-unsigned-so.hap"); + sync(); + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + OHOS::SignatureTools::SignElf(data, size); + OHOS::SignatureTools::SignBin(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd018_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..37b68c7d2718690ad123d8782e19b272485e5938 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd019FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ + "processcmd019_fuzzer.cpp", + ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d3af684054b624780f89e520bd0fc2c2bc779fb4 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" +#include "extension.h" +#include "merkle_tree_extension.h" +#include "segment_header.h" +#include "code_signing.h" +#include "file_utils.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/entry-default-signed-so.hap"; + char arg4[] = "-outCertChain"; + char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg6[] = "-outProfile"; + char arg7[] = "./generateKeyPair/app-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 }; + int argc = 8; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} + +bool VerifyElf(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/entry-default-signed-so.elf"; + char arg4[] = "-outCertChain"; + char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg6[] = "-outProfile"; + char arg7[] = "./generateKeyPair/app-profile.p7b"; + char arg8[] = "-inForm"; + char arg9[] = "elf"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; + int argc = 10; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} + +bool VerifyBin(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/entry-default-signed-so.bin"; + char arg4[] = "-outCertChain"; + char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg6[] = "-outProfile"; + char arg7[] = "./generateKeyPair/app-profile.p7b"; + char arg8[] = "-inForm"; + char arg9[] = "bin"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; + int argc = 10; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} + +bool TestDatastructure(const uint8_t* data, size_t size) +{ + Extension extension; + int32_t sizet = extension.GetSize(); + MerkleTreeExtension merkleTreeExtension; + SegmentHeader segmentHeader; + CodeSigning codeSigning; + return sizet != 0; +} + +bool TestFileUtils(const uint8_t* data, size_t size) +{ + std::string bytes; + std::string file; + bool flag = FileUtils::WriteByteToOutFile(bytes, file); + FileUtils::DelDir(file); + return flag; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + (void)rename("./generateKeyPair/entry-default-signed-so.txt", "./generateKeyPair/entry-default-signed-so.hap"); + (void)rename("./generateKeyPair/signed-elf.txt", "./generateKeyPair/entry-default-signed-so.elf"); + (void)rename("./generateKeyPair/signed-bin.txt", "./generateKeyPair/entry-default-signed-so.bin"); + sync(); + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + OHOS::SignatureTools::VerifyElf(data, size); + OHOS::SignatureTools::VerifyBin(data, size); + OHOS::SignatureTools::TestDatastructure(data, size); + OHOS::SignatureTools::TestFileUtils(data, size); + sync(); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..be1f8ac88ad4b22d1939fd807c2215c75f4a9709 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd019_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 30 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8efeb34ba63a69d1ed26f09f260a536ea4f1b5eb --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd020FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd020_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae9dc83249e2bbf1fed320acf8e67f7312927cc4 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app1.cer"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char arg28[] = "-issuerKeyPwd"; + char arg29[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29 }; + int argc = 30; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd020_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2f01acbb962017b14bb4092a5b59e592b9bf14f3 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd021FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd021_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01d822dd56139fa63577a4bf509999ac34bc2252 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/profile1.cer"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char arg28[] = "-issuerKeyPwd"; + char arg29[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29 }; + int argc = 30; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd021_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c691f8d0962a75709b854f9b509f14aca0845596 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd022FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd022_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d17271208d14d13fc2aff8e0ab899bdcea806a2 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool GenerateAppCertTest2() +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-subCaCertFile"; + char arg21[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg22[] = "-outForm"; + char arg23[] = "certChain"; + char arg24[] = "-rootCaCertFile"; + char arg25[] = "./generateKeyPair/root-ca1.cer"; + char arg26[] = "-issuerKeyPwd"; + char arg27[] = "123456"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27}; + int argc = 27; + + return ParamsRunTool::ProcessCmd(argv, argc); +} +bool GenerateAppCertTest3() +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-subCaCertFile"; + char arg21[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg22[] = "-outForm"; + char arg23[] = "cert"; + char arg24[] = "-rootCaCertFile"; + char arg25[] = "./generateKeyPair/root-ca1.cer"; + char arg26[] = "-issuerKeyPwd"; + char arg27[] = "123456"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27}; + int argc = 27; + + return ParamsRunTool::ProcessCmd(argv, argc); +} +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "cert"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char arg28[] = "-issuerKeyPwd"; + char arg29[] = "123456"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29}; + int argc = 30; + + bool ret = false; + ret = ParamsRunTool::ProcessCmd(argv, argc); + ret = GenerateAppCertTest2(); + ret = GenerateAppCertTest3(); + + return ret; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd022_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fcdf1ecd671ab72dbd9ccec1ce6bcf6c10e52700 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd023FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd023_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b3dcb41fbcdbaa05a7300c3250a4a6e8e60702f6 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "params_run_tool.h" +#include "cmd_util.h" +#include "options.h" +#include "file_utils.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + X509* cert = X509_new(); + X509* certRet = nullptr; + std::vector certChain; + std::string inputType = "clientAuthentication"; + CmdUtil::VerifyType(inputType); + Options options; + std::string key1 = "key1"; + std::string key2 = "key2"; + bool status = true; + (options)["booltype"] = status; + options.Equals(key1, key2); + options.GetBool("booltype"); + std::shared_ptr serviceImplPtr = std::make_shared(); + serviceImplPtr->PrintX509CertFromMemory(cert); + serviceImplPtr->PrintX509CertChainFromMemory(certChain); + X509_free(cert); + CertTools certTool; + status = certTool.SetSubjectForCert(nullptr, nullptr); + certRet = certTool.GenerateRootCertificate(nullptr,nullptr, &options); + status = FileUtils::WriteInputToOutPut("", ""); + FileUtils::DelDir(""); + + return true; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd023_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..be2ff045d954030e57bfbc805e5e3e93a6315e5b --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ProcessCmd024FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "processcmd024_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67cf0b743547a1e58e725a7a6f57081a777c2bcf --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "signature_algorithm_helper.h" +#include "verify_hap_openssl_utils.h" +#include "hash_utils.h" +#include "params.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + Params param; + std::string str; + std::string retStr; + std::string algName; + bool retBool = false; + int algId = 256; + std::vector paramFields; + std::vector fileBytes; + std::unordered_set unordered; + std::vector vec; + int64_t length = 0; + SignatureAlgorithmHelper out; + ByteBuffer crlBuffer; + int32_t offset = 0; + int32_t len = 0; + std::ofstream crlFile; + CertChain certsChain; + Pkcs7Context pkcs7Context; + long long certNumber = 0; + Options* options = nullptr; + X509* cert = nullptr; + X509_CRL* x509Crl = nullptr; + + param.SetMethod(str); + retStr = param.GetMethod(); + options = param.GetOptions(); + unordered = param.InitParamField(paramFields); + retBool = param.GetSignatureAlgorithm(str, out); + retStr = HashUtils::GetHashAlgName(algId); + vec = HashUtils::GetDigestFromBytes(fileBytes, length, algName); + cert = VerifyCertOpensslUtils::GetX509CertFromBase64String(str); + retBool = VerifyCertOpensslUtils::CompareX509Cert(nullptr, str); + x509Crl = VerifyCertOpensslUtils::GetX509CrlFromDerBuffer(crlBuffer, offset, len); + VerifyCertOpensslUtils::WriteX509CrlToStream(crlFile, nullptr); + retBool = VerifyCertOpensslUtils::VerifyCrl(certsChain, nullptr, pkcs7Context); + x509Crl = VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(nullptr, nullptr); + retBool = VerifyCertOpensslUtils::GetIssuerFromX509(nullptr, str); + retBool = VerifyCertOpensslUtils::GetSerialNumberFromX509(nullptr, certNumber); + retBool = VerifyCertOpensslUtils::GetIssuerFromX509Crl(nullptr, str); + + return true; +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..efdd42baa799b896e4a412fab517290e76c20912 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/process_cmd/processcmd024_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 10 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/profile/BUILD.gn b/hapsigntool_cpp/test/fuzztest/profile/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..50b985112ebd53c4883cbe30ec52fd5a47230040 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/profile/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("profile_fuzztest") { + testonly = true + deps = [ "./profile001_fuzzer:Profile001FuzzTest" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b30817bddca8e59c0193819a8167d0df3e5ba220 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("Profile001FuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "profile001_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..69878dec001c0e4f7b666b02d376d8a491428508 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +/data/local/ark-cache/tmp/demo.an \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad506c198e76f3fbf39750bb6ee6c51fd42c7967 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "securec.h" +#include "../profile_resources.h" + +using namespace OHOS::SignatureTools; + +namespace OHOS { +bool SignProfileTest001(const uint8_t* data, size_t size) +{ + std::string content(data, data + size); + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + PKCS7Data p7; + std::string p7b; + int result = p7.Sign(content, signer, signAlg, p7b); + return result == 0; +} + +bool SignProfileTest002(const uint8_t* data, size_t size) +{ + std::string content(data, data + size); + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + PKCS7Data::PrintCertChainSub(certs); + return true; +} + +bool SignProfileTest003(const uint8_t* data, size_t size) +{ + ASN1_TIME* time_ = ASN1_TIME_new(); + time_t now; + if (time(&now) < 0) { + return false; + } + ASN1_TIME_set(time_, now); + std::string result = PKCS7Data::GetASN1Time(time_); + ASN1_TIME_free(time_); + return result.empty() == false; +} + +bool SignProfileTest004(const uint8_t* data, size_t size) +{ + ProfileInfo info; + info.type = ProvisionType::RELEASE; + ProfileInfo info2(info); + return true; +} + +bool SignProfileTest005(const uint8_t* data, size_t size) +{ + SetRdDevice(static_cast(size)); + return true; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + SignProfileTest001(data, size); + SignProfileTest002(data, size); + SignProfileTest003(data, size); + SignProfileTest004(data, size); + SignProfileTest005(data, 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); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6d3e765c7dc1097ac2fb92d825dfad6b0b08636d --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/profile/profile001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/profile/profile_resources.h b/hapsigntool_cpp/test/fuzztest/profile/profile_resources.h new file mode 100644 index 0000000000000000000000000000000000000000..2987bee334e90653793e38249b3d9ceb8ba0dd73 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/profile/profile_resources.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PROFILE_RESOURCE_H +#define PROFILE_RESOURCE_H + +#include +#include +#include + +#include "options.h" +#include "sign_tool_service_impl.h" +#include "nlohmann/json.hpp" +#include "signer_factory.h" +#include "profile_sign_tool.h" +#include "params_run_tool.h" +#include "pkcs7_data.h" +#include "signer_config.h" +#include "local_signer.h" +#include "bc_pkcs7_generator.h" +#include "bc_signeddata_generator.h" +#include "profile_verify.h" +#include "constant.h" +#include "profile_verify_utils.h" +#include "cms_utils.h" + + +using nlohmann::json; + +namespace OHOS { +namespace SignatureTools { + +// sign profile使用的全局参数 +const std::string SIGN_PROFILE_MODE = "localSign"; +const std::string SIGN_PROFILE_KEY_ALIAS = "oh-profile1-key-v1"; +const std::string SIGN_PROFILE_PROFILE_CERT_FILE = "./signProfile/profile-release1.pem"; +const std::string SIGN_PROFILE_SIGN_ALG = "SHA384withECDSA"; +const std::string SIGN_PROFILE_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +const std::string SIGN_PROFILE_OUT_FILE = "./signProfile/signed-profile.p7b"; +const std::string SIGN_PROFILE_IN_FILE = "./signProfile/profile.json"; + +const std::string SIGN_PROFILE_CERT_PEM = "./signProfile/profile-release1-cert.pem"; +const std::string SIGN_PROFILE_REVERSE_PEM = "./signProfile/profile-release1-reverse.pem"; +const std::string SIGN_PROFILE_DOUBLE_CERT_PEM = "./signProfile/" +"profile-release1-invalid_cert_chain.pem"; + +// verify profile 使用的全局参数 +const std::string VERIFY_PROFILE_IN_FILE = "./signProfile/app1-profile1.p7b"; +const std::string VERIFY_PROFILE_OUT_FILE = "./signProfile/verify-result.json"; +} +} +#endif + diff --git a/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1522ee8c7297c46b3c97dc2cd563a4d3c8cf7d10 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("RemoteSignerFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ + "remotesigner_fuzzer.cpp", + ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} + +group("remote_signer_fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":RemoteSignerFuzzTest", + ] +} diff --git a/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6c04f4f3af5564d68b24691adc25c92e82468505 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..49b206d709244e95ae18d9629d8bd4c5538c7196 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 60 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/remotesigner_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/remotesigner_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3aa428b03df0866e4356b6192c4b14ff009d528c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/remotesigner_fuzzer/remotesigner_fuzzer.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "params_run_tool.h" + +namespace OHOS { +namespace SignatureTools { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (!data || !size) { + return true; + } + + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-mode"; + char arg3[] = "remoteSign"; + char arg4[] = "-keyAlias"; + char arg5[] = "oh-app1-key-v1"; + char arg6[] = "-profileFile"; + char arg7[] = "./remote_signer/signed-profile.p7b"; + char arg8[] = "-inFile"; + char arg9[] = "./remote_signer/raw.hap"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA256withECDSA"; + char arg12[] = "-outFile"; + char arg13[] = "./remote_signer/signed-raw.hap"; + char arg14[] = "-signServer"; + char arg15[] = "./remote_signer/app-release1.pem"; + char arg16[] = "-signerPlugin"; + char arg17[] = "./remote_signer/libremote_signer.z.so"; + char arg18[] = "-onlineAuthMode"; + char arg19[] = "./remote_signer/OpenHarmony.p12"; + char arg20[] = "-username"; + char arg21[] = "123456"; + char arg22[] = "-userPwd"; + char arg23[] = "123456"; + char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23}; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + return ret; +} + +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + (void)rename("./remote_signer/raw.txt", "./remote_signer/raw.hap"); + sync(); + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/OpenHarmony.p12 b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/OpenHarmony.p12 new file mode 100644 index 0000000000000000000000000000000000000000..c97cb66984b92d3cd228033fce03dc2e8f573ded Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/OpenHarmony.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/OpenHarmony1.p12 b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/OpenHarmony1.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f9bb2d0511b411cd2d51658fbdbf724a83dc9a57 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/OpenHarmony1.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/app-sign-srv-ca1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/app-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..1083a95c26e4561ae01a24eba6fde83344d0b50b --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/app-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICCTCCAY+gAwIBAgIIW5GcLu/C7jowCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjE3MDMwMDMzWhcNMzQw +NjE1MDMwMDMzWjBuMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEpMCcGA1UEAwwgQXBwbGlj +YXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwdjAQBgcqhkjOPQIBBgUrgQQAIgNi +AAQGEl+CJE6Pocw15dIrBbgD/xYXsTVNxQg4Xon1TKkPOZK+YinO1yEf5tsQRnbY +99uDl6+XpBTY5qIetV14yDCIkGQyiNKK0vtQGk3raKoaa3eiV0t/YHm4TSvZgFYS +hfOjEzARMA8GA1UdEwQIMAYBAf8CAQAwCgYIKoZIzj0EAwMDaAAwZQIxAMKnEvkq +Mr+piaRdgB3mjF4YpBywCcVC4UwNbWTL8Do/TyxLN6KSGaoNmBepeW2hzQIwQ4IA +V+jAcBrplY02ZnDniW/ttnaOyd4CXT7c4bv+uZZLxbGBrikUNmnf8ue9A8j/ +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/apptest.p12 b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/apptest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..e1ae5478f00b37b5315e1eea08a015f3e9f4c587 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/apptest.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/ohtest.p12 b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..022a182258d12c284449ea961b981c484ba6335d Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/profile-sign-srv-ca1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/profile-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..676db8ff47304176fd36651a3462b68201f3a784 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/profile-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICBTCCAYugAwIBAgII+khBvfAMGqUwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjE1MDczNDU1WhcNMjUw +NjE1MDczNDU1WjBqMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTElMCMGA1UEAwwcUHJvZmls +ZSBTaWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABBnv +25yOncnQealn6zh2B3JPqQP1QvbySDYwUClyqqWv949XN9JRfby/gmnSXjR75BXx +s9SVMGoz/F6JKF0dUPp4ttOMSYqzLBE+UYI1hewvIp9R4a33quolxuKJeCjv2aMT +MBEwDwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNoADBlAjBaR7W28/FArcxZ +VDxj/bBoW3Kq+ymswCwIpVrmB7DpEhOl4iSofbL3NvToWGCtYpMCMQDsBrJMnqKx +kzzYOlJ1Tmu/2xC6rOLgPn0EpZftLpbgR6heLUt78q5m6vBMV8F2xbM= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/profile-sign-srv-ca1test.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/profile-sign-srv-ca1test.cer new file mode 100644 index 0000000000000000000000000000000000000000..f40a14c89b303dac5bd0991c8cc74c8596493954 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/profile-sign-srv-ca1test.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB/jCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yMzA4MDUwOTIwNDNaFw0yNDA4MDQwOTIw +NDNaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEF+vCQnGuAjaJ +D0IZl6VBtH1BfaxcKq8nxZlqhwPQ04hZ7J+YocmnYL0LVDYIskBRUU50YuEOdQNW +FR3/R9F36IbTbW9QrL8zIUwYs3ISdvNcf8IT1e2337mBPHleV8jnoxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA2gAMGUCMQCTiGJQ7OJVDK60yNLQqcM4 +116vCZt7wM9Cu51VlN+GrdeVZaHsDOuunHGWhx9DWeMCMAGnjB+zGyZDjNKBgwdc +hiob7oAN6vBZEmUpdxru6ty7DqInKjr5QqhGSwjCcQTYNg== +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/root-ca1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/root-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..96593e5169efbf0790b1a6aa9d42d1756970933b --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/root-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB7zCCAXWgAwIBAgIHr+ykXzRxQDAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJD +TjEUMBIGA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENv +bW11bml0eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MTcwMjU5MzdaFw0yNTA2 +MTcwMjU5MzdaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEe +MBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENB +MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEZmG6LbwmkTdG6BswxBVMAl+skd6X5/51 +v1OxB+W+Ug77i/s/TsDnfwuQvjcViroozYFNPxRSwJJQ9tSjBNogBpFQSgarOJrW +H7dnE5QvqHlvvx93x2XqR6zs6PhW7cUwoxMwETAPBgNVHRMECDAGAQH/AgEAMAoG +CCqGSM49BAMDA2gAMGUCMQDkXLXMZTknnLzlwSruEMObjEItwF3ZHjCTBo62EI9k +5X0HyW0xxGPigvknS5czJX8CMEKD/UfktN731CDz24ogKhiPyJOFvxqLi2GyKb97 +v+4ChH3VYDIHkz5l/SUK+XPmVw== +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_ca/root-ca1test.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/root-ca1test.cer new file mode 100644 index 0000000000000000000000000000000000000000..90b3aba66f279771149f47d8798c35e1a368f52a --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_ca/root-ca1test.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yMzA4MDUwOTIwMjBaFw0yNDA4MDQwOTIw +MjBaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEKYjo4oUoHev5f4D+P5uOYSGAGq439OIrgkXi6sQP +2ku/Ovln3BPZYf10vqym+YLSkJbTVqUiEdkPBl/vy+kPxzu4VJG0AhL8QOKHeeBH +KNTwgM+i1AtmmYQ57WviEzleoxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2kAMGYCMQDzlOyoFx38xmTeUC9RFel2fU3kBOvvE0QN9aP5Fz4S7Wm72QtX +25INA1Dl040hNpECMQDE6K6yq8hCu+GmHR/cGZ+/fDcuUkHOtO0Iw5BKMOUDkeM3 +5Vj0L8RnL3dgjAfvlv0= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_csr/ohtest.p12 b/hapsigntool_cpp/test/fuzztest/resource/generate_csr/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..de5c0e36a8a937f2d19934600575c10c4393a2ed Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_csr/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/OpenHarmony.p12 b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/OpenHarmony.p12 new file mode 100644 index 0000000000000000000000000000000000000000..c05a3f7f8bb66401e695591f52a4cd8bc504d1c4 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/OpenHarmony.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/VerifyResult.json b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/VerifyResult.json new file mode 100644 index 0000000000000000000000000000000000000000..cad5cac3e5bb221fa1db9993efa223b8c1ebb05d --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/VerifyResult.json @@ -0,0 +1 @@ +{"bundle-info":{"app-feature":"hos_system_app","bundle-name":"com.example.nativetemplatedemo","developer-id":"OpenHarmony","development-certificate":"-----BEGIN CERTIFICATE-----\nMIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\nMjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\nodSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\nUYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\no2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\nBQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\nAwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\nQT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\n4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\n-----END CERTIFICATE-----\n"},"debug-info":{"device-id-type":"udid","device-ids":["69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42","7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865"]},"issuer":"pki_internal","permissions":{"restricted-permissions":[""]},"type":"debug","uuid":"fe686e1b-3770-4824-a938-961b140a7c98","validity":{"not-after":1705127532,"not-before":1610519532},"version-code":1,"version-name":"1.0.0"} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-profile.p7b b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..cbfbce936969fffaa7a857663653a3d8e06dae63 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-profile.p7b differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-release1.pem b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..c6a41cf7f39e905c49b35c96451db1610fc946b4 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-release1.pem @@ -0,0 +1,42 @@ +-----BEGIN CERTIFICATE----- +MIICcDCCAfagAwIBAgIIdLvvPjsiK7EwCgYIKoZIzj0EAwMwbjELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxKTAnBgNVBAMMIEFwcGxpY2F0aW9uIFNpZ25hdHVyZSBTZXJ2aWNl +IENBMB4XDTI0MDYyMDAyMDE0NloXDTI1MDYyMDAyMDE0NlowWjELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxFTATBgNVBAMMDEFwcDEgUmVsZWFzZTB2MBAGByqGSM49AgEGBSuB +BAAiA2IABPvdywSeJDzxgHxB/UUtg8CCsBgmeIyH2JNDSaEDyyM5UgX1HcUhGhjB +0XijxCp3Dh6xGVTEEtTStGqL3DFm2aIm8YIr1NuxUhaNjdiGzLV0aLCFaC0QBx8z ++sOhoUId0aN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAww +CgYIKwYBBQUHAwMwJwYDVR0OBCAJGPL8NRaTn4xhcJUbKKMLS47KqeVIHKrY9UHw +d2VfCzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49BAMDA2gAMGUC +MQDmnw8AzNnmeTiYHrZ+OEA/B/0zWihVNnYfKNu/w2JHm/HU2qva4QE/R2GBO9/y +4gUCMHaum1b9UiyNKiL42iXFJsxGrMk6t6H1AMezUW1LCZ2CtpG4RoHu+58rDkxd +g7cIHg== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICCjCCAY+gAwIBAgIIMipjW007xFMwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTQ1WhcNMjUw +NjIwMDE1OTQ1WjBuMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEpMCcGA1UEAwwgQXBwbGlj +YXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwdjAQBgcqhkjOPQIBBgUrgQQAIgNi +AATLg4+9LgxPwCfIsp050P7tvEvX8ZlHG7mG/yq+HsuzfTwA4/W/Or//+GMRYBU0 +4jHEGz+1cweBMus3DQtDcZ8PvmwgIttsnSgdFd6GCPKgwM3Ta9KzV2DDBj2bKrDq +Rt2jEzARMA8GA1UdEwQIMAYBAf8CAQAwCgYIKoZIzj0EAwMDaQAwZgIxAO6f5uDX +AfsA6lUZI11CrR/wMlJYsrjDNdQ3UzX/nH7ixFHylcEZnTQNMGrdgpj2OwIxAPdt +0JOzD1OrrB4rUe8vJNWVd57vHnBJnxuGY/+c+h4U2oEVhPcOL90Z6ypb6F6naQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB8DCCAXagAwIBAgIIHjNgndejADUwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTI5WhcNMjUw +NjIwMDE1OTI5WjBVMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEQMA4GA1UEAwwHUm9vdCBD +QTB2MBAGByqGSM49AgEGBSuBBAAiA2IABPRSEXb5kd/pbMQx8JILcIjjj+Vk4MvE +vU79vdf79omd5CWpA8JAfovO4myNvqKFCHI/eQkhE0ao6TmcOjAU6h6R/WW4HocI +sVo4+OrefbWc/IshUmlFqo4mAk2J5LWNIKMTMBEwDwYDVR0TBAgwBgEB/wIBADAK +BggqhkjOPQQDAwNoADBlAjAflguU+S0NN1GKSVK9PZwsoehgHelD6sMTLzK+L6cN +M6jRPIJ6Bg5/rU1nEkf8SGECMQC07fkIu22nIA97zVfgDBK6RZlQs6siUVrmHTi4 +anzAfRrTOGpx37l7Q5S7U5SzSlA= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-sign-srv-ca1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..e8377c64ebfbc427c55efb95a212455a6834ecef --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app-sign-srv-ca1.cer @@ -0,0 +1,45 @@ +C=CN, O=OpenHarmony, OU=OpenHarmony Community, CN=App1 Release +-----BEGIN CERTIFICATE----- +MIICcDCCAfagAwIBAgIIdLvvPjsiK7EwCgYIKoZIzj0EAwMwbjELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxKTAnBgNVBAMMIEFwcGxpY2F0aW9uIFNpZ25hdHVyZSBTZXJ2aWNl +IENBMB4XDTI0MDYyMDAyMDE0NloXDTI1MDYyMDAyMDE0NlowWjELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxFTATBgNVBAMMDEFwcDEgUmVsZWFzZTB2MBAGByqGSM49AgEGBSuB +BAAiA2IABPvdywSeJDzxgHxB/UUtg8CCsBgmeIyH2JNDSaEDyyM5UgX1HcUhGhjB +0XijxCp3Dh6xGVTEEtTStGqL3DFm2aIm8YIr1NuxUhaNjdiGzLV0aLCFaC0QBx8z ++sOhoUId0aN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAww +CgYIKwYBBQUHAwMwJwYDVR0OBCAJGPL8NRaTn4xhcJUbKKMLS47KqeVIHKrY9UHw +d2VfCzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49BAMDA2gAMGUC +MQDmnw8AzNnmeTiYHrZ+OEA/B/0zWihVNnYfKNu/w2JHm/HU2qva4QE/R2GBO9/y +4gUCMHaum1b9UiyNKiL42iXFJsxGrMk6t6H1AMezUW1LCZ2CtpG4RoHu+58rDkxd +g7cIHg== +-----END CERTIFICATE----- +C=CN, O=OpenHarmony, OU=OpenHarmony Community, CN=Application Signature Service CA +-----BEGIN CERTIFICATE----- +MIICCjCCAY+gAwIBAgIIMipjW007xFMwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTQ1WhcNMjUw +NjIwMDE1OTQ1WjBuMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEpMCcGA1UEAwwgQXBwbGlj +YXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwdjAQBgcqhkjOPQIBBgUrgQQAIgNi +AATLg4+9LgxPwCfIsp050P7tvEvX8ZlHG7mG/yq+HsuzfTwA4/W/Or//+GMRYBU0 +4jHEGz+1cweBMus3DQtDcZ8PvmwgIttsnSgdFd6GCPKgwM3Ta9KzV2DDBj2bKrDq +Rt2jEzARMA8GA1UdEwQIMAYBAf8CAQAwCgYIKoZIzj0EAwMDaQAwZgIxAO6f5uDX +AfsA6lUZI11CrR/wMlJYsrjDNdQ3UzX/nH7ixFHylcEZnTQNMGrdgpj2OwIxAPdt +0JOzD1OrrB4rUe8vJNWVd57vHnBJnxuGY/+c+h4U2oEVhPcOL90Z6ypb6F6naQ== +-----END CERTIFICATE----- +C=CN, O=OpenHarmony, OU=OpenHarmony Community, CN=Root CA +-----BEGIN CERTIFICATE----- +MIIB8DCCAXagAwIBAgIIHjNgndejADUwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTI5WhcNMjUw +NjIwMDE1OTI5WjBVMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEQMA4GA1UEAwwHUm9vdCBD +QTB2MBAGByqGSM49AgEGBSuBBAAiA2IABPRSEXb5kd/pbMQx8JILcIjjj+Vk4MvE +vU79vdf79omd5CWpA8JAfovO4myNvqKFCHI/eQkhE0ao6TmcOjAU6h6R/WW4HocI +sVo4+OrefbWc/IshUmlFqo4mAk2J5LWNIKMTMBEwDwYDVR0TBAgwBgEB/wIBADAK +BggqhkjOPQQDAwNoADBlAjAflguU+S0NN1GKSVK9PZwsoehgHelD6sMTLzK+L6cN +M6jRPIJ6Bg5/rU1nEkf8SGECMQC07fkIu22nIA97zVfgDBK6RZlQs6siUVrmHTi4 +anzAfRrTOGpx37l7Q5S7U5SzSlA= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app1.cer new file mode 100644 index 0000000000000000000000000000000000000000..c332e85883619777d1fe2ebce26768cef52b41cc --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/app1.cer @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIICcDCCAfagAwIBAgIIHmJ8z14Mep0wCgYIKoZIzj0EAwMwbjELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxKTAnBgNVBAMMIEFwcGxpY2F0aW9uIFNpZ25hdHVyZSBTZXJ2aWNl +IENBMB4XDTI0MDYyMDAyMDEzM1oXDTI1MDYyMDAyMDEzM1owWjELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxFTATBgNVBAMMDEFwcDEgUmVsZWFzZTB2MBAGByqGSM49AgEGBSuB +BAAiA2IABPvdywSeJDzxgHxB/UUtg8CCsBgmeIyH2JNDSaEDyyM5UgX1HcUhGhjB +0XijxCp3Dh6xGVTEEtTStGqL3DFm2aIm8YIr1NuxUhaNjdiGzLV0aLCFaC0QBx8z ++sOhoUId0aN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAww +CgYIKwYBBQUHAwMwJwYDVR0OBCAJGPL8NRaTn4xhcJUbKKMLS47KqeVIHKrY9UHw +d2VfCzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49BAMDA2gAMGUC +MBi90BmacOREDzbb8a3aZbfP0LlvnImsDHLpWyAezrCp3071sa1cJWebI03v2Yvc +wgIxAP2cx3PVqdKJST3XBno2lNlq8AN5y/pvpxIV4nVMN0UkssKuGCRU/nJPlHKq +kbazKw== +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/entry-default-signed-so.txt b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/entry-default-signed-so.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e7e3c83e2044ba21f5b53224f3df55b51b6f6e3 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/entry-default-signed-so.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/phone-default-unsigned.txt b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/phone-default-unsigned.txt new file mode 100644 index 0000000000000000000000000000000000000000..0b855719afc7ea3e9cb81397bd54c8fc80300cc6 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/phone-default-unsigned.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile-release1.pem b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..134b66ed26740925cbe501c0b6d020a8d2ce129b --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile-release1.pem @@ -0,0 +1,42 @@ +-----BEGIN CERTIFICATE----- +MIICcTCCAfagAwIBAgIInhCsamtu33cwCgYIKoZIzj0EAwMwajELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxJTAjBgNVBAMMHFByb2ZpbGUgU2lnbmF0dXJlIFNlcnZpY2UgQ0Ew +HhcNMjQwNjIwMDIwMzA4WhcNMjUwNjIwMDIwMzA4WjBeMQswCQYDVQQGEwJDTjEU +MBIGA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11 +bml0eTEZMBcGA1UEAwwQUHJvZmlsZTEgUmVsZWFzZTB2MBAGByqGSM49AgEGBSuB +BAAiA2IABPYN7x4f//G5AuyDqCKLHzKfV8blYAtiyD+xlhx6wRPNA/NJkfT2zKjZ +HiYqShkd92x13xuJF2M2UDtoRcNEiXCJ8n9WE9nYW7GU28spf1GMepDMSfd0E+Bh +d4SEoILoXaN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAww +CgYIKwYBBQUHAwMwJwYDVR0OBCAbo/UsGYKduf7oGQKZQv7PBNvtiL7PbAG3/+fY +x5DmVDAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqGSM49BAMDA2kAMGYC +MQDu2Y2eU4CwMgHfKZLhJ12PzunPTRejp02NY39JlgHM+pwPaU/1OneTourI7g+f +P68CMQDGyIEDbQ3z41SO/0PqUHRN4jlJ3juv4D3DM09Gt+c9dEQZmMMGMzsqB8Hr +o1N6HQg= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICBjCCAYugAwIBAgII6495SBCPeyowCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTU2WhcNMjUw +NjIwMDE1OTU2WjBqMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTElMCMGA1UEAwwcUHJvZmls +ZSBTaWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABJwY +OcX3IPb4BC8cEFnFYEv+6b3Ko9fiVBUdrtFfYSEJQxucIacrSopp9QU60UR2rEGO +DlbhdMnyr4nl9S7JmI8Z/EIY+7kUCM3LR5V9RTrA8SKPFpNyaxEo9h4ADlvb6qMT +MBEwDwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNpADBmAjEA/unF2UH+IB60 ++9RucjEAEXtSWsaabogqiHSZfs8CRsPEqK9cjyPNijfizI1aUFKEAjEAtm8eEivF +nk1uxrd9SAf0FgnW5i28IPfMCLoQ5P2fjYlLZBn1g6N95UM9ZKFuV6OE +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB8DCCAXagAwIBAgIIHjNgndejADUwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTI5WhcNMjUw +NjIwMDE1OTI5WjBVMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEQMA4GA1UEAwwHUm9vdCBD +QTB2MBAGByqGSM49AgEGBSuBBAAiA2IABPRSEXb5kd/pbMQx8JILcIjjj+Vk4MvE +vU79vdf79omd5CWpA8JAfovO4myNvqKFCHI/eQkhE0ao6TmcOjAU6h6R/WW4HocI +sVo4+OrefbWc/IshUmlFqo4mAk2J5LWNIKMTMBEwDwYDVR0TBAgwBgEB/wIBADAK +BggqhkjOPQQDAwNoADBlAjAflguU+S0NN1GKSVK9PZwsoehgHelD6sMTLzK+L6cN +M6jRPIJ6Bg5/rU1nEkf8SGECMQC07fkIu22nIA97zVfgDBK6RZlQs6siUVrmHTi4 +anzAfRrTOGpx37l7Q5S7U5SzSlA= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile-sign-srv-ca1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..747fdecd349fd49771bb4561253c3e0258328d57 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICBjCCAYugAwIBAgII6495SBCPeyowCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTU2WhcNMjUw +NjIwMDE1OTU2WjBqMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTElMCMGA1UEAwwcUHJvZmls +ZSBTaWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABJwY +OcX3IPb4BC8cEFnFYEv+6b3Ko9fiVBUdrtFfYSEJQxucIacrSopp9QU60UR2rEGO +DlbhdMnyr4nl9S7JmI8Z/EIY+7kUCM3LR5V9RTrA8SKPFpNyaxEo9h4ADlvb6qMT +MBEwDwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNpADBmAjEA/unF2UH+IB60 ++9RucjEAEXtSWsaabogqiHSZfs8CRsPEqK9cjyPNijfizI1aUFKEAjEAtm8eEivF +nk1uxrd9SAf0FgnW5i28IPfMCLoQ5P2fjYlLZBn1g6N95UM9ZKFuV6OE +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile.json b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile.json new file mode 100644 index 0000000000000000000000000000000000000000..824028a6d187a81b9a5d5b02c0491381f5227f10 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile.json @@ -0,0 +1,31 @@ +{ + "version-name": "1.0.0", + "version-code": 1, + "uuid": "fe686e1b-3770-4824-a938-961b140a7c98", + "validity": { + "not-before": 1610519532, + "not-after": 1705127532 + }, + "type": "debug", + "bundle-info": { + "developer-id": "OpenHarmony", + "development-certificate": "-----BEGIN CERTIFICATE-----\nMIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\nMjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\nodSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\nUYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\no2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\nBQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\nAwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\nQT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\n4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\n-----END CERTIFICATE-----\n", + "bundle-name": "com.example.nativetemplatedemo", + "app-feature": "hos_system_app" + }, + "permissions": { + "restricted-permissions": [ + "" + ] + }, + "debug-info": { + "device-ids": [ + "69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42", + "7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865" + ], + "device-id-type": "udid" + }, + "issuer": "pki_internal" +} + + diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile1.cer new file mode 100644 index 0000000000000000000000000000000000000000..5436533ae100dab2015307f2ec75cb85f1a31779 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/profile1.cer @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIICcTCCAfagAwIBAgIIdhxAKFh1HDkwCgYIKoZIzj0EAwMwajELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxJTAjBgNVBAMMHFByb2ZpbGUgU2lnbmF0dXJlIFNlcnZpY2UgQ0Ew +HhcNMjQwNjIwMDIwMjUwWhcNMjUwNjIwMDIwMjUwWjBeMQswCQYDVQQGEwJDTjEU +MBIGA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11 +bml0eTEZMBcGA1UEAwwQUHJvZmlsZTEgUmVsZWFzZTB2MBAGByqGSM49AgEGBSuB +BAAiA2IABPYN7x4f//G5AuyDqCKLHzKfV8blYAtiyD+xlhx6wRPNA/NJkfT2zKjZ +HiYqShkd92x13xuJF2M2UDtoRcNEiXCJ8n9WE9nYW7GU28spf1GMepDMSfd0E+Bh +d4SEoILoXaN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCB4AwEwYDVR0lBAww +CgYIKwYBBQUHAwMwJwYDVR0OBCAbo/UsGYKduf7oGQKZQv7PBNvtiL7PbAG3/+fY +x5DmVDAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqGSM49BAMDA2kAMGYC +MQDKxJjPW4PzF8pUUYXPGaDzB58/vTyg62B/2lTVBd+uDKrbDe1zGrnVs3jzl+Ie +uQ4CMQDdzSw28YMOTvzFlyFPIhwiGTqY6hIj9LWbm3mD8iLB/lcfTuK4sqwe4OIl +nh9CBS0= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/root-ca1.cer b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/root-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..2578de8d51c12e6e963b1cc23bfee54c6da82b5e --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/root-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB8DCCAXagAwIBAgIIHjNgndejADUwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjIwMDE1OTI5WhcNMjUw +NjIwMDE1OTI5WjBVMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEQMA4GA1UEAwwHUm9vdCBD +QTB2MBAGByqGSM49AgEGBSuBBAAiA2IABPRSEXb5kd/pbMQx8JILcIjjj+Vk4MvE +vU79vdf79omd5CWpA8JAfovO4myNvqKFCHI/eQkhE0ao6TmcOjAU6h6R/WW4HocI +sVo4+OrefbWc/IshUmlFqo4mAk2J5LWNIKMTMBEwDwYDVR0TBAgwBgEB/wIBADAK +BggqhkjOPQQDAwNoADBlAjAflguU+S0NN1GKSVK9PZwsoehgHelD6sMTLzK+L6cN +M6jRPIJ6Bg5/rU1nEkf8SGECMQC07fkIu22nIA97zVfgDBK6RZlQs6siUVrmHTi4 +anzAfRrTOGpx37l7Q5S7U5SzSlA= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-bin.txt b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-bin.txt new file mode 100644 index 0000000000000000000000000000000000000000..82962570642ecb4af69fc86d07960e104e446889 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-bin.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-elf.txt b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-elf.txt new file mode 100644 index 0000000000000000000000000000000000000000..237bd8e7223b7240b2e4483920f8d0e8e50d16ef Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-elf.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-profile.p7b b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..8a5ba8ecdf9bb9148f823f9c556a1f42eb970205 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/generate_keypair/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/hap_sign/app-release1.pem b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..808e5d708074d6b7c065ce117fb500bf5e26efed --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/app-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNTE4MDQ1MzQzWhcNMjUwNTE4MDQ1MzQzWjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE ++04w+5zGqED2KchTGuk2elEN4fm2o25Se6PKYckLisCGVFfHsBI82YV+5ZuHWWlQ +g41Vjg4zoZMaZZB9aRoS/WJF7WqdmIj0Z3oR2hKjuK1KFE84HZJtSvhv73kFDy93 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFOByt27GaQS0FI1YSgi305J803ouMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDZwAwZAIwFJc69hPcTKT6laW6dv6PTs9Z +hZfhFHdxmvZUPSc9BpC66euaa3x4Qog6Ud1v5GHtAjByFfBhxwQ7MKVqpqgHYznK +F6AGNITX1Uu7F+78l/VdqjUnBagHf+A4zpkP+96sXv8= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICAzCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUyMDZaFw0yNTA1MTgwNDUy +MDZaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGOgpW8s +Sc7ed3633LQVYKSBAxLgv1h8UlQqUPBCFdht+d2DeyjVG3cUM3C0+SHiBGYE1Y6/ +gPM8avBXjedRxZkWj4L3+vwqbE2EyToS9haJK5zFiEYMSapQ0fw46kTAYaMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNpADBmAjEAwfpd7dzUzjJLypyg +/gcCmwn8JG845RU2p5XSF3NGx25eRF5CjOBMutMOwMCh6k+WAjEAyiefVEkXRox6 +/9BGyNQxE4vijOR9P8KPbHhWqa1AxMf3n9Ub/GtrCl+bKh7xdfcK +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUwNDJaFw0yNTA1MTgwNDUw +NDJaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEQrLv/IWf/6m6OL+EUzHWuknOv9USUsfq/B9z2lKP +8dXyDIOI2N5gNbSRZuSLQVY8XNjUjRfCoNSQXG5NCy4AG863AVsLbIrU7WSclDxi +O3teTpfuYCdRy0tDk6dxSXWloxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2kAMGYCMQDDTXyRxZOe5WpPSrqVILmI8rkL2TQB4j7NoYZXCKQ3HMj66Ct7 +wNASFAHlxOBnztcCMQCYAoo9nyo4fKvFIiWFbXraPJ4AX9a2cZwvOM/P1kVyrxX2 +6sKc2Qw5Y1A0avI1saQ= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/hap_sign/app1-profile1.p7b b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/app1-profile1.p7b new file mode 100644 index 0000000000000000000000000000000000000000..dcaaaf2b90c023ca233c0ca2bd4e8962e58cb731 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/app1-profile1.p7b differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/hap_sign/ohtest.jks b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/ohtest.jks new file mode 100644 index 0000000000000000000000000000000000000000..dbc3c40df72f07d938d3588bc6b5b25d932ae787 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/ohtest.jks differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/hap_sign/ohtest.p12 b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f3eae4d373faa3caff06021db21786f81d7af92f Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/hap_sign/signed-profile.p7b b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7e8192a1fc8376cbc49ee3a5fba5f173e48d0c08 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/hap_sign/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/ohos_test.xml b/hapsigntool_cpp/test/fuzztest/resource/ohos_test.xml new file mode 100644 index 0000000000000000000000000000000000000000..645a6db129253238ca2e9f02fe88e489d1498414 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/ohos_test.xml @@ -0,0 +1,321 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hapsigntool_cpp/test/fuzztest/resource/remote_signer/OpenHarmony.p12 b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/OpenHarmony.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f3eae4d373faa3caff06021db21786f81d7af92f Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/OpenHarmony.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/remote_signer/app-release1.pem b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..808e5d708074d6b7c065ce117fb500bf5e26efed --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/app-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNTE4MDQ1MzQzWhcNMjUwNTE4MDQ1MzQzWjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE ++04w+5zGqED2KchTGuk2elEN4fm2o25Se6PKYckLisCGVFfHsBI82YV+5ZuHWWlQ +g41Vjg4zoZMaZZB9aRoS/WJF7WqdmIj0Z3oR2hKjuK1KFE84HZJtSvhv73kFDy93 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFOByt27GaQS0FI1YSgi305J803ouMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDZwAwZAIwFJc69hPcTKT6laW6dv6PTs9Z +hZfhFHdxmvZUPSc9BpC66euaa3x4Qog6Ud1v5GHtAjByFfBhxwQ7MKVqpqgHYznK +F6AGNITX1Uu7F+78l/VdqjUnBagHf+A4zpkP+96sXv8= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICAzCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUyMDZaFw0yNTA1MTgwNDUy +MDZaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGOgpW8s +Sc7ed3633LQVYKSBAxLgv1h8UlQqUPBCFdht+d2DeyjVG3cUM3C0+SHiBGYE1Y6/ +gPM8avBXjedRxZkWj4L3+vwqbE2EyToS9haJK5zFiEYMSapQ0fw46kTAYaMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNpADBmAjEAwfpd7dzUzjJLypyg +/gcCmwn8JG845RU2p5XSF3NGx25eRF5CjOBMutMOwMCh6k+WAjEAyiefVEkXRox6 +/9BGyNQxE4vijOR9P8KPbHhWqa1AxMf3n9Ub/GtrCl+bKh7xdfcK +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUwNDJaFw0yNTA1MTgwNDUw +NDJaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEQrLv/IWf/6m6OL+EUzHWuknOv9USUsfq/B9z2lKP +8dXyDIOI2N5gNbSRZuSLQVY8XNjUjRfCoNSQXG5NCy4AG863AVsLbIrU7WSclDxi +O3teTpfuYCdRy0tDk6dxSXWloxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2kAMGYCMQDDTXyRxZOe5WpPSrqVILmI8rkL2TQB4j7NoYZXCKQ3HMj66Ct7 +wNASFAHlxOBnztcCMQCYAoo9nyo4fKvFIiWFbXraPJ4AX9a2cZwvOM/P1kVyrxX2 +6sKc2Qw5Y1A0avI1saQ= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/remote_signer/raw.txt b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/raw.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f2aefe5aab434337439e188d136a2f272378327 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/raw.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/remote_signer/signed-profile.p7b b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..e93127913fb04430028a26853bf3bfb97c9ec259 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/remote_signer/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/VerifyResult.json b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/VerifyResult.json new file mode 100644 index 0000000000000000000000000000000000000000..d739a9edb6ba9a0d99656be91f515b0b0f75f134 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/VerifyResult.json @@ -0,0 +1 @@ +{"bundle-info":{"app-feature":"hos_system_app","bundle-name":"com.OpenHarmony.app.test","developer-id":"OpenHarmony","development-certificate":"-----BEGIN CERTIFICATE-----\nMIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\nMRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\nbTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\nMTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\nT3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\nH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\nhkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\nJwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\nFtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\ncRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\nLMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\nzAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\n-----END CERTIFICATE-----\n"},"debug-info":{"device-id-type":"udid","device-ids":["69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42","7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865"]},"issuer":"pki_internal","permissions":{"restricted-permissions":[""]},"type":"debug","uuid":"fe686e1b-3770-4824-a938-961b140a7c98","validity":{"not-after":1705127532,"not-before":1610519532},"version-code":1,"version-name":"1.0.0"} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/app-release1.pem b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..64322d39adb55e6486fd19c9773daef2dd92cd0c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/app-release1.pem @@ -0,0 +1,37 @@ +-----BEGIN CERTIFICATE----- +MIICLDCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNjA2MDc1MzI0WhcNMjUwNjA2MDc1MzI0WjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEkJ4RF7ebnhY5Cc2FzVyDnFFXl3SxAMho5HQroZOM8QInRs1ubLydHG3NNDez +8SADEI3DxwXqsCPi5YbyRWUrf6N1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCCp/sVxEKanJIj73eDH6T3D +7TdUnSd+kcMD6U0QEQhauDAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA0gAMEUCIQDqbwU7TqVEY2TWgXfZ1spYNtYxzraUEN+W/7spc2G1zAIg +YknxDuAbsw4hrZTfrbTuWO/6nI1HdBYVBhEM05IxLZI= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIBxTCCAWugAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABOUp +vD1yP1PHhPqBXXC+pnRWZopd2bifQcvWuG+KnHvbcG7kQlcdjNU4/IPgXKZQ74Wf +YUZgQ7IWZvDIDxp93Z6jEzARMA8GA1UdEwQIMAYBAf8CAQAwCgYIKoZIzj0EAwMD +SAAwRQIgUhVySRrw7Ig717JSe4XcZXw9PAtiVhBQSsZZZF2YmPICIQDqzPBMwiF/ +oIsBeSDgCPWKy7+j5P/1gNhf9Ddp8tnsMg== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIBrDCCAVKgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMFkwEwYH +KoZIzj0CAQYIKoZIzj0DAQcDQgAEF4naj8HotEn5337K9ldrVLO7xSL6NDeNwU9c +Fzsj0VDwHcmD4HvVm6FqVBfaGHEsGEDi7ufWXlxvoCV7pFjn+KMTMBEwDwYDVR0T +BAgwBgEB/wIBADAKBggqhkjOPQQDAwNIADBFAiArWW1W/IL20Z/b/yJDO45CjDxY +jlsZf6AWijIry4frqgIhAMmBmdrFnRRgI4BMOZOEBBjrhiG/5gciCpmzvBoW6Fxr +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/ohtest.p12 b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..44a50f48592fd283cdfd00d2222dbea44c1403fd Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-cert.pem b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..ee4dd109f0a556f724db4d3d9f4ed6cedf57d3d1 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-cert.pem @@ -0,0 +1,15 @@ +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-invalid_cert_chain.pem b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-invalid_cert_chain.pem new file mode 100644 index 0000000000000000000000000000000000000000..8f02c93a849f0ca6795abc926e4c6ba2df9edc07 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-invalid_cert_chain.pem @@ -0,0 +1,30 @@ +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-reverse.pem b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-reverse.pem new file mode 100644 index 0000000000000000000000000000000000000000..030f7e553360cf627bd84598d81eb81f48c99c19 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1-reverse.pem @@ -0,0 +1,39 @@ +-----BEGIN CERTIFICATE----- +MIIBrDCCAVKgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMFkwEwYH +KoZIzj0CAQYIKoZIzj0DAQcDQgAEF4naj8HotEn5337K9ldrVLO7xSL6NDeNwU9c +Fzsj0VDwHcmD4HvVm6FqVBfaGHEsGEDi7ufWXlxvoCV7pFjn+KMTMBEwDwYDVR0T +BAgwBgEB/wIBADAKBggqhkjOPQQDAwNIADBFAiArWW1W/IL20Z/b/yJDO45CjDxY +jlsZf6AWijIry4frqgIhAMmBmdrFnRRgI4BMOZOEBBjrhiG/5gciCpmzvBoW6Fxr +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB3jCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAELvqlDXjWHD86 +XCO0aCnPNfIdLl+4ZuMLYToVZQaspe8JWREqw+XnQsO3b7Mzpxidq5oqCa52p73p +Y8+VjBIqVoz70A1JhElNv2FXYU7Kl6KVLCmD8IDADcPxcbOh6x8roxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA0gAMEUCIBwN2f5691S3Xthkv5D1OI5I +vcBpEuDgRe6ReW4ANTRqAiEAmiU1r7eCagnSDGqUfhokh8pXzq8p/DZKg+x1IaP+ +ao4= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1.pem b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..2d2bfa342457be8953c460014443ad3753e6e122 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile-release1.pem @@ -0,0 +1,39 @@ +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB3jCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAELvqlDXjWHD86 +XCO0aCnPNfIdLl+4ZuMLYToVZQaspe8JWREqw+XnQsO3b7Mzpxidq5oqCa52p73p +Y8+VjBIqVoz70A1JhElNv2FXYU7Kl6KVLCmD8IDADcPxcbOh6x8roxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA0gAMEUCIBwN2f5691S3Xthkv5D1OI5I +vcBpEuDgRe6ReW4ANTRqAiEAmiU1r7eCagnSDGqUfhokh8pXzq8p/DZKg+x1IaP+ +ao4= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIBrDCCAVKgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMFkwEwYH +KoZIzj0CAQYIKoZIzj0DAQcDQgAEF4naj8HotEn5337K9ldrVLO7xSL6NDeNwU9c +Fzsj0VDwHcmD4HvVm6FqVBfaGHEsGEDi7ufWXlxvoCV7pFjn+KMTMBEwDwYDVR0T +BAgwBgEB/wIBADAKBggqhkjOPQQDAwNIADBFAiArWW1W/IL20Z/b/yJDO45CjDxY +jlsZf6AWijIry4frqgIhAMmBmdrFnRRgI4BMOZOEBBjrhiG/5gciCpmzvBoW6Fxr +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile.json b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile.json new file mode 100644 index 0000000000000000000000000000000000000000..d4f3bbf71e34cd8f7ed1bcdb7837c3083ccc948f --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/profile.json @@ -0,0 +1,29 @@ +{ + "version-name": "1.0.0", + "version-code": 1, + "uuid": "fe686e1b-3770-4824-a938-961b140a7c98", + "validity": { + "not-before": 1610519532, + "not-after": 1705127532 + }, + "type": "debug", + "bundle-info": { + "developer-id": "OpenHarmony", + "development-certificate": "-----BEGIN CERTIFICATE-----\nMIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\nMRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\nbTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\nMTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\nT3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\nH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\nhkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\nJwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\nFtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\ncRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\nLMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\nzAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\n-----END CERTIFICATE-----\n", + "bundle-name": "com.OpenHarmony.app.test", + "app-feature": "hos_system_app" + }, + "permissions": { + "restricted-permissions": [ + "" + ] + }, + "debug-info": { + "device-ids": [ + "69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42", + "7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865" + ], + "device-id-type": "udid" + }, + "issuer": "pki_internal" +} diff --git a/hapsigntool_cpp/test/fuzztest/resource/sign_profile/signed-profile.p7b b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..95297c4151068245e54592df7933f863b97c10b5 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/sign_profile/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/zip/data_descriptor_hap.txt b/hapsigntool_cpp/test/fuzztest/resource/zip/data_descriptor_hap.txt new file mode 100644 index 0000000000000000000000000000000000000000..ded3f02c25ab2083d7fb92d50c46c9d616ce347c Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/zip/data_descriptor_hap.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/zip/raw.txt b/hapsigntool_cpp/test/fuzztest/resource/zip/raw.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f2aefe5aab434337439e188d136a2f272378327 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/zip/raw.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/resource/zip/whole.txt b/hapsigntool_cpp/test/fuzztest/resource/zip/whole.txt new file mode 100644 index 0000000000000000000000000000000000000000..8708accf5ecf14a87edde514e4433ba6d0cfe974 Binary files /dev/null and b/hapsigntool_cpp/test/fuzztest/resource/zip/whole.txt differ diff --git a/hapsigntool_cpp/test/fuzztest/utils/BUILD.gn b/hapsigntool_cpp/test/fuzztest/utils/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..afa9283cff7de70f3febdfa66c5403f46f3b5f5d --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/utils/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("utils_fuzztest") { + testonly = true + deps = [ "./hapsignerblockutils_fuzzer:HapSignerBlockUtilsFuzzTest" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6cb68c874a6b30a2e2d1d41edb856d683b3f004d --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("HapSignerBlockUtilsFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ "hapsignerblockutils_fuzzer.cpp" ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..f7880ef1a502193121ec4b74e27bfc616e66cd26 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..9e45756ac98b3d80fc6acc3b495a5ff981d636c9 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "hap_signer_block_utils.h" + +using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { +const std::string pathFile = "./zip/tmp.hap"; +void HapSignerBlockUtilsFunc(const uint8_t* data, size_t size) +{ + SignatureInfo info; + HapSignerBlockUtils::CreatTestZipFile(pathFile, info); + + HapSubSignBlockHead signBlock; + HapSubSignBlockHead profileBlock; + HapSubSignBlockHead propertyBlock; + HapSignerBlockUtils::CreateHapSubSignBlockHead(signBlock, profileBlock, propertyBlock); +} + +void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + + HapSignerBlockUtilsFunc(data, size); +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..49b206d709244e95ae18d9629d8bd4c5538c7196 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/utils/hapsignerblockutils_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 60 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/zip/BUILD.gn b/hapsigntool_cpp/test/fuzztest/zip/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..775cb9baf105b1f127cd346fd6f73e2aed781f83 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("zip_fuzztest") { + testonly = true + deps = [ + "./randomaccessfileinputoutput_fuzzer:RandomAccessFileInputOutputFuzzTest", + "./zipsigner_fuzzer:ZipSignerFuzzTest", + ] +} diff --git a/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..56e57d080b0bdcffaa34f839733f24bc1727c7f3 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("RandomAccessFileInputOutputFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ + "randomaccessfileinputoutput_fuzzer.cpp", + ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..f7880ef1a502193121ec4b74e27bfc616e66cd26 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..49b206d709244e95ae18d9629d8bd4c5538c7196 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 60 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6e360d48612188ecb0f402d3ac4265db55a4e99c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "random_access_file.h" +#include "random_access_file_input.h" +#include "random_access_file_output.h" + +using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { + +const char* g_rawHapFilePath = "./zip/raw.hap"; +void RandomAccessFileReadFileFunc(const uint8_t* data, size_t size) +{ + auto outputHap = std::make_shared(); + if (!outputHap->Init(g_rawHapFilePath)) { + return; + } + std::string buf(1, 0); + outputHap->ReadFileFullyFromOffset(buf.data(), 0, 1); +} + +void RandomAccessFileInputConstructor(const uint8_t* data, size_t size) +{ + RandomAccessFile file; + if (!file.Init(g_rawHapFilePath)) { + return; + } + int64_t fileLength = file.GetLength(); + RandomAccessFileInput fileInput(file, 0, fileLength); + fileInput.Size(); +} + +void RandomAccessFileOutputConstructor(const uint8_t* data, size_t size) +{ + RandomAccessFile file; + if (!file.Init(g_rawHapFilePath)) { + return; + } + RandomAccessFileOutput fileOutput(&file); +} + +void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + + RandomAccessFileReadFileFunc(data, size); + RandomAccessFileInputConstructor(data, size); + RandomAccessFileOutputConstructor(data, size); +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + (void)rename("./zip/raw.txt", g_rawHapFilePath); + sync(); + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/BUILD.gn b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8394af067f1143c1f5ef9b9c36367a9aa27cfb0c --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../signature_tools.gni") +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_fuzztest("ZipSignerFuzzTest") { + testonly = true + module_out_path = module_out_path + fuzz_config_file = "." + resource_config_file = + "${signature_tools_test}/fuzztest/resource/ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ + "zipsigner_fuzzer.cpp", + ] + + deps = [ "${signature_tools_test}:service_target" ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] +} diff --git a/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/corpus/init b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..f7880ef1a502193121ec4b74e27bfc616e66cd26 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/project.xml b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..49b206d709244e95ae18d9629d8bd4c5538c7196 --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 60 + + 4096 + + diff --git a/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4f4d206fb609fced6b589934037ec998091c9dd --- /dev/null +++ b/hapsigntool_cpp/test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "zip_signer.h" + +using namespace OHOS::SignatureTools; +namespace OHOS { +namespace SignatureTools { +static constexpr int ALIGNMENT = 4; +const char* g_rawHapFilePath = "./zip/raw.hap"; +const char* g_wholeHapFilePath = "./zip/whole.hap"; +const char* g_outHapFilePath = "./zip/signed.hap"; +const char* g_dataDescHapFilePath = "./zip/data_descriptor_hap.hap"; + +void ZipSignerCompleteFlowFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_wholeHapFilePath, std::ios::binary); + std::ofstream outputFile(g_outHapFilePath, std::ios::binary | std::ios::trunc); + auto zip = std::make_shared(); + if (!zip->Init(inputFile)) { + return; + } + zip->Alignment(ALIGNMENT); + zip->RemoveSignBlock(); + zip->ToFile(inputFile, outputFile); +} + +void ZipSignerInfoFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_wholeHapFilePath, std::ios::binary); + auto zip = std::make_shared(); + if (!zip->Init(inputFile)) { + return; + } + std::vector zipEntries{nullptr}; + zip->SetZipEntries(zipEntries); + zip->SetSigningOffset(size); + std::string signingBlock(reinterpret_cast(data), size); + zip->SetSigningBlock(signingBlock); + zip->SetCDOffset(size); + zip->SetEOCDOffset(size); + zip->SetEndOfCentralDirectory(nullptr); + + zip->GetZipEntries(); + zip->GetSigningOffset(); + zip->GetSigningBlock(); + zip->GetCDOffset(); + zip->GetEOCDOffset(); + zip->GetEndOfCentralDirectory(); +} + +void ZipEntryHeaderInfoFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_wholeHapFilePath, std::ios::binary); + auto zip = std::make_shared(); + if (!zip->Init(inputFile)) { + return; + } + auto zipEntries = zip->GetZipEntries(); + for (const auto& zipEntry : zipEntries) { + auto zipEntryData = zipEntry->GetZipEntryData(); + auto zipEntryHeader = zipEntryData->GetZipEntryHeader(); + + std::string fileName(reinterpret_cast(data), size); + zipEntryHeader->SetFileName(fileName); + + zipEntryHeader->GetCrc32(); + zipEntryHeader->GetLastTime(); + zipEntryHeader->GetLastDate(); + zipEntryHeader->GetCompressedSize(); + zipEntryHeader->GetUnCompressedSize(); + zipEntryHeader->GetHeaderLength(); + zipEntryHeader->GetSIGNATURE(); + zipEntryHeader->GetVersion(); + } +} + +void CentralDirectoryInfoFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_rawHapFilePath, std::ios::binary); + auto zip = std::make_shared(); + if (!zip->Init(inputFile)) { + return; + } + auto zipEntries = zip->GetZipEntries(); + for (const auto& zipEntry : zipEntries) { + auto cd = zipEntry->GetCentralDirectory(); + cd->GetLength(); + cd->GetCdLength(); + cd->GetSIGNATURE(); + cd->GetVersion(); + cd->GetVersionExtra(); + cd->GetFlag(); + cd->GetLastTime(); + cd->GetLastDate(); + cd->GetCrc32(); + cd->GetDiskNumStart(); + cd->GetInternalFile(); + cd->GetExternalFile(); + cd->GetFileName(); + + std::string comment(reinterpret_cast(data), size); + cd->SetComment(comment); + + cd->GetComment(); + } +} + +void DataDescriptorInfoFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_dataDescHapFilePath, std::ios::binary); + auto zip = std::make_shared(); + if (!zip->Init(inputFile)) { + return; + } + auto zipEntries = zip->GetZipEntries(); + for (const auto& zipEntry : zipEntries) { + auto zipEntryData = zipEntry->GetZipEntryData(); + auto dataDescriptor = zipEntryData->GetDataDescriptor(); + if (!dataDescriptor) { + continue; + } + dataDescriptor->GetDesLength(); + dataDescriptor->GetSIGNATURE(); + dataDescriptor->GetCrc32(); + dataDescriptor->GetCompressedSize(); + dataDescriptor->GetUnCompressedSize(); + } +} + +void AlignmentFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_rawHapFilePath, std::ios::binary); + auto zip = std::make_shared(); + int aliBytes = 102400; + if (!zip->Init(inputFile)) { + return; + } + auto zipEntries = zip->GetZipEntries(); + for (const auto& zipEntry : zipEntries) { + zipEntry->Alignment(aliBytes); + } +} + +void EndOfCentralDirectoryInfoFunc(const uint8_t* data, size_t size) +{ + std::ifstream inputFile(g_rawHapFilePath, std::ios::binary); + auto zip = std::make_shared(); + if (!zip->Init(inputFile)) { + return; + } + auto eocd = zip->GetEndOfCentralDirectory(); + eocd->GetLength(); + eocd->GetEocdLength(); + eocd->GetSIGNATURE(); + eocd->GetDiskNum(); + eocd->GetcDStartDiskNum(); + eocd->GetThisDiskCDNum(); + + std::string comment(reinterpret_cast(data), size); + eocd->SetComment(comment); + + eocd->GetComment(); +} + +void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + + ZipSignerCompleteFlowFunc(data, size); + ZipSignerInfoFunc(data, size); + ZipEntryHeaderInfoFunc(data, size); + CentralDirectoryInfoFunc(data, size); + DataDescriptorInfoFunc(data, size); + AlignmentFunc(data, size); + EndOfCentralDirectoryInfoFunc(data, size); +} +} // namespace SignatureTools +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + (void)rename("./zip/data_descriptor_hap.txt", g_dataDescHapFilePath); + (void)rename("./zip/raw.txt", g_rawHapFilePath); + (void)rename("./zip/whole.txt", g_wholeHapFilePath); + sync(); + OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/.gitignore b/hapsigntool_cpp/test/unittest/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..259148fa18f9fb7ef58563f4ff15fc7b172339fb --- /dev/null +++ b/hapsigntool_cpp/test/unittest/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/hapsigntool_cpp/test/unittest/BUILD.gn b/hapsigntool_cpp/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cc41258326814df9e09d5309a85332f63c1aeabf --- /dev/null +++ b/hapsigntool_cpp/test/unittest/BUILD.gn @@ -0,0 +1,102 @@ +# Copyright (c) 2024-2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") +import("../../signature_tools.gni") + +module_out_path = "developtools/hapsigner/hapsigner_pc" + +ohos_unittest("hapsigntool_pc_unittest") { + testonly = true + module_out_path = module_out_path + resource_config_file = "ohos_test.xml" + + configs = [ "${signature_tools_test}:service_include" ] + + sources = [ + "./byteBuffer/byte_buffer_test.cpp", + "./codeSigning/datastructure/code_sign_block_header_test.cpp", + "./codeSigning/datastructure/code_sign_block_test.cpp", + "./codeSigning/datastructure/elf_sign_block_test.cpp", + "./codeSigning/datastructure/extension_test.cpp", + "./codeSigning/datastructure/fs_verity_info_segment_test.cpp", + "./codeSigning/datastructure/hap_info_segment_test.cpp", + "./codeSigning/datastructure/merkle_tree_extension_test.cpp", + "./codeSigning/datastructure/native_lib_info_segment_test.cpp", + "./codeSigning/datastructure/segment_header_test.cpp", + "./codeSigning/datastructure/sign_info_test.cpp", + "./codeSigning/datastructure/signed_file_pos_test.cpp", + "./codeSigning/fsverity/fs_verity_descriptor_test.cpp", + "./codeSigning/fsverity/fs_verity_descriptor_with_sign_test.cpp", + "./codeSigning/fsverity/fs_verity_digest_test.cpp", + "./codeSigning/fsverity/fs_verity_generator_test.cpp", + "./codeSigning/fsverity/fs_verity_hash_algorithm_test.cpp", + "./codeSigning/fsverity/merkle_tree_builder_test.cpp", + "./codeSigning/sign/bc_signeddata_generator_test.cpp", + "./codeSigning/sign/code_signing_test.cpp", + "./codeSigning/sign/verify_code_signature_test.cpp", + "./codeSigning/utils/cms_utils_test.cpp", + "./codeSigning/utils/fs_digest_utils_test.cpp", + "./elfVerify/hap_utils_test.cpp", + "./elfVerify/sign_block_info_test.cpp", + "./elfVerify/sign_content_info_test.cpp", + "./elfVerify/signature_block_types_test.cpp", + "./elfVerify/signing_block_test.cpp", + "./elfVerify/verify_bin_test.cpp", + "./elfVerify/verify_elf_test.cpp", + "./generateCA/generate_ca_test.cpp", + "./generateCA/generate_general_ca_test.cpp", + "./generateCA/generate_sub_ca_test.cpp", + "./generateCsr/generate_csr_test.cpp", + "./generateKeyPair/generate_keypair_test.cpp", + "./generateKeyPair/hap_sign_cmd_test.cpp", + "./generateKeyPair/hap_sign_tool_test.cpp", + "./generateKeyPair/options_test.cpp", + "./generateKeyPair/process_cmd_expansion_test.cpp", + "./generateKeyPair/process_cmd_test.cpp", + "./hapSign/hap_openssl_utils_test.cpp", + "./hapSign/hap_sign_test.cpp", + "./hapSign/hw_block_data_test.cpp", + "./hapSign/hw_block_head_test.cpp", + "./hapSign/hw_sign_head_test.cpp", + "./hapSign/sign_bin_test.cpp", + "./hapSign/sign_block_data_test.cpp", + "./hapSign/sign_elf_test.cpp", + "./hapSign/sign_provider_test.cpp", + "./hapVerify/hap_cert_verify_openssl_utils_test.cpp", + "./hapVerify/hap_signer_block_utils_test.cpp", + "./hapVerify/hap_verify_result_test.cpp", + "./hapVerify/hap_verify_test.cpp", + "./hapVerify/provision_verify_test.cpp", + "./hapVerify/random_access_file_test.cpp", + "./remoteSigner/remote_signer_test.cpp", + "./signProfile/pkcs7_data_test.cpp", + "./signProfile/profile_test.cpp", + "./signProfile/provision_test.cpp", + "./signProfile/sign_profile_test.cpp", + "./utils/byte_array_utils_test.cpp", + "./utils/file_utils_test.cpp", + "./zip/zip_signer_test.cpp", + "./zip/random_access_file_input_output_test.cpp", + ] + + remove_configs = [ "//build/config/compiler:no_exceptions" ] + + deps = [ "${signature_tools_test}:service_target" ] + + install_images = [ "system" ] + install_enable = true + part_name = "hapsigner" + subsystem_name = "developtools" +} diff --git a/hapsigntool_cpp/test/unittest/byteBuffer/byte_buffer_test.cpp b/hapsigntool_cpp/test/unittest/byteBuffer/byte_buffer_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef166d058b8e6f3e37fec34b93c8b119d455ef34 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/byteBuffer/byte_buffer_test.cpp @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../hapVerify/test_const.h" +#include "byte_buffer.h" + +namespace OHOS { +namespace SignatureTools { +class ByteBufferTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase(void) + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: Test ByteBuffer Constructor and overload function. + * @tc.desc: The static function will return an object of ByteBuffer; + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, ByteBufferConstructorTest001, testing::ext::TestSize.Level1) +{ + ByteBuffer buffer1; + ByteBuffer buffer2(buffer1); + bool judge1 = (buffer2.GetCapacity() == buffer1.GetCapacity()) && + (buffer2.GetPosition() == buffer1.GetPosition()) && + (buffer2.GetLimit() == buffer1.GetLimit()) && + (buffer2.GetBufferPtr() == nullptr); + ASSERT_TRUE(judge1); + + ByteBuffer buffer3(1); + ByteBuffer buffer4(buffer3); + bool judge2 = (buffer4.GetCapacity() == buffer3.GetCapacity()) && + (buffer4.GetPosition() == buffer3.GetPosition()) && + (buffer4.GetLimit() == buffer3.GetLimit()) && + (buffer4.GetBufferPtr() != nullptr); + ASSERT_TRUE(judge2); +} + +/** + * @tc.name: Test ByteBuffer IsEqual. + * @tc.desc: Test function of ByteBuffer::IsEqual() interface. + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, ByteBufferIsEqualTest001, testing::ext::TestSize.Level1) +{ + ByteBuffer buffer1(2); + buffer1.PutInt32(0, 10); + ByteBuffer buffer2(1); + buffer2.PutInt32(0, 1); + buffer1 = buffer2; + ASSERT_TRUE(buffer1.IsEqual(buffer2)); + + ByteBuffer buffer3; + ByteBuffer buffer4; + buffer4 = buffer3; + ASSERT_FALSE(buffer4.IsEqual(buffer3)); + + ASSERT_FALSE(buffer1.IsEqual(buffer3)); + + ASSERT_FALSE(buffer3.IsEqual(buffer1)); + + ByteBuffer buffer5(1); + ByteBuffer buffer6(3); + ASSERT_FALSE(buffer5.IsEqual(buffer6)); + + std::string str{ "abc" }; + ASSERT_FALSE(buffer5.IsEqual(str)); + + buffer6.PutByte('a'); + buffer6.PutByte('b'); + buffer6.PutByte('c'); + + ASSERT_TRUE(buffer6.IsEqual(str)); +} + +/** + * @tc.name: Test ByteBuffer IsEqual. + * @tc.desc: Test function of ByteBuffer's PutGetData interface. + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, PutGetDataTest001, testing::ext::TestSize.Level1) +{ + ByteBuffer buffer(1); + uint32_t v1; + ASSERT_FALSE(buffer.GetUInt32(v1)); + + uint16_t v2; + ASSERT_FALSE(buffer.GetUInt16(v2)); + + int16_t v3; + ASSERT_FALSE(buffer.GetInt16(v3)); + + uint8_t v4 = 1; + buffer.PutUInt8(v4); + uint8_t v5 = 0; + buffer.PutUInt8(v5); + ASSERT_FALSE(buffer.GetUInt8(v5)); + + int8_t v6; + ASSERT_FALSE(buffer.GetInt8(v6)); + + + int16_t v7 = 1; + int32_t v8 = 1; + int64_t v9 = 1; + uint8_t v10 = 1; + buffer.SetPosition(1); + buffer.PutInt16(v7); + buffer.PutInt32(v8); + buffer.PutInt64(v9); + buffer.PutUInt8(v10); + buffer.PutData("a", 2); + + buffer.SetPosition(0); + const char* dummy = nullptr; + buffer.PutData(dummy, 1); + buffer.PutData("a", -1); + int8_t* data = nullptr; + buffer.PutData(data, 1); + buffer.PutInt16(1); + buffer.ClearData(); + + ByteBuffer empty; + empty.PutByte(1); + empty.PutInt16(1); + empty.PutInt32(1); + empty.PutInt64(1); + empty.PutUInt8(1); + empty.PutData("a", 2); + empty.PutData(data, 1); + empty.ClearData(); +} + +/** + * @tc.name: Test a ByteBuffer object's operation of GetInt and Put + * @tc.desc: The static function will return data from ByteBuffer's buffer + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, GetIntAndPutOperation001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. Create an empty buffer and get data from it. + * @tc.expected: step1. The return result is false. + */ + ByteBuffer emptyBuffer; + int32_t dataInt32; + ASSERT_FALSE(emptyBuffer.GetInt32(dataInt32)); + long long dataInt64; + ASSERT_FALSE(emptyBuffer.GetInt64(dataInt64)); + unsigned short dataUInt16; + ASSERT_FALSE(emptyBuffer.GetUInt16(0, dataUInt16)); + /* + * @tc.steps: step2. Create a ByteBuffer with one byte's buffer and get data from second byte. + * @tc.expected: step2. The return result is false. + */ + ByteBuffer testBuffer(1); + char testChar = TEST_HAPBYTEBUFFER_CHAR_DATA; + testBuffer.PutData(0, &testChar, sizeof(testChar)); + uint32_t dataUInt32; + ASSERT_FALSE(testBuffer.GetUInt32(1, dataUInt32)); + ASSERT_FALSE(testBuffer.GetInt32(1, dataInt32)); + ASSERT_FALSE(testBuffer.GetInt64(1, dataInt64)); + ASSERT_FALSE(testBuffer.GetUInt16(1, dataUInt16)); + /* + * @tc.steps: step3. Get data from negative position. + * @tc.expected: step3. The return result is false. + */ + ASSERT_FALSE(testBuffer.GetInt64(TEST_HAPBYTEBUFFER_INVALID_INDEX, dataInt64)); + /* + * @tc.steps: step4. Put data to buffer and get data from it. + * @tc.expected: step4. The return data is same as which we put. + */ + ByteBuffer testBuffer2(TEST_HAPBYTEBUFFER_LENGTH); + testBuffer2.PutByte(0, testChar); +} + +/** + * @tc.name: Test ByteBuffer function of slice + * @tc.desc: The static function will get an object after slice and detect it is right; + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, Slice001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. Set a fixed length buffer. + * @tc.expected: step1. The return is same as value is set. + */ + ByteBuffer buffer1(TEST_HAPBYTEBUFFER_LENGTH_2); + buffer1.SetCapacity(TEST_HAPBYTEBUFFER_LENGTH); + ASSERT_TRUE(buffer1.GetCapacity() == TEST_HAPBYTEBUFFER_LENGTH); + /* + * @tc.steps: step2. Slice buffer. + * @tc.expected: step2. The return is the target length after slice. + */ + buffer1.PutInt32(0, TEST_HAPBYTEBUFFER_INT32_DATA); + buffer1.PutInt32(sizeof(int), TEST_HAPBYTEBUFFER_INT32_DATA_2); + buffer1.SetPosition(sizeof(int)); + buffer1.SetLimit(sizeof(int) + sizeof(int)); + buffer1.Slice(); + ASSERT_TRUE(buffer1.Remaining() == sizeof(int)); + /* + * @tc.steps: step3. Get int32 from buffer1. + * @tc.expected: step3. The return result is equal to TEST_HAPBYTEBUFFER_INT32_DATA_2. + */ + int32_t testDataInt32; + ASSERT_TRUE(buffer1.GetInt32(testDataInt32)); + ASSERT_EQ(testDataInt32, TEST_HAPBYTEBUFFER_INT32_DATA_2); + /* + * @tc.steps: step4. Slice continue, reset position and limit, and calculate if buffer has remain. + * @tc.expected: step4. The return result is true. + */ + buffer1.Slice(); + buffer1.Clear(); + ASSERT_TRUE(buffer1.HasRemaining()); +} + +/** + * @tc.name: Test ByteBuffer function of IsEqual001 + * @tc.desc: The static function will return two object whether is equal. + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, IsEqual001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. Create a buffer, and compare it with itself. + * @tc.expected: step1. The return result is true. + */ + char testChar[TEST_HAPBYTEBUFFER_LENGTH] = "Hello, world!!"; + ByteBuffer buffer1(TEST_HAPBYTEBUFFER_LENGTH); + buffer1.PutData(0, testChar, TEST_HAPBYTEBUFFER_LENGTH); + ASSERT_TRUE(buffer1.IsEqual(buffer1)); + /* + * @tc.steps: step2. Create another buffer and compare it with buffer1. + * @tc.expected: step2. The return result is false. + */ + ByteBuffer buffer2; + ASSERT_FALSE(buffer1.IsEqual(buffer2)); + /* + * @tc.steps: step3. Set length of buffer2 same as buffer1. + * @tc.expected: step3. The return result is false. + */ + buffer2.SetCapacity(TEST_HAPBYTEBUFFER_LENGTH); + ASSERT_FALSE(buffer1.IsEqual(buffer2)); + /* + * @tc.steps: step4. Use copy constructor to create an buffer3, and compare it with buffer1. + * @tc.expected: step4. The return result is true. + */ + ByteBuffer buffer3(buffer1); + ASSERT_TRUE(buffer1.IsEqual(buffer3)); +} + +/** + * @tc.name: Test ByteBuffer function of IsEqual002 + * @tc.desc: The static function will return whether the value in buffer is equal to a string. + * @tc.type: FUNC + */ +HWTEST_F(ByteBufferTest, IsEqual002, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. Create a buffer and string, and compare. + * @tc.expected: step1. The return is false. + */ + std::string testStr = "Hello, world!!!"; + ByteBuffer buffer1; + const ByteBuffer& buffer2 = buffer1; + buffer1 = buffer2; + ASSERT_FALSE(buffer1.IsEqual(testStr)); + /* + * @tc.steps: step2. Set length of buffer1 same as string. + * @tc.expected: step2. The return is false. + */ + buffer1.SetCapacity(static_cast(testStr.size())); + ASSERT_FALSE(buffer1.IsEqual(testStr)); + /* + * @tc.steps: step3. Put string to buffer1 and compare. + * @tc.expected: step3. The return is true. + */ + for (int32_t i = 0; i < static_cast(testStr.size()); i++) { + buffer1.PutByte(i, testStr[i]); + } + ASSERT_TRUE(buffer1.IsEqual(testStr)); +} + +} // namespace SignatureTools +} // namespace OHOS 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 new file mode 100644 index 0000000000000000000000000000000000000000..26a552e3918488286041a623eefa36c65d55943d --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/code_sign_block_header_test.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "code_sign_block_header.h" + +using namespace OHOS::SignatureTools; + +/* +* 测试套件,固定写法 +*/ +class CodeSignBlockHeaderTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: fromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, fromByteArray001, testing::ext::TestSize.Level1) +{ + // 走第一个分支:长度不相等,返回 + std::shared_ptr api = std::make_shared(); + + std::vector bytes; + CodeSignBlockHeader* codeSignBlockHeader = api->FromByteArray(bytes); + + EXPECT_EQ(codeSignBlockHeader, nullptr); +} + +/** + * @tc.name: fromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, fromByteArray002, testing::ext::TestSize.Level1) +{ + // 走第二个分支:inMagic不相等 + std::shared_ptr api = std::make_shared(); + + std::vector bytes{ -1, -91, 34, -16, 97, -32, -121, 1, 5, 3, 8, 8, 15, + 12, 12, 13, 58, 19, 50, 10, 54, 29, 59, 17, 102, 105, 15, 19, 29, 30, 32, 59 }; + CodeSignBlockHeader* codeSignBlockHeader = api->FromByteArray(bytes); + + EXPECT_EQ(codeSignBlockHeader, nullptr); +} + +/** + * @tc.name: fromByteArray003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, fromByteArray003, testing::ext::TestSize.Level1) +{ + // 走第三个分支:inVersion不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(33); + byteBuffer.PutInt64(-2285919006713316147); + byteBuffer.PutInt32(2); + byteBuffer.Flip(); + + char readComment[32] = { 0 }; + byteBuffer.GetData(readComment, 32); + std::vector bytes(readComment, readComment + 32); + + CodeSignBlockHeader* codeSignBlockHeader = api->FromByteArray(bytes); + EXPECT_EQ(codeSignBlockHeader, nullptr); +} + +/** + * @tc.name: fromByteArray004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, fromByteArray004, testing::ext::TestSize.Level1) +{ + // 走第四个分支:inSegmentNum 不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(33); + byteBuffer.PutInt64(-2285919006713316147); + byteBuffer.PutInt32(1); + byteBuffer.PutInt32(4); // inBlockSize + byteBuffer.PutInt32(4); // inSegmentNum + byteBuffer.Flip(); + + char readComment[32] = { 0 }; + byteBuffer.GetData(readComment, 32); + std::vector bytes(readComment, readComment + 32); + + CodeSignBlockHeader* codeSignBlockHeader = api->FromByteArray(bytes); + EXPECT_EQ(codeSignBlockHeader, nullptr); +} + +/** + * @tc.name: fromByteArray005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, fromByteArray005, testing::ext::TestSize.Level1) +{ + // 走第五个分支:inFlags 不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(33); + byteBuffer.PutInt64(-2285919006713316147); + byteBuffer.PutInt32(1); + byteBuffer.PutInt32(4); // inBlockSize + byteBuffer.PutInt32(3); // inSegmentNum + byteBuffer.PutInt32(-1); // inFlags + byteBuffer.Flip(); + + char readComment[32] = { 0 }; + byteBuffer.GetData(readComment, 32); + std::vector bytes(readComment, readComment + 32); + + CodeSignBlockHeader* codeSignBlockHeader = api->FromByteArray(bytes); + EXPECT_EQ(codeSignBlockHeader, nullptr); +} + +/** + * @tc.name: fromByteArray006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, fromByteArray006, testing::ext::TestSize.Level1) +{ + // 走完 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(33); + byteBuffer.PutInt64(-2285919006713316147); + byteBuffer.PutInt32(1); + byteBuffer.PutInt32(4); // inBlockSize + byteBuffer.PutInt32(3); // inSegmentNum + byteBuffer.PutInt32(0); // inFlags + byteBuffer.Flip(); + + char readComment[32] = { 0 }; + byteBuffer.GetData(readComment, 32); + std::vector bytes(readComment, readComment + 32); + + CodeSignBlockHeader* codeSignBlockHeader = api->FromByteArray(bytes); + EXPECT_NE(codeSignBlockHeader, nullptr); +} + +/** + * @tc.name: getBlockSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, getBlockSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int blockSize = api->GetBlockSize(); + + EXPECT_EQ(blockSize, 0); +} + +/** + * @tc.name: getSegmentNum + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, getSegmentNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int segmentNum = api->GetSegmentNum(); + + EXPECT_EQ(segmentNum, 0); +} + +/** + * @tc.name: setBlockSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, setBlockSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->SetBlockSize(1024); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setFlags + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, setFlags, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->SetFlags(1); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setSegmentNum + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, setSegmentNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->SetSegmentNum(4); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: size + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, size, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int headerSize = api->Size(); + + EXPECT_EQ(headerSize, 32); +} + +/** + * @tc.name: toByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockHeaderTest, toByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector byteArray; + api->ToByteArray(byteArray); + + EXPECT_EQ(byteArray.size(), 32); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..b4af48c6c238fe7c31f90221bdc54b5095480d83 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/code_sign_block_test.cpp @@ -0,0 +1,428 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "code_sign_block.h" +#include "segment_header.h" +#include "hap_info_segment.h" +#include "sign_info.h" + +using namespace OHOS::SignatureTools; + +/* +* 测试套件,固定写法 +*/ +class CodeSignBlockTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: addOneMerkleTree001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, addOneMerkleTree001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + const std::string key; + std::vector merkleTree; + api->AddOneMerkleTree(key, merkleTree); // 返回值void + + EXPECT_EQ(true, true); +} + +/** + * @tc.name: addOneMerkleTree002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, addOneMerkleTree002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + const std::string key = "111"; + std::vector merkleTree; + api->AddOneMerkleTree(key, merkleTree); + + EXPECT_EQ(true, true); +} + +/** + * @tc.name: addToSegmentList + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, addToSegmentList, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + SegmentHeader sh(SegmentHeader::CSB_NATIVE_LIB_INFO_SEG, 0); + api->AddToSegmentList(sh); + + EXPECT_EQ(true, true); +} + +/** + * @tc.name: computeMerkleTreeOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, computeMerkleTreeOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + long long codeSignBlockOffset = 949572; + long long offset = api->ComputeMerkleTreeOffset(codeSignBlockOffset); + + EXPECT_NE(offset, 0); +} + +/** + * @tc.name: computeMerkleTreeOffset001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, computeMerkleTreeOffset001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + long long codeSignBlockOffset = -68; + long long offset = api->ComputeMerkleTreeOffset(codeSignBlockOffset); + + EXPECT_EQ(offset, 0); +} + +/** + * @tc.name: computeSegmentOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, computeSegmentOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->ComputeSegmentOffset(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getCodeSignBlockHeader + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, getCodeSignBlockHeader, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->GetCodeSignBlockHeader(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getHapInfoSegment + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, getHapInfoSegment, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->GetHapInfoSegment(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getOneMerkleTreeByFileName001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, getOneMerkleTreeByFileName001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::string key = "test.so"; + std::vector name = api->GetOneMerkleTreeByFileName(key); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getOneMerkleTreeByFileName002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, getOneMerkleTreeByFileName002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::string key; + std::vector name = api->GetOneMerkleTreeByFileName(key); + int size = name.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: getSegmentHeaderList + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, getSegmentHeaderList, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector segmentHeaderList = api->GetSegmentHeaderList(); + + EXPECT_EQ(segmentHeaderList.size(), 0); +} + +/** + * @tc.name: getSoInfoSegment + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, getSoInfoSegment, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->GetSoInfoSegment(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setCodeSignBlockFlag + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setCodeSignBlockFlag, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->SetCodeSignBlockFlag(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setCodeSignBlockFlag001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setCodeSignBlockFlag001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + NativeLibInfoSegment nativeLibInfoSegment(0, + 0, + 1, + std::vector(), + std::vector(), + std::vector(), + std::vector()); + + api->SetSoInfoSegment(nativeLibInfoSegment); + api->SetCodeSignBlockFlag(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setCodeSignBlockHeader + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setCodeSignBlockHeader, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + CodeSignBlockHeader::Builder* build = new CodeSignBlockHeader::Builder(); + build->SetBlockSize(4096); + build->SetFlags(1); + build->SetMagic(29); + std::vector reservedVec(32, 1); + build->SetReserved(reservedVec); + build->SetSegmentNum(394); + build->SetVersion(9); + CodeSignBlockHeader codeSignBlockHeader(build); + + api->SetCodeSignBlockHeader(codeSignBlockHeader); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setFsVerityInfoSegment + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setFsVerityInfoSegment, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + FsVerityInfoSegment fsVeritySeg(1, 1, 12); + + api->SetFsVerityInfoSegment(fsVeritySeg); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setHapInfoSegment + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setHapInfoSegment, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t saltSize = 0; + int32_t flags = 1; + int64_t dataSize = 5390336; + std::vector salt; + std::vector sig{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, 1, 7, + 2, -96, -126, 7, -61, 48, -126, 7, -65, 2, 1, 1, 49, 13, 48, 11, 6, 9, 96, -122, + 72, 1, 101, 3, 4, 2, 1, 48, 11, 6, 9, 42, -122, 72, -122, -9, 13, 1, 7, 1, -96, + -126, 6, 43, 48, -126, 1, -32, 48, -126, 1, -121, -96, 3, 2, 1, 2, 2, 4, 85, -67, + -54, 116, 48, 10, 6, 8, 42, -122, 72, -50, 61, 4, 3, 3, 48, 85, 49, 11, 48, 9, 6, + 3, 85, 4, 6, 1 }; + SignInfo signInfo(saltSize, flags, dataSize, salt, sig); + HapInfoSegment hapInfoSegment(10945, signInfo); + api->SetHapInfoSegment(hapInfoSegment); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setSegmentHeaders + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setSegmentHeaders, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->SetSegmentHeaders(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setSegmentNum + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setSegmentNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->SetSegmentNum(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: setSoInfoSegment + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSignBlockTest, setSoInfoSegment, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t magic = 248702752; + int32_t segmentSize = 0; + int32_t sectionNum = 0; + std::vector signedFilePosList; + std::vector fileNameList; + std::vector signInfoList; + std::vector zeroPadding; + + NativeLibInfoSegment soSeg(magic, segmentSize, sectionNum, signedFilePosList, + fileNameList, signInfoList, zeroPadding); + api->SetSoInfoSegment(soSeg); + + EXPECT_EQ(true, 1); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..bd9812a493e1e45bc6952ca2ac4a0a15ac071482 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/elf_sign_block_test.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "elf_sign_block.h" +#include "byte_buffer.h" + +using namespace OHOS::SignatureTools; + +class ElfSignBlockTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: FromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ElfSignBlockTest, FromByteArray001, testing::ext::TestSize.Level1) +{ + int32_t treeLength = 8; + std::vector merkleTreeWithPadding = { 1, 1, 1, 1, 1, 1, 1, 1 }; + FsVerityDescriptorWithSign descriptorWithSign; + ElfSignBlock elfSignBlock(treeLength, merkleTreeWithPadding, descriptorWithSign); + std::vector arr; + elfSignBlock.ToByteArray(arr); + ElfSignBlock block; + bool flag = elfSignBlock.FromByteArray(arr, block); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: FromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ElfSignBlockTest, FromByteArray002, testing::ext::TestSize.Level1) +{ + int32_t treeLength = 8; + std::vector merkleTreeWithPadding = { 1, 1, 1, 1, 1, 1, 1, 1 }; + FsVerityDescriptorWithSign descriptorWithSign; + ElfSignBlock elfSignBlock(treeLength, merkleTreeWithPadding, descriptorWithSign); + std::vector arr; + elfSignBlock.ToByteArray(arr); + arr[24] = 0; + ElfSignBlock block; + bool flag = elfSignBlock.FromByteArray(arr, block); + + EXPECT_EQ(flag, false); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..cf300019a1086e08d31b97dbe40b4b4cd3928d1d --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/extension_test.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "extension.h" + +using namespace OHOS::SignatureTools; + + /* + * 测试套件,固定写法 + */ +class ExtensionTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: getSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ExtensionTest, getSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t sizeInt = api->GetSize(); + + EXPECT_NE(sizeInt, 0); +} + +/** + * @tc.name: isType + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ExtensionTest, isType, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t type = 1; + bool bIsType = api->IsType(type); + + EXPECT_EQ(bIsType, false); +} + +/** + * @tc.name: toByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ExtensionTest, toByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector byteArray; + api->ToByteArray(byteArray); + + EXPECT_EQ(byteArray.size(), 8); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..198bc697f9883d311ae5f4083746606f21e7cd80 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/fs_verity_info_segment_test.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "fs_verity_info_segment.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class FsVerityInfoSegmentTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: fromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray001, testing::ext::TestSize.Level1) +{ + // 走第一个分支:size不相等 + std::shared_ptr api = std::make_shared(); + + std::vector bytes; + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray002, testing::ext::TestSize.Level1) +{ + // 走第二个分支:inMagic 不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(0); // inMagic + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray003, testing::ext::TestSize.Level1) +{ + // 走第三个分支:inVersion 不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(506999211); // inMagic + byteBuffer.PutUInt8(0); // inVersion + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray004, testing::ext::TestSize.Level1) +{ + // 走第四个分支:inHashAlgorithm 不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(506999211); // inMagic + byteBuffer.PutUInt8(1); // inVersion + byteBuffer.PutUInt8(0); // inHashAlgorithm + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray005, testing::ext::TestSize.Level1) +{ + // 走第五个分支:inLog2BlockSize 不相等 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(506999211); // inMagic + byteBuffer.PutUInt8(1); // inVersion + byteBuffer.PutUInt8(1); // inHashAlgorithm + byteBuffer.PutUInt8(0); // inLog2BlockSize + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray006, testing::ext::TestSize.Level1) +{ + // 走完 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(506999211); // inMagic + byteBuffer.PutUInt8(1); // inVersion + byteBuffer.PutUInt8(1); // inHashAlgorithm + byteBuffer.PutUInt8(12); // inLog2BlockSize + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, fromByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector bytes{ 12, 45, 58, -12, 38, 29, 12, 45, 58, -12, 38, 29, 12, 45, + 58, -12, 38, 29, 12, 45, 58, -12, 38, 29, 12, 45, 58, -12, 38, 29, 13, 26, 12, 45, + 58, -12, 38, 29, 12, 45, 58, -12, 38, 29, 12, 45, 58, -12, 38, 29, 12, 45, 58, -12, + 38, 29, 12, 45, 58, -12, 38, 29, 13, 26 }; + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: size + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, size, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int fsVerityInfoSegmentSize = api->Size(); + + EXPECT_EQ(fsVerityInfoSegmentSize, 64); +} + +/** + * @tc.name: toByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityInfoSegmentTest, toByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector byteArray; + api->ToByteArray(byteArray); + + EXPECT_EQ(byteArray.size(), 64); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..a192d6eeff6101566d0d8de762c0a5caa47d3603 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/hap_info_segment_test.cpp @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "hap_info_segment.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class HapInfoSegmentTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: fromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, fromByteArray001, testing::ext::TestSize.Level1) +{ + // 走第一个分支:inMagic 不一样 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(32); + byteBuffer.PutInt32(0); // inMagic + byteBuffer.Flip(); + + char readComment[32] = { 0 }; + byteBuffer.GetData(readComment, 32); + std::vector bytes(readComment, readComment + 32); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, fromByteArray002, testing::ext::TestSize.Level1) +{ + // 走第三个分支:inHapSignInfo.getDataSize() + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(-1045050266); // inMagic + byteBuffer.PutInt32(0); // inSaltSize + byteBuffer.PutInt32(0); // inSigSize + byteBuffer.PutInt32(1); // inFlags + byteBuffer.PutInt64(5); // inDataSize + + std::vector inSalt(32, 0); + byteBuffer.PutData((const char*)inSalt.data(), 32); + + byteBuffer.PutInt32(1); // inExtensionNum + byteBuffer.PutInt32(4); // inExtensionOffset + + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, fromByteArray003, testing::ext::TestSize.Level1) +{ + // 走第四个分支:inHapSignInfo.getExtensionNum() + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(-1045050266); // inMagic + byteBuffer.PutInt32(0); // inSaltSize + byteBuffer.PutInt32(0); // inSigSize + byteBuffer.PutInt32(1); // inFlags + byteBuffer.PutInt64(4096); // inDataSize + + std::vector inSalt(32, 0); + byteBuffer.PutData((const char*)inSalt.data(), 32); + + byteBuffer.PutInt32(2); // inExtensionNum + byteBuffer.PutInt32(4); // inExtensionOffset + + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, fromByteArray004, testing::ext::TestSize.Level1) +{ + // 走完 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(64); + byteBuffer.PutInt32(-1045050266); // inMagic + byteBuffer.PutInt32(0); // inSaltSize + byteBuffer.PutInt32(0); // inSigSize + byteBuffer.PutInt32(1); // inFlags + byteBuffer.PutInt64(4096); // inDataSize + + std::vector inSalt(32, 0); + byteBuffer.PutData((const char*)inSalt.data(), 32); + + byteBuffer.PutInt32(1); // inExtensionNum + byteBuffer.PutInt32(4); // inExtensionOffset + + byteBuffer.Flip(); + + char readComment[64] = { 0 }; + byteBuffer.GetData(readComment, 64); + std::vector bytes(readComment, readComment + 64); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + + +/** + * @tc.name: getSignInfo + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, getSignInfo, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + api->GetSignInfo(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, getSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t hapInfoSegmentSize = api->GetSize(); + + EXPECT_EQ(hapInfoSegmentSize, 64); +} + +/** + * @tc.name: setSignInfo + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, setSignInfo, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t saltSize = 0; + int32_t flags = 1; + int64_t dataSize = 5390336; + std::vector salt; + std::vector sig{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, + 1, 7, 2, -96, -126, 7, -61, 48, -126, 7, -65, 2, 1, 1, 49, 13, 48, 11, 6, + 9, 96, -122, 72, 1, 101, 3, 4, 2, 1, 48, 11, 6, 9, 42, -122, 72, -122, -9, + 13, 1, 7, 1, -96, -126, 6, 43, 48, -126, 1, -32, 48, -126, 1, -121, -96, 3, + 2, 1, 2, 2, 4, 85, -67, -54, 116, 48, 10, 6, 8, 42, -122, 72, -50, 61, 4, 3, + 3, 48, 85, 49, 11, 48, 9, 6, 3, 85, 4, 6, 1 }; + SignInfo signInfo(saltSize, flags, dataSize, salt, sig); + api->SetSignInfo(signInfo); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: toByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapInfoSegmentTest, toByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector byteArray; + api->ToByteArray(byteArray); + + EXPECT_EQ(byteArray.size(), 64); +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..4677ea234ff599ce4ccc4441c78e305efe8f85f2 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/merkle_tree_extension_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "merkle_tree_extension.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class MerkleTreeExtensionTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: fromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, fromByteArray001, testing::ext::TestSize.Level1) +{ + // 走进第一个分支:inMerkleTreeSize = 4095 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(8); + byteBuffer.PutInt64(4095); + byteBuffer.Flip(); + + char readComment[8] = { 0 }; + byteBuffer.GetData(readComment, 8); + std::vector bytes(readComment, readComment + 8); + + Extension* pExtension = api->FromByteArray(bytes); + + EXPECT_EQ(pExtension, nullptr); +} + +/** + * @tc.name: fromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, fromByteArray002, testing::ext::TestSize.Level1) +{ + // 走进第二个分支:inMerkleTreeOffset = 4095 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(16); + byteBuffer.PutInt64(4096); + byteBuffer.PutInt64(4095); // inMerkleTreeOffset + byteBuffer.Flip(); + + char readComment[16] = { 0 }; + byteBuffer.GetData(readComment, 16); + std::vector bytes(readComment, readComment + 16); + + Extension* pExtension = api->FromByteArray(bytes); + + EXPECT_EQ(pExtension, nullptr); +} + +/** + * @tc.name: fromByteArray003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, fromByteArray003, testing::ext::TestSize.Level1) +{ + // 走完 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(16); + byteBuffer.PutInt64(4096); + byteBuffer.PutInt64(4096); // inMerkleTreeOffset + byteBuffer.Flip(); + + char readComment[16] = { 0 }; + byteBuffer.GetData(readComment, 16); + std::vector bytes(readComment, readComment + 16); + + Extension* pExtension = api->FromByteArray(bytes); + + EXPECT_NE(pExtension, nullptr); +} + +/** + * @tc.name: getMerkleTreeOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, getMerkleTreeOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int64_t merkleTreeOffset = api->GetMerkleTreeOffset(); + + EXPECT_EQ(merkleTreeOffset, 0); +} + +/** + * @tc.name: getMerkleTreeSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, getMerkleTreeSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int64_t merkleTreeSize = api->GetMerkleTreeSize(); + + EXPECT_EQ(merkleTreeSize, 0); +} + +/** + * @tc.name: getSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, getSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t merkleTreeExtensionSize = api->GetSize(); + + EXPECT_EQ(merkleTreeExtensionSize, 88); +} + +/** + * @tc.name: isType + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, isType, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t type = 1; + bool bIsType = api->IsType(type); + + EXPECT_EQ(bIsType, true); +} + +/** + * @tc.name: setMerkleTreeOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, setMerkleTreeOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int64_t offset = 927046; + api->SetMerkleTreeOffset(offset); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: toByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeExtensionTest, toByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector byteArray; + + api->ToByteArray(byteArray); + + EXPECT_EQ(byteArray.size(), 88); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..669eeb8bec3fe44ecf1ade8603cda8c77f0dc28a --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/native_lib_info_segment_test.cpp @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "native_lib_info_segment.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class NativeLibInfoSegmentTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: fromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, fromByteArray001, testing::ext::TestSize.Level1) +{ + // 走进 inMagic = 4096这个分支 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(4); + byteBuffer.PutInt32(4096); // inMagic + byteBuffer.Flip(); + + char readComment[4] = { 0 }; + byteBuffer.GetData(readComment, 4); + std::vector bytes(readComment, readComment + 4); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, fromByteArray002, testing::ext::TestSize.Level1) +{ + // 走进 if (inSegmentSize < 0) 这个分支 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(8); + byteBuffer.PutInt32(248702752); // inMagic + byteBuffer.PutInt32(-1); // inSegmentSize + byteBuffer.Flip(); + + char readComment[8] = { 0 }; + byteBuffer.GetData(readComment, 8); + std::vector bytes(readComment, readComment + 8); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, fromByteArray003, testing::ext::TestSize.Level1) +{ + // 走进 if (inSectionNum < 0) 这个分支 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(12); + byteBuffer.PutInt32(248702752); // inMagic + byteBuffer.PutInt32(0); // inSegmentSize + byteBuffer.PutInt32(-1); // inSectionNum + byteBuffer.Flip(); + + char readComment[12] = { 0 }; + byteBuffer.GetData(readComment, 12); + std::vector bytes(readComment, readComment + 12); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, fromByteArray004, testing::ext::TestSize.Level1) +{ + // 走进 if (pos.getSignInfoOffset() % ALIGNMENT_FOR_SIGNINFO != 0) 这个分支 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(36); + byteBuffer.PutInt32(248702752); // inMagic + byteBuffer.PutInt32(0); // inSegmentSize + byteBuffer.PutInt32(1); // inSectionNum + + byteBuffer.PutInt32(1); // inFileNameOffset + byteBuffer.PutInt32(7); // inFileNameSize + byteBuffer.PutInt32(3); // inSignInfoOffset + byteBuffer.PutInt32(4); // inSignInfoSize + + std::string fileName = { "test.so" }; + byteBuffer.PutData(fileName.c_str(), 7); + + std::vector inZeroPadding(1, 33); + byteBuffer.PutData((char*)inZeroPadding.data(), 1); + + byteBuffer.Flip(); + + char readComment[36] = { 0 }; + byteBuffer.GetData(readComment, 36); + std::vector bytes(readComment, readComment + 36); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: fromByteArray005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, fromByteArray005, testing::ext::TestSize.Level1) +{ + // 走完 + std::shared_ptr api = std::make_shared(); + + ByteBuffer byteBuffer(36); + byteBuffer.PutInt32(248702752); // inMagic + byteBuffer.PutInt32(0); // inSegmentSize + byteBuffer.PutInt32(1); // inSectionNum + + byteBuffer.PutInt32(1); // inFileNameOffset + byteBuffer.PutInt32(7); // inFileNameSize + byteBuffer.PutInt32(4); // inSignInfoOffset + byteBuffer.PutInt32(4); // inSignInfoSize + + std::string fileName = { "test.so" }; + byteBuffer.PutData(fileName.c_str(), 7); + + std::vector inZeroPadding(1, 33); + byteBuffer.PutData((char*)inZeroPadding.data(), 1); + + byteBuffer.Flip(); + + char readComment[36] = { 0 }; + byteBuffer.GetData(readComment, 36); + std::vector bytes(readComment, readComment + 36); + + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getFileNameList + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, getFileNameList, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector fileNameVec = api->GetFileNameList(); + + EXPECT_EQ(fileNameVec.size(), 0); +} + +/** + * @tc.name: getSectionNum + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, getSectionNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + api->GetSectionNum(); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getSignInfoList + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, getSignInfoList, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector signInfoVec = api->GetSignInfoList(); + + EXPECT_EQ(signInfoVec.size(), 0); +} + +/** + * @tc.name: setSoInfoList + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, setSoInfoList, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t saltSize = 0; + int32_t flags = 1; + int64_t dataSize = 5390336; + std::vector salt; + std::vector sig1{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, 1, 7, 2, + -96, -126, 7, -61, 48, -126, 7, -65, 2, 1, 1, 49, 13, 48, 11, 6, 9, 96, -122, 72, + 1, 101, 3, 4, 2, 1, 48, 11, 6, 9, 42, -122, 72, -122, -9, 13, 1, 7, 1, -96, -126, + 6, 43, 48, -126, 1, -32, 48, -126, 1, -121, -96, 3, 2, 1, 2, 2, 4, 85, -67, -54, + 116, 48, 10, 6, 8, 42, -122, 72, -50, 61, 4, 3, 3, 48, 85, 49, 11, 48, 9, 6, 3, + 85, 4, 6, 1 }; + std::vector sig2{ 49, -127, 8, -47, 7, 10, 43, -123, 73, -123, -10, 14, 2, 8, + 3, -97, -127, 8, -62, 49, -127, 8, -66, 3, 2, 2, 50, 14, 49, 12, 7, 10, 97, -123, + 73, 2, 102, 4, 5, 3, 2, 49, 12, 7, 10, 43, -123, 73, -123, -10, 14, 2, 8, 2, -97, + -127, 7, 44, 49, -127, 2, -33, 49, -127, 2, -122, -97, 4, 3, 2, 3, 3, 5, 86, -68, + -55, 117, 49, 11, 7, 9, 43, -123, 73, -51, 62, 5, 4, 4, 49, 86, 50, 12, 49, 10, 7, + 4, 86, 5, 7, 2 }; + SignInfo signInfo1(saltSize, flags, dataSize, salt, sig1); + SignInfo signInfo2(saltSize, flags, dataSize, salt, sig2); + + std::vector> soInfoList; + soInfoList.push_back(std::make_pair("info.so", signInfo1)); + soInfoList.push_back(std::make_pair("info.so", signInfo2)); + + api->SetSoInfoList(soInfoList); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: size + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(NativeLibInfoSegmentTest, size, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t nativeLibInfoSegmentSize = api->Size(); + + EXPECT_NE(nativeLibInfoSegmentSize, 0); +} + +// /** +// * @tc.name: toByteArray001 +// * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. +// * @tc.size: MEDIUM +// * @tc.type: FUNC +// * @tc.level Level 1 +// * @tc.require: SR000H63TL +// */ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/datastructure/segment_header_test.cpp b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/segment_header_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4b8e9c0cbfa86321dd9319303adfd2d3b1efff3e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/segment_header_test.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "segment_header.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class SegmentHeaderTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: getSegmentOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SegmentHeaderTest, getSegmentOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t segmentOffset = api->GetSegmentOffset(); + + EXPECT_NE(segmentOffset, -1); +} + +/** + * @tc.name: FromByteArray001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SegmentHeaderTest, FromByteArray001, testing::ext::TestSize.Level1) +{ + SegmentHeader segmentHeader(1, 1, 8); + std::vector arr = { 1, 1, 1, 1 }; + std::unique_ptr ptr = segmentHeader.FromByteArray(arr); + + EXPECT_EQ(arr.size(), 4); +} + +/** + * @tc.name: FromByteArray002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SegmentHeaderTest, FromByteArray002, testing::ext::TestSize.Level1) +{ + SegmentHeader segmentHeader(0, 1, 8); + std::vector arr; + segmentHeader.ToByteArray(arr); + std::unique_ptr ptr = segmentHeader.FromByteArray(arr); + + EXPECT_NE(arr.size(), 0); +} + +/** + * @tc.name: FromByteArray003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SegmentHeaderTest, FromByteArray003, testing::ext::TestSize.Level1) +{ + SegmentHeader segmentHeader(1, 1, -1); + std::vector arr; + segmentHeader.ToByteArray(arr); + std::unique_ptr ptr = segmentHeader.FromByteArray(arr); + + EXPECT_NE(arr.size(), 0); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..7b3cc1842c155570ccf296afc2e5a8a9862c2e55 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/sign_info_test.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "sign_info.h" +#include "byte_buffer.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class SignInfoTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: fromByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, fromByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector bytes = { 11, -93, 88, 107, -121, 96, 121, 23, -64, -58, -95, + -71, -126, 60, 116, 60, 10, 15, -125, 107, 127, -123, 81, 68, 28, -121, -20, + -42, -116, -81, -6, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getDataSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, getDataSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int64_t dataSize = api->GetDataSize(); + + EXPECT_EQ(dataSize, 0); +} + +/** + * @tc.name: getExtensionByType + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, getExtensionByType, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t type = 1; + Extension* pExtension = api->GetExtensionByType(type); + + EXPECT_EQ(pExtension, nullptr); +} + +/** + * @tc.name: getExtensionNum + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, getExtensionNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t extensionNum = api->GetExtensionNum(); + + EXPECT_EQ(extensionNum, 0); +} + +/** + * @tc.name: getSignature + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, getSignature, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector signatureVec = api->GetSignature(); + + EXPECT_EQ(signatureVec.size(), 0); +} + +/** + * @tc.name: getSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, getSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + int32_t sizeInt = api->GetSize(); + + EXPECT_EQ(sizeInt, 60); +} + +/** + * @tc.name: parseMerkleTreeExtension + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, parseMerkleTreeExtension, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector bytes = std::vector{ 1, 0, 0, 0, 80, 0, 0, 0, 0, 16, 0, 0, + 0, 0, 0, 0, 0, 96, 21, 0, 0, 0, 0, 0, 75, 43, 18, -27, 86, 118, 101, 64, -128, -112, + 84, 68, 4, -107, 110, 92, 33, -118, 113, -65, -79, -103, 40, 59, 82, -90, -87, -115, + 27, 77, 3, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + ByteBuffer bf((int32_t)bytes.size()); + bf.PutData((char*)bytes.data(), bytes.size()); + + std::vector extensionVec = api->ParseMerkleTreeExtension(&bf, 1); + + EXPECT_EQ(extensionVec.size(), 0); +} + +/** + * @tc.name: toByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignInfoTest, toByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector bytes; + api->ToByteArray(bytes); + + EXPECT_EQ(bytes.size(), 60); +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..9b827a429aa2fc28ce5e7f53021f23957cf2ff1b --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/datastructure/signed_file_pos_test.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "signed_file_pos.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class SignedFilePosTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: fromByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, fromByteArray, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + std::vector bytes = { 11, -93, 88, 107, -121, 96, 121, 23, -64, -58, -95, -71, + -126, 60, 116, 60, 10, 15, -125, 107, 127, -123, 81, 68, 28, -121, -20, -42, -116, + -81, -6, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + api->FromByteArray(bytes); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getFileNameOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, getFileNameOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + int32_t offset = api->GetFileNameOffset(); + + EXPECT_EQ(offset, 108); +} + +/** + * @tc.name: getFileNameSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, getFileNameSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + int32_t fileNameSize = api->GetFileNameSize(); + + EXPECT_EQ(fileNameSize, 31); +} + +/** + * @tc.name: getSignInfoOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, getSignInfoOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + int32_t signInfoOffset = api->GetSignInfoOffset(); + + EXPECT_EQ(signInfoOffset, 280); +} + +/** + * @tc.name: getSignInfoSize + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, getSignInfoSize, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + int32_t signInfoSize = api->GetSignInfoSize(); + + EXPECT_EQ(signInfoSize, 2068); +} + +/** + * @tc.name: increaseFileNameOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, increaseFileNameOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + api->IncreaseFileNameOffset(1); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: increaseSignInfoOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignedFilePosTest, increaseSignInfoOffset, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(108, 31, 280, 2068); + + api->IncreaseSignInfoOffset(2); + + EXPECT_EQ(true, 1); +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..9dd64ff6c0a4de297be8e45c2b63073d3763ddc4 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/fsverity/fs_verity_descriptor_test.cpp @@ -0,0 +1,400 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "fs_verity_descriptor.h" + +using namespace OHOS::SignatureTools; + +class FsVerityDescriptorTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Build + * @tc.desc: Test function of FsVerityDescriptor::Build() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, Build, testing::ext::TestSize.Level1) +{ + std::vector salt = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + + EXPECT_EQ(fsVerityDescriptor.GetFileSize(), 32); +} + +/** + * @tc.name: GetFileSize + * @tc.desc: Test function of FsVerityDescriptor::GetFileSize() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, GetFileSize, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + + EXPECT_EQ(fsVerityDescriptor.GetFileSize(), 32); +} + +/** + * @tc.name: GetMerkleTreeOffset + * @tc.desc: Test function of FsVerityDescriptor::GetMerkleTreeOffset() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, GetMerkleTreeOffset, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + + EXPECT_EQ(fsVerityDescriptor.GetMerkleTreeOffset(), 0); +} + +/** + * @tc.name: GetSignSize + * @tc.desc: Test function of FsVerityDescriptor::GetSignSize() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, GetSignSize, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + + EXPECT_EQ(fsVerityDescriptor.GetSignSize(), 32); +} + +/** + * @tc.name: ToByteArray001 + * @tc.desc: Test function of FsVerityDescriptor::ToByteArray() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, ToByteArray001, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector arr; + fsVerityDescriptor.ToByteArray(arr); + + EXPECT_EQ(fsVerityDescriptor.GetSignSize(), 32); +} + +/** + * @tc.name: ToByteArray002 + * @tc.desc: Test function of FsVerityDescriptor::ToByteArray() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, ToByteArray002, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)64) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector arr; + fsVerityDescriptor.ToByteArray(arr); + int32_t size = arr.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: FromByteArray001 + * @tc.desc: Test function of FsVerityDescriptor::FromByteArray() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, FromByteArray001, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector arr; + fsVerityDescriptor.ToByteArray(arr); + FsVerityDescriptor fromArr = FsVerityDescriptor::FromByteArray(arr); + + EXPECT_EQ(fromArr.GetFileSize(), 32); +} + +/** + * @tc.name: FromByteArray002 + * @tc.desc: Test function of FsVerityDescriptor::FromByteArray() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, FromByteArray002, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector arr; + fsVerityDescriptor.ToByteArray(arr); + arr[0] = 2; + FsVerityDescriptor fromArr = FsVerityDescriptor::FromByteArray(arr); + + EXPECT_EQ(fromArr.GetFileSize(), 0); +} + +/** + * @tc.name: FromByteArray003 + * @tc.desc: Test function of FsVerityDescriptor::FromByteArray() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, FromByteArray003, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(4097) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector arr; + fsVerityDescriptor.ToByteArray(arr); + FsVerityDescriptor fromArr = FsVerityDescriptor::FromByteArray(arr); + + EXPECT_EQ(fromArr.GetFileSize(), 32); +} + +/** + * @tc.name: GetByteForGenerateDigest001 + * @tc.desc: Test function of FsVerityDescriptor::GetByteForGenerateDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, GetByteForGenerateDigest001, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector bytes; + fsVerityDescriptor.GetByteForGenerateDigest(bytes); + + EXPECT_EQ(fsVerityDescriptor.GetSignSize(), 32); +} + +/** + * @tc.name: GetByteForGenerateDigest002 + * @tc.desc: Test function of FsVerityDescriptor::GetByteForGenerateDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, GetByteForGenerateDigest002, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)64) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + std::vector bytes; + fsVerityDescriptor.GetByteForGenerateDigest(bytes); + int32_t size = bytes.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: WriteBytesWithSize + * @tc.desc: Test function of FsVerityDescriptor::GetByteForGenerateDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorTest, WriteBytesWithSize, testing::ext::TestSize.Level1) +{ + std::vector salt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + std::vector rootHash = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + FsVerityDescriptor::Builder builder = (new FsVerityDescriptor::Builder())->SetFileSize(32) + .SetCsVersion(1) + .SetHashAlgorithm(1) + .SetLog2BlockSize(12) + .SetSignSize((uint8_t)32) + .SetSaltSize((uint8_t)32) + .SetSalt(salt) + .SetRawRootHash(rootHash) + .SetFlags(1) + .SetMerkleTreeOffset(0) + .SetCsVersion(1); + FsVerityDescriptor fsVerityDescriptor = builder.Build(); + + std::unique_ptr buffer = std::make_unique(64); + std::vector src = { 1, 1, 1, 1, 1, 1, 1, 1 }; + fsVerityDescriptor.WriteBytesWithSize(buffer.get(), src, 4); + int32_t size = src.size(); + + EXPECT_EQ(size, 8); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..10a778cd827b5c673526a476096d1e6beacbd656 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/fsverity/fs_verity_descriptor_with_sign_test.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "fs_verity_descriptor_with_sign.h" + +using namespace OHOS::SignatureTools; + +class FsVerityDescriptorWithSignTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: Size001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorWithSignTest, Size001, testing::ext::TestSize.Level1) +{ + FsVerityDescriptorWithSign descriptor; + int32_t size = descriptor.Size(); + + EXPECT_NE(size, 0); +} + +/** + * @tc.name: Size002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorWithSignTest, Size002, testing::ext::TestSize.Level1) +{ + FsVerityDescriptor fsVerityDescriptor; + std::vector signature = { 1, 1, 1, 1 }; + FsVerityDescriptorWithSign descriptor(fsVerityDescriptor, signature); + int32_t size = descriptor.Size(); + + EXPECT_NE(size, 0); +} + +/** + * @tc.name: Size003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorWithSignTest, Size003, testing::ext::TestSize.Level1) +{ + FsVerityDescriptor fsVerityDescriptor; + std::vector signature; + FsVerityDescriptorWithSign descriptor(fsVerityDescriptor, signature); + int32_t size = descriptor.Size(); + + EXPECT_NE(size, 0); +} + +/** + * @tc.name: ToByteArray + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorWithSignTest, ToByteArray, testing::ext::TestSize.Level1) +{ + FsVerityDescriptor fsVerityDescriptor; + std::vector signature = { 1, 1, 1, 1 }; + int32_t type = 1; + int32_t length = 0; + FsVerityDescriptorWithSign descriptor(type, length, fsVerityDescriptor, signature); + std::vector bytes; + descriptor.ToByteArray(bytes); + int32_t size = bytes.size(); + + EXPECT_NE(size, 0); +} + +/** + * @tc.name: GetFsVerityDescriptor + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorWithSignTest, GetFsVerityDescriptor, testing::ext::TestSize.Level1) +{ + FsVerityDescriptor fsVerityDescriptor; + std::vector signature = { 1, 1, 1, 1 }; + int32_t type = 1; + int32_t length = 0; + FsVerityDescriptorWithSign descriptor(type, length, fsVerityDescriptor, signature); + FsVerityDescriptor getObj = descriptor.GetFsVerityDescriptor(); + int32_t size = getObj.GetSignSize(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetSignature + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDescriptorWithSignTest, GetSignature, testing::ext::TestSize.Level1) +{ + FsVerityDescriptor fsVerityDescriptor; + std::vector signature = { 1, 1, 1, 1 }; + int32_t type = 1; + int32_t length = 0; + FsVerityDescriptorWithSign descriptor(type, length, fsVerityDescriptor, signature); + std::vector sig = descriptor.GetSignature(); + int32_t size = sig.size(); + + EXPECT_EQ(size, 4); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..c01cb3947db94e9ada203f2de41dd87b31e345ad --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/fsverity/fs_verity_digest_test.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +using namespace OHOS::SignatureTools; + +class FsVerityDigestTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GetFsVerityDigest + * @tc.desc: Test function of FsVerityDigest::GetFsVerityDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityDigestTest, GetFsVerityDigest, testing::ext::TestSize.Level1) +{ + std::vector digest = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + std::vector fsVerityDigest; + FsVerityDigest::GetFsVerityDigest(1, digest, fsVerityDigest); + + EXPECT_EQ(digest.size(), 16); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..4f40502f1ca29f7fe0955b9f399651e6a2205b6b --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/fsverity/fs_verity_generator_test.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "fs_verity_generator.h" + +using namespace OHOS::SignatureTools; + +class FsVerityGeneratorTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + (void)rename("./codeSigning/entry-default-signed-so.txt", "./codeSigning/entry-default-signed-so.hap"); + } + static void TearDownTestCase() + { + + } + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GenerateMerkleTree + * @tc.desc: Test function of FsVerityGenerator::GenerateMerkleTree() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GenerateMerkleTree, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm FS_SHA256(1, "SHA-256", 256 / 8); + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + MerkleTree* merkleTree = fsVerityGenerator.GenerateMerkleTree(inputStream, 69632, FS_SHA256); + + EXPECT_NE(merkleTree, nullptr); +} + +/** + * @tc.name: GenerateFsVerityDigest + * @tc.desc: Test function of FsVerityGenerator::GenerateFsVerityDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GenerateFsVerityDigest, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + + EXPECT_NE(fsVerityGenerator.GetFsVerityDigest()[0], 0); +} + +/** + * @tc.name: GetFsVerityDigest + * @tc.desc: Test function of FsVerityGenerator::GetFsVerityDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GetFsVerityDigest, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + std::vector digest = fsVerityGenerator.GetFsVerityDigest(); + + EXPECT_NE(digest[0], 0); +} + +/** + * @tc.name: GetTreeBytes + * @tc.desc: Test function of FsVerityGenerator::GetTreeBytes() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GetTreeBytes, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + std::vector treeBytes = fsVerityGenerator.GetTreeBytes(); + + EXPECT_NE(treeBytes[0], 0); +} + +/** + * @tc.name: GetRootHash + * @tc.desc: Test function of FsVerityGenerator::GetRootHash() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GetRootHash, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + std::vector rootHash = fsVerityGenerator.GetRootHash(); + + EXPECT_NE(rootHash[0], 0); +} + +/** + * @tc.name: GetSaltSize + * @tc.desc: Test function of FsVerityGenerator::GetSaltSize() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GetSaltSize, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + int saltSize = fsVerityGenerator.GetSaltSize(); + + EXPECT_EQ(saltSize, 0); +} + +/** + * @tc.name: GetFsVerityHashAlgorithm + * @tc.desc: Test function of FsVerityGenerator::GetFsVerityHashAlgorithm() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GetFsVerityHashAlgorithm, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + uint8_t algorithm = fsVerityGenerator.GetFsVerityHashAlgorithm(); + + EXPECT_NE(algorithm, 0); +} + +/** + * @tc.name: GetLog2BlockSize + * @tc.desc: Test function of FsVerityGenerator::GetLog2BlockSize() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityGeneratorTest, GetLog2BlockSize, testing::ext::TestSize.Level1) +{ + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + FsVerityGenerator fsVerityGenerator; + + fsVerityGenerator.GenerateFsVerityDigest(inputStream, 69632, 1400832); + uint8_t blockSize = fsVerityGenerator.GetLog2BlockSize(); + + EXPECT_NE(blockSize, 0); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..1c4f9615e87c7517b35d3923b3417bdb7b752adb --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/fsverity/fs_verity_hash_algorithm_test.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "fs_verity_hash_algorithm.h" + +using namespace OHOS::SignatureTools; + +class FsVerityHashAlgorithmTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GetId + * @tc.desc: Test function of FsVerityHashAlgorithm::GetId() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityHashAlgorithmTest, GetId, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); + + EXPECT_EQ(SHA256.GetId(), 1); +} + +/** + * @tc.name: GetHashAlgorithm + * @tc.desc: Test function of FsVerityHashAlgorithm::GetHashAlgorithm() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityHashAlgorithmTest, GetHashAlgorithm, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); + + EXPECT_EQ(SHA256.GetHashAlgorithm(), "SHA-256"); +} + +/** + * @tc.name: GetOutputByteSize + * @tc.desc: Test function of FsVerityHashAlgorithm::GetOutputByteSize() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FsVerityHashAlgorithmTest, GetOutputByteSize, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); + + EXPECT_EQ(SHA256.GetOutputByteSize(), 256 / 8); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..b441ea3a308c3df3508a889f3d08b0a891d17bba --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/fsverity/merkle_tree_builder_test.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "merkle_tree_builder.h" + +using namespace OHOS::SignatureTools; + +class MerkleTreeBuilderTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + (void)rename("./codeSigning/entry-default-signed-so.txt", "./codeSigning/entry-default-signed-so.hap"); + } + static void TearDownTestCase() + { + + } + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GenerateMerkleTree001 + * @tc.desc: Test function of MerkleTreeBuilder::GenerateMerkleTree() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeBuilderTest, GenerateMerkleTree001, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + + MerkleTreeBuilder builder; + MerkleTree* merkleTree = builder.GenerateMerkleTree(inputStream, 69632, SHA256); + + EXPECT_NE(merkleTree, nullptr); +} + +/** + * @tc.name: GenerateMerkleTree002 + * @tc.desc: Test function of MerkleTreeBuilder::GenerateMerkleTree() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeBuilderTest, GenerateMerkleTree002, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + + MerkleTreeBuilder builder; + MerkleTree* merkleTree = builder.GenerateMerkleTree(inputStream, 4095, SHA256); + + EXPECT_EQ(merkleTree, nullptr); +} + +/** + * @tc.name: GenerateMerkleTree003 + * @tc.desc: Test function of MerkleTreeBuilder::GenerateMerkleTree() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(MerkleTreeBuilderTest, GenerateMerkleTree003, testing::ext::TestSize.Level1) +{ + const FsVerityHashAlgorithm SHA256((char)1, "SHA-256", 256 / 8); + std::ifstream inputStream("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + + MerkleTreeBuilder builder; + MerkleTree* merkleTree = builder.GenerateMerkleTree(inputStream, 0, SHA256); + + EXPECT_EQ(merkleTree, nullptr); +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/elf_parse_sign_block_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/elf_parse_sign_block_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..f61a73deb26db1475ced660489120f9182ae20c0 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/elf_parse_sign_block_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/entry-default-signed-so.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/entry-default-signed-so.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a7b44608ce82c4f91ace4917b28d42bc96f732f Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/entry-default-signed-so.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/entry-default-unsigned-so.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/entry-default-unsigned-so.txt new file mode 100644 index 0000000000000000000000000000000000000000..417e4bf88c1c29f983171b731ba4bc88cbbe6ad2 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/entry-default-unsigned-so.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_file_type_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_file_type_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3b3d65c646a5bb69e096e37f897c7ed48c8a9e9 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_file_type_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_invalid_block_header_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_invalid_block_header_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..b8e144eeaf8af935593c38c5a24aaf2f6eb540cc Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_invalid_block_header_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_magic_number_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_magic_number_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..b5400f96b991515abe604272abfbcd3417ded085 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_magic_number_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_merkle_tree_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_merkle_tree_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..2907350d041983bf9185de5150b343a141d329a0 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_merkle_tree_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_native_libs_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_native_libs_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..c80a1890c8808a7ddff073116bb67299dced150d Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_native_libs_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_no_suffix_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_no_suffix_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..2a3f5a914e3c68745ec0c482867f0861cd1b2420 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_no_suffix_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_offset_align_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_offset_align_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf7cf4b9aa285dd2d28c4f586a0e10637862d951 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_offset_align_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_profile_is_null_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_profile_is_null_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..e386f2da9bbd498f43a6d4f25760b1166e298206 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_profile_is_null_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/hap_segment_header_err.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_segment_header_err.txt new file mode 100644 index 0000000000000000000000000000000000000000..f92314fdd0cb1288f5a0952a4209c6b6ab900279 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/hap_segment_header_err.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/linuxout-unsigned.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/linuxout-unsigned.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3b3d65c646a5bb69e096e37f897c7ed48c8a9e9 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/linuxout-unsigned.txt differ diff --git a/hapsigntool_cpp/test/unittest/codeSigning/package/unsigned-linux.txt b/hapsigntool_cpp/test/unittest/codeSigning/package/unsigned-linux.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b82db1b540acd6bacd821b3755d4981525b24d1 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/codeSigning/package/unsigned-linux.txt differ 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 new file mode 100644 index 0000000000000000000000000000000000000000..6c3e22934ac75e4d80345532f03453cf6b103746 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/sign/bc_signeddata_generator_test.cpp @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "bc_signeddata_generator.h" +#include "code_signing.h" +#include "options.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class BCSignedDataGeneratorTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void BCSignedDataGeneratorTest::SetUpTestCase(void) +{ + (void)rename("./codeSigning/entry-default-unsigned-so.txt", "./codeSigning/entry-default-unsigned-so.hap"); + +} + +void BCSignedDataGeneratorTest::TearDownTestCase(void) +{ +} + +void BCSignedDataGeneratorTest::SetUp() +{ +} + +void BCSignedDataGeneratorTest::TearDown() +{ +} + +/** + * @tc.name: GenerateSignedData001 + * @tc.desc: Test function of BCSignedDataGenerator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, GenerateSignedData001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector arr = { 70, 83, 86, 101, 114, 105, 116, 121, 1, 0, 32, 0, -61, -44, + -75, -90, 72, 25, -110, -41, -90, 12, 102, -121, 99, 106, -25, -47, -120, 113, -32, + 30, 62, -64, 23, 114, 12, 25, 105, 121, 116, 88, -20, 4 }; + std::string signed_data(arr.begin(), arr.end()); + + // 1.构造SignerConfig + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + std::string ret; + int result = api->GenerateSignedData(signed_data, &signerConfig, ret); + + EXPECT_NE(result, 0); +} + +/** + * @tc.name: GenerateSignedData002 + * @tc.desc: Test function of BCSignedDataGenerator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, GenerateSignedData002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::string signed_data; + SignerConfig signerConfig; + std::string ret; + int result = api->GenerateSignedData(signed_data, &signerConfig, ret); + + EXPECT_NE(result, 0); +} + +/** + * @tc.name: GenerateSignedData003 + * @tc.desc: Test function of BCSignedDataGenerator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, GenerateSignedData003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::vector arr = { 70, 83, 86, 101, 114, 105, 116, 121, 1, 0, 32, 0, -61, -44, + -75, -90, 72, 25, -110, -41, -90, 12, 102, -121, 99, 106, -25, -47, -120, 113, -32, + 30, 62, -64, 23, 114, 12, 25, 105, 121, 116, 88, -20, 4 }; + std::string signed_data(arr.begin(), arr.end()); + std::string ret; + int result = api->GenerateSignedData(signed_data, NULL, ret); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: GetSigAlg001 + * @tc.desc: Test function of BCSignedDataGenerator::GetSigAlg() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, GetSigAlg001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + // 1.构造SignerConfig + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + std::string sigAlg; + int ret = api->GetSigAlg(&signerConfig, sigAlg); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: GetSigAlg002 + * @tc.desc: Test function of BCSignedDataGenerator::GetSigAlg() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, GetSigAlg002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + // 1.构造SignerConfig + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + std::string sigAlg; + int ret = api->GetSigAlg(&signerConfig, sigAlg); + EXPECT_NE(ret, 0); +} + +/** + * @tc.name: GetSigAlg003 + * @tc.desc: Test function of BCSignedDataGenerator::GetSigAlg() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, GetSigAlg003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + // 1.构造SignerConfig + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA384, "ECDSA_WITH_SHA384", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + std::string sigAlg; + int ret = api->GetSigAlg(&signerConfig, sigAlg); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: SetOwnerId + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(BCSignedDataGeneratorTest, SetOwnerId, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + + std::string ownerID; + api->SetOwnerId(ownerID); + EXPECT_EQ(true, 1); +} diff --git a/hapsigntool_cpp/test/unittest/codeSigning/sign/code_signing_test.cpp b/hapsigntool_cpp/test/unittest/codeSigning/sign/code_signing_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4783914d0a78aef9e2fba44874f1d318464bdac0 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/sign/code_signing_test.cpp @@ -0,0 +1,790 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "code_signing.h" +#include "zip_signer.h" +#include "sign_provider.h" +#include "local_sign_provider.h" +#include "unzip_handle_param.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class CodeSigningTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + (void)rename("./codeSigning/entry-default-unsigned-so.txt", "./codeSigning/entry-default-unsigned-so.hap"); + (void)rename("./codeSigning/entry-default-unsigned-so.txt", "./codeSigning/entry-default-unsigned-so.elf"); + (void)rename("./hapSign/unsigned-linux.txt", "./hapSign/unsigned-linux.hap"); + } + static void TearDownTestCase() + { + } + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: generateSignature001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, generateSignature001, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + + std::vector signedData = {70, 83, 86, 101, 114, 105, 116, 121, 1, + 0, 32, 0, -82, 98, 15, 102, 95, -26, -90, 88, 83, 8, -42, -65, -121, + 117, -43, -95, -102, -56, 109, 93, 25, -9, -88, 44, -25, 119, -39, -68, + -15, 11, 123, -80}; + std::string ownerID; + std::vector ret; + bool flag = codeSigning.GenerateSignature(signedData, ownerID, ret); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: generateSignature002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, generateSignature002, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + + std::vector signedData; + std::string ownerID; + std::vector ret; + bool flag = codeSigning.GenerateSignature(signedData, ownerID, ret); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: GetNativeEntriesFromHap + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, GetNativeEntriesFromHap, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + + std::string packageName = "./codeSigning/entry-default-unsigned-so.hap"; + std::vector> ret; + std::string ownerID; + UnzipHandleParam param(ret, ownerID, true); + bool flag = codeSigning.GetNativeEntriesFromHap(packageName, param); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: getTimestamp + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, getTimestamp, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + int64_t timeStamp = codeSigning.GetTimestamp(); + EXPECT_NE(timeStamp, 0); +} + +/** + * @tc.name: isNativeFile + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, isNativeFile, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + std::string input = "libs/arm64-v8a/libc++_shared.so"; + bool flag = codeSigning.IsNativeFile(input); + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: signFile + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, signFile, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + + std::ifstream inputStream; + inputStream.open("./codeSigning/entry-default-unsigned-so.hap", std::ios::binary); + int64_t fileSize = 3479976; + bool storeTree = true; + int64_t fsvTreeOffset = 1024; + std::string ownerID; + std::pair> ret; + bool flag = codeSigning.SignFile(inputStream, fileSize, storeTree, fsvTreeOffset, ownerID, ret); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: signNativeLibs + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, signNativeLibs, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + std::string input = "./codeSigning/entry-default-unsigned-so.hap"; + std::string ownerID; + bool flag = codeSigning.SignNativeLibs(input, ownerID); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: updateCodeSignBlock + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, updateCodeSignBlock, testing::ext::TestSize.Level1) +{ + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./codeSigning/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./codeSigning/entry-default-signed-so.hap"; + params["profileFile"] = "./codeSigning/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./codeSigning/ohtest.jks"; + params["inFile"] = "./codeSigning/entry-default-unsigned-so.hap"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./codeSigning/entry-default-signed-so.hap")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./codeSigning/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./codeSigning/ohtest.jks")); + options.emplace("appCertFile", std::string("./codeSigning/app-release1.pem")); + options.emplace("inFile", std::string("./codeSigning/entry-default-unsigned-so.hap")); + signerConfig.SetOptions(&options); + + CodeSigning codeSigning(&signerConfig); + codeSigning.UpdateCodeSignBlock(); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: AppendCodeSignBlock + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, AppendCodeSignBlock, testing::ext::TestSize.Level1) +{ + std::shared_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./codeSigning/app-release1.pem"; + std::string profileFile = "./codeSigning/signed-profile.p7b"; + std::string inFile = "./codeSigning/entry-default-unsigned-so.elf"; + std::string keystoreFile = "./codeSigning/ohtest.p12"; + std::string outFile = "./codeSigning/entry-default-signed-so.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string inForm = "elf"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["inForm"] = inForm; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +void SetParamsMap(std::map& params) +{ + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./hapSign/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./hapSign/entry-default-signed.elf"; + params["profileFile"] = "./hapSign/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./hapSign/ohtest.jks"; + params["inFile"] = "./hapSign/unsigned-linux.out"; + params["profileSigned"] = "1"; + params["inForm"] = "elf"; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-" + "feature\":\"hos_system_app\",\"bundle-name\":\"com.OpenHarmony.app.test\",\"developer-id\":\"O" + "penHarmony\",\"distribution-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB" + "44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C76" + "79A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":" + "[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":" + "{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + params["profileContent"] = provision; +} + +void SetOptions(Options* options) +{ + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned-linux.out"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + static char keyPwd[] = "123456"; + static char keystorePwd[] = "123456"; + + (*options)["mode"] = "localSign"; + (*options)["keyAlias"] = keyAlias; + (*options)["signAlg"] = signAlg; + (*options)["signCode"] = signCode; + (*options)["appCertFile"] = appCertFile; + (*options)["profileFile"] = profileFile; + (*options)["inFile"] = inFile; + (*options)["keystoreFile"] = keystoreFile; + (*options)["outFile"] = outFile; + (*options)["inForm"] = inForm; + (*options)["keyPwd"] = keyPwd; + (*options)["keystorePwd"] = keystorePwd; +} + +/** + * @tc.name: GetElfCodeSignBlock + * @tc.desc: Test function of CodeSigning::GetElfCodeSignBlock interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, GetElfCodeSignBlock001, testing::ext::TestSize.Level1) +{ + // success + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + signerConfig.SetOptions(options.get()); + signerConfig.GetSigner(); + + CodeSigning codeSigning(&signerConfig); + std::string inputFile = "./hapSign/tmpFile1718344274"; + int64_t offset = 29184024; + std::vector codesignData; + std::string inForm = "elf"; + bool ret = codeSigning.GetElfCodeSignBlock(inputFile, offset, inForm, params.at("profileContent"), codesignData); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: GetElfCodeSignBlock002 + * @tc.desc: Test function of CodeSigning::GetElfCodeSignBlock interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, GetElfCodeSignBlock002, testing::ext::TestSize.Level1) +{ + // inForm error + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + params["inForm"] = "bin"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + (*options)["inForm"] = "bin"; + signerConfig.SetOptions(options.get()); + signerConfig.GetSigner(); + + CodeSigning codeSigning(&signerConfig); + std::string inputFile = "./hapSign/tmpFile1718344274"; + int64_t offset = 29184024; + std::vector codesignData; + std::string inForm = "bin"; + bool ret = codeSigning.GetElfCodeSignBlock(inputFile, offset, inForm, params.at("profileContent"), codesignData); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: GetElfCodeSignBlock003 + * @tc.desc: Test function of CodeSigning::GetElfCodeSignBlock interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, GetElfCodeSignBlock003, testing::ext::TestSize.Level1) +{ + // inFile error + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + params["inFile"] = "./hapSign_test/tmpFile1718344274"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + (*options)["inFile"] = "./hapSign_test/tmpFile1718344274"; + signerConfig.SetOptions(options.get()); + signerConfig.GetSigner(); + + CodeSigning codeSigning(&signerConfig); + std::string inputFile = params.at("inFile"); + int64_t offset = 29184024; + std::vector codesignData; + std::string inForm = "elf"; + bool ret = codeSigning.GetElfCodeSignBlock(inputFile, offset, inForm, params.at("profileContent"), codesignData); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: GetElfCodeSignBlock004 + * @tc.desc: Test function of CodeSigning::GetElfCodeSignBlock interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CodeSigningTest, GetElfCodeSignBlock004, testing::ext::TestSize.Level1) +{ + // signatureAlgorithm set DSA_WITH_SHA256 error + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::DSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + signerConfig.SetOptions(options.get()); + signerConfig.GetSigner(); + + CodeSigning codeSigning(&signerConfig); + std::string inputFile = params.at("inFile"); + int64_t offset = 29184024; + std::vector codesignData; + std::string inForm = "elf"; + bool ret = codeSigning.GetElfCodeSignBlock(inputFile, offset, inForm, params.at("profileContent"), codesignData); + EXPECT_EQ(ret, false); +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..5a27850469f39287c5a773446b44e89b3db3f66f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/sign/verify_code_signature_test.cpp @@ -0,0 +1,502 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "verify_code_signature.h" +#include "verify_hap.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class VerifyCodeSignatureTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void VerifyCodeSignatureTest::SetUpTestCase(void) +{ + (void)rename("./codeSigning/hap_no_suffix_err.txt", "./codeSigning/hap_no_suffix_err"); + (void)rename("./codeSigning/elf_parse_sign_block_err.txt", "./codeSigning/elf_parse_sign_block_err.elf"); + (void)rename("./codeSigning/hap_merkle_tree_err.txt", "./codeSigning/hap_merkle_tree_err.elf"); + (void)rename("./codeSigning/hap_profile_is_null_err.txt", "./codeSigning/hap_profile_is_null_err.hap"); + (void)rename("./codeSigning/hap_invalid_block_header_err.txt", "./codeSigning/hap_invalid_block_header_err.hap"); + (void)rename("./codeSigning/hap_offset_align_err.txt", "./codeSigning/hap_offset_align_err.hap"); + (void)rename("./codeSigning/hap_magic_number_err.txt", "./codeSigning/hap_magic_number_err.hap"); + (void)rename("./codeSigning/hap_segment_header_err.txt", "./codeSigning/hap_segment_header_err.hap"); + (void)rename("./codeSigning/entry-default-signed-so.txt", "./codeSigning/entry-default-signed-so.hap"); + (void)rename("./codeSigning/hap_file_type_err.txt", "./codeSigning/hap_file_type_err.elf"); + (void)rename("./codeSigning/hap_native_libs_err.txt", "./codeSigning/hap_native_libs_err.hap"); +} + +void VerifyCodeSignatureTest::TearDownTestCase(void) +{ +} + +void VerifyCodeSignatureTest::SetUp() +{ +} + +void VerifyCodeSignatureTest::TearDown() +{ +} + +/** + * @tc.name: AreVectorsEqual001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, AreVectorsEqual001, testing::ext::TestSize.Level1) +{ + std::vector vec1{ 21, 53, 29, 18, -17, 56, 92, 60, 29, 10, 28, 18, 19, 52, 59, 92 }; + std::vector vec2{ 21, 53, 29, 18, -17, 56, 92, 60, 29, 10, 28, 18, 19, 52, 59, 92 }; + bool flag = VerifyCodeSignature::AreVectorsEqual(vec1, vec2); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: AreVectorsEqual002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, AreVectorsEqual002, testing::ext::TestSize.Level1) +{ + std::vector vec1{ 21, 53, 29, 19, -17, 56, 92, 60, 29, 10, 28, 18, 19 }; + std::vector vec2{ 21, 53, 29, 18, -17, 56, 92, 60, 29, 10, 28, 18, 19, 52, 59, 92 }; + bool flag = VerifyCodeSignature::AreVectorsEqual(vec1, vec2); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyCodeSign + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyCodeSign, testing::ext::TestSize.Level1) +{ + std::pair pairResult = std::make_pair("", "debug"); + std::string file = "./codeSigning/entry-default-signed-so.hap"; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = "hap"; + std::string profileContent = ""; + VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + CodeSignBlock csb; + bool flag = VerifyCodeSignature::VerifyCodeSign(file, pairResult, csb); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap001, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/entry-default-signed-so.hap"; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = "hap"; + std::string profileContent = ""; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap002, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/entry-default-signed-so.hap"; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = ""; + std::string profileContent = ""; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: VerifyHap003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap003, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/entry-default-signed-so.hap"; + int64_t offset = 1397151; + int64_t length = 23194; + std::string fileFormat = "hap"; + std::string profileContent = ""; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap004, testing::ext::TestSize.Level1) +{ + std::string file = ""; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = "hap"; + std::string profileContent = ""; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap005, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_invalid_block_header_err.hap"; + int64_t offset = 1397151; + int64_t length = 23221; + std::string fileFormat = "hap"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap006, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_offset_align_err.hap"; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = "hap"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap007 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap007, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_magic_number_err.hap"; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = "hap"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap008 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyHap008, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_segment_header_err.hap"; + int64_t offset = 1397151; + int64_t length = 23193; + std::string fileFormat = "hap"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifySingleFile + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifySingleFile, testing::ext::TestSize.Level1) +{ + std::ifstream input; + input.open("./codeSigning/entry-default-signed-so.hap", std::ios::binary); + int64_t length = 4096; + std::vector signature; + int64_t merkleTreeOffset = 64; + std::vector inMerkleTreeBytes; + bool flag = VerifyCodeSignature::VerifySingleFile(input, length, signature, merkleTreeOffset, inMerkleTreeBytes); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElf001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf001, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_merkle_tree_err.elf"; + int64_t offset = 8216; + int64_t length = 10516; + std::string fileFormat = "elf"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElf002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf002, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_merkle_tree_err.elf"; + int64_t offset = 8216; + int64_t length = 10516; + std::string fileFormat = "hap"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: VerifyElf003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf003, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_merkle_tree_err111.elf"; + int64_t offset = 8216; + int64_t length = 10516; + std::string fileFormat = "elf"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElf004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf004, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_merkle_tree_err.elf"; + int64_t offset = 8216; + int64_t length = 2; + std::string fileFormat = "elf"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElf005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf005, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_merkle_tree_err.elf"; + int64_t offset = 8216; + int64_t length = 10516; + std::string fileFormat = "elf"; + std::string profileContent = "{\"version-code\":1,\"app-identifier\":\"111\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElf006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf006, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_file_type_err.elf"; + int64_t offset = 8216; + int64_t length = 10516; + std::string fileFormat = "elf"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElf007 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyElf007, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/elf_parse_sign_block_err.elf"; + int64_t offset = 8216; + int64_t length = 10516; + std::string fileFormat = "elf"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyElf(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyNativeLib001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyNativeLib001, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_native_libs_err.hap"; + unzFile zFile = unzOpen(file.c_str()); + std::pair pairResult; + pairResult.first = "111"; + pairResult.second = "222"; + CodeSignBlock csb; + bool flag = VerifyCodeSignature::VerifyNativeLib(csb, file, zFile, pairResult); + unzClose(zFile); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyNativeLib002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyCodeSignatureTest, VerifyNativeLib002, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/hap_profile_is_null_err.hap"; + int64_t offset = 1397151; + int64_t length = 23221; + std::string fileFormat = "hap"; + std::string profileContent = "{\"version-code\":1,\"version-name\":\"1.0.0\"}"; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: CheckCodeSign001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +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")); + + HapVerifyResult hapVerifyResult; + VerifyHap hapVerifyV2; + int32_t ret = hapVerifyV2.Verify(options.GetString(Options::IN_FILE), hapVerifyResult, &options); + + EXPECT_NE(ret, 0); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..73917bd12bc502039bb21da657dc3447679bd66a --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/utils/cms_utils_test.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "cms_utils.h" +#include "verify_code_signature.h" + +using namespace OHOS::SignatureTools; + +/* + * 测试套件,固定写法 + */ +class CmsUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void CmsUtilsTest::SetUpTestCase(void) +{ + (void)rename("./codeSigning/entry-default-unsigned-so.txt", "./codeSigning/entry-default-unsigned-so.hap"); +} + +void CmsUtilsTest::TearDownTestCase(void) +{ +} + +void CmsUtilsTest::SetUp() +{ +} + +void CmsUtilsTest::TearDown() +{ +} + +/** + * @tc.name: CheckOwnerID001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, CheckOwnerID001, testing::ext::TestSize.Level1) +{ + // 走进分支 if (p7 == nullptr) + const std::string signature; + const std::string profileOwnerID; + const std::string profileType = "debug"; + bool flag = CmsUtils::CheckOwnerID(signature, profileOwnerID, profileType); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: CheckOwnerID002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, CheckOwnerID002, testing::ext::TestSize.Level1) +{ + // 走进 for 下的 if ("debug" == profileType) 分支 + std::string signature; + FileUtils::ReadFile("./codeSigning/signed-profile.p7b", signature); + + const std::string profileOwnerID = "xxx"; + const std::string profileType = "debug"; + bool flag = CmsUtils::CheckOwnerID(signature, profileOwnerID, profileType); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: CheckOwnerID003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, CheckOwnerID003, testing::ext::TestSize.Level1) +{ + // 走进 for 下的 if (ownerID.empty()) 分支 + std::string signature; + FileUtils::ReadFile("./codeSigning/signed-profile.p7b", signature); + + const std::string profileOwnerID; + const std::string profileType = "release"; + bool flag = CmsUtils::CheckOwnerID(signature, profileOwnerID, profileType); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: CheckOwnerID004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, CheckOwnerID004, testing::ext::TestSize.Level1) +{ + // 走进 for 下的 else 分支 + std::string signature; + FileUtils::ReadFile("./codeSigning/signed-profile.p7b", signature); + + const std::string profileOwnerID = "007"; + const std::string profileType = "release"; + bool flag = CmsUtils::CheckOwnerID(signature, profileOwnerID, profileType); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyHap + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, VerifyHap, testing::ext::TestSize.Level1) +{ + std::string file = "./codeSigning/entry-default-signed-so.hap"; + int64_t offset = 1397151; + int64_t length = 23221; + std::string fileFormat = "hap"; + std::string profileContent = ""; + bool flag = VerifyCodeSignature::VerifyHap(file, offset, length, fileFormat, profileContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: CreateNIDFromOID + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, CreateNIDFromOID, testing::ext::TestSize.Level1) +{ + std::string oid; + std::string shortName; + std::string longName; + int nID = CmsUtils::CreateNIDFromOID(oid, shortName, longName); + + EXPECT_EQ(nID, 0); +} + +/** + * @tc.name: VerifySignDataWithUnsignedDataDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(CmsUtilsTest, VerifySignDataWithUnsignedDataDigest, testing::ext::TestSize.Level1) +{ + std::vector unsignedDataDigest; + std::vector signedData; + bool flag = CmsUtils::VerifySignDataWithUnsignedDataDigest(unsignedDataDigest, signedData); + + EXPECT_EQ(flag, false); +} diff --git a/hapsigntool_cpp/test/unittest/codeSigning/utils/fs_digest_utils_test.cpp b/hapsigntool_cpp/test/unittest/codeSigning/utils/fs_digest_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8431dced75a8e49b5edc7f5c69dfaafa4713b14 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/codeSigning/utils/fs_digest_utils_test.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "fs_digest_utils.h" + + /* + * 测试套件,固定写法 + */ +class DigestUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: addData001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(DigestUtilsTest, addData001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(HASH_SHA256); + + char charData[32] = { -66, -72, 8, -21, 1, 28, 23, 2, -1, -1, -1, -1, 15, 16, 40, -57, -34, + -119, 1, 6, -76, -72, 8, -66, -72, 8, -66, -72, 8, -86, -50, 8 }; + std::string data(charData); + api->AddData(data); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: addData002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(DigestUtilsTest, addData002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(HASH_SHA256); + + char pData[32] = { -66, -72, 8, -21, 1, 28, 23, 2, -1, -1, -1, -1, 15, 16, 40, -57, -34, + -119, 1, 6, -76, -72, 8, -66, -72, 8, -66, -72, 8, -86, -50, 8 }; + int length = 32; + api->AddData(pData, length); + + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: result + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(DigestUtilsTest, result, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(HASH_SHA256); + + DigestUtils::Type type = DigestUtils::Type::HEX; + std::string str = api->Result(type); + + EXPECT_EQ(str.size(), 64); +} diff --git a/hapsigntool_cpp/test/unittest/elfVerify/hap_utils_test.cpp b/hapsigntool_cpp/test/unittest/elfVerify/hap_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3cbcdc76b5563005f7606854f64c5d26f1c7bba3 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/hap_utils_test.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "hap_utils.h" +#include "byte_buffer.h" + +using namespace OHOS::SignatureTools; + +class HapUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GetAppIdentifier + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapUtilsTest, GetAppIdentifier, testing::ext::TestSize.Level1) +{ + std::string content = "{\"type\":\"xxx\",\"bundle-info\":{\"app-identifier\":\"123\"}}"; + std::string result = HapUtils::GetAppIdentifier(content); + int length = result.length(); + + EXPECT_NE(length, 0); +} + +/** + * @tc.name: GetHapSigningBlockMagic + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapUtilsTest, GetHapSigningBlockMagic, testing::ext::TestSize.Level1) +{ + std::vector result = HapUtils::GetHapSigningBlockMagic(4); + int size = result.size(); + + EXPECT_NE(size, 0); +} + +/** + * @tc.name: GetHapSigningBlockVersion + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapUtilsTest, GetHapSigningBlockVersion, testing::ext::TestSize.Level1) +{ + int result = HapUtils::GetHapSigningBlockVersion(4); + + EXPECT_NE(result, 0); +} + +/** + * @tc.name: ReadFileToByteBuffer + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HapUtilsTest, ReadFileToByteBuffer, testing::ext::TestSize.Level1) +{ + std::string file; + ByteBuffer buffer; + bool result = HapUtils::ReadFileToByteBuffer(file, buffer); + + EXPECT_EQ(result, false); +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/bin_get_digest_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_get_digest_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a749b9e2d95d56e86acd32677db62205d045999 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_get_digest_err_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/bin_get_profile_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_get_profile_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f1d2603843353787295cb1f953da3bc50066daa Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_get_profile_err_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/bin_signed_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_signed_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..3112a97020fe4921d663f5821dcd17756853f413 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_signed_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/bin_unsigned_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_unsigned_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3b3d65c646a5bb69e096e37f897c7ed48c8a9e9 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_unsigned_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/bin_verify_digest_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_verify_digest_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..e844ba0d6e60b597cc480d49d9e8e120c01cff70 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/bin_verify_digest_err_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/elf_check_file_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_check_file_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..f61a73deb26db1475ced660489120f9182ae20c0 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_check_file_err_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/elf_check_ownerid_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_check_ownerid_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..3141125a0def97213e8ecd48e0c12c3809c53695 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_check_ownerid_err_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/elf_signed_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_signed_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..237bd8e7223b7240b2e4483920f8d0e8e50d16ef Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_signed_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/elf_unsigned_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_unsigned_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3b3d65c646a5bb69e096e37f897c7ed48c8a9e9 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_unsigned_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/elf_verify_data_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_verify_data_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a1214da11124253ead4ccb1e427f41b9391e5b8 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_verify_data_err_package.txt differ diff --git a/hapsigntool_cpp/test/unittest/elfVerify/package/elf_verify_pkcs7_err_package.txt b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_verify_pkcs7_err_package.txt new file mode 100644 index 0000000000000000000000000000000000000000..cbda152702fe8df3416a842a10cbcd6410140583 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/elfVerify/package/elf_verify_pkcs7_err_package.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 new file mode 100644 index 0000000000000000000000000000000000000000..35b8508e38dbba1d8701ddc652daaa72b2d46888 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/sign_block_info_test.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "sign_block_info.h" + +using namespace OHOS::SignatureTools; + +class SignBlockInfoTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GetSignBlockMap + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockInfoTest, GetSignBlockMap, testing::ext::TestSize.Level1) +{ + SignBlockInfo signBlockInfo(false); + std::unordered_map signBlockMap = signBlockInfo.GetSignBlockMap(); + int size = signBlockMap.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetFileDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockInfoTest, GetFileDigest, testing::ext::TestSize.Level1) +{ + SignBlockInfo signBlockInfo(true); + std::vector fileDigest = signBlockInfo.GetFileDigest(); + int size = fileDigest.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: SetFileDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockInfoTest, SetFileDigest, testing::ext::TestSize.Level1) +{ + SignBlockInfo signBlockInfo(true); + std::vector fileDigest; + signBlockInfo.SetFileDigest(fileDigest); + int size = fileDigest.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetRawDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockInfoTest, GetRawDigest, testing::ext::TestSize.Level1) +{ + SignBlockInfo signBlockInfo(true); + std::vector digest = signBlockInfo.GetRawDigest(); + int size = digest.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: SetRawDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockInfoTest, SetRawDigest, testing::ext::TestSize.Level1) +{ + SignBlockInfo signBlockInfo(true); + std::vector digest; + signBlockInfo.SetRawDigest(digest); + int size = digest.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetNeedGenerateDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockInfoTest, GetNeedGenerateDigest, testing::ext::TestSize.Level1) +{ + SignBlockInfo signBlockInfo(true); + bool needGenerateDigest = signBlockInfo.GetNeedGenerateDigest(); + + EXPECT_EQ(needGenerateDigest, true); +} diff --git a/hapsigntool_cpp/test/unittest/elfVerify/sign_content_info_test.cpp b/hapsigntool_cpp/test/unittest/elfVerify/sign_content_info_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a7f75b0b73e30e34e10e082016fc78ad8ef3668 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/sign_content_info_test.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "sign_content_info.h" + +using namespace OHOS::SignatureTools; + +class SignContentInfoTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; diff --git a/hapsigntool_cpp/test/unittest/elfVerify/signature_block_types_test.cpp b/hapsigntool_cpp/test/unittest/elfVerify/signature_block_types_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6573e1ad6cb41f5cea72f3f3817f7cd75adff77c --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/signature_block_types_test.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "signature_block_types.h" + +using namespace OHOS::SignatureTools; + +class SignatureBlockTypesTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GetProfileBlockTypes001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignatureBlockTypesTest, GetProfileBlockTypes001, testing::ext::TestSize.Level1) +{ + char type = SignatureBlockTypes::GetProfileBlockTypes("0"); + bool flag = type == SignatureBlockTypes::PROFILE_NOSIGNED_BLOCK; + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: GetProfileBlockTypes002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignatureBlockTypesTest, GetProfileBlockTypes002, testing::ext::TestSize.Level1) +{ + char type = SignatureBlockTypes::GetProfileBlockTypes("1"); + bool flag = type == SignatureBlockTypes::PROFILE_SIGNED_BLOCK; + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: GetProfileBlockTypes003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignatureBlockTypesTest, GetProfileBlockTypes003, testing::ext::TestSize.Level1) +{ + char type = SignatureBlockTypes::GetProfileBlockTypes("2"); + bool flag = type == SignatureBlockTypes::PROFILE_NOSIGNED_BLOCK; + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: GetProfileBlockTypes004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignatureBlockTypesTest, GetProfileBlockTypes004, testing::ext::TestSize.Level1) +{ + char type = SignatureBlockTypes::GetProfileBlockTypes(""); + bool flag = type == SignatureBlockTypes::PROFILE_NOSIGNED_BLOCK; + + EXPECT_EQ(flag, true); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..f056d0d42f5dc386549ccceeaab992df55de2d0e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/signing_block_test.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "signing_block.h" + +using namespace OHOS::SignatureTools; + +class SigningBlockTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: GetLength + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SigningBlockTest, GetLength, testing::ext::TestSize.Level1) +{ + std::vector value; + SigningBlock signingBlock(0, value, 0); + int32_t length = signingBlock.GetLength(); + + EXPECT_EQ(length, 0); +} + +/** + * @tc.name: GetValue + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SigningBlockTest, GetValue, testing::ext::TestSize.Level1) +{ + std::vector value; + SigningBlock signingBlock(0, value, 0); + std::vector val = signingBlock.GetValue(); + int size = val.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetOffset + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SigningBlockTest, GetOffset, testing::ext::TestSize.Level1) +{ + std::vector value; + SigningBlock signingBlock(0, value, 0); + int32_t offset = signingBlock.GetOffset(); + + EXPECT_EQ(offset, 0); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..01f87f3074f93f69273a4b48ec28872ab9de1672 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/verify_bin_test.cpp @@ -0,0 +1,504 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "verify_bin.h" +#include "sign_bin.h" +#include "hash_utils.h" + +using namespace OHOS::SignatureTools; + +class VerifyBinTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void VerifyBinTest::SetUpTestCase(void) +{ + (void)rename("./elfVerify/bin_verify_digest_err_package.txt", "./elfVerify/bin_verify_digest_err_package.bin"); + (void)rename("./elfVerify/bin_get_profile_err_package.txt", "./elfVerify/bin_get_profile_err_package.bin"); + (void)rename("./elfVerify/bin_get_digest_err_package.txt", "./elfVerify/bin_get_digest_err_package.bin"); + (void)rename("./elfVerify/bin_signed_package.txt", "./elfVerify/bin_signed_package.bin"); + (void)rename("./elfVerify/bin_unsigned_package.txt", "./elfVerify/bin_unsigned_package.bin"); +} + +void VerifyBinTest::TearDownTestCase(void) +{ +} + +void VerifyBinTest::SetUp() +{ +} + +void VerifyBinTest::TearDown() +{ +} + +static const std::map PARAMS = { {"keyPwd", "123456"}, + {"mode", "localSign"}, + {"keyAlias", "oh-app1-key-v1"}, + {"signAlg", "SHA256withECDSA"}, + {"appCertFile", "./hapSign/app-release1.pem"}, + {"signCode", "1"}, + {"compatibleVersion", "9"}, + {"keystorePwd", "123456"}, + {"outFile", "./elfVerify/linuxout-signed.bin"}, + {"profileSigned", "1"}, + {"profileFile", "./hapSign/signed-profile.p7b"}, + {"keystoreFile", "./hapSign/ohtest.jks"}, + {"inFile", "./elfVerify/linuxout-unsigned.bin"} }; + +/** + * @tc.name: Verify001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify001, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_signed_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: Verify002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify002, testing::ext::TestSize.Level1) +{ + VerifyBin verifyBin; + bool flag = verifyBin.Verify(nullptr); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify003, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_signed_package.bin")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify004, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_signed_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify005, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify006, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_signed_package111.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify007 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify007, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_unsigned_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify008 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify008, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_signed_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/readonly.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: Verify009 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify009, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_verify_digest_err_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify010 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify010, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_get_profile_err_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify011 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, Verify011, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/bin_get_digest_err_package.bin")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyBin verifyBin; + bool flag = verifyBin.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignBin001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, SignBin001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::map signParams; + signParams["a"] = "4"; + signParams["appCertFile"] = "./hapSign/app-release1.pem"; + signParams["compatibleVersion"] = "9"; + signParams["inFile"] = "./elfVerify/bin_unsigned_package.bin"; + signParams["inForm"] = "bin"; + signParams["keyAlias"] = "oh-app1-key-v1"; + signParams["keyPwd"] = "123456"; + signParams["keystoreFile"] = "./hapSign/ohtest.p12"; + signParams["keystorePwd"] = "123456"; + signParams["outFile"] = "./elfVerify/bin_signed_package.bin"; + signParams["profileFile"] = "./hapSign/signed-profile.p7b"; + signParams["profileSigned"] = "1"; + signParams["signAlg"] = "SHA256withECDSA"; + signParams["signCode"] = "1"; + + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + signerConfig.FillParameters(PARAMS); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./elfVerify/bin_signed_package.bin")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.p12")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/bin_unsigned_package.bin")); + signerConfig.SetOptions(&options); + bool flag = api->Sign(signerConfig, signParams); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: GetHashAlgsId001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgsId001, testing::ext::TestSize.Level1) +{ + int algId = HashUtils::GetHashAlgsId("SHA-224"); + + EXPECT_EQ(algId, 0); +} + +/** + * @tc.name: GetHashAlgsId002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgsId002, testing::ext::TestSize.Level1) +{ + int algId = HashUtils::GetHashAlgsId("SHA-256"); + + EXPECT_EQ(algId, 6); +} + +/** + * @tc.name: GetHashAlgsId003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgsId003, testing::ext::TestSize.Level1) +{ + int algId = HashUtils::GetHashAlgsId("SHA-384"); + + EXPECT_EQ(algId, 7); +} + +/** + * @tc.name: GetHashAlgsId004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgsId004, testing::ext::TestSize.Level1) +{ + int algId = HashUtils::GetHashAlgsId("SHA-512"); + + EXPECT_EQ(algId, 8); +} + +/** + * @tc.name: GetHashAlgName001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgName001, testing::ext::TestSize.Level1) +{ + std::string alg = HashUtils::GetHashAlgName(5); + int size = alg.size(); + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetHashAlgName002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgName002, testing::ext::TestSize.Level1) +{ + std::string alg = HashUtils::GetHashAlgName(6); + int size = alg.size(); + EXPECT_NE(size, 0); +} + +/** + * @tc.name: GetHashAlgName003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgName003, testing::ext::TestSize.Level1) +{ + std::string alg = HashUtils::GetHashAlgName(7); + int size = alg.size(); + EXPECT_NE(size, 0); +} + +/** + * @tc.name: GetHashAlgName004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetHashAlgName004, testing::ext::TestSize.Level1) +{ + std::string alg = HashUtils::GetHashAlgName(8); + int size = alg.size(); + EXPECT_NE(size, 0); +} + +/** + * @tc.name: GetDigestFromBytes001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetDigestFromBytes001, testing::ext::TestSize.Level1) +{ + std::vector fileBytes; + int64_t length = 0; + std::string algName = "SHA-256"; + std::vector dig = HashUtils::GetDigestFromBytes(fileBytes, length, algName); + int size = dig.size(); + + EXPECT_EQ(size, 0); +} + +/** + * @tc.name: GetDigestFromBytes002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyBinTest, GetDigestFromBytes002, testing::ext::TestSize.Level1) +{ + std::vector fileBytes = { 1, 1 }; + int64_t length = 0; + std::string algName = "SHA-256"; + std::vector dig = HashUtils::GetDigestFromBytes(fileBytes, length, algName); + int size = dig.size(); + + EXPECT_EQ(size, 0); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..75150fbc38c4ab7c8a9a9847f8fa9f3a3bd2b411 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/elfVerify/verify_elf_test.cpp @@ -0,0 +1,780 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "verify_elf.h" +#include "hw_block_data.h" +#include "sign_provider.h" +#include "verify_hap.h" + +using namespace OHOS::SignatureTools; + +class VerifyElfTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void VerifyElfTest::SetUpTestCase(void) +{ + (void)rename("./elfVerify/elf_verify_data_err_package.txt", "./elfVerify/elf_verify_data_err_package.elf"); + (void)rename("./elfVerify/elf_verify_pkcs7_err_package.txt", "./elfVerify/elf_verify_pkcs7_err_package.elf"); + (void)rename("./elfVerify/elf_check_ownerid_err_package.txt", "./elfVerify/elf_check_ownerid_err_package.elf"); + (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 VerifyElfTest::TearDownTestCase(void) +{ +} + +void VerifyElfTest::SetUp() +{ +} + +void VerifyElfTest::TearDown() +{ +} + +/** + * @tc.name: Verify001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify001, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.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: Verify002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify002, testing::ext::TestSize.Level1) +{ + VerifyElf verifyElf; + bool flag = verifyElf.Verify(nullptr); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify003, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyElf verifyElf; + bool flag = verifyElf.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify004, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + + VerifyElf verifyElf; + bool flag = verifyElf.Verify(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Verify005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify005, testing::ext::TestSize.Level1) +{ + Options options; + 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, false); +} + +/** + * @tc.name: Verify006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify006, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package111.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, false); +} + +/** + * @tc.name: Verify007 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify007, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_unsigned_package.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, false); +} + +/** + * @tc.name: Verify008 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify008, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/readonly.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + VerifyElf verifyElf; + bool flag = verifyElf.Verify(&options); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: Verify009 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify009, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_check_ownerid_err_package.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, false); +} + +/** + * @tc.name: Verify010 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify010, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_verify_data_err_package.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, false); +} + +/** + * @tc.name: Verify011 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify011, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_verify_pkcs7_err_package.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, false); +} + +/** + * @tc.name: Verify013 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, Verify013, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_check_file_err_package.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 SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, CheckParams, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + bool flag = VerifyElf::CheckParams(&options); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: CheckSignFile + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, CheckSignFile, testing::ext::TestSize.Level1) +{ + std::string file = "./elfVerify/elf_signed_package.elf"; + + bool flag = VerifyElf::CheckSignFile(file); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: GetSignBlockData + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, GetSignBlockData, testing::ext::TestSize.Level1) +{ + std::vector bytes = { 1, 1, 1, 1, 1, 1, 1, 1 }; + HwBlockData hwBlockData(0, 0); + + bool flag = VerifyElf::GetSignBlockData(bytes, hwBlockData, "elf"); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: GetSignBlockInfo + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, GetSignBlockInfo, testing::ext::TestSize.Level1) +{ + std::string file = "./elfVerify/elf_signed_package.elf"; + SignBlockInfo signBlockInfo(false); + + bool flag = VerifyElf::GetSignBlockInfo(file, signBlockInfo, "elf"); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: GetFileDigest + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, GetFileDigest, testing::ext::TestSize.Level1) +{ + std::string file = "./elfVerify/elf_signed_package.elf"; + SignBlockInfo signBlockInfo(false); + VerifyElf::GetSignBlockInfo(file, signBlockInfo, "elf"); + std::vector fileBytes = { 1, 1, 1, 1, 1, 1, 1, 1 }; + std::vector signatrue = { 1, 1, 1, 1, 1, 1, 1, 1 }; + + bool flag = VerifyElf::GetFileDigest(fileBytes, signatrue, signBlockInfo); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: GetRawContent + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, GetRawContent, testing::ext::TestSize.Level1) +{ + std::vector contentVec = { 1, 1, 1, 1, 1, 1, 1, 1 }; + std::string rawContent; + + bool flag = VerifyElf::GetRawContent(contentVec, rawContent); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyP7b + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, VerifyP7b, testing::ext::TestSize.Level1) +{ + std::unordered_map signBlockMap; + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + Pkcs7Context pkcs7Context; + HapVerifyResult verifyResult; + std::string profileJson; + + bool flag = VerifyElf::VerifyP7b(signBlockMap, &options, pkcs7Context, verifyResult, profileJson); + + EXPECT_EQ(flag, true); +} + +/** + * @tc.name: SignElf001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf001, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("signCode", std::string("1")); + options.emplace("inForm", std::string("elf")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf002, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("signCode", std::string("0")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf003, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("signCode", std::string("2")); + options.emplace("inForm", std::string("elf")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf004, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package")); + options.emplace("signCode", std::string("1")); + options.emplace("inForm", std::string("elf")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf005, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package111.elf")); + options.emplace("signCode", std::string("1")); + options.emplace("inForm", std::string("elf")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf006, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA512withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("signCode", std::string("1")); + options.emplace("inForm", std::string("elf")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf007 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf007, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("signCode", std::string("1")); + options.emplace("inForm", std::string("elf")); + options.emplace("compatibleVersion", std::string("a")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignElf008 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignElf008, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile111.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("signCode", std::string("1")); + options.emplace("inForm", std::string("elf")); + + SignProvider signProvider; + bool flag = signProvider.SignElf(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: SignBin001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, SignBin001, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace("mode", std::string("localSign")); + options.emplace("keyPwd", std::string("123456")); + options.emplace("outFile", std::string("./hapSign/entry-default-signed.elf")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/signed-profile.p7b")); + options.emplace("signAlg", std::string("SHA512withECDSA")); + options.emplace("keystorePwd", std::string("123456")); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.jks")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./elfVerify/elf_unsigned_package.elf")); + options.emplace("inForm", std::string("bin")); + + SignProvider signProvider; + bool flag = signProvider.SignBin(&options); + + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: VerifyElfProfile001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, VerifyElfProfile001, testing::ext::TestSize.Level1) +{ + Options options; + std::vector profileData = { 1, 1, 1, 1, 1, 1, 1, 1 }; + HapVerifyResult result; + Pkcs7Context pkcs7Context; + VerifyHap verifyHap; + int32_t flag = verifyHap.VerifyElfProfile(profileData, result, &options, pkcs7Context); + + EXPECT_NE(flag, -1); +} + +/** + * @tc.name: WriteVerifyOutput001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, WriteVerifyOutput001, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_PROFILE, std::string("./elfVerify/xx.p7b")); + + SignBlockInfo signBlockInfo(false); + VerifyElf::GetSignBlockInfo("./elfVerify/elf_signed_package.elf", signBlockInfo, "elf"); + std::unordered_map signBlockMap = signBlockInfo.GetSignBlockMap(); + SigningBlock profileSign = signBlockMap.find(2)->second; + std::vector profileByte = profileSign.GetValue(); + HapVerifyResult result; + Pkcs7Context pkcs7Context; + VerifyHap hapVerifyV2; + hapVerifyV2.VerifyElfProfile(profileByte, result, &options, pkcs7Context); + int32_t flag = hapVerifyV2.WriteVerifyOutput(pkcs7Context, result.GetProfile(), &options); + + EXPECT_NE(flag, 0); +} + +/** + * @tc.name: WriteVerifyOutput002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(VerifyElfTest, WriteVerifyOutput002, testing::ext::TestSize.Level1) +{ + Options options; + options.emplace(Options::IN_FILE, std::string("./elfVerify/elf_signed_package.elf")); + options.emplace(Options::OUT_CERT_CHAIN, std::string("./elfVerify/xx.cer")); + + SignBlockInfo signBlockInfo(false); + VerifyElf::GetSignBlockInfo("./elfVerify/elf_signed_package.elf", signBlockInfo, "elf"); + std::unordered_map signBlockMap = signBlockInfo.GetSignBlockMap(); + SigningBlock profileSign = signBlockMap.find(2)->second; + std::vector profileByte = profileSign.GetValue(); + HapVerifyResult result; + Pkcs7Context pkcs7Context; + VerifyHap hapVerifyV2; + hapVerifyV2.VerifyElfProfile(profileByte, result, &options, pkcs7Context); + int32_t flag = hapVerifyV2.WriteVerifyOutput(pkcs7Context, result.GetProfile(), &options); + + EXPECT_NE(flag, 0); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..d486b3b541576e862f86095619ea9840a6f40d2c --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateCA/generate_ca_test.cpp @@ -0,0 +1,1828 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" +#include "fs_digest_utils.h" +#include "constant.h" +#include +#include + +namespace OHOS { +namespace SignatureTools { + +class GenerateCaTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + + +// rootCa +/** + * @tc.name: generate_ca_test_001 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/profile.cer"; + int keySize = 384; + int validity = 3650; + char secret[] = "123456"; + char ksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, true); +} + +// rootCa +/** + * @tc.name: generate_ca_test_002 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, true); +} + +// rootCa +/** + * @tc.name: generate_ca_test_003 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + int keySize = 384; + int validity = 365; + int basicConstraintsPathLen = 0; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["validity"] = validity; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_004 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + int keySize = 384; + int validity = 365; + int basicConstraintsPathLen = 0; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["validity"] = validity; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_005 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + int keySize = 384; + int validity = 365; + int basicConstraintsPathLen = 0; + (*params)["keyAlias"] = keyAlias; + (*params)["keySize"] = keySize; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["validity"] = validity; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_006 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/profile.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "adhjkljasjhdk"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_007 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/profile.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "adhjkljasjhdk"; + char ksPwd[] = "123456"; + char isksPwd[] = "554245"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_008 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_008, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/profile.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.pp12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "adhjkljasjhdk"; + char ksPwd[] = "123456"; + char isksPwd[] = "554245"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_009 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_009, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 5; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/profile.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "adhjkljasjhdk"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_010 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_010, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 5; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_ca_test_011 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_011, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + int keySize = 384; + int validity = 365; + int basicConstraintsPathLen = 5; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["validity"] = validity; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_012 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_012, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + int keySize = 384; + int validity = 365; + int basicConstraintsPathLen = 5; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["validity"] = validity; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_013 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_013, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/root-ca-test.cer"; + int keySize = 384; + int validity = 365; + int basicConstraintsPathLen = 5; + (*params)["keyAlias"] = keyAlias; + (*params)["keySize"] = keySize; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["validity"] = validity; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_014 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_014, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + int basicConstraintsPathLen = 5; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/profile.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "adhjkljasjhdk"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_015 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_015, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-root-ca-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/root-ca1.cer"; + int validity = 365; + int keySize = 384; + char keypwd[] = "123456"; + char ksPwd[] = "123456"; + (*params)["keyPwd"] = keypwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_ca_test_016 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_016, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string issuerkeyAlias = "oh-root-ca-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/app-sign-srv-ca1.cer"; + int validity = 365; + int keySize = 384; + char keypwd[] = "123456"; + char ksPwd[] = "123456"; + char issuerPwd[] = "123456"; + (*params)["keyPwd"] = keypwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeyPwd"] = issuerPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_ca_test_017 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_ca_test_017, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string issuerkeyAlias = "oh-root-ca-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/profile-sign-srv-ca1.cer"; + int validity = 365; + int keySize = 384; + char keypwd[] = "123456"; + char ksPwd[] = "123456"; + char issuerPwd[] = "123456"; + (*params)["keyPwd"] = keypwd; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeyPwd"] = issuerPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + bool ret = api->GenerateCA(params.get()); + EXPECT_EQ(ret, false); +} + + +/** + * @tc.name: generate_sub_cert_test_001 + * @tc.desc: Test function of GenerateCa() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_test_001, 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"; + char isksPwd[] = "123456"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateSubCert(keyPair, csr, params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_sub_cert_test_002 + * @tc.desc: Test function of GenerateCa() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = EVP_PKEY_new(); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = X509_REQ_new(); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateSubCert(keyPair, csr, params.get()); + EXPECT_EQ(ret, false); +} + + +/** + * @tc.name: generate_sub_cert_test_003 + * @tc.desc: Test function of GenerateCa() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = ""; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = EVP_PKEY_new(); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = X509_REQ_new(); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateSubCert(keyPair, csr, params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_sub_cert_test_004 + * @tc.desc: Test function of GenerateCa() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 5; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = EVP_PKEY_new(); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = X509_REQ_new(); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateSubCert(keyPair, csr, params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_sub_cert_test_005 + * @tc.desc: Test function of GenerateCa() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = ""; + int basicConstraintsPathLen = 5; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = EVP_PKEY_new(); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = X509_REQ_new(); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateSubCert(keyPair, csr, params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_sub_cert_test_006 + * @tc.desc: Test function of GenerateCa() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_test_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + int basicConstraintsPathLen = 0; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string outFile = "/data/test/generateCA/subca.cer"; + std::string issuerKeystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int keySize = 384; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + int validity = 365; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + (*params)["outFile"] = outFile; + (*params)["validity"] = validity; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = EVP_PKEY_new(); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = X509_REQ_new(); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateSubCert(keyPair, csr, params.get()); + EXPECT_EQ(ret, false); +} + + +/** + * @tc.name: valid_file_type_test_001 + * @tc.desc: Test function of ValidFileType() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, valid_file_type_test_001, testing::ext::TestSize.Level1) +{ + std::string issuerKeystoreFile = "ab.p12"; + bool ret = FileUtils::ValidFileType(issuerKeystoreFile, { "p12", "jks" }); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: get_chars_test_001 + * @tc.desc: Test function of Options::GetChars() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_chars_test_001, testing::ext::TestSize.Level1) +{ + Options option; + const std::string test = "test"; + char value[6] = "value"; + option[test] = value; + char* tmp = option.GetChars(test); + EXPECT_EQ(std::strcmp("value", tmp), 0); +} + +/** + * @tc.name: get_string_test_001 + * @tc.desc: Test function of Options::GetString() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_string_test_001, testing::ext::TestSize.Level1) +{ + Options option; + std::string test = "test"; + std::string value = "value"; + option[test] = value; + std::string str = option.GetString(test); + EXPECT_EQ(std::strcmp("value", str.c_str()), 0); +} + +/** + * @tc.name: equals_test_001 + * @tc.desc: Test function of Options::Equals() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, equals_test_001, testing::ext::TestSize.Level1) +{ + Options option; + const std::string test1 = "test1"; + const std::string test2 = "test2"; + bool ret = option.Equals(test1, test2); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: is_empty_test_001 + * @tc.desc: Test function of Options::IsEmpty() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, is_empty_test_001, testing::ext::TestSize.Level1) +{ + Options option; + std::string test1 = "test1"; + bool ret = option.IsEmpty(test1); + EXPECT_EQ(ret, false); +} + +// general cert +/** + * @tc.name: generate_cert_test_001 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + 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 = true; + char secret[] = "123456"; + char isksPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerkeypwd[] = "123456"; + int validity = 365; + std::string outfile = "/data/test/generateCA/general.cer"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["issuerKeyPwd"] = issuerkeypwd; + (*params)["keyAlias"] = keyAlias; + (*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; + (*params)["validity"] = validity; + (*params)["outFile"] = outfile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +// general cert +/** + * @tc.name: generate_cert_test_002 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + 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 = true; + char secret[] = "123456"; + char isksPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerkeypwd[] = "123456"; + std::string outFile = "/data/test/generateCA/rootCa.cer"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["issuerKeyPwd"] = issuerkeypwd; + (*params)["keyAlias"] = keyAlias; + (*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; + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + + +// general cert +/** + * @tc.name: generate_cert_test_003 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_003, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI(" welcome to test space !!! "); + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string issuer = "C=CNA,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + std::string signAlg = "SHA384withECDSA"; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int keySize = 384; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keyUsage"] = keyUsage; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["keyUsageCritical"] = keyUsageCritical; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = keystorePwd; + + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +// general cert +/** + * @tc.name: generate_cert_test_004 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + std::string signAlg = ""; + 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 isksPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerkeypwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["issuerKeyPwd"] = issuerkeypwd; + (*params)["keyAlias"] = keyAlias; + (*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; + + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +// general cert +/** + * @tc.name: generate_cert_test_005 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + std::string signAlg = ""; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char isksPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerkeypwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["issuerKeyPwd"] = issuerkeypwd; + (*params)["keyAlias"] = keyAlias; + (*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; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} +// general cert +/** + * @tc.name: generate_cert_test_006 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int keySize = 384; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keyUsage"] = keyUsage; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["keyUsageCritical"] = keyUsageCritical; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = keystorePwd; + + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_cert_test_007 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string subject = ""; + std::string signAlg = ""; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int keySize = 384; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keyUsage"] = keyUsage; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["keyUsageCritical"] = keyUsageCritical; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = keystorePwd; + + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_cert_test_008 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_008, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string issuer = "C=CNA,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + std::string signAlg = "SHA256withRSA"; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int keySize = 384; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keyUsage"] = keyUsage; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["keyUsageCritical"] = keyUsageCritical; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = keystorePwd; + + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_cert_test_009 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_009, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string signAlg = "SHA384withECDSA"; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int keySize = 384; + (*params)["keySize"] = keySize; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keyUsage"] = keyUsage; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["keyUsageCritical"] = keyUsageCritical; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +// general cert +/** + * @tc.name: generate_cert_test_010 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_010, 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 = 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); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} + +/** + * @tc.name: generate_cert_test_011 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @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); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} + + +/** + * @tc.name: generate_cert_test_012 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @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); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} + + +/** + * @tc.name: generate_cert_test_013 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @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); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} + +/** + * @tc.name: generate_cert_test_014 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @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; + 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); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} + +/** + * @tc.name: generate_cert_test_015 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_015, 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; + 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; + EVP_PKEY* keyPair = EVP_PKEY_new(); + X509_REQ* csr = X509_REQ_new(); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_EQ(cert, nullptr); +} + +/** + * @tc.name: generate_cert_test_016 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_016, 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; + 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 = X509_REQ_new(); + X509 *cert = CertTools::GenerateCert(keyPair, csr, params.get()); + EXPECT_EQ(cert, nullptr); +} +} +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateCA/generate_general_ca_test.cpp b/hapsigntool_cpp/test/unittest/generateCA/generate_general_ca_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38a3f8a9201f7f689af80f41f9ed7982747267b2 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateCA/generate_general_ca_test.cpp @@ -0,0 +1,1703 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" +#include "fs_digest_utils.h" +#include "constant.h" +#include +#include + +namespace OHOS { +namespace SignatureTools { + +class GenerateCaTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + + +/** + * @tc.name: generate_cert_test_017 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_017, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + std::string issuerKeystoreFile = "/data/test/generateKeyPair/pp.p12"; + std::string signAlg = ""; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + char isksPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerkeypwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["issuerKeyPwd"] = issuerkeypwd; + (*params)["keyAlias"] = keyAlias; + (*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; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_cert_test_018 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_018, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + 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 = true; + char secret[] = "123456"; + char isksPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerkeypwd[] = "123456"; + std::string outFile = "/datamt/test/generateCA/general-ca-test.cer"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["issuerKeyPwd"] = issuerkeypwd; + (*params)["keyAlias"] = keyAlias; + (*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; + (*params)["outFile"] = outFile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_cert_test_019 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_019, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string keyUsage = "digitalSignature"; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int validity = 365; + std::string outfile = "/data/test/generateCA/single-app1.cer"; + (*params)["keyPwd"] = secret; + (*params)["keyAlias"] = keyAlias; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyUsage"] = keyUsage; + (*params)["validity"] = validity; + (*params)["outFile"] = outfile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_cert_test_020 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_020, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string signAlg = ""; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string keyUsage = "digitalSignature"; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int validity = 365; + std::string outfile = "/data/test/generateCA/single-app1.cer"; + (*params)["keyPwd"] = secret; + (*params)["keyAlias"] = keyAlias; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyUsage"] = keyUsage; + (*params)["validity"] = validity; + (*params)["outFile"] = outfile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_cert_test_021 + * @tc.desc: Test function of GenerateCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_cert_test_021, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string signAlg = "SHA384withECDSA"; + std::string subject = ""; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string keyUsage = "digitalSignature"; + char secret[] = "123456"; + char keystorePwd[] = "123456"; + int validity = 365; + std::string outfile = "/data/test/generateCA/single-app1.cer"; + (*params)["keyPwd"] = secret; + (*params)["keyAlias"] = keyAlias; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["keyUsage"] = keyUsage; + (*params)["validity"] = validity; + (*params)["outFile"] = outfile; + bool ret = api->GenerateCert(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: get_int_test_001 + * @tc.desc: Test function of GetInt() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_int_test_001, testing::ext::TestSize.Level1) +{ + Options option; + std::string str = "test"; + int tmp = option.GetInt(str); + EXPECT_EQ(std::to_string(tmp).size(), 1U); +} + +/** + * @tc.name: generate_app_cert_test_001 + * @tc.desc: Test function of GenerateAppCert() interface for certChain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string rootCaCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/app-sign-srv-ca1.cer"; + std::string outFile = "/data/test/generateCA/app-release1.pem"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + int validity = 365; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::CA_CERT_FILE] = rootCaCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_app_cert_test_002 + * @tc.desc: Test function of GenerateAppCert() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/app-release1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + int validity = 365; + std::string outForm = "cert"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_app_cert_test_003 + * @tc.desc: Test function of GenerateAppCert() interface for certChain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_003, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string rootCaCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/app-sign-srv-ca1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + int validity = 365; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::CA_CERT_FILE] = rootCaCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_app_cert_test_004 + * @tc.desc: Test function of GenerateAppCert() interface for certChain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_004, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + int validity = 365; + std::string outForm = "cert"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_app_cert_test_005 + * @tc.desc: Test function of GenerateAppCert() interface for certChain FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_005, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/apptest.p12"; + std::string caCertFile = "/data/test/generateCA/root-ca1test.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1test.cer"; + std::string outFile = "/data/test/generateCA/test-profile-cert-v1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, false); +} +/** + * @tc.name: generate_app_cert_test_006 + * @tc.desc: Test function of GenerateAppCert() interface for certChain FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_006, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "45679887"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/apptest.p12"; + std::string caCertFile = "/data/test/generateCA/root-ca1test.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1test.cer"; + std::string outFile = "/data/test/generateCA/test-profile-cert-v1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, false); +} +/** + * @tc.name: generate_app_cert_test_007 + * @tc.desc: Test function of GenerateAppCert() interface for certChain FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_appcert_test_007, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string keystoreFile = "/data/test/generateCA/apptest.p12"; + std::string caCertFile = "/data/test/generateCA/root-ca1test.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1test.cer"; + std::string outFile = "/data/test/generateCA/test-profile-cert-v1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + bool result = api.GenerateAppCert(¶ms); + EXPECT_EQ(result, false); +} +/** + * @tc.name: generate_profile_cert_test_001 + * @tc.desc: Test function of GenerateProfileCert() interface for certChain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/profile1.cer"; + int validity = 365; + char secret[] = "123456"; + char ksPwd[] = "123456"; + std::string outForm = "cert"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_profile_cert_test_002 + * @tc.desc: Test function of GenerateProfileCert() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string rootCaCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1.cer"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + std::string outFile = "/data/test/generateCA/profile-release1.pem"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + std::string outForm = "certChain"; + int validity = 365; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::CA_CERT_FILE] = rootCaCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_profile_cert_test_003 + * @tc.desc: Test function of GenerateProfileCert() interface for certChain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_003, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + int validity = 365; + char secret[] = "123456"; + char ksPwd[] = "123456"; + std::string outForm = "cert"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_profile_cert_test_004 + * @tc.desc: Test function of GenerateProfileCert() interface for certChain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_004, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string rootCaCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1.cer"; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + std::string outForm = "certChain"; + int validity = 365; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::CA_CERT_FILE] = rootCaCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FORM] = outForm; + params[Options::VALIDITY] = validity; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, true); +} +/** + * @tc.name: generate_profile_cert_test_005 + * @tc.desc: Test function of GenerateProfileCert() interface for certChain FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_005, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string caCertFile = "/data/test/generateCA/root-ca1test.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1test.cer"; + std::string outFile = "/data/test/generateCA/test-profile-cert-v1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, false); +} +/** + * @tc.name: generate_profile_cert_test_006 + * @tc.desc: Test function of GenerateProfileCert() interface for certChain FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_006, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "45679887"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string caCertFile = "/data/test/generateCA/root-ca1test.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1test.cer"; + std::string outFile = "/data/test/generateCA/test-profile-cert-v1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SUBJECT] = subject; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, false); +} +/** + * @tc.name: generate_profile_cert_test_007 + * @tc.desc: Test function of GenerateProfileCert() interface for certChain FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_profilecert_test_007, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + std::string caCertFile = "/data/test/generateCA/root-ca1test.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1test.cer"; + std::string outFile = "/data/test/generateCA/test-profile-cert-v1.cer"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + std::string outForm = "certChain"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::KEY_ALIAS] = keyAlias; + params[Options::ISSUER] = issuer; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::KEY_STORE_FILE] = keystoreFile; + params[Options::OUT_FILE] = outFile; + params[Options::OUT_FORM] = outForm; + bool result = api.GenerateProfileCert(¶ms); + EXPECT_EQ(result, false); +} + + +/** + * @tc.name: judge_alg_type_test_001 + * @tc.desc: Test function of JudgeAlgType() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, judge_alg_type_test_001, testing::ext::TestSize.Level1) +{ + std::string str = "ECC"; + bool ret = CmdUtil::JudgeAlgType(str); + EXPECT_EQ(ret, true); +} +/** + * @tc.name: judge_size_test_001 + * @tc.desc: Test function of JudgeSize() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, judge_size_test_001, testing::ext::TestSize.Level1) +{ + int size = 255; + bool ret = CmdUtil::JudgeSize(size); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name:generate_root_cert_001 + * @tc.desc: Test function of :GenerateRootCertificate() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_root_cert_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["algorithm"] = algorithm; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["subject"] = subject; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} +/** + * @tc.name:generate_root_cert_002 + * @tc.desc: Test function of :GenerateRootCertificate() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_root_cert_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string basicConstraintsPathLen = "5"; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["algorithm"] = algorithm; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["subject"] = subject; + (*params)["basicConstraintsPathLen"] = basicConstraintsPathLen; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); +} + +/** + * @tc.name:generate_root_cert_003 + * @tc.desc: Test function of :GenerateRootCertificate() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_root_cert_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "alias"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = ""; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["algorithm"] = algorithm; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["subject"] = subject; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_EQ(csr, nullptr); + X509* cert = CertTools::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_EQ(cert, nullptr); +} +/** + * @tc.name: generate_end_cert_test_001 + * @tc.desc: Test function of GenerateEndCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_end_cert_test_001, testing::ext::TestSize.Level1) +{ + const char appSigningCapability[] = {0x30, 0x06, 0x02, 0x01, 0x01, 0x0A, 0x01, 0x00}; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 3650; + params["keyAlias"] = keyAlias; + params["keyPwd"] = keyPwd; + params["keySize"] = keySize; + params["keystoreFile"] = keystoreFile; + params["keystorePwd"] = keystorePwd; + params["algorithm"] = algorithm; + params["signAlgorithm"] = signAlgorithm; + params["subject"] = subject; + params["issuer"] = issuer; + params["validity"] = validity; + LocalizationAdapter adapter(¶ms); + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateEndCert(csr, keyPair, adapter, appSigningCapability, + sizeof(appSigningCapability)); + EXPECT_NE(cert, nullptr); +} + +/** + * @tc.name: generate_end_cert_test_002 + * @tc.desc: Test function of GenerateEndCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_end_cert_test_002, testing::ext::TestSize.Level1) +{ + char appSigningCapability[] = {0x30, 0x06, 0x02, 0x01, 0x01, 0x0A, 0x01, 0x00}; + Options params; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + params["keyPwd"] = keyPwd; + params["keySize"] = keySize; + params["keystoreFile"] = keystoreFile; + params["keystorePwd"] = keystorePwd; + params["algorithm"] = algorithm; + params["signAlgorithm"] = signAlgorithm; + params["subject"] = subject; + params["issuer"] = issuer; + LocalizationAdapter adapter(¶ms); + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateEndCert(csr, keyPair, adapter, appSigningCapability, + sizeof(appSigningCapability)); + EXPECT_NE(cert, nullptr); +} + +/** + * @tc.name: generate_end_cert_test_003 + * @tc.desc: Test function of GenerateEndCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_end_cert_test_003, testing::ext::TestSize.Level1) +{ + char appSigningCapability[] = {0x30, 0x06, 0x02, 0x01, 0x01, 0x0A, 0x01, 0x00}; + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "alias"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["algorithm"] = algorithm; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["subject"] = subject; + LocalizationAdapter adapter(params.get()); + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateEndCert(csr, keyPair, adapter, appSigningCapability, + sizeof(appSigningCapability)); + EXPECT_EQ(cert, nullptr); +} + +/** + * @tc.name: is_out_form_chain_test_001 + * @tc.desc: Test function of IsOutFormChain() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, is_out_form_chain_test_001, testing::ext::TestSize.Level1) +{ + Options params; + std::string outForm = "certChain"; + params[Options::OUT_FORM] = outForm; + LocalizationAdapter adapter(¶ms); + bool ret = adapter.IsOutFormChain(); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: is_out_form_chain_test_002 + * @tc.desc: Test function of IsOutFormChain() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, is_out_form_chain_test_002, testing::ext::TestSize.Level1) +{ + Options params; + std::string outForm = "cert"; + params[Options::OUT_FORM] = outForm; + LocalizationAdapter adapter(¶ms); + bool ret = adapter.IsOutFormChain(); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: get_cert_fromfile_test_001 + * @tc.desc: Test function of GetCertsFromFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_cert_fromfile_test_001, testing::ext::TestSize.Level1) +{ + Options params; + std::string path = ""; + LocalizationAdapter adapter(¶ms); + auto ret = adapter.GetCertsFromFile(path, " "); + EXPECT_EQ(ret.empty(), true); +} + +/** + * @tc.name: get_cert_fromfile_test_002 + * @tc.desc: Test function of GetCertsFromFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_cert_fromfile_test_002, testing::ext::TestSize.Level1) +{ + Options params; + std::string path = "certs"; + LocalizationAdapter adapter(¶ms); + auto ret = adapter.GetCertsFromFile(path, " "); + EXPECT_EQ(ret.empty(), true); +} + +/** + * @tc.name: output_cert_test_001 + * @tc.desc: Test function of OutPutCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, output_cert_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + char appSigningCapability[] = {0x30, 0x06, 0x02, 0x01, 0x01, 0x0A, 0x01, 0x00}; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 3650; + params["keyAlias"] = keyAlias; + params["keyPwd"] = keyPwd; + params["keySize"] = keySize; + params["keystoreFile"] = keystoreFile; + params["keystorePwd"] = keystorePwd; + params["algorithm"] = algorithm; + params["signAlgorithm"] = signAlgorithm; + params["subject"] = subject; + params["issuer"] = issuer; + params["validity"] = validity; + LocalizationAdapter adapter(¶ms); + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateEndCert(csr, keyPair, adapter, appSigningCapability, + sizeof(appSigningCapability)); + EXPECT_NE(cert, nullptr); + bool ret = api.OutPutCert(cert, "/data/test/generateCA/test.cer"); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: output_cert_test_002 + * @tc.desc: Test function of OutPutCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, output_cert_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + char appSigningCapability[] = {0x30, 0x06, 0x02, 0x01, 0x01, 0x0A, 0x01, 0x00}; + Options params; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char keystorePwd[] = "123456"; + std::string algorithm = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 3650; + params["keyAlias"] = keyAlias; + params["keyPwd"] = keyPwd; + params["keySize"] = keySize; + params["keystoreFile"] = keystoreFile; + params["keystorePwd"] = keystorePwd; + params["algorithm"] = algorithm; + params["signAlgorithm"] = signAlgorithm; + params["subject"] = subject; + params["issuer"] = issuer; + params["validity"] = validity; + LocalizationAdapter adapter(¶ms); + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateEndCert(csr, keyPair, adapter, appSigningCapability, + sizeof(appSigningCapability)); + EXPECT_NE(cert, nullptr); + bool ret = api.OutPutCert(cert, "/datasgje/test/generateCA/test.cer "); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: output_cert_chain_test_001 + * @tc.desc: Test function of OutPutCertChain() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, output_cert_chain_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + X509* cert1 = X509_new(); + X509* cert2 = X509_new(); + X509* cert3 = X509_new(); + std::string path = "/data/test/generateCA/test.pem"; + std::vector certs; + certs.push_back(cert1); + certs.push_back(cert2); + certs.push_back(cert3); + bool ret = api.OutPutCertChain(certs, path); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: output_cert_chain_test_002 + * @tc.desc: Test function of OutPutCertChain() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, output_cert_chain_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + X509* cert1 = X509_new(); + X509* cert2 = X509_new(); + X509* cert3 = X509_new(); + std::string path = ""; + std::vector certs; + certs.push_back(cert1); + certs.push_back(cert2); + certs.push_back(cert3); + bool ret = api.OutPutCertChain(certs, path); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: print_x509_test_001 + * @tc.desc: Test function of PrintX509CertFromMemory() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, print_x509_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + X509* cert1 = X509_new(); + bool ret = api.PrintX509CertFromMemory(cert1); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: read_x509_test_001 + * @tc.desc: Test function of ReadfileToX509() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, read_x509_test_001, testing::ext::TestSize.Level1) +{ + std::string path = ""; + X509* cert1 = CertTools::ReadfileToX509(path); + EXPECT_EQ(cert1, nullptr); +} + +/** + * @tc.name: read_x509_test_002 + * @tc.desc: Test function of ReadfileToX509 interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, read_x509_test_002, testing::ext::TestSize.Level1) +{ + std::string path = "/data/test/generateCA/root-ca1.cer"; + X509* cert1 = CertTools::ReadfileToX509(path); + EXPECT_NE(cert1, nullptr); +} + +/** + * @tc.name: get_and_output_cert_test_001 + * @tc.desc: Test function of GetAndOutPutCert() interface for certchain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_and_output_cert_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string caCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::OUT_FORM] = outForm; + LocalizationAdapter adapter(¶ms); + std::string path = "/data/test/generateCA/root-ca1.cer"; + X509* cert1 = CertTools::ReadfileToX509(path); + EXPECT_NE(cert1, nullptr); + bool result = api.GetAndOutPutCert(adapter, cert1); + EXPECT_EQ(result, true); +} +/** + * @tc.name: get_and_output_cert_test_002 + * @tc.desc: Test function of GetAndOutPutCert() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_and_output_cert_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string outForm = "cert"; + params[Options::OUT_FORM] = outForm; + LocalizationAdapter adapter(¶ms); + std::string path = "/data/test/generateCA/root-ca1.cer"; + X509* cert1 = CertTools::ReadfileToX509(path); + EXPECT_NE(cert1, nullptr); + bool result = api.GetAndOutPutCert(adapter, cert1); + EXPECT_EQ(result, true); +} +/** + * @tc.name: get_and_output_cert_test_003 + * @tc.desc: Test function of GetAndOutPutCert() interface for certchain SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_and_output_cert_test_003, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string caCertFile = "/data/test/generateCA/root-ca1.cer"; + std::string subCaCertFile = "/data/test/generateCA/profile-sign-srv-ca1.cer"; + std::string outFile = "/data/test/generateCA/certChain"; + params[Options::CA_CERT_FILE] = caCertFile; + params[Options::SUB_CA_CERT_FILE] = subCaCertFile; + params[Options::OUT_FORM] = outFile; + LocalizationAdapter adapter(¶ms); + std::string path = "/data/test/generateCA/root-ca1.cer"; + X509* cert1 = CertTools::ReadfileToX509(path); + EXPECT_NE(cert1, nullptr); + bool result = api.GetAndOutPutCert(adapter, cert1); + EXPECT_EQ(result, true); +} +/** + * @tc.name: hap_verify_test_001 + * @tc.desc: Test function of VerifyHapSigner() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, hap_verify_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string inFile = "/data/test/generateCA/phone1-default-signed.hap"; + std::string outCertChain = "/data/test/generateCA/hap-verify.cer"; + std::string outProfile = "/data/test/generateCA/hap-profile.p7b"; + params[Options::IN_FILE] = inFile; + params[Options::OUT_CERT_CHAIN] = outCertChain; + params[Options::OUT_PROFILE] = outProfile; + bool result = api.VerifyHapSigner(¶ms); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: hap_verify_test_002 + * @tc.desc: Test function of VerifyHapSigner() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, hap_verify_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string inFile = ""; + std::string outCertChain = "/data/test/generateCA/hap-verify.cer"; + std::string outProfile = "/data/test/generateCA/hap-profile.p7b"; + params[Options::IN_FILE] = inFile; + params[Options::OUT_CERT_CHAIN] = outCertChain; + params[Options::OUT_PROFILE] = outProfile; + bool result = api.VerifyHapSigner(¶ms); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: generate_key_pair_test_001 + * @tc.desc: Test function of GetIssuerKeyByAlias() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_key_pair_test_001, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string issuerkeyStroeFile = "/data/test/generateCA/ohtest.p12"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_STORE_FILE] = issuerkeyStroeFile; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + LocalizationAdapter adapter(¶ms); + adapter.SetIssuerKeyStoreFile(true); + EVP_PKEY* issueKeyPair = adapter.GetIssuerKeyByAlias(); + EXPECT_NE(issueKeyPair, nullptr); +} +/** + * @tc.name: generate_key_pair_test_002 + * @tc.desc: Test function of GetIssuerKeyByAlias() interface for cert SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_key_pair_test_002, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string issuerkeyStroeFile = "/data/test/generateCA/ohtest.p12"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_STORE_FILE] = issuerkeyStroeFile; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + LocalizationAdapter adapter(¶ms); + adapter.SetIssuerKeyStoreFile(true); + EVP_PKEY* issueKeyPair = nullptr; + adapter.GetKeyPair(true, &issueKeyPair); + EXPECT_NE(issueKeyPair, nullptr); +} +/** + * @tc.name: generate_key_pair_test_003 + * @tc.desc: Test function of GenerateKeyPair() interface for cert FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_key_pair_test_003, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string issuerKeyAlias = "oh"; + std::string issuerkeyStroeFile = "/data/test/generateCA/ohtest.p12"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "/data/test/generateCA/ohtest.p12"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + char isskeypwd[] = "123456"; + params[Options::KEY_RIGHTS] = secret; + params[Options::KEY_STORE_RIGHTS] = ksPwd; + params[Options::ISSUER_KEY_STORE_FILE] = issuerkeyStroeFile; + params[Options::ISSUER_KEY_RIGHTS] = isksPwd; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + params[Options::SIGN_ALG] = signAlg; + params[Options::KEY_STORE_FILE] = keystoreFile; + LocalizationAdapter adapter(¶ms); + adapter.SetIssuerKeyStoreFile(true); + EVP_PKEY* issueKeyPair = adapter.GetIssuerKeyByAlias(); + EXPECT_EQ(issueKeyPair, nullptr); +} +/** + * @tc.name: generate_key_pair_test_004 + * @tc.desc: Test function of GenerateKeyPair() interface for cert FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_key_pair_test_004, testing::ext::TestSize.Level1) +{ + SignToolServiceImpl api; + Options params; + std::string issuerKeyAlias = ""; + std::string issuerkeyStroeFile = ""; + char isskeypwd[] = {0}; + params[Options::ISSUER_KEY_STORE_FILE] = issuerkeyStroeFile; + params[Options::ISSUER_KEY_STORE_RIGHTS] = isskeypwd; + params[Options::ISSUER_KEY_ALIAS] = issuerKeyAlias; + LocalizationAdapter adapter(¶ms); + adapter.SetIssuerKeyStoreFile(true); + EVP_PKEY* issueKeyPair = adapter.GetIssuerKeyByAlias(); + EXPECT_EQ(issueKeyPair, nullptr); +} + +/** + * @tc.name: set_expandedInf_ext_one_test_001 + * @tc.desc: Test function of SetKeyUsage() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_expandedInf_ext_one_test_001, testing::ext::TestSize.Level1) +{ + + std::shared_ptr params = std::make_shared(); + X509* cert = X509_new(); + bool keyUsageCritical = true; + std::string keyUsage = ""; + (*params)["keyUsage"] = keyUsage; + (*params)["keyUsageCritical"] = keyUsageCritical; + bool cert1 = CertTools::SetKeyUsage(cert, params.get()); + EXPECT_NE(cert1, false); +} + +/** + * @tc.name: set_expandedInf_ext_one_test_002 + * @tc.desc: Test function of SetKeyUsage() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_expandedInf_ext_one_test_002, testing::ext::TestSize.Level1) +{ + + std::shared_ptr params = std::make_shared(); + X509* cert = X509_new(); + bool keyUsageCritical = false; + std::string keyUsage = "digitalSignature,nonRepudiation"; + (*params)["keyUsage"] = keyUsage; + (*params)["keyUsageCritical"] = keyUsageCritical; + bool cert1 = CertTools::SetKeyUsage(cert, params.get()); + EXPECT_NE(cert1, false); +} + +/** + * @tc.name: set_expandedInf_ext_two_test_001 + * @tc.desc: Test function of SetkeyUsageExt() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_expandedInf_ext_two_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + X509* cert = X509_new(); + bool extKeyUsageCritical = true; + std::string extKeyUsage = "clientAuthentication"; + (*params)["extKeyUsageCritical"] = extKeyUsageCritical; + (*params)["extKeyUsage"] = extKeyUsage; + bool cert1 = CertTools::SetkeyUsageExt(cert, params.get()); + EXPECT_NE(cert1, false); +} + +/** + * @tc.name: set_expandedInf_ext_two_test_002 + * @tc.desc: Test function of SetkeyUsageExt() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_expandedInf_ext_two_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + X509* cert = X509_new(); + bool extKeyUsageCritical = false; + std::string extKeyUsage = ""; + (*params)["extKeyUsageCritical"] = extKeyUsageCritical; + (*params)["extKeyUsage"] = extKeyUsage; + bool cert1 = CertTools::SetkeyUsageExt(cert, params.get()); + EXPECT_NE(cert1, false); +} + +/** + * @tc.name: generate_sub_cert_to_file_test_001 + * @tc.desc: Test function of GenerateCaToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + std::string outFile = "/datamt/test/generateCA/sub-ca-test.cer"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outFile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_sub_cert_to_file_test_002 + * @tc.desc: Test function of GenerateCaToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_sub_cert_to_file_test_003 + * @tc.desc: Test function of GenerateCaToFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + 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::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, true); +} +} +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateCA/generate_sub_ca_test.cpp b/hapsigntool_cpp/test/unittest/generateCA/generate_sub_ca_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f9efb338f368b76fb53d9283f9f327bea8dd8e33 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateCA/generate_sub_ca_test.cpp @@ -0,0 +1,1777 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "localization_adapter.h" +#include "fs_digest_utils.h" +#include "constant.h" +#include +#include + +namespace OHOS { +namespace SignatureTools { + +class GenerateCaTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: generate_sub_cert_to_file_test_004 + * @tc.desc: Test function of GenerateSubCertToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + 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 = ""; + char secret[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + X509* cert = CertTools::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, false); +} +/** + * @tc.name: generate_sub_cert_to_file_test_005 + * @tc.desc: Test function of GenerateCaToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECD"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + 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::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_EQ(cert, nullptr); + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_sub_cert_to_file_test_006 + * @tc.desc: Test function of GenerateCaToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECD"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + EVP_PKEY* keyPair = nullptr; + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_sub_cert_to_file_test_007 + * @tc.desc: Test function of GenerateCaToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, generate_sub_cert_to_file_test_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECD"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + std::string outFile = "/datamt/test/generateCA/sub-ca-test.cer"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outFile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + bool ret = api->GenerateSubCertToFile(params.get(), keyPair); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: set_cert_version_test_001 + * @tc.desc: Test function of SetCertVersion() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_cert_version_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = nullptr; + bool res = CertTools::SetCertVersion(cert, 1); + EXPECT_EQ(res, false); +} +/** + * @tc.name: set_pubkey_and_sign_cert_test_001 + * @tc.desc: Test function of SetPubkeyAndSignCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_pubkey_and_sign_cert_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlgorithm, issuer); + EXPECT_NE(issuercsr, nullptr); + X509* cert = CertTools::GenerateRootCertificate(keyPair, csr, params.get()); + EXPECT_NE(cert, nullptr); + bool cert1 = CertTools::SetPubkeyAndSignCert(cert, issuercsr, csr, keyPair, params.get()); + EXPECT_NE(cert1, false); +} + + +/** + * @tc.name: set_pubkey_and_sign_cert_test_002 + * @tc.desc: Test function of SetPubkeyAndSignCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_pubkey_and_sign_cert_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + std::string signAlgorithm = "SHA256withECDSA"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlgorithm"] = signAlgorithm; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlgorithm, issuer); + EXPECT_NE(issuercsr, nullptr); + X509* cert = nullptr; + EXPECT_EQ(cert, nullptr); + bool cert1 = CertTools::SetPubkeyAndSignCert(cert, issuercsr, csr, keyPair, params.get()); + EXPECT_EQ(cert1, false); +} + + +/** + * @tc.name: set_pubkey_and_sign_cert_test_003 + * @tc.desc: Test function of SetPubkeyAndSignCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_pubkey_and_sign_cert_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/keypair.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA256withECDSA"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + X509_REQ* csr = X509_REQ_new(); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + X509* cert = nullptr; + bool cert1 = CertTools::SetPubkeyAndSignCert(cert, issuercsr, csr, keyPair, params.get()); + EXPECT_EQ(cert1,false); +} + +/** + * @tc.name: set_pubkey_and_sign_cert_test_004 + * @tc.desc: Test function of SetPubkeyAndSignCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_pubkey_and_sign_cert_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/key.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA256withECDSA"; + 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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + X509_REQ* csr = X509_REQ_new(); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + X509* cert = nullptr; + bool cert1 = CertTools::SetPubkeyAndSignCert(cert, issuercsr, csr, keyPair, params.get()); + EXPECT_EQ(cert1, false); +} + +/** + * @tc.name: set_pubkey_and_sign_cert_test_005 + * @tc.desc: Test function of SetPubkeyAndSignCert() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_pubkey_and_sign_cert_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string keyAlias = "alias"; + std::string issuerkeyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateKeyPair/key.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"; + char secret[] = "123456"; + char ksPwd[] = "123456"; + char isksPwd[] = "123456"; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = ksPwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerkeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + X509_REQ* csr = X509_REQ_new(); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + X509* cert = nullptr; + bool cert1 = CertTools::SetPubkeyAndSignCert(cert, issuercsr, csr, keyPair, params.get()); + EXPECT_EQ(cert1, false); +} + +/** + * @tc.name: set_cert_serial_test_003 + * @tc.desc: Test function of SetCertSubjectName() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_cert_serial_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + X509_REQ* req = X509_REQ_new(); + bool res = CertTools::SetCertSubjectName(cert, req); + EXPECT_EQ(res, true); +} + +/** + * @tc.name: set_cert_validity_test_001 + * @tc.desc: Test function of SetCertValidityStartAndEnd() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, set_cert_validity_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + bool res = CertTools::SetCertValidityStartAndEnd(cert, -1, 2); + X509_free(cert); + EXPECT_EQ(res, true); +} + + +/** + * @tc.name: X509_certverify_test_001 + * @tc.desc: Test function of X509CertVerify() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, X509_certverify_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + std::shared_ptr api = std::make_shared(); + 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"; + 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; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + bool ret = api->X509CertVerify(cert, keyPair); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: X509_certverify_test_002 + * @tc.desc: Test function of X509CertVerify() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ + +HWTEST_F(GenerateCaTest, X509_certverify_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + X509* cert = X509_new(); + EVP_PKEY* keyPair = EVP_PKEY_new(); + bool ret = api->X509CertVerify(cert, keyPair); + EXPECT_NE(ret, false); +} + + +/** + * @tc.name: X509_certverify_test_003 + * @tc.desc: Test function of X509CertVerify() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, X509_certverify_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = 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"; + 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; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509* cert = X509_new(); + bool ret = api->X509CertVerify(cert, keyPair); + X509_free(cert); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: isempty_test_001 + * @tc.desc: Test function of IsEmpty() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, isempty_test_001, testing::ext::TestSize.Level1) +{ + std::string cs = ""; + bool res = FileUtils::IsEmpty(cs); + EXPECT_EQ(res, true); +} +/** + * @tc.name: Read_File_By_Offset_And_Length_test_001 + * @tc.desc: Test function of ReadInputByOffsetAndLength() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, Read_File_By_Offset_And_Length_test_001, testing::ext::TestSize.Level1) +{ + std::ifstream file("/data/test/generateKeyPair/keypair.p12"); + std::string ret("std::string& ret"); + int res = FileUtils::ReadFileByOffsetAndLength(file, 1, 50, ret); + EXPECT_EQ(res, 0); +} +/** + * @tc.name: Read_File_By_Offset_And_Length_test_002 + * @tc.desc: Test function of ReadInputByOffsetAndLength() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, Read_Input_By_Offset_And_Length_test_002, testing::ext::TestSize.Level1) +{ + std::ifstream file("/data/test/"); + std::string ret("std::string& ret"); + int res = FileUtils::ReadInputByOffsetAndLength(file, 111, 2147483647, ret); + EXPECT_EQ(res, -1); +} +/** +* @tc.name: Read_File_By_Length_test_001 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Read_Input_By_Length_test_001, testing::ext::TestSize.Level1) +{ + std::ifstream file("/data/test/"); + std::string ret("std::string& ret"); + int res = FileUtils::ReadInputByLength(file, 2147483647, ret); + EXPECT_EQ(res, -1); +} +/** +* @tc.name: Append_Write_File_ByOffset_To_File_test_001 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Append_Write_File_ByOffset_To_File_test_001, testing::ext::TestSize.Level1) +{ + std::ifstream file(""); + std::ofstream out(""); + bool res = FileUtils::AppendWriteFileByOffsetToFile(file, out, 10000, 100000); + EXPECT_EQ(res, false); +} +/** +* @tc.name: Append_Write_File_ByOffset_To_File_test_002 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Append_Write_File_ByOffset_To_File_test_002, testing::ext::TestSize.Level1) +{ + std::ifstream file("/data/test/generateKeyPair/keypair.p12"); + std::ofstream out("/data/test/generateKeyPair/test.txt"); + bool res = FileUtils::AppendWriteFileByOffsetToFile(file, out, 10, 100); + EXPECT_EQ(res, true); +} +/** +* @tc.name: Append_Write_File_ByOffset_To_File_test_003 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Append_Write_File_ByOffset_To_File_test_003, testing::ext::TestSize.Level1) +{ + std::ifstream file("/data/test/generateKeyPair/keypair.p12"); + std::ofstream out(""); + bool res = FileUtils::AppendWriteFileByOffsetToFile(file, out, 10, 100); + EXPECT_EQ(res, false); +} +/** +* @tc.name: Is_Runnable_File_test_001 +* @tc.desc: Test function of IsRunnableFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Is_Runnable_File_test_001, testing::ext::TestSize.Level1) +{ + std::string name = ""; + bool res = FileUtils::IsRunnableFile(name); + EXPECT_EQ(res, false); +} +/** +* @tc.name: WriteByteToOutFile_test_001 +* @tc.desc: Test function of WriteByteToOutFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, WriteByteToOutFile_test_001, testing::ext::TestSize.Level1) +{ + std::string bytes = "587469"; + std::ofstream outFile("/data/test/test.txt"); + bool res = FileUtils::WriteByteToOutFile(bytes, outFile); + EXPECT_EQ(res, true); +} +/** +* @tc.name: WriteByteToOutFile_test_002 +* @tc.desc: Test function of WriteByteToOutFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, WriteByteToOutFile_test_002, testing::ext::TestSize.Level1) +{ + std::string bytes = ""; + std::ofstream outFile(""); + bool res = FileUtils::WriteByteToOutFile(bytes, outFile); + EXPECT_EQ(res, false); +} +/** +* @tc.name: ReadFile_test_002 +* @tc.desc: Test function of ReadFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, ReadFile_test_002, testing::ext::TestSize.Level1) +{ + std::string path = "/data/test/"; + std::string ret; + int res = FileUtils::ReadFile(path, ret); + EXPECT_EQ(res, 0); +} +/** +* @tc.name: WriteByteToOutFile_test_003 +* @tc.desc: Test function of WriteByteToOutFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, WriteByteToOutFile_test_003, testing::ext::TestSize.Level1) +{ + std::string bytes = "111"; + std::string outFile = "/data/test/test.txt"; + bool res = FileUtils::WriteByteToOutFile(bytes, outFile); + EXPECT_EQ(res, true); +} +/** +* @tc.name: WriteByteToOutFile_test_004 +* @tc.desc: Test function of WriteByteToOutFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, WriteByteToOutFile_test_004, testing::ext::TestSize.Level1) +{ + std::string bytes = "111"; + std::string outFile = ""; + int res = FileUtils::WriteByteToOutFile(bytes, outFile); + EXPECT_EQ(res, false); +} +/** +* @tc.name: ParsePkcs7Package_test_001 +* @tc.desc: Test function of ParsePkcs7Package() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, ParsePkcs7Package_test_001, testing::ext::TestSize.Level1) +{ + const unsigned char packageData[] = {0}; + Pkcs7Context pkcs7Context; + bool res = VerifyHapOpensslUtils::ParsePkcs7Package(packageData, 10, pkcs7Context); + EXPECT_EQ(res, false); +} +/** +* @tc.name: ParsePkcs7Package_test_002 +* @tc.desc: Test function of ParsePkcs7Package() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, ParsePkcs7Package_test_002, testing::ext::TestSize.Level1) +{ + const unsigned char packageData[] = {1, 1, 1, 1, 1}; + Pkcs7Context pkcs7Context; + bool res = VerifyHapOpensslUtils::ParsePkcs7Package(packageData, 10, pkcs7Context); + EXPECT_EQ(res, false); +} +/** +* @tc.name: GetCertChains_test_001 +* @tc.desc: Test function of GetCertChains() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, GetCertChains_test_001, testing::ext::TestSize.Level1) +{ + PKCS7* p7 = nullptr; + Pkcs7Context pkcs7Context; + bool ret = VerifyHapOpensslUtils::GetCertChains(p7, pkcs7Context); + EXPECT_EQ(ret, false); +} +/** +* @tc.name: GetCertChains_test_002 +* @tc.desc: Test function of GetCertChains() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, GetCertChains_test_002, testing::ext::TestSize.Level1) +{ + PKCS7* p7 = PKCS7_new(); + Pkcs7Context pkcs7Context; + bool ret = VerifyHapOpensslUtils::GetCertChains(p7, pkcs7Context); + PKCS7_free(p7); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: set_bisic_constraints_patchlen_test_001 + * @tc.desc: Test function of SetBisicConstraintsPathLen() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ + +HWTEST_F(GenerateCaTest, set_bisic_constraints_patchlen_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + Options options; + options[Options::BASIC_CONSTRAINTS_PATH_LEN] = 1; + bool cert1 = CertTools::SetBisicConstraintsPathLen(&options, cert); + EXPECT_NE(cert1, false); +} + + +/** + * @tc.name: sign_for_subcert_test_001 + * @tc.desc: Test function of SignForSubCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, sign_for_subcert_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + 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"; + 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; + 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_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + bool cert1 = CertTools::SignForSubCert(cert, csr, issuercsr, keyPair, params.get()); + EXPECT_EQ(cert1, true); +} + + +/** + * @tc.name: sign_for_subcert_test_002 + * @tc.desc: Test function of SignForSubCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, sign_for_subcert_test_002, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + 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"; + 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; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = X509_REQ_new(); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + bool cert1 = CertTools::SignForSubCert(cert, csr, issuercsr, keyPair, params.get()); + EXPECT_EQ(cert1, false); +} + + +/** + * @tc.name: sign_for_subcert_test_003 + * @tc.desc: Test function of SignForSubCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, sign_for_subcert_test_003, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + 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 = "SHA256withECDSA"; + 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"; + 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; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + X509_REQ* issuercsr = X509_REQ_new(); + bool cert1 = CertTools::SignForSubCert(cert, csr, issuercsr, keyPair, params.get()); + + EXPECT_NE(cert1, false); +} + +/** + * @tc.name: sign_for_subcert_test_004 + * @tc.desc: Test function of SignForSubCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, sign_for_subcert_test_004, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + 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 = "SHA256withECDSA"; + 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"; + 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; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + bool cert1 = CertTools::SignForSubCert(cert, csr, issuercsr, keyPair, params.get()); + + EXPECT_EQ(cert1, true); +} + +/** + * @tc.name: sign_for_subcert_test_005 + * @tc.desc: Test function of SignForSubCert() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, sign_for_subcert_test_005, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + 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 = "SHA256withECDSA"; + 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"; + 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; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + X509_REQ* issuercsr = CertTools::GenerateCsr(keyPair, signAlg, issuer); + bool cert1 = CertTools::SignForSubCert(cert, csr, issuercsr, keyPair, params.get()); + + EXPECT_EQ(cert1, true); +} + +/** + * @tc.name: get_csr_test_001 + * @tc.desc: Test function of GetCsr() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ + +HWTEST_F(GenerateCaTest, get_csr_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::string signAlg = ""; + std::string subject = ""; + EVP_PKEY* keyPair = nullptr; + bool ret = api->GetCsr(keyPair, signAlg, subject); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: get_csr_test_002 + * @tc.desc: Test function of GetCsr() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, get_csr_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + EVP_PKEY* keyPair = nullptr; + bool ret = api->GetCsr(keyPair, signAlg, subject); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: save_cert_to_file_test_001 + * @tc.desc: Test function of CertTools::SaveCertTofile interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, save_cert_to_file_test_001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + EXPECT_NE(cert, nullptr); + std::string rootoutFile = "root-ca1.cer"; + CertTools::SaveCertTofile(rootoutFile, cert); +} + + +/** + * @tc.name: save_cert_to_file_test_002 + * @tc.desc: Test function of CertTools::SaveCertTofile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, save_cert_to_file_test_002, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + std::string rootoutFile = ""; + CertTools::SaveCertTofile(rootoutFile, cert); +} + +/** + * @tc.name: isempty_test_002 + * @tc.desc: Test function of IsEmpty() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, isempty_test_002, testing::ext::TestSize.Level1) +{ + std::string cs = "1234"; + bool res = FileUtils::IsEmpty(cs); + EXPECT_EQ(res, false); +} +/** + * @tc.name: write_test_001 + * @tc.desc: Test function of IsEmpty() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, write_test_001, testing::ext::TestSize.Level1) +{ + std::string cs = "1234"; + int res = FileUtils::Write(cs, "/data/test/"); + EXPECT_EQ(res, -103); +} +/** + * @tc.name: read_test_001 + * @tc.desc: Test function of IsEmpty() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCaTest, read_test_001, testing::ext::TestSize.Level1) +{ + std::string cs = "1234"; + std::ifstream input; + + int res = FileUtils::Read(input, cs); + EXPECT_EQ(res, 0); +} +/** +* @tc.name: Append_Write_File_ByOffset_To_File_test_004 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Append_Write_File_ByOffset_To_File_test_004, testing::ext::TestSize.Level1) +{ + std::string file = "/data/test/"; + std::ifstream in(file); + std::ofstream out(""); + bool res = FileUtils::AppendWriteFileByOffsetToFile(in, out, 10, 100); + EXPECT_EQ(res, false); + out.close(); + in.close(); +} +/** +* @tc.name: Append_Write_File_ByOffset_To_File_test_005 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Append_Write_File_ByOffset_To_File_test_005, testing::ext::TestSize.Level1) +{ + std::string file = "/data/test/generateKeyPair/keypair.p12"; + std::ifstream in(file); + std::ofstream out("/data/test/generateKeyPair/test.txt"); + bool res = FileUtils::AppendWriteFileByOffsetToFile(in, out, 10, 100); + EXPECT_EQ(res, true); + out.close(); + in.close(); +} +/** +* @tc.name: Append_Write_File_ByOffset_To_File_test_006 +* @tc.desc: Test function of AppendWriteFileByOffsetToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Append_Write_File_ByOffset_To_File_test_006, testing::ext::TestSize.Level1) +{ + std::string file = "/data/test/"; + std::ifstream in(file); + std::ofstream out("/data/test/generateKeyPair/test.txt"); + bool res = FileUtils::AppendWriteFileByOffsetToFile(in, out, 10, 100); + EXPECT_EQ(res, false); + out.close(); + in.close(); +} + +/** +* @tc.name: Verify_Hap_test_001 +* @tc.desc: Test function of VerifyHapSigner() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Verify_Hap_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string inForm = "zip"; + (*params)["inForm"] = inForm; + bool res = api->VerifyHapSigner(params.get()); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: Verify_Hap_test_002 +* @tc.desc: Test function of VerifyHapSigner() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Verify_Hap_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string inForm = "elf"; + (*params)["inForm"] = inForm; + bool res = api->VerifyHapSigner(params.get()); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: Verify_Hap_test_003 +* @tc.desc: Test function of VerifyHapSigner() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Verify_Hap_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string inForm = "bin"; + (*params)["inForm"] = inForm; + bool res = api->VerifyHapSigner(params.get()); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: Verify_Hap_test_004 +* @tc.desc: Test function of VerifyHapSigner() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, Verify_Hap_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string inForm = "mmmmm"; + (*params)["inForm"] = inForm; + bool res = api->VerifyHapSigner(params.get()); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: generate_root_cert_to_flie_001 +* @tc.desc: Test function of GenerateRootCertToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_root_cert_to_flie_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + EVP_PKEY* keyPair = nullptr; + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + bool res = api->GenerateRootCertToFile(params.get(), keyPair); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: generate_root_cert_to_flie_002 +* @tc.desc: Test function of GenerateRootCertToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_root_cert_to_flie_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + 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 = ""; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + char isksPwd[] = "123456"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + bool res = api->GenerateRootCertToFile(params.get(), keyPair); + EXPECT_EQ(res, false); +} +/** +* @tc.name: generate_root_cert_to_flie_003 +* @tc.desc: Test function of GenerateRootCertToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_root_cert_to_flie_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + 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 = "SHA256withRSA"; + 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"; + char isksPwd[] = "123456"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + bool res = api->GenerateRootCertToFile(params.get(), keyPair); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: generate_root_cert_to_flie_004 +* @tc.desc: Test function of GenerateRootCertToFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_root_cert_to_flie_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + 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"; + char isksPwd[] = "123456"; + std::string outFile = "/datamt/test/generateCA/root-ca-test.cer"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outFile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + bool res = api->GenerateRootCertToFile(params.get(), keyPair); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: out_put_mode_of_cert_001 +* @tc.desc: Test function of OutputModeOfCert() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, out_put_mode_of_cert_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + X509* cert = X509_new(); + std::string outFile = "/datamt/test/generateCA/sub-ca-test.cer"; + (*params)["outFile"] = outFile; + bool res = api->OutputModeOfCert(cert, params.get()); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: generate_key_store_001 +* @tc.desc: Test function of GenerateKeyStore() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_key_store_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = ""; + (*params)["keyAlias"] = keyAlias; + bool res = api->GenerateKeyStore(params.get()); + EXPECT_EQ(res, false); +} + +/** +* @tc.name: handle_issuer_key_alias_empty_001 +* @tc.desc: Test function of HandleIssuerKeyAliasEmpty() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, handle_issuer_key_alias_empty_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keystoreFile = "/data/test/generateCA/other.p12"; + std::string issuerKeystoreFile = "/data/test/generateCA/issuer.p12"; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["keystoreFile"] = keystoreFile; + api->HandleIssuerKeyAliasEmpty(params.get()); +} + +/** +* @tc.name: handle_issuer_key_alias_empty_002 +* @tc.desc: Test function of HandleIssuerKeyAliasEmpty() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, handle_issuer_key_alias_empty_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + char keystorepwd[] = ""; + char issuerstorepwd[] = "123456"; + std::string keystoreFile = "/data/test/generateCA/other.p12"; + std::string issuerKeystoreFile = "/data/test/generateCA/other.p12"; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystorePwd"] = issuerstorepwd; + (*params)["keystorePwd"] = keystorepwd; + api->HandleIssuerKeyAliasEmpty(params.get()); +} + +/** +* @tc.name: handle_issuer_key_alias_empty_003 +* @tc.desc: Test function of HandleIssuerKeyAliasEmpty() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, handle_issuer_key_alias_empty_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + char keystorepwd[] = "234567"; + char issuerstorepwd[] = "123456"; + std::string keystoreFile = "/data/test/generateCA/other.p12"; + std::string issuerKeystoreFile = "/data/test/generateCA/other.p12"; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystorePwd"] = issuerstorepwd; + (*params)["keystorePwd"] = keystorepwd; + api->HandleIssuerKeyAliasEmpty(params.get()); +} + +/** +* @tc.name: handle_issuer_key_alias_empty_004 +* @tc.desc: Test function of HandleIssuerKeyAliasEmpty() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, handle_issuer_key_alias_empty_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + std::string keystoreFile = "/data/test/generateCA/other.p12"; + std::string issuerKeystoreFile = ""; + char keystorepwd[] = "234567"; + char issuerstorepwd[] = "123456"; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerKeystorePwd"] = issuerstorepwd; + (*params)["keystorePwd"] = keystorepwd; + api->HandleIssuerKeyAliasEmpty(params.get()); +} +/** +* @tc.name: handle_issuer_key_alias_not_empty_001 +* @tc.desc: Test function of HandleIsserKeyAliasNotEmpty() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, handle_issuer_key_alias_not_empty_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string issuerKeystoreFile = ""; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + api->HandleIsserKeyAliasNotEmpty(params.get()); +} + +/** +* @tc.name: handle_issuer_key_alias_not_empty_002 +* @tc.desc: Test function of HandleIsserKeyAliasNotEmpty() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, handle_issuer_key_alias_not_empty_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::shared_ptr api = std::make_shared(); + std::string issuerKeystoreFile = "/data/test/generateCA/other.cer"; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + api->HandleIsserKeyAliasNotEmpty(params.get()); +} + +/** +* @tc.name: generate_end_cert_001 +* @tc.desc: Test function of GenerateEndCert() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_end_cert_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app-sign-srv-ca-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char isksPwd[] = "123456"; + std::string outfile = "/data/test/generateCA/app-release.cer"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outfile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EVP_PKEY* issuerkeyPair = nullptr; + adaptePtr->SetIssuerKeyStoreFile(true); + issuerkeyPair = adaptePtr->GetIssuerKeyByAlias(); + X509_REQ* csr = nullptr; + csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateEndCert(csr, issuerkeyPair, *adaptePtr, PROFILE_SIGNING_CAPABILITY, + sizeof(PROFILE_SIGNING_CAPABILITY)); + EXPECT_EQ(ret, true); +} + +/** +* @tc.name: generate_end_cert_002 +* @tc.desc: Test function of GenerateEndCert() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_end_cert_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerkeyAlias = "oh-app-sign-srv-ca-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char isksPwd[] = "123456"; + std::string outfile = "/data/test/generateCA/app-release.cer"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outfile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EVP_PKEY* issuerkeyPair = nullptr; + X509_REQ* csr = nullptr; + csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateEndCert(csr, issuerkeyPair, *adaptePtr, PROFILE_SIGNING_CAPABILITY, + sizeof(PROFILE_SIGNING_CAPABILITY)); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name: generate_end_cert_003 +* @tc.desc: Test function of GenerateEndCert() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_end_cert_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuerkeyAlias = "oh-profile-sign-srv-ca-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + char isksPwd[] = "123456"; + std::string outfile = "/data/test/generateCA/app-release.cer"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outfile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EVP_PKEY* issuerkeyPair = nullptr; + adaptePtr->SetIssuerKeyStoreFile(true); + issuerkeyPair = adaptePtr->GetIssuerKeyByAlias(); + X509_REQ* csr = nullptr; + csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateEndCert(csr, issuerkeyPair, *adaptePtr, PROFILE_SIGNING_CAPABILITY, + sizeof(PROFILE_SIGNING_CAPABILITY)); + EXPECT_EQ(ret, true); +} + +/** +* @tc.name: generate_end_cert_004 +* @tc.desc: Test function of GenerateEndCert() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, generate_end_cert_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-profile1-key-v1"; + std::string issuerkeyAlias = "oh-profile-sign-srv-ca-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string signAlg = "SHA384withECDSA"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile1 Release"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Profile Signature Service CA"; + char isksPwd[] = "123456"; + std::string outfile = "/data/test/generateCA/app-release.cer"; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeystorePwd"] = isksPwd; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + (*params)["outFile"] = outfile; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EVP_PKEY* issuerkeyPair = nullptr; + X509_REQ* csr = nullptr; + csr = CertTools::GenerateCsr(keyPair, signAlg, subject); + EXPECT_NE(csr, nullptr); + bool ret = CertTools::GenerateEndCert(csr, issuerkeyPair, *adaptePtr, PROFILE_SIGNING_CAPABILITY, + sizeof(PROFILE_SIGNING_CAPABILITY)); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name: issuer_key_store_file_001 +* @tc.desc: Test function of IssuerKeyStoreFile() interface for FAIL. +* @tc.type: FUNC +* @tc.require: SR000H63TL +*/ +HWTEST_F(GenerateCaTest, issuer_key_store_file_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v123"; + std::string issuerkeyAlias = "oh-app1-key-v122222"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "/data/test/generateCA/OpenHarmony1.p12"; + char keystorePwd[] = "123456"; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeyAlias"] = issuerkeyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + adaptePtr->IssuerKeyStoreFile(&keyPair, true); +} +} +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateCsr/generate_csr_test.cpp b/hapsigntool_cpp/test/unittest/generateCsr/generate_csr_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b0c286422fe631c812d1abff54e86aa61247b47 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateCsr/generate_csr_test.cpp @@ -0,0 +1,951 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "gtest/gtest.h" +#include "openssl/x509.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "cert_tools.h" +#include "params_run_tool.h" +#include "file_utils.h" +#include "hash_utils.h" +#include "constant.h" +#include "securec.h" +#include "file_data_source.h" +#include "byte_buffer_data_source.h" + +namespace OHOS { +namespace SignatureTools { + +class GenerateCsrTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: generate_csr_test_001 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_001, testing::ext::TestSize.Level1) // 已有p12直接生成csr +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-1.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_csr_test_002 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_002, testing::ext::TestSize.Level1) // 生成p12并用于生成csr +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + (*params)["keyAlias"] = std::string("oh-app1-key-v2"); + (*params)["keyAlg"] = std::string("ECC"); + (*params)["keySize"] = 256; + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest2.p12"); + + { + char keyPwd[] = "keyPwdChars"; + char keystorePwd[] = "keystorePwdChars"; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, true); + } + + { + char keyPwd[] = "keyPwdChars"; + char keystorePwd[] = "keystorePwdChars"; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App2 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA384); + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-2.csr"); + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, true); + } +} + +/** + * @tc.name: generate_csr_test_003 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_003, testing::ext::TestSize.Level1) // 已有p12直接生成csr但必选参数缺失如subject +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-3.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_004 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_004, testing::ext::TestSize.Level1) // 已有p12直接生成csr但subject参数字符串格式无效 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-4.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_005 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_005, testing::ext::TestSize.Level1) // 已有p12直接生成csr但subject参数格式无效 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,ABC=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-5.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_006 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_006, testing::ext::TestSize.Level1) // 已有p12直接生成csr但keyAlias错误 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v6"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-6.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_007 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_007, testing::ext::TestSize.Level1) // 已有p12直接生成csr但keystorePwd错误 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "654321"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-7.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_008 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_008, testing::ext::TestSize.Level1) // 已有p12直接生成csr但signAlg错误 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string("SHA256"); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-8.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_009 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_009, testing::ext::TestSize.Level1) // 已有p12直接生成csr不输出到文件 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_csr_test_010 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_010, testing::ext::TestSize.Level1) // 已有p12直接生成csr但路径错误 +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/d/test/resource/oh-app1-key-10.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + + +/** + * @tc.name: generate_csr_test_011 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_011, testing::ext::TestSize.Level1) // 必选参数缺失keystoreFile, keystorePwd +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-11.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: generate_csr_test_012 + * @tc.desc: Test function of SignToolServiceImpl::GenerateCsr() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_012, testing::ext::TestSize.Level1) // 已有p12直接生成csr +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = std::string("/data/test/generateCsr/oh-app1-key-12.csr"); + + bool ret = api->GenerateCsr(params.get()); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: generate_csr_test_013 + * @tc.desc: Test function of CertTools::GenerateCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_013, testing::ext::TestSize.Level1) +{ + int keySize = 256; + std::string algorithm = "ECC"; + std::string signAlgorithm = SIGN_ALG_SHA256; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + EXPECT_NE(keyPair, nullptr); + if (!keyPair) { + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + if (csr) { + X509_REQ_free(csr); + } + EVP_PKEY_free(keyPair); + } +} + +/** + * @tc.name: generate_csr_test_014 + * @tc.desc: Test function of CertTools::GenerateCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, generate_csr_test_014, testing::ext::TestSize.Level1) +{ + std::string signAlgorithm = SIGN_ALG_SHA256; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + X509_REQ* csr = CertTools::GenerateCsr(nullptr, signAlgorithm, subject); + EXPECT_EQ(csr, nullptr); +} + +/** + * @tc.name: csr_to_string_test_001 + * @tc.desc: Test function of CertTools::CsrToString() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, csr_to_string_test_001, testing::ext::TestSize.Level1) +{ + int keySize = 256; + std::string algorithm = "ECC"; + std::string signAlgorithm = SIGN_ALG_SHA256; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::shared_ptr keyStoreHelper = std::make_shared(); + EVP_PKEY* keyPair = keyStoreHelper->GenerateKeyPair(algorithm, keySize); + + EXPECT_NE(keyPair, nullptr); + + if (keyPair) { + X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlgorithm, subject); + EXPECT_NE(csr, nullptr); + if (csr) { + std::string csrStr = CertTools::CsrToString(csr); + EXPECT_NE(csrStr.size(), 0U); + X509_REQ_free(csr); + } + EVP_PKEY_free(keyPair); + } +} + +/** + * @tc.name: csr_to_string_test_002 + * @tc.desc: Test function of CertTools::CsrToString() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, csr_to_string_test_002, testing::ext::TestSize.Level1) +{ + std::string csrStr = CertTools::CsrToString(nullptr); + EXPECT_EQ(csrStr, ""); +} + +/** + * @tc.name: output_string_test_001 + * @tc.desc: Test function of SignToolServiceImpl::OutputString() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, output_string_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + EXPECT_EQ(api->OutputString("hello world", "/data/test/generateCsr/output_string.txt"), true); +} + +/** + * @tc.name: run_csr_test_001 + * @tc.desc: Test function of ParamsRunTool::RunCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, run_csr_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunCsr(params.get(), *api); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: run_csr_test_002 + * @tc.desc: Test function of ParamsRunTool::RunCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, run_csr_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string("SHA256"); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunCsr(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: run_csr_test_003 + * @tc.desc: Test function of ParamsRunTool::RunCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, run_csr_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunCsr(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: run_csr_test_004 + * @tc.desc: Test function of ParamsRunTool::RunCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, run_csr_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*params)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p11"); + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunCsr(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: build_dn_test_001 + * @tc.desc: Test function of BuildDN() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, build_dn_test_001, testing::ext::TestSize.Level1) +{ + X509_REQ* csr = X509_REQ_new(); + EXPECT_NE(csr, nullptr); + if (csr) { + X509_NAME* name = BuildDN("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", csr); + EXPECT_NE(name, nullptr); + if (name) { + X509_NAME_free(name); + } + } +} + +/** + * @tc.name: check_dn_test_001 + * @tc.desc: Test function of g_checkDn() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, check_dn_test_001, testing::ext::TestSize.Level1) +{ + std::vector> pairs; + EXPECT_EQ(g_checkDn("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", pairs), 0); +} + +/** + * @tc.name: split_string_test_001 + * @tc.desc: Test function of StringUtils::SplitString() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, split_string_test_001, testing::ext::TestSize.Level1) +{ + std::string str = "0:0:0:0"; + std::vector vec = StringUtils::SplitString(str, ':'); + EXPECT_EQ(vec.size(), 4U); + if (vec.size() == 4) { + EXPECT_EQ(vec[0].size(), 1U); + if (vec[0].size() == 1U) { + EXPECT_EQ(vec[0][0], '0'); + } + } +} + +/** + * @tc.name: trim_test_001 + * @tc.desc: Test function of StringUtils::Trim() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, trim_test_001, testing::ext::TestSize.Level1) +{ + std::string str = " \n\r\f\va \n\r\f\v"; + std::string str1 = StringUtils::Trim(str); + EXPECT_EQ(str1.size(), 1U); +} + +/** + * @tc.name: call_generators_test_001 + * @tc.desc: Test function of ParamsRunTool::CallGenerators() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, call_generators_test_001, testing::ext::TestSize.Level1) +{ + ParamsSharedPtr params = std::make_shared(); + params->SetMethod(GENERATE_CSR); + Options* options = params->GetOptions(); + std::shared_ptr api = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + (*options)["keyAlias"] = std::string("oh-app1-key-v1"); + (*options)["keyPwd"] = keyPwd; + (*options)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*options)["signAlg"] = std::string(SIGN_ALG_SHA256); + (*options)["keystoreFile"] = std::string("/data/test/generateCsr/ohtest.p12"); + (*options)["keystorePwd"] = keystorePwd; + + EXPECT_EQ(ParamsRunTool::CallGenerators(params, *api), true); +} + +/** + * @tc.name: process_cmd_test_001 + * @tc.desc: Test function of ParamsRunTool::ProcessCmd() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, process_cmd_test_001, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "generate-csr", arg2[] = "-keyAlias", arg3[] = "oh-app1-key-v1", + arg4[] = "-subject", arg5[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", + arg6[] = "-signAlg", arg8[] = "-keystoreFile", + arg9[] = "/data/test/generateCsr/ohtest.p12", arg10[] = "-keystorePwd", arg11[] = "123456", + arg12[] = "-keyPwd", arg13[] = "123456"; + char* arg7 = new char[SIGN_ALG_SHA256.size() + 1](); + arg7[SIGN_ALG_SHA256.size()] = '\0'; + EXPECT_EQ(memcpy_s(arg7, SIGN_ALG_SHA256.size(), SIGN_ALG_SHA256.c_str(), SIGN_ALG_SHA256.size()), 0); + char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + EXPECT_EQ(ParamsRunTool::ProcessCmd(args, sizeof(args) / sizeof((char*)arg0)), true); + delete[] arg7; +} + +/** + * @tc.name: process_cmd_test_003 + * @tc.desc: Test function of ParamsRunTool::ProcessCmd() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, process_cmd_test_003, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "-h", arg2[] = ""; + char* args[] = { arg0, arg1 }; + EXPECT_EQ(ParamsRunTool::ProcessCmd(args, sizeof(args) / sizeof((char*)arg0)), true); + char* args1[] = { arg0, arg2 }; + EXPECT_EQ(ParamsRunTool::ProcessCmd(args, sizeof(args1) / sizeof((char*)arg0)), true); +} + +/** + * @tc.name: process_cmd_test_004 + * @tc.desc: Test function of ParamsRunTool::ProcessCmd() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, process_cmd_test_004, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "-v"; + char* args[] = { arg0, arg1 }; + EXPECT_EQ(ParamsRunTool::ProcessCmd(args, sizeof(args) / sizeof((char*)arg0)), true); +} + +/** + * @tc.name: is_valid_file_test_001 + * @tc.desc: Test function of FileUtils::IsValidFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, is_valid_file_test_001, testing::ext::TestSize.Level1) +{ + EXPECT_EQ(FileUtils::IsValidFile("/data/test/generateCsr/ohtest.p12"), true); + EXPECT_EQ(FileUtils::IsValidFile("/data/test/generateCsr/ohtest.p11"), false); + EXPECT_EQ(FileUtils::IsValidFile("/data/test/generateCsr/"), false); +} + +/** + * @tc.name: version_test_001 + * @tc.desc: Test function of ParamsRunTool::Version() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, version_test_001, testing::ext::TestSize.Level1) +{ + ParamsRunTool::Version(); +} + +/** + * @tc.name: convert2params_test_001 + * @tc.desc: Test function of CmdUtil::Convert2Params() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, convert2params_test_001, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "generate-csr", arg2[] = "-keyAlias", arg3[] = "oh-app1-key-v1", + arg4[] = "-subject", arg5[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", + arg6[] = "-signAlg", arg8[] = "-keystoreFile", + arg9[] = "/data/test/generateCsr/ohtest.p12", arg10[] = "-keystorePwd", arg11[] = "123456", + arg12[] = "-keyPwd", arg13[] = "123456"; + char* arg7 = new char[SIGN_ALG_SHA256.size() + 1](); + arg7[SIGN_ALG_SHA256.size()] = '\0'; + EXPECT_EQ(memcpy_s(arg7, SIGN_ALG_SHA256.size(), SIGN_ALG_SHA256.c_str(), SIGN_ALG_SHA256.size()), 0); + char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, + arg11, arg12, arg13 }; + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + EXPECT_EQ(cmdUtil.Convert2Params(args, sizeof(args) / sizeof((char*)arg0), param), true); + delete[] arg7; +} + +/** + * @tc.name: convert2params_test_002 + * @tc.desc: Test function of CmdUtil::Convert2Params() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, convert2params_test_002, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "generate", arg2[] = "-keyAlias", arg3[] = "oh-app1-key-v1", + arg4[] = "-subject", arg5[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", + arg6[] = "-signAlg", arg8[] = "-keystoreFile", + arg9[] = "/data/test/generateCsr/ohtest.p12", arg10[] = "-keystorePwd", arg11[] = "123456", + arg12[] = "-keyPwd", arg13[] = "123456"; + char* arg7 = new char[SIGN_ALG_SHA256.size() + 1](); + arg7[SIGN_ALG_SHA256.size()] = '\0'; + EXPECT_EQ(memcpy_s(arg7, SIGN_ALG_SHA256.size(), SIGN_ALG_SHA256.c_str(), SIGN_ALG_SHA256.size()), 0); + char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, + arg11, arg12, arg13 }; + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + EXPECT_EQ(cmdUtil.Convert2Params(args, sizeof(args) / sizeof((char*)arg0), param), false); + delete[] arg7; +} + +/** + * @tc.name: convert2params_test_003 + * @tc.desc: Test function of CmdUtil::Convert2Params() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, convert2params_test_003, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "generate-csr", arg2[] = "-keyAlias", arg3[] = "oh-app1-key-v1", + arg4[] = "-subject", arg5[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", + arg6[] = "-signAlg", arg8[] = "-keystoreFile", + arg9[] = "/data/test/generateCsr/ohtest.p12", arg10[] = "-keystorePwd", arg11[] = "123456", + arg12[] = "-keyPwd", arg13[] = "123456", arg14[] = "-signcode"; + char* arg7 = new char[SIGN_ALG_SHA256.size() + 1](); + arg7[SIGN_ALG_SHA256.size()] = '\0'; + EXPECT_EQ(memcpy_s(arg7, SIGN_ALG_SHA256.size(), SIGN_ALG_SHA256.c_str(), SIGN_ALG_SHA256.size()), 0); + char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, + arg11, arg12, arg13, arg14 }; + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + EXPECT_EQ(cmdUtil.Convert2Params(args, sizeof(args) / sizeof((char*)arg0), param), false); + delete[] arg7; +} + +/** + * @tc.name: convert2params_test_004 + * @tc.desc: Test function of CmdUtil::Convert2Params() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, convert2params_test_004, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "generate-csr", arg2[] = "-keyAlias", arg3[] = "oh-app1-key-v1", + arg4[] = "-subject", arg5[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", + arg6[] = "-signAlg", arg8[] = "-keystoreFile", + arg9[] = "/data/test/generateCsr/ohtest.p12", arg10[] = "-keystorePwd", arg11[] = "123456", + arg12[] = "-keyPwd", arg13[] = "123456", arg14[] = ""; + char* arg7 = new char[SIGN_ALG_SHA256.size() + 1](); + arg7[SIGN_ALG_SHA256.size()] = '\0'; + EXPECT_EQ(memcpy_s(arg7, SIGN_ALG_SHA256.size(), SIGN_ALG_SHA256.c_str(), SIGN_ALG_SHA256.size()), 0); + char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, + arg11, arg12, arg13, arg14 }; + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + EXPECT_EQ(cmdUtil.Convert2Params(args, sizeof(args) / sizeof((char*)arg0), param), false); + delete[] arg7; +} + +/** + * @tc.name: get_method_test_001 + * @tc.desc: Test function of Params::GetMethod() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, get_method_test_001, testing::ext::TestSize.Level1) +{ + Params params; + params.SetMethod("test"); + EXPECT_EQ(params.GetMethod(), "test"); +} + +/** + * @tc.name: dispatch_params_test_001 + * @tc.desc: Test function of ParamsRunTool::DispatchParams() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, dispatch_params_test_001, testing::ext::TestSize.Level1) +{ + char arg0[] = "", arg1[] = "generate-csr", arg2[] = "-keyAlias", arg3[] = "oh-app1-key-v1", + arg4[] = "-subject", arg5[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release", + arg6[] = "-signAlg", arg8[] = "-keystoreFile", + arg9[] = "/data/test/generateCsr/ohtest.p12", arg10[] = "-keystorePwd", arg11[] = "123456", + arg12[] = "-keyPwd", arg13[] = "123456"; + char* arg7 = new char[SIGN_ALG_SHA256.size() + 1](); + arg7[SIGN_ALG_SHA256.size()] = '\0'; + EXPECT_EQ(memcpy_s(arg7, SIGN_ALG_SHA256.size(), SIGN_ALG_SHA256.c_str(), SIGN_ALG_SHA256.size()), 0); + char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, + arg11, arg12, arg13 }; + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + EXPECT_EQ(cmdUtil.Convert2Params(args, sizeof(args) / sizeof((char*)arg0), param), true); + std::shared_ptr service_api = std::make_shared(); + EXPECT_EQ(ParamsRunTool::DispatchParams(param, *service_api), true); + delete[] arg7; +} + +/** + * @tc.name: get_hash_algs_id_test_001 + * @tc.desc: Test function of HashUtils::GetHashAlgsId() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, get_hash_algs_id_test_001, testing::ext::TestSize.Level1) +{ + HashUtils::GetHashAlgsId("SHA-224"); + HashUtils::GetHashAlgsId("SHA-384"); + HashUtils::GetHashAlgsId("SHA-512"); + HashUtils::GetHashAlgsId("SHA-1024"); +} + +/** + * @tc.name: get_hash_algs_name_test_001 + * @tc.desc: Test function of HashUtils::GetHashAlgName() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, get_hash_algs_name_test_001, testing::ext::TestSize.Level1) +{ + HashUtils::GetHashAlgName(5); + HashUtils::GetHashAlgName(7); + HashUtils::GetHashAlgName(8); + HashUtils::GetHashAlgName(9); +} + +/** + * @tc.name: get_digest_from_bytes_test_001 + * @tc.desc: Test function of HashUtils::GetDigestFromBytes() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, get_digest_from_bytes_test_001, testing::ext::TestSize.Level1) +{ + HashUtils::GetDigestFromBytes({}, 1, ""); + HashUtils::GetDigestFromBytes({ 'a' }, 0, ""); +} + +/** + * @tc.name: read_data_and_digest_update_test_001 + * @tc.desc: Test function of FileDataSource::ReadDataAndDigestUpdate() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, read_data_and_digest_update_test_001, testing::ext::TestSize.Level1) +{ + RandomAccessFile file; + FileDataSource src(file, 0, 0, 0); + DigestParameter param; + src.ReadDataAndDigestUpdate(param, -1); +} + +/** + * @tc.name: read_data_and_digest_update_test_002 + * @tc.desc: Test function of ByteBufferDataSource::ReadDataAndDigestUpdate() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(GenerateCsrTest, read_data_and_digest_update_test_002, testing::ext::TestSize.Level1) +{ + ByteBuffer buffer; + ByteBufferDataSource src(buffer); + DigestParameter param; + src.ReadDataAndDigestUpdate(param, -1); +} + +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateKeyPair/generate_keypair_test.cpp b/hapsigntool_cpp/test/unittest/generateKeyPair/generate_keypair_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c12bd6c0e25315852dc001440a6107c39150142 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateKeyPair/generate_keypair_test.cpp @@ -0,0 +1,810 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "localization_adapter.h" +#include "openssl/ssl.h" +#include "openssl/pem.h" +#include "openssl/err.h" +#include "p12_local.h" +#include "cmd_util.h" +#include "file_utils.h" +#include "params_run_tool.h" +#include "constant.h" +#include "params.h" +#include "params_trust_list.h" +#include "param_constants.h" + +namespace OHOS { +namespace SignatureTools { + +class GenerateKeyPairTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/* + * @tc.name: generate_keypair_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_001, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: generate_keypair_test_002 + * @tc.desc: If you search for a key pair in the keystore using an alias, + * @the key pair pointer is returned on success, and NULL is returned on failure. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + + int status = adaptePtr->IsAliasExist(adaptePtr->options->GetString(Options::KEY_ALIAS)); + EXPECT_EQ(status, 0); +} + +/* + * @tc.name: generate_keypair_test_003 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EVP_PKEY* keyPair = nullptr; + keyPair = adaptePtr->GetAliasKey(true); + EXPECT_NE(keyPair, nullptr); +} + +/* + * @tc.name: generate_keypair_test_004 + * @tc.desc: Generate key pair. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlg = "ECC"; + int keySize = 256; + + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + + EVP_PKEY* keyPair = nullptr; + std::string keyStorePath = adaptePtr->options->GetString(Options::KEY_STORE_FILE); + keyPair = adaptePtr->keyStoreHelper->GenerateKeyPair(adaptePtr->options->GetString(Options::KEY_ALG), + adaptePtr->options->GetInt(Options::KEY_SIZE)); + EXPECT_NE(keyPair, nullptr); +} + +/* + * @tc.name: generate_keypair_test_005 + * @tc.desc: Load the key pair into the file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + + EVP_PKEY* keyPair = nullptr; + std::string keyStorePath = adaptePtr->options->GetString(Options::KEY_STORE_FILE); + keyPair = adaptePtr->keyStoreHelper->GenerateKeyPair(adaptePtr->options->GetString(Options::KEY_ALG), + adaptePtr->options->GetInt(Options::KEY_SIZE)); + int ret = adaptePtr->keyStoreHelper->WriteKeyStore(keyPair, keyStorePath, + adaptePtr->options->GetChars(Options::KEY_STORE_RIGHTS), + adaptePtr->options->GetString(Options::KEY_ALIAS), + adaptePtr->options->GetChars(Options::KEY_RIGHTS)); + EXPECT_NE(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_006 + * @tc.desc: Read the key pair from the file by alias. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + + EVP_PKEY* keyPair = nullptr; + std::string keyStorePath = adaptePtr->options->GetString(Options::KEY_STORE_FILE); + adaptePtr->keyStoreHelper->ReadKeyStore(keyStorePath, adaptePtr->options->GetChars(Options::KEY_STORE_RIGHTS), + adaptePtr->options->GetString(Options::KEY_ALIAS), + adaptePtr->options->GetChars(Options::KEY_RIGHTS), &keyPair); + EXPECT_NE(keyPair, nullptr); +} + +/* + * @tc.name: generate_keypair_test_007 + * @tc.desc: reset passwords. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + char issuerKeyPwd[] = "123456"; + char issuerkeystorePwd[] = "123456"; + + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["issuerKeyPwd"] = issuerKeyPwd; + (*params)["issuerKeystorePwd"] = issuerkeystorePwd; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + + std::string str = ""; + adaptePtr->ResetPwd(); + EXPECT_EQ(adaptePtr->options->GetChars(Options::KEY_RIGHTS), str); + EXPECT_EQ(adaptePtr->options->GetChars(Options::KEY_STORE_RIGHTS), str); + EXPECT_EQ(adaptePtr->options->GetChars(Options::ISSUER_KEY_RIGHTS), str); + EXPECT_EQ(adaptePtr->options->GetChars(Options::ISSUER_KEY_STORE_RIGHTS), str); +} + +/* + * @tc.name: generate_keypair_test_008 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_008, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "aaa"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 385; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: generate_keypair_test_010 +* @tc.desc: Generate a key pair and load it into the keystore. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_010, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456909"; + std::string keyAlg = "ECC"; + int keySize = 385; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: generate_keypair_test_013 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_013, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + KeyStoreHelper keystorehelper; + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "1234563333"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + EVP_PKEY* keyPair = keystorehelper.GenerateKeyPair(keyAlg, keySize); + + int ret = keystorehelper.WriteKeyStore(keyPair, keystoreFile, keystorePwd, keyAlias, keyPwd); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_014 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_014, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + KeyStoreHelper keystorehelper; + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony99999.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + EVP_PKEY* keyPair = nullptr; + + int ret = keystorehelper.ReadKeyStore(keystoreFile, keystorePwd, keyAlias, keyPwd, &keyPair); + EXPECT_EQ(ret, RET_FAILED); +} + +/* +* @tc.name: generate_keypair_test_016 +* @tc.desc: Generate a key pair and load it into the keystore. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_016, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: generate_keypair_test_017 +* @tc.desc: Generate a key pair and load it into the keystore. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_017, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = ""; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = ""; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: generate_keypair_test_018 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_018, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlg = "ECC"; + int keySize = 256; + std::string keystoreFile = "./generateKeyPair/OpenHarmony1.p12"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + + bool ret = api->GenerateKeyStore(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: generate_keypair_test_019 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_019, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmony.p12"; + char storePwd[] = "123456"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + + keyhelper.CreatePKCS12(&p12, keyStorePath.c_str(), storePwd, keyPwd, alias.c_str(), keypair, cert); + int ret = keyhelper.FindKeyPair(p12, "", nullptr, nullptr, nullptr, ""); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_020 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_020, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmony11.p12"; + char storePwd[] = "123456"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + int ret = keyhelper.CreatePKCS12(&p12, keyStorePath.c_str(), storePwd, keyPwd, alias.c_str(), keypair, cert); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_021 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_021, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + int ret = keyhelper.Pkcs12PasswordParse(nullptr, nullptr, ""); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_022 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_022, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmonyDamage.p12"; + char storePwd[] = "123456"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + int ret = keyhelper.CreatePKCS12(&p12, keyStorePath.c_str(), storePwd, keyPwd, alias.c_str(), keypair, cert); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_023 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_023, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmonyNullpwd.p12"; + std::string alias = "oh-app1-key-v1"; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + keyhelper.CreatePKCS12(&p12, keyStorePath.c_str(), nullptr, nullptr, alias.c_str(), keypair, cert); + int ret = keyhelper.Pkcs12PasswordParse(p12, nullptr, ""); + EXPECT_EQ(ret, RET_OK); +} + +/* + * @tc.name: generate_keypair_test_024 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_024, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmonyNullpwd.p12"; + char storePwd[] = ""; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = ""; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + keyhelper.CreatePKCS12(&p12, keyStorePath.c_str(), storePwd, keyPwd, alias.c_str(), keypair, cert); + int ret = keyhelper.Pkcs12PasswordParse(p12, nullptr, ""); + EXPECT_EQ(ret, RET_OK); +} + +/* + * @tc.name: generate_keypair_test_025 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_025, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + EVP_PKEY* keypair = keyhelper.GenerateKeyPair("", 256); + EXPECT_EQ(keypair, nullptr); +} + +/* + * @tc.name: generate_keypair_test_026 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_026, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + PKCS12* p12 = nullptr; + p12 = keyhelper.CreatePKCS12(nullptr, nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0, nullptr); + EXPECT_EQ(p12, nullptr); +} + +/* + * @tc.name: generate_keypair_test_027 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_027, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + EVP_PKEY* keypair = keyhelper.GenerateKeyPair("ECC", 0); + EXPECT_EQ(keypair, nullptr); +} + +/* + * @tc.name: generate_keypair_test_028 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_028, testing::ext::TestSize.Level1) +{ + int nidKey = 1; + int iter = 1; + int maIter = 1; + bool ret = true; + KeyStoreHelper keyhelper; + keyhelper.SetNidMac(nidKey, iter, maIter); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: generate_keypair_test_029 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_029, testing::ext::TestSize.Level1) +{ + int nidKey = 0; + int iter = 0; + int macIter = 0; + bool ret = true; + KeyStoreHelper keyhelper; + keyhelper.SetNidMac(nidKey, iter, macIter); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: generate_keypair_test_030 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_030, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + int ret = keyhelper.SetCertPkcs12(nullptr, nullptr, nullptr, nullptr, 0, nullptr, nullptr, 0, 0, nullptr); + EXPECT_EQ(ret, RET_OK); +} + +/* + * @tc.name: generate_keypair_test_031 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_031, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + X509* cert = X509_new(); + int ret = keyhelper.SetCertPkcs12(cert, nullptr, nullptr, nullptr, -2, nullptr, nullptr, 0, 0, nullptr); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_033 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_033, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + int ret = keyhelper.SetPkeyPkcs12(nullptr, nullptr, nullptr, nullptr, nullptr, 0, nullptr, 0, 0, nullptr, 0); + EXPECT_EQ(ret, RET_OK); +} + +/* + * @tc.name: generate_keypair_test_034 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_034, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + STACK_OF(PKCS7)* safes = nullptr; + + std::string keyStorePath = "./generateKeyPair/OpenHarmony.p12"; + char storePwd1[] = "99999"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = ""; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + p12 = keyhelper.CreatePKCS12(storePwd1, keyPwd, nullptr, keypair, cert, 0, -2, -2, -1, 0, &safes); + EXPECT_EQ(p12, nullptr); +} + +/* + * @tc.name: generate_keypair_test_035 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_035, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + STACK_OF(PKCS7)* safes = nullptr; + + std::string keyStorePath = "./generateKeyPair/OpenHarmony.p12"; + char storePwd1[] = "99999"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = ""; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + p12 = keyhelper.CreatePKCS12(storePwd1, keyPwd, nullptr, keypair, cert, -2, 0, 0, -1, 0, &safes); + EXPECT_EQ(p12, nullptr); +} + +/* + * @tc.name: generate_keypair_test_036 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_036, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + PKCS12* p12 = nullptr; + EVP_PKEY* keypair = nullptr; + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmony.p12"; + char storePwd[] = "123456"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + + keypair = keyhelper.GenerateKeyPair("ECC", 256); + keyhelper.InitX509(*cert, *keypair); + + keyhelper.CreatePKCS12(&p12, keyStorePath.c_str(), storePwd, keyPwd, alias.c_str(), keypair, cert); + p12->authsafes = PKCS7_new(); + int ret = keyhelper.FindKeyPair(p12, "", nullptr, nullptr, nullptr, ""); + EXPECT_EQ(ret, RET_FAILED); +} + +/* + * @tc.name: generate_keypair_test_037 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GenerateKeyPairTest, generate_keypair_test_037, testing::ext::TestSize.Level1) +{ + KeyStoreHelper keyhelper; + + std::string keyStorePath = "./generateKeyPair/OpenHarmony.p12"; + char storePwd[] = "123456"; + std::string alias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + + int ret = keyhelper.WriteKeyStore(nullptr, keyStorePath, storePwd, alias, keyPwd); + EXPECT_EQ(ret, RET_FAILED); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateKeyPair/hap_sign_cmd_test.cpp b/hapsigntool_cpp/test/unittest/generateKeyPair/hap_sign_cmd_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3fd851130107563b2dbcbfcb13bad82670659e12 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateKeyPair/hap_sign_cmd_test.cpp @@ -0,0 +1,1607 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "localization_adapter.h" +#include "openssl/ssl.h" +#include "openssl/pem.h" +#include "openssl/err.h" +#include "p12_local.h" +#include "cmd_util.h" +#include "file_utils.h" +#include "params_run_tool.h" +#include "constant.h" +#include "params.h" +#include "params_trust_list.h" +#include "param_constants.h" + +namespace OHOS { +namespace SignatureTools { + +class HapSignToolCmdTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/* + * @tc.name: hap_sign_tool_test_053 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_053, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.txt"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_054 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_054, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_055 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_055, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + std::string issuerKeystoreFile = "./generateKeyPair/OpenHarmony.txt"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + (*params)["issuerKeystoreFile"] = issuerKeystoreFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: hap_sign_tool_test_056 +* @tc.desc: Generate an app debug certificate for entry checks. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_056, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/profile-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/profile-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunProfileCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_057 + * @tc.desc: Generates a key pair input check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_057, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 384; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunKeypair(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_058 + * @tc.desc: Generates a key pair input check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_058, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "RSA"; + int keySize = 384; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunKeypair(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_059 + * @tc.desc: Generates a key pair input check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_059, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 999; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunKeypair(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_060 + * @tc.desc: Generates a key pair input check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_060, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 384; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunKeypair(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: hap_sign_tool_test_061 + * @tc.desc: Test function of SignToolServiceImpl::RunCsr() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, run_csr_test_061, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = std::string("oh-app1-key-v1"); + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = std::string("C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"); + (*params)["keystoreFile"] = std::string("./generateKeyPair/OpenHarmony.p12"); + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunCsr(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_062 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_062, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string outFile = "./generateKeyPair/VerifyResult.json"; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunVerifyProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_063 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_063, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/signed-profile.txt"; + std::string outFile = "./generateKeyPair/VerifyResult.json"; + + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunVerifyProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_064 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_064, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/signed-profile.p7b"; + std::string outFile = "./generateKeyPair/VerifyResult.txt"; + + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunVerifyProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_065 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_065, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string outCertChain = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outProfile = "./generateKeyPair/app-profile.p7b"; + + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + + bool ret = ParamsRunTool::RunVerifyApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_066 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_066, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string outCertChain = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outProfile = "./generateKeyPair/app-profile.txt"; + + (*params)["inFile"] = inFile; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + + bool ret = ParamsRunTool::RunVerifyApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: hap_sign_tool_test_067 +* @tc.desc: Invoke the Generate generic certificate interface. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_067, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = " - validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsPathLen"; + char arg23[] = "0"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_068 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_068, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = " - validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsPathLen"; + char arg23[] = "1000000000000000000000000000000000000000000000000000000"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_069 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_069, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = " - validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-validity"; + char arg23[] = "558g22"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_070 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_070, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-validity"; + char arg23[] = "558g2hhhsss1111111111111111111111111111111111112"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_071 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_071, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_072 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_072, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_073 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_073, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_074 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_074, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + cmdUtil.Convert2Params(argv, argc, param); + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_075 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_075, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "FALSE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_076 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_076, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_077 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_077, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraints"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_078 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_078, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraints"; + char arg23[] = "FALSE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_079 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_079, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraints"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_080 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_080, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_081 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_081, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "FALSE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_082 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_082, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_083 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_083, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_084 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_084, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "FALSE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_085 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_085, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_086 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_086, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.p7b"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_087 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_087, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "abcd"; + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_088 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_088, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384withECDSA"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_089 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_089, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_090 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_090, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384acd"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_091 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_091, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.txt"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_092 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolCmdTest, hap_sign_tool_test_092, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string outCertChain = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outProfile = "./generateKeyPair/app-profile.p7b"; + std::string inform = "abcd"; + + (*params)["inFile"] = inFile; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + (*params)["inForm"] = inform; + + bool ret = ParamsRunTool::RunVerifyApp(params.get(), *api); + EXPECT_EQ(ret, false); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateKeyPair/hap_sign_tool_test.cpp b/hapsigntool_cpp/test/unittest/generateKeyPair/hap_sign_tool_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23472065ecd2449397f194d771e9b185419a6dd8 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateKeyPair/hap_sign_tool_test.cpp @@ -0,0 +1,1938 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "localization_adapter.h" +#include "openssl/ssl.h" +#include "openssl/pem.h" +#include "openssl/err.h" +#include "p12_local.h" +#include "cmd_util.h" +#include "file_utils.h" +#include "params_run_tool.h" +#include "constant.h" +#include "params.h" +#include "params_trust_list.h" +#include "param_constants.h" + +namespace OHOS { +namespace SignatureTools { + +class HapSignToolTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/* + * @tc.name: hap_sign_tool_test_001 + * @tc.desc: Generates a key pair input check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_001, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string keyAlg = "ECC"; + int keySize = 384; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunKeypair(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_002 + * @tc.desc: Generate a csr entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_002, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string signAlg = "SHA256withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/oh-app1-key-v1.csr"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunCsr(params.get(), *api); + EXPECT_EQ(ret, true); +} + +/* +* @tc.name: hap_sign_tool_test_003 +* @tc.desc: Generate the root certificate entry check. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_003, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "ECC"; + int keySize = 384; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, true); +} + +/* +* @tc.name: hap_sign_tool_test_004 +* @tc.desc: Generate an app debug certificate for entry checks. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_004, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/profile-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/profile-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunProfileCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_005 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_005, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_006 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_006, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/general.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_007 + * @tc.desc: Generate profile signature entry checks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_007, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string profileCertFile = "./generateKeyPair/profile-release1.pem"; + std::string inFile = "./generateKeyPair/profile.json"; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["profileCertFile"] = profileCertFile; + (*params)["inFile"] = inFile; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignProfile(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_008 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_008, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/signed-profile.p7b"; + std::string outFile = "./generateKeyPair/VerifyResult.json"; + + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunVerifyProfile(params.get(), *api); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_tool_test_009 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_009, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_010 + * @tc.desc: Generate a profile check-in check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_010, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string outCertChain = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outProfile = "./generateKeyPair/app-profile.p7b"; + + (*params)["inFile"] = inFile; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + + bool ret = ParamsRunTool::RunVerifyApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: hap_sign_tool_test_011 +* @tc.desc: Invoke the generate key pair interface. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_011, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-384"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + int argc = 14; + + ParamsSharedPtr param = std::make_shared(); + std::shared_ptr service_api = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + bool ret = ParamsRunTool::DispatchParams(param, *service_api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_012 + * @tc.desc: Invoke to generate hap signature interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_012, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signCode"; + char arg9[] = "1"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-appCertFile"; + char arg13[] = "./generateKeyPair/app-release1.pem"; + char arg14[] = "-profileFile"; + char arg15[] = "./generateKeyPair/signed-profile.p7b"; + char arg16[] = "-inFile"; + char arg17[] = "entry-default-unsigned-so.hap"; + char arg18[] = "-keystoreFile"; + char arg19[] = "./generateKeyPair/OpenHarmony.p12"; + char arg20[] = "-keystorePwd"; + char arg21[] = "123456"; + char arg22[] = "-outFile"; + char arg23[] = "./generateKeyPair/entry-default-signed-so.hap"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_013 + * @tc.desc: Invoke the generate profile signature interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_013, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "sign-profile"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA384withECDSA"; + char arg10[] = "-inFile"; + char arg11[] = "./generateKeyPair/profile.json"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/signed-profile.p7b"; + char arg18[] = "-profileCertFile"; + char arg19[] = "./generateKeyPair/signed-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19 }; + int argc = 20; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_014 + * @tc.desc: Invoke to generate hap check interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_014, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/entry-default-signed-so.hap"; + char arg4[] = "-outCertChain"; + char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg6[] = "-outProfile"; + char arg7[] = "./generateKeyPair/app-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 }; + int argc = 8; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_015 + * @tc.desc: Invoke the generate profile check interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_015, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/signed-profile.p7b"; + std::string outFile = "./generateKeyPair/VerifyResult.json"; + + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + + char arg0[] = ""; + char arg1[] = "verify-profile"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/signed-profile.p7b"; + char arg4[] = "-outFile"; + char arg5[] = "./generateKeyPair/VerifyResult.json"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5 }; + int argc = 6; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_tool_test_016 + * @tc.desc: Invoke the Generate root certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_016, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21 }; + int argc = 20; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_017 + * @tc.desc: Invoke the generate app certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_017, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_018 + * @tc.desc: Invoke the Generate profile certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_018, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/profile-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/profile-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, + arg21, arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_019 + * @tc.desc: Invoke the Generate generic certificate interface. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_019, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21 }; + int argc = 22; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_020 + * @tc.desc: Command error, does not invoke any check interface. + * @tc.type: FUNC + * @tc.require:(generate-parameter) + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_020, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char arg0[] = ""; + char arg1[] = "generate-parameter"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21 }; + int argc = 22; + + ParamsSharedPtr param = std::make_shared(); + CmdUtil cmdUtil; + + cmdUtil.Convert2Params(argv, argc, param); + + bool ret = ParamsRunTool::DispatchParams(param, *api.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_021 + * @tc.desc: Print help document. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_021, testing::ext::TestSize.Level1) +{ + ParamsRunTool::PrintHelp(); + bool ret = true; + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_tool_test_022 + * @tc.desc: Print version number. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_022, testing::ext::TestSize.Level1) +{ + ParamsRunTool::Version(); +} + +/* +* @tc.name: hap_sign_tool_test_023 +* @tc.desc: Generate the root certificate entry check. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_023, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + (*params)["keyAlias"] = keyAlias; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_024 + * @tc.desc: Generate the root certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_024, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "RSA"; + int keySize = 384; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_025 + * @tc.desc: Generate the root certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_025, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + int validity = 365; + std::string signAlg = "SHA385withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "ECC"; + int keySize = 999; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_026 + * @tc.desc: Generate the root certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_026, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + int validity = 365; + std::string signAlg = "SHA385withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "ECC"; + int keySize = 999; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + (*params)["issuer"] = issuer; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_028 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_028, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string issuerKeyAlias = "oh-app1-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string issuer = + "C=CNA,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + std::string signAlg = "SHA384withECDSA"; + 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; + bool keyUsageCritical = true; + char secret[] = "123456"; + int keysize = 384; + (*params)["keyAlias"] = keyAlias; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["keysize"] = keysize; + (*params)["subject"] = subject; + (*params)["issuer"] = issuer; + (*params)["signAlg"] = signAlg; + (*params)["keyStoreFile"] = keyStoreFile; + (*params)["keyUsage"] = keyUsage; + (*params)["basicConstraints"] = basicConstraints; + (*params)["basicConstraintsCritical"] = basicConstraintsCritical; + (*params)["basicConstraintsCa"] = basicConstraintsCa; + (*params)["keyUsageCritical"] = keyUsageCritical; + (*params)["keyPwd"] = secret; + (*params)["keystorePwd"] = secret; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_029 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_029, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_030 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_030, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_031 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_031, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.txt"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_032 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_032, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA385withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_033 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_033, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_034 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_034, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.txt"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_035 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_035, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.txt"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string profileSigned = "0"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: hap_sign_tool_test_040 +* @tc.desc: Generate the root certificate entry check. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_040, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + int validity = 365; + std::string signAlg = "SHA385withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "ECC"; + int keySize = 384; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: hap_sign_tool_test_041 +* @tc.desc: Generate the root certificate entry check. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_041, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "ECC"; + int keySize = 384; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_042 + * @tc.desc: Generate the root certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_042, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-root-ca-key-v1"; + char keyPwd[] = "123456"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/root-ca1.cer"; + std::string keyAlg = "ECC"; + int keySize = 384; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["subject"] = subject; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyAlg"] = keyAlg; + (*params)["keySize"] = keySize; + (*params)["validity"] = validity; + (*params)["issuer"] = issuer; + + bool ret = ParamsRunTool::RunCa(params.get(), *api); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_tool_test_043 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_043, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/general.cer"; + std::string keyUsage = "digitalSignature"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyUsage"] = keyUsage; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_044 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_044, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/general.cer"; + std::string keyUsage = "abcd"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyUsage"] = keyUsage; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_045 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_045, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/general.cer"; + std::string keyUsage = "digitalSignature"; + std::string extKeyUsage = "abcd"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyUsage"] = keyUsage; + (*params)["extKeyUsage"] = extKeyUsage; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_046 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_046, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA385withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/general.cer"; + std::string keyUsage = "digitalSignature"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyUsage"] = keyUsage; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_047 + * @tc.desc: Generate a universal certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_047, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-profile1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-profile-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.txt"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/general.cer"; + std::string keyUsage = "digitalSignature"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["keyUsage"] = keyUsage; + + bool ret = ParamsRunTool::RunCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_048 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_048, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_049 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_049, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA385withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_050 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_050, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_051 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_051, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "123456"; + std::string rootCaCertFile = "./generateKeyPair/root-ca1.cer"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + (*params)["rootCaCertFile"] = rootCaCertFile; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_052 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_052, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; + std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + int validity = 365; + std::string signAlg = "SHA384withECDSA"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app-release1.pem"; + std::string subCaCertFile = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outForm = "certChain"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["subject"] = subject; + (*params)["validity"] = validity; + (*params)["signAlg"] = signAlg; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["subCaCertFile"] = subCaCertFile; + (*params)["outForm"] = outForm; + + bool ret = ParamsRunTool::RunAppCert(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_053 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_053, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string profileSigned = "1"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_054 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_054, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384wA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string profileSigned = "1"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_055 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_055, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string outCertChain = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outProfile = "./generateKeyPair/app-profile.p7b"; + + (*params)["inFile"] = inFile; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + bool ret = ParamsRunTool::RunVerifyApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_tool_test_056 + * @tc.desc: Generate profile debugging certificate entry check. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignToolTest, hap_sign_tool_test_056, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string inFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string outCertChain = "./generateKeyPair/app-sign-srv-ca1.cer"; + std::string outProfile = "./generateKeyPair/app-profile.txt"; + + (*params)["inFile"] = inFile; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + bool ret = ParamsRunTool::RunVerifyApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateKeyPair/options_test.cpp b/hapsigntool_cpp/test/unittest/generateKeyPair/options_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..716cb04e8c9443366b45884327553003a9ae199d --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateKeyPair/options_test.cpp @@ -0,0 +1,1389 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "localization_adapter.h" +#include "openssl/ssl.h" +#include "openssl/pem.h" +#include "openssl/err.h" +#include "p12_local.h" +#include "cmd_util.h" +#include "file_utils.h" +#include "params_run_tool.h" +#include "constant.h" +#include "params.h" +#include "params_trust_list.h" +#include "param_constants.h" + +namespace OHOS { +namespace SignatureTools { + +class OptionsCmdTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/* + * @tc.name: Options_test_001 + * @tc.desc: get char* type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + char keyPwd[] = "123456"; + (*params)["keyPwd"] = keyPwd; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + char* strPrt = adaptePtr->options->GetChars(Options::KEY_RIGHTS); + EXPECT_NE(strPrt, nullptr); +} + +/* + * @tc.name: Options_test_002 + * @tc.desc: get string type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + (*params)["keyAlias"] = keyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + std::string strPrt = adaptePtr->options->GetString(Options::KEY_ALIAS); + + EXPECT_NE(strPrt, ""); +} + +/* + * @tc.name: Options_test_003 + * @tc.desc: get two-parameter string type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + std::string str = "test"; + (*params)["keyAlias"] = keyAlias; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + std::string strPrt = adaptePtr->options->GetString(Options::KEY_ALIAS, str); + + if (strPrt == keyAlias) { + EXPECT_EQ(strPrt, keyAlias); + } else if (strPrt == str) { + EXPECT_EQ(strPrt, str); + } else { + EXPECT_EQ(strPrt, keyAlias); + } +} + +/* + * @tc.name: Options_test_004 + * @tc.desc: get Int type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + int keySize = 256; + (*params)["keySize"] = keySize; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + int size = adaptePtr->options->GetInt(Options::KEY_SIZE); + + EXPECT_NE(size, 0); +} + +/* + * @tc.name: Options_test_005 + * @tc.desc: Check for equality. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + std::string issuerkeystoreFile = "./generateKeyPair/OpenHarmony.p12"; + + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerkeystoreFile"] = issuerkeystoreFile; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EXPECT_EQ(adaptePtr->options->Equals(Options::KEY_STORE_FILE, Options::ISSUER_KEY_STORE_FILE), false); +} + +/* + * @tc.name: Options_test_006 + * @tc.desc: Check for presence. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + std::string issuerkeystoreFile = "./generateKeyPair/OpenHarmony.p12"; + + (*params)["keystoreFile"] = keystoreFile; + (*params)["issuerkeystoreFile"] = issuerkeystoreFile; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EXPECT_EQ(adaptePtr->options->Required({ Options::KEY_STORE_FILE, Options::ISSUER_KEY_STORE_FILE }), false); +} +/* + * @tc.name: Options_test_007 + * @tc.desc: Check whether it is empty. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string str = ""; + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EXPECT_EQ(adaptePtr->options->IsEmpty(str), true); +} + +/* +* @tc.name: Options_test_008 +* @tc.desc: get string type value, and do type checking. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(OptionsCmdTest, Options_test_008, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + (*params)["keyAlias"]; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + std::string strPrt = adaptePtr->options->GetString(Options::KEY_ALIAS); + EXPECT_EQ(strPrt, ""); +} + +/* + * @tc.name: Options_test_009 + * @tc.desc: get two-parameter string type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_009, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + (*params)["keyAlias"] = keyAlias; + + std::string strPrt = params->GetString(Options::KEY_STORE_FILE); + EXPECT_EQ(strPrt, ""); +} + +/* + * @tc.name: Options_test_010 + * @tc.desc: get two-parameter string type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_010, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + std::string strPrt = params->GetString(Options::KEY_RIGHTS); + EXPECT_EQ(strPrt, ""); +} + +/* + * @tc.name: Options_test_011 + * @tc.desc: get two-parameter string type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_011, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string str = "abcd"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + std::string strPrt = params->GetString(Options::KEY_RIGHTS, str); + EXPECT_EQ(strPrt, str); +} + +/* + * @tc.name: Options_test_012 + * @tc.desc: get two-parameter string type value, and do type checking. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_012, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = ""; + char keyPwd[] = "123456"; + std::string str = "abcd"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + std::string strPrt = params->GetString(Options::KEY_ALIAS, str); + EXPECT_EQ(strPrt, str); +} + +/* + * @tc.name: Options_test_013 + * @tc.desc: Required. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_013, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string outForm = "cert"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["outForm"] = outForm; + (*params)["keystoreFile"] = keystoreFile; + params->Required({ Options::KEY_ALIAS, Options::SIGN_ALG, Options::OUT_FORM, Options::KEY_STORE_FILE }); +} + +/* + * @tc.name: Options_test_014 + * @tc.desc: Required. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_014, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + params->Required({ "" }); +} + +/* + * @tc.name: Options_test_015 + * @tc.desc: Required. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_015, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + + (*params)["inFile"] = keyAlias; + params->Required({ Options::KEY_ALIAS }); +} + +/* + * @tc.name: Options_test_016 + * @tc.desc: Required. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, Options_test_016, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + + (*params)["keyAlias"] = keyAlias; + params->Required({ Options::KEY_ALIAS }); +} + +/* + * @tc.name: cmd_util_test_001 + * @tc.desc: Check whether the algorithm is in ECC format. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, cmd_util_test_001, testing::ext::TestSize.Level1) +{ + std::string keyAlg = "ECC"; + EXPECT_EQ(CmdUtil::JudgeAlgType(keyAlg), true); +} + +/* + * @tc.name: cmd_util_test_002 + * @tc.desc: Check whether the algorithm length is 256 or 384. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, cmd_util_test_002, testing::ext::TestSize.Level1) +{ + int size = 256; + EXPECT_EQ(CmdUtil::JudgeSize(size), true); +} + +/* + * @tc.name: cmd_util_test_003 + * @tc.desc: Write command line arguments to map. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, cmd_util_test_003, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-384"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + int argc = 14; + + CmdUtil cmdUtil; + ParamsSharedPtr param = std::make_shared(); + bool ret = cmdUtil.Convert2Params(argv, argc, param); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: cmd_util_test_004 + * @tc.desc: Gets command line arguments. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, cmd_util_test_004, testing::ext::TestSize.Level1) +{ + char argv[][100] = { "generate-keypair", + "-keyAlias", "oh-app1-key-v1", + "-keyPwd", "123456", + "-keyAlg", "ECC", + "-keySize", "NIST-P-384", + "-keystoreFile", "./generateKeyPair/OpenHarmony.p12", + "-keystorePwd", "123456" + }; + + ParamsTrustList params_trust_list; + std::vector trustList = params_trust_list.GetTrustList(argv[1]); + if (trustList.empty()) { + bool ret = false; + EXPECT_EQ(ret, false); + } else { + bool ret = true; + EXPECT_EQ(ret, true); + } +} + +/* + * @tc.name: cmd_util_test_006 + * @tc.desc: Write command line arguments to map. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, cmd_util_test_006, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-384"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + int argc = 14; + + CmdUtil cmdUtil; + ParamsSharedPtr param = std::make_shared(); + bool ret = cmdUtil.Convert2Params(argv, argc, param); + + EXPECT_EQ(ret, true); +} +/* + * @tc.name: file_util_test_001 + * @tc.desc: Check whether the file format is p12 or jks. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, file_util_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + (*params)["keystoreFile"] = keystoreFile; + + std::unique_ptr adaptePtr = std::make_unique(params.get()); + EXPECT_EQ(FileUtils::ValidFileType(adaptePtr->options->GetString(Options::KEY_STORE_FILE), + { "p12", "jks" }), true); +} + +/* +* @tc.name: params_run_test_061 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(OptionsCmdTest, params_run_test_061, testing::ext::TestSize.Level1) +{ + std::string str = ""; + bool ret = CmdUtil::VerifyTypes(str); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_068 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_068, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "abcd"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_069 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_069, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string inform = "abcd"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inform; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_070 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_070, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384w"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = ""; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string inform = "elf"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inform; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_071 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_071, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384w"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.txt"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string profileSigned = "1"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_072 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_072, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384w"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.txt"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string profileSigned = "0"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_073 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_073, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384w"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_074 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_074, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_075 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_075, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_076 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_076, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_077 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_077, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_078 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_078, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: params_run_test_104 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(OptionsCmdTest, params_run_test_104, testing::ext::TestSize.Level1) +{ + std::string str = "clientAuthentication"; + bool ret = CmdUtil::VerifyType(str); + + EXPECT_EQ(ret, true); +} + +/* +* @tc.name: params_run_test_105 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(OptionsCmdTest, params_run_test_105, testing::ext::TestSize.Level1) +{ + std::string supportTypes = "abc,cba"; + std::string inputtype = "abc"; + bool ret = CmdUtil::VerifyType(inputtype, supportTypes); + + EXPECT_EQ(ret, true); +} + +/* +* @tc.name: params_run_test_106 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(OptionsCmdTest, params_run_test_106, testing::ext::TestSize.Level1) +{ + std::string supportTypes = "abc,cba"; + std::string inputtype = "cba"; + bool ret = CmdUtil::VerifyType(inputtype, supportTypes); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: params_run_test_108 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_108, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "./generateKeyPair/entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_109 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_109, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "./generateKeyPair/entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_110 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_110, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_111 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_111, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_112 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_112, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_113 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_113, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = ""; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = ""; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = ""; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = ""; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_114 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_114, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/signed-profile.p7b"; + std::string inFile = "./generateKeyPair/entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string inForm = "abcd"; + std::string profileSigned = "1"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_115 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_115, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string signCode = "1"; + std::string signAlg = "SHA384withECDSA"; + std::string appCertFile = "./generateKeyPair/app-release1.pem"; + std::string profileFile = "./generateKeyPair/profile.json"; + std::string inFile = "./generateKeyPair/entry-default-unsigned-so.hap"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/entry-default-signed-so.hap"; + std::string inForm = "abcd"; + std::string profileSigned = "0"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["signCode"] = signCode; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["profileSigned"] = profileSigned; + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_run_test_116 + * @tc.desc: The hap signature entry check is generated. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_run_test_116, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string keyAlias = "oh-app1-key-v1"; + char keyPwd[] = "123456"; + std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuerKeyAlias = "abcd"; + std::string subject = "abcd"; + std::string signAlg = "SHA256withECDSA"; + std::string outForm = "cert"; + std::string keystoreFile = "./generateKeyPair/OpenHarmony.p12"; + char keystorePwd[] = "123456"; + std::string outFile = "./generateKeyPair/app1.txt"; + + (*params)["keyAlias"] = keyAlias; + (*params)["keyPwd"] = keyPwd; + (*params)["issuer"] = issuer; + (*params)["issuerKeyAlias"] = issuerKeyAlias; + (*params)["signAlg"] = signAlg; + (*params)["subject"] = subject; + (*params)["outForm"] = outForm; + (*params)["keystoreFile"] = keystoreFile; + (*params)["keystorePwd"] = keystorePwd; + (*params)["outFile"] = outFile; + + bool ret = ParamsRunTool::CheckEndCertArguments(*params); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: params_test_001 + * @tc.desc: Set the first parameter of the command. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_test_001, testing::ext::TestSize.Level1) +{ + char argv[][100] = { "generate-keypair", + "-keyAlias", "oh-app1-key-v1", + "-keyPwd", "123456", + "-keyAlg", "ECC", + "-keySize", "NIST-P-384", + "-keystoreFile", "./generateKeyPair/OpenHarmony.p12", + "-keystorePwd", "123456" + }; + + ParamsSharedPtr param = std::make_shared(); + param->SetMethod(argv[1]); +} + +/* + * @tc.name: params_test_002 + * @tc.desc: Remove the white space. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_test_002, testing::ext::TestSize.Level1) +{ + std::string str = " 123456 "; + std::string params = StringUtils::Trim(str); + if (params == "123456") { + bool ret = true; + EXPECT_EQ(ret, true); + } else { + bool ret = false; + EXPECT_EQ(ret, false); + } +} + +/* + * @tc.name: params_test_003 + * @tc.desc: Gets the first command line argument. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_test_003, testing::ext::TestSize.Level1) +{ + char argv[][100] = { "generate-keypair", + "-keyAlias", "oh-app1-key-v1", + "-keyPwd", "123456", + "-keyAlg", "ECC", + "-keySize", "NIST-P-384", + "-keystoreFile", "./generateKeyPair/OpenHarmony.p12", + "-keystorePwd", "123456" + }; + + ParamsSharedPtr param = std::make_shared(); + param->SetMethod(argv[1]); + + if (param->GetMethod().empty()) { + bool ret = false; + EXPECT_EQ(ret, false); + } else { + bool ret = true; + EXPECT_EQ(ret, true); + } +} + +/* + * @tc.name: params_test_004 + * @tc.desc: Gets the first command line argument. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_test_004, testing::ext::TestSize.Level1) +{ + std::string signatureAlgorithm = ParamConstants::HAP_SIG_ALGORITHM_SHA384_ECDSA; + SignatureAlgorithmHelper out; + bool ret = Params::GetSignatureAlgorithm(signatureAlgorithm, out); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: params_test_005 + * @tc.desc: Gets the first command line argument. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(OptionsCmdTest, params_test_005, testing::ext::TestSize.Level1) +{ + std::string signatureAlgorithm = "123456"; + SignatureAlgorithmHelper out; + bool ret = Params::GetSignatureAlgorithm(signatureAlgorithm, out); + EXPECT_EQ(ret, false); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateKeyPair/process_cmd_expansion_test.cpp b/hapsigntool_cpp/test/unittest/generateKeyPair/process_cmd_expansion_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbff252a20d8e916314acadd560c2fab471ab12f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateKeyPair/process_cmd_expansion_test.cpp @@ -0,0 +1,964 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "localization_adapter.h" +#include "openssl/ssl.h" +#include "openssl/pem.h" +#include "openssl/err.h" +#include "p12_local.h" +#include "cmd_util.h" +#include "file_utils.h" +#include "params_run_tool.h" +#include "constant.h" +#include "params.h" +#include "params_trust_list.h" +#include "param_constants.h" + +namespace OHOS { +namespace SignatureTools { + +class ProcessCmdExpansionTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + + +/* + * @tc.name: processcmd_test_091 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_091, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_092 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_092, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_093 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_093, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-profile"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA384withECDSA"; + char arg10[] = "-inFile"; + char arg11[] = "./abcd/profile11.json"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/signed-profile.p7b"; + char arg18[] = "-profileCertFile"; + char arg19[] = "./generateKeyPair/signed-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19 }; + int argc = 20; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_094 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_094, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_095 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_095, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_096 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_096, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "abc"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_097 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_097, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-inFile"; + char arg3[] = "./generateKeyPair/entry-default-signed-so.hap"; + char arg4[] = "-outCertChain"; + char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg6[] = "-outProfile"; + char arg7[] = "./generateKeyPair/app-profile.p7b"; + char arg8[] = "-inForm"; + char arg9[] = "abc"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; + int argc = 10; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_098 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_098, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "abcd"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_099 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_099, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "abcd"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_100 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_100, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "cert"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_101 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_101, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "certChain"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_103 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_103, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_104 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_104, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 22; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_105 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_105, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA256withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_106 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_106, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_107 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_107, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "abcd"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_108 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_108, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-signAlg"; + char arg3[] = "SHA384withECDSA"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_109 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_109, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-signAlg"; + char arg3[] = "SHA384withECDSA"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_110 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_110, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "abcd"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_111 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_111, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-profile-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-app-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/app-release1.pem"; + char arg22[] = "-subCaCertFile"; + char arg23[] = "./generateKeyPair/app-sign-srv-ca1.cer"; + char arg24[] = "-outForm"; + char arg25[] = "abcd"; + char arg26[] = "-rootCaCertFile"; + char arg27[] = "./generateKeyPair/root-ca1.cer"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, + arg22, arg23, arg24, arg25, arg26, arg27 }; + int argc = 28; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_112 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_112, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-profile"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "remoteSign"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA384withECDSA"; + char arg10[] = "-inFile"; + char arg11[] = "./generateKeyPair/profile.json"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/signed-profile.p7b"; + char arg18[] = "-profileCertFile"; + char arg19[] = "./generateKeyPair/signed-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19 }; + int argc = 20; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_113 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_113, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-profile"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA384withECDSA"; + char arg10[] = "-inFile"; + char arg11[] = "./generateKeyPair/profile.json"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/signed-profile.p7b"; + char arg18[] = "-profileCertFile"; + char arg19[] = "./generateKeyPair/signed-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19 }; + int argc = 18; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_114 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdExpansionTest, processcmd_test_114, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-profile"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-mode"; + char arg7[] = "localSign"; + char arg8[] = "-signAlg"; + char arg9[] = "SHA384withECDSA"; + char arg10[] = "-inFile"; + char arg11[] = "./generateKeyPair/profile.json"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123k456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/signed-profile.p7b"; + char arg18[] = "-profileCertFile"; + char arg19[] = "./generateKeyPair/signed-profile.p7b"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19 }; + int argc = 20; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/generateKeyPair/process_cmd_test.cpp b/hapsigntool_cpp/test/unittest/generateKeyPair/process_cmd_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..689c61dd557b238055ada20e28fbf674bf541bdd --- /dev/null +++ b/hapsigntool_cpp/test/unittest/generateKeyPair/process_cmd_test.cpp @@ -0,0 +1,1882 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "signature_tools_log.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "localization_adapter.h" +#include "openssl/ssl.h" +#include "openssl/pem.h" +#include "openssl/err.h" +#include "p12_local.h" +#include "cmd_util.h" +#include "file_utils.h" +#include "params_run_tool.h" +#include "constant.h" +#include "params.h" +#include "params_trust_list.h" +#include "param_constants.h" + +namespace OHOS { +namespace SignatureTools { + +class ProcessCmdTest : public testing::Test { +public: + static void SetUpTestCase() + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/* + * @tc.name: processcmd_test_001 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_001, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-384"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + + int argc = 14; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_002 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_002, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = ""; + char* argv[] = { arg0, arg1 }; + + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_003 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_003, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "-h"; + char* argv[] = { arg0, arg1 }; + + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_004 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_004, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "-v"; + char* argv[] = { arg0, arg1 }; + + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_005 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_005, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = ""; + char* argv[] = { arg0, arg1, arg2, arg3 }; + + int argc = 4; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_006 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_006, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = ""; + char arg3[] = ""; + char* argv[] = { arg0, arg1, arg2, arg3 }; + + int argc = 4; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_008 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_008, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-385"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + + int argc = 14; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_012 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_012, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-256"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, + arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + + int argc = 14; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_013 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_013, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-257"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + + int argc = 14; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_020 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_020, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-257"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char arg14[] = "-extKeyUsageCritical"; + char arg15[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, + arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15 }; + + int argc = 16; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_028 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_028, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_029 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_029, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_030 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_030, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_031 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_031, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_032 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_032, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_033 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_033, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_034 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_034, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraints"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_035 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_035, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraints"; + char arg23[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_036 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_036, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraints"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_037 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_037, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_038 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_038, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_039 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_039, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_040 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_040, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_041 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_041, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_042 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_042, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-ca"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-root-ca-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-subject"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + char arg8[] = "-validity"; + char arg9[] = "365"; + char arg10[] = "-signAlg"; + char arg11[] = "SHA384withECDSA"; + char arg12[] = "-keystoreFile"; + char arg13[] = "./generateKeyPair/OpenHarmony.p12"; + char arg14[] = "-keystorePwd"; + char arg15[] = "123456"; + char arg16[] = "-outFile"; + char arg17[] = "./generateKeyPair/root-ca1.cer"; + char arg18[] = "-keyAlg"; + char arg19[] = "ECC"; + char arg20[] = "-keySize"; + char arg21[] = "NIST-P-384"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_043 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_043, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyPwd"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22 }; + int argc = 23; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_044 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_044, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-256"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + int argc = 14; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_045 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_045, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "/mnt/d/file/0613test/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "/mnt/d/file/0613test/general.cer"; + char arg22[] = "-basicConstraintsPathLen"; + char arg23[] = "0"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_046 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_046, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_047 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_047, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_048 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_048, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_049 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_049, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "0"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_050 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_050, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "false"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_051 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_051, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "FALSE"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_052 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_052, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-profileSigned"; + char arg3[] = "abcd"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_053 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_053, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-256"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./aabc123/OpenHarmony.p12"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + int argc = 14; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_054 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_054, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-keypair"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-app1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-keyAlg"; + char arg7[] = "ECC"; + char arg8[] = "-keySize"; + char arg9[] = "NIST-P-256"; + char arg10[] = "-keystoreFile"; + char arg11[] = "./generateKeyPair"; + char arg12[] = "-keystorePwd"; + char arg13[] = "123456"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 }; + int argc = 14; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_055 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_055, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-signAlg"; + char arg3[] = "abcd"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_056 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_056, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "sign-app"; + char arg2[] = "-signAlg"; + char arg3[] = "SHA384withECDSA"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_057 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_057, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "verify-app"; + char arg2[] = "-inForm"; + char arg3[] = "abcd"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_058 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_058, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char arg2[] = "-outForm"; + char arg3[] = "abcd"; + char* argv[] = { arg0, arg1, arg2, arg3 }; + int argc = 4; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* +* @tc.name: processcmd_test_059 +* @tc.desc: main function entry function. +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(ProcessCmdTest, processcmd_test_059, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-app-cert"; + char* argv[] = { arg0, arg1 }; + int argc = 2; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_063 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_063, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "-h"; + char* argv[] = { arg0, arg1 }; + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_064 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_064, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "-help"; + char* argv[] = { arg0, arg1 }; + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_065 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_065, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "-v"; + char* argv[] = { arg0, arg1 }; + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_066 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_066, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "-version"; + char* argv[] = { arg0, arg1 }; + int argc = 2; + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_067 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_067, testing::ext::TestSize.Level1) +{ + bool ret = ParamsRunTool::ProcessCmd(nullptr, 5); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: processcmd_test_079 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_079, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_080 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_080, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-keyUsageCritical"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_081 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_081, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_082 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_082, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_083 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_083, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-extKeyUsageCritical"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_084 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_084, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraints"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_085 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_085, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraints"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_086 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_086, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraints"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_087 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_087, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "true"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_088 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_088, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "TRUE"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_089 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_089, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCritical"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: processcmd_test_090 + * @tc.desc: main function entry function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ProcessCmdTest, processcmd_test_090, testing::ext::TestSize.Level1) +{ + char arg0[] = ""; + char arg1[] = "generate-cert"; + char arg2[] = "-keyAlias"; + char arg3[] = "oh-profile1-key-v1"; + char arg4[] = "-keyPwd"; + char arg5[] = "123456"; + char arg6[] = "-issuer"; + char arg7[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + char arg8[] = "-issuerKeyAlias"; + char arg9[] = "oh-profile-sign-srv-ca-key-v1"; + char arg10[] = "-subject"; + char arg11[] = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + char arg12[] = "-validity"; + char arg13[] = "365"; + char arg14[] = "-signAlg"; + char arg15[] = "SHA384withECDSA"; + char arg16[] = "-keystoreFile"; + char arg17[] = "./generateKeyPair/OpenHarmony.p12"; + char arg18[] = "-keystorePwd"; + char arg19[] = "123456"; + char arg20[] = "-outFile"; + char arg21[] = "./generateKeyPair/general.cer"; + char arg22[] = "-basicConstraintsCa"; + char arg23[] = "1"; + char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, + arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23 }; + int argc = 24; + + bool ret = ParamsRunTool::ProcessCmd(argv, argc); + + EXPECT_EQ(ret, false); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/hapSign/hap_openssl_utils_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/hap_openssl_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1fdc095ff433edc106e901ef3844fc4fb5ac84e6 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hap_openssl_utils_test.cpp @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "hap_openssl_utils_test.h" +#include "params_run_tool.h" +#include "sign_hap.h" +#include "sign_provider.h" +#include "sign_tool_service_impl.h" +namespace OHOS { +namespace SignatureTools { +/* + * @tc.name: hap_openssl_utils_test_001 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_001, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + DigestParameter parameter; + + bool ret = VerifyHapOpensslUtils::DigestInit(parameter); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_002, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + DigestParameter parameter; + parameter.md = EVP_sha256(); + bool ret = VerifyHapOpensslUtils::DigestInit(parameter); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_003, testing::ext::TestSize.Level1) +{ + DigestParameter parameter; + parameter.md = EVP_sha256(); + const unsigned char content[] = "123"; + int32_t len = 5; + bool ret = VerifyHapOpensslUtils::DigestUpdate(parameter, content, len); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_004, testing::ext::TestSize.Level1) +{ + DigestParameter parameter; + parameter.md = EVP_sha256(); + int32_t len = 5; + bool ret = VerifyHapOpensslUtils::DigestUpdate(parameter, nullptr, len); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_005, testing::ext::TestSize.Level1) +{ + DigestParameter parameter; + unsigned char dig[EVP_MAX_MD_SIZE]; + int32_t ret = VerifyHapOpensslUtils::GetDigest(parameter, dig); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_006, testing::ext::TestSize.Level1) +{ + DigestParameter parameter; + parameter.md = EVP_sha256(); + ByteBuffer chunk; + std::vector optionalBlocks; + unsigned char out[EVP_MAX_MD_SIZE]; + int32_t ret = VerifyHapOpensslUtils::GetDigest(chunk, optionalBlocks, parameter, out); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_007, testing::ext::TestSize.Level1) +{ + DigestParameter parameter; + DigestParameter parameter_test(parameter); + parameter_test = parameter; + DigestParameter* parameter_ptr = ¶meter; + *parameter_ptr = parameter; + ByteBuffer chunk; + std::vector optionalBlocks; + unsigned char out[EVP_MAX_MD_SIZE]; + int32_t ret = VerifyHapOpensslUtils::GetDigest(chunk, optionalBlocks, parameter, out); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_008, testing::ext::TestSize.Level1) +{ + int32_t digId = VerifyHapOpensslUtils::GetDigestAlgorithmId(ALGORITHM_SHA384_WITH_ECDSA); + EXPECT_EQ(digId, NID_sha384); + digId = VerifyHapOpensslUtils::GetDigestAlgorithmId(ALGORITHM_SHA512_WITH_ECDSA); + EXPECT_EQ(digId, NID_sha512); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_009, testing::ext::TestSize.Level1) +{ + CertChain signCertChain; + signCertChain.push_back(nullptr); + std::vector SignatureVec; + bool ret = VerifyHapOpensslUtils::GetSignatures(signCertChain, SignatureVec); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_010, testing::ext::TestSize.Level1) +{ + CertChain signCertChain; + signCertChain.push_back(nullptr); + std::vector SignatureVec; + bool ret = VerifyHapOpensslUtils::GetPublickeys(signCertChain, SignatureVec); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_011, testing::ext::TestSize.Level1) +{ + CertChain signCertChain; + X509* t = X509_new(); + signCertChain.push_back(t); + std::vector SignatureVec; + bool ret = VerifyHapOpensslUtils::GetPublickeys(signCertChain, SignatureVec); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_012, testing::ext::TestSize.Level1) +{ + Pkcs7Context pkcs7Context; + bool ret = VerifyHapOpensslUtils::VerifyPkcs7(pkcs7Context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_013, testing::ext::TestSize.Level1) +{ + Pkcs7Context pkcs7Context; + pkcs7Context.p7 = PKCS7_new(); + PKCS7_set_type(pkcs7Context.p7, NID_pkcs7_signed); + PKCS7_content_new(pkcs7Context.p7, NID_pkcs7_data); + bool ret = VerifyHapOpensslUtils::VerifyPkcs7(pkcs7Context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_015, testing::ext::TestSize.Level1) +{ + Pkcs7Context pkcs7Context; + pkcs7Context.p7 = PKCS7_new(); + PKCS7_set_type(pkcs7Context.p7, NID_pkcs7_signed); + PKCS7_content_new(pkcs7Context.p7, NID_pkcs7_data); + bool ret = VerifyHapOpensslUtils::VerifyPkcs7(pkcs7Context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_016, testing::ext::TestSize.Level1) +{ + Pkcs7Context pkcs7Context; + pkcs7Context.p7 = PKCS7_new(); + PKCS7_set_type(pkcs7Context.p7, NID_pkcs7_data); + bool ret = VerifyHapOpensslUtils::VerifyPkcs7(pkcs7Context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_017, testing::ext::TestSize.Level1) +{ + Pkcs7Context pkcs7Context; + pkcs7Context.p7 = PKCS7_new(); + PKCS7_set_type(pkcs7Context.p7, NID_pkcs7_signed); + bool ret = VerifyHapOpensslUtils::VerifyPkcs7(pkcs7Context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_018, testing::ext::TestSize.Level1) +{ + PKCS7* p7 = nullptr; + Pkcs7Context pkcs7Context; + bool ret = VerifyHapOpensslUtils::GetCertChains(p7, pkcs7Context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_019, testing::ext::TestSize.Level1) +{ + Pkcs7Context pkcs7Context; + pkcs7Context.p7 = PKCS7_new(); + PKCS7_set_type(pkcs7Context.p7, NID_pkcs7_signed); + PKCS7_content_new(pkcs7Context.p7, NID_pkcs7_data); + PKCS7* pkcsBak = pkcs7Context.p7; + bool ret = VerifyHapOpensslUtils::GetCertChains(pkcsBak, pkcs7Context); + EXPECT_EQ(ret, false); +} +/* + * @tc.name: hap_openssl_utils_test_002 + * @tc.desc: Verify Hap Openssl Utils. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapOpensslUtilsTest, hap_openssl_utils_test_020, testing::ext::TestSize.Level1) +{ + CertChain signCertChain; + signCertChain.push_back(nullptr); + std::vector SignatureVec; + bool ret = VerifyHapOpensslUtils::GetSignatures(signCertChain, SignatureVec); + EXPECT_EQ(ret, false); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/hapSign/hap_openssl_utils_test.h b/hapsigntool_cpp/test/unittest/hapSign/hap_openssl_utils_test.h new file mode 100644 index 0000000000000000000000000000000000000000..0b460b764e62e5489b07596e06a3a9645f47d73e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hap_openssl_utils_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_HAP_SIGN_TEST_H +#define OHOS_HAP_SIGN_TEST_H +#include "openssl/err.h" +#include "openssl/pem.h" +#include "openssl/ssl.h" +#include "sign_tool_service_impl.h" +#include "signature_tools_log.h" +#include "verify_hap_openssl_utils.h" +#include + +namespace OHOS { +namespace SignatureTools { +class HapOpensslUtilsTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; +} // namespace SignatureTools +} // namespace OHOS + +#endif // OHOS_HAP_SIGN_TEST_H \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/hapSign/hap_sign_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/hap_sign_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5bc8e6ef3f1e64951a83f12188dbb846f4b1f3f3 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hap_sign_test.cpp @@ -0,0 +1,1938 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "params_run_tool.h" +#include "local_sign_provider.h" +#include "sign_hap.h" +#include "sign_provider.h" +#include "sign_tool_service_impl.h" +#include "remote_sign_provider.h" +#include "hap_sign_test.h" +#include + +namespace OHOS { +namespace SignatureTools { + +void GenUnvaildUnSignHap(const std::string& path) +{ + std::ofstream outfile(path); + if (!outfile) { + SIGNATURE_TOOLS_LOGE("Unable to open file: %s", path.c_str()); + return; + } + outfile << "Hello, this is a Unvaild un sign Hap.\n"; + outfile.flush(); + outfile.close(); + return; +} + +void HapSignTest::SetUpTestCase(void) +{ + GenUnvaildUnSignHap("./hapSign/phone-default-unsigned"); + GenUnvaildUnSignHap("./hapSign/nohap.hap"); + + (void)rename("./hapSign/phone-default-unsigned-test.txt", "./hapSign/phone-default-unsigned-test.hap"); + (void)rename("./hapSign/phone-default-unsigned.txt", "./hapSign/phone-default-unsigned.hap"); + (void)rename("./hapSign/unsigned_with_cd_and_eocd.txt", "./hapSign/unsigned_with_cd_and_eocd.hap"); + (void)rename("./hapSign/unsigned_with_eocd.txt", "./hapSign/unsigned_with_eocd.hap"); + sync(); +} + +void HapSignTest::TearDownTestCase(void) +{ +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_001, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, true); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_002, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, true); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_003, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "0"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, false); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_004, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, true); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_005, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + signProvider->CheckInputCertMatchWithProfile(nullptr, nullptr); + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_test_006 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_006, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "3"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, false); +} + +/* + * @tc.name: hap_sign_test_007 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_007, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + (*params)["signCode"] = std::string("3"); + bool retParamT = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParamT, false); + + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = std::string(""); + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_008, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_009, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "0"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_010, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_011, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + ContentDigestAlgorithm alg_tmp; + ContentDigestAlgorithm alg_1 = ContentDigestAlgorithm::SHA256; + ContentDigestAlgorithm* alg_2 = &alg_1; + *alg_2 = alg_1; + alg_tmp = alg_1; + ContentDigestAlgorithm alg = ContentDigestAlgorithm::SHA256; + std::string algname = alg.GetDigestAlgorithm(); + EXPECT_EQ(algname, std::string("SHA-256")); + int size = alg.GetDigestOutputByteSize(); + EXPECT_EQ(size, 256 / 8); + + ContentDigestAlgorithm alg_384 = ContentDigestAlgorithm::SHA384; + std::string algname_384 = alg_384.GetDigestAlgorithm(); + EXPECT_EQ(algname_384, std::string("SHA-384")); + int size384 = alg_384.GetDigestOutputByteSize(); + EXPECT_EQ(size384, 384 / 8); + + ContentDigestAlgorithm alg_512 = ContentDigestAlgorithm::SHA512; + alg_512 = ContentDigestAlgorithm::SHA512; + std::string algname_512 = alg_512.GetDigestAlgorithm(); + EXPECT_EQ(algname_512, std::string("SHA-512")); + int size512 = alg_512.GetDigestOutputByteSize(); + EXPECT_EQ(size512, 512 / 8); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_012, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + ByteBuffer bf1("123456789", 9); + ByteBuffer bf2("123456789", 9); + ByteBuffer bf3("123456789", 9); + ByteBuffer bf4("123456789", 9); + ByteBufferDataSource ds1(bf1); + ByteBufferDataSource ds2(bf2); + ByteBufferDataSource ds3(bf3); + + DataSource* contents[] = {&ds1, &ds2, &ds3}; + int32_t len = 3; + + std::vector optionalBlocks; + optionalBlocks.push_back({HapUtils::HAP_PROFILE_BLOCK_ID, bf4}); + ByteBuffer dig_context; + + SignatureAlgorithm algo = SignatureAlgorithm::ALGORITHM_SHA256_WITH_ECDSA; + int32_t nId = VerifyHapOpensslUtils::GetDigestAlgorithmId(algo); + DigestParameter digestParam = HapSignerBlockUtils::GetDigestParameter(nId); + + bool ret = SignHap::ComputeDigests(digestParam, contents, len, optionalBlocks, dig_context); + EXPECT_EQ(ret, true); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_013, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release-nohave.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_014, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/nohave.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_015, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release-.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + signProvider->CheckParams(params.get()); + + signProvider->GetCrl(); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_016, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "/d/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_017, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-unsigned.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_018, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withEA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + std::optional crl = signProvider->GetCrl(); + EXPECT_EQ(crl.has_value(), false); + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_019, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_020, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_021, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/nohap.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_022, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned_with_eocd.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_023, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_024, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteResign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_025, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_026, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + ByteBuffer bf1("123456789", 9); + ByteBuffer bf2("123456789", 9); + ByteBuffer bf3("123456789", 9); + ByteBuffer bf4("123456789", 9); + ByteBufferDataSource ds1(bf1); + ByteBufferDataSource ds2(bf2); + ByteBufferDataSource ds3(bf3); + + DataSource* contents[] = {&ds1, &ds2, &ds3}; + DataSource* contents_t[] = {nullptr, nullptr, nullptr}; + int32_t len = 3; + + std::vector optionalBlocks; + std::vector optionalBlockSTest; + optionalBlocks.push_back({HapUtils::HAP_PROFILE_BLOCK_ID, bf4}); + ByteBuffer dig_context; + + SignatureAlgorithm algo = SignatureAlgorithm::ALGORITHM_SHA256_WITH_ECDSA; + int32_t nId = VerifyHapOpensslUtils::GetDigestAlgorithmId(algo); + DigestParameter digestParam = HapSignerBlockUtils::GetDigestParameter(nId); + + SignerConfig config; + ByteBuffer result; + ByteBuffer result1; + bool ret1 = SignHap::Sign(contents, 2, config, optionalBlocks, result); + EXPECT_EQ(ret1, false); + + ret1 = SignHap::Sign(contents_t, 3, config, optionalBlocks, result1); + EXPECT_EQ(ret1, false); + + std::vector sig{SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE}; + config.SetSignatureAlgorithms(sig); + ret1 = SignHap::Sign(contents_t, 3, config, optionalBlocks, result1); + EXPECT_EQ(ret1, false); + bool ret = SignHap::ComputeDigests(digestParam, contents, len, optionalBlockSTest, dig_context); + ret = SignHap::ComputeDigests(digestParam, contents_t, len, optionalBlocks, dig_context); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_027, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_028, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_test_029, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256w"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = api->SignHap(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: get_options_test_001 + * @tc.desc: Test function of GetOptions() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, get_options_test_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr params = std::make_shared(); + std::string keyAlias = "oh-app1-key-v1"; + (*params)["keyAlias"] = keyAlias; + SignerConfig signerConfig; + signerConfig.SetOptions(params.get()); + EXPECT_EQ(params.get(), signerConfig.GetOptions()); +} + +/** + * @tc.name: get_certificates_test_001 + * @tc.desc: Test function of GetCertificates() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, get_certificates_test_001, testing::ext::TestSize.Level1) +{ + X509* newCert = X509_new(); + EXPECT_TRUE(X509_set_version(newCert, 2)); + SignerConfig signerConfig; + signerConfig.SetX509CRLs(nullptr); + signerConfig.GetX509CRLs(); + signerConfig.SetCertificates(nullptr); + signerConfig.GetCertificates(); + signerConfig.GetSignParamMap(); + STACK_OF(X509) *certs = sk_X509_new_null(); + sk_X509_push(certs, newCert); + signerConfig.SetCertificates(certs); + + EXPECT_NE(signerConfig.GetCertificates(), nullptr); +} + +/** + * @tc.name: get_X509_CRLs_test_001 + * @tc.desc: Test function of GetX509CRLs() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, get_X509_CRLs_test_001, testing::ext::TestSize.Level1) +{ + STACK_OF(X509_CRL)* x509CRLs = nullptr; + SignerConfig signerConfig; + signerConfig.SetX509CRLs(x509CRLs); + EXPECT_EQ(x509CRLs, signerConfig.GetX509CRLs()); +} + +/** + * @tc.name: get_X509_CRLs_test_001 + * @tc.desc: Test function of GetX509CRLs() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, get_X509_CRLs_test_002, testing::ext::TestSize.Level1) +{ + STACK_OF(X509_CRL)* x509CRLs = nullptr; + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256w"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned_with_cd_and_eocd.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + SignerConfig signerConfig; + signerConfig.SetOptions(params.get()); + + signerConfig.GetX509CRLs(); + STACK_OF(X509_CRL)* crls = sk_X509_CRL_new_null(); + signerConfig.SetX509CRLs(crls); + signerConfig.GetX509CRLs(); + + signerConfig.SetCertificates(nullptr); + signerConfig.SetX509CRLs(x509CRLs); + signerConfig.GetX509CRLs(); + + X509* newCert = X509_new(); + X509_set_version(newCert, 2); + signerConfig.SetCertificates((STACK_OF(X509)*)newCert); + signerConfig.GetX509CRLs(); + + signerConfig.GetSigner(); + signerConfig.SetX509CRLs(x509CRLs); + signerConfig.SetCertificates(nullptr); + signerConfig.GetCertificates(); + EXPECT_EQ(false, (signerConfig.GetX509CRLs() != nullptr)); +} + +/** + * @tc.name: get_compatible_version_test_001 + * @tc.desc: Test function of GetCompatibleVersion() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, get_compatible_version_test_001, testing::ext::TestSize.Level1) +{ + int n = 5; + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(n); + EXPECT_EQ(5, signerConfig.GetCompatibleVersion()); +} + +/** + * @tc.name: find_by_id_test_001 + * @tc.desc: Test function of FindById() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, find_by_id_test_001, testing::ext::TestSize.Level1) +{ + const SignatureAlgorithmHelper* tmp = SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::ECDSA_WITH_SHA256); + EXPECT_EQ(&(SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE), tmp); + const SignatureAlgorithmHelper* tmp1 = SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::ECDSA_WITH_SHA384); + EXPECT_EQ(&(SignatureAlgorithmHelper::ECDSA_WITH_SHA384_INSTANCE), tmp1); +} + +/** + * @tc.name: find_by_id_test_001 + * @tc.desc: Test function of FindById() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(HapSignTest, find_by_id_test_002, testing::ext::TestSize.Level1) +{ + SignatureAlgorithmHelper tmp1 = SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE; + SignatureAlgorithmHelper tmp3 = SignatureAlgorithmHelper::ECDSA_WITH_SHA384_INSTANCE; + SignatureAlgorithmHelper* tmp2 = &tmp1; + *tmp2 = tmp1; + tmp3 = tmp1; + const SignatureAlgorithmHelper* tmp = SignatureAlgorithmHelper::FindById(SignatureAlgorithmId::DSA_WITH_SHA512); + EXPECT_EQ(nullptr, tmp); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_001, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12"; + std::string compatibleVersion = "8"; + std::string signerPlugin = "/mnt/d/libRemoteSigner.so"; + std::string signServer = "/mnt/d/testcpuls/app-release1.pem"; + std::string username = "test"; + char userPwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + (*params)["onlineAuthMode"] = onlineAuthMode; + (*params)["compatibleVersion"] = compatibleVersion; + (*params)["signerPlugin"] = signerPlugin; + (*params)["signServer"] = signServer; + (*params)["username"] = username; + (*params)["userPwd"] = userPwd; + + (*params)["signCode"] = std::string("3"); + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_002, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + bool ret = signProvider->CheckInputCertMatchWithProfile(nullptr, nullptr); + EXPECT_EQ(ret, false); + + X509* cert = nullptr; + STACK_OF(X509)* sk_cert = sk_X509_new(nullptr); + BIO* certBio = BIO_new_file("./hapSign/app-release1.pem", "rb"); + if (certBio == nullptr) { + sk_X509_pop_free(sk_cert, X509_free); + EXPECT_NE(certBio, nullptr); + } + // 读取 + while (1) { + cert = PEM_read_bio_X509(certBio, NULL, NULL, NULL); + if (cert == nullptr) { + break; + } + sk_X509_push(sk_cert, cert); + } + BIO_free(certBio); + if (sk_X509_num(sk_cert) > 1) { + X509* first_cert = sk_X509_value(sk_cert, 0); + X509* second_cert = sk_X509_value(sk_cert, 1); + bool val = signProvider->CheckInputCertMatchWithProfile(first_cert, first_cert); + val = signProvider->CheckInputCertMatchWithProfile(first_cert, second_cert); + EXPECT_EQ(val, false); + } + sk_X509_pop_free(sk_cert, X509_free); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_003, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + CertTools::SetCertIssuerName(cert, BuildDN(issuername, issuerReq)); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_set_subject_name(cert, BuildDN(subjectname, issuerReq)); + + X509* cert1 = X509_new(); + X509_REQ* issuerReq1 = X509_REQ_new(); + std::string issuername1 = "C=wc,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + CertTools::SetCertIssuerName(cert1, BuildDN(issuername1, issuerReq1)); + + std::string subjectname1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_set_subject_name(cert1, BuildDN(subjectname1, issuerReq1)); + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + X509_REQ_free(issuerReq1); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_004, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + CertTools::SetCertIssuerName(cert, BuildDN(issuername, issuerReq)); + CertTools::SetCertSerialNum(cert); + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_set_subject_name(cert, BuildDN(subjectname, issuerReq)); + + X509* cert1 = X509_new(); + X509_REQ* issuerReq1 = X509_REQ_new(); + std::string issuername1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + CertTools::SetCertIssuerName(cert1, BuildDN(issuername1, issuerReq1)); + CertTools::SetCertSerialNum(cert1); + std::string subjectname1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_set_subject_name(cert1, BuildDN(subjectname1, issuerReq1)); + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + X509_REQ_free(issuerReq1); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_005, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12"; + std::string compatibleVersion = "8"; + std::string signerPlugin = "/mnt/d/libRemoteSigner.so"; + std::string signServer = "/mnt/d/testcpuls/app-release1.pem"; + std::string username = "test"; + char userPwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + (*params)["onlineAuthMode"] = onlineAuthMode; + (*params)["compatibleVersion"] = compatibleVersion; + (*params)["signerPlugin"] = signerPlugin; + (*params)["signServer"] = signServer; + (*params)["username"] = username; + (*params)["userPwd"] = userPwd; + + (*params)["signCode"] = std::string("3"); + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_006, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + std::string onlineAuthMode = "/mnt/d/testcpuls/OpenHarmony.p12"; + std::string compatibleVersion = "8"; + std::string signerPlugin = "/mnt/d/libRemoteSigner.so"; + std::string signServer = "/mnt/d/testcpuls/app-release1.pem"; + std::string username = "test"; + char userPwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + (*params)["onlineAuthMode"] = onlineAuthMode; + (*params)["compatibleVersion"] = compatibleVersion; + (*params)["signerPlugin"] = signerPlugin; + (*params)["signServer"] = signServer; + (*params)["username"] = username; + (*params)["userPwd"] = userPwd; + bool retParam = signProvider->CheckParams(params.get()); + EXPECT_EQ(retParam, true); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_007, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + CertTools::SetCertIssuerName(cert, BuildDN(issuername, issuerReq)); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + + X509_REQ* issuerReq1 = X509_REQ_new(); + std::string issuername1 = "C=wc,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + CertTools::SetCertIssuerName(cert1, BuildDN(issuername1, issuerReq1)); + + std::string subjectname1 = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + X509_REQ_free(issuerReq1); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_008, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* issName = BuildDN(issuername, issuerReq); + CertTools::SetCertIssuerName(cert, issName); + CertTools::SetCertIssuerName(cert1, issName); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + KeyStoreHelper stroe; + EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256); + EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256); + + X509_set_pubkey(cert, key1); + X509_set_pubkey(cert1, key2); + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + EVP_PKEY_free(key1); + EVP_PKEY_free(key2); + EXPECT_EQ(ret, false); +} +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_009, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* issName = BuildDN(issuername, issuerReq); + CertTools::SetCertIssuerName(cert, issName); + CertTools::SetCertIssuerName(cert1, issName); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + KeyStoreHelper stroe; + EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256); + EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256); + + X509_set_pubkey(cert, key1); + X509_set_pubkey(cert1, key2); + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, nullptr); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + EVP_PKEY_free(key1); + EVP_PKEY_free(key2); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_010, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* issName = BuildDN(issuername, issuerReq); + CertTools::SetCertIssuerName(cert, issName); + CertTools::SetCertIssuerName(cert1, issName); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + KeyStoreHelper stroe; + EVP_PKEY* key1 = stroe.GenerateKeyPair("ECC", 256); + + X509_set_pubkey(cert, key1); + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + EVP_PKEY_free(key1); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_011, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* issName = BuildDN(issuername, issuerReq); + CertTools::SetCertIssuerName(cert, issName); + CertTools::SetCertIssuerName(cert1, issName); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + KeyStoreHelper stroe; + EVP_PKEY* key2 = stroe.GenerateKeyPair("ECC", 256); + + X509_set_pubkey(cert1, key2); + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + EVP_PKEY_free(key2); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, remote_sign_provider_012, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + + X509* cert = X509_new(); + X509* cert1 = X509_new(); + X509_REQ* issuerReq = X509_REQ_new(); + std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* issName = BuildDN(issuername, issuerReq); + CertTools::SetCertIssuerName(cert, issName); + CertTools::SetCertIssuerName(cert1, issName); + + std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + X509_NAME* subName = BuildDN(subjectname, issuerReq); + X509_set_subject_name(cert, subName); + X509_set_subject_name(cert1, subName); + KeyStoreHelper stroe; + + bool ret = signProvider->CheckInputCertMatchWithProfile(cert1, cert); + X509_free(cert); + X509_free(cert1); + X509_REQ_free(issuerReq); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: remote_sign_provider_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapSignTest, hap_sign_error_001, testing::ext::TestSize.Level1) +{ + ByteBuffer bf1("123456789", 9); + ByteBuffer bf2("123456789", 9); + ByteBuffer bf3("123456789", 9); + ByteBuffer bf4(0x7FFFFFFF); + ByteBufferDataSource ds1(bf1); + ByteBufferDataSource ds2(bf2); + ByteBufferDataSource ds3(bf3); + DataSource* contents[] = {&ds1, &ds2, &ds3}; + std::vector optionalBlocks; + optionalBlocks.push_back({HapUtils::HAP_PROFILE_BLOCK_ID, bf4}); + std::shared_ptr params = std::make_shared(); + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "/mnt/d/testcpuls/app-release1.pem"; + std::string profileFile = "/mnt/d/testcpuls/signed-profile.p7b"; + std::string inFile = "/mnt/d/testcpuls/entry-default-unsigned-so.hap"; + std::string keystoreFile = "/mnt/d/testcpuls/OpenHarmony.p12"; + std::string outFile = "/mnt/d/testcpuls/entry-default-signed-so.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + SignerConfig config; + std::vector sig{SignatureAlgorithmHelper::ECDSA_WITH_SHA256_INSTANCE}; + config.SetSignatureAlgorithms(sig); + config.SetOptions(params.get()); + ByteBuffer result; + bool ret1 = SignHap::Sign(contents, 3, config, optionalBlocks, result); + EXPECT_EQ(ret1, false); +} +} // namespace SignatureTools +} // namespace OHOS diff --git a/hapsigntool_cpp/test/unittest/hapSign/hap_sign_test.h b/hapsigntool_cpp/test/unittest/hapSign/hap_sign_test.h new file mode 100644 index 0000000000000000000000000000000000000000..835b8450e637ba343171191393df2774574ec9eb --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hap_sign_test.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SIGNATURETOOLS_HAP_SIGN_TEST_H +#define SIGNATURETOOLS_HAP_SIGN_TEST_H +#include + +#include "localization_adapter.h" +#include "openssl/err.h" +#include "openssl/pem.h" +#include "openssl/ssl.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "signature_tools_log.h" + +namespace OHOS { +namespace SignatureTools { +class HapSignTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() {}; + void TearDown() {}; +}; +} // namespace SignatureTools +} // namespace OHOS + +#endif // SIGNATURETOOLS_HAP_SIGN_TEST_H \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/hapSign/hw_block_data_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/hw_block_data_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a88bf7dd565f539d32d45d815ff7dfa6c11c3352 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hw_block_data_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "hw_block_data.h" + +using namespace OHOS::SignatureTools; + +/* +* 测试套件,固定写法 +*/ +class HwBlockDataTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: GetBlockNum + * @tc.desc: Test function of HwBlockDataTest::GetBlockNum() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockDataTest, GetBlockNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(2, 0); + int32_t blockNum = api->GetBlockNum(); + EXPECT_EQ(blockNum, 2); +} + +/** + * @tc.name: GetBlockStart + * @tc.desc: Test function of HwBlockDataTest::GetBlockStart() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockDataTest, GetBlockStart, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(2, 0); + int32_t blockStart = api->GetBlockStart(); + EXPECT_EQ(blockStart, 0); +} + +/** + * @tc.name: SetBlockNum + * @tc.desc: Test function of HwBlockDataTest::SetBlockNum() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockDataTest, SetBlockNum, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(2, 0); + api->SetBlockNum(3); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: SetBlockStart + * @tc.desc: Test function of HwBlockDataTest::SetBlockStart() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockDataTest, SetBlockStart, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(2, 0); + api->SetBlockStart(1); + EXPECT_EQ(true, 1); +} diff --git a/hapsigntool_cpp/test/unittest/hapSign/hw_block_head_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/hw_block_head_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09f00d99bb2cea47f20913a8d307a0ddef67c145 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hw_block_head_test.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "hw_block_head.h" + +using namespace OHOS::SignatureTools; + +/* +* 测试套件,固定写法 +*/ +class HwBlockHeadTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: GetBlockHead + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockHeadTest, GetBlockHead, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::string blockHead = api->GetBlockHead(0, 0, 0, 29148868); + EXPECT_NE(blockHead.size(), 0); +} + +/** + * @tc.name: GetBlockHeadLittleEndian + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockHeadTest, GetBlockHeadLittleEndian, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + api->GetBlockHeadLittleEndian(0, 0, 0, 29148868); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getBlockHeadLittleEndian + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockHeadTest, getBlockHeadLittleEndian, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + api->GetBlockHeadLittleEndian(0, 0, 0, 29148868); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: GetBlockLen + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockHeadTest, GetBlockLen, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + int blockLen = api->GetBlockLen(); + EXPECT_EQ(blockLen, 8); +} + +/** + * @tc.name: GetElfBlockLen + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwBlockHeadTest, GetElfBlockLen, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + int elfBlockLen = api->GetElfBlockLen(); + EXPECT_EQ(elfBlockLen, 12); +} diff --git a/hapsigntool_cpp/test/unittest/hapSign/hw_sign_head_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/hw_sign_head_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d97d216427ff1901a1bc5f6aa910547d452fb8f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/hw_sign_head_test.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "hw_sign_head.h" + +using namespace OHOS::SignatureTools; + +/* +* 测试套件,固定写法 +*/ +class HwSignHeadTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: GetSignHead + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwSignHeadTest, GetSignHead, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::vector signHead = api->GetSignHead(5254); + EXPECT_EQ(signHead.size(), 32); +} + +/** + * @tc.name: getSignHeadLittleEndian + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(HwSignHeadTest, getSignHeadLittleEndian, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::vector signHeadLittleEndian = api->GetSignHeadLittleEndian(1024, 1); + EXPECT_EQ(signHeadLittleEndian.size(), 32); +} diff --git a/hapsigntool_cpp/test/unittest/hapSign/packets/phone-default-unsigned-test.txt b/hapsigntool_cpp/test/unittest/hapSign/packets/phone-default-unsigned-test.txt new file mode 100644 index 0000000000000000000000000000000000000000..417e4bf88c1c29f983171b731ba4bc88cbbe6ad2 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapSign/packets/phone-default-unsigned-test.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapSign/packets/phone-default-unsigned.txt b/hapsigntool_cpp/test/unittest/hapSign/packets/phone-default-unsigned.txt new file mode 100644 index 0000000000000000000000000000000000000000..417e4bf88c1c29f983171b731ba4bc88cbbe6ad2 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapSign/packets/phone-default-unsigned.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned-linux.txt b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned-linux.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b82db1b540acd6bacd821b3755d4981525b24d1 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned-linux.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned.txt b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned.txt new file mode 100644 index 0000000000000000000000000000000000000000..66b16d6dcb026164483a6433c0b29ca2d02da9f8 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned_with_cd_and_eocd.txt b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned_with_cd_and_eocd.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3b3d65c646a5bb69e096e37f897c7ed48c8a9e9 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned_with_cd_and_eocd.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned_with_eocd.txt b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned_with_eocd.txt new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapSign/packets/unsigned_with_eocd.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapSign/sign_bin_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/sign_bin_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d1830d800f35110531b2d70fa5e01831e9ec53b9 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/sign_bin_test.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "sign_bin.h" +#include "sign_provider.h" +#include "local_sign_provider.h" + +#define VERSION 9 +#define BYTE_NUMBER 32 + +namespace OHOS { +namespace SignatureTools { +void ConstructSignerConfig(SignerConfig& signerConfig, Options& options) +{ + signerConfig.SetCompatibleVersion(VERSION); + + std::map params; + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./hapSign/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./hapSign/signed.bin"; + params["profileFile"] = "./hapSign/app1-profile1.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./hapSign/ohtest.p12"; + params["inFile"] = "./hapSign/unsigned.bin"; + params["profileSigned"] = "1"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", BYTE_NUMBER); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + options.emplace("mode", std::string("localSign")); + char keyPwd[] = "123456"; + options.emplace("keyPwd", keyPwd); + options.emplace("outFile", std::string("./hapSign/signed.bin")); + options.emplace("keyAlias", std::string("oh-app1-key-v1")); + options.emplace("profileFile", std::string("./hapSign/app1-profile1.p7b")); + options.emplace("signAlg", std::string("SHA256withECDSA")); + char keystorePwd[] = "123456"; + options.emplace("keystorePwd", keystorePwd); + options.emplace("keystoreFile", std::string("./hapSign/ohtest.p12")); + options.emplace("appCertFile", std::string("./hapSign/app-release1.pem")); + options.emplace("inFile", std::string("./hapSign/unsigned.bin")); + signerConfig.SetOptions(&options); +} + +void ConstructSignParams(std::map& signParams) +{ + signParams["a"] = "4"; + signParams["appCertFile"] = "./hapSign/app-release1.pem"; + signParams["compatibleVersion"] = "9"; + signParams["inFile"] = "./hapSign/unsigned.bin"; + signParams["inForm"] = "bin"; + signParams["keyAlias"] = "oh-app1-key-v1"; + signParams["keyPwd"] = "123456"; + signParams["keystoreFile"] = "./hapSign/ohtest.p12"; + signParams["keystorePwd"] = "123456"; + signParams["outFile"] = "./hapSign/signed.bin"; + signParams["profileFile"] = "./hapSign/app1-profile1.p7b"; + signParams["profileSigned"] = "1"; + signParams["signAlg"] = "SHA256withECDSA"; + signParams["signCode"] = "1"; +} + +/* +* 测试套件,固定写法 +*/ +class SignBinTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + (void)rename("./hapSign/unsigned.txt", "./hapSign/unsigned.bin"); + }; + static void TearDownTestCase() + { + + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: GenerateFileDigest001 + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBinTest, GenerateFileDigest001, testing::ext::TestSize.Level1) +{ + // error algorithm, go to branch "get Signature Algorithm failed" + std::shared_ptr api = std::make_shared(); + std::vector generateFileDigest = api->GenerateFileDigest("./signed.bin", "SHA266"); + EXPECT_EQ(generateFileDigest.size(), 0); +} + +/** + * @tc.name: GenerateFileDigest002 + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBinTest, GenerateFileDigest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr api = std::make_shared(); + std::vector generateFileDigest = api->GenerateFileDigest("./signed.bin", "SHA384withECDSA"); + EXPECT_EQ(generateFileDigest.size(), 0); +} + +/** + * @tc.name: Sign001 + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBinTest, Sign001, testing::ext::TestSize.Level1) +{ + // go to branch "The block head data made failed" + std::shared_ptr api = std::make_shared(); + + // 1.construct SignerConfig + SignerConfig signerConfig; + Options options; + ConstructSignerConfig(signerConfig, options); + + // 2.construct signParams + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string compatibleVersion = "9"; + std::string inFile = "./hapSign/unvalid.bin"; + std::string inForm = "bin"; + std::string keyAlias = "oh-app1-key-v1"; + static char keyPwd[] = "123456"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + static char keystorePwd[] = "123456"; + std::string outFile = "./hapSign/signed.bin"; + std::string profileFile = "./hapSign/app1-profile1.p7b"; + std::string profileSigned = "1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string mode = "localSign"; + + std::map signParams; + signParams["a"] = "4"; + signParams["appCertFile"] = appCertFile; + signParams["compatibleVersion"] = compatibleVersion; + signParams["inFile"] = inFile; + signParams["inForm"] = inForm; + signParams["keyAlias"] = keyAlias; + signParams["keyPwd"] = keyPwd; + signParams["keystoreFile"] = keystoreFile; + signParams["keystorePwd"] = keystorePwd; + signParams["outFile"] = outFile; + signParams["profileFile"] = profileFile; + signParams["profileSigned"] = profileSigned; + signParams["signAlg"] = signAlg; + signParams["signCode"] = signCode; + signParams["mode"] = mode; + + api->Sign(signerConfig, signParams); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: Sign002 + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBinTest, Sign002, testing::ext::TestSize.Level1) +{ + // go to branch "The sign data made failed" + std::shared_ptr api = std::make_shared(); + + // 1.construct SignerConfig + SignerConfig signerConfig; + Options options; + ConstructSignerConfig(signerConfig, options); + + // 2.construct sign params + std::map signParams; + ConstructSignParams(signParams); + + api->Sign(signerConfig, signParams); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: SignBinTest + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBinTest, SignBin001, testing::ext::TestSize.Level1) +{ + // go to branch "check Compatible Version failed" + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/app1-profile1.p7b"; + std::string inFile = "./hapSign/unsigned.bin"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/signed.bin"; + std::string inForm = "bin"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string compatibleVersion = ""; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["compatibleVersion"] = compatibleVersion; + bool ret = signProvider->SignBin(params.get()); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: SignBinTest + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBinTest, SignBin002, testing::ext::TestSize.Level1) +{ + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/app1-profile1.p7b"; + std::string inFile = "./hapSign/unsigned.bin"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/signed.bin"; + std::string inForm = "bin"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string compatibleVersion = "9"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["compatibleVersion"] = compatibleVersion; + bool ret = signProvider->SignBin(params.get()); + EXPECT_EQ(ret, true); +} + +} // namespace SignatureTools +} // namespace OHOS diff --git a/hapsigntool_cpp/test/unittest/hapSign/sign_block_data_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/sign_block_data_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1acdea0aa566a8468ed79cb772fad9dd4ce151cc --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/sign_block_data_test.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "sign_block_data.h" + +using namespace OHOS::SignatureTools; + +/* +* 测试套件,固定写法 +*/ +class SignBlockDataTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: getBlockHead + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, getBlockHead, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + api->GetBlockHead(); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: getByte + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, getByte, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + bool byte = api->GetByte(); + EXPECT_EQ(byte, true); +} + +/** + * @tc.name: getLen + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, getLen, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + long len = api->GetLen(); + EXPECT_EQ(len, 32); +} + +/** + * @tc.name: getSignData + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, getSignData, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + std::vector retSignData = api->GetSignData(); + EXPECT_EQ(retSignData.size(), 32); +} + +/** + * @tc.name: getSignFile + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, getSignFile, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + std::string signFile = api->GetSignFile(); + EXPECT_EQ(signFile.size(), 0); +} + +/** + * @tc.name: getType + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, getType, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + char type = api->GetType(); + EXPECT_EQ(type, 3); +} + +/** + * @tc.name: setBlockHead + * @tc.desc: Test interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignBlockDataTest, setBlockHead, testing::ext::TestSize.Level1) +{ + std::vector signData(std::vector(32, 0)); + std::shared_ptr api = std::make_shared(signData, 3); + api->SetBlockHead(signData); + EXPECT_EQ(true, 1); +} diff --git a/hapsigntool_cpp/test/unittest/hapSign/sign_elf_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/sign_elf_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c067f49d0ccba0bce51f32c157cc8de77792f18f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/sign_elf_test.cpp @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "sign_elf.h" +#include "code_signing.h" + +namespace OHOS { +namespace SignatureTools { +class SignElfTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + (void)rename("./hapSign/unsigned-linux.txt", "./hapSign/unsigned-linux.hap"); + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +void SetParamsMap(std::map& params) +{ + params["keyPwd"] = "123456"; + params["mode"] = "localSign"; + params["keyAlias"] = "oh-app1-key-v1"; + params["signAlg"] = "SHA256withECDSA"; + params["appCertFile"] = "./hapSign/app-release1.pem"; + params["signCode"] = "1"; + params["compatibleVersion"] = "9"; + params["outFile"] = "./hapSign/entry-default-signed.elf"; + params["profileFile"] = "./hapSign/signed-profile.p7b"; + params["keystorePwd"] = "123456"; + params["keystoreFile"] = "./hapSign/ohtest.jks"; + params["inFile"] = "./hapSign/unsigned-linux.hap"; + params["profileSigned"] = "1"; + params["inForm"] = "elf"; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-" + "feature\":\"hos_system_app\",\"bundle-name\":\"com.OpenHarmony.app.test\",\"developer-id\":\"O" + "penHarmony\",\"distribution-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB" + "44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C76" + "79A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":" + "[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":" + "{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + params["profileContent"] = provision; +} + +void SetOptions(Options* options) +{ + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned-linux.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + static char keyPwd[] = "123456"; + static char keystorePwd[] = "123456"; + + (*options)["mode"] = "localSign"; + (*options)["keyAlias"] = keyAlias; + (*options)["signAlg"] = signAlg; + (*options)["signCode"] = signCode; + (*options)["appCertFile"] = appCertFile; + (*options)["profileFile"] = profileFile; + (*options)["inFile"] = inFile; + (*options)["keystoreFile"] = keystoreFile; + (*options)["outFile"] = outFile; + (*options)["inForm"] = inForm; + (*options)["keyPwd"] = keyPwd; + (*options)["keystorePwd"] = keystorePwd; +} + +/** + * @tc.name: sign001 + * @tc.desc: Test function of SignElf::sign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignElfTest, Sign001, testing::ext::TestSize.Level1) +{ + // success + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + signerConfig.SetOptions(options.get()); + + signerConfig.GetSigner(); + SignElf::Sign(signerConfig, params); + EXPECT_EQ(signerConfig.GetCompatibleVersion(), 9); +} + +/** + * @tc.name: sign002 + * @tc.desc: Test function of SignElf::sign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignElfTest, Sign002, testing::ext::TestSize.Level1) +{ + // failed: inFile is null + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + params["inFile"] = "./hapSign/unsigned-linux-no.out"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + (*options)["inFile"] = "./hapSign/unsigned-linux-no.out"; + signerConfig.SetOptions(options.get()); + + signerConfig.GetSigner(); + bool ret = SignElf::Sign(signerConfig, params); + + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: sign003 + * @tc.desc: Test function of SignElf::sign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignElfTest, Sign003, testing::ext::TestSize.Level1) +{ + // failed:profileFile is null + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + params["profileFile"] = "./hapSign/signed-profile-no.p7b"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + (*options)["profileFile"] = "./hapSign/signed-profile-no.p7b"; + signerConfig.SetOptions(options.get()); + + signerConfig.GetSigner(); + bool ret = SignElf::Sign(signerConfig, params); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: sign004 + * @tc.desc: Test function of SignElf::sign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignElfTest, Sign004, testing::ext::TestSize.Level1) +{ + // failed:outFile is null + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + params["outFile"] = "./hapSign_test/entry-default-signed.elf"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + (*options)["outFile"] = "./hapSign_test/entry-default-signed.elf"; + signerConfig.SetOptions(options.get()); + + signerConfig.GetSigner(); + bool ret = SignElf::Sign(signerConfig, params); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: sign005 + * @tc.desc: Test function of SignElf::sign() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignElfTest, Sign005, testing::ext::TestSize.Level1) +{ + // failed:signCode is 0 + SignerConfig signerConfig; + signerConfig.SetCompatibleVersion(9); + + std::map params; + SetParamsMap(params); + params["signCode"] = "0"; + signerConfig.FillParameters(params); + + ContentDigestAlgorithm contentDigestAlgorithm("SHA-256", 32); + std::pair signatureAlgAndParams("SHA256withECDSA", nullptr); + SignatureAlgorithmHelper signatureAlgorithm(SignatureAlgorithmId::ECDSA_WITH_SHA256, "ECDSA_WITH_SHA256", + contentDigestAlgorithm, signatureAlgAndParams); + std::vector signatureAlgorithms; + signatureAlgorithms.push_back(signatureAlgorithm); + signerConfig.SetSignatureAlgorithms(signatureAlgorithms); + + std::shared_ptr options = std::make_shared(); + SetOptions(options.get()); + (*options)["signCode"] = "0"; + signerConfig.SetOptions(options.get()); + + signerConfig.GetSigner(); + bool ret = SignElf::Sign(signerConfig, params); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: GetCodeSignBlock001 + * @tc.desc: Test function of CodeSigning::GetCodeSignBlock() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignElfTest, GetCodeSignBlock001, testing::ext::TestSize.Level1) +{ + CodeSigning object; + std::string input = "./hapSign_test/entry-default-signed.elf"; + int64_t offset = 0; + std::string inForm = "elf"; + std::string profileContent = ""; + ZipSigner zip; + std::vector ret; + object.GetCodeSignBlock(input, offset, inForm, profileContent, zip, ret); + EXPECT_EQ(profileContent, ""); +} + +} +} diff --git a/hapsigntool_cpp/test/unittest/hapSign/sign_provider_test.cpp b/hapsigntool_cpp/test/unittest/hapSign/sign_provider_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4f2f394f934a0d065119410942775a5ccfc97ed --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/sign_provider_test.cpp @@ -0,0 +1,1175 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "sign_provider_test.h" +#include "params_run_tool.h" +#include "local_sign_provider.h" +#include "remote_sign_provider.h" +#include "sign_hap.h" +#include "sign_provider.h" +#include "sign_tool_service_impl.h" +#include + +namespace OHOS { +namespace SignatureTools { + +void GenUnvaildUnProviderHap(const std::string& path) +{ + std::ofstream outfile(path); + if (!outfile) { + SIGNATURE_TOOLS_LOGE("Unable to open file: %s", path.c_str()); + return; + } + outfile << "Hello, this is a Unvaild un provider Hap.\n"; + outfile.flush(); + outfile.close(); + return; +} + +void SignProviderTest::SetUpTestCase(void) +{ + GenUnvaildUnProviderHap("./hapSign/phone-default-unsigned"); + GenUnvaildUnProviderHap("./hapSign/phone-default-unsigned.txt"); + GenUnvaildUnProviderHap("./hapSign/nohap.hap"); + + (void)rename("./hapSign/packages/phone-default-unsigned-test.txt", "./hapSign/phone-default-unsigned-test.hap"); + (void)rename("./hapSign/packages/phone-default-unsigned.txt", "./hapSign/phone-default-unsigned.hap"); + (void)rename("./hapSign/packages/unsigned_with_cd_and_eocd.txt", "./hapSign/unsigned_with_cd_and_eocd.hap"); + (void)rename("./hapSign/packages/unsigned_with_eocd.txt", "./hapSign/unsigned_with_eocd.hap"); + (void)rename("./hapSign/packages/unsigned-linux.txt", "./hapSign/unsigned-linux.out"); + sync(); +} + +void SignProviderTest::TearDownTestCase(void) +{ +} +/* + * @tc.name: sign_provider_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_001, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned-test.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-unsigned-test.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} +/* + * @tc.name: sign_provider_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_002, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + (*params)["compatibleVersion"] = std::string("a"); + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_003 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_003, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_003 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_004, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string compatibleVersion = "a"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["compatibleVersion"] = compatibleVersion; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_004 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_006, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string property = "./hapSign/signed-profile.p7b"; + std::string proof = "./hapSign/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["property"] = property; + (*params)["proof"] = proof; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: sign_provider_test_005 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_007, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string property = "./hapSign/signed-nohavaprofile.p7b"; + std::string proof = "./hapSign/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["property"] = property; + (*params)["proof"] = proof; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_005 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_008, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-nohaveprofile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string property = "./hapSign/signed-profile.p7b"; + std::string proof = "./hapSign/signed-profile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["property"] = property; + (*params)["proof"] = proof; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_005 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_009, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string property = "./hapSign/signed-profile.p7b"; + std::string proof = "./hapSign/signed-nohaveprofile.p7b"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["property"] = property; + (*params)["proof"] = proof; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, true); +} + +/* + * @tc.name: sign_provider_test_006 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_010, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign_test/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_007 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_011, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_008 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_012, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = ""; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_009 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_013, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-nohava-profile.p7b"; + std::string inFile = "./hapSign_test/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_009 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_014, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string compatibleVersion = "a"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["compatibleVersion"] = compatibleVersion; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_009 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_015, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_009 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_016, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA512withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_017, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile-nohave.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned-test.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed-test.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_018, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA-nohave"; + std::string signCode = "0"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned-test.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed-test.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_019, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "3"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_020, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = ""; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: hap_sign_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_021, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = ""; + std::string inFile = "./hapSign/phone-default-unsigned.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: sign_provider_test_001 + * @tc.desc: Generate a key pair and load it into the keystore. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, sign_provider_test_022, testing::ext::TestSize.Level1) +{ + SIGNATURE_TOOLS_LOGI("hello world !!!"); + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "0"; + std::string appCertFile = ""; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string profileSigned = "1"; + std::string inFile = "./hapSign/phone-default-unsigned-test.hap"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/phone-default-signed-test.hap"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["profileSigned"] = profileSigned; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->Sign(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SignElf_001 + * @tc.desc: sign elf file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, SignElf_001, testing::ext::TestSize.Level1) +{ + // success + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned-linux.out"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool ret = signProvider->SignElf(params.get()); + + EXPECT_NE(ret, -1); +} + +/* + * @tc.name: SignElf_002 + * @tc.desc: sign elf file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, SignElf_002, testing::ext::TestSize.Level1) +{ + // profileFile:p7b is null + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string inFile = "./hapSign/unsigned-linux.out"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool ret = signProvider->SignElf(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SignElf_003 + * @tc.desc: sign elf file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, SignElf_003, testing::ext::TestSize.Level1) +{ + // compatibleVersion is null + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned-linux.out"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string compatibleVersion = ""; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["compatibleVersion"] = compatibleVersion; + bool ret = signProvider->SignElf(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SignElf_004 + * @tc.desc: sign elf file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, SignElf_004, testing::ext::TestSize.Level1) +{ + // inFile is null + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = ""; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + + bool ret = signProvider->SignElf(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SignElf_005 + * @tc.desc: sign elf file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, SignElf_005, testing::ext::TestSize.Level1) +{ + // inFile path is false + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign_test/unsigned-linux.out"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool ret = signProvider->SignElf(params.get()); + EXPECT_EQ(ret, false); +} + +/* + * @tc.name: SignElf_006 + * @tc.desc: sign elf file. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SignProviderTest, SignElf_006, testing::ext::TestSize.Level1) +{ + // signAlg format is false + std::unique_ptr signProvider = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + std::string mode = "localSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string signAlg = "SHA512withECDSA"; + std::string signCode = "1"; + std::string appCertFile = "./hapSign/app-release1.pem"; + std::string profileFile = "./hapSign/signed-profile.p7b"; + std::string inFile = "./hapSign/unsigned-linux.out"; + std::string keystoreFile = "./hapSign/ohtest.p12"; + std::string outFile = "./hapSign/entry-default-signed.elf"; + std::string inForm = "elf"; + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["appCertFile"] = appCertFile; + (*params)["profileFile"] = profileFile; + (*params)["inFile"] = inFile; + (*params)["keystoreFile"] = keystoreFile; + (*params)["outFile"] = outFile; + (*params)["inForm"] = inForm; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + bool ret = signProvider->SignElf(params.get()); + EXPECT_EQ(ret, false); +} +} // namespace SignatureTools +} // namespace OHOS diff --git a/hapsigntool_cpp/test/unittest/hapSign/sign_provider_test.h b/hapsigntool_cpp/test/unittest/hapSign/sign_provider_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b757e43984911e9d69f08d57feee4eabc960c637 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapSign/sign_provider_test.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_HAP_SIGN_TEST_H +#define OHOS_HAP_SIGN_TEST_H + +#include "localization_adapter.h" +#include "openssl/err.h" +#include "openssl/pem.h" +#include "openssl/ssl.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "signature_tools_log.h" +#include + +namespace OHOS { +namespace SignatureTools { +class SignProviderTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() {}; + void TearDown() {}; +}; +} // namespace SignatureTools +} // namespace OHOS + +#endif // OHOS_HAP_SIGN_TEST_H \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..fb95ea94bdb3a5d4dd593fcc793e3e35be1dc961 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.cpp @@ -0,0 +1,400 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hap_cert_verify_openssl_utils_test.h" + +#include +#include + +#include "openssl/asn1.h" +#include "openssl/x509.h" +#include "verify_hap.h" +#include "verify_cert_openssl_utils.h" + +using namespace testing::ext; +using namespace OHOS::SignatureTools; + +namespace OHOS { + namespace SignatureTools { + bool Base64StringDecode(const std::string& base64String, ByteBuffer& output) + { + std::unique_ptr decodeBuffer = std::make_unique(base64String.size()); + if (decodeBuffer == nullptr) { + return false; + } + + const unsigned char* input = reinterpret_cast(base64String.c_str()); + int32_t len = EVP_DecodeBlock(reinterpret_cast(decodeBuffer.get()), + input, base64String.size()); + if (len <= 0) { + return false; + } + + output.SetCapacity(len); + output.PutData(0, decodeBuffer.get(), len); + decodeBuffer.reset(nullptr); + return true; + } + } // namespace SignatureTools +} // namespace OHOS + +namespace { + class VerifyCertOpensslUtilsTest : public testing::Test { + public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); + }; + + void VerifyCertOpensslUtilsTest::SetUpTestCase(void) + { + } + + void VerifyCertOpensslUtilsTest::TearDownTestCase(void) + { + } + void VerifyCertOpensslUtilsTest::SetUp() + { + } + + void VerifyCertOpensslUtilsTest::TearDown() + { + } + + /** + * @tc.name: Test CertVerify function + * @tc.desc: Check whether the CertVerify function can be used to verify a certificate. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, CertVerify001, TestSize.Level1) + { + /* + * @tc.steps: step1. Input an ECC self signed cert with PEM encoded. + * @tc.expected: step1. The return is an X509 object. + */ + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromPemString(ECC_TEST_CERT); + ASSERT_TRUE(certX509 != nullptr); + /* + * @tc.steps: step2. Use all possible input to test CertVerify. + * @tc.expected: step2. The return is verify result. + */ + ASSERT_FALSE(VerifyCertOpensslUtils::CertVerify(nullptr, certX509)); + ASSERT_FALSE(VerifyCertOpensslUtils::CertVerify(certX509, nullptr)); + ASSERT_TRUE(VerifyCertOpensslUtils::CertVerify(certX509, certX509)); + X509_free(certX509); + } + + /** + * @tc.name: Test GetX509CertFromBase64String function + * @tc.desc: Verify whether the GetX509CertFromBase64String function can get an X509 cert from a Base64S string. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, Base64NotUrlSafeCertTest001, TestSize.Level1) + { + /* + * @tc.steps: step1. Input string of ECC cert with base64 decode + * @tc.expected: step1. The return is an X509 object. + */ + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromBase64String(BASE64_NOT_URL_SAFE_CERT); + ASSERT_TRUE(certX509 != nullptr); + std::string subject; + ASSERT_TRUE(VerifyCertOpensslUtils::GetSubjectFromX509(certX509, subject)); + X509_free(certX509); + certX509 = nullptr; + /* + * @tc.steps: step2. Use the subject as an error input. + * @tc.expected: step2. The return is nullptr. + */ + certX509 = VerifyCertOpensslUtils::GetX509CertFromBase64String(subject); + ASSERT_TRUE(certX509 == nullptr); + } + + /** + * @tc.name: Test GetX509CrlFromDerBuffer function + * @tc.desc: Verify whether the GetX509CrlFromDerBuffer function can get an X509 Crl from DerData. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, GetX509CrlFromDerBufferTest001, TestSize.Level1) + { + /* + * @tc.steps: step1. Input invalid data. + * @tc.expected: step1. The return is nullptr. + */ + ByteBuffer crlBuffer; + X509_CRL* crlX509 = VerifyCertOpensslUtils::GetX509CrlFromDerBuffer(crlBuffer, 0, 0); + ASSERT_TRUE(crlX509 == nullptr); + crlBuffer.SetCapacity(TEST_HAPBYTEBUFFER_LENGTH); + crlX509 = VerifyCertOpensslUtils::GetX509CrlFromDerBuffer(crlBuffer, 0, 0); + ASSERT_TRUE(crlX509 == nullptr); + /* + * @tc.steps: step2. Input a string of crl encoded by base64. + * @tc.expected: step2. Ihe return is a crl object. + */ + ASSERT_TRUE(Base64StringDecode(BASE64_CRL, crlBuffer)); + crlX509 = VerifyCertOpensslUtils::GetX509CrlFromDerBuffer(crlBuffer, 0, crlBuffer.GetCapacity()); + std::string crlIssuer; + ASSERT_FALSE(VerifyCertOpensslUtils::GetIssuerFromX509Crl(nullptr, crlIssuer)); + ASSERT_TRUE(VerifyCertOpensslUtils::GetIssuerFromX509Crl(crlX509, crlIssuer)); + ASSERT_TRUE(crlX509 != nullptr); + X509_CRL_free(crlX509); + } + + /** + * @tc.name: Test GetCertsChain function + * @tc.desc: Verify whether the GetCertsChain function can get a trusted cert chain from certs. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, GetCertsChainTest001, TestSize.Level1) + { + /* + * @tc.steps: step1. Use a certVisitSign included a self signed cert and an empty certsChain as input. + * @tc.expected: step1. The return is false due to invalid input. + */ + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromPemString(ECC_TEST_CERT); + ASSERT_TRUE(certX509 != nullptr); + CertChain certsChain; + CertSign certVisitSign; + certVisitSign[certX509] = false; + ASSERT_FALSE(VerifyCertOpensslUtils::GetCertsChain(certsChain, certVisitSign)); + } + + /** + * @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 GetSerialNumberFromX509 function. + * @tc.desc: Verify whether the GetSerialNumberFromX509 function can get the SerialNumber from an X509 certificate. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, GetSerialNumberFromX509Test001, TestSize.Level1) + { + /* + * @tc.steps: step1. Use nullptr as input to test GetSerialNumberFromX509. + * @tc.expected: step1. The return is false. + */ + long long certSerialNumber; + ASSERT_FALSE(VerifyCertOpensslUtils::GetSerialNumberFromX509(nullptr, certSerialNumber)); + /* + * @tc.steps: step2. Use real cert to test GetX509CertFromPemString. + * @tc.expected: step2. the return is true. + */ + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromPemString(ECC_TEST_CERT); + ASSERT_TRUE(certX509 != nullptr); + ASSERT_TRUE(VerifyCertOpensslUtils::GetSerialNumberFromX509(certX509, certSerialNumber)); + X509_free(certX509); + } + + /** + * @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: step2. Input a nullptr signTime and a certChain with two cert. + * @tc.expected: step2. The return is false. + */ + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromBase64String(BASE64_NOT_URL_SAFE_CERT); + ASSERT_TRUE(certX509 != nullptr); + certsChain.push_back(certX509); + certsChain.push_back(certX509); + 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)); + X509_free(certX509); + 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; + ASSERT_FALSE(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(); + ASSERT_TRUE(crls != nullptr); + certsChain.push_back(nullptr); + certsChain.push_back(nullptr); + ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context)); + /* + * @tc.steps: step3. Input valid certChain and null. + * @tc.expected: step3. The return is true due to crl is optional. + */ + certsChain.clear(); + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromPemString(ECC_TEST_CERT); + ASSERT_TRUE(certX509 != nullptr); + certsChain.push_back(certX509); + certsChain.push_back(certX509); + ASSERT_TRUE(VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context)); + /* + * @tc.steps: step4. Input error certChain and crls. + * @tc.expected: step4. The return is false. + */ + certsChain.clear(); + X509* root = VerifyCertOpensslUtils::GetX509CertFromPemString(ROOTCERT); + ASSERT_TRUE(root != nullptr); + certsChain.push_back(root); + certsChain.push_back(certX509); + ByteBuffer crlBuffer; + ASSERT_TRUE(Base64StringDecode(BASE64_CRL, crlBuffer)); + X509_CRL* crlX509 = VerifyCertOpensslUtils::GetX509CrlFromDerBuffer(crlBuffer, 0, crlBuffer.GetCapacity()); + ASSERT_TRUE(crlX509 != nullptr); + sk_X509_CRL_push(crls, crlX509); + ASSERT_FALSE(VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context)); + /* + * @tc.steps: step5. Input right certChain and crls. + * @tc.expected: step5. The return is true. + */ + certsChain.clear(); + certsChain.push_back(root); + certsChain.push_back(root); + ASSERT_TRUE(VerifyCertOpensslUtils::VerifyCrl(certsChain, crls, pkcs7Context)); + X509_free(certX509); + X509_free(root); + sk_X509_CRL_pop_free(crls, X509_CRL_free); + } + + /** + * @tc.name: Test CompareX509Cert function + * @tc.desc: Verify whether the CompareX509Cert function can compare two certificates. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, CompareX509CertTest001, TestSize.Level1) + { + /* + * @tc.steps: step1. Use nullptr as input to test CompareX509Cert. + * @tc.expected: step1. The return is false. + */ + ASSERT_FALSE(VerifyCertOpensslUtils::CompareX509Cert(nullptr, ECC_TEST_KEY)); + /* + * @tc.steps: step2. The second cert is not a cert string. + * @tc.expected: step2. the return is false. + */ + X509* certX509 = VerifyCertOpensslUtils::GetX509CertFromPemString(ECC_TEST_CERT); + ASSERT_TRUE(certX509 != nullptr); + ASSERT_FALSE(VerifyCertOpensslUtils::CompareX509Cert(certX509, ECC_TEST_KEY)); + /* + * @tc.steps: step3. Input two same cert. + * @tc.expected: step3. The return is true. + */ + ASSERT_TRUE(VerifyCertOpensslUtils::CompareX509Cert(certX509, ECC_TEST_CERT)); + X509_free(certX509); + } + + /** + * @tc.name: Test WriteX509CrlToStream function. + * @tc.desc: Verify whether the WriteX509CrlToStream function can write crl to a file. + * @tc.type: FUNC + */ + HWTEST_F(VerifyCertOpensslUtilsTest, WriteX509CrlToStreamTest001, TestSize.Level1) + { + /* + * @tc.steps: step1. Use invalid input. + * @tc.expected: step1. The file length is zero. + */ + std::ofstream crlFile; + VerifyCertOpensslUtils::WriteX509CrlToStream(crlFile, nullptr); + std::string filePath = "./hapVerify/test_crl"; + crlFile.open(filePath, std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); + VerifyCertOpensslUtils::WriteX509CrlToStream(crlFile, nullptr); + ASSERT_TRUE(crlFile.tellp() == 0); + if (crlFile.is_open()) { + crlFile.close(); + } + } + + /** + * @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)); + } +} diff --git a/hapsigntool_cpp/test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.h b/hapsigntool_cpp/test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b7ae2ebfe3a4d68dfecbf02358713398ee9be95f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_cert_verify_openssl_utils_test.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HAP_CERT_VERIFY_OPENSSL_UTILS_TEST_H +#define HAP_CERT_VERIFY_OPENSSL_UTILS_TEST_H + +#include +#include + +#include "byte_buffer.h" + +#include "test_const.h" + +namespace OHOS { + namespace SignatureTools { + bool Base64StringDecode(const std::string& base64String, SignatureTools::ByteBuffer& output); + } +} + +int32_t GetCertInfo001(void); +int32_t CertVerify001(void); +int32_t Base64NotUrlSafeCertTest001(void); +int32_t GetX509CrlFromDerBufferTest001(void); +int32_t GetIssuerAndSubjectTest001(void); +int32_t GetSerialNumberFromX509Test001(void); +int32_t VerifyCertChainPeriodOfValidityTest001(void); +int32_t VerifyCrlTest001(void); +int32_t CompareX509CertTest001(void); +int32_t WriteX509CrlToStreamTest001(void); +int32_t PrivateFuncInvalidInputTest001(void); +#endif // HAP_CERT_VERIFY_OPENSSL_UTILS_TEST_H 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 new file mode 100644 index 0000000000000000000000000000000000000000..630135db2fc299d68367ea05c2defaa7beab6722 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_signer_block_utils_test.cpp @@ -0,0 +1,524 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "byte_buffer_data_source.h" +#include "random_access_file.h" +#include "hap_signer_block_utils.h" +#include "hap_signer_block_utils_test.h" + +using namespace testing::ext; +using namespace OHOS::SignatureTools; + +namespace OHOS { +namespace SignatureTools { +void CreateHapSubSignBlockHead(HapSubSignBlockHead& signBlob, HapSubSignBlockHead& profileBlob, + HapSubSignBlockHead& propertyBlob) +{ + signBlob.type = HAP_SIGN_BLOB; + signBlob.length = TEST_FILE_BLOCK_LENGTH; + signBlob.offset = sizeof(HapSubSignBlockHead) * TEST_FILE_BLOCK_COUNT; + profileBlob.type = PROFILE_BLOB; + profileBlob.length = TEST_FILE_BLOCK_LENGTH; + profileBlob.offset = signBlob.offset + signBlob.length; + propertyBlob.type = PROPERTY_BLOB; + propertyBlob.length = TEST_FILE_BLOCK_LENGTH; + propertyBlob.offset = profileBlob.offset + profileBlob.length; +} + +long long CreatTestZipFile(const std::string& pathFile, SignatureInfo& signInfo) +{ + std::ofstream hapFile(pathFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + if (!hapFile.is_open()) { + return 0; + } + char block[TEST_FILE_BLOCK_LENGTH] = { 0 }; + /* input contents of ZIP entries */ + hapFile.seekp(0, std::ios_base::beg); + hapFile.write(block, sizeof(block)); + /* input sign block */ + HapSubSignBlockHead signBlob; + HapSubSignBlockHead profileBlob; + HapSubSignBlockHead propertyBlob; + CreateHapSubSignBlockHead(signBlob, profileBlob, propertyBlob); + hapFile.write(reinterpret_cast(&signBlob), sizeof(signBlob)); + hapFile.write(reinterpret_cast(&profileBlob), sizeof(profileBlob)); + hapFile.write(reinterpret_cast(&propertyBlob), sizeof(propertyBlob)); + for (int32_t i = 0; i < TEST_FILE_BLOCK_COUNT; i++) { + hapFile.write(block, sizeof(block)); + } + int32_t blockCount = TEST_FILE_BLOCK_COUNT; + hapFile.write(reinterpret_cast(&blockCount), sizeof(blockCount)); + long long signBlockSize = (sizeof(HapSubSignBlockHead) + sizeof(block)) * + TEST_FILE_BLOCK_COUNT + + HapSignerBlockUtils::ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH; + hapFile.write(reinterpret_cast(&signBlockSize), sizeof(signBlockSize)); + long long magic = HapSignerBlockUtils::HAP_SIG_BLOCK_MAGIC_LOW_OLD; + hapFile.write(reinterpret_cast(&magic), sizeof(magic)); + magic = HapSignerBlockUtils::HAP_SIG_BLOCK_MAGIC_HIGH_OLD; + hapFile.write(reinterpret_cast(&magic), sizeof(magic)); + int32_t version = 1; + hapFile.write(reinterpret_cast(&version), sizeof(version)); + /* input central direction */ + hapFile.write(block, sizeof(block)); + /* input end of central direction */ + int32_t zidEocdSign = HapSignerBlockUtils::ZIP_EOCD_SEGMENT_FLAG; + hapFile.write(reinterpret_cast(&zidEocdSign), sizeof(zidEocdSign)); + hapFile.write(reinterpret_cast(&magic), sizeof(magic)); + uint32_t centralDirLen = sizeof(block); + hapFile.write(reinterpret_cast(¢ralDirLen), sizeof(centralDirLen)); + uint32_t centralDirOffset = TEST_FILE_BLOCK_LENGTH + signBlockSize; + hapFile.write(reinterpret_cast(¢ralDirOffset), sizeof(centralDirOffset)); + short eocdCommentLen = 0; + hapFile.write(reinterpret_cast(&eocdCommentLen), sizeof(eocdCommentLen)); + hapFile.close(); + signInfo.hapCentralDirOffset = centralDirOffset; + signInfo.hapEocdOffset = centralDirOffset + centralDirLen; + signInfo.hapSignatureBlock.SetCapacity(TEST_FILE_BLOCK_LENGTH); + signInfo.hapSignatureBlock.PutData(0, block, sizeof(block)); + long long sumLen = signInfo.hapEocdOffset + sizeof(zidEocdSign) + sizeof(centralDirLen) + + sizeof(centralDirOffset) + sizeof(magic) + sizeof(eocdCommentLen); + return sumLen; +} +} // namespace SignatureTools +} // namespace OHOS + +namespace { +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 { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static const int32_t TEST_ZIP_BLOCKS_NUM_NEED_DIGEST; +}; + +const int32_t HapSignerBlockUtilsTest::TEST_ZIP_BLOCKS_NUM_NEED_DIGEST = 3; + +void HapSignerBlockUtilsTest::SetUpTestCase(void) +{ + (void)rename("./hapVerify/hap_verify_v2.txt", HAP_VERIFY_V2_PATH.c_str()); + (void)rename("./hapVerify/hap_verify_v3.txt", HAP_VERIFY_V3_PATH.c_str()); + sync(); +} + +void HapSignerBlockUtilsTest::TearDownTestCase(void) +{ +} + +void HapSignerBlockUtilsTest::SetUp() +{ +} + +void HapSignerBlockUtilsTest::TearDown() +{ +} + +/** + * @tc.name: Test FindHapSignature function + * @tc.desc: input one right file and some error files, The static function will return correct result; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, FindHapSignatureTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. create a test zip file. + */ + std::string pathFile = "./hapVerify/test_hap_verify.hap"; + SignatureInfo signInfo; + int32_t sumLen = CreatTestZipFile(pathFile, signInfo); + /* + * @tc.steps: step2. test FindHapSignature function + * @tc.expected: step2. the return will be true. + */ + RandomAccessFile hapTestFile; + ASSERT_TRUE(hapTestFile.Init(pathFile)); + ASSERT_EQ(hapTestFile.GetLength(), sumLen); + SignatureInfo hapSignInfo; + ASSERT_TRUE(HapSignerBlockUtils::FindHapSignature(hapTestFile, hapSignInfo)); + /* + * @tc.steps: step3. make central offset error, and test FindHapSignature function + * @tc.expected: step3. can not find central directory, the return will be false. + */ + ByteBuffer eocd(TEST_ZIP_EOCD_SIZE); + EXPECT_GT(hapTestFile.ReadFileFullyFromOffset(eocd, sumLen - TEST_ZIP_EOCD_SIZE), 0); + ByteBuffer buff(eocd); + buff.PutInt32(TEST_ZIP_ECD_OFFSET_FIELD_OFFSET, TEST_HAPBYTEBUFFER_INT32_DATA); + EXPECT_GT(hapTestFile.WriteToFile(buff, sumLen - TEST_ZIP_EOCD_SIZE, buff.GetCapacity()), 0); + ASSERT_FALSE(HapSignerBlockUtils::FindHapSignature(hapTestFile, hapSignInfo)); + /* + * @tc.steps: step4. make eocd comment error, and test FindHapSignature function + * @tc.expected: step4. can not find eocd, the return will be false. + */ + ByteBuffer buff2(eocd); + buff2.PutInt16(TEST_ZIP_EOCD_COMMENT_OFFSET, TEST_HAPBYTEBUFFER_UINT16_DATA); + EXPECT_GT(hapTestFile.WriteToFile(buff2, sumLen - TEST_ZIP_EOCD_SIZE, buff2.GetCapacity()), 0); + ASSERT_FALSE(HapSignerBlockUtils::FindHapSignature(hapTestFile, hapSignInfo)); + /* + * @tc.steps: step5. make hap signing block error, and test FindHapSignature function + * @tc.expected: step4. can not find hap signing block, the return will be false. + */ + RandomAccessFile hapTestFile2; + ASSERT_TRUE(hapTestFile2.Init(HAP_VERIFY_V2_PATH)); + ASSERT_FALSE(HapSignerBlockUtils::FindHapSignature(hapTestFile2, hapSignInfo)); +} + +/** + * @tc.name: Test FindEocdInHap function + * @tc.desc: create a file with invalid length, The function will return false; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, FindEocdInHapTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. create a test file with invalid length. + */ + std::string pathFile = "./hapVerify/test_hap_verify.hap"; + std::ofstream hapFile; + hapFile.open(pathFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile.is_open()); + uint32_t centralDirLen = TEST_HAPBYTEBUFFER_UINT32_DATA; + hapFile.write(reinterpret_cast(¢ralDirLen), sizeof(centralDirLen)); + hapFile.close(); + /* + * @tc.steps: step2. test FindEocdInHap function + * @tc.expected: step2. the return will be false. + */ + RandomAccessFile hapTestFile; + hapTestFile.Init(pathFile); + std::pair eocd; + + ASSERT_FALSE(HapSignerBlockUtils::FindEocdInHap(hapTestFile, eocd)); + /* + * @tc.steps: step3. test FindEocdInHap function + * @tc.expected: step3. make the file length is right, but the comment size is wrong, the return will be false. + */ + ByteBuffer fileLen(TEST_FILE_BLOCK_LENGTH); + EXPECT_GT(hapTestFile.WriteToFile(fileLen, 0, fileLen.GetCapacity()), 0); + int32_t maxCommentSize = TEST_INVALID_MAX_COMMENT_SIZE; + ASSERT_FALSE(HapSignerBlockUtils::FindEocdInHap(hapTestFile, maxCommentSize, eocd)); + maxCommentSize = TEST_MAX_COMMENT_SIZE; + ASSERT_FALSE(HapSignerBlockUtils::FindEocdInHap(hapTestFile, maxCommentSize, eocd)); + /* + * @tc.steps: step4. test FindEocdInSearchBuffer function + * @tc.expected: step4. make the searchBuffer is wrong, the return will be false. + */ + ByteBuffer testHapBuffer(TEST_HAPBYTEBUFFER_LENGTH); + int32_t offset = 0; + ASSERT_FALSE(HapSignerBlockUtils::FindEocdInSearchBuffer(testHapBuffer, offset)); + ByteBuffer eocdBuff(TEST_ZIP_EOCD_SIZE); + eocdBuff.PutInt32(HapSignerBlockUtils::ZIP_EOCD_SEGMENT_FLAG); + eocdBuff.Flip(); + ASSERT_FALSE(HapSignerBlockUtils::FindEocdInSearchBuffer(eocdBuff, offset)); +} + +/** + * @tc.name: Test GetCentralDirectoryOffset function + * @tc.desc: create an ecod with invalid central offset and length, + * The function will return TEST_NOT_FIND_TARGET_OFFSET; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, GetCentralDirectoryOffsetTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. create a test eocd with invalid central offset and length. + */ + ByteBuffer testEocd(TEST_ZIP_EOCD_SIZE); + int32_t centralDirLen = TEST_FILE_BLOCK_LENGTH; + testEocd.PutInt32(TEST_ZIP_ECD_SIZE_FIELD_OFFSET, centralDirLen); + int32_t centralDirOffset = TEST_FILE_BLOCK_LENGTH; + testEocd.PutInt32(TEST_ZIP_ECD_OFFSET_FIELD_OFFSET, centralDirOffset); + + ASSERT_FALSE(HapSignerBlockUtils::SetUnsignedInt32(testEocd, 0, TEST_INVALID_MAX_COMMENT_SIZE)); + ByteBuffer emptyEocd; + /* + * @tc.steps: step2. run function with error eocdoffset + * @tc.expected: step2. the return will be NOT_FIND_TARGET_OFFSET. + */ + long long offset; + ASSERT_FALSE(HapSignerBlockUtils::GetCentralDirectoryOffset(emptyEocd, 0, offset)); + ASSERT_FALSE(HapSignerBlockUtils::GetCentralDirectoryOffset(testEocd, 0, offset)); + ASSERT_FALSE(HapSignerBlockUtils::GetCentralDirectoryOffset(testEocd, TEST_FILE_BLOCK_LENGTH, offset)); +} + +/** + * @tc.name: Test GetCentralDirectorySize function + * @tc.desc: create an wrong eocd, the function will return false; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, GetCentralDirectorySizeTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. create a test eocd with invalid length; + * @tc.expected: step1. the return will be false. + */ + ByteBuffer testEocd(TEST_HAPBYTEBUFFER_LENGTH); + long centralDirectorySize; + + ASSERT_FALSE(HapSignerBlockUtils::GetCentralDirectorySize(testEocd, centralDirectorySize)); +} + +/** + * @tc.name: Test FindHapSigningBlock function + * @tc.desc: input one right file and some error files, The static function will return correct result; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, FindHapSigningBlockTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. create a test zip file. + */ + std::string pathFile = "./hapVerify/test_hap_verify.hap"; + SignatureInfo signInfo; + int32_t sumLen = CreatTestZipFile(pathFile, signInfo); + /* + * @tc.steps: step2. test FindHapSigningBlock function + * @tc.expected: step2. the return will be true. + */ + RandomAccessFile hapTestFile; + ASSERT_TRUE(hapTestFile.Init(pathFile)); + ASSERT_EQ(hapTestFile.GetLength(), sumLen); + + SignatureInfo hapSignInfo; + ASSERT_TRUE(HapSignerBlockUtils::FindHapSigningBlock(hapTestFile, signInfo.hapCentralDirOffset, hapSignInfo)); + /* + * @tc.steps: step3. test FindHapSigningBlock function + * @tc.expected: step3. can not find cd offset, the return will be false. + */ + ASSERT_FALSE(HapSignerBlockUtils::FindHapSigningBlock(hapTestFile, 0, hapSignInfo)); + /* + * @tc.steps: step4. test FindHapSigningBlock function + * @tc.expected: step4. cd offset is out of range, the return will be false. + */ + ASSERT_FALSE(HapSignerBlockUtils::FindHapSigningBlock(hapTestFile, TEST_HAPBYTEBUFFER_INT32_DATA, hapSignInfo)); + /* + * @tc.steps: step5. test CheckSignBlockHead function + * @tc.expected: step5. make hapSignBlockMagic is wrong, the return will be false. + */ + RandomAccessFile hapTestFile2; + ASSERT_TRUE(hapTestFile2.Init(HAP_VERIFY_V2_PATH)); + int64_t fileLength = hapTestFile2.GetLength(); + ByteBuffer eocd(TEST_ZIP_EOCD_SIZE); + int32_t centralDirOffset; + EXPECT_GT(hapTestFile2.ReadFileFullyFromOffset(eocd, fileLength - TEST_ZIP_EOCD_SIZE), 0); + ASSERT_TRUE(eocd.GetInt32(TEST_ZIP_ECD_OFFSET_FIELD_OFFSET, centralDirOffset)); + ASSERT_FALSE(HapSignerBlockUtils::FindHapSigningBlock(hapTestFile2, centralDirOffset, hapSignInfo)); + /* + * @tc.steps: step6. test CheckSignBlockHead function + * @tc.expected: step6. make hapSignBlockOffset is wrong, the return will be false. + */ + RandomAccessFile hapTestFile3; + ASSERT_TRUE(hapTestFile3.Init(HAP_VERIFY_V3_PATH)); + fileLength = hapTestFile3.GetLength(); + ByteBuffer eocd2(TEST_ZIP_EOCD_SIZE); + EXPECT_GT(hapTestFile3.ReadFileFullyFromOffset(eocd2, fileLength - TEST_ZIP_EOCD_SIZE), 0); + ASSERT_TRUE(eocd2.GetInt32(TEST_ZIP_ECD_OFFSET_FIELD_OFFSET, centralDirOffset)); + ASSERT_FALSE(HapSignerBlockUtils::FindHapSigningBlock(hapTestFile3, centralDirOffset, hapSignInfo)); +} + +/** + * @tc.name: Test CheckSignBlockHead function + * @tc.desc: input one right file and some error files, The static function will return correct result; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, CheckSignBlockHeadTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. test CheckSignBlockHead function + * @tc.expected: step1. check the hapSignBlockMagicHi is wrong, the return will be false. + */ + HapSignBlockHead hapSignBlockHead{ + .version = 3, + .blockCount = 0, + .hapSignBlockSize = 0, + .hapSignBlockMagicLo = HapSignerBlockUtils::HAP_SIG_BLOCK_MAGIC_LOW, + .hapSignBlockMagicHi = 0, + }; + + ASSERT_FALSE(HapSignerBlockUtils::CheckSignBlockHead(hapSignBlockHead)); + /* + * @tc.steps: step2. test CheckSignBlockHead function + * @tc.expected: step2. check the hapSignBlockSize is less than ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH, + * the return will be false. + */ + hapSignBlockHead.hapSignBlockMagicHi = HapSignerBlockUtils::HAP_SIG_BLOCK_MAGIC_HIGH; + ASSERT_FALSE(HapSignerBlockUtils::CheckSignBlockHead(hapSignBlockHead)); + /* + * @tc.steps: step3. test CheckSignBlockHead function + * @tc.expected: step3. check the hapSignBlockSize is greater than MAX_HAP_SIGN_BLOCK_SIZE, + * the return will be false. + */ + hapSignBlockHead.hapSignBlockSize = INT_MAX; + ASSERT_FALSE(HapSignerBlockUtils::CheckSignBlockHead(hapSignBlockHead)); + /* + * @tc.steps: step4. test CheckSignBlockHead function + * @tc.expected: step4. check the blockCount is greater than MAX_BLOCK_COUNT, the return will be false. + */ + hapSignBlockHead.hapSignBlockSize = HapSignerBlockUtils::ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH; + hapSignBlockHead.blockCount = INT_MAX; + ASSERT_FALSE(HapSignerBlockUtils::CheckSignBlockHead(hapSignBlockHead)); +} + +/** + * @tc.name: Test FindHapSubSigningBlock function + * @tc.desc: input one right file and some error files, The static function will return correct result; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, FindHapSubSigningBlockTest001, TestSize.Level1) +{ + RandomAccessFile hapTestFile; + ASSERT_TRUE(hapTestFile.Init(HAP_VERIFY_V2_PATH)); + + ByteBuffer hapSignatureBlock(1); + ByteBuffer hapEocd(1); + ByteBuffer optionalBlockValue(1); + std::vector optionalBlocks{ + { + .optionalType = 0, + .optionalBlockValue = optionalBlockValue + } + }; + SignatureInfo signatureInfo{ + .hapSignatureBlock = hapSignatureBlock, + .hapSigningBlockOffset = 0, + .hapCentralDirOffset = 0, + .hapEocdOffset = 0, + .hapEocd = hapEocd, + .optionBlocks = optionalBlocks, + .version = 0 + }; + + ASSERT_FALSE(HapSignerBlockUtils::FindHapSubSigningBlock(hapTestFile, 0, INT_MAX, 0, signatureInfo)); + + ASSERT_FALSE(HapSignerBlockUtils::FindHapSubSigningBlock(hapTestFile, 1, 0, INT_MAX, signatureInfo)); + + ASSERT_FALSE(HapSignerBlockUtils::FindHapSubSigningBlock(hapTestFile, 1, 0, 0, signatureInfo)); + + ASSERT_FALSE(HapSignerBlockUtils::FindHapSubSigningBlock(hapTestFile, 1, 128, 128, signatureInfo)); +} + +/** + * @tc.name: Test ClassifyHapSubSigningBlock function + * @tc.desc: test function of classify optional block + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, ClassifyHapSubSigningBlock001, TestSize.Level1) +{ + /* + * @tc.steps: step1. run function with input of property block + * @tc.expected: step1. the return signInfo.optionBlocks has property block which inputed. + */ + SignatureInfo signInfo; + ByteBuffer subBlock; + uint32_t type = PROPERTY_BLOB; + + HapSignerBlockUtils::ClassifyHapSubSigningBlock(signInfo, subBlock, type); + ASSERT_FALSE(signInfo.optionBlocks.empty()); + ASSERT_TRUE(signInfo.optionBlocks[0].optionalType == PROPERTY_BLOB); +} + +/** + * @tc.name: Test ComputeDigestsWithOptionalBlock function + * @tc.desc: use an error nid and a right nid to compute digest + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, ComputeDigestsWithOptionalBlock001, TestSize.Level1) +{ + /* + * @tc.steps: step1. run function with an error nid and a right nid + * @tc.expected: step1. the return will be false and right respectively. + */ + OptionalBlock testOptionalBlock; + testOptionalBlock.optionalType = PROPERTY_BLOB; + testOptionalBlock.optionalBlockValue.SetCapacity(TEST_HAPBYTEBUFFER_LENGTH); + std::vector optionalBlocks; + optionalBlocks.push_back(testOptionalBlock); + + ByteBuffer chunkDigest(TEST_HAPBYTEBUFFER_LENGTH); + ByteBuffer finalDigest; + int32_t nid = TEST_NULL_NID; + DigestParameter errorParam = HapSignerBlockUtils::GetDigestParameter(nid); + int32_t ret = HapSignerBlockUtils::ComputeDigestsWithOptionalBlock( + errorParam, optionalBlocks, chunkDigest, finalDigest); + ASSERT_FALSE(ret); + nid = TEST_SHA256_NID; + DigestParameter digestParam = HapSignerBlockUtils::GetDigestParameter(nid); + ret = HapSignerBlockUtils::ComputeDigestsWithOptionalBlock(digestParam, optionalBlocks, chunkDigest, finalDigest); + ASSERT_TRUE(ret); +} + +/** + * @tc.name: Test GetSumOfChunkDigestLen function + * @tc.desc: Test GetSumOfChunkDigestLen with some error inputs + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, GetSumOfChunkDigestLenTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input some error input to test GetSumOfChunkDigestLen + * @tc.expected: step1. the return will be false. + */ + int32_t chunkCount = 0; + int32_t sumOfChunkDigestLen = 0; + DataSource* contents[TEST_ZIP_BLOCKS_NUM_NEED_DIGEST] = { nullptr, nullptr, nullptr }; + bool ret = HapSignerBlockUtils::GetSumOfChunkDigestLen(contents, 0, 0, chunkCount, sumOfChunkDigestLen); + ASSERT_FALSE(ret); + ret = HapSignerBlockUtils::GetSumOfChunkDigestLen(contents, + TEST_ZIP_BLOCKS_NUM_NEED_DIGEST, 0, + chunkCount, sumOfChunkDigestLen); + ASSERT_FALSE(ret); + ByteBuffer testBuffer(TEST_ZIP_EOCD_SIZE); + ByteBufferDataSource testSource(testBuffer); + for (int32_t i = 0; i < TEST_ZIP_BLOCKS_NUM_NEED_DIGEST; i++) { + contents[i] = &testSource; + } + ret = HapSignerBlockUtils::GetSumOfChunkDigestLen(contents, + TEST_ZIP_BLOCKS_NUM_NEED_DIGEST, + INT_MAX, chunkCount, + sumOfChunkDigestLen); + ASSERT_FALSE(ret); +} + +/** + * @tc.name: Test VerifyHapIntegrity function + * @tc.desc: create a file and input error digest, The static function will return false; + * @tc.type: FUNC + */ +HWTEST_F(HapSignerBlockUtilsTest, VerifyHapIntegrityTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. create a test zip file without eocd. + */ + std::string pathFile = "./hapVerify/test_hap_verify.hap"; + SignatureInfo signInfo; + CreatTestZipFile(pathFile, signInfo); + /* + * @tc.steps: step2. create an error digest to test VerifyHapIntegrity function + * @tc.expected: step2. the return will be false. + */ + Pkcs7Context digestInfo; + digestInfo.content.SetCapacity(TEST_FILE_BLOCK_LENGTH); + RandomAccessFile hapTestFile; + hapTestFile.Init(pathFile); + + ASSERT_FALSE(HapSignerBlockUtils::VerifyHapIntegrity(digestInfo, hapTestFile, signInfo)); +} +} // namespace \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/hapVerify/hap_signer_block_utils_test.h b/hapsigntool_cpp/test/unittest/hapVerify/hap_signer_block_utils_test.h new file mode 100644 index 0000000000000000000000000000000000000000..be434ad442f23335fde6ea4b7480096ad55cb647 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_signer_block_utils_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HAP_SIGNING_BLOCK_UTILS_TEST_H +#define HAP_SIGNING_BLOCK_UTILS_TEST_H + +#include +#include + +#include "signature_info.h" + +#include "test_const.h" + +int32_t FindHapSignatureTest001(void); +int32_t VerifyHapIntegrityTest001(void); +int32_t FindEocdInHapTest001(void); +int32_t GetCentralDirectoryOffsetTest001(void); +int32_t ClassifyHapSubSigningBlock001(void); +int32_t ComputeDigestsWithOptionalBlock001(void); +int32_t GetSumOfChunkDigestLenTest001(void); +#endif // HAP_SIGNING_BLOCK_UTILS_TEST_H diff --git a/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_result_test.cpp b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_result_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..874658f9bfa397332490bdaf061b21c635635d98 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_result_test.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hap_verify_result_test.h" + +#include +#include + +#include + +#include "hap_verify_result.h" +#include "hap_signer_block_utils.h" + +using namespace testing::ext; +using namespace OHOS::SignatureTools; +namespace { + class HapVerifyResultTest : public testing::Test { + public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); + }; + + void HapVerifyResultTest::SetUpTestCase(void) + { + } + + void HapVerifyResultTest::TearDownTestCase(void) + { + } + + void HapVerifyResultTest::SetUp() + { + } + + void HapVerifyResultTest::TearDown() + { + } + + /** + * @tc.name: Test GetPublicKey and GetSignature function + * @tc.desc: The static function return publickey and signature will be null; + * @tc.type: FUNC + */ + HWTEST_F(HapVerifyResultTest, GetPublicKeyAndSignature001, TestSize.Level1) + { + /* + * @tc.steps: step1. set a null buffer to HapVerifyResult as data package of pkcs7, + * and do GetPublicKey and GetSignature. + * @tc.expected: step1. the return vector of string is null. + */ + ByteBuffer testBuffer; + HapVerifyResult hapVerifyResult; + hapVerifyResult.SetPkcs7SignBlock(testBuffer); + std::vector publicKeys = hapVerifyResult.GetPublicKey(); + ASSERT_TRUE(publicKeys.empty()); + std::vector signatures = hapVerifyResult.GetSignature(); + ASSERT_TRUE(signatures.empty()); + } + + /** + * @tc.name: Test SetOptionalBlocks and GetProfile GetProperty function + * @tc.desc: The static function will return no profile and have a property; + * @tc.type: FUNC + */ + HWTEST_F(HapVerifyResultTest, GetProfileAndProperty001, TestSize.Level1) + { + /* + * @tc.steps: step1. set an option with property to HapVerifyResult + */ + std::vector option; + HapVerifyResult hapVerifyResult; + OptionalBlock testblock; + testblock.optionalType = PROPERTY_BLOB; + testblock.optionalBlockValue.SetCapacity(TEST_HAPBYTEBUFFER_LENGTH); + option.push_back(testblock); + hapVerifyResult.SetOptionalBlocks(option); + /* + * @tc.steps: step2. GetProfile and detect it right. + * @tc.expected: step2. the return code will be NO_THIS_BLOCK_IN_PACKAGE. + */ + std::string getProfile; + GetOptionalBlockResultCode targetResult = NO_THIS_BLOCK_IN_PACKAGE; + int32_t ret = hapVerifyResult.GetBlockFromOptionalBlocks(PROFILE_BLOB, getProfile); + ASSERT_TRUE(ret == targetResult); + /* + * @tc.steps: step3. GetProperty. + * @tc.expected: step3. the return code will be GET_SUCCESS. + */ + std::string getProperty; + ASSERT_TRUE(hapVerifyResult.GetProperty(getProperty) == GET_SUCCESS); + } + + /** + * @tc.name: Test SetVersion and GetVersion function + * @tc.desc: The static function return Version which is set; + * @tc.type: FUNC + */ + HWTEST_F(HapVerifyResultTest, SetVersionAndGetVersion001, TestSize.Level1) + { + /* + * @tc.steps: step1. set a target version to HapVerifyResult. + * @tc.expected: step1. the return version is the value we set. + */ + int32_t targetVersion = TEST_HAP_SIGN_VERSION; + HapVerifyResult hapVerifyResult; + hapVerifyResult.SetVersion(targetVersion); + int32_t version = hapVerifyResult.GetVersion(); + ASSERT_TRUE(version == targetVersion); + } +} diff --git a/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_result_test.h b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_result_test.h new file mode 100644 index 0000000000000000000000000000000000000000..f103d926e6b0cb65e027eb45f07e17bcfabe59a1 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_result_test.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HAP_VERIFY_RESULT_TEST_H +#define HAP_VERIFY_RESULT_TEST_H + +#include + +#include "test_const.h" + +int32_t GetPublicKeyAndSignature001(void); +int32_t GetProfileAndProperty001(void); +int32_t SetVersionAndGetVersion001(void); +#endif // HAP_VERIFY_RESULT_TEST_H diff --git a/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_test.cpp b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c22de12c14e853d4bab3ae792461e69aff9ee6dc --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_test.cpp @@ -0,0 +1,1235 @@ + +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hap_verify_test.h" +#include +#include +#include +#include "profile_info.h" +#include "verify_hap.h" +#include "test_hap_file_data.h" +#include "hap_cert_verify_openssl_utils_test.h" +#include "test_const.h" +#include "test_hap_file_data.h" +#include "file_utils.h" +#include "random_access_file.h" +#include "signature_tools_log.h" +#include "verify_hap.h" +#include "hap_signer_block_utils.h" +#include "hap_verify_result.h" +#include "openssl/pem.h" +#include "options.h" + +using namespace testing::ext; + +namespace OHOS { +namespace SignatureTools { +const std::string ERROR_CERTIFICATE = "errorCertificate"; +const std::string TEST_CERTIFICATE = "-----BEGIN CERTIFICATE-----\n\ +MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\n\ +MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\n\ +bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\n\ +MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\n\ +T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\n\ +H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\n\ +hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\n\ +JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\n\ +FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\n\ +cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\n\ +LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\n\ +zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\n\ +-----END CERTIFICATE-----\n"; + +class VerifyHapTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void GenUnvaildVerfyHap(const std::string& path) +{ + std::ofstream outfile(path); + if (!outfile) { + SIGNATURE_TOOLS_LOGE("Unable to open file: %s", path.c_str()); + return; + } + outfile << "Hello, this is a Unvaild verfy Hap.\n"; + outfile.flush(); + outfile.close(); + return; +} + +void VerifyHapTest::SetUpTestCase(void) +{ + GenUnvaildVerfyHap("./hapVerify/unvaild.app"); + GenUnvaildVerfyHap("./hapVerify/unvaild.hap"); + GenUnvaildVerfyHap("./hapVerify/unvaild.hqf"); + GenUnvaildVerfyHap("./hapVerify/unvaild.hsp"); + GenUnvaildVerfyHap("./hapVerify/unvaild.txt"); + (void)rename("./hapVerify/packet_diget_algo_error.txt", "./hapVerify/packet_diget_algo_error.hap"); + (void)rename("./hapVerify/packet_hap_integrity_error.txt", "./hapVerify/packet_hap_integrity_error.hap"); + (void)rename("./hapVerify/packet_verify_app_error.txt", "./hapVerify/packet_verify_app_error.hap"); + (void)rename("./hapVerify/packet_get_certchain_error.txt", "./hapVerify/packet_get_certchain_error.hap"); + (void)rename("./hapVerify/packet_get_optional_block_error.txt", "./hapVerify/packet_get_optional_block_error.hap"); + (void)rename("./hapVerify/packet_parse_profile_error.txt", "./hapVerify/packet_parse_profile_error.hap"); + (void)rename("./hapVerify/phone-default-signed.txt", "./hapVerify/phone-default-signed.hap"); + sync(); +} + +void VerifyHapTest::TearDownTestCase(void) +{ +} + +void VerifyHapTest::SetUp() +{ +} + +void VerifyHapTest::TearDown() +{ +} + +/** + * @tc.name: Test CheckFilePath function + * @tc.desc: The static function test whether input is a valid filepath; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, CheckFilePathTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input an too long filepath. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + std::string filePath = HAP_FILE_ECC_SIGN_BASE64; + std::string standardFilePath; + ASSERT_FALSE(v2.CheckFilePath(filePath, standardFilePath)); +} + +/** + * @tc.name: Test GenerateAppId function + * @tc.desc: The static function will return whether generate appid successfully; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GenerateAppIdTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input a null ProvisionInfo. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + ProfileInfo provisionInfo; + ASSERT_FALSE(v2.GenerateAppId(provisionInfo)); +} + +/** + * @tc.name: Test GenerateFingerprint function + * @tc.desc: The static function will return whether generate fingerprint successfully; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GenerateFingerprintTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input a null ProvisionInfo. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + ProfileInfo provisionInfo; + ASSERT_FALSE(v2.GenerateFingerprint(provisionInfo)); +} + +/** + * @tc.name: Test GenerateFingerprint function + * @tc.desc: The static function will return whether generate fingerprint successfully; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GenerateFingerprintTest002, TestSize.Level1) +{ + /* + * @tc.steps: step1. input ProvisionInfo with error distributionCertificate. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + ProfileInfo provisionInfo; + provisionInfo.bundleInfo.distributionCertificate = ERROR_CERTIFICATE; + ASSERT_FALSE(v2.GenerateFingerprint(provisionInfo)); +} + +/** + * @tc.name: Test GenerateFingerprint function + * @tc.desc: The static function will return whether generate fingerprint successfully; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GenerateFingerprintTest003, TestSize.Level1) +{ + /* + * @tc.steps: step1. input ProvisionInfo with error distributionCertificate. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + ProfileInfo provisionInfo; + provisionInfo.bundleInfo.developmentCertificate = ERROR_CERTIFICATE; + ASSERT_FALSE(v2.GenerateFingerprint(provisionInfo)); +} + +/** + * @tc.name: Test GenerateFingerprint function + * @tc.desc: The static function will return whether generate fingerprint successfully; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GenerateFingerprintTest004, TestSize.Level1) +{ + /* + * @tc.steps: step1. input ProvisionInfo with error distributionCertificate. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + ProfileInfo provisionInfo; + provisionInfo.bundleInfo.distributionCertificate = TEST_CERTIFICATE; + ASSERT_TRUE(v2.GenerateFingerprint(provisionInfo)); +} + +/** + * @tc.name: Test GenerateFingerprint function + * @tc.desc: The static function will return whether generate fingerprint successfully; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GenerateFingerprintTest005, TestSize.Level1) +{ + /* + * @tc.steps: step1. input ProvisionInfo with correct distributionCertificate. + * @tc.expected: step1. the return will be true. + */ + VerifyHap v2; + ProfileInfo provisionInfo; + provisionInfo.bundleInfo.developmentCertificate = TEST_CERTIFICATE; + ASSERT_TRUE(v2.GenerateFingerprint(provisionInfo)); +} + +/** + * @tc.name: Test VerifyProfileInfo function + * @tc.desc: The static function will return result of verify profile info; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyProfileInfoTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. profile match with debug and profile type is release. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + Pkcs7Context pkcs7Context; + Pkcs7Context profileContext; + ProfileInfo provisionInfo; + profileContext.matchResult.matchState = MATCH_WITH_PROFILE_DEBUG; + provisionInfo.type = ProvisionType::RELEASE; + ASSERT_FALSE(v2.VerifyProfileInfo(pkcs7Context, profileContext, provisionInfo)); +} + +/** + * @tc.name: Test ParseAndVerifyProfileIfNeed function + * @tc.desc: The static function will return result of ParseAndVerifyProfileIfNeed; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, ParseAndVerifyProfileIfNeedTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input a null profile. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + std::string profile; + ProfileInfo provisionInfo; + ASSERT_FALSE(v2.ParseAndVerifyProfileIfNeed(profile, provisionInfo, false)); + /* + * @tc.steps: step1. input no need parse and verify profile. + * @tc.expected: step1. the return will be true. + */ + ASSERT_TRUE(v2.ParseAndVerifyProfileIfNeed(profile, provisionInfo, true)); +} + +/** + * @tc.name: Test GetDigestAndAlgorithm function + * @tc.desc: The static function will return result of GetDigestAndAlgorithm; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, GetDigestAndAlgorithmTest001, TestSize.Level1) +{ + /* + * @tc.steps: step1. input an error pkcs7 content. + * @tc.expected: step1. the return will be false. + */ + VerifyHap v2; + Pkcs7Context digest; + digest.content.SetCapacity(TEST_FILE_BLOCK_LENGTH); + ASSERT_FALSE(v2.GetDigestAndAlgorithm(digest)); +} + + +/** + * @tc.name: VerifyHapTest.Verify001 + * @tc.desc: The static function will return verify result; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify001, TestSize.Level0) +{ + /* + * @tc.steps: step1. input a invalid path to function of HapVerify. + * @tc.expected: step1. the return will be FILE_PATH_INVALID. + */ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/signed_test.app"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + OHOS::SignatureTools::VerifyHapResultCode targetResult = OHOS::SignatureTools::VERIFY_SUCCESS; + ASSERT_TRUE(resultCode != targetResult); + std::ofstream appFile; + appFile.open(errorFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(appFile.is_open()); + appFile.close(); + resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + ASSERT_TRUE(resultCode != targetResult); +} + + +/** + * @tc.name: VerifyHapTest.HapVerifyOsApp001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, HapVerifyOsApp001, TestSize.Level0) +{ + /* + * @tc.steps: step1. input a signed file to verify. + * @tc.expected: step1. the return will be VERIFY_SUCCESS. + */ + + std::string filePath = "./hapVerify/phone-default-signed.hap"; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + + VerifyHap verify; + int32_t ret = verify.Verify(filePath, hapVerifyResult, &options); + ASSERT_EQ(ret, OHOS::SignatureTools::VERIFY_SUCCESS); +} + +/** + * @tc.name: VerifyHapTest.Verify002 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify002, TestSize.Level0) +{ + std::string filePath = "./hapVerify/phone-default-signed.hap"; + std::string errorfilePath = "./hapVerify/phone-default-signed_error.hap"; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + OHOS::SignatureTools::ByteBuffer byteBuffer; + std::ifstream hapFile; + hapFile.open(filePath, std::ifstream::binary); + ASSERT_TRUE(hapFile.is_open()); + std::stringstream hapFileStr; + hapFileStr << hapFile.rdbuf(); + size_t strSize = hapFileStr.str().size(); + byteBuffer.SetCapacity(strSize); + byteBuffer.PutData(hapFileStr.str().c_str(), hapFileStr.str().size()); + hapFile.close(); + /* + * @tc.steps: step1. input a signed file to verify. + * @tc.expected: step1. the return will be VERIFY_SUCCESS. + */ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + VerifyHap verify; + ASSERT_TRUE(verify.Verify(filePath, hapVerifyResult, &options) == OHOS::SignatureTools::VERIFY_SUCCESS); + // /* + // * @tc.steps: step2. check verify result. + // * @tc.expected: step2. cert version is 1, certChains Len is 3. + // */ + OHOS::SignatureTools::ProfileInfo profile = hapVerifyResult.GetProvisionInfo(); + std::vector publicKeys = hapVerifyResult.GetPublicKey(); + ASSERT_TRUE(static_cast(publicKeys.size()) == TEST_CERT_CHAIN_LEN); + std::vector signatures = hapVerifyResult.GetSignature(); + ASSERT_TRUE(static_cast(signatures.size()) == TEST_CERT_CHAIN_LEN); + /* + * @tc.steps: step3. change comment data. + * @tc.expected: step3. the return will be VERIFY_INTEGRITY_FAIL. + */ + OHOS::SignatureTools::ByteBuffer errorCommentFile = byteBuffer; + char tmp = TEST_HAPBYTEBUFFER_CHAR_DATA; + errorCommentFile.PutByte(0, tmp); + std::ofstream errorFile; + errorFile.open(errorfilePath.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(errorFile.is_open()); + errorFile.seekp(0, std::ios_base::beg); + errorFile.write(errorCommentFile.GetBufferPtr(), errorCommentFile.GetCapacity()); + errorFile.close(); + OHOS::SignatureTools::HapVerifyResult verifyRet; + ASSERT_NE(verify.Verify(errorfilePath, verifyRet, &options), OHOS::SignatureTools::VERIFY_SUCCESS); + /* + * @tc.steps: step4. change profile pkcs7 data. + * @tc.expected: step4. the return will be APP_SOURCE_NOT_TRUSTED. + */ + errorCommentFile.PutByte(TEST_PFOFILE_PKCS7_DATA_INDEX, tmp); + errorFile.open(errorfilePath.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(errorFile.is_open()); + errorFile.seekp(0, std::ios_base::beg); + errorFile.write(errorCommentFile.GetBufferPtr(), errorCommentFile.GetCapacity()); + errorFile.close(); + ASSERT_NE(verify.Verify(errorfilePath, verifyRet, &options), OHOS::SignatureTools::VERIFY_SUCCESS); + /* + * @tc.steps: step5. change app pkcs7 data. + * @tc.expected: step5. the return will be VERIFY_APP_PKCS7_FAIL. + */ + errorCommentFile.PutByte(TEST_APP_PKCS7_DATA_INDEX, tmp); + errorFile.open(errorfilePath.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(errorFile.is_open()); + errorFile.seekp(0, std::ios_base::beg); + errorFile.write(errorCommentFile.GetBufferPtr(), errorCommentFile.GetCapacity()); + errorFile.close(); + ASSERT_NE(verify.Verify(errorfilePath, verifyRet, &options), OHOS::SignatureTools::VERIFY_SUCCESS); +} + +/** + * @tc.name: VerifyHapTest.Verify003 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ + +HWTEST_F(VerifyHapTest, Verify004, TestSize.Level0) +{ + /* + * @tc.steps: step1. input a invalid path to function of HapVerify. + * @tc.expected: step1. the return will be FILE_PATH_INVALID. + */ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + VerifyHap verify; + /* + * @tc.steps: step2. create a hapfile and run HapVerify. + * @tc.expected: step2. the return will be SIGNATURE_NOT_FOUND. + */ + std::string rightFile = "./hapVerify/signed.hap"; + std::ofstream hapFile; + hapFile.open(rightFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile.is_open()); + hapFile.seekp(0, std::ios_base::beg); + hapFile.write(MINIHAPFILE, TEST_MINI_HAP_FILE_LENGTH); + hapFile.close(); + int32_t resultCode = verify.Verify(rightFile, hapVerifyResult, &options); + ASSERT_TRUE(resultCode == OHOS::SignatureTools::SIGNATURE_NOT_FOUND); + + /* + * @tc.steps: step3. create an error hapfile and run HapVerify. + * @tc.expected: step3. the return will be SIGNATURE_NOT_FOUND. + */ + std::string rightFile1 = "./hapVerify/signed1.hap"; + std::ofstream hapFile1; + hapFile1.open(rightFile1.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile1.is_open()); + hapFile1.seekp(0, std::ios_base::beg); + hapFile1.write(MINIHAPFILE, sizeof(MINIHAPFILE)); + hapFile1.seekp(TEST_MINI_HAP_FILE_LENGTH - sizeof(short), std::ios_base::beg); + hapFile1.close(); + resultCode = verify.Verify(rightFile1, hapVerifyResult, &options); + ASSERT_TRUE(resultCode == OHOS::SignatureTools::SIGNATURE_NOT_FOUND); + + /* + * @tc.steps: step4. use an empty file to run HapVerify. + * @tc.expected: step4. the return will be SIGNATURE_NOT_FOUND. + */ + std::string invalidFile = "./hapVerify/signed2.hap"; + std::ofstream hapFile2; + hapFile2.open(invalidFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile2.is_open()); + hapFile2.close(); + resultCode = verify.Verify(invalidFile, hapVerifyResult, &options); + ASSERT_TRUE(resultCode == OHOS::SignatureTools::SIGNATURE_NOT_FOUND); +} +/** + * @tc.name: VerifyHapTest.Verify007 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify007, TestSize.Level0) +{ + std::string outPutPath = "./test.log"; + PKCS7* p7 = nullptr; + VerifyHap verify; + bool ret = verify.HapOutPutPkcs7(p7, outPutPath); + EXPECT_EQ(ret, false); +} +/** +* @tc.name: VerifyHapTest.Verify008 +* @tc.desc: The static function will return verify result of signed file; +* @tc.type: FUNC +*/ +HWTEST_F(VerifyHapTest, Verify008, TestSize.Level0) +{ + std::string profile = ""; + std::string ret = "111"; + VerifyHap verify; + int rets = verify.GetProfileContent(profile, ret); + EXPECT_EQ(rets, -1); +} +/** + * @tc.name: VerifyHapTest.Verify009 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify009, TestSize.Level0) +{ + VerifyHap verify; + std::string profile = "{version-name: 1.0.0,version-code: 1,uuid: fe686e1b-3770-4824-a938-961b140a7c98}"; + std::string ret = "111"; + int rets = verify.GetProfileContent(profile, ret); + EXPECT_EQ(rets, -1); +} +/** + * @tc.name: VerifyHapTest.Verify010 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify010, TestSize.Level0) +{ + VerifyHap verify; + Pkcs7Context pkcs7Context; + ByteBuffer hapSignatureBlock; + bool ret = verify.VerifyAppPkcs7(pkcs7Context, hapSignatureBlock); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.Verify013 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify013, TestSize.Level0) +{ + VerifyHap verify; + ProfileInfo provisionInfo; + verify.SetOrganization(provisionInfo); +} +/** + * @tc.name: VerifyHapTest.Verify014 + * @tc.desc: The static function will return verify result; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify014, TestSize.Level0) +{ + /* + * @tc.steps: step1. input a invalid path to function of HapVerify. + * @tc.expected: step1. the return will be FILE_PATH_INVALID. + */ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/signed_test.app"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + OHOS::SignatureTools::VerifyHapResultCode targetResult = OHOS::SignatureTools::VERIFY_SUCCESS; + ASSERT_TRUE(resultCode != targetResult); + std::ofstream appFile; + appFile.open(errorFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(appFile.is_open()); + appFile.close(); + resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + ASSERT_TRUE(resultCode != targetResult); + /* + * @tc.steps: step2. create a hapfile and run HapVerify. + * @tc.expected: step2. the return will be SIGNATURE_NOT_FOUND. + */ + std::string rightFile = "./hapVerify/signed.hap"; + std::ofstream hapFile; + hapFile.open(rightFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile.is_open()); + hapFile.seekp(0, std::ios_base::beg); + hapFile.write(MINIHAPFILE, TEST_MINI_HAP_FILE_LENGTH); + hapFile.close(); + resultCode = verify.Verify(rightFile, hapVerifyResult, &options); + ASSERT_TRUE(resultCode == OHOS::SignatureTools::SIGNATURE_NOT_FOUND); + + /* + * @tc.steps: step3. create an error hapfile and run HapVerify. + * @tc.expected: step3. the return will be SIGNATURE_NOT_FOUND. + */ + std::string rightFile1 = "./hapVerify/signed1.hap"; + std::ofstream hapFile1; + hapFile1.open(rightFile1.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile1.is_open()); + hapFile1.seekp(0, std::ios_base::beg); + hapFile1.write(MINIHAPFILE, sizeof(MINIHAPFILE)); + hapFile1.seekp(TEST_MINI_HAP_FILE_LENGTH - sizeof(short), std::ios_base::beg); + hapFile1.close(); + resultCode = verify.Verify(rightFile1, hapVerifyResult, &options); + ASSERT_TRUE(resultCode == OHOS::SignatureTools::SIGNATURE_NOT_FOUND); + + /* + * @tc.steps: step4. use an empty file to run HapVerify. + * @tc.expected: step4. the return will be SIGNATURE_NOT_FOUND. + */ + std::string invalidFile = "./hapVerify/signed2.hap"; + std::ofstream hapFile2; + hapFile2.open(invalidFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(hapFile2.is_open()); + hapFile2.close(); + resultCode = verify.Verify(invalidFile, hapVerifyResult, &options); + ASSERT_TRUE(resultCode == OHOS::SignatureTools::SIGNATURE_NOT_FOUND); +} + + +/** + * @tc.name: VerifyHapTest.Verify015 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify015, TestSize.Level0) +{ + /* + * @tc.steps: step1. input a signed file to verify. + * @tc.expected: step1. the return will be VERIFY_SUCCESS. + */ + + std::string filePath = "./hapVerify/phone-default-signed.hap"; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + + VerifyHap verify; + int32_t ret = verify.Verify(filePath, hapVerifyResult, &options); + ASSERT_EQ(ret, OHOS::SignatureTools::VERIFY_SUCCESS); +} + +/** + * @tc.name: VerifyHapTest.Verify016 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify016, TestSize.Level0) +{ + std::string filePath = "./hapVerify/phone-default-signed.hap"; + std::string errorfilePath = "./hapVerify/phone-default-signed_error.hap"; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + OHOS::SignatureTools::ByteBuffer byteBuffer; + std::ifstream hapFile; + hapFile.open(filePath, std::ifstream::binary); + ASSERT_TRUE(hapFile.is_open()); + std::stringstream hapFileStr; + hapFileStr << hapFile.rdbuf(); + size_t strSize = hapFileStr.str().size(); + byteBuffer.SetCapacity(strSize); + byteBuffer.PutData(hapFileStr.str().c_str(), hapFileStr.str().size()); + hapFile.close(); + /* + * @tc.steps: step1. input a signed file to verify. + * @tc.expected: step1. the return will be VERIFY_SUCCESS. + */ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + VerifyHap verify; + ASSERT_TRUE(verify.Verify(filePath, hapVerifyResult, &options) == OHOS::SignatureTools::VERIFY_SUCCESS); + // /* + // * @tc.steps: step2. check verify result. + // * @tc.expected: step2. cert version is 1, certChains Len is 3. + // */ + OHOS::SignatureTools::ProfileInfo profile = hapVerifyResult.GetProvisionInfo(); + std::vector publicKeys = hapVerifyResult.GetPublicKey(); + ASSERT_TRUE(static_cast(publicKeys.size()) == TEST_CERT_CHAIN_LEN); + std::vector signatures = hapVerifyResult.GetSignature(); + ASSERT_TRUE(static_cast(signatures.size()) == TEST_CERT_CHAIN_LEN); + /* + * @tc.steps: step3. change comment data. + * @tc.expected: step3. the return will be VERIFY_INTEGRITY_FAIL. + */ + OHOS::SignatureTools::ByteBuffer errorCommentFile = byteBuffer; + char tmp = TEST_HAPBYTEBUFFER_CHAR_DATA; + errorCommentFile.PutByte(0, tmp); + std::ofstream errorFile; + errorFile.open(errorfilePath.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(errorFile.is_open()); + errorFile.seekp(0, std::ios_base::beg); + errorFile.write(errorCommentFile.GetBufferPtr(), errorCommentFile.GetCapacity()); + errorFile.close(); + OHOS::SignatureTools::HapVerifyResult verifyRet; + ASSERT_NE(verify.Verify(errorfilePath, verifyRet, &options), OHOS::SignatureTools::VERIFY_SUCCESS); + /* + * @tc.steps: step4. change profile pkcs7 data. + * @tc.expected: step4. the return will be APP_SOURCE_NOT_TRUSTED. + */ + errorCommentFile.PutByte(TEST_PFOFILE_PKCS7_DATA_INDEX, tmp); + errorFile.open(errorfilePath.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(errorFile.is_open()); + errorFile.seekp(0, std::ios_base::beg); + errorFile.write(errorCommentFile.GetBufferPtr(), errorCommentFile.GetCapacity()); + errorFile.close(); + ASSERT_NE(verify.Verify(errorfilePath, verifyRet, &options), OHOS::SignatureTools::VERIFY_SUCCESS); + /* + * @tc.steps: step5. change app pkcs7 data. + * @tc.expected: step5. the return will be VERIFY_APP_PKCS7_FAIL. + */ + errorCommentFile.PutByte(TEST_APP_PKCS7_DATA_INDEX, tmp); + errorFile.open(errorfilePath.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); + ASSERT_TRUE(errorFile.is_open()); + errorFile.seekp(0, std::ios_base::beg); + errorFile.write(errorCommentFile.GetBufferPtr(), errorCommentFile.GetCapacity()); + errorFile.close(); + ASSERT_NE(verify.Verify(errorfilePath, verifyRet, &options), OHOS::SignatureTools::VERIFY_SUCCESS); +} + +/** + * @tc.name: VerifyHapTest.Verify021 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify021, TestSize.Level0) +{ + std::string outPutPath = "./test.log"; + PKCS7* p7 = nullptr; + VerifyHap verify; + bool ret = verify.HapOutPutPkcs7(p7, outPutPath); + EXPECT_EQ(ret, false); +} +/** +* @tc.name: VerifyHapTest.Verify022 +* @tc.desc: The static function will return verify result of signed file; +* @tc.type: FUNC +*/ +HWTEST_F(VerifyHapTest, Verify022, TestSize.Level0) +{ + std::string profile = ""; + std::string ret = "111"; + VerifyHap verify; + int rets = verify.GetProfileContent(profile, ret); + EXPECT_EQ(rets, -1); +} +/** + * @tc.name: VerifyHapTest.Verify023 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify023, TestSize.Level0) +{ + VerifyHap verify; + std::string profile = "{version-name: 1.0.0,version-code: 1,uuid: fe686e1b-3770-4824-a938-961b140a7c98}"; + std::string ret = "111"; + int rets = verify.GetProfileContent(profile, ret); + EXPECT_EQ(rets, -1); +} +/** + * @tc.name: VerifyHapTest.Verify024 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify024, TestSize.Level0) +{ + VerifyHap verify; + Pkcs7Context pkcs7Context; + ByteBuffer hapSignatureBlock; + bool ret = verify.VerifyAppPkcs7(pkcs7Context, hapSignatureBlock); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.Verify027 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, Verify027, TestSize.Level0) +{ + VerifyHap verify; + ProfileInfo provisionInfo; + verify.SetOrganization(provisionInfo); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError001, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/unvaild.hqf"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError002, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/unvaild.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError003, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/unvaild.app"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError004, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/unvaild.hsp"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError005, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/unvaild.txt"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError006, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify_nohave/certchain.pem"; + options[Options::OUT_PROFILE] = "./hapVerify_nohava/profile.p7b"; + + std::string errorFile = "./hapVerify/phone-default-signed.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError007, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + std::shared_ptr params = std::make_shared(); + + std::string outCertChain = "./hapVerify_nohave/certchain.pem"; + std::string outProfile = "./hapVerify/profile.p7b"; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + + + std::string errorFile = "./hapVerify/phone-default-signed.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, params.get()); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError008, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + std::shared_ptr params = std::make_shared(); + + std::string outCertChain = "./hapVerify/certchain.pem"; + std::string outProfile = "./hapVerify_nohave/profile.p7b"; + (*params)["outCertChain"] = outCertChain; + (*params)["outProfile"] = outProfile; + + + std::string errorFile = "./hapVerify/phone-default-signed.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, params.get()); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError009, TestSize.Level0) +{ + Pkcs7Context pkcs7Context_t; + MatchingResult t; + t.matchState = MATCH_WITH_SIGN; + t.source = APP_THIRD_PARTY_PRELOAD; + pkcs7Context_t.matchResult = t; + VerifyHap verify; + bool ret = verify.VerifyProfileSignature(pkcs7Context_t, pkcs7Context_t); + EXPECT_NE(ret, true); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError010, TestSize.Level0) +{ + AppDistType type = APP_GALLERY; + ProfileInfo provisionInfo; + VerifyHap verify; + bool ret = verify.IsAppDistributedTypeAllowInstall(type, provisionInfo); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError011, TestSize.Level0) +{ + AppDistType type = NONE_TYPE; + ProfileInfo provisionInfo; + VerifyHap verify; + bool ret = verify.IsAppDistributedTypeAllowInstall(type, provisionInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError012, TestSize.Level0) +{ + VerifyHap verify; + Pkcs7Context digest; + ByteBuffer content("1", 1); + digest.content = content; + bool ret = verify.GetDigestAndAlgorithm(digest); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError013, TestSize.Level0) +{ + VerifyHap verify; + Pkcs7Context digest; + ByteBuffer content("12345678912345", 14); + digest.content = content; + bool ret = verify.GetDigestAndAlgorithm(digest); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError014, TestSize.Level0) +{ + VerifyHap verify; + Pkcs7Context digest; + ByteBuffer content("123456789123456789123456789", 27); + digest.content = content; + bool ret = verify.GetDigestAndAlgorithm(digest); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError015, TestSize.Level0) +{ + VerifyHap verify; + Pkcs7Context digest; + ByteBuffer content("123456789123456789123456789", 19); + digest.content = content; + bool ret = verify.GetDigestAndAlgorithm(digest); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name: VerifyHapTest.VerifyHapError001 +* @tc.desc: The static function will return verify result of signed file; +* @tc.type: FUNC +*/ +HWTEST_F(VerifyHapTest, VerifyHapError016, TestSize.Level0) +{ + bool ret = false; + VerifyHap verify; + Pkcs7Context pkcs7Context; + MatchingResult t; + t.matchState = MATCH_WITH_SIGN; + t.source = APP_GALLARY; + pkcs7Context.matchResult = t; + ByteBuffer hapProfileBlock; + ProfileInfo provisionInfo; + verify.SetProfileBlockData(pkcs7Context, hapProfileBlock, provisionInfo); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name: VerifyHapTest.VerifyHapError001 +* @tc.desc: The static function will return verify result of signed file; +* @tc.type: FUNC +*/ +HWTEST_F(VerifyHapTest, VerifyHapError017, TestSize.Level0) +{ + bool ret = false; + VerifyHap verify; + Pkcs7Context pkcs7Context; + MatchingResult t; + t.matchState = MATCH_WITH_SIGN; + t.source = APP_THIRD_PARTY_PRELOAD; + pkcs7Context.matchResult = t; + ByteBuffer hapProfileBlock; + ProfileInfo provisionInfo; + verify.SetProfileBlockData(pkcs7Context, hapProfileBlock, provisionInfo); + EXPECT_EQ(ret, false); +} + +/** +* @tc.name: VerifyHapTest.VerifyHapError001 +* @tc.desc: The static function will return verify result of signed file; +* @tc.type: FUNC +*/ +HWTEST_F(VerifyHapTest, VerifyHapError018, TestSize.Level0) +{ + bool ret = false; + VerifyHap verify; + Pkcs7Context pkcs7Context; + MatchingResult t; + t.matchState = MATCH_WITH_SIGN; + t.source = APP_THIRD_PARTY_PRELOAD; + pkcs7Context.matchResult = t; + ByteBuffer hapProfileBlock; + ProfileInfo provisionInfo; + verify.SetProfileBlockData(pkcs7Context, hapProfileBlock, provisionInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError019, TestSize.Level0) +{ + bool ret = false; + VerifyHap verify; + Pkcs7Context pkcs7Context; + Pkcs7Context profileContext; + ProfileInfo provisionInfo; + provisionInfo.type = ProvisionType::RELEASE; + provisionInfo.distributionType = APP_GALLERY; + ret = verify.VerifyProfileInfo(pkcs7Context, profileContext, provisionInfo); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError024, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.cer"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/packet_diget_algo_error.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError025, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.cer"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/packet_hap_integrity_error.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError026, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.cer"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/packet_verify_app_error.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError027, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.cer"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/packet_get_certchain_error.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError028, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.cer"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/packet_get_optional_block_error.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} + +/** + * @tc.name: VerifyHapTest.VerifyHapError001 + * @tc.desc: The static function will return verify result of signed file; + * @tc.type: FUNC + */ +HWTEST_F(VerifyHapTest, VerifyHapError029, TestSize.Level0) +{ + OHOS::SignatureTools::HapVerifyResult hapVerifyResult; + Options options; + options[Options::OUT_CERT_CHAIN] = "./hapVerify/certchain.cer"; + options[Options::OUT_PROFILE] = "./hapVerify/profile.p7b"; + + std::string errorFile = "./hapVerify/packet_parse_profile_error.hap"; + + VerifyHap verify; + int32_t resultCode = verify.Verify(errorFile, hapVerifyResult, &options); + EXPECT_NE(resultCode, 0); +} +} +} diff --git a/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_test.h b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_test.h new file mode 100644 index 0000000000000000000000000000000000000000..00a95757e39599edebf2b1f6a3c711dce31c4a57 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/hap_verify_test.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HAP_VERIFY_V2_TEST_H +#define HAP_VERIFY_V2_TEST_H + +#include + +#include "test_const.h" + +int32_t CheckFilePathTest001(void); +int32_t GenerateAppIdTest001(void); +int32_t ParseAndVerifyProfileIfNeedTest001(void); +int32_t GetDigestAndAlgorithmTest001(void); +#endif // HAP_VERIFY_V2_TEST_H diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/hap_verify_v2.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/hap_verify_v2.txt new file mode 100644 index 0000000000000000000000000000000000000000..947d98d2ffed294a5a8181f933dcf343d1047c60 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/hap_verify_v2.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/hap_verify_v3.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/hap_verify_v3.txt new file mode 100644 index 0000000000000000000000000000000000000000..f10c3888d327f1bd793cb19a749c0a2ca929c4fd Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/hap_verify_v3.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_diget_algo_error.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_diget_algo_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..e726e0857d0cc219f473b0d499b0383662acfcfe Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_diget_algo_error.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_get_certchain_error.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_get_certchain_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..6f589912b605642da31c538bd0ab082730327fc8 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_get_certchain_error.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_get_optional_block_error.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_get_optional_block_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..f65d71e299f9f358519d2459769d7c0333efec54 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_get_optional_block_error.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_hap_integrity_error.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_hap_integrity_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..e871713a51d09cf0c994356c96e53e1c3d3a2fa4 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_hap_integrity_error.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_parse_profile_error.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_parse_profile_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..702e4ab11ab7107aa856d5a744243947fd3bb113 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_parse_profile_error.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_verify_app_error.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_verify_app_error.txt new file mode 100644 index 0000000000000000000000000000000000000000..e9623cdf94b4adb1959814ecc9a59bcc87b56964 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/packet_verify_app_error.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/packets/phone-default-signed.txt b/hapsigntool_cpp/test/unittest/hapVerify/packets/phone-default-signed.txt new file mode 100644 index 0000000000000000000000000000000000000000..33a705d43869eda0396cea3bf52747895e635d23 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/hapVerify/packets/phone-default-signed.txt differ diff --git a/hapsigntool_cpp/test/unittest/hapVerify/provision_verify_test.cpp b/hapsigntool_cpp/test/unittest/hapVerify/provision_verify_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e33169db8e893d4a98b62a59d31073ab4b677cf --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/provision_verify_test.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "provision_verify_test.h" + +#include +#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" + })"; + + class ProvisionVerifyTest : public testing::Test { + public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); + }; + + void ProvisionVerifyTest::SetUpTestCase(void) + { + } + + void ProvisionVerifyTest::TearDownTestCase(void) + { + } + + void ProvisionVerifyTest::SetUp() + { + } + + 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_EQ(ret, AppProvisionVerifyResult::PROVISION_INVALID); + ret = ParseAndVerify(INVALID_PROVISION_2, info); + ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_INVALID); + ret = ParseAndVerify(INVALID_PROVISION_3, info); + ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_INVALID); + } + + /** + * @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 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 diff --git a/hapsigntool_cpp/test/unittest/hapVerify/provision_verify_test.h b/hapsigntool_cpp/test/unittest/hapVerify/provision_verify_test.h new file mode 100644 index 0000000000000000000000000000000000000000..f4cc3755b02fe86523790322d20b8058d6c9a887 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/provision_verify_test.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef PROVISION_VERIFY_TEST_H +#define PROVISION_VERIFY_TEST_H + +#include + +int32_t ProvisionVerify001(void); +int32_t ProvisionVerify002(void); +int32_t ProvisionVerify003(void); +int32_t ProvisionVerify004(void); +int32_t ProvisionVerify005(void); +int32_t ProvisionVerify006(void); +int32_t ProvisionVerify007(void); +int32_t ProvisionVerify008(void); +#endif // PROVISION_VERIFY_TEST_H diff --git a/hapsigntool_cpp/test/unittest/hapVerify/random_access_file_test.cpp b/hapsigntool_cpp/test/unittest/hapVerify/random_access_file_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09d45cbb7e8beffaa53bf4d21532ffaab1dfdaf7 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/random_access_file_test.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "random_access_file_test.h" + +#include + +#include + +#include "byte_buffer.h" +#include "random_access_file.h" +#include "hap_verify_result.h" + +#include "hap_signer_block_utils.h" +#include "hap_signer_block_utils_test.h" +#include "test_const.h" + +using namespace testing::ext; +using namespace OHOS::SignatureTools; + +namespace { + class RandomAccessFileTest : public testing::Test { + public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); + }; + + void RandomAccessFileTest::SetUpTestCase(void) + { + } + + void RandomAccessFileTest::TearDownTestCase(void) + { + } + + void RandomAccessFileTest::SetUp() + { + } + + 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; + int32_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; + long long 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); + } +} diff --git a/hapsigntool_cpp/test/unittest/hapVerify/random_access_file_test.h b/hapsigntool_cpp/test/unittest/hapVerify/random_access_file_test.h new file mode 100644 index 0000000000000000000000000000000000000000..6ef57b10a252087f51c22584386927e646c5b2b3 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/random_access_file_test.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef RANDOM_ACCESS_FILE_TEST_H +#define RANDOM_ACCESS_FILE_TEST_H + +#include + +int32_t ReadFileFullyFromOffsetTest001(void); +#endif // RANDOM_ACCESS_FILE_TEST_H diff --git a/hapsigntool_cpp/test/unittest/hapVerify/test_const.h b/hapsigntool_cpp/test/unittest/hapVerify/test_const.h new file mode 100644 index 0000000000000000000000000000000000000000..0643f2667eb8c5a6e9c458a163c6b332be39a7e9 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/test_const.h @@ -0,0 +1,435 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HAPVERIFY_TEST_CONST_H +#define HAPVERIFY_TEST_CONST_H + +#include +#include + +namespace OHOS { + namespace SignatureTools { + constexpr char TEST_HAPBYTEBUFFER_CHAR_DATA = 0xff; + constexpr unsigned short TEST_HAPBYTEBUFFER_UINT16_DATA = 0xffff; + constexpr uint32_t TEST_HAPBYTEBUFFER_UINT32_DATA = 0xffffffff; + constexpr int32_t TEST_HAPBYTEBUFFER_INT32_DATA = 0xffffffff; + constexpr long long TEST_HAPBYTEBUFFER_INT64_DATA = 0xffffffffffffffff; + constexpr int32_t TEST_HAPBYTEBUFFER_INT32_DATA_2 = 100000; + constexpr int32_t TEST_HAPBYTEBUFFER_INVALID_INDEX = -1; + + constexpr int32_t TEST_RANDOMREAD_LENGTH = 150000; + constexpr int32_t TEST_HAPBYTEBUFFER_LENGTH = 15; + constexpr int32_t TEST_HAPBYTEBUFFER_LENGTH_2 = 8; + constexpr int32_t TEST_HAPBYTEBUFFER_POSITION = 10; + + constexpr int32_t TEST_HAPBYTEBUFFER_UINT16_LENGTH = 2; + constexpr int32_t TEST_HAPBYTEBUFFER_INT64_LENGTH = 8; + + constexpr int32_t TEST_FILE_BLOCK_LENGTH = 50; + constexpr int32_t TEST_FILE_BLOCK_COUNT = 3; + + constexpr int32_t TEST_FILE_CD_OFFSET_POSITION = 6; + + constexpr int32_t TEST_HAP_SIGN_VERSION = 1; + + constexpr int32_t TEST_MAX_COMMENT_SIZE = 4; + constexpr int32_t TEST_INVALID_MAX_COMMENT_SIZE = -1; + + constexpr int32_t TEST_ZIP_EOCD_SIZE = 22; + constexpr int32_t TEST_ZIP_ECD_OFFSET_FIELD_OFFSET = 16; + constexpr int32_t TEST_ZIP_ECD_SIZE_FIELD_OFFSET = 12; + constexpr int32_t TEST_ZIP_EOCD_COMMENT_OFFSET = 20; + + constexpr int32_t TEST_NULL_NID = 118; + constexpr int32_t TEST_SHA256_NID = 672; + constexpr int32_t TEST_SHA384_NID = 673; + constexpr int32_t TEST_SHA512_NID = 674; + + constexpr int32_t TEST_MINI_HAP_FILE_LENGTH = 2619; + + constexpr int32_t TEST_SIGN_VERSION = 2; + constexpr int32_t TEST_CERT_CHAIN_LEN = 3; + + constexpr int32_t TEST_FILE_NUM = 2; + constexpr int32_t TEST_PFOFILE_PKCS7_DATA_INDEX = 5110; + constexpr int32_t TEST_APP_PKCS7_DATA_INDEX = 7000; + constexpr int32_t TEST_VERSION_CODE = 1; + + const std::string TEST_ANS_TIME = "000000000000Z"; + const std::string TEST_FINGERPRINT = "7A1B38212FE86369DECE606D901CB66C7199CC1BDC4EFF52A86EFBFFB1B99A19"; + const std::string TEST_VERSION_NAME = "1.0.0"; + + constexpr char MINIHAPFILE[] = { + 80, 75, 3, 4, 10, 0, 0, 8, 0, 0, 0, 0, 33, + 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 18, 0, + 49, 46, 116, 120, 116, 85, 84, 9, 0, 6, 49, 40, 41, + 94, 49, 40, 41, 94, -2, -54, 0, 0, 0, 0, 0, + 0, 32, -117, 9, 0, 0, 48, -126, 9, -121, 6, + 9, 42, -122, 72, -122, -9, 13, 1, 7, 2, -96, -126, 9, + 120, 48, -126, 9, 116, 2, 1, 1, 49, 15, 48, + 13, 6, 9, 96, -122, 72, 1, 101, 3, 4, 2, 1, 5, 0, 48, + -126, 3, -6, 6, 9, 42, -122, 72, -122, -9, + 13, 1, 7, 1, -96, -126, 3, -21, 4, -126, 3, -25, 44, 0, + 0, 0, 40, 0, 0, 0, 1, 1, 0, 0, 32, 0, 0, 0, + -9, 111, -2, 4, -40, -83, -50, -26, 50, -78, -26, 18, + 101, 6, -30, -100, -26, -96, 17, -84, 15, 112, + 74, -114, -67, 67, -81, -49, 19, -28, -110, 48, -77, + 3, 0, 0, -81, 3, 0, 0, 48, -126, 3, -85, 48, + -126, 2, -109, -96, 3, 2, 1, 2, 2, 20, 122, 93, -87, + 110, 73, 90, -84, 41, -27, -29, -93, 93, 59, + 56, -105, -122, -20, -75, 10, -99, 48, 13, 6, 9, 42, + -122, 72, -122, -9, 13, 1, 1, 11, 5, 0, 48, + 101, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 67, 78, 49, + 17, 48, 15, 6, 3, 85, 4, 8, 12, 8, 83, 104, + 101, 110, 122, 104, 101, 110, 49, 17, 48, 15, 6, 3, 85, + 4, 7, 12, 8, 83, 104, 101, 110, 122, 104, 101, + 110, 49, 15, 48, 13, 6, 3, 85, 4, 10, 12, 6, 72, 117, + 97, 119, 101, 105, 49, 15, 48, 13, 6, 3, 85, + 4, 11, 12, 6, 72, 117, 97, 119, 101, 105, 49, 14, 48, 12, + 6, 3, 85, 4, 3, 12, 5, 67, 104, 105, 110, 97, + 48, 30, 23, 13, 50, 48, 48, 49, 49, 48, 48, 55, 51, 54, + 53, 57, 90, 23, 13, 52, 55, 48, 53, 50, 56, + 48, 55, 51, 54, 53, 57, 90, 48, 101, 49, 11, 48, 9, 6, 3, + 85, 4, 6, 19, 2, 67, 78, 49, 17, 48, 15, 6, + 3, 85, 4, 8, 12, 8, 83, 104, 101, 110, 122, 104, 101, 110, + 49, 17, 48, 15, 6, 3, 85, 4, 7, 12, 8, 83, 104, + 101, 110, 122, 104, 101, 110, 49, 15, 48, 13, 6, 3, 85, + 4, 10, 12, 6, 72, 117, 97, 119, 101, 105, 49, + 15, 48, 13, 6, 3, 85, 4, 11, 12, 6, 72, 117, 97, 119, 101, + 105, 49, 14, 48, 12, 6, 3, 85, 4, 3, 12, 5, 67, + 104, 105, 110, 97, 48, -126, 1, 34, 48, 13, 6, 9, 42, + -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, + 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -17, -107, + -66, -22, 68, -42, -13, 116, 108, -23, 84, -30, + -19, 127, -45, -40, -60, -67, -53, -33, -114, 26, -11, + 104, 46, 103, 105, -78, -42, -32, 89, -70, 87, + 67, 32, 81, 35, 61, -121, 114, -83, 71, 8, -100, -35, 82, + -91, -3, 44, 95, -55, -118, 118, 19, 1, -50, 35, + -3, -123, 29, 103, 54, -16, -3, 36, -67, 54, 51, 2, 107, + 112, -9, -23, 40, -117, -84, -72, -7, 112, -92, + -127, 97, 122, -86, -126, 93, -37, -55, 17, 35, 118, -110, + -40, 27, -123, 2, 123, 102, 39, 117, -48, -71, + 103, -84, -105, -81, 28, -86, 118, -95, 63, 59, 107, 4, -71, + -30, 83, 39, 105, -112, -35, -15, 112, -52, -58, + -118, -114, 127, -54, -125, 46, 70, -95, -70, -11, 125, 49, + 116, -54, 34, 93, 34, 113, 119, -33, -26, -21, 13, + 69, -69, -33, -54, 87, 95, 62, -64, -125, -108, 4, -80, + -86, -11, 103, -121, 97, 122, -114, -88, -83, 59, + 119, 56, 22, 72, 35, -67, -67, -83, -60, 112, 105, 117, + 50, -19, 16, -53, 83, 103, -110, -107, 45, 5, 17, + -28, -97, -90, 59, 117, -88, 47, -86, -32, 17, -96, 111, + 88, -103, -60, -55, 20, -80, 44, 64, -48, 104, 94, + -118, 49, 72, -68, 42, 2, -9, 87, 17, -127, -43, -82, 85, + 70, 13, -98, 24, -55, -90, -51, 103, -65, -58, -97, + 52, -71, -85, -3, -118, -99, -84, 110, 2, 110, 56, -18, + -21, -109, -65, 67, 2, 3, 1, 0, 1, -93, 83, 48, 81, + 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 49, 59, -102, + -88, 25, -106, 97, 76, -15, -86, -88, -67, -85, -88, + -36, 8, -122, 3, 36, -51, 48, 31, 6, 3, 85, 29, 35, + 4, 24, 48, 22, -128, 20, 49, 59, -102, -88, 25, -106, + 97, 76, -15, -86, -88, -67, -85, -88, -36, 8, -122, + 3, 36, -51, 48, 15, 6, 3, 85, 29, 19, 1, 1, -1, 4, + 5, 48, 3, 1, 1, -1, 48, 13, 6, 9, 42, -122, 72, -122, + -9, 13, 1, 1, 11, 5, 0, 3, -126, 1, 1, 0, -33, 97, + 20, 104, -18, -45, -47, -109, 81, -55, -69, 34, -119, + -4, -78, 9, -101, 7, -42, 107, 41, -65, -115, -64, + -89, -38, 24, 103, -119, 22, -38, 60, 4, -2, 36, -94, + 103, 84, 89, 115, -93, -67, -2, -41, 124, 53, 6, 37, + 116, -30, 49, -78, 83, -110, 50, 26, 120, -58, -11, + 91, -119, -121, 87, 99, 74, -71, 23, -113, -63, -14, + -68, -44, 17, -109, 24, -94, -26, -60, 32, -8, 77, 29, + 113, 42, -94, -9, -92, -71, -57, -41, 24, -62, 2, -3, + 53, -98, -99, -32, -1, 120, -17, 26, 32, -2, -59, 85, + -22, 23, -79, 9, -72, 116, 67, 55, 118, 12, 7, 79, -83, + -103, -66, 123, -55, 5, -29, -53, 92, -95, 99, 4, -23, + 26, -121, -22, 69, 89, 7, -109, -54, -76, -59, 0, 54, + -24, -58, -42, 14, -51, -121, -14, 97, 68, -70, -122, -30, + -113, 43, -102, -34, 96, 38, -8, -14, 65, 83, -124, -104, + 27, 69, -42, -69, -30, -108, -76, -1, -47, -117, -2, + 108, 9, 61, 79, 59, 67, -18, -126, -117, 36, -14, -102, + 23, 55, -27, 97, -47, -24, 16, 102, 60, 88, 47, -59, 63, + -57, 46, -77, -112, -88, -93, -60, -120, 101, -3, 117, + -102, -113, -10, -61, -69, -122, 6, 96, -78, 28, -111, 1, + -88, -60, -123, -39, 28, -28, 40, -28, -59, -97, 77, + -45, -9, -113, 120, 84, 58, 105, 24, -35, -113, -97, 115, + -107, -3, 121, 56, -60, 75, -60, -96, -126, 3, -81, + 48, -126, 3, -85, 48, -126, 2, -109, -96, 3, 2, 1, 2, 2, + 20, 122, 93, -87, 110, 73, 90, -84, 41, -27, -29, -93, + 93, 59, 56, -105, -122, -20, -75, 10, -99, 48, 13, 6, + 9, 42, -122, 72, -122, -9, 13, 1, 1, 11, 5, 0, 48, 101, + 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 67, 78, 49, 17, + 48, 15, 6, 3, 85, 4, 8, 12, 8, 83, 104, 101, 110, 122, + 104, 101, 110, 49, 17, 48, 15, 6, 3, 85, 4, 7, 12, 8, + 83, 104, 101, 110, 122, 104, 101, 110, 49, 15, 48, 13, + 6, 3, 85, 4, 10, 12, 6, 72, 117, 97, 119, 101, 105, 49, + 15, 48, 13, 6, 3, 85, 4, 11, 12, 6, 72, 117, 97, 119, + 101, 105, 49, 14, 48, 12, 6, 3, 85, 4, 3, 12, 5, 67, 104, + 105, 110, 97, 48, 30, 23, 13, 50, 48, 48, 49, 49, 48, + 48, 55, 51, 54, 53, 57, 90, 23, 13, 52, 55, 48, 53, 50, + 56, 48, 55, 51, 54, 53, 57, 90, 48, 101, 49, 11, 48, + 9, 6, 3, 85, 4, 6, 19, 2, 67, 78, 49, 17, 48, 15, 6, 3, + 85, 4, 8, 12, 8, 83, 104, 101, 110, 122, 104, 101, 110, + 49, 17, 48, 15, 6, 3, 85, 4, 7, 12, 8, 83, 104, 101, + 110, 122, 104, 101, 110, 49, 15, 48, 13, 6, 3, 85, 4, + 10, 12, 6, 72, 117, 97, 119, 101, 105, 49, 15, 48, 13, + 6, 3, 85, 4, 11, 12, 6, 72, 117, 97, 119, 101, 105, 49, + 14, 48, 12, 6, 3, 85, 4, 3, 12, 5, 67, 104, 105, 110, + 97, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, + -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, + 10, 2, -126, 1, 1, 0, -17, -107, -66, -22, 68, -42, -13, + 116, 108, -23, 84, -30, -19, 127, -45, -40, -60, -67, + -53, -33, -114, 26, -11, 104, 46, 103, 105, -78, -42, + -32, 89, -70, 87, 67, 32, 81, 35, 61, -121, 114, -83, 71, + 8, -100, -35, 82, -91, -3, 44, 95, -55, -118, 118, 19, + 1, -50, 35, -3, -123, 29, 103, 54, -16, -3, 36, -67, 54, + 51, 2, 107, 112, -9, -23, 40, -117, -84, -72, -7, 112, + -92, -127, 97, 122, -86, -126, 93, -37, -55, 17, 35, 118, + -110, -40, 27, -123, 2, 123, 102, 39, 117, -48, -71, + 103, -84, -105, -81, 28, -86, 118, -95, 63, 59, 107, 4, + -71, -30, 83, 39, 105, -112, -35, -15, 112, -52, -58, + -118, -114, 127, -54, -125, 46, 70, -95, -70, -11, 125, + 49, 116, -54, 34, 93, 34, 113, 119, -33, -26, -21, 13, + 69, -69, -33, -54, 87, 95, 62, -64, -125, -108, 4, -80, + -86, -11, 103, -121, 97, 122, -114, -88, -83, 59, 119, 56, + 22, 72, 35, -67, -67, -83, -60, 112, 105, 117, 50, + -19, 16, -53, 83, 103, -110, -107, 45, 5, 17, -28, -97, + -90, 59, 117, -88, 47, -86, -32, 17, -96, 111, 88, + -103, -60, -55, 20, -80, 44, 64, -48, 104, 94, -118, 49, + 72, -68, 42, 2, -9, 87, 17, -127, -43, -82, 85, 70, + 13, -98, 24, -55, -90, -51, 103, -65, -58, -97, 52, -71, + -85, -3, -118, -99, -84, 110, 2, 110, 56, -18, -21, + -109, -65, 67, 2, 3, 1, 0, 1, -93, 83, 48, 81, 48, 29, 6, + 3, 85, 29, 14, 4, 22, 4, 20, 49, 59, -102, -88, 25, + -106, 97, 76, -15, -86, -88, -67, -85, -88, -36, 8, -122, + 3, 36, -51, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, + -128, 20, 49, 59, -102, -88, 25, -106, 97, 76, -15, -86, + -88, -67, -85, -88, -36, 8, -122, 3, 36, -51, 48, 15, + 6, 3, 85, 29, 19, 1, 1, -1, 4, 5, 48, 3, 1, 1, -1, 48, + 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 11, 5, 0, 3, + -126, 1, 1, 0, -33, 97, 20, 104, -18, -45, -47, -109, + 81, -55, -69, 34, -119, -4, -78, 9, -101, 7, -42, 107, 41, + -65, -115, -64, -89, -38, 24, 103, -119, 22, -38, 60, + 4, -2, 36, -94, 103, 84, 89, 115, -93, -67, -2, -41, 124, + 53, 6, 37, 116, -30, 49, -78, 83, -110, 50, 26, 120, + -58, -11, 91, -119, -121, 87, 99, 74, -71, 23, -113, -63, + -14, -68, -44, 17, -109, 24, -94, -26, -60, 32, -8, 77, + 29, 113, 42, -94, -9, -92, -71, -57, -41, 24, -62, 2, + -3, 53, -98, -99, -32, -1, 120, -17, 26, 32, -2, -59, + 85, -22, 23, -79, 9, -72, 116, 67, 55, 118, 12, 7, 79, + -83, -103, -66, 123, -55, 5, -29, -53, 92, -95, 99, + 4, -23, 26, -121, -22, 69, 89, 7, -109, -54, -76, -59, 0, + 54, -24, -58, -42, 14, -51, -121, -14, 97, 68, -70, + -122, -30, -113, 43, -102, -34, 96, 38, -8, -14, 65, 83, + -124, -104, 27, 69, -42, -69, -30, -108, -76, -1, + -47, -117, -2, 108, 9, 61, 79, 59, 67, -18, -126, -117, 36, + -14, -102, 23, 55, -27, 97, -47, -24, 16, 102, 60, + 88, 47, -59, 63, -57, 46, -77, -112, -88, -93, -60, -120, + 101, -3, 117, -102, -113, -10, -61, -69, -122, 6, + 96, -78, 28, -111, 1, -88, -60, -123, -39, 28, -28, 40, -28, + -59, -97, 77, -45, -9, -113, 120, 84, 58, 105, 24, + -35, -113, -97, 115, -107, -3, 121, 56, -60, 75, -60, 49, + -126, 1, -85, 48, -126, 1, -89, 2, 1, 1, 48, 125, + 48, 101, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 67, 78, 49, + 17, 48, 15, 6, 3, 85, 4, 8, 19, 8, 83, 104, 101, + 110, 122, 104, 101, 110, 49, 17, 48, 15, 6, 3, 85, 4, 7, 19, + 8, 83, 104, 101, 110, 122, 104, 101, 110, 49, 15, + 48, 13, 6, 3, 85, 4, 10, 19, 6, 72, 117, 97, 119, 101, 105, + 49, 15, 48, 13, 6, 3, 85, 4, 11, 19, 6, 72, 117, + 97, 119, 101, 105, 49, 14, 48, 12, 6, 3, 85, 4, 3, 19, 5, 67, + 104, 105, 110, 97, 2, 20, 122, 93, -87, 110, 73, + 90, -84, 41, -27, -29, -93, 93, 59, 56, -105, -122, -20, -75, + 10, -99, 48, 13, 6, 9, 96, -122, 72, 1, 101, 3, 4, + 2, 1, 5, 0, 48, 14, 6, 10, 42, -122, 72, -122, -9, 13, 1, 1, + -113, 95, 5, 0, 4, -126, 1, 0, 10, -19, -16, -126, + -10, -94, 59, 95, 83, 115, -33, 23, 97, -30, -91, -114, 59, + 93, 97, -15, -12, 60, 39, -53, 28, -25, -6, 32, + -48, 120, -97, 64, 125, 23, -9, 53, 104, -122, 18, -5, 122, 126, + 19, -80, 53, 14, 70, 21, 63, -99, -76, -52, -2, + 103, -114, 95, -21, -60, -49, -42, -81, 58, -16, -23, 19, 108, + -30, -32, -12, -103, -107, 25, 33, 85, 61, 2, 30, 17, 0, 117, + -63, -12, -112, 60, 12, 58, 114, 126, 24, -25, + -123, 32, 19, 99, 54, -2, -78, -23, 126, 61, 46, 61, 4, -114, + -36, 53, -1, -71, 22, -10, 127, 63, -10, -73, + 51, -74, -8, 80, -34, 63, 57, -17, 106, 100, -109, -27, -30, + 46, 35, -85, -91, -20, -72, -128, 22, -97, 107, + 101, 21, 63, -36, 50, -69, 99, -10, -88, 52, 19, -115, 67, 53, + 53, 30, -107, 122, -123, -118, -56, 80, -50, + -58, 30, 110, -109, -14, 50, 18, 2, -46, 102, 64, 6, -71, 25, + 71, -36, 95, -121, -7, -11, 90, 18, 20, 96, + -6, -61, 59, 90, -1, 64, -111, 73, 82, 50, -61, 111, 41, -29, + -102, 100, -100, -73, 42, -88, 21, -64, -122, + 8, 117, -65, 47, 86, -55, -37, -14, 20, 60, 91, -22, -101, 90, + -18, 10, -101, -40, 64, -110, -120, 119, -7, + -41, -109, 82, -2, -122, 72, 74, 44, 54, -48, -51, -52, -37, + -56, -10, -8, 78, 64, -105, 59, -71, 54, -25, + -9, 105, 29, -95, 0, 1, 0, 0, 0, -77, 9, 0, 0, 0, 0, 0, 0, 72, + 65, 80, 32, 83, 105, 103, 32, 66, 108, 111, + 99, 107, 32, 52, 50, 1, 0, 0, 0, 80, 75, 1, 2, 10, 0, 10, 0, + 0, 8, 0, 0, 0, 0, 33, 58, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 49, 46, 116, 120, 116, 85, 84, 1, 0, 6, + -2, -54, 0, 0, 0, 80, 75, 5, 6, 0, 0, 0, 0, 1, 0, 1, 0, 61, + 0, 0, 0, -24, 9, 0, 0, 0, 0, -33, -26, -21, 13, 69, + -69, -33, -54, 87, 95, 62, -64, -125, -108, 4, -80, -86, -11, + 103, -121, 97, 122, -114, -88, -83, 59, 119, 56, + 22, 72, 35, -67, -67, -83, -60, 112, 105, 117, 50, -19, 16, + -53, 83, 103, -110, -107, 45, 5, 17, -28, -97, -90, + 59, 117, -88, 47, -86, -32, 17, -96, 111, 88, -103, -60, -55, + 20, -80, 44, 64, -48, 104, 94, -118, 49, 72, -68, + 42, 2, -9, 87, 17, -127, -43, -82, 85, 70, 13, -98, 24, -55, + -90, -51, 103, -65, -58, -97, 52, -71, -85, -3, + -118, -99, -84, 110, 2, 110, 56, -18, -21, -109, -65, 67, 2, + 3, 1, 0, 1, -93, 83, 48, 81, 48, 29, 6, 3, 85, 29, + 14, 4, 22, 4, 20, 49, 59, -102, -88, 25, -106, 97, 76, -15, + -86, -88, -67, -85, -88, -36, 8, -122, 3, 36, -51, + 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 49, 59, + -102, -88, 25, -106, 97, 76, -15, -86, -88, -67, -85, + -88, -36, 8, -122, 3, 36, -51, 48, 15, 6, 3, 85, 29, 19, 1, + 1, -1, 4, 5, 48, 3, 1, 1, -1, 48, 13, 6, 9, 42, -122, + 72, -122, -9, 13, 1, 1, 11, 5, 0, 3, -126, 1, 1, 0, -33, 97, + 20, 104, -18, -45, -47, -109, 81, -55, -69, 34, -119, + -4, -78, 9, -101, 7, -42, 107, 41, -65, -115, -64, -89, -38, + 24, 103, -119, 22, -38, 60, 4, -2, 36, -94, 103, 84, + 89, 115, -93, -67, -2, -41, 124, 53, 6, 37, 116, -30, 49, + -78, 83, -110, 50, 26, 120, -58, -11, 91, -119, -121, + 87, 99, 74, -71, 23, -113, -63, -14, -68, -44, 17, -109, 24, + -94, -26, -60, 32, -8, 77, 29, 113, 42, -94, -9, + -92, -71, -57, -41, 24, -62, 2, -3, 53, -98, -99, -32, -1, + 120, -17, 26, 32, -2, -59, 85, -22, 23, -79, 9, -72, + 116, 67, 55, 118, 12, 7, 79, -83, -103, -66, 123, -55, 5, + -29, -53, 92, -95, 99, 4, -23, 26, -121, -22, 69, 89, + 7, -109, -54, -76, -59, 0, 54, -24, -58, -42, 14, -51, -121, + -14, 97, 68, -70, -122, -30, -113, 43, -102, -34, + 96, 38, -8, -14, 65, 83, -124, -104, 27, 69, -42, -69, -30, + -108, -76, -1, -47, -117, -2, 108, 9, 61, 79, 59, + 67, -18, -126, -117, 36, -14, -102, 23, 55, -27, 97, -47, + -24, 16, 102, 60, 88, 47, -59, 63, -57, 46, -77, + -112, -88, -93, -60, -120, 101, -3, 117, -102, -113, -10, + -61, -69, -122, 6, 96, -78, 28, -111, 1, -88, -60, + -123, -39, 28 + }; + + const std::string ROOTCERT = "-----BEGIN CERTIFICATE-----\n" + "MIICGjCCAaGgAwIBAgIIShhpn519jNAwCgYIKoZIzj0EAwMwUzELMAkGA1UEBhMC\n" + "Q04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEeMBwGA1UE\n" + "AwwVSHVhd2VpIENCRyBSb290IENBIEcyMB4XDTIwMDMxNjAzMDQzOVoXDTQ5MDMx\n" + "NjAzMDQzOVowUzELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UE\n" + "CwwKSHVhd2VpIENCRzEeMBwGA1UEAwwVSHVhd2VpIENCRyBSb290IENBIEcyMHYw\n" + "EAYHKoZIzj0CAQYFK4EEACIDYgAEWidkGnDSOw3/HE2y2GHl+fpWBIa5S+IlnNrs\n" + "GUvwC1I2QWvtqCHWmwFlFK95zKXiM8s9yV3VVXh7ivN8ZJO3SC5N1TCrvB2lpHMB\n" + "wcz4DA0kgHCMm/wDec6kOHx1xvCRo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0T\n" + "AQH/BAUwAwEB/zAdBgNVHQ4EFgQUo45a9Vq8cYwqaiVyfkiS4pLcIAAwCgYIKoZI\n" + "zj0EAwMDZwAwZAIwMypeB7P0IbY7c6gpWcClhRznOJFj8uavrNu2PIoz9KIqr3jn\n" + "BlBHJs0myI7ntYpEAjBbm8eDMZY5zq5iMZUC6H7UzYSix4Uy1YlsLVV738PtKP9h\n" + "FTjgDHctXJlC5L7+ZDY=\n-----END CERTIFICATE-----\n"; + + const std::string SOFT_CA_CERT = "-----BEGIN CERTIFICATE-----\n" + "MIIDADCCAoegAwIBAgIIJGDixWQS3MkwCgYIKoZIzj0EAwMwUzELMAkGA1UEBhMC\n" + "Q04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEeMBwGA1UE\n" + "AwwVSHVhd2VpIENCRyBSb290IENBIEcyMB4XDTIwMDMxNjEyMzIzOVoXDTQwMDMx\n" + "NjEyMzIzOVowZDELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UE\n" + "CwwKSHVhd2VpIENCRzEvMC0GA1UEAwwmSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWdu\n" + "aW5nIFNlcnZpY2UgQ0EwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAASsEz7cwYkzFh9b\n" + "xIwKfXx5qHGjl5WITy0teGnNWqv+jYCceeixHqErvK7YRn2hVPIqhRqKWeANHZUK\n" + "G0qxi+NIpmSmQS8/63CLz1QAcxfv2Xl3/V82dF0v9lm16ehMsN+jggEVMIIBETAf\n" + "BgNVHSMEGDAWgBSjjlr1WrxxjCpqJXJ+SJLiktwgADAdBgNVHQ4EFgQU+vX3viBW\n" + "XV3U2m3xFBU8HQnbsjQwDwYDVR0TAQH/BAUwAwEB/zBGBgNVHSAEPzA9MDsGBFUd\n" + "IAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9j\n" + "cGtpL2NwczAOBgNVHQ8BAf8EBAMCAQYwZgYDVR0fBF8wXTBboFmgV4ZVaHR0cDov\n" + "L2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24u\n" + "Y3JsP2NlcnR5cGU9MTAmL3Jvb3RfZzJfY3JsLmNybDAKBggqhkjOPQQDAwNnADBk\n" + "AjBrAQQxUlNgqhYkcEm5eksnPxDkPJSY/qNd2BDgbvEydiLwPSvB7Z9lipxz8ikZ\n" + "EeUCMGppWcaV//SIG1y5tEwthLwWeEaF613vUILWQLir8+CA3RZGsRBqtE8xSqfz\n" + "yafLYQ==\n-----END CERTIFICATE-----\n"; + + const std::string UAT_SOFT_SIGN_CA = "-----BEGIN CERTIFICATE-----\n" + "MIIDCjCCApGgAwIBAgIIWbEqGvOqT10wCgYIKoZIzj0EAwMwWDELMAkGA1UEBhMC\n" + "Q04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEjMCEGA1UE\n" + "AwwaSHVhd2VpIENCRyBSb290IENBIEcyIFRlc3QwHhcNMjAwMzEzMTE1ODI4WhcN\n" + "NDAwMzEzMTE1ODI4WjBpMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMw\n" + "EQYDVQQLDApIdWF3ZWkgQ0JHMTQwMgYDVQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJl\n" + "IFNpZ25pbmcgU2VydmljZSBDQSBUZXN0MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\n" + "ukPDS3s0TpYa/lANCTc7eX8fdGGjMPUbvso3TtlBvzdm0XDNTdVtZq3XVOfefgpE\n" + "OaC/JSoXgiNHkeEQ4XSSm0d7MbeoYEyoEKWa1G2/SOQxbVNqKLexxlGMjMuOLdMb\n" + "o4IBFTCCAREwHwYDVR0jBBgwFoAUaV3AWPH1POb9CkDxHWBz3Bx4xsUwHQYDVR0O\n" + "BBYEFHu4R1Kn8cxYnvtV7OEtcQ4Hmi8mMA8GA1UdEwEB/wQFMAMBAf8wRgYDVR0g\n" + "BD8wPTA7BgRVHSAAMDMwMQYIKwYBBQUHAgEWJWh0dHA6Ly9jcGtpLWNhd2ViLmh1\n" + "YXdlaS5jb20vY3BraS9jcHMwDgYDVR0PAQH/BAQDAgEGMGYGA1UdHwRfMF0wW6BZ\n" + "oFeGVWh0dHA6Ly9jcGtpLWNhd2ViLmh1YXdlaS5jb20vY3BraS9zZXJ2bGV0L2Ny\n" + "bEZpbGVEb3duLmNybD9jZXJ0eXBlPTEwJi9yb290X2cyX2NybC5jcmwwCgYIKoZI\n" + "zj0EAwMDZwAwZAIwF7PjIuOODhpDhzpw2cqV/xbLNJ5CExFJHxcy1D0bHljE5xTt\n" + "csIN40Ma6aEi3MJQAjAHQLfAzZvMmreYwKnc2bHXlS68roSRvNTvrUKp3Lcp92nK\n" + "MzieiyKHlWKEgrUjnKc=\n-----END CERTIFICATE-----\n"; + + const std::string ECC_TEST_KEY = "-----BEGIN EC PARAMETERS-----\n" + "BggqhkjOPQMBBw==\n-----END EC PARAMETERS-----\n" + "-----BEGIN EC PRIVATE KEY-----\n" + "MHcCAQEEIPPNgGEGZA97B5g54d0D8kDBIOYS1LDldMGRf1aifZauoAoGCCqGSM49\n" + "AwEHoUQDQgAE4BehGAUU+XDXxtlQ+7Ct4sILmYL7CligKCSWbRw0YsBp4F20626u\n" + "8+T9xNlH7pGc5moba0EKy003FH1sVbtEtg==\n-----END EC PRIVATE KEY-----\n"; + + const std::string ECC_TEST_CERT = "-----BEGIN CERTIFICATE-----\n" + "MIIBkjCCATgCCQCncuWaDED8pjAKBggqhkjOPQQDAjBQMQswCQYDVQQGEwJDTjEM\n" + "MAoGA1UECgwDQ0JHMRwwGgYDVQQLDBNDQkcgSE9TIHNpZ25lZCBUZWFtMRUwEwYD\n" + "VQQDDAxIT1MgdW5pdHRlc3QwIBcNMjAwNDI3MDQwNDQ2WhgPMjEyMDA0MDMwNDA0\n" + "NDZaMFAxCzAJBgNVBAYTAkNOMQwwCgYDVQQKDANDQkcxHDAaBgNVBAsME0NCRyBI\n" + "T1Mgc2lnbmVkIFRlYW0xFTATBgNVBAMMDEhPUyB1bml0dGVzdDBZMBMGByqGSM49\n" + "AgEGCCqGSM49AwEHA0IABOAXoRgFFPlw18bZUPuwreLCC5mC+wpYoCgklm0cNGLA\n" + "aeBdtOturvPk/cTZR+6RnOZqG2tBCstNNxR9bFW7RLYwCgYIKoZIzj0EAwIDSAAw\n" + "RQIhALYbUacS0XrpPzVatHMpHnCmYgsi28hf1UTBNk+iPG/9AiBGh25CpFoDmGqb\n" + "fz5ebYSvkSe1KNtVHUTprMBQeWaB0A==\n" + "-----END CERTIFICATE-----\n"; + + const std::string APP_SIGN_TEST = "-----BEGIN CERTIFICATE-----\n" + "MIIDHjCCAqWgAwIBAgIISwRVtFpC3o0wCgYIKoZIzj0EAwMwaTELMAkGA1UEBhMC\n" + "Q04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzE0MDIGA1UE\n" + "AwwrSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWduaW5nIFNlcnZpY2UgQ0EgVGVzdDAe\n" + "Fw0yMDA0MjcxMjQyMjJaFw0yMzA0MjcxMjQyMjJaMGUxCzAJBgNVBAYTAkNOMRMw\n" + "EQYDVQQKDApIdWF3ZWkgQ0JHMR0wGwYDVQQLDBRIT1MgRGV2ZWxvcG1lbnQgVGVh\n" + "bTEiMCAGA1UEAwwZSE9TIEFwcGxpY2F0aW9uIFByb3Zpc2lvbjBZMBMGByqGSM49\n" + "AgEGCCqGSM49AwEHA0IABNrFL0TBoPUBcwLCT+jzlDatUBcxv8l4/3xirQkSgPq8\n" + "ZTsrVChJE51ZotHcDN8QOtLfEJZC92ev+hAqksltfDKjggE5MIIBNTAfBgNVHSME\n" + "GDAWgBR7uEdSp/HMWJ77VezhLXEOB5ovJjAdBgNVHQ4EFgQU80TcTfc+VizmL+/V\n" + "0fFAXwsh2vgwRgYDVR0gBD8wPTA7BgRVHSAAMDMwMQYIKwYBBQUHAgEWJWh0dHA6\n" + "Ly9jcGtpLWNhd2ViLmh1YXdlaS5jb20vY3BraS9jcHMwDgYDVR0PAQH/BAQDAgeA\n" + "MGwGA1UdHwRlMGMwYaBfoF2GW2h0dHA6Ly9jcGtpLWNhd2ViLmh1YXdlaS5jb20v\n" + "Y3BraS9zZXJ2bGV0L2NybEZpbGVEb3duLmNybD9jZXJ0eXBlPTE0Ji9zb2Z0X3Np\n" + "Z25fc3J2X2NybC5jcmwwEwYDVR0lBAwwCgYIKwYBBQUHAwMwGAYMKwYBBAGPWwKC\n" + "eAECBAgwBgIBAQoBADAKBggqhkjOPQQDAwNnADBkAjAqTxz2Z9F1HaPVoBD2e3fL\n" + "VXWASZx+YGFMpN0pyCGScDQr4zj+MXuNKewv13M+yaICMHCemT39agd/dHF+sorJ\n" + "Gz6qDn/r0hmkeHoCzUwA0Dwq/417Re81BbZvHHv7yPO7jw==\n" + "-----END CERTIFICATE-----\n"; + + const std::string BASE64_NOT_URL_SAFE_CERT = + "MIIDLDCCArOgAwIBAgIIRBvbxEi6hzwwCgYIKoZIzj0EAwMwaTELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwK" + "SHVhd2VpIENCRzE0MDIGA1UEAwwrSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWduaW5nIFNlcnZpY2UgQ0EgVGVzdDAeFw0yMDA0MjkxMTUw" + "NTlaFw0yMzA0MjkxMTUwNTlaMHMxCzAJBgNVBAYTAkNOMRMwEQYDVQQKDApIdWF3ZWkgQ0JHMR0wGwYDVQQLDBRIT1MgRGV2ZWxvcG1l" + "bnQgVGVhbTEwMC4GA1UEAwwnSE9TIEFwcGxpY2F0aW9uIFByb3Zpc2lvbiBQcm9maWxlIERlYnVnMFkwEwYHKoZIzj0CAQYIKoZIzj0D" + "AQcDQgAEcS/2lY4sb1EHegznTHYurPL4isgkq/AS4r8TqTnAkP2GI3N/e/+AX9MvdNQrCdNObSp/jXikxnU/Ng/m/pL0UaOCATkwggE1" + "MB8GA1UdIwQYMBaAFHu4R1Kn8cxYnvtV7OEtcQ4Hmi8mMB0GA1UdDgQWBBSOm2cVJTbTlMJF+CJer6HVFCC1iDBGBgNVHSAEPzA9MDsG" + "BFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8BAf8EBAMCB4AwbAYD" + "VR0fBGUwYzBhoF+gXYZbaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24uY3JsP2NlcnR5" + "cGU9MTQmL3NvZnRfc2lnbl9zcnZfY3JsLmNybDATBgNVHSUEDDAKBggrBgEFBQcDAzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoG" + "CCqGSM49BAMDA2cAMGQCMBs+JL4mtRpANjBvrv4zPQr/dE9Fk+eS/rj38qwkMM2CyDdoo0akI8HQ+fNGJP6JKwIwJqNjupjVsQ60b2tQ" + "AQSLisHmegx5s7USRD3dlpcUEGnepWMop1r8D4Ko8jHsKOX7"; + + const std::string BASE64_CRL = + "MIIBLTCBswIBATAKBggqhkjOPQQDAzBTMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMR4w" + "HAYDVQQDDBVIdWF3ZWkgQ0JHIFJvb3QgQ0EgRzIXDTIwMDMyNjE2NDkwNVoXDTMwMDMyNTAxMzgzM1qgLzAtMB8GA1UdIwQYMBaAFKOO" + "WvVavHGMKmolcn5IkuKS3CAAMAoGA1UdFAQDAgEAMAoGCCqGSM49BAMDA2kAMGYCMQCuQOz7IvwENw/Mf1ytoXT5AHiknrrOaw/dqTuZ" + "RR0wcxP5IJqI1I3Bg5WNbUmTomMCMQDIs23wc9iLgvuDOmMQia4srWunydbbslpFNfV3SIIhtyWDIPVch7RTf/s92HqnrVw="; + + } // SignatureTools +} // OHOS +#endif // HAPVERIFY_TEST_CONST_H diff --git a/hapsigntool_cpp/test/unittest/hapVerify/test_hap_file_data.h b/hapsigntool_cpp/test/unittest/hapVerify/test_hap_file_data.h new file mode 100644 index 0000000000000000000000000000000000000000..aa75bd15a25ab57d8ac81262d5e05b24003b0bad --- /dev/null +++ b/hapsigntool_cpp/test/unittest/hapVerify/test_hap_file_data.h @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef TEST_HAP_FILE_DATA_H +#define TEST_HAP_FILE_DATA_H + +#include + +namespace OHOS { + namespace SignatureTools { + + const std::string HAP_FILE_ECC_SIGN_BASE64 = + "UEsDBBQACAgIAAAAIToAAAAAAAAAAAAAAAAFAAQAMS50eHT+ygAAMzQEAFBLBwh3FVrWBAAAAAIAAAACAAAg2hMAABgAAAAAAAAgmA0AAP" + "ITAAAwghPWBgkqhkiG9w0BBwKgghPHMIITwwIBATEPMA0GCWCGSAFlAwQCAQUAMIIGhAYJKoZIhvcNAQcBoIIGdQSCBnF7InZlcnNpb24t" + "bmFtZSI6IjEuMC4wIiwidmVyc2lvbi1jb2RlIjoxLCJhcHAtZGlzdHJpYnV0aW9uLXR5cGUiOiJvc19pbnRlZ3JhdGlvbiIsInV1aWQiOi" + "I5OEE3Rjc3Mi01ODRCLTRFRDctOTczRC1CMDg4M0YwRjE5RUYiLCJ2YWxpZGl0eSI6eyJub3QtYmVmb3JlIjoxNTg2NDIyNzQzLCJub3Qt" + "YWZ0ZXIiOjI1MzU2OTk4NDN9LCJ0eXBlIjoicmVsZWFzZSIsImJ1bmRsZS1pbmZvIjp7ImRldmVsb3Blci1pZCI6Inpob25neGlhbmciLC" + "JkaXN0cmlidXRpb24tY2VydGlmaWNhdGUiOiItLS0tLUJFR0lOIENFUlRJRklDQVRFLS0tLS1cbk1JSUREVENDQXBPZ0F3SUJBZ0lJYmZG" + "eTVTaXR3ME13Q2dZSUtvWkl6ajBFQXdNd2FURUxNQWtHQTFVRUJoTUNcblEwNHhEekFOQmdOVkJBb01Ca2gxWVhkbGFURVRNQkVHQTFVRU" + "N3d0tTSFZoZDJWcElFTkNSekUwTURJR0ExVUVcbkF3d3JTSFZoZDJWcElFTkNSeUJUYjJaMGQyRnlaU0JUYVdkdWFXNW5JRk5sY25acFky" + "VWdRMEVnVkdWemREQWVcbkZ3MHlNREEwTWpnd016SXlNRGRhRncwek1EQTBNamd3TXpJeU1EZGFNRkF4Q3pBSkJnTlZCQVlUQWtOT01ROH" + "dcbkRRWURWUVFLREFaSWRXRjNaV2t4RXpBUkJnTlZCQXNNQ2toMVlYZGxhU0JEUWtjeEd6QVpCZ05WQkFNTUVucG9cbmIyNW5lR2xoYm1k" + "ZmNtVnNaV0Z6WlRCMk1CQUdCeXFHU000OUFnRUdCU3VCQkFBaUEySUFCRzEzc1J3RjJVeXVcblVTdFpoblJLV3ZKMkxHZGdOTGxEMk54cj" + "RCRWtBUnVQVnB2aDBvMGV0UmpxSEFjZ1k3K0c1dmpobytLL01zSHlcbjVPeHJ3clBaenFmT2dsSjlvL2ZNakJNR2I2VUVzWS9ncE5xd1Vi" + "WjNEdU5uZmt6VFo2QldMcU9DQVI4d2dnRWJcbk1COEdBMVVkSXdRWU1CYUFGSHU0UjFLbjhjeFludnRWN09FdGNRNEhtaThtTUIwR0ExVW" + "REZ1FXQkJTcXAwa3Fcbi9UQ29tKzc2R2YrNzBGcjROYXAyNHpCR0JnTlZIU0FFUHpBOU1Ec0dCRlVkSUFBd016QXhCZ2dyQmdFRkJRY0Nc" + "bkFSWWxhSFIwY0RvdkwyTndhMmt0WTJGM1pXSXVhSFZoZDJWcExtTnZiUzlqY0d0cEwyTndjekFPQmdOVkhROEJcbkFmOEVCQU1DQjRBd2" + "JBWURWUjBmQkdVd1l6QmhvRitnWFlaYmFIUjBjRG92TDJOd2Eya3RZMkYzWldJdWFIVmhcbmQyVnBMbU52YlM5amNHdHBMM05sY25ac1pY" + "UXZZM0pzUm1sc1pVUnZkMjR1WTNKc1AyTmxjblI1Y0dVOU1UUW1cbkwzTnZablJmYzJsbmJsOXpjblpmWTNKc0xtTnliREFUQmdOVkhTVU" + "VEREFLQmdnckJnRUZCUWNEQXpBS0JnZ3Fcbmhrak9QUVFEQXdOb0FEQmxBakE1Y2VicEo2alQzL1A5b3N0S2V6UGl3cGRNODUvTnRneWp3" + "QU4wQi82SUZIYlZcblNDWllMcStZcXNQYUt2SXh4RkVDTVFESUgxeDZUTVdwZmJNV2M4N0R5OTZ4Q0hLbEtsU0tkalM2dXZML210N2Zcbk" + "YzT3o1QXIxZFhuVDRBSi9RYzFsUHNrPVxuLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLVxuIiwiYnVuZGxlLW5hbWUiOiJjb20uaHVhd2Vp" + "Lmhpd29ybGQuaGlkZW1vIiwiYXBwLWZlYXR1cmUiOiJob3Nfbm9ybWFsX2FwcCJ9LCJwZXJtaXNzaW9ucyI6eyJyZXN0cmljdGVkLXBlcm" + "1pc3Npb25zIjpbImhhcm1vbnlvcy5wZXJtaXNzaW9uLkFOU1dFUl9QSE9ORV9DQUxMIiwiQkJCIl0sInJlc3RyaWN0ZWQtY2FwYWJpbGl0" + "aWVzIjpbIkNDQyIsImRkZCJdfSwiaXNzdWVyIjoiSHVhd2VpIEFwcHMgU3RvcmUifaCCBj4wggMKMIICkaADAgECAghZsSoa86pPXTAKBg" + "gqhkjOPQQDAzBYMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMSMwIQYDVQQDDBpIdWF3ZWkg" + "Q0JHIFJvb3QgQ0EgRzIgVGVzdDAeFw0yMDAzMTMxMTU4MjhaFw00MDAzMTMxMTU4MjhaMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdW" + "F3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3Qw" + "djAQBgcqhkjOPQIBBgUrgQQAIgNiAAS6Q8NLezROlhr+UA0JNzt5fx90YaMw9Ru+yjdO2UG/N2bRcM1N1W1mrddU595+CkQ5oL8lKheCI0" + "eR4RDhdJKbR3sxt6hgTKgQpZrUbb9I5DFtU2oot7HGUYyMy44t0xujggEVMIIBETAfBgNVHSMEGDAWgBRpXcBY8fU85v0KQPEdYHPcHHjG" + "xTAdBgNVHQ4EFgQUe7hHUqfxzFie+1Xs4S1xDgeaLyYwDwYDVR0TAQH/BAUwAwEB/zBGBgNVHSAEPzA9MDsGBFUdIAAwMzAxBggrBgEFBQ" + "cCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8BAf8EBAMCAQYwZgYDVR0fBF8wXTBboFmgV4ZVaHR0" + "cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24uY3JsP2NlcnR5cGU9MTAmL3Jvb3RfZzJfY3JsLm" + "NybDAKBggqhkjOPQQDAwNnADBkAjAXs+Mi444OGkOHOnDZypX/Fss0nkITEUkfFzLUPRseWMTnFO1ywg3jQxrpoSLcwlACMAdAt8DNm8ya" + "t5jAqdzZsdeVLryuhJG81O+tQqnctyn3acozOJ6LIoeVYoSCtSOcpzCCAywwggKxoAMCAQICCC0zffQhq5r9MAoGCCqGSM49BAMDMGkxCz" + "AJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUg" + "U2lnbmluZyBTZXJ2aWNlIENBIFRlc3QwHhcNMjAwNTA2MDcwMDE5WhcNMjMwNTA2MDcwMDE5WjBxMQswCQYDVQQGEwJDTjETMBEGA1UECg" + "wKSHVhd2VpIENCRzEdMBsGA1UECwwUSE9TIERldmVsb3BtZW50IFRlYW0xLjAsBgNVBAMMJUhPUyBBcHBsaWNhdGlvbiBQcm92aXNpb24g" + "UHJvZmlsZSBEZXYwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARn9+yWcHv7JRXSe4bPNE6jQnMaPwRAwJOXn3hGvMoPJPCQKg+hYIoxU/" + "XNOBxnfNbneRDaFToQGJuEAK8ljAWvo4IBOTCCATUwHwYDVR0jBBgwFoAUe7hHUqfxzFie+1Xs4S1xDgeaLyYwHQYDVR0OBBYEFH4PO+Wo" + "xfnSw6b2fU0tsRiDSeXuMEYGA1UdIAQ/MD0wOwYEVR0gADAzMDEGCCsGAQUFBwIBFiVodHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2" + "Nwa2kvY3BzMA4GA1UdDwEB/wQEAwIHgDBsBgNVHR8EZTBjMGGgX6BdhltodHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2Nwa2kvc2Vy" + "dmxldC9jcmxGaWxlRG93bi5jcmw/Y2VydHlwZT0xNCYvc29mdF9zaWduX3Nydl9jcmwuY3JsMBMGA1UdJQQMMAoGCCsGAQUFBwMDMBgGDC" + "sGAQQBj1sCgngBAwQIMAYCAQEKAQEwCgYIKoZIzj0EAwMDaQAwZgIxAOWOtWEhKZU2e11FBrOtaBnshDWzQJBi1RIB0uqicO/dGx7Vj7JA" + "RD8ayn/zGtUzewIxAKHSW0bh2OmR2Eg3JnwufW0UXomUkm21Q72Dg6pY33wl6pHsuh1dX8hHFb72ZZPvcKGCBY4wggWKMIIFEgIBATAJBg" + "cqhkjOPQQBMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBD" + "QkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3QXDTIwMDQxNzA3MzMzM1oXDTIwMDQxNzExMzMzM1owggRGMBkCCBQ7Mzvv7Z" + "C+Fw0yMDA0MDkwMjA1NTJaMBkCCBSA32VRL2VeFw0yMDA0MTcwMTUzMzVaMBkCCBYmVCtJx/+kFw0yMDA0MTUwNjMyMzRaMBkCCBi/h30p" + "K2v/Fw0yMDA0MDkwMzM5MjZaMBkCCBj5CND8zwXzFw0yMDA0MDkwMjIxMTdaMBkCCBudm6FoXeaVFw0yMDA0MDkwMzM5NDdaMBkCCByX9U" + "IEDNzVFw0yMDA0MTUwNzAwMzdaMBkCCB+KU7liKiVhFw0yMDA0MDkwMjU0MzNaMBkCCCLAsIoTu/iwFw0yMDA0MDkxMTU4MzVaMBkCCCgo" + "U4TvQ32IFw0yMDA0MDkwMjQxMjVaMBkCCCtAYEt1H/RnFw0yMDA0MTUwNzAxNDVaMBkCCCwAAOA2rIzzFw0yMDA0MTYwODAzNTZaMBkCCD" + "Kbwm3X4D7mFw0yMDA0MDkwMjA5MTVaMBkCCDQiVSB03omGFw0yMDA0MTUwNjM4MDFaMBkCCDfCGtH0VgS1Fw0yMDAyMjkwNzQ1NDdaMBkC" + "CDovxg55Y7gVFw0yMDA0MTYwOTI0NTFaMBkCCDqAWrQshdpqFw0yMDA0MTcwMTU5MTFaMBkCCDwNfcU9P+TRFw0yMDA0MDkwMjE1NTFaMB" + "kCCEWkdoBvixoAFw0yMDA0MTUwNjI2MDZaMBkCCEylThTZzbp7Fw0yMDA0MTYxMDAyMzNaMBkCCE6WLxqaTr6XFw0yMDA0MDkwMjE3MTVa" + "MBkCCFEVrlniOFY2Fw0yMDA0MTUwNjQ1MTlaMBkCCFFPWlb5RYu6Fw0yMDA0MTUxMjE2MTVaMBkCCFWrBpwf8tY1Fw0yMDAyMjkwNzE1ND" + "daMBkCCFkV+qnGkK8jFw0yMDA0MDgxNTE2NDFaMBkCCFmvnY1ZRhGyFw0yMDA0MTUxMjE4MjNaMBkCCFtwgS4KQccDFw0yMDA0MTcwMTQ0" + "MTlaMBkCCGPYgX6lNTnMFw0yMDA0MTUwNjM2MjdaMBkCCGROy+k9NVtAFw0yMDAyMjkxMTQzMjNaMBkCCGWCw3Z7LNl0Fw0yMDA0MDkxMj" + "M4NDJaMBkCCG1z2rPL27TIFw0yMDA0MTUwNzAxMzdaMBkCCG3irdaon9JqFw0yMDA0MTYwMjI3MzBaMBkCCG8VTBqYZE7VFw0yMDA0MDkw" + "MjIzMTBaMBkCCHcl5BXlOZvEFw0yMDA0MDkwMzQ1MTRaMBkCCHg9MloZjR+KFw0yMDA0MTYwMjAyMTNaMBkCCHlwKWcGSdHIFw0yMDA0MD" + "kwMjA3NTJaMBkCCHmjwsQHeeh5Fw0yMDA0MTUwNjM1MDJaMCcCCH1zgq/HgbUOFw0yMDAzMDMwNjM2MDdaMAwwCgYDVR0VBAMKAQEwGQII" + "fYZw60gU/m8XDTIwMDQwOTAzMzcyNFowGQIIfzH9qPOrQIkXDTIwMDQxNjAyNTkxNVqgLzAtMB8GA1UdIwQYMBaAFHu4R1Kn8cxYnvtV7O" + "EtcQ4Hmi8mMAoGA1UdFAQDAgEAMAkGByqGSM49BAEDZwAwZAIwHhVVU3rHk8TQz1YwSs1ayFCRpxqSuEifVqXC3cFhYRmubytVrISh8Oa1" + "Ic7xMV7gAjBJpFlyHbtdJryQ2Qmk4E/UONIQ0aU6nzomCXWSKi1/ge/Aio7vGYij85V/OeE/FP0xggFPMIIBSwIBATB1MGkxCzAJBgNVBA" + "YTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmlu" + "ZyBTZXJ2aWNlIENBIFRlc3QCCC0zffQhq5r9MA0GCWCGSAFlAwQCAQUAoGkwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w" + "0BCQUxDxcNMjAwNTA4MDc1MjA3WjAvBgkqhkiG9w0BCQQxIgQgY1QMuzDpNck6aYoxiVQ79R8dWxgp8xTHA/Cq1xm0scwwDAYIKoZIzj0E" + "AwIFAARHMEUCIQCq2jaEIY9xdwh515mNlLRcSrdHWileCGhh3zsEnFlObwIgVFiEUq8WZb0+N+EtqRsbFZLEDpgh1ymsAyl2PsP8+70wgg" + "2UBgkqhkiG9w0BBwKggg2FMIINgQIBATEPMA0GCWCGSAFlAwQCAQUAMEMGCSqGSIb3DQEHAaA2BDQCAAAAAQAAACgAAAABAgAAIAAAAHOw" + "6RfHW0zQuwMzDSFUEEK6E4bUJMc7BikhRX4RcTq9oIIGHzCCAwowggKRoAMCAQICCFmxKhrzqk9dMAoGCCqGSM49BAMDMFgxCzAJBgNVBA" + "YTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxIzAhBgNVBAMMGkh1YXdlaSBDQkcgUm9vdCBDQSBHMiBUZXN0" + "MB4XDTIwMDMxMzExNTgyOFoXDTQwMDMxMzExNTgyOFowaTELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2" + "VpIENCRzE0MDIGA1UEAwwrSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWduaW5nIFNlcnZpY2UgQ0EgVGVzdDB2MBAGByqGSM49AgEGBSuBBAAi" + "A2IABLpDw0t7NE6WGv5QDQk3O3l/H3RhozD1G77KN07ZQb83ZtFwzU3VbWat11Tn3n4KRDmgvyUqF4IjR5HhEOF0kptHezG3qGBMqBClmt" + "Rtv0jkMW1Taii3scZRjIzLji3TG6OCARUwggERMB8GA1UdIwQYMBaAFGldwFjx9Tzm/QpA8R1gc9wceMbFMB0GA1UdDgQWBBR7uEdSp/HM" + "WJ77VezhLXEOB5ovJjAPBgNVHRMBAf8EBTADAQH/MEYGA1UdIAQ/MD0wOwYEVR0gADAzMDEGCCsGAQUFBwIBFiVodHRwOi8vY3BraS1jYX" + "dlYi5odWF3ZWkuY29tL2Nwa2kvY3BzMA4GA1UdDwEB/wQEAwIBBjBmBgNVHR8EXzBdMFugWaBXhlVodHRwOi8vY3BraS1jYXdlYi5odWF3" + "ZWkuY29tL2Nwa2kvc2VydmxldC9jcmxGaWxlRG93bi5jcmw/Y2VydHlwZT0xMCYvcm9vdF9nMl9jcmwuY3JsMAoGCCqGSM49BAMDA2cAMG" + "QCMBez4yLjjg4aQ4c6cNnKlf8WyzSeQhMRSR8XMtQ9Gx5YxOcU7XLCDeNDGumhItzCUAIwB0C3wM2bzJq3mMCp3Nmx15UuvK6EkbzU761C" + "qdy3KfdpyjM4nosih5VihIK1I5ynMIIDDTCCApOgAwIBAgIIbfFy5Sitw0MwCgYIKoZIzj0EAwMwaTELMAkGA1UEBhMCQ04xDzANBgNVBA" + "oMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzE0MDIGA1UEAwwrSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWduaW5nIFNlcnZpY2UgQ0Eg" + "VGVzdDAeFw0yMDA0MjgwMzIyMDdaFw0zMDA0MjgwMzIyMDdaMFAxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCk" + "h1YXdlaSBDQkcxGzAZBgNVBAMMEnpob25neGlhbmdfcmVsZWFzZTB2MBAGByqGSM49AgEGBSuBBAAiA2IABG13sRwF2UyuUStZhnRKWvJ2" + "LGdgNLlD2Nxr4BEkARuPVpvh0o0etRjqHAcgY7+G5vjho+K/MsHy5OxrwrPZzqfOglJ9o/fMjBMGb6UEsY/gpNqwUbZ3DuNnfkzTZ6BWLq" + "OCAR8wggEbMB8GA1UdIwQYMBaAFHu4R1Kn8cxYnvtV7OEtcQ4Hmi8mMB0GA1UdDgQWBBSqp0kq/TCom+76Gf+70Fr4Nap24zBGBgNVHSAE" + "PzA9MDsGBFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8BAf8EBAMCB4" + "AwbAYDVR0fBGUwYzBhoF+gXYZbaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24uY3JsP2Nl" + "cnR5cGU9MTQmL3NvZnRfc2lnbl9zcnZfY3JsLmNybDATBgNVHSUEDDAKBggrBgEFBQcDAzAKBggqhkjOPQQDAwNoADBlAjA5cebpJ6jT3/" + "P9ostKezPiwpdM85/NtgyjwAN0B/6IFHbVSCZYLq+YqsPaKvIxxFECMQDIH1x6TMWpfbMWc87Dy96xCHKlKlSKdjS6uvL/mt7fF3Oz5Ar1" + "dXnT4AJ/Qc1lPsmhggWOMIIFijCCBRICAQEwCQYHKoZIzj0EATBpMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDA" + "pIdWF3ZWkgQ0JHMTQwMgYDVQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ25pbmcgU2VydmljZSBDQSBUZXN0Fw0yMDA0MTcwNzMzMzNa" + "Fw0yMDA0MTcxMTMzMzNaMIIERjAZAggUOzM77+2QvhcNMjAwNDA5MDIwNTUyWjAZAggUgN9lUS9lXhcNMjAwNDE3MDE1MzM1WjAZAggWJl" + "QrScf/pBcNMjAwNDE1MDYzMjM0WjAZAggYv4d9KStr/xcNMjAwNDA5MDMzOTI2WjAZAggY+QjQ/M8F8xcNMjAwNDA5MDIyMTE3WjAZAggb" + "nZuhaF3mlRcNMjAwNDA5MDMzOTQ3WjAZAggcl/VCBAzc1RcNMjAwNDE1MDcwMDM3WjAZAggfilO5YiolYRcNMjAwNDA5MDI1NDMzWjAZAg" + "giwLCKE7v4sBcNMjAwNDA5MTE1ODM1WjAZAggoKFOE70N9iBcNMjAwNDA5MDI0MTI1WjAZAggrQGBLdR/0ZxcNMjAwNDE1MDcwMTQ1WjAZ" + "AggsAADgNqyM8xcNMjAwNDE2MDgwMzU2WjAZAggym8Jt1+A+5hcNMjAwNDA5MDIwOTE1WjAZAgg0IlUgdN6JhhcNMjAwNDE1MDYzODAxWj" + "AZAgg3whrR9FYEtRcNMjAwMjI5MDc0NTQ3WjAZAgg6L8YOeWO4FRcNMjAwNDE2MDkyNDUxWjAZAgg6gFq0LIXaahcNMjAwNDE3MDE1OTEx" + "WjAZAgg8DX3FPT/k0RcNMjAwNDA5MDIxNTUxWjAZAghFpHaAb4saABcNMjAwNDE1MDYyNjA2WjAZAghMpU4U2c26excNMjAwNDE2MTAwMj" + "MzWjAZAghOli8amk6+lxcNMjAwNDA5MDIxNzE1WjAZAghRFa5Z4jhWNhcNMjAwNDE1MDY0NTE5WjAZAghRT1pW+UWLuhcNMjAwNDE1MTIx" + "NjE1WjAZAghVqwacH/LWNRcNMjAwMjI5MDcxNTQ3WjAZAghZFfqpxpCvIxcNMjAwNDA4MTUxNjQxWjAZAghZr52NWUYRshcNMjAwNDE1MT" + "IxODIzWjAZAghbcIEuCkHHAxcNMjAwNDE3MDE0NDE5WjAZAghj2IF+pTU5zBcNMjAwNDE1MDYzNjI3WjAZAghkTsvpPTVbQBcNMjAwMjI5" + "MTE0MzIzWjAZAghlgsN2eyzZdBcNMjAwNDA5MTIzODQyWjAZAghtc9qzy9u0yBcNMjAwNDE1MDcwMTM3WjAZAght4q3WqJ/SahcNMjAwND" + "E2MDIyNzMwWjAZAghvFUwamGRO1RcNMjAwNDA5MDIyMzEwWjAZAgh3JeQV5TmbxBcNMjAwNDA5MDM0NTE0WjAZAgh4PTJaGY0fihcNMjAw" + "NDE2MDIwMjEzWjAZAgh5cClnBknRyBcNMjAwNDA5MDIwNzUyWjAZAgh5o8LEB3noeRcNMjAwNDE1MDYzNTAyWjAnAgh9c4Kvx4G1DhcNMj" + "AwMzAzMDYzNjA3WjAMMAoGA1UdFQQDCgEBMBkCCH2GcOtIFP5vFw0yMDA0MDkwMzM3MjRaMBkCCH8x/ajzq0CJFw0yMDA0MTYwMjU5MTVa" + "oC8wLTAfBgNVHSMEGDAWgBR7uEdSp/HMWJ77VezhLXEOB5ovJjAKBgNVHRQEAwIBADAJBgcqhkjOPQQBA2cAMGQCMB4VVVN6x5PE0M9WME" + "rNWshQkacakrhIn1alwt3BYWEZrm8rVayEofDmtSHO8TFe4AIwSaRZch27XSa8kNkJpOBP1DjSENGlOp86Jgl1kiotf4HvwIqO7xmIo/OV" + "fznhPxT9MYIBbzCCAWsCAQEwdTBpMQswCQYDVQQGEwJDTjEPMA0GA1UEChMGSHVhd2VpMRMwEQYDVQQLEwpIdWF3ZWkgQ0JHMTQwMgYDVQ" + "QDEytIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ25pbmcgU2VydmljZSBDQSBUZXN0Aght8XLlKK3DQzANBglghkgBZQMEAgEFAKBpMBgGCSqG" + "SIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTIwMDUwODA5MzAwN1owLwYJKoZIhvcNAQkEMSIEIOg1/B6HaR3SK2EDaF" + "sNg9yGRV5v1HAGMoJijpJ2mDaRMAwGCCqGSM49BAMCBQAEZzBlAjB9HZPKO+YuVOuZ5R5VfU5HIURtOB/uxyfArnT+esEWIwJSXZtPDQx1" + "1bLtAOruHloCMQDikYgfLOAEVOqayrENBjUgedTryzXKIjzu57P+ckKJWoCCuH5lb4/+Hva5mN+yoZ0CAAAAqiEAAAAAAABIQVAgU2lnIE" + "Jsb2NrIDQyAgAAAFBLAQIUABQACAgIAAAAITp3FVrWBAAAAAIAAAAFAAQAAAAAAAAAAAAAAAAAAAAxLnR4dP7KAABQSwUGAAAAAAEAAQA3" + "AAAA5SEAAAAA"; + + const std::string HAP_FILE_RSA_SIGN_BASE64 = + "UEsDBBQACAgIAAAAIToAAAAAAAAAAAAAAAAMAAQAcnNhX3Rlc3QuaGFw/soAADM0BABQSwcIdxVa1gQAAAACAAAAAgAAIFIVAAAYAAAAAA" + "AAILEMAABqFQAAMIIVTgYJKoZIhvcNAQcCoIIVPzCCFTsCAQExDzANBglghkgBZQMEAgEFADCCB/sGCSqGSIb3DQEHAaCCB+wEggfoeyJ2" + "ZXJzaW9uLW5hbWUiOiIxLjAuMCIsInZlcnNpb24tY29kZSI6MSwiYXBwLWRpc3RyaWJ1dGlvbi10eXBlIjoib3NfaW50ZWdyYXRpb24iLC" + "J1dWlkIjoiOThBN0Y3NzItNTg0Qi00RUQ3LTk3M0QtQjA4ODNGMEYxOUVGIiwidmFsaWRpdHkiOnsibm90LWJlZm9yZSI6MTU4NjQyMjc0" + "Mywibm90LWFmdGVyIjoxNjE3OTU4NzQzfSwidHlwZSI6InJlbGVhc2UiLCJidW5kbGUtaW5mbyI6eyJkZXZlbG9wZXItaWQiOiJ6aG9uZ3" + "hpYW5nIiwiZGlzdHJpYnV0aW9uLWNlcnRpZmljYXRlIjoiLS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tXG5NSUlFVXpDQ0E5cWdBd0lC" + "QWdJSWRFY05DbEFLNmU4d0NnWUlLb1pJemowRUF3TXdhVEVMTUFrR0ExVUVCaE1DXG5RMDR4RHpBTkJnTlZCQW9NQmtoMVlYZGxhVEVUTU" + "JFR0ExVUVDd3dLU0hWaGQyVnBJRU5DUnpFME1ESUdBMVVFXG5Bd3dyU0hWaGQyVnBJRU5DUnlCVGIyWjBkMkZ5WlNCVGFXZHVhVzVuSUZO" + "bGNuWnBZMlVnUTBFZ1ZHVnpkREFlXG5GdzB5TURBMU1Ea3dNalU0TlRCYUZ3MHlNVEExTURrd01qVTROVEJhTUU4eFRUQkxCZ05WQkFZTV" + "JFTk9JRTg5XG5TSFZoZDJWcElFTkNSeUJQVlQxSVQxTWdSR1YyWld4dmNHMWxiblFnU1VSRklGUmxZVzBnUTA0OWFIZGZhR0Z3XG5hMlY1" + "WDNKellWOXBaR1ZmWkdWMk1JSUJvakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBWThBTUlJQmlnS0NBWUVBXG5oM3VJalE1ZUhvL1pmMG5hVV" + "J6L2VRZ0hnOHdzSUl5VEFYd3lYdGh2VDZ6TEdtcmpCbjBiOWhEeHcwbGJxU2NGXG4yamZLQzk3b0EyNlg1K2E2NmdGdzhzTnZQa29DaHJI" + "T08yRloyMS9vUEVGbGYwK21NY3N4UjNDZUpkTTF1NmxvXG5samxncEF0TFZveFJiSTVqMW9SU3U5Vkw4aUFycHJIeEVnclFSbHV5aERzRm" + "RtZHN3ZnROaWl1UDdidVhQeHFYXG5ISWxka0IwK0RFSzlvSHY0L0JRWnhoOFJFQlBuYjNCck45OFc4SnYrYWdIMzhPMlBxd1gyeDZHRFl2" + "SSt6ODVLXG5uRFpCNlFPL3JTVjdiWVhuWXFkSDZJa3lGMzNuTzFnbVZ5T3lZQlF0azhLNE1mYkMrM29pWERwVzlxQnByUHJzXG4zek1ubz" + "NLa1ZNMEpJdzFXVTFwK05nNk1lTDJja3JYRzYrV3lrM2x5QnNuZ2VDVEp6ejBaZ29JOTRFZWxNL3pxXG5tejZ6cTl5TUFpWTZnTWhTdWpJ" + "a1pOendKQ3d1N1BMZXFrKzdyLy8rNGNXMEJJZ3Q5WElCTmdXd1FoOGdNWU9sXG5saHNxZmR4VWlUa1FpYnpZOXNQQ0J4bFBNWnJENW9WSX" + "hJZ1IyTUZMRDVyam5CN0ZZUytJYU14bTV1NFBYYytCXG5BZ01CQUFHamdnRTVNSUlCTlRBZkJnTlZIU01FR0RBV2dCUjd1RWRTcC9ITVdK" + "NzdWZXpoTFhFT0I1b3ZKakFkXG5CZ05WSFE0RUZnUVVmVFkwVGZhS0VjdWhhM1dPUHJnNE1XMDBaMHd3UmdZRFZSMGdCRDh3UFRBN0JnUl" + "ZIU0FBXG5NRE13TVFZSUt3WUJCUVVIQWdFV0pXaDBkSEE2THk5amNHdHBMV05oZDJWaUxtaDFZWGRsYVM1amIyMHZZM0JyXG5hUzlqY0hN" + "d0RnWURWUjBQQVFIL0JBUURBZ2VBTUd3R0ExVWRId1JsTUdNd1lhQmZvRjJHVzJoMGRIQTZMeTlqXG5jR3RwTFdOaGQyVmlMbWgxWVhkbG" + "FTNWpiMjB2WTNCcmFTOXpaWEoyYkdWMEwyTnliRVpwYkdWRWIzZHVMbU55XG5iRDlqWlhKMGVYQmxQVEUwSmk5emIyWjBYM05wWjI1ZmMz" + "SjJYMk55YkM1amNtd3dFd1lEVlIwbEJBd3dDZ1lJXG5Ld1lCQlFVSEF3TXdHQVlNS3dZQkJBR1BXd0tDZUFFREJBZ3dCZ0lCQVFvQkFEQU" + "tCZ2dxaGtqT1BRUURBd05uXG5BREJrQWpCRHJGTUNiZzAyTUdoa0p3emhCdFVIbk85Ny9hMlNqVCs4bEpxTkpCTkhMWVh3VER1Kzg5a1Jj" + "cG1zXG4rVFlCam5vQ01BL0dHUXJscTgrbldIZFNZMjkzY0hNcG5DZ09oNVJkdk5BRkRwNjlkU0NqSTdqTWc2YWN5Y2hHXG5qVlorTXVIY1" + "VRPT1cbi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS1cbiIsImJ1bmRsZS1uYW1lIjoiY29tLmh1YXdlaS5oaXdvcmxkLmhpZGVtbyIsImFw" + "cC1mZWF0dXJlIjoiaG9zX25vcm1hbF9hcHAifSwicGVybWlzc2lvbnMiOnsicmVzdHJpY3RlZC1wZXJtaXNzaW9ucyI6WyJhYWEiLCJCQk" + "IiXX0sImlzc3VlciI6Ikh1YXdlaSBBcHBzIFN0b3JlIn2gggY+MIIDCjCCApGgAwIBAgIIWbEqGvOqT10wCgYIKoZIzj0EAwMwWDELMAkG" + "A1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEjMCEGA1UEAwwaSHVhd2VpIENCRyBSb290IENBIEcyIF" + "Rlc3QwHhcNMjAwMzEzMTE1ODI4WhcNNDAwMzEzMTE1ODI4WjBpMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApI" + "dWF3ZWkgQ0JHMTQwMgYDVQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ25pbmcgU2VydmljZSBDQSBUZXN0MHYwEAYHKoZIzj0CAQYFK4" + "EEACIDYgAEukPDS3s0TpYa/lANCTc7eX8fdGGjMPUbvso3TtlBvzdm0XDNTdVtZq3XVOfefgpEOaC/JSoXgiNHkeEQ4XSSm0d7MbeoYEyo" + "EKWa1G2/SOQxbVNqKLexxlGMjMuOLdMbo4IBFTCCAREwHwYDVR0jBBgwFoAUaV3AWPH1POb9CkDxHWBz3Bx4xsUwHQYDVR0OBBYEFHu4R1" + "Kn8cxYnvtV7OEtcQ4Hmi8mMA8GA1UdEwEB/wQFMAMBAf8wRgYDVR0gBD8wPTA7BgRVHSAAMDMwMQYIKwYBBQUHAgEWJWh0dHA6Ly9jcGtp" + "LWNhd2ViLmh1YXdlaS5jb20vY3BraS9jcHMwDgYDVR0PAQH/BAQDAgEGMGYGA1UdHwRfMF0wW6BZoFeGVWh0dHA6Ly9jcGtpLWNhd2ViLm" + "h1YXdlaS5jb20vY3BraS9zZXJ2bGV0L2NybEZpbGVEb3duLmNybD9jZXJ0eXBlPTEwJi9yb290X2cyX2NybC5jcmwwCgYIKoZIzj0EAwMD" + "ZwAwZAIwF7PjIuOODhpDhzpw2cqV/xbLNJ5CExFJHxcy1D0bHljE5xTtcsIN40Ma6aEi3MJQAjAHQLfAzZvMmreYwKnc2bHXlS68roSRvN" + "TvrUKp3Lcp92nKMzieiyKHlWKEgrUjnKcwggMsMIICsaADAgECAggtM330Iaua/TAKBggqhkjOPQQDAzBpMQswCQYDVQQGEwJDTjEPMA0G" + "A1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMTQwMgYDVQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ25pbmcgU2VydmljZS" + "BDQSBUZXN0MB4XDTIwMDUwNjA3MDAxOVoXDTIzMDUwNjA3MDAxOVowcTELMAkGA1UEBhMCQ04xEzARBgNVBAoMCkh1YXdlaSBDQkcxHTAb" + "BgNVBAsMFEhPUyBEZXZlbG9wbWVudCBUZWFtMS4wLAYDVQQDDCVIT1MgQXBwbGljYXRpb24gUHJvdmlzaW9uIFByb2ZpbGUgRGV2MFkwEw" + "YHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZ/fslnB7+yUV0nuGzzROo0JzGj8EQMCTl594RrzKDyTwkCoPoWCKMVP1zTgcZ3zW53kQ2hU6EBib" + "hACvJYwFr6OCATkwggE1MB8GA1UdIwQYMBaAFHu4R1Kn8cxYnvtV7OEtcQ4Hmi8mMB0GA1UdDgQWBBR+DzvlqMX50sOm9n1NLbEYg0nl7j" + "BGBgNVHSAEPzA9MDsGBFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8B" + "Af8EBAMCB4AwbAYDVR0fBGUwYzBhoF+gXYZbaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd2" + "4uY3JsP2NlcnR5cGU9MTQmL3NvZnRfc2lnbl9zcnZfY3JsLmNybDATBgNVHSUEDDAKBggrBgEFBQcDAzAYBgwrBgEEAY9bAoJ4AQMECDAG" + "AgEBCgEBMAoGCCqGSM49BAMDA2kAMGYCMQDljrVhISmVNntdRQazrWgZ7IQ1s0CQYtUSAdLqonDv3Rse1Y+yQEQ/Gsp/8xrVM3sCMQCh0l" + "tG4djpkdhINyZ8Ln1tFF6JlJJttUO9g4OqWN98JeqR7LodXV/IRxW+9mWT73ChggWOMIIFijCCBRICAQEwCQYHKoZIzj0EATBpMQswCQYD" + "VQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMTQwMgYDVQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ2" + "5pbmcgU2VydmljZSBDQSBUZXN0Fw0yMDA0MTcwNzMzMzNaFw0yMDA0MTcxMTMzMzNaMIIERjAZAggUOzM77+2QvhcNMjAwNDA5MDIwNTUy" + "WjAZAggUgN9lUS9lXhcNMjAwNDE3MDE1MzM1WjAZAggWJlQrScf/pBcNMjAwNDE1MDYzMjM0WjAZAggYv4d9KStr/xcNMjAwNDA5MDMzOT" + "I2WjAZAggY+QjQ/M8F8xcNMjAwNDA5MDIyMTE3WjAZAggbnZuhaF3mlRcNMjAwNDA5MDMzOTQ3WjAZAggcl/VCBAzc1RcNMjAwNDE1MDcw" + "MDM3WjAZAggfilO5YiolYRcNMjAwNDA5MDI1NDMzWjAZAggiwLCKE7v4sBcNMjAwNDA5MTE1ODM1WjAZAggoKFOE70N9iBcNMjAwNDA5MD" + "I0MTI1WjAZAggrQGBLdR/0ZxcNMjAwNDE1MDcwMTQ1WjAZAggsAADgNqyM8xcNMjAwNDE2MDgwMzU2WjAZAggym8Jt1+A+5hcNMjAwNDA5" + "MDIwOTE1WjAZAgg0IlUgdN6JhhcNMjAwNDE1MDYzODAxWjAZAgg3whrR9FYEtRcNMjAwMjI5MDc0NTQ3WjAZAgg6L8YOeWO4FRcNMjAwND" + "E2MDkyNDUxWjAZAgg6gFq0LIXaahcNMjAwNDE3MDE1OTExWjAZAgg8DX3FPT/k0RcNMjAwNDA5MDIxNTUxWjAZAghFpHaAb4saABcNMjAw" + "NDE1MDYyNjA2WjAZAghMpU4U2c26excNMjAwNDE2MTAwMjMzWjAZAghOli8amk6+lxcNMjAwNDA5MDIxNzE1WjAZAghRFa5Z4jhWNhcNMj" + "AwNDE1MDY0NTE5WjAZAghRT1pW+UWLuhcNMjAwNDE1MTIxNjE1WjAZAghVqwacH/LWNRcNMjAwMjI5MDcxNTQ3WjAZAghZFfqpxpCvIxcN" + "MjAwNDA4MTUxNjQxWjAZAghZr52NWUYRshcNMjAwNDE1MTIxODIzWjAZAghbcIEuCkHHAxcNMjAwNDE3MDE0NDE5WjAZAghj2IF+pTU5zB" + "cNMjAwNDE1MDYzNjI3WjAZAghkTsvpPTVbQBcNMjAwMjI5MTE0MzIzWjAZAghlgsN2eyzZdBcNMjAwNDA5MTIzODQyWjAZAghtc9qzy9u0" + "yBcNMjAwNDE1MDcwMTM3WjAZAght4q3WqJ/SahcNMjAwNDE2MDIyNzMwWjAZAghvFUwamGRO1RcNMjAwNDA5MDIyMzEwWjAZAgh3JeQV5T" + "mbxBcNMjAwNDA5MDM0NTE0WjAZAgh4PTJaGY0fihcNMjAwNDE2MDIwMjEzWjAZAgh5cClnBknRyBcNMjAwNDA5MDIwNzUyWjAZAgh5o8LE" + "B3noeRcNMjAwNDE1MDYzNTAyWjAnAgh9c4Kvx4G1DhcNMjAwMzAzMDYzNjA3WjAMMAoGA1UdFQQDCgEBMBkCCH2GcOtIFP5vFw0yMDA0MD" + "kwMzM3MjRaMBkCCH8x/ajzq0CJFw0yMDA0MTYwMjU5MTVaoC8wLTAfBgNVHSMEGDAWgBR7uEdSp/HMWJ77VezhLXEOB5ovJjAKBgNVHRQE" + "AwIBADAJBgcqhkjOPQQBA2cAMGQCMB4VVVN6x5PE0M9WMErNWshQkacakrhIn1alwt3BYWEZrm8rVayEofDmtSHO8TFe4AIwSaRZch27XS" + "a8kNkJpOBP1DjSENGlOp86Jgl1kiotf4HvwIqO7xmIo/OVfznhPxT9MYIBUDCCAUwCAQEwdTBpMQswCQYDVQQGEwJDTjEPMA0GA1UECgwG" + "SHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMTQwMgYDVQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ25pbmcgU2VydmljZSBDQSBUZX" + "N0AggtM330Iaua/TANBglghkgBZQMEAgEFAKBpMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTIwMDUwOTA2" + "MTg0MVowLwYJKoZIhvcNAQkEMSIEILRwLw0SaJaZgBqv0Ua7mE2AoiYF+K+MD57mOOlUoQ4RMAwGCCqGSM49BAMCBQAESDBGAiEAw0onJy" + "3Lf14GFN3TlFrWyBSTJr97HZUkgLFtJIZOI3ACIQCQTj0Dg5puHWX6KpZw7FKNaP22uAY6gM4yuMKVtOTDVDCCDK0GCSqGSIb3DQEHAqCC" + "DJ4wggyaAgEBMQ8wDQYJYIZIAWUDBAICBQAwUwYJKoZIhvcNAQcBoEYERAIAAAABAAAAOAAAAAIBAAAwAAAAWzpm+iYRXS5oYmfWhDVKzp" + "PpBXw7ImKibUESgF0Zr1ugoZC5qm9RKh1aRxsvfip1oIIJjjCCAiUwggGroAMCAQICCG//Sp1YnlU4MAoGCCqGSM49BAMDMFgxCzAJBgNV" + "BAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxIzAhBgNVBAMMGkh1YXdlaSBDQkcgUm9vdCBDQSBHMiBUZX" + "N0MB4XDTIwMDMxMjEyNDQwMFoXDTQ5MDMxMjEyNDQwMFowWDELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVh" + "d2VpIENCRzEjMCEGA1UEAwwaSHVhd2VpIENCRyBSb290IENBIEcyIFRlc3QwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAS0uH4L2mCin8jGVv" + "+JzU7Er8alcajhA3y8kmSv30hDdCA0I9LCv6iuYb539DsVocCOPT93ShpkPnEro178tJntgyU42Ndu12GSa7ycMDJK0/7zK2QuZEjhCW7d" + "agIEpomjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRpXcBY8fU85v0KQPEdYHPcHHjGxTAKBggqhk" + "jOPQQDAwNoADBlAjEAglA0WoJZsnFBqx5hfi/KMCiYW6jlKm8Ll+1y/7yXKdx3h44l7u12ZmEPkALxz4VNAjAosFhWw5fBE8OFStuUG8IS" + "/0IlH4kXwiei87Xjr4y0xFeYnm0DM/50tY+/6I90bKowggMKMIICkaADAgECAghZsSoa86pPXTAKBggqhkjOPQQDAzBYMQswCQYDVQQGEw" + "JDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMSMwIQYDVQQDDBpIdWF3ZWkgQ0JHIFJvb3QgQ0EgRzIgVGVzdDAe" + "Fw0yMDAzMTMxMTU4MjhaFw00MDAzMTMxMTU4MjhaMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaS" + "BDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3QwdjAQBgcqhkjOPQIBBgUrgQQAIgNi" + "AAS6Q8NLezROlhr+UA0JNzt5fx90YaMw9Ru+yjdO2UG/N2bRcM1N1W1mrddU595+CkQ5oL8lKheCI0eR4RDhdJKbR3sxt6hgTKgQpZrUbb" + "9I5DFtU2oot7HGUYyMy44t0xujggEVMIIBETAfBgNVHSMEGDAWgBRpXcBY8fU85v0KQPEdYHPcHHjGxTAdBgNVHQ4EFgQUe7hHUqfxzFie" + "+1Xs4S1xDgeaLyYwDwYDVR0TAQH/BAUwAwEB/zBGBgNVHSAEPzA9MDsGBFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZW" + "IuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8BAf8EBAMCAQYwZgYDVR0fBF8wXTBboFmgV4ZVaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2Vp" + "LmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24uY3JsP2NlcnR5cGU9MTAmL3Jvb3RfZzJfY3JsLmNybDAKBggqhkjOPQQDAwNnADBkAj" + "AXs+Mi444OGkOHOnDZypX/Fss0nkITEUkfFzLUPRseWMTnFO1ywg3jQxrpoSLcwlACMAdAt8DNm8yat5jAqdzZsdeVLryuhJG81O+tQqnc" + "tyn3acozOJ6LIoeVYoSCtSOcpzCCBFMwggPaoAMCAQICCHRHDQpQCunvMAoGCCqGSM49BAMDMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDA" + "ZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRl" + "c3QwHhcNMjAwNTA5MDI1ODUwWhcNMjEwNTA5MDI1ODUwWjBPMU0wSwYDVQQGDERDTiBPPUh1YXdlaSBDQkcgT1U9SE9TIERldmVsb3BtZW" + "50IElERSBUZWFtIENOPWh3X2hhcGtleV9yc2FfaWRlX2RldjCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAId7iI0OXh6P2X9J" + "2lEc/3kIB4PMLCCMkwF8Ml7Yb0+syxpq4wZ9G/YQ8cNJW6knBdo3ygve6ANul+fmuuoBcPLDbz5KAoaxzjthWdtf6DxBZX9PpjHLMUdwni" + "XTNbupaJY5YKQLS1aMUWyOY9aEUrvVS/IgK6ax8RIK0EZbsoQ7BXZnbMH7TYorj+27lz8alxyJXZAdPgxCvaB7+PwUGcYfERAT529wazff" + "FvCb/moB9/Dtj6sF9sehg2LyPs/OSpw2QekDv60le22F52KnR+iJMhd95ztYJlcjsmAULZPCuDH2wvt6Ilw6Vvagaaz67N8zJ6NypFTNCS" + "MNVlNafjYOjHi9nJK1xuvlspN5cgbJ4Hgkyc89GYKCPeBHpTP86ps+s6vcjAImOoDIUroyJGTc8CQsLuzy3qpPu6///uHFtASILfVyATYF" + "sEIfIDGDpZYbKn3cVIk5EIm82PbDwgcZTzGaw+aFSMSIEdjBSw+a45wexWEviGjMZubuD13PgQIDAQABo4IBOTCCATUwHwYDVR0jBBgwFo" + "AUe7hHUqfxzFie+1Xs4S1xDgeaLyYwHQYDVR0OBBYEFH02NE32ihHLoWt1jj64ODFtNGdMMEYGA1UdIAQ/MD0wOwYEVR0gADAzMDEGCCsG" + "AQUFBwIBFiVodHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2Nwa2kvY3BzMA4GA1UdDwEB/wQEAwIHgDBsBgNVHR8EZTBjMGGgX6Bdhl" + "todHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2Nwa2kvc2VydmxldC9jcmxGaWxlRG93bi5jcmw/Y2VydHlwZT0xNCYvc29mdF9zaWdu" + "X3Nydl9jcmwuY3JsMBMGA1UdJQQMMAoGCCsGAQUFBwMDMBgGDCsGAQQBj1sCgngBAwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDZwAwZAIwQ6" + "xTAm4NNjBoZCcM4QbVB5zve/2tko0/vJSajSQTRy2F8Ew7vvPZEXKZrPk2AY56AjAPxhkK5avPp1h3UmNvd3BzKZwoDoeUXbzQBQ6evXUg" + "oyO4zIOmnMnIRo1WfjLh3FExggKbMIIClwIBATB1MGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKEwZIdWF3ZWkxEzARBgNVBAsTCkh1YXdlaS" + "BDQkcxNDAyBgNVBAMTK0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3QCCHRHDQpQCunvMA0GCWCGSAFlAwQC" + "AgUAoHkwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjAwNzA4MDk0NDA0WjA/BgkqhkiG9w0BCQQxMgQwOL" + "EvnL4cEWbEqTNF7esYgRUohGGQqh9+wFbegP6EXq8b6gT0J89i4SeKKCxdMJ3/MA0GCSqGSIb3DQEBCgUABIIBgHDm/h9/MGJdNAOJs4zk" + "uP41PmnWSyjxGtoUzhNscXn0iO0Mw1NDMEsBzjXZBAoEvzQ8KxN4gXNFZ/Jlb8IZ4uSd0cKRWig9lSTP52mJwHbVXYG+AlU81nauqzieVw" + "Wr4HQwXFONw4zJLyWm3ZWSw398kJ2S8nSamqvPOHWgKUIWNktPywNQk4yF4QY0gZ0AiA1AiGynkObkw88aPsLQ+afgsLCnXGzf42QSz5QM" + "/l9DcBndUpL0palOLHGLcl4o+QaYHFa4ywHGc8m9tb/omiIGPs6YnmaNCbEOBB9dgMdExqbOpVw40aRRCc7Vz7WhW7gh0PS/sIlMOj2d8c" + "DkWLAaDio8nRz8lmT+PUelubHt8svP2RMw5vI/j4CR9XVbL8qxhbZAYt0700f53ihuuGglh0ABhtpazSyT7bUcC8s/nXQVV5gmzw/aRlAa" + "m+cArPFrDBen/P6ezF5PTqvcqenc5X9Lc97HXn0UZEluIQAStfs6J4hq3+YXbXJAVy5WJgIAAAA7IgAAAAAAAEhBUCBTaWcgQmxvY2sgND" + "ICAAAAUEsBAhQAFAAICAgAAAAhOncVWtYEAAAAAgAAAAwABAAAAAAAAAAAAAAAAAAAAHJzYV90ZXN0LmhhcP7KAABQSwUGAAAAAAEAAQA+" + "AAAAfSIAAAAA"; + + const std::string HAP_FILE_INNER = + "UEsDBBQACAgIAAAAIToAAAAAAAAAAAAAAAAFAAQAMS50eHT+ygAAMzQ0NAQAUEsHCPfI+dsGAAAABAAAAAIAACBhEwAAGAAAAAAAACBVGQ" + "AAeRMAADCCE10GCSqGSIb3DQEHAqCCE04wghNKAgEBMQ8wDQYJYIZIAWUDBAIBBQAwggYHBgkqhkiG9w0BBwGgggX4BIIF9HsidmVyc2lv" + "bi1uYW1lIjoiMS4wLjAiLCJ2ZXJzaW9uLWNvZGUiOjEsImFwcC1kaXN0cmlidXRpb24tdHlwZSI6Im9zX2ludGVncmF0aW9uIiwidXVpZC" + "I6Ijk5QTdGNzcyLTU4NEItNEVENy05NzNELUIwODgzRjBGMTlFRiIsInZhbGlkaXR5Ijp7Im5vdC1iZWZvcmUiOjE1ODg3NDc2MTUsIm5v" + "dC1hZnRlciI6MTY4MzM1NTYxNX0sInR5cGUiOiJyZWxlYXNlIiwiYnVuZGxlLWluZm8iOnsiZGV2ZWxvcGVyLWlkIjoiaHVhd2VpIiwiZG" + "lzdHJpYnV0aW9uLWNlcnRpZmljYXRlIjoiLS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tXG5NSUlESkRDQ0FxbWdBd0lCQWdJSVJyaDhw" + "cTUwNEZFd0NnWUlLb1pJemowRUF3TXdhVEVMTUFrR0ExVUVCaE1DXG5RMDR4RHpBTkJnTlZCQW9NQmtoMVlYZGxhVEVUTUJFR0ExVUVDd3" + "dLU0hWaGQyVnBJRU5DUnpFME1ESUdBMVVFXG5Bd3dyU0hWaGQyVnBJRU5DUnlCVGIyWjBkMkZ5WlNCVGFXZHVhVzVuSUZObGNuWnBZMlVn" + "UTBFZ1ZHVnpkREFlXG5GdzB5TURBMU1EWXdOalV4TkRoYUZ3MHlNekExTURZd05qVXhORGhhTUdreEN6QUpCZ05WQkFZVEFrTk9NUk13XG" + "5FUVlEVlFRS0RBcElkV0YzWldrZ1EwSkhNUjB3R3dZRFZRUUxEQlJJVDFNZ1JHVjJaV3h2Y0cxbGJuUWdWR1ZoXG5iVEVtTUNRR0ExVUVB" + "d3dkU0U5VElFRndjR3hwWTJGMGFXOXVJRkJ5YjNacGMybHZiaUJFWlhZd1dUQVRCZ2NxXG5oa2pPUFFJQkJnZ3Foa2pPUFFNQkJ3TkNBQV" + "MxYjZwS3FPVXo2WC9YMURNRThici9NaHlZdldyVHhVYnFQMlpYXG5UWk9iNk1tOUZoMno2YUtkdE43RVJ6N0hvVGNPbGpHQzBhU1BybHho" + "UjdqNk8ySjBvNElCT1RDQ0FUVXdId1lEXG5WUjBqQkJnd0ZvQVVlN2hIVXFmeHpGaWUrMVhzNFMxeERnZWFMeVl3SFFZRFZSME9CQllFRk" + "43ejA5RjUvajRkXG5nalRMK1pxajhjZ2U4RUNCTUVZR0ExVWRJQVEvTUQwd093WUVWUjBnQURBek1ERUdDQ3NHQVFVRkJ3SUJGaVZvXG5k" + "SFJ3T2k4dlkzQnJhUzFqWVhkbFlpNW9kV0YzWldrdVkyOXRMMk53YTJrdlkzQnpNQTRHQTFVZER3RUIvd1FFXG5Bd0lIZ0RCc0JnTlZIUj" + "hFWlRCak1HR2dYNkJkaGx0b2RIUndPaTh2WTNCcmFTMWpZWGRsWWk1b2RXRjNaV2t1XG5ZMjl0TDJOd2Eya3ZjMlZ5ZG14bGRDOWpjbXhH" + "YVd4bFJHOTNiaTVqY213L1kyVnlkSGx3WlQweE5DWXZjMjltXG5kRjl6YVdkdVgzTnlkbDlqY213dVkzSnNNQk1HQTFVZEpRUU1NQW9HQ0" + "NzR0FRVUZCd01ETUJnR0RDc0dBUVFCXG5qMXNDZ25nQkF3UUlNQVlDQVFFS0FRQXdDZ1lJS29aSXpqMEVBd01EYVFBd1pnSXhBTC9mNXQ5" + "VGVxRStWcDVXXG5HOEgwVktxYWNFdGhVVmVzV1VKSTU3ZXRMclFkQ2dUY2haMjBqMC9Sc25oSCtsYWhmd0l4QUlOMWlpY2M3OUVhXG5Fb0" + "9URFNZMUVzaFpucSsvaUkwallYMUlJNitnbjVKZmJmem14RG1VcEtIaEsyVjAzZEpKMFE9PVxuLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0t" + "LVxuIiwiYnVuZGxlLW5hbWUiOiIuKiIsImFwcC1mZWF0dXJlIjoiaG9zX3N5c3RlbV9hcHAifSwiaXNzdWVyIjoiSHVhd2VpIEFwcHMgU3" + "RvcmUifaCCBkMwggMKMIICkaADAgECAghZsSoa86pPXTAKBggqhkjOPQQDAzBYMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMw" + "EQYDVQQLDApIdWF3ZWkgQ0JHMSMwIQYDVQQDDBpIdWF3ZWkgQ0JHIFJvb3QgQ0EgRzIgVGVzdDAeFw0yMDAzMTMxMTU4MjhaFw00MDAzMT" + "MxMTU4MjhaMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBD" + "QkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3QwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAS6Q8NLezROlhr+UA0JNzt5fx90Ya" + "Mw9Ru+yjdO2UG/N2bRcM1N1W1mrddU595+CkQ5oL8lKheCI0eR4RDhdJKbR3sxt6hgTKgQpZrUbb9I5DFtU2oot7HGUYyMy44t0xujggEV" + "MIIBETAfBgNVHSMEGDAWgBRpXcBY8fU85v0KQPEdYHPcHHjGxTAdBgNVHQ4EFgQUe7hHUqfxzFie+1Xs4S1xDgeaLyYwDwYDVR0TAQH/BA" + "UwAwEB/zBGBgNVHSAEPzA9MDsGBFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL2NwczAO" + "BgNVHQ8BAf8EBAMCAQYwZgYDVR0fBF8wXTBboFmgV4ZVaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRm" + "lsZURvd24uY3JsP2NlcnR5cGU9MTAmL3Jvb3RfZzJfY3JsLmNybDAKBggqhkjOPQQDAwNnADBkAjAXs+Mi444OGkOHOnDZypX/Fss0nkIT" + "EUkfFzLUPRseWMTnFO1ywg3jQxrpoSLcwlACMAdAt8DNm8yat5jAqdzZsdeVLryuhJG81O+tQqnctyn3acozOJ6LIoeVYoSCtSOcpzCCAz" + "EwggK3oAMCAQICCGv0psZNBT6MMAoGCCqGSM49BAMDMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdl" + "aSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3QwHhcNMjAwNTA2MDcwMTEzWhcNMj" + "MwNTA2MDcwMTEzWjB3MQswCQYDVQQGEwJDTjETMBEGA1UECgwKSHVhd2VpIENCRzEdMBsGA1UECwwUSE9TIERldmVsb3BtZW50IFRlYW0x" + "NDAyBgNVBAMMK0hPUyBBcHBsaWNhdGlvbiBQcm92aXNpb24gUHJvZmlsZSBEZXZfRGVidWcwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAA" + "QdB9SYqO9atez14k6Jv6xX7TfE+m7gzj8ttU7P9+eGGBYCLRbs0LcNb6Z7krHq+8bUgnr0dffQfbhvJCaRp135o4IBOTCCATUwHwYDVR0j" + "BBgwFoAUe7hHUqfxzFie+1Xs4S1xDgeaLyYwHQYDVR0OBBYEFFTh4cdLADjM2EtQnZFreAUtdWZuMEYGA1UdIAQ/MD0wOwYEVR0gADAzMD" + "EGCCsGAQUFBwIBFiVodHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2Nwa2kvY3BzMA4GA1UdDwEB/wQEAwIHgDBsBgNVHR8EZTBjMGGg" + "X6BdhltodHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2Nwa2kvc2VydmxldC9jcmxGaWxlRG93bi5jcmw/Y2VydHlwZT0xNCYvc29mdF" + "9zaWduX3Nydl9jcmwuY3JsMBMGA1UdJQQMMAoGCCsGAQUFBwMDMBgGDCsGAQQBj1sCgngBAwQIMAYCAQEKAQEwCgYIKoZIzj0EAwMDaAAw" + "ZQIwfX/jQDoWeCvU+U285TgTBPgj8wMY9R2aR/UvL5eKwuDiMbEMWra/7OnGeG4tM6m/AjEA6ek/0qGNL+9QoxYs+p4NCcMERSN2fbLLaC" + "OH/nqKKqzJfgMuBhsGEDylKsuAl7BuoYIFjjCCBYowggUSAgEBMAkGByqGSM49BAEwaTELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdl" + "aTETMBEGA1UECwwKSHVhd2VpIENCRzE0MDIGA1UEAwwrSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWduaW5nIFNlcnZpY2UgQ0EgVGVzdBcNMj" + "AwNDE3MDczMzMzWhcNMjAwNDE3MTEzMzMzWjCCBEYwGQIIFDszO+/tkL4XDTIwMDQwOTAyMDU1MlowGQIIFIDfZVEvZV4XDTIwMDQxNzAx" + "NTMzNVowGQIIFiZUK0nH/6QXDTIwMDQxNTA2MzIzNFowGQIIGL+HfSkra/8XDTIwMDQwOTAzMzkyNlowGQIIGPkI0PzPBfMXDTIwMDQwOT" + "AyMjExN1owGQIIG52boWhd5pUXDTIwMDQwOTAzMzk0N1owGQIIHJf1QgQM3NUXDTIwMDQxNTA3MDAzN1owGQIIH4pTuWIqJWEXDTIwMDQw" + "OTAyNTQzM1owGQIIIsCwihO7+LAXDTIwMDQwOTExNTgzNVowGQIIKChThO9DfYgXDTIwMDQwOTAyNDEyNVowGQIIK0BgS3Uf9GcXDTIwMD" + "QxNTA3MDE0NVowGQIILAAA4DasjPMXDTIwMDQxNjA4MDM1NlowGQIIMpvCbdfgPuYXDTIwMDQwOTAyMDkxNVowGQIINCJVIHTeiYYXDTIw" + "MDQxNTA2MzgwMVowGQIIN8Ia0fRWBLUXDTIwMDIyOTA3NDU0N1owGQIIOi/GDnljuBUXDTIwMDQxNjA5MjQ1MVowGQIIOoBatCyF2moXDT" + "IwMDQxNzAxNTkxMVowGQIIPA19xT0/5NEXDTIwMDQwOTAyMTU1MVowGQIIRaR2gG+LGgAXDTIwMDQxNTA2MjYwNlowGQIITKVOFNnNunsX" + "DTIwMDQxNjEwMDIzM1owGQIITpYvGppOvpcXDTIwMDQwOTAyMTcxNVowGQIIURWuWeI4VjYXDTIwMDQxNTA2NDUxOVowGQIIUU9aVvlFi7" + "oXDTIwMDQxNTEyMTYxNVowGQIIVasGnB/y1jUXDTIwMDIyOTA3MTU0N1owGQIIWRX6qcaQryMXDTIwMDQwODE1MTY0MVowGQIIWa+djVlG" + "EbIXDTIwMDQxNTEyMTgyM1owGQIIW3CBLgpBxwMXDTIwMDQxNzAxNDQxOVowGQIIY9iBfqU1OcwXDTIwMDQxNTA2MzYyN1owGQIIZE7L6T" + "01W0AXDTIwMDIyOTExNDMyM1owGQIIZYLDdnss2XQXDTIwMDQwOTEyMzg0MlowGQIIbXPas8vbtMgXDTIwMDQxNTA3MDEzN1owGQIIbeKt" + "1qif0moXDTIwMDQxNjAyMjczMFowGQIIbxVMGphkTtUXDTIwMDQwOTAyMjMxMFowGQIIdyXkFeU5m8QXDTIwMDQwOTAzNDUxNFowGQIIeD" + "0yWhmNH4oXDTIwMDQxNjAyMDIxM1owGQIIeXApZwZJ0cgXDTIwMDQwOTAyMDc1MlowGQIIeaPCxAd56HkXDTIwMDQxNTA2MzUwMlowJwII" + "fXOCr8eBtQ4XDTIwMDMwMzA2MzYwN1owDDAKBgNVHRUEAwoBATAZAgh9hnDrSBT+bxcNMjAwNDA5MDMzNzI0WjAZAgh/Mf2o86tAiRcNMj" + "AwNDE2MDI1OTE1WqAvMC0wHwYDVR0jBBgwFoAUe7hHUqfxzFie+1Xs4S1xDgeaLyYwCgYDVR0UBAMCAQAwCQYHKoZIzj0EAQNnADBkAjAe" + "FVVTeseTxNDPVjBKzVrIUJGnGpK4SJ9WpcLdwWFhGa5vK1WshKHw5rUhzvExXuACMEmkWXIdu10mvJDZCaTgT9Q40hDRpTqfOiYJdZIqLX" + "+B78CKju8ZiKPzlX854T8U/TGCAU4wggFKAgEBMHUwaTELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2Vp" + "IENCRzE0MDIGA1UEAwwrSHVhd2VpIENCRyBTb2Z0d2FyZSBTaWduaW5nIFNlcnZpY2UgQ0EgVGVzdAIIa/Smxk0FPowwDQYJYIZIAWUDBA" + "IBBQCgaTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMDA1MTIwMTQ2MjJaMC8GCSqGSIb3DQEJBDEiBCAx" + "eideQInV0KroGq8UIbL9iLYLySzJa59VG6JYNgvHIjAMBggqhkjOPQQDAgUABEYwRAIgPlEcefLiTI6O1k5bHXSQbNAdbqwzole+GCy/Fh" + "yaeToCIDGRq7Vuv3NjwJwKs5SY2VYQd8RKyGNIfyj81OGNFelrMIIZUQYJKoZIhvcNAQcCoIIZQjCCGT4CAQExDzANBglghkgBZQMEAgEF" + "ADBDBgkqhkiG9w0BBwGgNgQ0AgAAAAEAAAAoAAAAAQIAACAAAABnpJHqjk6xmfDRI0Vb4AiTDLB3/h2aJrYlm0pRCuQ++qCCBjYwggMKMI" + "ICkaADAgECAghZsSoa86pPXTAKBggqhkjOPQQDAzBYMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkg" + "Q0JHMSMwIQYDVQQDDBpIdWF3ZWkgQ0JHIFJvb3QgQ0EgRzIgVGVzdDAeFw0yMDAzMTMxMTU4MjhaFw00MDAzMTMxMTU4MjhaMGkxCzAJBg" + "NVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMMK0h1YXdlaSBDQkcgU29mdHdhcmUgU2ln" + "bmluZyBTZXJ2aWNlIENBIFRlc3QwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAS6Q8NLezROlhr+UA0JNzt5fx90YaMw9Ru+yjdO2UG/N2bRcM" + "1N1W1mrddU595+CkQ5oL8lKheCI0eR4RDhdJKbR3sxt6hgTKgQpZrUbb9I5DFtU2oot7HGUYyMy44t0xujggEVMIIBETAfBgNVHSMEGDAW" + "gBRpXcBY8fU85v0KQPEdYHPcHHjGxTAdBgNVHQ4EFgQUe7hHUqfxzFie+1Xs4S1xDgeaLyYwDwYDVR0TAQH/BAUwAwEB/zBGBgNVHSAEPz" + "A9MDsGBFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8BAf8EBAMCAQYw" + "ZgYDVR0fBF8wXTBboFmgV4ZVaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2VpLmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24uY3JsP2Nlcn" + "R5cGU9MTAmL3Jvb3RfZzJfY3JsLmNybDAKBggqhkjOPQQDAwNnADBkAjAXs+Mi444OGkOHOnDZypX/Fss0nkITEUkfFzLUPRseWMTnFO1y" + "wg3jQxrpoSLcwlACMAdAt8DNm8yat5jAqdzZsdeVLryuhJG81O+tQqnctyn3acozOJ6LIoeVYoSCtSOcpzCCAyQwggKpoAMCAQICCEa4fK" + "audOBRMAoGCCqGSM49BAMDMGkxCzAJBgNVBAYTAkNOMQ8wDQYDVQQKDAZIdWF3ZWkxEzARBgNVBAsMCkh1YXdlaSBDQkcxNDAyBgNVBAMM" + "K0h1YXdlaSBDQkcgU29mdHdhcmUgU2lnbmluZyBTZXJ2aWNlIENBIFRlc3QwHhcNMjAwNTA2MDY1MTQ4WhcNMjMwNTA2MDY1MTQ4WjBpMQ" + "swCQYDVQQGEwJDTjETMBEGA1UECgwKSHVhd2VpIENCRzEdMBsGA1UECwwUSE9TIERldmVsb3BtZW50IFRlYW0xJjAkBgNVBAMMHUhPUyBB" + "cHBsaWNhdGlvbiBQcm92aXNpb24gRGV2MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtW+qSqjlM+l/19QzBPG6/zIcmL1q08VG6j9mV0" + "2Tm+jJvRYds+minbTexEc+x6E3DpYxgtGkj65cYUe4+jtidKOCATkwggE1MB8GA1UdIwQYMBaAFHu4R1Kn8cxYnvtV7OEtcQ4Hmi8mMB0G" + "A1UdDgQWBBTe89PRef4+HYI0y/mao/HIHvBAgTBGBgNVHSAEPzA9MDsGBFUdIAAwMzAxBggrBgEFBQcCARYlaHR0cDovL2Nwa2ktY2F3ZW" + "IuaHVhd2VpLmNvbS9jcGtpL2NwczAOBgNVHQ8BAf8EBAMCB4AwbAYDVR0fBGUwYzBhoF+gXYZbaHR0cDovL2Nwa2ktY2F3ZWIuaHVhd2Vp" + "LmNvbS9jcGtpL3NlcnZsZXQvY3JsRmlsZURvd24uY3JsP2NlcnR5cGU9MTQmL3NvZnRfc2lnbl9zcnZfY3JsLmNybDATBgNVHSUEDDAKBg" + "grBgEFBQcDAzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49BAMDA2kAMGYCMQC/3+bfU3qhPlaeVhvB9FSqmnBLYVFXrFlC" + "SOe3rS60HQoE3IWdtI9P0bJ4R/pWoX8CMQCDdYonHO/RGhKDkw0mNRLIWZ6vv4iNI2F9SCOvoJ+SX2385sQ5lKSh4StldN3SSdGhghFVMI" + "IRUTCCENcCAQEwCQYHKoZIzj0EATBpMQswCQYDVQQGEwJDTjEPMA0GA1UECgwGSHVhd2VpMRMwEQYDVQQLDApIdWF3ZWkgQ0JHMTQwMgYD" + "VQQDDCtIdWF3ZWkgQ0JHIFNvZnR3YXJlIFNpZ25pbmcgU2VydmljZSBDQSBUZXN0Fw0yMDA1MTkwNDMyNDJaFw0yMDA1MTkwODMyNDJaMI" + "IQCzAZAggRw8ia8W75jBcNMjAwNDIzMDkwNzQ1WjAZAggSPIRWNvcy6BcNMjAwNDIxMDczNTQ3WjAZAggSxqS2QKLsGRcNMjAwNDIyMDIw" + "NDU2WjAZAggSzb1mEJBdLxcNMjAwNTE4MTMwMTUwWjAZAggUHl5GAn9a5BcNMjAwNTA4MDk1MjAwWjAZAggUOzM77+2QvhcNMjAwNDA5MD" + "IwNTUyWjAZAggUgN9lUS9lXhcNMjAwNDE3MDE1MzM1WjAZAggVP0dR/dhVnRcNMjAwNDI0MDcwMzQ4WjAZAggWJlQrScf/pBcNMjAwNDE1" + "MDYzMjM0WjAnAggW8pe/uV0ULRcNMjAwNDI5MTE0NjU3WjAMMAoGA1UdFQQDCgEEMBkCCBi/h30pK2v/Fw0yMDA0MDkwMzM5MjZaMBkCCB" + "j5CND8zwXzFw0yMDA0MDkwMjIxMTdaMBkCCBmrse8TKPGCFw0yMDA0MjMwOTUyNTlaMBkCCBqe/C1UiuuQFw0yMDA0MjAwODQ2MzRaMBkC" + "CBudm6FoXeaVFw0yMDA0MDkwMzM5NDdaMBkCCByX9UIEDNzVFw0yMDA0MTUwNzAwMzdaMBkCCB2f+W+m/SHvFw0yMDA1MTUwNzU1NTdaMC" + "cCCB6t45AxXxubFw0yMDA0MjcxMjQ1NDdaMAwwCgYDVR0VBAMKAQQwGQIIH4pTuWIqJWEXDTIwMDQwOTAyNTQzM1owGQIIIJ6eyjVmnyIX" + "DTIwMDUwNzA4MjAwNVowGQIIIeTffJjZ1uAXDTIwMDQyNDA2NTQ0MFowGQIIIhFU2C1gP1wXDTIwMDUwOTA4MjY0MlowGQIIIjqqS80vIx" + "QXDTIwMDUwODA5MTAzNlowGQIIIsCwihO7+LAXDTIwMDQwOTExNTgzNVowGQIIJduF1ZHbSMQXDTIwMDQyMDA3MjAwOFowGQIIKChThO9D" + "fYgXDTIwMDQwOTAyNDEyNVowGQIIKEKMGTLX2KgXDTIwMDQyNDA3MTQwMVowGQIIKH2qQauaBZ8XDTIwMDQyMDA3MzY0OFowGQIIKIo2kc" + "HT2t4XDTIwMDQyMjAyMjUyNlowGQIIKJtq9P1H8dYXDTIwMDUwODA0MDA0M1owGQIIKLLjX3ItshAXDTIwMDQyMzEyMDAxMVowGQIIKMkP" + "SPgi+0EXDTIwMDUwODA5NDYwMVowGQIIK0BgS3Uf9GcXDTIwMDQxNTA3MDE0NVowGQIILAAA4DasjPMXDTIwMDQxNjA4MDM1NlowGQIILB" + "pRL8+5mZwXDTIwMDUwNzEwMDEwMFowGQIILLqywHG708IXDTIwMDQyMDA3MjAwOFowGQIILcctigwK/OkXDTIwMDQyMDA4NDYzNFowGQII" + "LdC5XGL4EbwXDTIwMDUwODA5MjgxNFowGQIILesevZtJFO8XDTIwMDQyNDA3MjkwNVowGQIILgZpk1xCNtAXDTIwMDQyMTAzNDY0OVowGQ" + "IIMMxW0ANOPWYXDTIwMDQyNDA3MjQzM1owGQIIMiJQSIZh+zsXDTIwMDUwNzA4MzUwMVowGQIIMpWFIZRsCEoXDTIwMDQxODAyMjc0Mlow" + "GQIIMpvCbdfgPuYXDTIwMDQwOTAyMDkxNVowGQIINAqMx79nqaEXDTIwMDQyMTAzNDg0MVowGQIINCJVIHTeiYYXDTIwMDQxNTA2MzgwMV" + "owGQIINESKaOek64MXDTIwMDQyMzExNTcyN1owGQIINGS9PWvTkqQXDTIwMDQyMjAyMjQxMFowGQIINm9HCKGQbZYXDTIwMDQyMjAyMjkz" + "NlowGQIINzNWtXSL8i4XDTIwMDQyMjAzMDcwMVowGQIIN8Ia0fRWBLUXDTIwMDIyOTA3NDU0N1owGQIIOGt3O/WvI9sXDTIwMDQyNDA3Mz" + "E1MFowGQIIOLOf/5XE6J4XDTIwMDQyMzA4MTQwOFowGQIIOVoVU9S9DuYXDTIwMDQyMjAxNDI1MVowGQIIOYEZ4yqZGK0XDTIwMDQyMDA3" + "MjUzOFowGQIIOY9C2n5bLk8XDTIwMDQyMzEyMDUwMlowGQIIOi/GDnljuBUXDTIwMDQxNjA5MjQ1MVowGQIIOoBatCyF2moXDTIwMDQxNz" + "AxNTkxMVowGQIIPA19xT0/5NEXDTIwMDQwOTAyMTU1MVowGQIIPLT7f7ssWWQXDTIwMDUwODA4MjcxOFowGQIIPNCjeFLsf7gXDTIwMDQy" + "NDA3MjcwNFowJwIIPTbsmMfN3E0XDTIwMDQyOTA4MTYwN1owDDAKBgNVHRUEAwoBBDAZAgg9/xLTMvsP+xcNMjAwNDI0MDcxMjM5WjAZAg" + "hAWmUdJiOiWhcNMjAwNTA4MDk1MjAwWjAZAghBdyyT2JAmBhcNMjAwNDI0MDcyODE5WjAZAghBiOyv2p8rSRcNMjAwNDIxMDgyNTQ4WjAZ" + "AghBpLscrhmSihcNMjAwNTA5MDI0OTM5WjAZAghDGl8awjPPBhcNMjAwNDIyMDI0ODIxWjAZAghDqQWys4P59xcNMjAwNDIxMDczODIwWj" + "AZAghDtHT2zh3fbBcNMjAwNDIzMTIwMzE2WjAZAghFEL8BxuopRxcNMjAwNDI0MDcxNjMyWjAZAghFSPaAijUVkBcNMjAwNDIzMTIwNDE4" + "WjAZAghFbosqySi0ARcNMjAwNTE4MTI0OTU2WjAZAghFewgDEVa3SxcNMjAwNDIwMDgxMzAwWjAZAghFpHaAb4saABcNMjAwNDE1MDYyNj" + "A2WjAZAghGFaNwg527mxcNMjAwNDIzMDk0ODQxWjAZAghHrlNOH61BcRcNMjAwNDI0MDY1MTM3WjAZAghH442azuDPYxcNMjAwNDIwMDk1" + "NTQyWjAZAghIiJkAX3St7hcNMjAwNDIyMDE0MzA2WjAZAghJxM0ZdDYy9BcNMjAwNDIwMDczNjA2WjAZAghKWn7ubOHwqxcNMjAwNDI0MD" + "Y1MzM0WjAZAghKzRHseyakDRcNMjAwNDIzMDkxNDU3WjAZAghK5uONo4eLTxcNMjAwNTEyMDkxOTI3WjAZAghK8RS1X2IutBcNMjAwNDIz" + "MDgzNTQ4WjAnAghLBFW0WkLejRcNMjAwNDI5MDgxNTM4WjAMMAoGA1UdFQQDCgEEMBkCCEspJVytDON2Fw0yMDA0MjMwODM0MzdaMBkCCE" + "ylThTZzbp7Fw0yMDA0MTYxMDAyMzNaMBkCCEzNmjGa8E4jFw0yMDA1MTIwMjUwMjlaMBkCCE0/YY+AiORNFw0yMDA0MjAxMDEwMzhaMBkC" + "CE6WLxqaTr6XFw0yMDA0MDkwMjE3MTVaMBkCCFAd09CCIk05Fw0yMDA0MjEwMjU1MDdaMBkCCFBNwttlWKhSFw0yMDA0MjMxMjAxMzlaMB" + "kCCFBbZaGViJmpFw0yMDA0MjAwODQ4NTVaMBkCCFEVrlniOFY2Fw0yMDA0MTUwNjQ1MTlaMBkCCFFPWlb5RYu6Fw0yMDA0MTUxMjE2MTVa" + "MBkCCFHPa/3Dr91sFw0yMDA0MjAwNzIwMDhaMBkCCFJ8jfDJXghAFw0yMDA0MjIwMjQ5NTNaMBkCCFWrBpwf8tY1Fw0yMDAyMjkwNzE1ND" + "daMBkCCFaqp3Qds/3SFw0yMDA1MDgwODM5NDBaMBkCCFiO0B91crBhFw0yMDA0MjQwNzA0NTlaMBkCCFkV+qnGkK8jFw0yMDA0MDgxNTE2" + "NDFaMBkCCFmvnY1ZRhGyFw0yMDA0MTUxMjE4MjNaMBkCCFnIlVfIRjkXFw0yMDA1MDgwODM4MDBaMBkCCFtwgS4KQccDFw0yMDA0MTcwMT" + "Q0MTlaMBkCCFu8Fm6OYIGhFw0yMDA0MjMwOTU1MzdaMBkCCF1nIAjSXkMUFw0yMDA0MjEwMjU3MjRaMBkCCF4os4UVMTyyFw0yMDA0MjQw" + "NzAyMzlaMBkCCF5+i3G+5IRpFw0yMDA1MTIwOTIxMDZaMBkCCF8GjEAbzVZgFw0yMDA1MDcxMDA0MzhaMBkCCF+4tdCkDl4wFw0yMDA0Mj" + "IwMzA1NDhaMCcCCF//wxV9lHhNFw0yMDA0MjkwODE2MjhaMAwwCgYDVR0VBAMKAQQwGQIIYxLkwxiSGdUXDTIwMDQyMjAyNDI1MVowGQII" + "Y9iBfqU1OcwXDTIwMDQxNTA2MzYyN1owGQIIZE7L6T01W0AXDTIwMDIyOTExNDMyM1owGQIIZRDT7NN8CU8XDTIwMDQxODAyMjczOFowGQ" + "IIZYLDdnss2XQXDTIwMDQwOTEyMzg0MlowGQIIaeDUYW3CTw4XDTIwMDQyNDA3MTcxNlowGQIIa6l/qIaPjhMXDTIwMDUwOTAyNTA1M1ow" + "GQIIa8iBo8YJnUEXDTIwMDQyMjAzMTIxNlowGQIIbCI4QAVfbcwXDTIwMDUwODAzNTk0NFowGQIIbCNjZR+4VFgXDTIwMDQyNzA5NDcxOV" + "owGQIIbDvkcNNm4roXDTIwMDUwODA5MTA1NFowGQIIbJoslmc9AWoXDTIwMDUwODA0MDA0M1owGQIIbNKN/8olD/EXDTIwMDQyNDA3MDIw" + "MFowGQIIbPYoEIrcOqUXDTIwMDQyMDA5MzM0N1owGQIIbXPas8vbtMgXDTIwMDQxNTA3MDEzN1owGQIIbeKt1qif0moXDTIwMDQxNjAyMj" + "czMFowGQIIbxVMGphkTtUXDTIwMDQwOTAyMjMxMFowGQIIb0OxEUF//ZgXDTIwMDQyMDA3MjAzOFowGQIIcF2U+84/lksXDTIwMDQxODAy" + "MTcxOVowGQIIcIDTBxd1c/4XDTIwMDUwODA4MjczNFowGQIIcVws5rlV56oXDTIwMDQyMzA4MTUwN1owGQIIdNVdMNqpX5cXDTIwMDQyMD" + "A3MjUzOFowGQIIdWcT8qO1MC8XDTIwMDQyMDEwMDUzNFowGQIIdXDbdSAO1KIXDTIwMDQyMjAyNTAxMFowGQIIdtaE6X5Rx8YXDTIwMDQy" + "NzA3MTg0MVowGQIIdyXkFeU5m8QXDTIwMDQwOTAzNDUxNFowGQIId2WjEN2ht+EXDTIwMDQyMDA3MTYzNFowGQIIeD0yWhmNH4oXDTIwMD" + "QxNjAyMDIxM1owGQIIeEMVBDwkkzUXDTIwMDQyMjAyNDg0MFowGQIIeXApZwZJ0cgXDTIwMDQwOTAyMDc1MlowGQIIeaPCxAd56HkXDTIw" + "MDQxNTA2MzUwMlowGQIIesa6ku0aQxkXDTIwMDUwODA4MzQwOFowGQIIfRTKZtAJ7NMXDTIwMDQyMTA4MDAwN1owJwIIfXOCr8eBtQ4XDT" + "IwMDMwMzA2MzYwN1owDDAKBgNVHRUEAwoBATAZAgh9hnDrSBT+bxcNMjAwNDA5MDMzNzI0WjAZAgh9phcngSdjOBcNMjAwNDI0MDcxMTM0" + "WjAZAgh/Mf2o86tAiRcNMjAwNDE2MDI1OTE1WjAZAgh/nzTqlL59kxcNMjAwNDI0MDcxNTA0WqAvMC0wHwYDVR0jBBgwFoAUe7hHUqfxzF" + "ie+1Xs4S1xDgeaLyYwCgYDVR0UBAMCAQAwCQYHKoZIzj0EAQNpADBmAjEAhGEUqOzhyDj44i29rYQtMuh0NnsH34Wd5KKcqVvnmALJx4g/" + "YWxhYRhn+t5W5wpWAjEA2I9jN5dclJPdh8P6FN4Ylhr4T6+FfuMjVHNWdy6t+/Tl6E3OTFLi9x6bZ7QGEd/YMYIBTjCCAUoCAQEwdTBpMQ" + "swCQYDVQQGEwJDTjEPMA0GA1UEChMGSHVhd2VpMRMwEQYDVQQLEwpIdWF3ZWkgQ0JHMTQwMgYDVQQDEytIdWF3ZWkgQ0JHIFNvZnR3YXJl" + "IFNpZ25pbmcgU2VydmljZSBDQSBUZXN0AghGuHymrnTgUTANBglghkgBZQMEAgEFAKBpMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHA" + "YJKoZIhvcNAQkFMQ8XDTIwMDUyMjA3MjUwNFowLwYJKoZIhvcNAQkEMSIEID5HL8jGQ7YKAy0Cu6k8ACWppHacefnK9CS9FJyJ2B0IMAwG" + "CCqGSM49BAMCBQAERjBEAiB02lgYgtVcme6/GuCQx5OSzpuigQCOqcUYw5o/W4NyTwIgBdDvrTCGIOM4V8egLRJ6YRIai5Jyk6uJ8PHR2l" + "9xO58CAAAA7iwAAAAAAABIQVAgU2lnIEJsb2NrIDQyAgAAAFBLAQIUABQACAgIAAAAITr3yPnbBgAAAAQAAAAFAAQAAAAAAAAAAAAAAAAA" + "AAAxLnR4dP7KAABQSwUGAAAAAAEAAQA3AAAAKy0AAAAA"; + } // namespace SignatureTools +} // namespace OHOS +#endif // TEST_HAP_FILE_DATA_H diff --git a/hapsigntool_cpp/test/unittest/ohos_test.xml b/hapsigntool_cpp/test/unittest/ohos_test.xml new file mode 100644 index 0000000000000000000000000000000000000000..53c11f5636c3eead7d3cc3a63454f2305f32b8f5 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/ohos_test.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + diff --git a/hapsigntool_cpp/test/unittest/remoteSigner/packets/whole.txt b/hapsigntool_cpp/test/unittest/remoteSigner/packets/whole.txt new file mode 100644 index 0000000000000000000000000000000000000000..8708accf5ecf14a87edde514e4433ba6d0cfe974 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/remoteSigner/packets/whole.txt differ diff --git a/hapsigntool_cpp/test/unittest/remoteSigner/remote_signer_test.cpp b/hapsigntool_cpp/test/unittest/remoteSigner/remote_signer_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c6647b04f1052ba8927a6bba06759dbe3d0af70e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/remoteSigner/remote_signer_test.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "remote_sign_provider.h" + +namespace OHOS { +namespace SignatureTools { +const std::string WHOLE_HAP_PATH = "./remoteSigner/whole.hap"; +class RemoteSignerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void RemoteSignerTest::SetUpTestCase(void) +{ + (void)rename("./remoteSigner/whole.txt", WHOLE_HAP_PATH.c_str()); + sync(); +} + +void RemoteSignerTest::TearDownTestCase(void) +{ +} + +void RemoteSignerTest::SetUp() +{ +} + +void RemoteSignerTest::TearDown() +{ +} + +/** + * @tc.name: RemoteSignerTest + * @tc.desc: Test RemoteSigner interface. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RemoteSignerTest, RemoteSignerTest001, testing::ext::TestSize.Level1) +{ + std::string mode = "remoteSign"; + std::string keyAlias = "oh-app1-key-v1"; + std::string profileFile = "./remoteSigner/signed-profile.p7b"; + std::string signAlg = "SHA256withECDSA"; + std::string signCode = "1"; + std::string compatibleVersion = "8"; + std::string inFile = WHOLE_HAP_PATH; + std::string outFile = "./remoteSigner/signed.hap"; + std::string signServer = "./remoteSigner/app-release1.pem"; + std::string signerPluginV1 = "./remoteSigner/libremote_signer.z.so"; + std::string signerPluginV2 = "./remoteSigner/libremote_signer_without_create.z.so"; + std::string signerPluginV3 = "./remoteSigner/dummy.z.so"; + std::string onlineAuthMode = "./remoteSigner/OpenHarmony.p12"; + std::string username = "123456"; + char userPwd[] = "123456"; + + std::shared_ptr params = std::make_shared(); + (*params)["mode"] = mode; + (*params)["keyAlias"] = keyAlias; + (*params)["profileFile"] = profileFile; + (*params)["signAlg"] = signAlg; + (*params)["signCode"] = signCode; + (*params)["compatibleVersion"] = compatibleVersion; + (*params)["inFile"] = inFile; + (*params)["outFile"] = outFile; + (*params)["signServer"] = signServer; + (*params)["onlineAuthMode"] = onlineAuthMode; + (*params)["username"] = username; + (*params)["userPwd"] = userPwd; + + /* + * @tc.steps: step1. test remoteSign full process + * @tc.expected: step1. make the remote sign so file is right, the return will be true. + */ + (*params)["signerPlugin"] = signerPluginV1; + std::unique_ptr signProvider1 = std::make_unique(); + ASSERT_TRUE(signProvider1->Sign(params.get())); + + /* + * @tc.steps: step1. test remoteSign full process + * @tc.expected: step1. make the remote sign so file is right, the return will be true. + */ + (*params)["signerPlugin"] = signerPluginV2; + std::unique_ptr signProvider2 = std::make_unique(); + ASSERT_FALSE(signProvider2->Sign(params.get())); + + /* + * @tc.steps: step1. test remoteSign full process + * @tc.expected: step1. make the remote sign so file is right, the return will be true. + */ + (*params)["signerPlugin"] = signerPluginV3; + std::unique_ptr signProvider3 = std::make_unique(); + ASSERT_FALSE(signProvider3->Sign(params.get())); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/app-release1.pem b/hapsigntool_cpp/test/unittest/resource/codeSigning/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..886cbd21d41ae1d143882c2fc689e03057912410 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/app-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAjBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNTA4MTE1MzMyWhcNMjUwNTA4MTE1MzMyWjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE +gANeWIvryslvYakOb8HdidEPI4UuETrZ66kU1t1NJa5DipCwgpM0O0wuTW2F/hFJ +8bXM0K1BlTEGkwyJTIwm9mTTssjLAXCNV5JiFyiS9L8bIqAmG1LRmDlYxTehodkK +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFEZ4MvwluAy8Z1+oWvpdu6hNBB0+MBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwIDaQAwZgIxAO0oF//DZbZD4KobRzuz+GH9 +0uHdJ2um1AcznWC6NmmXF2wiWiHCdK0xrCcesfteZQIxANeLbVi+Z96CNd6xbqXU +uvlEMLaojC7YmSz70lfobNiaptypBJ8hxBbWY+RlZKKVuw== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICAjCCAYigAwIBAgIBATAKBggqhkjOPQQDAjBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MDgxMTUyNTlaFw0yNTA1MDgxMTUy +NTlaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABJXOFbzA +GvJ7kRpVUWrmzWZiQQuS1FJJ+hF0sBAGD0p48i3JWcsq+zVubvk8Oy1NX7mnzJ0H +YBoKtMv+k9N07bCcoUFVezhcZSLk4Bvo2tX0iRSnjrtFoH8rZ+XzDETT8KMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAgNoADBlAjEAgcO/yoSrZGn+SUjk +3KBDMO3Gqapm4GHhhUehEeAqRyrCfS03Gow8HmdVfO6tgHQsAjAY8E3CrWOUrAKM ++gX2AevV3/6tqViqrUufD1eijnngKtpn+1G0LOldAZH213gnn/o= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAjBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MDgxMTUyMjlaFw0yNTA1MDgxMTUy +MjlaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEC8wThVvicR00Z8SUj94Z34x88j1G2as4pn47KcTi +8azUixrLvmEIsaA+5E+VTzw855qdWk4HmQiCD1abmWq8REp4UhDKrYv1Ym1Hfp3e +xPRc/BwDVV0xFJ63PQDmWAUfoxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMCA2kAMGYCMQCAwFOt9eJhCTYKAdtxo7GDFRDicJACWALsgF8Qab+DgO2IvJHX +SgDGbv9t8FhWTb8CMQCbq7lRv3s526Bs/3um3eg19uohidzXMvRiPPVgBukAUZSy +yHdutdUgHoKMob2Ei8g= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/app-sign-srv-ca1.cer b/hapsigntool_cpp/test/unittest/resource/codeSigning/app-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..00a7d15904d346f43f9195590caab067f953f245 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/app-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICAjCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0xNzA4MDYxNzA1NTJaFw0xODA4MDYxNzA1 +NTJaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABB8TrYcG +n8m1NLonCDOEsBoejsPAKGsPPxnITc6PpHJ4g3m5RgL0c+wIknXBss4ZrMQIxcbg +PG8Nu91/6t3YwqV63wT3YskekUFCEGbK5B6gaqHIWR7jm9082h8eAzY1lKMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNoADBlAjBAYaXY4zaxkywVhFrC +8AVLQbMq4k9r/pNtMuUbTsmxOz66LgD7PQN5mNyCBh+ge9QCMQDIChPmQUfor/m2 +LzVFg82zD/lfXYMAnEPFK9loE6OB9NItuziSDY8sHo9N2ojcQuI= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/ohtest.jks b/hapsigntool_cpp/test/unittest/resource/codeSigning/ohtest.jks new file mode 100644 index 0000000000000000000000000000000000000000..dbc3c40df72f07d938d3588bc6b5b25d932ae787 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/codeSigning/ohtest.jks differ diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/ohtest.p12 b/hapsigntool_cpp/test/unittest/resource/codeSigning/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..bb571466a82073b187f8fcfd8027a8c288bec65e Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/codeSigning/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/profile-release1.pem b/hapsigntool_cpp/test/unittest/resource/codeSigning/profile-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..00e814698e622611076a03a5d993f83511ca433d --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/profile-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA1 +MDgxMTUzNTlaFw0yNTA1MDgxMTUzNTlaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE ++cgcr4GMXxCXYIJCTgpxKkohj9xezuqEN4Vae8hLU4VCFzu0cAoFzV/WhHr6aREc +bC2T2lXbKaRk3ddyu9PLc8cTAVtuFIL25euDDc6hc8BFlMkkOi7mGPha3SFo0Xd8 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFLnk9AmfxK4b/IJt1shzAepD/LUlMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQEwCgYIKoZIzj0EAwIDZwAwZAIwRYkkvVBhDQSj0cxfqWvcziTA +1LcCB+Sa/8NSIfGPWO8Lb6YOCnmsSfQYIafoIN0LAjB3v4k+jdJaO70zZpL9DF4Y +3m/sQW9Cv7zowlj0ByikUDZzXZmO6cLGJqGOmGWH/B8= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB/TCCAYSgAwIBAgIBATAKBggqhkjOPQQDAjBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MDgxMTUzMTVaFw0yNTA1MDgxMTUz +MTVaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEnXBbn2sZZ/Hy +44xkF9bzBHRoWtt1xDGxMxXSJDaQrRAttty76sMbxvNFWnxCjEavTx2m+yl9sX7R +AxOOB7L/FEKVISuzDbJLBOqiDhD4OgAmuChuW54KDqBsIRwSNEQ2oxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMCA2cAMGQCMDURAx9wpY/KWmCV3aTr9r95 +ee29lZpYbyjqyGCEFgNp1MG8MJxgkqkCxPSuQORHCwIwMcUYJsxMCrKRYw5YPeNX +Yd68lxTRDv1ROSgFD3UMjXpRb1SKNA6CQsSwcROwoTkg +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAjBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MDgxMTUyMjlaFw0yNTA1MDgxMTUy +MjlaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEC8wThVvicR00Z8SUj94Z34x88j1G2as4pn47KcTi +8azUixrLvmEIsaA+5E+VTzw855qdWk4HmQiCD1abmWq8REp4UhDKrYv1Ym1Hfp3e +xPRc/BwDVV0xFJ63PQDmWAUfoxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMCA2kAMGYCMQCAwFOt9eJhCTYKAdtxo7GDFRDicJACWALsgF8Qab+DgO2IvJHX +SgDGbv9t8FhWTb8CMQCbq7lRv3s526Bs/3um3eg19uohidzXMvRiPPVgBukAUZSy +yHdutdUgHoKMob2Ei8g= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/profile-sign-srv-ca1.cer b/hapsigntool_cpp/test/unittest/resource/codeSigning/profile-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..22f8d4ae4e49bdb0af364b46608cd2ec3cb1b28e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/profile-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB/TCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0xNzA4MDYxNzA2MDNaFw0xODA4MDYxNzA2 +MDNaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAElC+gI6EWbJ9q +OQdd3cSbibrueLxH7KSPiU58kP2sVDATDPcgBLEJkaVaUbEqmqM3q+p0mI2u9s0B +YK/80m6s1OZU5ceaMlQIUHFgRa9Bg7lYUPulDuH9dUB+Pw/kURoOoxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA2cAMGQCMACsvXzfMhwi9InCwVjJteXb +qhh1HlvHZ+Nh+LnXp7r6fjqaqDDlqLtdpZjDr4Fe8gIwS47asWM21bhdwdj5Unfs +Fex2P3+CbgCckFiSS+wd07H5OiI8nrNgofWx32o+cCj5 +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/root-ca1.cer b/hapsigntool_cpp/test/unittest/resource/codeSigning/root-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..e45df9f389ed7596c14230c88d8bffeab2dd4087 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/root-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB6TCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0xNzA4MDYxNzA1MzBaFw0xODA4MDYxNzA1 +MzBaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAENM3BYhCgADNFGffXYZq/nZoxnfjN9h5k3ozVMctd +LT/2a3Zmk/jPEQ5GHTWkmmb57ukhnHnPNxRvVC7FbFDH/ZPYL7MjF0SOIEQFyFUV +Y3sfWwFAkLhyZpANrzD4H6tooxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2gAMGUCMQCoiOUYJ0X2fAPa8IxB+tA2QOftkKS6OG+OReEGp2w0YK9MIn+e +ZD4vVfnXskDUc20CMAOwFX7xZuraLmGgeZN5bpLkVGW17TewLllC5dSrEo5H9fcP +kzE/oiico7CK6NI9nA== +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/rootPrikey.pem b/hapsigntool_cpp/test/unittest/resource/codeSigning/rootPrikey.pem new file mode 100644 index 0000000000000000000000000000000000000000..15955a80555db8594d5bce63b793318ab5530197 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/rootPrikey.pem @@ -0,0 +1,6 @@ +-----BEGIN EC PRIVATE KEY----- +MIGkAgEBBDDK9vGeFwtj4sFQ/4EY6x3k+JY8lc5hmBXnq8elpAdnbxvMbS2IzmB7 +JolgtD5BPWygBwYFK4EEACKhZANiAAQ0zcFiEKAAM0UZ99dhmr+dmjGd+M32HmTe +jNUxy10tP/ZrdmaT+M8RDkYdNaSaZvnu6SGcec83FG9ULsVsUMf9k9gvsyMXRI4g +RAXIVRVjex9bAUCQuHJmkA2vMPgfq2g= +-----END EC PRIVATE KEY----- diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/rootPubkey.pem b/hapsigntool_cpp/test/unittest/resource/codeSigning/rootPubkey.pem new file mode 100644 index 0000000000000000000000000000000000000000..c1b6e44e33f5452af560b4431acef57744da6152 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/rootPubkey.pem @@ -0,0 +1,4 @@ +LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUhZd0VBWUhLb1pJemowQ0FRWUZL +NEVFQUNJRFlnQUVOTTNCWWhDZ0FETkZHZmZYWVpxL25ab3huZmpOOWg1awozb3pW +TWN0ZExULzJhM1ptay9qUEVRNUdIVFdrbW1iNTd1a2huSG5QTnhSdlZDN0ZiRkRI +L1pQWUw3TWpGMFNPCklFUUZ5RlVWWTNzZld3RkFrTGh5WnBBTnJ6RDRINnRvCi0t diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/signed-profile.p7b b/hapsigntool_cpp/test/unittest/resource/codeSigning/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..27ebd27b82c36c80d5f80e475670535594a8176f Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/codeSigning/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/codeSigning/sub.csr b/hapsigntool_cpp/test/unittest/resource/codeSigning/sub.csr new file mode 100644 index 0000000000000000000000000000000000000000..e974062764c78160af71a3a3ac90608f3d369803 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/codeSigning/sub.csr @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +-----BEGIN CERTIFICATE REQUEST----- +MIIBYjCB6QIBADBqMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTElMCMGA1UEAwwcUHJvZmls +ZSBTaWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABJQv +oCOhFmyfajkHXd3Em4m67ni8R+ykj4lOfJD9rFQwEwz3IASxCZGlWlGxKpqjN6vq +dJiNrvbNAWCv/NJurNTmVOXHmjJUCFBxYEWvQYO5WFD7pQ7h/XVAfj8P5FEaDqAA +MAoGCCqGSM49BAMDA2gAMGUCMAmV7db3cKc4g0HZpJaKsAwvHdmdMMZ3RZxi7CNG +j8NVgnlDM+wZsYHRy5mSh+lgPAIxAM8zGs9n2i+8MkiLqJo+m69DjS+cttfDwcv4 +8xKzyx1WPNzGP5cXlLe7kJVvajqekA== +-----END CERTIFICATE REQUEST----- diff --git a/hapsigntool_cpp/test/unittest/resource/elfVerify/readonly.cer b/hapsigntool_cpp/test/unittest/resource/elfVerify/readonly.cer new file mode 100644 index 0000000000000000000000000000000000000000..fb0b782363d34a02c3ed28fc3537b0df6c71ea2b --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/elfVerify/readonly.cer @@ -0,0 +1,44 @@ +C=CN, O=OpenHarmony, OU=OpenHarmony Community, CN=Profile1 Release +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA1 +MDgxMTUzNTlaFw0yNTA1MDgxMTUzNTlaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE ++cgcr4GMXxCXYIJCTgpxKkohj9xezuqEN4Vae8hLU4VCFzu0cAoFzV/WhHr6aREc +bC2T2lXbKaRk3ddyu9PLc8cTAVtuFIL25euDDc6hc8BFlMkkOi7mGPha3SFo0Xd8 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFLnk9AmfxK4b/IJt1shzAepD/LUlMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQEwCgYIKoZIzj0EAwIDZwAwZAIwRYkkvVBhDQSj0cxfqWvcziTA +1LcCB+Sa/8NSIfGPWO8Lb6YOCnmsSfQYIafoIN0LAjB3v4k+jdJaO70zZpL9DF4Y +3m/sQW9Cv7zowlj0ByikUDZzXZmO6cLGJqGOmGWH/B8= +-----END CERTIFICATE----- +C=CN, O=OpenHarmony, OU=OpenHarmony Community, CN=Profile Signature Service CA +-----BEGIN CERTIFICATE----- +MIIB/TCCAYSgAwIBAgIBATAKBggqhkjOPQQDAjBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MDgxMTUzMTVaFw0yNTA1MDgxMTUz +MTVaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEnXBbn2sZZ/Hy +44xkF9bzBHRoWtt1xDGxMxXSJDaQrRAttty76sMbxvNFWnxCjEavTx2m+yl9sX7R +AxOOB7L/FEKVISuzDbJLBOqiDhD4OgAmuChuW54KDqBsIRwSNEQ2oxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMCA2cAMGQCMDURAx9wpY/KWmCV3aTr9r95 +ee29lZpYbyjqyGCEFgNp1MG8MJxgkqkCxPSuQORHCwIwMcUYJsxMCrKRYw5YPeNX +Yd68lxTRDv1ROSgFD3UMjXpRb1SKNA6CQsSwcROwoTkg +-----END CERTIFICATE----- +C=CN, O=OpenHarmony, OU=OpenHarmony Community, CN=Root CA +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAjBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MDgxMTUyMjlaFw0yNTA1MDgxMTUy +MjlaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEC8wThVvicR00Z8SUj94Z34x88j1G2as4pn47KcTi +8azUixrLvmEIsaA+5E+VTzw855qdWk4HmQiCD1abmWq8REp4UhDKrYv1Ym1Hfp3e +xPRc/BwDVV0xFJ63PQDmWAUfoxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMCA2kAMGYCMQCAwFOt9eJhCTYKAdtxo7GDFRDicJACWALsgF8Qab+DgO2IvJHX +SgDGbv9t8FhWTb8CMQCbq7lRv3s526Bs/3um3eg19uohidzXMvRiPPVgBukAUZSy +yHdutdUgHoKMob2Ei8g= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/OpenHarmony.p12 b/hapsigntool_cpp/test/unittest/resource/generateCA/OpenHarmony.p12 new file mode 100644 index 0000000000000000000000000000000000000000..c97cb66984b92d3cd228033fce03dc2e8f573ded Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateCA/OpenHarmony.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/OpenHarmony1.p12 b/hapsigntool_cpp/test/unittest/resource/generateCA/OpenHarmony1.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f9bb2d0511b411cd2d51658fbdbf724a83dc9a57 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateCA/OpenHarmony1.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/app-sign-srv-ca1.cer b/hapsigntool_cpp/test/unittest/resource/generateCA/app-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..1083a95c26e4561ae01a24eba6fde83344d0b50b --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateCA/app-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICCTCCAY+gAwIBAgIIW5GcLu/C7jowCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjE3MDMwMDMzWhcNMzQw +NjE1MDMwMDMzWjBuMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTEpMCcGA1UEAwwgQXBwbGlj +YXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwdjAQBgcqhkjOPQIBBgUrgQQAIgNi +AAQGEl+CJE6Pocw15dIrBbgD/xYXsTVNxQg4Xon1TKkPOZK+YinO1yEf5tsQRnbY +99uDl6+XpBTY5qIetV14yDCIkGQyiNKK0vtQGk3raKoaa3eiV0t/YHm4TSvZgFYS +hfOjEzARMA8GA1UdEwQIMAYBAf8CAQAwCgYIKoZIzj0EAwMDaAAwZQIxAMKnEvkq +Mr+piaRdgB3mjF4YpBywCcVC4UwNbWTL8Do/TyxLN6KSGaoNmBepeW2hzQIwQ4IA +V+jAcBrplY02ZnDniW/ttnaOyd4CXT7c4bv+uZZLxbGBrikUNmnf8ue9A8j/ +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/apptest.p12 b/hapsigntool_cpp/test/unittest/resource/generateCA/apptest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..e1ae5478f00b37b5315e1eea08a015f3e9f4c587 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateCA/apptest.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/ohtest.p12 b/hapsigntool_cpp/test/unittest/resource/generateCA/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..022a182258d12c284449ea961b981c484ba6335d Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateCA/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/profile-sign-srv-ca1.cer b/hapsigntool_cpp/test/unittest/resource/generateCA/profile-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..676db8ff47304176fd36651a3462b68201f3a784 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateCA/profile-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICBTCCAYugAwIBAgII+khBvfAMGqUwCgYIKoZIzj0EAwMwVTELMAkGA1UEBhMC +Q04xFDASBgNVBAoMC09wZW5IYXJtb255MR4wHAYDVQQLDBVPcGVuSGFybW9ueSBD +b21tdW5pdHkxEDAOBgNVBAMMB1Jvb3QgQ0EwHhcNMjQwNjE1MDczNDU1WhcNMjUw +NjE1MDczNDU1WjBqMQswCQYDVQQGEwJDTjEUMBIGA1UECgwLT3Blbkhhcm1vbnkx +HjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0eTElMCMGA1UEAwwcUHJvZmls +ZSBTaWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABBnv +25yOncnQealn6zh2B3JPqQP1QvbySDYwUClyqqWv949XN9JRfby/gmnSXjR75BXx +s9SVMGoz/F6JKF0dUPp4ttOMSYqzLBE+UYI1hewvIp9R4a33quolxuKJeCjv2aMT +MBEwDwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNoADBlAjBaR7W28/FArcxZ +VDxj/bBoW3Kq+ymswCwIpVrmB7DpEhOl4iSofbL3NvToWGCtYpMCMQDsBrJMnqKx +kzzYOlJ1Tmu/2xC6rOLgPn0EpZftLpbgR6heLUt78q5m6vBMV8F2xbM= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/profile-sign-srv-ca1test.cer b/hapsigntool_cpp/test/unittest/resource/generateCA/profile-sign-srv-ca1test.cer new file mode 100644 index 0000000000000000000000000000000000000000..f40a14c89b303dac5bd0991c8cc74c8596493954 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateCA/profile-sign-srv-ca1test.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB/jCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yMzA4MDUwOTIwNDNaFw0yNDA4MDQwOTIw +NDNaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEF+vCQnGuAjaJ +D0IZl6VBtH1BfaxcKq8nxZlqhwPQ04hZ7J+YocmnYL0LVDYIskBRUU50YuEOdQNW +FR3/R9F36IbTbW9QrL8zIUwYs3ISdvNcf8IT1e2337mBPHleV8jnoxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA2gAMGUCMQCTiGJQ7OJVDK60yNLQqcM4 +116vCZt7wM9Cu51VlN+GrdeVZaHsDOuunHGWhx9DWeMCMAGnjB+zGyZDjNKBgwdc +hiob7oAN6vBZEmUpdxru6ty7DqInKjr5QqhGSwjCcQTYNg== +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/root-ca1.cer b/hapsigntool_cpp/test/unittest/resource/generateCA/root-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..96593e5169efbf0790b1a6aa9d42d1756970933b --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateCA/root-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB7zCCAXWgAwIBAgIHr+ykXzRxQDAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJD +TjEUMBIGA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENv +bW11bml0eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MTcwMjU5MzdaFw0yNTA2 +MTcwMjU5MzdaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEe +MBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENB +MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEZmG6LbwmkTdG6BswxBVMAl+skd6X5/51 +v1OxB+W+Ug77i/s/TsDnfwuQvjcViroozYFNPxRSwJJQ9tSjBNogBpFQSgarOJrW +H7dnE5QvqHlvvx93x2XqR6zs6PhW7cUwoxMwETAPBgNVHRMECDAGAQH/AgEAMAoG +CCqGSM49BAMDA2gAMGUCMQDkXLXMZTknnLzlwSruEMObjEItwF3ZHjCTBo62EI9k +5X0HyW0xxGPigvknS5czJX8CMEKD/UfktN731CDz24ogKhiPyJOFvxqLi2GyKb97 +v+4ChH3VYDIHkz5l/SUK+XPmVw== +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateCA/root-ca1test.cer b/hapsigntool_cpp/test/unittest/resource/generateCA/root-ca1test.cer new file mode 100644 index 0000000000000000000000000000000000000000..90b3aba66f279771149f47d8798c35e1a368f52a --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateCA/root-ca1test.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yMzA4MDUwOTIwMjBaFw0yNDA4MDQwOTIw +MjBaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEKYjo4oUoHev5f4D+P5uOYSGAGq439OIrgkXi6sQP +2ku/Ovln3BPZYf10vqym+YLSkJbTVqUiEdkPBl/vy+kPxzu4VJG0AhL8QOKHeeBH +KNTwgM+i1AtmmYQ57WviEzleoxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2kAMGYCMQDzlOyoFx38xmTeUC9RFel2fU3kBOvvE0QN9aP5Fz4S7Wm72QtX +25INA1Dl040hNpECMQDE6K6yq8hCu+GmHR/cGZ+/fDcuUkHOtO0Iw5BKMOUDkeM3 +5Vj0L8RnL3dgjAfvlv0= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateCsr/ohtest.p12 b/hapsigntool_cpp/test/unittest/resource/generateCsr/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..de5c0e36a8a937f2d19934600575c10c4393a2ed Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateCsr/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/OpenHarmony.p12 b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/OpenHarmony.p12 new file mode 100644 index 0000000000000000000000000000000000000000..16ea9840a1582fde8cdb4692aaa7ba14d2abd9a3 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/OpenHarmony.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/OpenHarmonyDamage.p12 b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/OpenHarmonyDamage.p12 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/VerifyResult.json b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/VerifyResult.json new file mode 100644 index 0000000000000000000000000000000000000000..cad5cac3e5bb221fa1db9993efa223b8c1ebb05d --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/VerifyResult.json @@ -0,0 +1 @@ +{"bundle-info":{"app-feature":"hos_system_app","bundle-name":"com.example.nativetemplatedemo","developer-id":"OpenHarmony","development-certificate":"-----BEGIN CERTIFICATE-----\nMIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\nMjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\nodSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\nUYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\no2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\nBQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\nAwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\nQT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\n4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\n-----END CERTIFICATE-----\n"},"debug-info":{"device-id-type":"udid","device-ids":["69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42","7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865"]},"issuer":"pki_internal","permissions":{"restricted-permissions":[""]},"type":"debug","uuid":"fe686e1b-3770-4824-a938-961b140a7c98","validity":{"not-after":1705127532,"not-before":1610519532},"version-code":1,"version-name":"1.0.0"} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-profile.p7b b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..5fa5b32985cc4664f20dcff2fa89e3245b908cc6 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-profile.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-release1.pem b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..ab0ff2461f69cb00df9a344a33109334381d4bac --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNTIyMDExMDEzWhcNMjUwNTIyMDExMDEzWjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE +Ur/rtQ7SewSvYko2QBabRWP9WJihVjIp+f7nKjCReN7+2+gcM4oVGKnynCmWd2Gy +adGn29nBR7i1lq2K+Tfj0OipQlQJr7AUtDxqs+5hO5/y/v3Zq/sFSvpjGttMtHP8 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFEDw+uxLfU+LaHit0VLzzulTt0QQMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQEwCgYIKoZIzj0EAwMDZwAwZAIwOFMX3TFornjBpMJjGDo6WhWl +HpklzhGTJHypjw+6jdNjoJ2R2Yb3krorQsvygx2ZAjARErUA1CWigJyzQEvafwi0 +kGnvwxPp1y9EBgfmGyi1DOq/NwK3GtiAPXk3xifvgn8= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICAjCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MjIwMTA5MTVaFw0yNTA1MjIwMTA5 +MTVaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABHNB77ZB +4ncBecQ1CZ1xgY3dmDbyFAHcZp0YL8BrE5EL3LTdbo2seKV99q9RqfannBXjZCoL +4BxtUlYYk0bJ7h4JwyllvA7t2HlNitGMFETNwJz25bId9FLYO0iZSaueJqMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNoADBlAjBiHsIMwkrPv7DwZJOe +6o3hAlctaDZU3k1LKp/UjOLpwrr2Z/Q7PNnzUWRElX9GOZMCMQDq18gcV8NPZXYo +d/IDH0LkTgBrH1IlXjrGOamAqQMn/GcRwusHc+YqdWyg/895+WQ= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6DCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MjIwMTA4NTdaFw0yNTA1MjIwMTA4 +NTdaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEzQt3bmc0sy0xpihXJ9lnCs6C43Ms7yzNYgFB9u39 +yB+UeD23mbP0bx0zTSHT0HbmadDyVK4o2xkBHe7vslSFJxbxG4998B7YNOm/qv4g +3qBZHGl0WdJRa6RWHzGvnKploxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2cAMGQCMATCdPn7YWzjUzE64pFpXsYuZpqa79iVYm54/HghpYamYK/pQCie +MYBEvbmSZr1L0gIwCSkMOSszkWkb5jg7PyGGJcqenr/ENxf6X3fKJVhAUsQ6GYaY +WCk/j10qCytH0M6n +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-sign-srv-ca1.cer b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..330bf098a19bf90f2ca3111e5a7faa6604b74862 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/app-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICAjCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MjIwMTA5MTVaFw0yNTA1MjIwMTA5 +MTVaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABHNB77ZB +4ncBecQ1CZ1xgY3dmDbyFAHcZp0YL8BrE5EL3LTdbo2seKV99q9RqfannBXjZCoL +4BxtUlYYk0bJ7h4JwyllvA7t2HlNitGMFETNwJz25bId9FLYO0iZSaueJqMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNoADBlAjBiHsIMwkrPv7DwZJOe +6o3hAlctaDZU3k1LKp/UjOLpwrr2Z/Q7PNnzUWRElX9GOZMCMQDq18gcV8NPZXYo +d/IDH0LkTgBrH1IlXjrGOamAqQMn/GcRwusHc+YqdWyg/895+WQ= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile-sign-srv-ca1.cer b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile-sign-srv-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..9e6f113d1b849413ed908642b3e3a7fb1a7d6eff --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile-sign-srv-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB/zCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MjIwMTA5NTRaFw0yNTA1MjIwMTA5 +NTRaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEYxLy1noyuYxM +h9ZX5WSJ8ZXhFMY/9EQwINt9KDdR6c4U5glNXIic19HRzpqFspuH/GUWT0YSkjY4 +26wVxZ03ID/7re5FndjRleQyato9kmlUzQzLtLVAOhkhp93XCO8GoxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA2kAMGYCMQDtnr6biQyw3jyk2/JYfEKC ++CywD8znunIHClUJE1GSghwbHhf3SzuE10a45j0NB8sCMQDVW4bXLCJxyLEewHX4 +dVHU+skIebcMx2GjGZKYjtWUwjP6JcA8I1mkQR++NhtDTrs= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile.json b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile.json new file mode 100644 index 0000000000000000000000000000000000000000..824028a6d187a81b9a5d5b02c0491381f5227f10 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile.json @@ -0,0 +1,31 @@ +{ + "version-name": "1.0.0", + "version-code": 1, + "uuid": "fe686e1b-3770-4824-a938-961b140a7c98", + "validity": { + "not-before": 1610519532, + "not-after": 1705127532 + }, + "type": "debug", + "bundle-info": { + "developer-id": "OpenHarmony", + "development-certificate": "-----BEGIN CERTIFICATE-----\nMIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\nMjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\nA1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\neTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\nodSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\nUYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\no2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\nBQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\nAwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\nQT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\n4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\n-----END CERTIFICATE-----\n", + "bundle-name": "com.example.nativetemplatedemo", + "app-feature": "hos_system_app" + }, + "permissions": { + "restricted-permissions": [ + "" + ] + }, + "debug-info": { + "device-ids": [ + "69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42", + "7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865" + ], + "device-id-type": "udid" + }, + "issuer": "pki_internal" +} + + diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile1.cer b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile1.cer new file mode 100644 index 0000000000000000000000000000000000000000..2a00df1acb921ed7d3c6886cbebe19308d67fa7f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/profile1.cer @@ -0,0 +1,15 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA1 +MjIwMTEwMjhaFw0yNTA1MjIwMTEwMjhaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE +15FqX6YrnTWzUfvQy6lv69YpOeZUfsKn64l3VQ00uVlEbUBH79HLzO21dg9GlKyr +L6I6P41Gcarc5yp4KV8/NfRPS7RIhqZYWLsw6rYeuflo3qj9YcZjgTwKf1Hc28vQ +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFBHlS/2GoS6VdB4cpxefIpwmwPv7MBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQEwCgYIKoZIzj0EAwMDZwAwZAIwJO1l3dwR3D8HKbsPpXrbe4LH +K4Ei6o+t4f1d9cGqGUW+25TJ71CEVrqMthqrOKuuAjAcX3NeSY5ux7n2tGVKbPLf +ZWfXcIFycewPDMnrIn3sInZHSPMPAQBIMqSU3X/W6pw= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/root-ca1.cer b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/root-ca1.cer new file mode 100644 index 0000000000000000000000000000000000000000..953185b6564897da83ec7e4b9eb92ef8d66e66ae --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/root-ca1.cer @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB6DCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MjIwMTA4NTdaFw0yNTA1MjIwMTA4 +NTdaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEzQt3bmc0sy0xpihXJ9lnCs6C43Ms7yzNYgFB9u39 +yB+UeD23mbP0bx0zTSHT0HbmadDyVK4o2xkBHe7vslSFJxbxG4998B7YNOm/qv4g +3qBZHGl0WdJRa6RWHzGvnKploxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2cAMGQCMATCdPn7YWzjUzE64pFpXsYuZpqa79iVYm54/HghpYamYK/pQCie +MYBEvbmSZr1L0gIwCSkMOSszkWkb5jg7PyGGJcqenr/ENxf6X3fKJVhAUsQ6GYaY +WCk/j10qCytH0M6n +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/rootPrikey.pem b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/rootPrikey.pem new file mode 100644 index 0000000000000000000000000000000000000000..78d1fc0e750120ea603d514daa04c7e17d308963 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/rootPrikey.pem @@ -0,0 +1,6 @@ +-----BEGIN EC PRIVATE KEY----- +MIGkAgEBBDD60jRpO8poqydrRyT8zyQM91RqwNIldK0SIKd1nxGetWJ+1bCU1CNi +0CEurs9ksCagBwYFK4EEACKhZANiAATNC3duZzSzLTGmKFcn2WcKzoLjcyzvLM1i +AUH27f3IH5R4PbeZs/RvHTNNIdPQduZp0PJUrijbGQEd7u+yVIUnFvEbj33wHtg0 +6b+q/iDeoFkcaXRZ0lFrpFYfMa+cqmU= +-----END EC PRIVATE KEY----- diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/rootPubkey.pem b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/rootPubkey.pem new file mode 100644 index 0000000000000000000000000000000000000000..ac4844fd4bbd874f714a2bfa9757a08a735a1d6f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/rootPubkey.pem @@ -0,0 +1,4 @@ +LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUhZd0VBWUhLb1pJemowQ0FRWUZL +NEVFQUNJRFlnQUV6UXQzYm1jMHN5MHhwaWhYSjlsbkNzNkM0M01zN3l6TgpZZ0ZC +OXUzOXlCK1VlRDIzbWJQMGJ4MHpUU0hUMEhibWFkRHlWSzRvMnhrQkhlN3ZzbFNG +SnhieEc0OTk4QjdZCk5PbS9xdjRnM3FCWkhHbDBXZEpSYTZSV0h6R3ZuS3BsCi0t diff --git a/hapsigntool_cpp/test/unittest/resource/generateKeyPair/signed-profile.p7b b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..e11352f96f5bede70f684013872da8d37ab46c7f Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/generateKeyPair/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/hapSign/app-release1.pem b/hapsigntool_cpp/test/unittest/resource/hapSign/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..808e5d708074d6b7c065ce117fb500bf5e26efed --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/hapSign/app-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNTE4MDQ1MzQzWhcNMjUwNTE4MDQ1MzQzWjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE ++04w+5zGqED2KchTGuk2elEN4fm2o25Se6PKYckLisCGVFfHsBI82YV+5ZuHWWlQ +g41Vjg4zoZMaZZB9aRoS/WJF7WqdmIj0Z3oR2hKjuK1KFE84HZJtSvhv73kFDy93 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFOByt27GaQS0FI1YSgi305J803ouMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDZwAwZAIwFJc69hPcTKT6laW6dv6PTs9Z +hZfhFHdxmvZUPSc9BpC66euaa3x4Qog6Ud1v5GHtAjByFfBhxwQ7MKVqpqgHYznK +F6AGNITX1Uu7F+78l/VdqjUnBagHf+A4zpkP+96sXv8= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICAzCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUyMDZaFw0yNTA1MTgwNDUy +MDZaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGOgpW8s +Sc7ed3633LQVYKSBAxLgv1h8UlQqUPBCFdht+d2DeyjVG3cUM3C0+SHiBGYE1Y6/ +gPM8avBXjedRxZkWj4L3+vwqbE2EyToS9haJK5zFiEYMSapQ0fw46kTAYaMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNpADBmAjEAwfpd7dzUzjJLypyg +/gcCmwn8JG845RU2p5XSF3NGx25eRF5CjOBMutMOwMCh6k+WAjEAyiefVEkXRox6 +/9BGyNQxE4vijOR9P8KPbHhWqa1AxMf3n9Ub/GtrCl+bKh7xdfcK +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUwNDJaFw0yNTA1MTgwNDUw +NDJaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEQrLv/IWf/6m6OL+EUzHWuknOv9USUsfq/B9z2lKP +8dXyDIOI2N5gNbSRZuSLQVY8XNjUjRfCoNSQXG5NCy4AG863AVsLbIrU7WSclDxi +O3teTpfuYCdRy0tDk6dxSXWloxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2kAMGYCMQDDTXyRxZOe5WpPSrqVILmI8rkL2TQB4j7NoYZXCKQ3HMj66Ct7 +wNASFAHlxOBnztcCMQCYAoo9nyo4fKvFIiWFbXraPJ4AX9a2cZwvOM/P1kVyrxX2 +6sKc2Qw5Y1A0avI1saQ= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/hapSign/app1-profile1.p7b b/hapsigntool_cpp/test/unittest/resource/hapSign/app1-profile1.p7b new file mode 100644 index 0000000000000000000000000000000000000000..dcaaaf2b90c023ca233c0ca2bd4e8962e58cb731 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/hapSign/app1-profile1.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/hapSign/ohtest.jks b/hapsigntool_cpp/test/unittest/resource/hapSign/ohtest.jks new file mode 100644 index 0000000000000000000000000000000000000000..dbc3c40df72f07d938d3588bc6b5b25d932ae787 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/hapSign/ohtest.jks differ diff --git a/hapsigntool_cpp/test/unittest/resource/hapSign/ohtest.p12 b/hapsigntool_cpp/test/unittest/resource/hapSign/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f3eae4d373faa3caff06021db21786f81d7af92f Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/hapSign/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/hapSign/signed-profile.p7b b/hapsigntool_cpp/test/unittest/resource/hapSign/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7e8192a1fc8376cbc49ee3a5fba5f173e48d0c08 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/hapSign/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/hapVerify/verify_err.p7b b/hapsigntool_cpp/test/unittest/resource/hapVerify/verify_err.p7b new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hapsigntool_cpp/test/unittest/resource/hapVerify/verify_test.p7b b/hapsigntool_cpp/test/unittest/resource/hapVerify/verify_test.p7b new file mode 100644 index 0000000000000000000000000000000000000000..eb6743bab2dd84b676120231128ba212dd58841d Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/hapVerify/verify_test.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/remoteSigner/OpenHarmony.p12 b/hapsigntool_cpp/test/unittest/resource/remoteSigner/OpenHarmony.p12 new file mode 100644 index 0000000000000000000000000000000000000000..f3eae4d373faa3caff06021db21786f81d7af92f Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/remoteSigner/OpenHarmony.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/remoteSigner/app-release1.pem b/hapsigntool_cpp/test/unittest/resource/remoteSigner/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..808e5d708074d6b7c065ce117fb500bf5e26efed --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/remoteSigner/app-release1.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIICXDCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNTE4MDQ1MzQzWhcNMjUwNTE4MDQ1MzQzWjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE ++04w+5zGqED2KchTGuk2elEN4fm2o25Se6PKYckLisCGVFfHsBI82YV+5ZuHWWlQ +g41Vjg4zoZMaZZB9aRoS/WJF7WqdmIj0Z3oR2hKjuK1KFE84HZJtSvhv73kFDy93 +o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF +BQcDAzAbBgNVHQ4EFOByt27GaQS0FI1YSgi305J803ouMBgGDCsGAQQBj1sCgngB +AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDZwAwZAIwFJc69hPcTKT6laW6dv6PTs9Z +hZfhFHdxmvZUPSc9BpC66euaa3x4Qog6Ud1v5GHtAjByFfBhxwQ7MKVqpqgHYznK +F6AGNITX1Uu7F+78l/VdqjUnBagHf+A4zpkP+96sXv8= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICAzCCAYigAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUyMDZaFw0yNTA1MTgwNDUy +MDZaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTB2MBAGByqGSM49AgEGBSuBBAAiA2IABGOgpW8s +Sc7ed3633LQVYKSBAxLgv1h8UlQqUPBCFdht+d2DeyjVG3cUM3C0+SHiBGYE1Y6/ +gPM8avBXjedRxZkWj4L3+vwqbE2EyToS9haJK5zFiEYMSapQ0fw46kTAYaMTMBEw +DwYDVR0TBAgwBgEB/wIBADAKBggqhkjOPQQDAwNpADBmAjEAwfpd7dzUzjJLypyg +/gcCmwn8JG845RU2p5XSF3NGx25eRF5CjOBMutMOwMCh6k+WAjEAyiefVEkXRox6 +/9BGyNQxE4vijOR9P8KPbHhWqa1AxMf3n9Ub/GtrCl+bKh7xdfcK +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB6jCCAW+gAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA1MTgwNDUwNDJaFw0yNTA1MTgwNDUw +NDJaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMHYwEAYH +KoZIzj0CAQYFK4EEACIDYgAEQrLv/IWf/6m6OL+EUzHWuknOv9USUsfq/B9z2lKP +8dXyDIOI2N5gNbSRZuSLQVY8XNjUjRfCoNSQXG5NCy4AG863AVsLbIrU7WSclDxi +O3teTpfuYCdRy0tDk6dxSXWloxMwETAPBgNVHRMECDAGAQH/AgEAMAoGCCqGSM49 +BAMDA2kAMGYCMQDDTXyRxZOe5WpPSrqVILmI8rkL2TQB4j7NoYZXCKQ3HMj66Ct7 +wNASFAHlxOBnztcCMQCYAoo9nyo4fKvFIiWFbXraPJ4AX9a2cZwvOM/P1kVyrxX2 +6sKc2Qw5Y1A0avI1saQ= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/remoteSigner/signed-profile.p7b b/hapsigntool_cpp/test/unittest/resource/remoteSigner/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..e93127913fb04430028a26853bf3bfb97c9ec259 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/remoteSigner/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/VerifyResult.json b/hapsigntool_cpp/test/unittest/resource/signProfile/VerifyResult.json new file mode 100644 index 0000000000000000000000000000000000000000..d739a9edb6ba9a0d99656be91f515b0b0f75f134 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/VerifyResult.json @@ -0,0 +1 @@ +{"bundle-info":{"app-feature":"hos_system_app","bundle-name":"com.OpenHarmony.app.test","developer-id":"OpenHarmony","development-certificate":"-----BEGIN CERTIFICATE-----\nMIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\nMRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\nbTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\nMTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\nT3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\nH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\nhkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\nJwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\nFtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\ncRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\nLMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\nzAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\n-----END CERTIFICATE-----\n"},"debug-info":{"device-id-type":"udid","device-ids":["69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42","7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865"]},"issuer":"pki_internal","permissions":{"restricted-permissions":[""]},"type":"debug","uuid":"fe686e1b-3770-4824-a938-961b140a7c98","validity":{"not-after":1705127532,"not-before":1610519532},"version-code":1,"version-name":"1.0.0"} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/app-release1.pem b/hapsigntool_cpp/test/unittest/resource/signProfile/app-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..64322d39adb55e6486fd19c9773daef2dd92cd0c --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/app-release1.pem @@ -0,0 +1,37 @@ +-----BEGIN CERTIFICATE----- +MIICLDCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBuMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN +MjQwNjA2MDc1MzI0WhcNMjUwNjA2MDc1MzI0WjBaMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEkJ4RF7ebnhY5Cc2FzVyDnFFXl3SxAMho5HQroZOM8QInRs1ubLydHG3NNDez +8SADEI3DxwXqsCPi5YbyRWUrf6N1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCCp/sVxEKanJIj73eDH6T3D +7TdUnSd+kcMD6U0QEQhauDAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA0gAMEUCIQDqbwU7TqVEY2TWgXfZ1spYNtYxzraUEN+W/7spc2G1zAIg +YknxDuAbsw4hrZTfrbTuWO/6nI1HdBYVBhEM05IxLZI= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIBxTCCAWugAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMG4xCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSkwJwYDVQQDDCBBcHBsaWNhdGlvbiBT +aWduYXR1cmUgU2VydmljZSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABOUp +vD1yP1PHhPqBXXC+pnRWZopd2bifQcvWuG+KnHvbcG7kQlcdjNU4/IPgXKZQ74Wf +YUZgQ7IWZvDIDxp93Z6jEzARMA8GA1UdEwQIMAYBAf8CAQAwCgYIKoZIzj0EAwMD +SAAwRQIgUhVySRrw7Ig717JSe4XcZXw9PAtiVhBQSsZZZF2YmPICIQDqzPBMwiF/ +oIsBeSDgCPWKy7+j5P/1gNhf9Ddp8tnsMg== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIBrDCCAVKgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMFkwEwYH +KoZIzj0CAQYIKoZIzj0DAQcDQgAEF4naj8HotEn5337K9ldrVLO7xSL6NDeNwU9c +Fzsj0VDwHcmD4HvVm6FqVBfaGHEsGEDi7ufWXlxvoCV7pFjn+KMTMBEwDwYDVR0T +BAgwBgEB/wIBADAKBggqhkjOPQQDAwNIADBFAiArWW1W/IL20Z/b/yJDO45CjDxY +jlsZf6AWijIry4frqgIhAMmBmdrFnRRgI4BMOZOEBBjrhiG/5gciCpmzvBoW6Fxr +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/ohtest.p12 b/hapsigntool_cpp/test/unittest/resource/signProfile/ohtest.p12 new file mode 100644 index 0000000000000000000000000000000000000000..44a50f48592fd283cdfd00d2222dbea44c1403fd Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/signProfile/ohtest.p12 differ diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-cert.pem b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..ee4dd109f0a556f724db4d3d9f4ed6cedf57d3d1 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-cert.pem @@ -0,0 +1,15 @@ +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-invalid_cert_chain.pem b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-invalid_cert_chain.pem new file mode 100644 index 0000000000000000000000000000000000000000..8f02c93a849f0ca6795abc926e4c6ba2df9edc07 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-invalid_cert_chain.pem @@ -0,0 +1,30 @@ +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-reverse.pem b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-reverse.pem new file mode 100644 index 0000000000000000000000000000000000000000..030f7e553360cf627bd84598d81eb81f48c99c19 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1-reverse.pem @@ -0,0 +1,39 @@ +-----BEGIN CERTIFICATE----- +MIIBrDCCAVKgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMFkwEwYH +KoZIzj0CAQYIKoZIzj0DAQcDQgAEF4naj8HotEn5337K9ldrVLO7xSL6NDeNwU9c +Fzsj0VDwHcmD4HvVm6FqVBfaGHEsGEDi7ufWXlxvoCV7pFjn+KMTMBEwDwYDVR0T +BAgwBgEB/wIBADAKBggqhkjOPQQDAwNIADBFAiArWW1W/IL20Z/b/yJDO45CjDxY +jlsZf6AWijIry4frqgIhAMmBmdrFnRRgI4BMOZOEBBjrhiG/5gciCpmzvBoW6Fxr +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB3jCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAELvqlDXjWHD86 +XCO0aCnPNfIdLl+4ZuMLYToVZQaspe8JWREqw+XnQsO3b7Mzpxidq5oqCa52p73p +Y8+VjBIqVoz70A1JhElNv2FXYU7Kl6KVLCmD8IDADcPxcbOh6x8roxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA0gAMEUCIBwN2f5691S3Xthkv5D1OI5I +vcBpEuDgRe6ReW4ANTRqAiEAmiU1r7eCagnSDGqUfhokh8pXzq8p/DZKg+x1IaP+ +ao4= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1.pem b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1.pem new file mode 100644 index 0000000000000000000000000000000000000000..2d2bfa342457be8953c460014443ad3753e6e122 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/profile-release1.pem @@ -0,0 +1,39 @@ +-----BEGIN CERTIFICATE----- +MIICTTCCAdKgAwIBAgIBATAKBggqhkjOPQQDAjBqMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTElMCMGA1UEAwwcUHJvZmlsZSBTaWduYXR1cmUgU2VydmljZSBDQTAeFw0yNDA2 +MDYwNzUzMjRaFw0yNTA2MDYwNzUzMjRaMF4xCzAJBgNVBAYTAkNOMRQwEgYDVQQK +DAtPcGVuSGFybW9ueTEeMBwGA1UECwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRkw +FwYDVQQDDBBQcm9maWxlMSBSZWxlYXNlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD +QgAEV96CExq3UwV9lv5LzxDjrfQXQA8TZwoONG7ly9pAYvD22EW1AvcwXidVB0DV ++MW5vHrFlp+csekq4R55Zw08/qN1MHMwDAYDVR0TAQH/BAIwADALBgNVHQ8EBAMC +B4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwJwYDVR0OBCDGtt+3RbQVBILUf6pVXkjb +Zhf5AXOnTzeKys9jzRKkpjAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEBMAoGCCqG +SM49BAMCA2kAMGYCMQCUpfmuQGKpVo+QU/axmZYS0uB8jWVJhQRQDckZvwIpaK7J +ixobed9xtyU4GcWmsJ0CMQCjMUHtMZQW/Pw/RZieC6ushuqfOdFp/Ko4IJ/7y9HL +Yhey6jPgMv3RqkitrggR6zc= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIB3jCCAYSgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMGoxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MSUwIwYDVQQDDBxQcm9maWxlIFNpZ25h +dHVyZSBTZXJ2aWNlIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAELvqlDXjWHD86 +XCO0aCnPNfIdLl+4ZuMLYToVZQaspe8JWREqw+XnQsO3b7Mzpxidq5oqCa52p73p +Y8+VjBIqVoz70A1JhElNv2FXYU7Kl6KVLCmD8IDADcPxcbOh6x8roxMwETAPBgNV +HRMECDAGAQH/AgEAMAoGCCqGSM49BAMDA0gAMEUCIBwN2f5691S3Xthkv5D1OI5I +vcBpEuDgRe6ReW4ANTRqAiEAmiU1r7eCagnSDGqUfhokh8pXzq8p/DZKg+x1IaP+ +ao4= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIBrDCCAVKgAwIBAgIBATAKBggqhkjOPQQDAzBVMQswCQYDVQQGEwJDTjEUMBIG +A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0 +eTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yNDA2MDYwNzUzMjRaFw0yNTA2MDYwNzUz +MjRaMFUxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtPcGVuSGFybW9ueTEeMBwGA1UE +CwwVT3Blbkhhcm1vbnkgQ29tbXVuaXR5MRAwDgYDVQQDDAdSb290IENBMFkwEwYH +KoZIzj0CAQYIKoZIzj0DAQcDQgAEF4naj8HotEn5337K9ldrVLO7xSL6NDeNwU9c +Fzsj0VDwHcmD4HvVm6FqVBfaGHEsGEDi7ufWXlxvoCV7pFjn+KMTMBEwDwYDVR0T +BAgwBgEB/wIBADAKBggqhkjOPQQDAwNIADBFAiArWW1W/IL20Z/b/yJDO45CjDxY +jlsZf6AWijIry4frqgIhAMmBmdrFnRRgI4BMOZOEBBjrhiG/5gciCpmzvBoW6Fxr +-----END CERTIFICATE----- diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/profile.json b/hapsigntool_cpp/test/unittest/resource/signProfile/profile.json new file mode 100644 index 0000000000000000000000000000000000000000..d4f3bbf71e34cd8f7ed1bcdb7837c3083ccc948f --- /dev/null +++ b/hapsigntool_cpp/test/unittest/resource/signProfile/profile.json @@ -0,0 +1,29 @@ +{ + "version-name": "1.0.0", + "version-code": 1, + "uuid": "fe686e1b-3770-4824-a938-961b140a7c98", + "validity": { + "not-before": 1610519532, + "not-after": 1705127532 + }, + "type": "debug", + "bundle-info": { + "developer-id": "OpenHarmony", + "development-certificate": "-----BEGIN CERTIFICATE-----\nMIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\nMRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\nbTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\nMTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\nT3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\nH09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\nhkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\nJwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\nFtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\ncRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\nLMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\nzAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\n-----END CERTIFICATE-----\n", + "bundle-name": "com.OpenHarmony.app.test", + "app-feature": "hos_system_app" + }, + "permissions": { + "restricted-permissions": [ + "" + ] + }, + "debug-info": { + "device-ids": [ + "69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42", + "7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865" + ], + "device-id-type": "udid" + }, + "issuer": "pki_internal" +} diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/signed-profile.p7b b/hapsigntool_cpp/test/unittest/resource/signProfile/signed-profile.p7b new file mode 100644 index 0000000000000000000000000000000000000000..95297c4151068245e54592df7933f863b97c10b5 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/signProfile/signed-profile.p7b differ diff --git a/hapsigntool_cpp/test/unittest/resource/signProfile/unsigned.txt b/hapsigntool_cpp/test/unittest/resource/signProfile/unsigned.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f2aefe5aab434337439e188d136a2f272378327 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/resource/signProfile/unsigned.txt differ diff --git a/hapsigntool_cpp/test/unittest/signProfile/pkcs7_data_test.cpp b/hapsigntool_cpp/test/unittest/signProfile/pkcs7_data_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f2439d0f4a10d82103e57e7ff7b708a0844790d --- /dev/null +++ b/hapsigntool_cpp/test/unittest/signProfile/pkcs7_data_test.cpp @@ -0,0 +1,966 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +#include "gtest/gtest.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "nlohmann/json.hpp" +#include "signer_factory.h" +#include "profile_sign_tool.h" +#include "params_run_tool.h" +#include "pkcs7_data.h" +#include "signer_config.h" +#include "local_signer.h" +#include "bc_pkcs7_generator.h" +#include "bc_signeddata_generator.h" +#include "profile_verify.h" +#include "verify_hap_openssl_utils.h" + +using nlohmann::json; + +namespace OHOS { +namespace SignatureTools { +// sign profile使用的全局参数 +static const std::string SIGN_PROFILE_MODE = "localSign"; +static const std::string SIGN_PROFILE_KEY_ALIAS = "oh-profile1-key-v1"; +static const std::string SIGN_PROFILE_PROFILE_CERT_FILE = "./signProfile/profile-release1.pem"; +static const std::string SIGN_PROFILE_SIGN_ALG = "SHA384withECDSA"; +static const std::string SIGN_PROFILE_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_PROFILE_OUT_FILE = "./signProfile/signed-profile.p7b"; +static const std::string SIGN_PROFILE_IN_FILE = "./signProfile/profile.json"; + +static const std::string SIGN_PROFILE_CERT_PEM = "./signProfile/profile-release1-cert.pem"; +static const std::string SIGN_PROFILE_REVERSE_PEM = "./signProfile/profile-release1-reverse.pem"; +static const std::string SIGN_PROFILE_DOUBLE_CERT_PEM = "./signProfile/profile-release1-invalid_cert_chain.pem"; + +// verify profile 使用的全局参数 +static const std::string VERIFY_PROFILE_IN_FILE = "./signProfile/signed-profile.p7b"; +static const std::string VERIFY_PROFILE_OUT_FILE = "./signProfile/VerifyResult.json"; + +class Pkcs7DataTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp()override; + void TearDown()override; +}; +void Pkcs7DataTest::SetUpTestCase(void) +{ +} + +void Pkcs7DataTest::TearDownTestCase(void) +{ +} + +void Pkcs7DataTest::SetUp() +{ +} + +void Pkcs7DataTest::TearDown() +{ +} + +/** + * @tc.name: pkcs7_test001 + * @tc.desc: Test function of VerifyCertOpensslUtils::CertVerify() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test001, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + X509* issuerCert = X509_new(); + bool result = VerifyCertOpensslUtils::CertVerify(NULL, issuerCert); + X509_free(cert); + X509_free(issuerCert); + EXPECT_FALSE(result); +} + +/** + * @tc.name: pkcs7_test002 + * @tc.desc: Test function of VerifyCertOpensslUtils::CertVerify() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test002, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + X509* issuerCert = X509_new(); + bool result = VerifyCertOpensslUtils::CertVerify(cert, NULL); + X509_free(cert); + X509_free(issuerCert); + EXPECT_FALSE(result); +} + +/** + * @tc.name: pkcs7_test003 + * @tc.desc: Test function of VerifyCertOpensslUtils::CertVerify interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test003, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + X509* issuerCert = X509_new(); + bool result = VerifyCertOpensslUtils::CertVerify(cert, issuerCert); + X509_free(cert); + X509_free(issuerCert); + EXPECT_FALSE(result); +} + +/** + * @tc.name: pkcs7_test004 + * @tc.desc: Test function of VerifyCertOpensslUtils::CertVerify() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test004, testing::ext::TestSize.Level1) +{ + X509* cert = X509_new(); + X509* issuerCert = X509_new(); + bool result = VerifyCertOpensslUtils::CertVerify(cert, issuerCert); + X509_free(cert); + X509_free(issuerCert); + EXPECT_FALSE(result); +} + +static void ReverseX509Stack(STACK_OF(X509)* certs) +{ + if (certs == NULL) + return; + std::vector certChain; + for (int i = 0; i < sk_X509_num(certs); i++) { + certChain.push_back(sk_X509_value(certs, i)); + } + std::reverse(certChain.begin(), certChain.end()); + while (sk_X509_num(certs))sk_X509_pop(certs); + for (int i = 0; i < static_cast(certChain.size()); i++) + sk_X509_push(certs, certChain[i]); +} + +\ +/** + * @tc.name: pkcs7_test005 + * @tc.desc: Test function of VerifyCertOpensslUtils::CertVerify() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test005, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + ReverseX509Stack(certs); + bool result = VerifyCertOpensslUtils::CertVerify(sk_X509_value(certs, 0), sk_X509_value(certs, 1)); + PKCS7Data::PrintCertChainSub(certs); + EXPECT_FALSE(result); +} + + +/** + * @tc.name: pkcs7_test007 + * @tc.desc: Test function of PKCS7Data::GetASN1Time() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test007, testing::ext::TestSize.Level1) +{ + ASN1_TIME* time = ASN1_TIME_new(); + ASN1_TIME_set(time, -1); + std::string result = PKCS7Data::GetASN1Time(time); + ASN1_TIME_free(time); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.name: pkcs7_test008 + * @tc.desc: Test function of VerifyCertOpensslUtils::GetTextFromX509Name() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test008, testing::ext::TestSize.Level1) +{ + std::string text; + VerifyCertOpensslUtils::GetTextFromX509Name(NULL, 45, text); + EXPECT_TRUE(text.empty()); +} + +/** + * @tc.name: pkcs7_test009 + * @tc.desc: Test function of VerifyCertOpensslUtils::GetDnToString() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test009, testing::ext::TestSize.Level1) +{ + std::string result = VerifyCertOpensslUtils::GetDnToString(NULL); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.name: pkcs7_test010 + * @tc.desc: Test function of VerifyCertOpensslUtils::GetSubjectFromX509() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test010, testing::ext::TestSize.Level1) +{ + std::string subject; + bool result = VerifyCertOpensslUtils::GetSubjectFromX509(NULL, subject); + EXPECT_FALSE(result); +} + +/** + * @tc.name: pkcs7_test011 + * @tc.desc: Test function of PKCS7Data::X509NameCompare() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test011, testing::ext::TestSize.Level1) +{ + int result = PKCS7Data::X509NameCompare(NULL, NULL); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test012 + * @tc.desc: Test function of PKCS7Data::X509NameCompare() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test012, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + int result = PKCS7Data::X509NameCompare(sk_X509_value(certs, 0), NULL); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test013 + * @tc.desc: Test function of PKCS7Data::X509NameCompare() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test013, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + int result = PKCS7Data::X509NameCompare(sk_X509_value(certs, 0), sk_X509_value(certs, 1)); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: pkcs7_test014 + * @tc.desc: Test function of Pkcs7Data::Parse() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test014, testing::ext::TestSize.Level1) +{ + PKCS7Data p7Data; + unsigned char buf[15] = "hello"; + const unsigned char* p = buf; + int len = 5; + std::string p7b(p, p + len); + int result = p7Data.Parse(p7b); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test015 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test015, testing::ext::TestSize.Level1) +{ + ASN1_TYPE* signTime = NULL; + ASN1_TIME* notBefore = NULL; + ASN1_TIME* notAfter = NULL; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, notBefore, notAfter); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test016 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test016, testing::ext::TestSize.Level1) +{ + ASN1_TYPE* signTime = NULL; + ASN1_TIME notBefore{ 0 }; + notBefore.data = NULL; + ASN1_TIME* notAfter = NULL; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, ¬Before, notAfter); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test017 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test017, testing::ext::TestSize.Level1) +{ + unsigned char data[5] = "hell"; + ASN1_TYPE* signTime = NULL; + ASN1_TIME notBefore{ 0 }; + notBefore.data = data; + ASN1_TIME* notAfter = NULL; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, ¬Before, notAfter); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test018 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test018, testing::ext::TestSize.Level1) +{ + unsigned char data[5] = "hell"; + ASN1_TYPE* signTime = NULL; + ASN1_TIME notBefore{ 0 }; + notBefore.data = data; + ASN1_TIME notAfter; + notAfter.data = NULL; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, ¬Before, ¬After); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test019 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test019, testing::ext::TestSize.Level1) +{ + unsigned char data[5] = "hell"; + ASN1_TYPE* signTime = NULL; + ASN1_TIME notBefore{ 0 }; + notBefore.data = data; + ASN1_TIME notAfter; + notAfter.data = data; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, ¬Before, ¬After); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test020 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test020, testing::ext::TestSize.Level1) +{ + unsigned char data[5] = "hell"; + ASN1_TYPE signTime; + signTime.value.asn1_string = NULL; + ASN1_TIME notBefore{ 0 }; + notBefore.data = data; + ASN1_TIME notAfter; + notAfter.data = data; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(&signTime, ¬Before, ¬After); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test021 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test021, testing::ext::TestSize.Level1) +{ + ASN1_STRING* tmp = ASN1_STRING_new(); + unsigned char data[5] = "hell"; + ASN1_TYPE signTime; + signTime.value.asn1_string = tmp; + signTime.value.asn1_string->data = NULL; + ASN1_TIME notBefore{ 0 }; + notBefore.data = data; + ASN1_TIME notAfter; + notAfter.data = data; + PKCS7Data p7Data; + int result = PKCS7Data::CheckSignTimeInValidPeriod(&signTime, ¬Before, ¬After); + ASN1_STRING_free(tmp); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test022 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test022, testing::ext::TestSize.Level1) +{ + ASN1_TIME* tmp = NULL; + ASN1_TYPE* signTime = NULL; + ASN1_TIME* notBefore = NULL; + ASN1_TIME* notAfter = NULL; + time_t t1 = 365 * 24 * 3600; + + signTime = ASN1_TYPE_new(); + tmp = ASN1_TIME_new(); + notBefore = ASN1_TIME_new(); + notAfter = ASN1_TIME_new(); + time_t timeNow = time(NULL); + ASN1_TIME_set(tmp, timeNow - t1); + ASN1_TYPE_set(signTime, V_ASN1_UTCTIME, tmp); + ASN1_TIME_set(notBefore, timeNow); + ASN1_TIME_set(notAfter, timeNow + t1); + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, notBefore, notAfter); + ASN1_TYPE_free(signTime); + ASN1_TIME_free(notBefore); + ASN1_TIME_free(notAfter); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test023 + * @tc.desc: Test function of PKCS7Data::CheckSignTimeInValidPeriod() interface for failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test023, testing::ext::TestSize.Level1) +{ + ASN1_TIME* tmp = NULL; + ASN1_TYPE* signTime = NULL; + ASN1_TIME* notBefore = NULL; + ASN1_TIME* notAfter = NULL; + time_t t1 = 365 * 24 * 3600; + + signTime = ASN1_TYPE_new(); + tmp = ASN1_TIME_new(); + notBefore = ASN1_TIME_new(); + notAfter = ASN1_TIME_new(); + time_t timeNow = time(NULL); + ASN1_TIME_set(tmp, timeNow + t1); + ASN1_TYPE_set(signTime, V_ASN1_UTCTIME, tmp); + ASN1_TIME_set(notBefore, timeNow - t1); + ASN1_TIME_set(notAfter, timeNow); + int result = PKCS7Data::CheckSignTimeInValidPeriod(signTime, notBefore, notAfter); + ASN1_TYPE_free(signTime); + ASN1_TIME_free(notBefore); + ASN1_TIME_free(notAfter); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: pkcs7_test024 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test024, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test025 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test025, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test026 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test026, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test027 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test027, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test028 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test028, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = "LocalSign"; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test029 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test029, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test030 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test030, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test031 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test031, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test032 + * @tc.desc: Test function of SignToolServiceImpl::GetProvisionContent() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test032, testing::ext::TestSize.Level1) +{ + std::string ret; + const std::string input = "invalid.txt"; + SignToolServiceImpl::GetProvisionContent(input, ret); + EXPECT_TRUE(ret.empty()); +} + +/** + * @tc.name: pkcs7_test033 + * @tc.desc: Test function of VerifyHapOpensslUtils::ParsePkcs7Package() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test033, testing::ext::TestSize.Level1) +{ + unsigned char packageData[] = "hello,world"; + uint32_t packageLen = 0; + Pkcs7Context ctx; + bool result = VerifyHapOpensslUtils::ParsePkcs7Package(packageData, packageLen, ctx); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test034 + * @tc.desc: Test function of SignToolServiceImpl::SignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test034, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = std::string("test.bin"); + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = api.SignProfile(&options); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: pkcs7_test035 + * @tc.desc: Test function of SignToolServiceImpl::SignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test035, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = api.SignProfile(&options); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: pkcs7_test036 + * @tc.desc: Test function of SignToolServiceImpl::SignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(Pkcs7DataTest, pkcs7_test036, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_DOUBLE_CERT_PEM; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = api.SignProfile(&options); + EXPECT_EQ(result, false); +} + +/** +* @tc.name: pkcs7_test037 +* @tc.desc: Test function of SignToolServiceImpl::VerifyProfile() interface for SUCCESS json写入OUT_FILE. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(Pkcs7DataTest, pkcs7_test037, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::IN_FILE] = SIGN_PROFILE_CERT_PEM; + options[Options::OUT_FILE] = VERIFY_PROFILE_OUT_FILE; + bool result = false; + SignToolServiceImpl api; + result = api.VerifyProfile(&options); + EXPECT_EQ(result, false); +} + +/** +* @tc.name: pkcs7_test038 +* @tc.desc: Test function of SignToolServiceImpl::VerifyProfile() interface for SUCCESS json写入OUT_FILE. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(Pkcs7DataTest, pkcs7_test038, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::IN_FILE] = VERIFY_PROFILE_IN_FILE; + bool result = false; + SignToolServiceImpl api; + result = api.VerifyProfile(&options); + EXPECT_EQ(result, true); +} + +/** +* @tc.name: pkcs7_test039 +* @tc.desc: Test function of SignToolServiceImpl::VerifyProfile() interface for SUCCESS json写入OUT_FILE. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(Pkcs7DataTest, pkcs7_test039, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::IN_FILE] = std::string("text.bin"); + bool result = false; + SignToolServiceImpl api; + result = api.VerifyProfile(&options); + EXPECT_EQ(result, false); +} + +} +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/signProfile/profile_test.cpp b/hapsigntool_cpp/test/unittest/signProfile/profile_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cde147b8c766cc5a3251c8b4582b062e7318501b --- /dev/null +++ b/hapsigntool_cpp/test/unittest/signProfile/profile_test.cpp @@ -0,0 +1,1053 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "nlohmann/json.hpp" +#include "signer_factory.h" +#include "profile_sign_tool.h" +#include "params_run_tool.h" +#include "pkcs7_data.h" +#include "signer_config.h" +#include "local_signer.h" +#include "bc_pkcs7_generator.h" +#include "bc_signeddata_generator.h" +#include "profile_verify.h" +#include "constant.h" +#include "profile_verify_utils.h" +#include "cms_utils.h" + +using nlohmann::json; + +namespace OHOS { +namespace SignatureTools { + +// sign profile使用的全局参数 +static const std::string SIGN_PROFILE_MODE = "localSign"; +static const std::string SIGN_PROFILE_KEY_ALIAS = "oh-profile1-key-v1"; +static const std::string SIGN_PROFILE_PROFILE_CERT_FILE = "./signProfile/profile-release1.pem"; +static const std::string SIGN_PROFILE_SIGN_ALG = "SHA384withECDSA"; +static const std::string SIGN_PROFILE_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_PROFILE_OUT_FILE = "./signProfile/signed-profile.p7b"; +static const std::string SIGN_PROFILE_IN_FILE = "./signProfile/profile.json"; + +static const std::string SIGN_PROFILE_CERT_PEM = "./signProfile/profile-release1-cert.pem"; +static const std::string SIGN_PROFILE_REVERSE_PEM = "./signProfile/profile-release1-reverse.pem"; +static const std::string SIGN_PROFILE_DOUBLE_CERT_PEM = "./signProfile/profile-release1-invalid_cert_chain.pem"; +static const std::string SIGN_PROFILE_TMP_P7B = "./signProfile/tmp.p7b"; + +// verify profile 使用的全局参数 +static const std::string VERIFY_PROFILE_IN_FILE = "./signProfile/app1-profile1.p7b"; +static const std::string VERIFY_PROFILE_OUT_FILE = "./signProfile/VerifyResult.json"; +// sign app 使用全局参数 +static const std::string SIGN_APP_MODE = "localSign"; +static const std::string SIGN_APP_KEY_ALIAS = "oh-app1-key-v1"; +static const std::string SIGN_APP_APP_CERT_FILE = "./signProfile/app-release1.pem"; +static const std::string SIGN_APP_PROFILE_FILE = "./signProfile/app1-profile1.p7b"; +static const std::string SIGN_APP_IN_FILE = "./signProfile/unsigned.hap"; +static const std::string SIGN_APP_IN_FILE_TXT = "./signProfile/unsigned.txt"; +static const std::string SIGN_APP_SIGN_ALG = "SHA256withECDSA"; +static const std::string SIGN_APP_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_APP_OUT_FILE = "./signProfile/signed.hap"; + +class ProfileTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp()override; + void TearDown()override; +}; +void ProfileTest::SetUpTestCase(void) +{ + std::filesystem::copy(SIGN_APP_IN_FILE_TXT, SIGN_APP_IN_FILE); +} + +void ProfileTest::TearDownTestCase(void) +{ + std::filesystem::remove(SIGN_APP_IN_FILE); +} + +void ProfileTest::SetUp() +{ +} + +void ProfileTest::TearDown() +{ +} + +/** + * @tc.name: profile_test001 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test001, testing::ext::TestSize.Level1) +{ + Pkcs7Context profilePkcs7Context; + Pkcs7Context hapPkcs7Context; + int length = 5; + std::string profile = "hello,world"; + ByteBuffer pkcs7ProfileBlock; + pkcs7ProfileBlock.SetCapacity(length); + pkcs7ProfileBlock.PutData("hello", length); + int result = ProfileVerifyUtils::ParseProfile(profilePkcs7Context, hapPkcs7Context, pkcs7ProfileBlock, profile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: profile_test002 + * @tc.desc: Test function of ProfileVerifyUtils::VerifyProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test002, testing::ext::TestSize.Level1) +{ + Pkcs7Context p7context; + int result = ProfileVerifyUtils::VerifyProfile(p7context); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: profile_test003 + * @tc.desc: Test function of ProfileVerifyUtils::VerifyProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test003, testing::ext::TestSize.Level1) +{ + Pkcs7Context p7context; + X509* cert = X509_new(); + std::vector certs; + certs.push_back(cert); + p7context.certChain.push_back(certs); + int result = ProfileVerifyUtils::VerifyProfile(p7context); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: profile_test004 + * @tc.desc: Test function of Pkcs7Generator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test004, testing::ext::TestSize.Level1) +{ + std::string content; + SignerConfig* config = NULL; + std::string ret; + std::shared_ptr generator = std::make_shared(); + int result = generator->GenerateSignedData(content, config, ret); + EXPECT_TRUE(result <= 0); +} + +/** + * @tc.name: profile_test005 + * @tc.desc: Test function of Pkcs7Generator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test005, testing::ext::TestSize.Level1) +{ + std::string content = "hello,world"; + SignerConfig* config = NULL; + std::string ret; + std::shared_ptr generator = std::make_shared(); + int result = generator->GenerateSignedData(content, config, ret); + EXPECT_TRUE(result <= 0); +} + +/** + * @tc.name: profile_test006 + * @tc.desc: Test function of Pkcs7Generator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test006, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_APP_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_APP_APP_CERT_FILE; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = ""; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::ECDSA_WITH_SHA256; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr pkcs7Generator = std::make_shared(); + int result = pkcs7Generator->GenerateSignedData(content, &config, signedData); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test007 + * @tc.desc: Test function of Pkcs7Generator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test007, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_APP_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_APP_APP_CERT_FILE; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::DSA_WITH_SHA512; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr pkcs7Generator = std::make_shared(); + int result = pkcs7Generator->GenerateSignedData(content, &config, signedData); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test008 + * @tc.desc: Test function of Pkcs7Generator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test008, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_PROFILE_DOUBLE_CERT_PEM; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::ECDSA_WITH_SHA256; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr pkcs7Generator = std::make_shared(); + int result = pkcs7Generator->GenerateSignedData(content, &config, signedData); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test009 + * @tc.desc: Test function of SignedDataGenerator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test009, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_APP_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_APP_APP_CERT_FILE; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_APP_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::ECDSA_WITH_SHA512; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr signedDataGenerator = + std::make_shared(); + signedDataGenerator->SetOwnerId(OWNERID_OID); + int result = signedDataGenerator->GenerateSignedData(content, &config, signedData); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test010 + * @tc.desc: Test function of SignedDataGenerator::GenerateSignedData() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test010, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_PROFILE_DOUBLE_CERT_PEM; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::ECDSA_WITH_SHA256; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr signedDataGenerator = + std::make_shared(); + signedDataGenerator->SetOwnerId("ownerID str"); + int result = signedDataGenerator->GenerateSignedData(content, &config, signedData); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test011 + * @tc.desc: Test function of Pkcs7Data::Verify() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test011, testing::ext::TestSize.Level1) +{ + std::string content = "signed content data"; + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + PKCS7Data p7; + std::string p7b; + PKCS7* pkcs7 = NULL; + int result = p7.Sign(content, signer, "SHA384withECDSA", p7b); + EXPECT_EQ(result, 0); + const unsigned char* p = reinterpret_cast(p7b.data()); + pkcs7 = d2i_PKCS7(NULL, &p, static_cast(p7b.size())); + STACK_OF(X509)* certs = pkcs7->d.sign->cert; + int num = 1; + while (sk_X509_num(certs) > num) { + X509* cert = sk_X509_delete(certs, sk_X509_num(certs) - 1); + X509_free(cert); + } + sk_X509_push(certs, sk_X509_value(certs, 0)); + X509_up_ref(sk_X509_value(certs, 0)); + unsigned char* out = NULL; + int len = 0; + len = i2d_PKCS7(pkcs7, &out); + p7b.assign(out, out + len); + result = p7.Parse(p7b); + EXPECT_EQ(result, 0); + result = p7.Verify(); + PKCS7_free(pkcs7); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test013 + * @tc.desc: Test function of Pkcs7Data::Verify() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test013, testing::ext::TestSize.Level1) +{ + std::string content = "signed content data"; + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + PKCS7Data p7; + std::string p7b; + PKCS7* pkcs7 = NULL; + int result = p7.Sign(content, signer, "SHA384withECDSA", p7b); + EXPECT_EQ(result, 0); + const unsigned char* p = reinterpret_cast(p7b.data()); + pkcs7 = d2i_PKCS7(NULL, &p, static_cast(p7b.size())); + STACK_OF(X509)* certs = pkcs7->d.sign->cert; + sk_X509_delete(certs, 2); + unsigned char* out = NULL; + int len = 0; + len = i2d_PKCS7(pkcs7, &out); + p7b.assign(out, out + len); + result = p7.Parse(p7b); + EXPECT_EQ(result, 0); + result = p7.Verify(); + PKCS7_free(pkcs7); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test014 + * @tc.desc: Test function of Pkcs7Data::Verify() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test014, testing::ext::TestSize.Level1) +{ + std::string content = "signed content data"; + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + PKCS7Data p7; + std::string p7b; + PKCS7* pkcs7 = NULL; + int result = p7.Sign(content, signer, "SHA384withECDSA", p7b); + EXPECT_EQ(result, 0); + const unsigned char* p = reinterpret_cast(p7b.data()); + pkcs7 = d2i_PKCS7(NULL, &p, static_cast(p7b.size())); + STACK_OF(X509)* certs = pkcs7->d.sign->cert; + sk_X509_delete(certs, 2); + sk_X509_push(certs, sk_X509_value(certs, 1)); + X509_up_ref(sk_X509_value(certs, 1)); + PKCS7Data::PrintCertChainSub(certs); + unsigned char* out = NULL; + int len = 0; + len = i2d_PKCS7(pkcs7, &out); + p7b.assign(out, out + len); + result = p7.Parse(p7b); + PKCS7Data::PrintCertChainSub(certs); + EXPECT_EQ(result, 0); + result = p7.Verify(); + PKCS7_free(pkcs7); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test015 + * @tc.desc: Test function of Provision operator ==() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test015, testing::ext::TestSize.Level1) +{ + ProfileInfo* info = NULL; + ProfileInfo info2; + info = &info2; + info2 = *info; +} + +/** + * @tc.name: profile_test016 + * @tc.desc: Test function of CmsUtils::VerifySignDataWithUnsignedDataDigest() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test016, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, content, ret); + EXPECT_EQ(result, 0); + std::vector signedData(ret.begin(), ret.end()); + std::string data = "hello,world"; + std::vector unsignedData(data.begin(), data.end()); + EXPECT_EQ(CmsUtils::VerifySignDataWithUnsignedDataDigest(unsignedData, signedData), false); +} + +/** + * @tc.name: profile_test017 + * @tc.desc: Test function of PKCS7Data::SortX509Stack() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, test017, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = sk_X509_new(NULL); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) < 0); + sk_X509_free(certs); +} + +/** + * @tc.name: profile_test019 + * @tc.desc: Test function of PKCS7Data::PrintCertChainSub() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test019, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = NULL; + PKCS7Data::PrintCertChainSub(certs); +} + +/** + * @tc.name: profile_test020 + * @tc.desc: Test function of PKCS7Data::GetASN1Time() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test020, testing::ext::TestSize.Level1) +{ + ASN1_TIME* time = NULL; + std::string result = PKCS7Data::GetASN1Time(time); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.name: profile_test021 + * @tc.desc: Test function of PKCS7Data::SortX509Stack() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test021, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = NULL; + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) < 0); +} + +/** + * @tc.name: profile_test022 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test022, testing::ext::TestSize.Level1) +{ + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-n" + "ame\":\"com.OpenHarmony.app.test\",\"developer-id\":\"OpenHarmony\",\"development-certi" + "ficate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA594" + "8C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856" + "AB10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"rest" + "ricted-permissions\":[\"\"]},\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961" + "b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":\"1610519532\"},\"ve" + "rsion-code\":1,\"version-name\":\"1.0.0\"}"; + ProfileInfo info; + AppProvisionVerifyResult result = ParseProfile(provision, info); + EXPECT_EQ(result, AppProvisionVerifyResult::PROVISION_OK); +} + +/** + * @tc.name: profile_test023 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test023, testing::ext::TestSize.Level1) +{ + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-nam" + "e\":\"com.OpenHarmony.app.test\",\"developer-id\":\"OpenHarmony\",\"development-certi" + "ficate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C" + "3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB1" + "0493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restric" + "ted-permissions\":[\"\"]},\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b14" + "0a7c98\",\"validity\":{\"name\":\"weixing\"},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + ProfileInfo info; + AppProvisionVerifyResult result = ParseProfile(provision, info); + EXPECT_EQ(result, AppProvisionVerifyResult::PROVISION_OK); +} + +/** + * @tc.name: profile_test024 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test024, testing::ext::TestSize.Level1) +{ + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-" + "feature\":\"hos_system_app\",\"bundle-name\":\"com.OpenHarmony.app.test\",\"developer-id\":\"O" + "penHarmony\",\"distribution-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB" + "44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C76" + "79A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":" + "[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":" + "{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + ProfileInfo info; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_EQ(result, AppProvisionVerifyResult::PROVISION_OK); +} + +/** + * @tc.name: profile_test027 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test027, testing::ext::TestSize.Level1) +{ + std::string provision = "{\"app-distribution-type\": \"app_gallery\"," + "\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":" + "\"com.OpenHarmony.app.test\",\"developer-id\":\"OpenHarmony\"," + "\"distribution-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[" + "\"69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\"," + "\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]}," + "\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions" + "\":[\"\"]},\"type\":\"release\",\"uuid\":\"\",\"validity\":{\"not-after" + "\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + ProfileInfo info; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_EQ(result, AppProvisionVerifyResult::PROVISION_INVALID); +} + +/** + * @tc.name: profile_test028 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test028, testing::ext::TestSize.Level1) +{ + std::string provision = "{\"app-distribution-type\": \"app_gallery\"," + "\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":" + "\"com.OpenHarmony.app.test\",\"developer-id\":\"OpenHarmony\"," + "\"distribution-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[" + "\"69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\"," + "\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]}," + "\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions" + "\":[\"\"]},\"type\":\"release\",\"uuid\":\"\",\"validity\":{\"not-after" + "\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + ProfileInfo info; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_EQ(result, AppProvisionVerifyResult::PROVISION_INVALID); +} + +/** + * @tc.name: profile_test029 + * @tc.desc: Test function of RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test029, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-" + "feature\":\"hos_system_app\",\"bundle-name\":\"com.OpenHarmony.app.test\",\"developer-id\":\"O" + "penHarmony\",\"distribution-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" + "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" + "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" + "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" + "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" + "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" + "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" + "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" + "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" + "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" + "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" + "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB" + "44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C76" + "79A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":" + "[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":" + "{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + FileUtils::Write(provision, VERIFY_PROFILE_OUT_FILE); + (*params)["mode"] = SIGN_APP_MODE; + (*params)["keyAlias"] = SIGN_APP_KEY_ALIAS; + (*params)["signAlg"] = SIGN_APP_SIGN_ALG; + (*params)["appCertFile"] = SIGN_APP_APP_CERT_FILE; + (*params)["profileFile"] = VERIFY_PROFILE_OUT_FILE; + (*params)["inFile"] = SIGN_APP_IN_FILE; + (*params)["keystoreFile"] = SIGN_APP_KEY_STORE_FILE; + (*params)["outFile"] = SIGN_APP_OUT_FILE; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["inForm"] = std::string("zip"); + (*params)["profileSigned"] = std::string("0"); + (*params)["signCode"] = std::string("0"); + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, true); +} + +static void GenerateTmpP7b() +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_DOUBLE_CERT_PEM; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string provision = "45"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, provision, ret); + FileUtils::Write(ret, SIGN_PROFILE_TMP_P7B); + EXPECT_TRUE(result < 0); +} + +/** + * @tc.name: profile_test030 + * @tc.desc: Test function of RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test030, testing::ext::TestSize.Level1) +{ + GenerateTmpP7b(); + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + (*params)["mode"] = SIGN_APP_MODE; + (*params)["keyAlias"] = SIGN_APP_KEY_ALIAS; + (*params)["signAlg"] = SIGN_APP_SIGN_ALG; + (*params)["appCertFile"] = SIGN_APP_APP_CERT_FILE; + (*params)["profileFile"] = SIGN_PROFILE_TMP_P7B; + (*params)["inFile"] = SIGN_APP_IN_FILE; + (*params)["keystoreFile"] = SIGN_APP_KEY_STORE_FILE; + (*params)["outFile"] = SIGN_APP_OUT_FILE; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["inForm"] = std::string("zip"); + (*params)["profileSigned"] = std::string("1"); + (*params)["signCode"] = std::string("0"); + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_FALSE(ret); +} + +static STACK_OF(X509)* ReadCerts(const std::string& path) +{ + X509* cert = NULL; + BIO* in = NULL; + STACK_OF(X509)* certs = NULL; + certs = sk_X509_new(NULL); + if (certs == NULL) + goto err; + in = BIO_new_file(path.c_str(), "rb"); + if (in == NULL) + goto err; + while ((cert = PEM_read_bio_X509(in, NULL, NULL, NULL))) + { + sk_X509_push(certs, cert); + } + BIO_free(in); + return certs; +err: + BIO_free(in); + sk_X509_pop_free(certs, X509_free); + return NULL; +} + +/** + * @tc.name: profile_test031 + * @tc.desc: Test function of RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test031, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = ReadCerts(SIGN_PROFILE_CERT_PEM); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) < 0); + sk_X509_pop_free(certs, X509_free); +} + +/** + * @tc.name: profile_test032 + * @tc.desc: Test function of RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test032, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = ReadCerts(SIGN_PROFILE_PROFILE_CERT_FILE); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) == 0); + X509* entityCert = sk_X509_value(certs, 0); + X509* entityCopy = X509_dup(entityCert); + X509* root = sk_X509_pop(certs); + X509* middle = sk_X509_pop(certs); + X509_free(root); + X509_free(middle); + sk_X509_insert(certs, entityCopy, 0); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) < 0); + sk_X509_pop_free(certs, X509_free); +} + +/** + * @tc.name: profile_test033 + * @tc.desc: Test function of RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test033, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = ReadCerts(SIGN_PROFILE_PROFILE_CERT_FILE); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) == 0); + X509* root = sk_X509_pop(certs); + X509_free(root); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) < 0); + sk_X509_pop_free(certs, X509_free); +} + +/** + * @tc.name: profile_test030 + * @tc.desc: Test function of RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProfileTest, profile_test034, testing::ext::TestSize.Level1) +{ + STACK_OF(X509)* certs = ReadCerts(SIGN_PROFILE_PROFILE_CERT_FILE); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) == 0); + X509* root = sk_X509_pop(certs); + X509* middle = sk_X509_pop(certs); + X509* entity = sk_X509_pop(certs); + X509_free(entity); + sk_X509_insert(certs, middle, 0); + sk_X509_insert(certs, X509_dup(middle), 0); + sk_X509_insert(certs, root, 0); + EXPECT_TRUE(PKCS7Data::SortX509Stack(certs) < 0); + sk_X509_pop_free(certs, X509_free); +} +} +} diff --git a/hapsigntool_cpp/test/unittest/signProfile/provision_test.cpp b/hapsigntool_cpp/test/unittest/signProfile/provision_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50da6fce0ca17019934dc619f3040d41c82b47a8 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/signProfile/provision_test.cpp @@ -0,0 +1,1615 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "nlohmann/json.hpp" +#include "signer_factory.h" +#include "profile_sign_tool.h" +#include "params_run_tool.h" +#include "pkcs7_data.h" +#include "signer_config.h" +#include "local_signer.h" +#include "bc_pkcs7_generator.h" +#include "bc_signeddata_generator.h" +#include "profile_verify.h" +#include "constant.h" +#include "profile_verify_utils.h" +#include "cms_utils.h" + +using nlohmann::json; + +namespace OHOS { +namespace SignatureTools { + +// sign profile使用的全局参数 +static const std::string SIGN_PROFILE_MODE = "localSign"; +static const std::string SIGN_PROFILE_KEY_ALIAS = "oh-profile1-key-v1"; +static const std::string SIGN_PROFILE_PROFILE_CERT_FILE = "./signProfile/profile-release1.pem"; +static const std::string SIGN_PROFILE_SIGN_ALG = "SHA384withECDSA"; +static const std::string SIGN_PROFILE_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_PROFILE_OUT_FILE = "./signProfile/signed-profile.p7b"; +static const std::string SIGN_PROFILE_IN_FILE = "./signProfile/profile.json"; + +static const std::string SIGN_PROFILE_CERT_PEM = "./signProfile/profile-release1-cert.pem"; +static const std::string SIGN_PROFILE_REVERSE_PEM = "./signProfile/profile-release1-reverse.pem"; +static const std::string SIGN_PROFILE_DOUBLE_CERT_PEM = "./signProfile/profile-release1-invalid_cert_chain.pem"; + +// verify profile 使用的全局参数 +static const std::string VERIFY_PROFILE_IN_FILE = "./signProfile/app1-profile1.p7b"; +static const std::string VERIFY_PROFILE_OUT_FILE = "./signProfile/VerifyResult.json"; +// sign app 使用全局参数 +static const std::string SIGN_APP_MODE = "localSign"; +static const std::string SIGN_APP_KEY_ALIAS = "oh-app1-key-v1"; +static const std::string SIGN_APP_APP_CERT_FILE = "./signProfile/app-release1.pem"; +static const std::string SIGN_APP_PROFILE_FILE = "./signProfile/app1-profile1.p7b"; +static const std::string SIGN_APP_IN_FILE = "./signProfile/unsigned.hap"; +static const std::string SIGN_APP_IN_FILE_TXT = "./signProfile/unsigned.txt"; +static const std::string SIGN_APP_SIGN_ALG = "SHA256withECDSA"; +static const std::string SIGN_APP_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_APP_OUT_FILE = "./signProfile/signed.hap"; + +class ProvisionTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp()override; + void TearDown()override; +}; +void ProvisionTest::SetUpTestCase(void) +{ + std::filesystem::copy(SIGN_APP_IN_FILE_TXT, SIGN_APP_IN_FILE); +} + +void ProvisionTest::TearDownTestCase(void) +{ + std::filesystem::remove(SIGN_APP_IN_FILE); +} + +void ProvisionTest::SetUp() +{ +} + +void ProvisionTest::TearDown() +{ +} + +/** + * @tc.name: provision_test001 + * @tc.desc: Test function of LocalSigner::GetCrls() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test001, testing::ext::TestSize.Level1) +{ + EVP_PKEY* pkey = NULL; + STACK_OF(X509)* certs = NULL; + std::shared_ptr signer = std::make_shared(pkey, certs); + STACK_OF(X509_CRL)* crls = signer->GetCrls(); + EXPECT_TRUE(crls == NULL); +} + +/** + * @tc.name: provision_test002 + * @tc.desc: Test function of LocalSigner::GetSignature() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test002, testing::ext::TestSize.Level1) +{ + std::string content = "signed content data"; + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + std::string signature1 = signer->GetSignature(content, "SHA384withECDSA"); + EXPECT_TRUE(signature1.size()); + std::string signature2 = signer->GetSignature(content, "SHA256withECDSA"); + EXPECT_TRUE(signature2.size()); + std::string signature3 = signer->GetSignature(content, "SHA999withECDSA"); + EXPECT_TRUE(signature3.empty()); + std::string signature4 = signer->GetSignature("", "SHA384withECDSA"); + EXPECT_FALSE(signature4.empty()); +} + +/** + * @tc.name: provision_test003 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test003, testing::ext::TestSize.Level1) +{ + SetRdDevice(false); + std::string provision = "{\"acls\":{\"allowed-acls\":[\"ac1\",\"ac2\"]},\"bundle-info\":{\"app-feature\":" + "\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\"," + "\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD53029605" + "4159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]}," + "\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"invalid de" + "bug\",\"uuid\"" + ":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610519532}" + ",\"version-code\":1,\"version-name\":\"1.0.0\",\"baseapp-info\":{\"package-name\":\"package_name\",\"packag" + "e-cert\":\"package_cert\"}}"; + ProfileInfo info; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test004 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test004, testing::ext::TestSize.Level1) +{ + std::string provision = "{\"acls\":{\"allowed-acls\":[\"ac1\",\"ac2\"]},\"bundle-info\":{\"app-feature\":" + "\"hos_system_" + "app\",\"bundle-name\":\".*\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":" + "\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD530296" + "054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]},\"" + "issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"debug\",\"uuid" + "\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":161051" + "9532},\"version-code\":1,\"version-name\":\"1.0.0\",\"baseapp-info\":{\"package-name\":\"package_name\"," + "\"package-cert\":\"package_cert\"}}"; + ProfileInfo info2; + AppProvisionVerifyResult result = ParseProvision(provision, info2); + EXPECT_TRUE(result == PROVISION_OK); +} +/** + * @tc.name: provision_test005 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test005, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "55.2"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test006 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test006, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"name\": \"feixing\",\"age\": 18}+"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test007 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test007, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "55.2"; + AppProvisionVerifyResult result = ParseProfile(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test008 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test008, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"name\": \"feixing\",\"age\": 18}+"; + AppProvisionVerifyResult result = ParseProfile(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test009 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test009, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "[88,99,42,11,22]"; + AppProvisionVerifyResult result = ParseProfile(provision, info); + EXPECT_TRUE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test010 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test010, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-feature\"" + ":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"developer-id\":\"OpenHarm" + "ony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD" + "530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F95873" + "2865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":" + "\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532" + ",\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_TRUE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test011 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test011, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com.e" + "xample.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-----BE" + "GIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44AB" + "CD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F" + "958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]}," + "\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after" + "\":1705127532,\"not-before\":1610519532},\"version-code\":0,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test012 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test012, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"c" + "om.example.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-" + "----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB4" + "4ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C767" + "9A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[" + "\"\"]},\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"" + "not-after\":1705127532,\"not-before\":1610519532},\"version-code_no\":0,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test013 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test013, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"c" + "om.example.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"" + "-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB4" + "4ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C76" + "79A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":" + "[\"\"]},\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{" + "\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":\"0\",\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test014 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test014, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-privilege-capabilities\": [99,\"88\"],\"bundle-info\":{\"app" + "-feature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"developer" + "-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB" + "44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7" + "679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\"" + ":[\"\"]},\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":" + "{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_TRUE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test015 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test015, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"\"," + "\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44AB" + "CD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F9" + "58732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"" + "type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1" + "705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test016 + * @tc.desc: Test function of RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test016, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com.exa" + "mple.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CE" + "RTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD5302" + "96054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]}" + ",\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"debug\",\"" + "uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":" + "1610519532},\"version-code\":1,\"version-name\":\"\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test017 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test017, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com.examp" + "le.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTI" + "FICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD530296" + "054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]},\"" + "issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"debug\",\"uu" + "id\":\"\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"vers" + "ion-name\":\"\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test018 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test018, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com.examp" + "le.nativetemplatedemo\",\"developer-id\":\"\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD5" + "30296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732" + "865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"" + "debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"" + "not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test019 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test019, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com" + ".example.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"\"},\"" + "d""ebug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD53029" + "6054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F95873286" + "5\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"de" + "bug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"no" + "t-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test020 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test020, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"bundle-info\":{\"app-feature\":\"\",\"bundle-name\":\"com.example.nativetem" + "platedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD53" + "0296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F9587328" + "65\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"" + "debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"" + "not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test021 + * @tc.desc: Test function of Provision operator==() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test021, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + ProfileInfo info2; + info2.profileBlockLength = 0; + info = info2; +} + +/** + * @tc.name: provision_test023 + * @tc.desc: Test function of Provision operator==() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test023, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + ProfileInfo info2; + info2.profileBlockLength = 5; + info2.profileBlock = NULL; + info = info2; +} + +/** + * @tc.name: provision_test025 + * @tc.desc: Test function of ProfileSignTool::GenerateP7b() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test025, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char invalidKeyPwd[] = "12345"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = invalidKeyPwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, content, ret); + EXPECT_FALSE(result == 0); +} + +/** + * @tc.name: provision_test026 + * @tc.desc: Test function of ProfileSignTool::GenerateP7b() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test026, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + std::string invalid_sigAlg = "SHA385withECDSA"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = invalid_sigAlg; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, content, ret); + EXPECT_FALSE(result == 0); +} + +/** + * @tc.name: provision_test027 + * @tc.desc: Test function of ProfileSignTool::GenerateP7b() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test027, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, content, ret); + EXPECT_TRUE(result == 0); +} + +/** + * @tc.name: provision_test028 + * @tc.desc: Test function of ProfileSignTool::SignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test028, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_PROFILE_CERT_FILE; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::SignProfile(content, signer, SIGN_PROFILE_SIGN_ALG, ret); + EXPECT_TRUE(result == 0); +} + +/** + * @tc.name: provision_test029 + * @tc.desc: Test function of ProfileSignTool::GenerateP7b() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test029, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_CERT_PEM; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, content, ret); + EXPECT_FALSE(result == 0); +} + +/** + * @tc.name: provision_test030 + * @tc.desc: Test function of ProfileSignTool::GenerateP7b() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test030, testing::ext::TestSize.Level1) +{ + Options options; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = SIGN_PROFILE_KEY_ALIAS; + options[Options::MODE] = SIGN_PROFILE_MODE; + options[Options::PROFILE_CERT_FILE] = SIGN_PROFILE_DOUBLE_CERT_PEM; + options[Options::SIGN_ALG] = SIGN_PROFILE_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_PROFILE_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_PROFILE_OUT_FILE; + options[Options::IN_FILE] = SIGN_PROFILE_IN_FILE; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + std::string ret; + int result = ProfileSignTool::GenerateP7b(adapter, content, ret); + EXPECT_FALSE(result == 0); +} + +/** + * @tc.name: provision_test031 + * @tc.desc: Test function of LocalSigner::GetCrls() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test031, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509_CRL)* crls = signer->GetCrls(); + EXPECT_TRUE(crls == NULL); +} + +/** + * @tc.name: provision_test032 + * @tc.desc: Test function of LocalSigner() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test032, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + EVP_PKEY* pkey = NULL; + STACK_OF(X509)* certs = NULL; + std::shared_ptr signer = NULL; + signer = std::make_shared(pkey, certs); +} + +/** + * @tc.name: provision_test033 + * @tc.desc: Test function of LocalSigner() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test033, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + EVP_PKEY* pkey = NULL; + STACK_OF(X509)* certs = NULL; + LocalizationAdapter adapter(&options); + pkey = adapter.GetAliasKey(false); + std::shared_ptr signer = std::make_shared(pkey, certs); +} + +/** + * @tc.name: provision_test034 + * @tc.desc: Test function of LocalSigner() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test034, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + EVP_PKEY* pkey = NULL; + STACK_OF(X509)* certs = sk_X509_new(NULL); + LocalizationAdapter adapter(&options); + pkey = adapter.GetAliasKey(false); + std::shared_ptr signer = std::make_shared(pkey, certs); +} + +/** + * @tc.name: provision_test035 + * @tc.desc: Test function of GetSignature::GetSignature() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test035, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + EVP_PKEY* pkey = NULL; + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + STACK_OF(X509)* certsDup = sk_X509_new(NULL); + X509* cert = sk_X509_value(certs, 0); + X509_up_ref(cert); + sk_X509_push(certsDup, cert); + std::shared_ptr signer2 = std::make_shared(pkey, certsDup); + std::string signature = signer2->GetSignature("content", "SHA384withECDSA"); +} + +/** + * @tc.name: provision_test036 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test036, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"app-distribution-type" + "\": \"app_gallery\",\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"co" + "m.example.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"development-certifica" + "te\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD530" + "296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865" + "\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"re" + "lease\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"n" + "ot-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test037 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test037, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-featur" + "e\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"developer-id\":\"Ope" + "nHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44A" + "BCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73" + "F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]" + "},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-a" + "fter\":1705127532,\"not-before\":1610519532},\"version-code\":0,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test038 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test038, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-fea" + "ture\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"developer-id\":\"" + "OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0C" + "B44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718" + "C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-permission" + "s\":[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"valid" + "ity\":{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code_no\":0,\"ver" + "sion-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test039 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test039, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app-f" + "eature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"developer-" + "id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69" + "C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7E" + "ED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]},\"is" + "suer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"t" + "ype\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"no" + "t-after\":1705127532,\"not-before\":1610519532},\"version-code\":\"0\",\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test040 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test040, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"app-privilege-cap" + "abilities\": [99,\"88\"],\"bundle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-" + "name\":\"com.example.nativetemplatedemo\",\"developer-id\":\"OpenHarmony\",\"develop" + "ment-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341B" + "DA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2F" + "AA019458B856AB10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"perm" + "issions\":{\"restricted-permissions\":[\"\"]},\"type\":\"release\",\"uuid\":\"fe6" + "86e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-bef" + "ore\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test041 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test041, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-in" + "fo\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"\",\"developer-id\":\"Op" + "enHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA" + "5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA0194" + "58B856AB10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions" + "\":{\"restricted-permissions\":[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-37" + "70-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610" + "519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test042 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test042, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"ap" + "p-feature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"devel" + "oper-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C" + "0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493" + "A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restricted-pe" + "rmissions\":[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c9" + "8\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610519532},\"version-code\":" + "1,\"version-name\":\"\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test043 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test043, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"a" + "pp-feature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"d" + "eveloper-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA59" + "48C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B" + "856AB10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"r" + "estricted-permissions\":[\"\"]},\"type\":\"release\",\"uuid\":\"\",\"validity\":{\"no" + "t-after\":1705127532,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test044 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test044, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"app" + "-feature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"develo" + "per-id\":\"\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5" + "948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B" + "856AB10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"re" + "stricted-permissions\":[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938" + "-961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610519532},\"ver" + "sion-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test045 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test045, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"a" + "pp-feature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"dev" + "eloper-id\":\"OpenHarmony\",\"development-certificate\":\"\"},\"debug-info\":{\"device-i" + "d-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16" + "A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]},\"i" + "ssuer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":[\"\"]},\"type\":\"de" + "bug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140a7c98\",\"validity\":{\"not-after\":17051275" + "32,\"not-before\":1610519532},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test046 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test046, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-in" + "fo\":{\"app-feature\":\"\",\"bundle-name\":\"com.example.nativetemplatedemo\",\"de" + "veloper-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA59" + "48C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B8" + "56AB10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"re" + "stricted-permissions\":[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-" + "961b140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610519532},\"ver" + "sion-code\":1,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_FALSE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test047 + * @tc.desc: Test function of ParseProvision() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test047, testing::ext::TestSize.Level1) +{ + ProfileInfo info; + std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"bundle-info\":{\"a" + "pl\":\"apl_\",\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com.example.nativetemp" + "latedemo\",\"developer-id\":\"OpenHarmony\",\"development-certificate\":\"-----BEGIN CERTIFICATE-----\\n" + "MIICXjCCAeOgAwIBAgIBATAKBggqhkjOPQQDAzBuMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEpMCcGA1UEAwwgQXBwbGljYXRpb24gU2lnbmF0dXJlIFNlcnZpY2UgQ0EwHhcN\\n" + "MjQwNDE1MDUzOTUyWhcNMjUwNDE1MDUzOTUyWjBaMQswCQYDVQQGEwJDTjEUMBIG\\n" + "A1UECgwLT3Blbkhhcm1vbnkxHjAcBgNVBAsMFU9wZW5IYXJtb255IENvbW11bml0\\n" + "eTEVMBMGA1UEAwwMQXBwMSBSZWxlYXNlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE\\n" + "odSztdiucyVAo7VQnzHzBJsS9vQYa1vU1cP92F6fiJLazWtvEljNP1XoJldSZaN9\\n" + "UYGdAVHh2yrHzaJFEqHCSB3uQhlJgSbl9sT0lJ4hro1YvVx921/knMRlunz4eAGX\\n" + "o2kwZzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEF\\n" + "BQcDAzAbBgNVHQ4EFEpzK6IntvQxLaKGX6xZQSiISBx+MBgGDCsGAQQBj1sCgngB\\n" + "AwQIMAYCAQEKAQAwCgYIKoZIzj0EAwMDaQAwZgIxAPboDdi9EhOiwAhO3N6vTRcK\\n" + "QT1K1TQq2vjvpC2231Dq4tLPeSzLz6ROq+Zv6IgBYgIxAJ9sZZUBoR2lgPHBzt01\\n" + "4uxt5nLfJj2XKa6Leb/JWDoosXjoVXoB47y699PtGetcFw==\\n" + "-----END CERTIFICATE-----\\n" + "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C7505BE341BDA594" + "8C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED06506FCE6325EB2E2FAA019458B856A" + "B10493A6718C7679A73F958732865\"]},\"issuer\":\"pki_internal\",\"permissions\":{\"restr" + "icted-permissions\":[\"\"]},\"type\":\"debug\",\"uuid\":\"fe686e1b-3770-4824-a938-961b" + "140a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":1610519532},\"versio" + "n-code\":3,\"version-name\":\"1.0.0\"}"; + AppProvisionVerifyResult result = ParseProvision(provision, info); + EXPECT_TRUE(result == PROVISION_OK); +} + +/** + * @tc.name: provision_test048 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test048, testing::ext::TestSize.Level1) +{ + Pkcs7Context profilePkcs7Context; + Pkcs7Context hapPkcs7Context; + std::string profile = "hello,world"; + hapPkcs7Context.matchResult.matchState = MATCH_WITH_SIGN; + hapPkcs7Context.matchResult.source = APP_GALLARY; + ByteBuffer pkcs7ProfileBlock; + pkcs7ProfileBlock.SetCapacity(5); + pkcs7ProfileBlock.PutData("hello", 5); + int result = ProfileVerifyUtils::ParseProfile(profilePkcs7Context, hapPkcs7Context, pkcs7ProfileBlock, profile); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: provision_test049 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test049, testing::ext::TestSize.Level1) +{ + Pkcs7Context profilePkcs7Context; + Pkcs7Context hapPkcs7Context; + int length = 5; + std::string profile = "hello,world"; + hapPkcs7Context.matchResult.source = APP_GALLARY; + ByteBuffer pkcs7ProfileBlock; + pkcs7ProfileBlock.SetCapacity(length); + pkcs7ProfileBlock.PutData("hello", length); + int result = ProfileVerifyUtils::ParseProfile(profilePkcs7Context, hapPkcs7Context, pkcs7ProfileBlock, profile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: provision_test050 + * @tc.desc: Test function of ParseProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ProvisionTest, provision_test050, testing::ext::TestSize.Level1) +{ + Pkcs7Context profilePkcs7Context; + Pkcs7Context hapPkcs7Context; + int length = 5; + std::string profile = "hello,world"; + hapPkcs7Context.matchResult.matchState = MATCH_WITH_SIGN; + ByteBuffer pkcs7ProfileBlock; + pkcs7ProfileBlock.SetCapacity(length); + pkcs7ProfileBlock.PutData("hello", length); + int result = ProfileVerifyUtils::ParseProfile(profilePkcs7Context, hapPkcs7Context, pkcs7ProfileBlock, profile); + EXPECT_EQ(result, false); +} + +} +} diff --git a/hapsigntool_cpp/test/unittest/signProfile/sign_profile_test.cpp b/hapsigntool_cpp/test/unittest/signProfile/sign_profile_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..918d4ac50d4f0e2ec06fad403a252464ea2d8a1e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/signProfile/sign_profile_test.cpp @@ -0,0 +1,755 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "options.h" +#include "sign_tool_service_impl.h" +#include "nlohmann/json.hpp" +#include "signer_factory.h" +#include "profile_sign_tool.h" +#include "params_run_tool.h" +#include "pkcs7_data.h" +#include "signer_config.h" +#include "local_signer.h" +#include "bc_pkcs7_generator.h" +#include "bc_signeddata_generator.h" +#include "profile_verify.h" +#include "constant.h" + +using nlohmann::json; + +namespace OHOS { +namespace SignatureTools { + +// sign profile使用的全局参数 +static const std::string SIGN_PROFILE_MODE = "localSign"; +static const std::string SIGN_PROFILE_KEY_ALIAS = "oh-profile1-key-v1"; +static const std::string SIGN_PROFILE_PROFILE_CERT_FILE = "./signProfile/profile-release1.pem"; +static const std::string SIGN_PROFILE_SIGN_ALG = "SHA384withECDSA"; +static const std::string SIGN_PROFILE_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_PROFILE_OUT_FILE = "./signProfile/signed-profile.p7b"; +static const std::string SIGN_PROFILE_IN_FILE = "./signProfile/profile.json"; +// verify profile 使用的全局参数 +static const std::string VERIFY_PROFILE_IN_FILE = "./signProfile/signed-profile.p7b"; +static const std::string VERIFY_PROFILE_OUT_FILE = "./signProfile/VerifyResult.json"; +// sign app 使用全局参数 +static const std::string SIGN_APP_MODE = "localSign"; +static const std::string SIGN_APP_KEY_ALIAS = "oh-app1-key-v1"; +static const std::string SIGN_APP_APP_CERT_FILE = "./signProfile/app-release1.pem"; +static const std::string SIGN_APP_PROFILE_FILE = "./signProfile/signed-profile.p7b"; +static const std::string SIGN_APP_IN_FILE = "./signProfile/unsigned.hap"; +static const std::string SIGN_APP_IN_FILE_TXT = "./signProfile/unsigned.txt"; +static const std::string SIGN_APP_SIGN_ALG = "SHA256withECDSA"; +static const std::string SIGN_APP_KEY_STORE_FILE = "./signProfile/ohtest.p12"; +static const std::string SIGN_APP_OUT_FILE = "./signProfile/signed.hap"; + +class SignProfileTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp()override; + + void TearDown()override; +}; + +void SignProfileTest::SetUpTestCase(void) +{ + std::filesystem::copy(SIGN_APP_IN_FILE_TXT, SIGN_APP_IN_FILE); +} + +void SignProfileTest::TearDownTestCase(void) +{ + std::filesystem::remove(SIGN_APP_IN_FILE); +} + +void SignProfileTest::SetUp() +{ +} + +void SignProfileTest::TearDown() +{ +} + +/** + * @tc.name: run_sign_profile_test001 + * @tc.desc: Test function of HapSignTool::RunSignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, run_sign_profile_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = ParamsRunTool::RunSignProfile(&options, api); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: sign_profile_test001 + * @tc.desc: Test function of SignToolServiceImpl::SignProfile() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, sign_profile_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + char pwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignToolServiceImpl api; + bool result = api.SignProfile(&options); + EXPECT_EQ(result, true); + // 密钥匿名错误 失败 + options[Options::KEY_ALIAS] = std::string("oh-profile1-key-v2"); + std::copy(pwd, pwd + 7, keypwd); + std::copy(pwd, pwd + 7, keyStorePwd); + result = api.SignProfile(&options); + options[Options::KEY_ALIAS] = std::string("oh-profile1-key-v1"); + EXPECT_EQ(result, false); + // 使用SHAwithECDSA256签名算法 成功 + options[Options::SIGN_ALG] = std::string("SHA256withECDSA"); + std::copy(pwd, pwd + 7, keypwd); + std::copy(pwd, pwd + 7, keyStorePwd); + result = api.SignProfile(&options); + options[Options::SIGN_ALG] = std::string("SHA384withECDSA"); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: get_provision_content_test001 + * @tc.desc: Test function of SignToolServiceImpl::GetProvisionContent() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, get_provision_content_test001, testing::ext::TestSize.Level1) +{ + std::string ret; + const std::string provisionFilePath = SIGN_PROFILE_IN_FILE; + SignToolServiceImpl::GetProvisionContent(provisionFilePath, ret); + EXPECT_TRUE(ret.size() > 0); +} + +/** +* @tc.name: parse_provision_test001 +* @tc.desc: Test function of ParseProvision() interface for SUCCESS. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(SignProfileTest, parse_provision_test001, testing::ext::TestSize.Level1) +{ + std::string bytes; + FileUtils::ReadFile(SIGN_PROFILE_IN_FILE, bytes); + ProfileInfo provision; + AppProvisionVerifyResult result = ParseProvision(bytes, provision); + EXPECT_TRUE(result == PROVISION_OK); +} + +/** + * @tc.name: generate_p7b_test001 + * @tc.desc: Test function of ProfileSignTool::GenerateP7b() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, generate_p7b_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + std::string content = "json content"; + int result = ProfileSignTool::GenerateP7b(adapter, content, content); + EXPECT_TRUE(result == 0); +} + +/** + * @tc.name: print_cert_chain_sub_test001 + * @tc.desc: Test function of PKCS7Data::PrintCertChainSub() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, print_cert_chain_sub_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + PKCS7Data::PrintCertChainSub(certs); + PKCS7Data::SortX509Stack(certs); + EXPECT_TRUE(true); +} + +/** +* @tc.name: run_verify_profile_test001 +* @tc.desc: Test function of HapSignTool::RunVerifyProfile() interface for SUCCESS. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(SignProfileTest, run_verify_profile_test001, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::IN_FILE] = VERIFY_PROFILE_IN_FILE; + options[Options::OUT_FILE] = VERIFY_PROFILE_OUT_FILE; + SignToolServiceImpl api; + ParamsRunTool::RunVerifyProfile(&options, api); +} + +/** +* @tc.name: run_sign_profile_test001 +* @tc.desc: Test function of SignToolServiceImpl::VerifyProfile() interface for SUCCESS json写入OUT_FILE. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(SignProfileTest, verify_profile_test001, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::IN_FILE] = VERIFY_PROFILE_IN_FILE; + options[Options::OUT_FILE] = VERIFY_PROFILE_OUT_FILE; + bool result = false; + SignToolServiceImpl api; + result = api.VerifyProfile(&options); + EXPECT_TRUE(result); +} + + +/** + * @tc.name: run_sign_profile_test001 + * @tc.desc: Test function of SignToolServiceImpl::VerifyProfile() interface for SUCCESS 验证成功打印json到控制台. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, verify_profile_test002, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::IN_FILE] = VERIFY_PROFILE_IN_FILE; + options[Options::OUT_FILE] = VERIFY_PROFILE_OUT_FILE; + bool result = false; + SignToolServiceImpl api; + result = api.VerifyProfile(&options); + EXPECT_TRUE(result); +} + +/** +* @tc.name: parse_test001 +* @tc.desc: Test function of PKCS7Data::Parse() interface for SUCCESS . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: SR000H63TL +*/ +HWTEST_F(SignProfileTest, parse_test001, testing::ext::TestSize.Level1) +{ + std::string p7b; + FileUtils::ReadFile(VERIFY_PROFILE_IN_FILE, p7b); + PKCS7Data p7; + int result = p7.Parse(p7b); + EXPECT_EQ(result, 0); +} + +/** + * @tc.name: parse_test001 + * @tc.desc: Test function of PKCS7Data::Parse() interface for SUCCESS . + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, parse_test002, testing::ext::TestSize.Level1) +{ + std::string p7b; + FileUtils::ReadFile(VERIFY_PROFILE_IN_FILE, p7b); + PKCS7Data p7; + std::vector p7b_(p7b.begin(), p7b.end()); + int result = p7.Parse(p7b_); + EXPECT_EQ(result, 0); +} + +/** + * @tc.name: parse_test001 + * @tc.desc: Test function of PKCS7Data::Sign() interface for SUCCESS . + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, sign_test001, testing::ext::TestSize.Level1) +{ + std::string content = "signed content data"; + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + PKCS7Data p7; + std::string p7b; + int result = p7.Sign(content, signer, "SHA384withECDSA", p7b); + EXPECT_EQ(result, 0); +} + +/** + * @tc.name: parse_test001 + * @tc.desc: Test function of PKCS7Data::Sign() interface for SUCCESS .数据分离 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, sign_test002, testing::ext::TestSize.Level1) +{ + std::string content = "signed content data"; + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + PKCS7Data p7(PKCS7_DETACHED_FLAGS); + std::string p7b; + int result = p7.Sign(content, signer, "SHA384withECDSA", p7b); + EXPECT_EQ(result, 0); +} + +/** + * @tc.name: parse_test001 + * @tc.desc: Test function of PKCS7Data::Verify() interface for SUCCESS .数据分离 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, verify_test001, testing::ext::TestSize.Level1) +{ + std::string p7b; + FileUtils::ReadFile(VERIFY_PROFILE_IN_FILE, p7b); + PKCS7Data p7; + int result = p7.Parse(p7b); + // 验证 + result = p7.Verify(); + EXPECT_EQ(result, 0); +} +/** + * @tc.name: get_original_raw_data_test001 + * @tc.desc: Test function of PKCS7Data::GetOriginalRawData() interface for SUCCESS . + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, get_original_raw_data_test001, testing::ext::TestSize.Level1) +{ + std::string p7b; + FileUtils::ReadFile(VERIFY_PROFILE_IN_FILE, p7b); + PKCS7Data p7; + int result = p7.Parse(p7b); + std::string provision; + result = p7.GetContent(provision); + EXPECT_EQ(result, 0); +} + +/** + * @tc.name: get_signer_test001 + * @tc.desc: Test function of SignerFactory::GetSigner() interface for SUCCESS . + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, get_signer_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + EXPECT_TRUE(signer != NULL); +} + +/** + * @tc.name: get_crls_test001 + * @tc.desc: Test function of LocalSigner::GetCrls() interface for SUCCESS . + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, get_crls_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509_CRL)* crls = signer->GetCrls(); + EXPECT_TRUE(crls == NULL); +} + +/** + * @tc.name: get_certificates_test001 + * @tc.desc: Test function of LocalSigner::GetCertificates() interface for SUCCESS . + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, get_certificates_test001, testing::ext::TestSize.Level1) +{ + Options options; + std::string mode = SIGN_PROFILE_MODE; + std::string keyAlias = SIGN_PROFILE_KEY_ALIAS; + std::string profileCertFile = SIGN_PROFILE_PROFILE_CERT_FILE; + std::string signAlg = SIGN_PROFILE_SIGN_ALG; + std::string keystoreFile = SIGN_PROFILE_KEY_STORE_FILE; + std::string outFile = SIGN_PROFILE_OUT_FILE; + std::string inFile = SIGN_PROFILE_IN_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_ALIAS] = keyAlias; + options[Options::MODE] = mode; + options[Options::PROFILE_CERT_FILE] = profileCertFile; + options[Options::SIGN_ALG] = signAlg; + options[Options::KEY_STORE_FILE] = keystoreFile; + options[Options::OUT_FILE] = outFile; + options[Options::IN_FILE] = inFile; + options[Options::KEY_RIGHTS] = keypwd; + options[Options::KEY_STORE_RIGHTS] = keyStorePwd; + + LocalizationAdapter adapter(&options); + SignerFactory factory; + std::shared_ptr signer = factory.GetSigner(adapter); + STACK_OF(X509)* certs = signer->GetCertificates(); + EXPECT_TRUE(certs != NULL); +} + +/** + * @tc.name: generate_signeddata_test001 + * @tc.desc: Test function of BCSignedDataGenerator::GenerateSignedData() interface for SUCCESS .set ownerid and + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, generate_signeddata_test001, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_APP_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_APP_APP_CERT_FILE; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_APP_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::ECDSA_WITH_SHA256; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr signedDataGenerator = + std::make_shared(); + signedDataGenerator->SetOwnerId(OWNERID_OID); + int result = signedDataGenerator->GenerateSignedData(content, &config, signedData); + EXPECT_EQ(result, 0); +} + +/** + * @tc.name: generate_signeddata_test002 + * @tc.desc: Test function of BCPkcs7Generator::GenerateSignedData() interface for SUCCESS + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(SignProfileTest, generate_signeddata_test002, testing::ext::TestSize.Level1) +{ + Options options; + options[Options::MODE] = SIGN_APP_MODE; + options[Options::KEY_ALIAS] = SIGN_APP_KEY_ALIAS; + options[Options::APP_CERT_FILE] = SIGN_APP_APP_CERT_FILE; + options[Options::PROFILE_FILE] = SIGN_APP_PROFILE_FILE; + options[Options::IN_FILE] = SIGN_APP_IN_FILE; + options[Options::SIGN_ALG] = SIGN_APP_SIGN_ALG; + options[Options::KEY_STORE_FILE] = SIGN_APP_KEY_STORE_FILE; + options[Options::OUT_FILE] = SIGN_APP_OUT_FILE; + char keyStorePwd[] = "123456"; + char keypwd[] = "123456"; + options[Options::KEY_RIGHTS] = keyStorePwd; + options[Options::KEY_STORE_RIGHTS] = keypwd; + + // config设置算法 signer + SignerConfig config; + config.SetOptions(&options); + SignatureAlgorithmHelper algClass; + std::vector sigs; + sigs.resize(1); + sigs[0].m_id = SignatureAlgorithmId::ECDSA_WITH_SHA256; + config.SetSignatureAlgorithms(sigs); + + std::string content = "digest content"; + std::string signedData; + std::shared_ptr pkcs7Generator = std::make_shared(); + int result = pkcs7Generator->GenerateSignedData(content, &config, signedData); + EXPECT_EQ(result, 0); +} +/** + * @tc.name: run_sign_app_test001 + * @tc.desc: Test function of HapSignTool::RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL +*/ +HWTEST_F(SignProfileTest, run_sign_app_test001, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = SIGN_APP_MODE; + (*params)["keyAlias"] = SIGN_APP_KEY_ALIAS; + (*params)["signAlg"] = SIGN_APP_SIGN_ALG; + (*params)["appCertFile"] = SIGN_APP_APP_CERT_FILE; + (*params)["profileFile"] = SIGN_APP_PROFILE_FILE; + (*params)["inFile"] = SIGN_APP_IN_FILE; + (*params)["keystoreFile"] = SIGN_APP_KEY_STORE_FILE; + (*params)["outFile"] = SIGN_APP_OUT_FILE; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["inForm"] = std::string("zip"); + (*params)["profileSigned"] = std::string("1"); + (*params)["signCode"] = std::string("1"); + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, true); +} + + +/** + * @tc.name: run_sign_app_test002 + * @tc.desc: Test function of HapSignTool::RunSignApp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL +*/ +HWTEST_F(SignProfileTest, run_sign_app_test002, testing::ext::TestSize.Level1) +{ + std::unique_ptr api = std::make_unique(); + std::shared_ptr params = std::make_shared(); + + char keyPwd[] = "123456"; + char keystorePwd[] = "123456"; + + (*params)["mode"] = SIGN_APP_MODE; + (*params)["keyAlias"] = SIGN_APP_KEY_ALIAS; + (*params)["signAlg"] = SIGN_APP_SIGN_ALG; + (*params)["appCertFile"] = SIGN_APP_APP_CERT_FILE; + (*params)["profileFile"] = SIGN_APP_PROFILE_FILE; + (*params)["inFile"] = SIGN_APP_IN_FILE; + (*params)["keystoreFile"] = SIGN_APP_KEY_STORE_FILE; + (*params)["outFile"] = SIGN_APP_OUT_FILE; + (*params)["keyPwd"] = keyPwd; + (*params)["keystorePwd"] = keystorePwd; + (*params)["inForm"] = std::string("zip"); + (*params)["profileSigned"] = std::string("0"); + (*params)["signCode"] = std::string("0"); + + bool ret = ParamsRunTool::RunSignApp(params.get(), *api); + EXPECT_EQ(ret, false); +} + +} +} \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/utils/byte_array_utils_test.cpp b/hapsigntool_cpp/test/unittest/utils/byte_array_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37e0d7510e1a965e73d392d2cf1aa69e92e4fc54 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/utils/byte_array_utils_test.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "byte_array_utils.h" + +namespace OHOS { +namespace SignatureTools { +/* +* 测试套件,固定写法 +*/ +class ByteArrayUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +/** + * @tc.name: InsertIntToByteArray + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ByteArrayUtilsTest, InsertIntToByteArray, testing::ext::TestSize.Level1) +{ + std::vector ret = { 49, 48, 48, 48, 0, 48, 0, 1, 0, -120, 0, 6, 0, 0, 0, 0 }; + int result = ByteArrayUtils::InsertIntToByteArray(ret, 16, 32); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: InsertShortToByteArray + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ByteArrayUtilsTest, InsertShortToByteArray, testing::ext::TestSize.Level1) +{ + std::vector ret = { 49, 48, 48, 48, 0, 48, 0, 1, 0, -120, 0, 0, 0, 0, 0, 0 }; + int result = ByteArrayUtils::InsertShortToByteArray(ret, 16, 16, 6); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: InsertByteToByteArray + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ByteArrayUtilsTest, InsertByteToByteArray, testing::ext::TestSize.Level1) +{ + std::vector ret = { 49, 48, 48, 48, 0, 48, 0, 1, 0, -120, 0, 6, 0, 0, 0, 32 }; + std::vector hashValue = { -114, -19, -78, 49, 26, 23, 116, -70, 72, 35, +-41, -43, 43, -115, -2, -93, -91, -67, -76, 77, +100, -83, -69, -36, -18, 59, -12, -64, -118, 123, 48, -99 }; + int result = ByteArrayUtils::InsertByteToByteArray(ret, 16, hashValue, 33); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: InsertCharToByteArray + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(ByteArrayUtilsTest, InsertCharToByteArray, testing::ext::TestSize.Level1) +{ + std::vector ret(48, 0); + int result = ByteArrayUtils::InsertCharToByteArray(ret, 45, "1000"); + EXPECT_EQ(result, -1); +} + +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/utils/file_utils_test.cpp b/hapsigntool_cpp/test/unittest/utils/file_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04343bad678d8ea9637d32a321f52bdbc1700072 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/utils/file_utils_test.cpp @@ -0,0 +1,712 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include "file_utils.h" + +namespace OHOS { +namespace SignatureTools { +/* +* 测试套件,固定写法 +*/ +class FileUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + }; + static void TearDownTestCase() + { + }; + void SetUp() + { + }; + void TearDown() + { + }; +}; + +const int THREAD_NUMS = 8; +const size_t MAX_FILE_SIZE = 1024 * 1024 * 10; +const size_t BUFFER_SIZE = 1024 * 128; + +void CreateTestFile() +{ + (void)mkdir("tmp", 0777); + srand((unsigned)time(NULL)); + + for (int i = 1; i <= THREAD_NUMS; i++) { + std::string fileName = "tmp/tmp-" + std::to_string(i) + ".txt"; + std::ofstream file(fileName, std::ios::binary); + if (!file.is_open()) { + printf("open file: %s failed.\n", fileName.c_str()); + continue; + } + + char buffer[BUFFER_SIZE]; + size_t remaining = MAX_FILE_SIZE; + while (remaining > 0) { + size_t min = std::min(BUFFER_SIZE, remaining); + for (size_t j = 0; j < min; j++) { + //generates a printable ASCII character (32 through 126) + // The ASCII code for ' ' is 32, so this generates characters between 32 and 126 + buffer[j] = ' ' + (char)(rand() % 95); + } + + file.write(buffer, min); + if (!file.good()) { + printf("write file: %s failed.\n", fileName.c_str()); + break; + } + + remaining -= min; + } + printf("File %s has been created with %zu bytes.\n", fileName.c_str(), MAX_FILE_SIZE); + } +} + +int Worker(const std::string& inputFile, const std::string& outputFile, int length) +{ + std::ifstream input(inputFile, std::ios::binary); + std::ofstream output(outputFile, std::ios::binary); + if (!input) { + printf("open file: %s failed.\n", inputFile.c_str()); + return -1; + } + if (!output) { + printf("open file: %s failed.\n", outputFile.c_str()); + return -1; + } + + int res = FileUtils::WriteInputToOutPut(input, output, length); + + std::thread::id id = std::this_thread::get_id(); + printf("thread: %u completed: %s -> %s res: %d\n", *(uint32_t*)&id, inputFile.c_str(), + outputFile.c_str(), res); + + output.close(); + input.close(); + return res; +} + +/** + * @tc.name: WriteByteToOutFile001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteByteToOutFile001, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get output stream object, outfile" + std::vector bytes; + std::ofstream output("./utilstmp/signed-linux.out", std::ios::binary); + bool flag = FileUtils::WriteByteToOutFile(bytes, output); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: WriteByteToOutFile002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteByteToOutFile002, testing::ext::TestSize.Level1) +{ + // outfile path is right + std::vector bytes; + std::ofstream output("./utils/signed-linux.out", std::ios::binary); + bool flag = FileUtils::WriteByteToOutFile(bytes, output); + EXPECT_EQ(flag, false); +} + +/** + * @tc.name: Write + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, Write, testing::ext::TestSize.Level1) +{ + // go to branch "Failed get output stream" + std::string str; + std::string fileName = "./utilsxxx/signed-linux.out"; + int result = FileUtils::Write(str, fileName); + EXPECT_EQ(result, -103); +} + +/** + * @tc.name: Read001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, Read001, testing::ext::TestSize.Level1) +{ + // go to branch "io error" + std::string outstr; + std::ifstream input("./utilsxxx/unsigned-linux.out", std::ios::binary); + int result = FileUtils::Read(input, outstr); + EXPECT_NE(result, -104); +} + +/** + * @tc.name: Read002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, Read002, testing::ext::TestSize.Level1) +{ + // go to all branch + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::Read(input, outstr); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: ReadFile001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadFile001, testing::ext::TestSize.Level1) +{ + // go to branch "open error" + std::string outstr; + std::string fileName = "./utilsxxx/unsigned-linux.out"; + int result = FileUtils::ReadFile(fileName, outstr); + EXPECT_NE(result, -104); +} + +/** + * @tc.name: ReadFile002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadFile002, testing::ext::TestSize.Level1) +{ + // go to all branch + std::string outstr; + std::string fileName = "./utils/unsigned-linux.out"; + int result = FileUtils::ReadFile(fileName, outstr); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: ReadFileByOffsetAndLength001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadFileByOffsetAndLength001, testing::ext::TestSize.Level1) +{ + // go to branch "Size cannot be greater than Integer max value" + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::ReadFileByOffsetAndLength(input, 0, 2147483648, outstr); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: ReadFileByOffsetAndLength002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadFileByOffsetAndLength002, testing::ext::TestSize.Level1) +{ + // go to branch "Error readInputByOffsetAndLength" + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::ReadFileByOffsetAndLength(input, -1, 32, outstr); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: ReadFileByOffsetAndLength003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadFileByOffsetAndLength003, testing::ext::TestSize.Level1) +{ + // go to all branch + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::ReadFileByOffsetAndLength(input, 0, 32, outstr); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: ReadInputByOffsetAndLength001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadInputByOffsetAndLength001, testing::ext::TestSize.Level1) +{ + // go to branch "Size cannot be greater than Integer max value" + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::ReadInputByOffsetAndLength(input, 0, 2147483648, outstr); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: ReadInputByOffsetAndLength002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadInputByOffsetAndLength002, testing::ext::TestSize.Level1) +{ + // go to branch "Error seek" + std::string outstr; + std::ifstream input("./utils/unsigned-linuxxx.out", std::ios::binary); + int result = FileUtils::ReadInputByOffsetAndLength(input, 0, 32, outstr); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: ReadInputByOffsetAndLength003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadInputByOffsetAndLength003, testing::ext::TestSize.Level1) +{ + // go to all branch + std::string outstr; + std::ifstream input("./utils/unsigned-linuxxx.out", std::ios::binary); + int result = FileUtils::ReadInputByOffsetAndLength(input, 0, 32, outstr); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: ReadInputByLength001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadInputByLength001, testing::ext::TestSize.Level1) +{ + // go to branch "Size cannot be greater than Integer max value" + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::ReadInputByLength(input, 2147483648, outstr); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: ReadInputByLength002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadInputByLength002, testing::ext::TestSize.Level1) +{ + // go to branch "Error input" + std::string outstr; + std::ifstream input("./utils/unsigned-linuxxx.out", std::ios::binary); + int result = FileUtils::ReadInputByLength(input, 32, outstr); + EXPECT_EQ(result, -1); +} + +/** + * @tc.name: ReadInputByLength003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, ReadInputByLength003, testing::ext::TestSize.Level1) +{ + std::string outstr; + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + int result = FileUtils::ReadInputByLength(input, 32, outstr); + EXPECT_NE(result, 0); +} + +/** + * @tc.name: AppendWriteFileByOffsetToFile005 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileByOffsetToFile005, testing::ext::TestSize.Level1) +{ + // go to branch "input failed" + std::ifstream input("./utils/unsigned-linuxxx.out", std::ios::binary); + std::ofstream output("./utils/signed-linux.out", std::ios::binary); + bool result = FileUtils::AppendWriteFileByOffsetToFile(input, output, 0, 32); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: AppendWriteFileByOffsetToFile006 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileByOffsetToFile006, testing::ext::TestSize.Level1) +{ + // go to branch "Failed get out stream" + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + std::ofstream output("./utilsxxx/signed-linux.out", std::ios::binary); + bool result = FileUtils::AppendWriteFileByOffsetToFile(input, output, 0, 32); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: AppendWriteFileByOffsetToFile007 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileByOffsetToFile007, testing::ext::TestSize.Level1) +{ + // go to branch "Failed seekg" + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + std::ofstream output("./utils/signed-linux.out", std::ios::binary); + bool result = FileUtils::AppendWriteFileByOffsetToFile(input, output, -1, 32); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: AppendWriteFileByOffsetToFile008 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileByOffsetToFile008, testing::ext::TestSize.Level1) +{ + // go to all branch + std::ifstream input("./utils/unsigned-linux.out", std::ios::binary); + std::ofstream output("./utils/signed-linux.out", std::ios::binary); + bool result = FileUtils::AppendWriteFileByOffsetToFile(input, output, 0, 32); + EXPECT_NE(result, true); +} + +/** + * @tc.name: AppendWriteFileToFile001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileToFile001, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get input stream object" + std::string inputFile = "./utils/unsigned-linuxxx.out"; + std::string outputFile = "./utils/signed-linux.out"; + bool result = FileUtils::AppendWriteFileToFile(inputFile, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: AppendWriteFileToFile002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileToFile002, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get output stream object" + std::string inputFile = "./utils/unsigned-linux.out"; + std::string outputFile = "./utilsxxx/signed-linux.out"; + bool result = FileUtils::AppendWriteFileToFile(inputFile, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: AppendWriteFileToFile003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteFileToFile003, testing::ext::TestSize.Level1) +{ + // go to all branch + std::string inputFile = "./utils/unsigned-linux.out"; + std::string outputFile = "./utilsxxx/signed-linux.out"; + bool result = FileUtils::AppendWriteFileToFile(inputFile, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: AppendWriteByteToFile + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, AppendWriteByteToFile, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to write data to output stream" + std::string bytes; + std::string outputFile = "./utilsxxx/signed-linux.out"; + bool result = FileUtils::AppendWriteByteToFile(bytes, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: WriteInputToOutPut001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteInputToOutPut001, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get input stream object" + std::string inputFile = "./utils/unsigned-linuxxx.out"; + std::string outputFile = "./utils/signed-linux.out"; + bool result = FileUtils::WriteInputToOutPut(inputFile, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: WriteInputToOutPut002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteInputToOutPut002, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get output stream object" + std::string inputFile = "./utils/unsigned-linux.out"; + std::string outputFile = "./utilsxxx/signed-linux.out"; + bool result = FileUtils::WriteInputToOutPut(inputFile, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: WriteInputToOutPut003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteInputToOutPut003, testing::ext::TestSize.Level1) +{ + // go to all branch + std::string inputFile = "./utils/unsigned-linux.out"; + std::string outputFile = "./utils/signed-linux.out"; + bool result = FileUtils::WriteInputToOutPut(inputFile, outputFile); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: WriteByteToOutFile003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteByteToOutFile003, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get output stream object" + std::string bytes; + std::ofstream output("./utilsxxx/signed-linux.out", std::ios::binary); + bool result = FileUtils::WriteByteToOutFile(bytes, output); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: WriteByteToOutFile004 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteByteToOutFile004, testing::ext::TestSize.Level1) +{ + // go to branch "Failed to get output stream object" + std::vector bytes; + std::ofstream output("./utilsxxx/signed-linux.out", std::ios::binary); + bool result = FileUtils::WriteByteToOutFile(bytes, output); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: WriteByteToOutFile005 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteByteToOutFile005, testing::ext::TestSize.Level1) +{ + // go to all branch + std::vector bytes; + std::ofstream output("./utils/signed-linux.out", std::ios::binary); + bool result = FileUtils::WriteByteToOutFile(bytes, output); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: IsRunnableFile001 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, IsRunnableFile001, testing::ext::TestSize.Level1) +{ + // go to branch "name.empty()" + std::string fileName; + bool result = FileUtils::IsRunnableFile(fileName); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: IsRunnableFile002 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, IsRunnableFile002, testing::ext::TestSize.Level1) +{ + // go to branch ".an" + std::string fileName = "test.an"; + bool result = FileUtils::IsRunnableFile(fileName); + EXPECT_EQ(result, true); +} + +/** + * @tc.name: IsRunnableFile003 + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, IsRunnableFile003, testing::ext::TestSize.Level1) +{ + // go to branch ".so" + std::string fileName = "test.so"; + bool result = FileUtils::IsRunnableFile(fileName); + EXPECT_NE(result, -1); +} + +/** + * @tc.name: DelDir + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, DelDir, testing::ext::TestSize.Level1) +{ + std::string fileName = "./utils/testdeldir"; + FileUtils::DelDir(fileName); + + // create dir and file again + std::filesystem::path dir_path(fileName); + std::filesystem::create_directories(dir_path); + + std::filesystem::path file_path = dir_path / "example.txt"; + std::ofstream file(file_path); + EXPECT_EQ(true, 1); +} + +/** + * @tc.name: WriteInputToOutPut + * @tc.desc: Test function interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ +HWTEST_F(FileUtilsTest, WriteInputToOutPutTest001, testing::ext::TestSize.Level1) +{ + CreateTestFile(); + + std::vector threads; + + for (int i = 1; i <= THREAD_NUMS; ++i) { + std::string inputFile = "tmp/tmp-" + std::to_string(i) + ".txt"; + std::string outputFile = "tmp/tmp-" + std::to_string(i) + "-copy.txt"; + auto length = std::filesystem::file_size(inputFile); + + threads.emplace_back(Worker, inputFile, outputFile, length); + } + + for (auto& thread : threads) { + thread.join(); + } + + printf("All threads completed.\n"); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/zip/packets/cd_only_v1.txt b/hapsigntool_cpp/test/unittest/zip/packets/cd_only_v1.txt new file mode 100644 index 0000000000000000000000000000000000000000..a8568b71652ed494bd1f96e77024bbfba3af4f3f Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/cd_only_v1.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/cd_only_v2.txt b/hapsigntool_cpp/test/unittest/zip/packets/cd_only_v2.txt new file mode 100644 index 0000000000000000000000000000000000000000..dcbf10c48a19518c4e10efcd464afb1197b580ed Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/cd_only_v2.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/data_descriptor_hap.txt b/hapsigntool_cpp/test/unittest/zip/packets/data_descriptor_hap.txt new file mode 100644 index 0000000000000000000000000000000000000000..ded3f02c25ab2083d7fb92d50c46c9d616ce347c Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/data_descriptor_hap.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/raw.txt b/hapsigntool_cpp/test/unittest/zip/packets/raw.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f2aefe5aab434337439e188d136a2f272378327 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/raw.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/whole.txt b/hapsigntool_cpp/test/unittest/zip/packets/whole.txt new file mode 100644 index 0000000000000000000000000000000000000000..8708accf5ecf14a87edde514e4433ba6d0cfe974 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/whole.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v1.txt b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v1.txt new file mode 100644 index 0000000000000000000000000000000000000000..fcf4334a25fff3bdfd86a86040e9288371a71e63 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v1.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v2.txt b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v2.txt new file mode 100644 index 0000000000000000000000000000000000000000..d79cb2989bfbd49be0d65f7a1cefc48d8fbc9bbb Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v2.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v3.txt b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v3.txt new file mode 100644 index 0000000000000000000000000000000000000000..e3b3d65c646a5bb69e096e37f897c7ed48c8a9e9 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v3.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v4.txt b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v4.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd496f7a5472cc053c51946ca16e23a9a38c359c Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/zip_entries_wrong_v4.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/packets/zip_entry_data_wrong.txt b/hapsigntool_cpp/test/unittest/zip/packets/zip_entry_data_wrong.txt new file mode 100644 index 0000000000000000000000000000000000000000..3784770ccea7d088884abeb743734cd2dfd53340 Binary files /dev/null and b/hapsigntool_cpp/test/unittest/zip/packets/zip_entry_data_wrong.txt differ diff --git a/hapsigntool_cpp/test/unittest/zip/random_access_file_input_output_test.cpp b/hapsigntool_cpp/test/unittest/zip/random_access_file_input_output_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da24617650df9cd74bd7410c98808bc1e31cd51e --- /dev/null +++ b/hapsigntool_cpp/test/unittest/zip/random_access_file_input_output_test.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "data_source.h" +#include "hap_signer_block_utils.h" +#include "random_access_file.h" +#include "random_access_file_input.h" +#include "random_access_file_output.h" + +namespace OHOS { +namespace SignatureTools { +const std::string RAW_HAP_PATH = "./zip/raw.hap"; +const std::string WHOLE_HAP_PATH = "./zip/whole.hap"; +class RandomAccessFileInputOutputTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void RandomAccessFileInputOutputTest::SetUpTestCase(void) +{ + (void)rename("./zip/raw.txt", RAW_HAP_PATH.c_str()); + (void)rename("./zip/whole.txt", WHOLE_HAP_PATH.c_str()); + sync(); +} + +void RandomAccessFileInputOutputTest::TearDownTestCase(void) +{ +} + +void RandomAccessFileInputOutputTest::SetUp() +{ +} + +void RandomAccessFileInputOutputTest::TearDown() +{ +} + +/** + * @tc.name: Test Init Function + * @tc.desc: Test function of RandomAccessFile::Init() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, InitTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + bool res = outputHap->Init(RAW_HAP_PATH); + EXPECT_EQ(res, true); +} + +/** + * @tc.name: Test Init Function + * @tc.desc: Test function of RandomAccessFile::Init() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, InitTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + bool res = outputHap->Init(""); + EXPECT_EQ(res, false); +} + +/** + * @tc.name: Test WriteToFile Function + * @tc.desc: Test function of RandomAccessFile::WriteToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, WriteToFileTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + bool res = outputHap->Init(RAW_HAP_PATH); + EXPECT_EQ(res, true); + ByteBuffer buffer(1); + buffer.PutByte(1); + EXPECT_EQ(outputHap->WriteToFile(buffer, 0, 1) > 0, true); +} + +/** + * @tc.name: Test WriteToFile Function + * @tc.desc: Test function of RandomAccessFile::WriteToFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, WriteToFileTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + bool res = outputHap->Init(RAW_HAP_PATH); + EXPECT_EQ(res, true); + ByteBuffer buffer; + EXPECT_EQ(outputHap->WriteToFile(buffer, 0, 0), -1); +} + +/** + * @tc.name: Test WriteToFile Function + * @tc.desc: Test function of RandomAccessFile::WriteToFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, WriteToFileTest003, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + bool res = outputHap->Init(RAW_HAP_PATH); + EXPECT_EQ(res, true); + ByteBuffer buffer(1); + buffer.PutByte(1); + EXPECT_EQ(outputHap->WriteToFile(buffer, -1, 0), READ_OFFSET_OUT_OF_RANGE); +} + +/** + * @tc.name: Test ReadFileFullyFromOffset Function + * @tc.desc: Test function of RandomAccessFile::ReadFileFullyFromOffset() interface for success + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, ReadFileFullyFromOffsetTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + ASSERT_TRUE(outputHap->Init(RAW_HAP_PATH)); + std::string buf(1, 0); + EXPECT_GT(outputHap->ReadFileFullyFromOffset(buf.data(), 0, 1), 0); +} + +/** + * @tc.name: Test RandomAccessFileInput Function + * @tc.desc: Test function of RandomAccessFileInput::RandomAccessFileInput() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(WHOLE_HAP_PATH), true); + std::shared_ptr outputHapIn = std::make_shared(*outputHap, 1, 1); + EXPECT_EQ(outputHapIn != nullptr, true); +} + +/** + * @tc.name: Test RandomAccessFileInput Function + * @tc.desc: Test function of RandomAccessFileInput::RandomAccessFileInput() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(WHOLE_HAP_PATH), true); + std::shared_ptr outputHapIn = std::make_shared(*outputHap, 1, -1); + EXPECT_EQ(outputHapIn != nullptr, true); +} + +/** + * @tc.name: Test RandomAccessFileInput Function + * @tc.desc: Test function of RandomAccessFileInput::RandomAccessFileInput() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputTest003, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(WHOLE_HAP_PATH), true); + std::shared_ptr outputHapIn = std::make_shared(*outputHap, -1, 1); + EXPECT_EQ(outputHapIn != nullptr, true); +} + +/** + * @tc.name: Test Slice Function + * @tc.desc: Test function of RandomAccessFileInput::Slice() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputSliceTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(WHOLE_HAP_PATH), true); + std::shared_ptr outputHapIn = std::make_shared(*outputHap); + std::pair eocdPair; + EXPECT_EQ(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair), true); + int64_t centralDirectoryOffset; + EXPECT_EQ(HapSignerBlockUtils::GetCentralDirectoryOffset(eocdPair.first, eocdPair.second, centralDirectoryOffset), + true); + DataSource* beforeCentralDir = outputHapIn->Slice(0, centralDirectoryOffset); + EXPECT_EQ(beforeCentralDir != nullptr, true); +} + +/** + * @tc.name: Test Slice Function + * @tc.desc: Test function of RandomAccessFileInput::Slice() interface + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputSliceTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + ASSERT_TRUE(outputHap->Init(WHOLE_HAP_PATH)); + auto outputHapIn1 = std::make_shared(*outputHap, 0, 10); + // step1: make the offset is less than 0 + ASSERT_EQ(outputHapIn1->Slice(-1, 10), nullptr); + + auto outputHapIn2 = std::make_shared(*outputHap, 0, 10); + // step2: make the size is less than 0 + ASSERT_EQ(outputHapIn2->Slice(0, -1), nullptr); + + auto outputHapIn3 = std::make_shared(*outputHap, 0, 10); + // step3: make the offset is greater than RandomAccessFile's length + ASSERT_EQ(outputHapIn3->Slice(20, 1), nullptr); + + auto outputHapIn4 = std::make_shared(*outputHap, 0, 10); + // step4: make the offset plus the size is greater than RandomAccessFile's length + ASSERT_EQ(outputHapIn4->Slice(0, 20), nullptr); + + auto outputHapIn5 = std::make_shared(*outputHap, 0, 10); + // step5: make the offset is zero and the offset is RandomAccessFile's length + ASSERT_NE(outputHapIn5->Slice(0, 10), nullptr); + + auto outputHapIn6 = std::make_shared(*outputHap, 0, 10); + // step6: make the offset plus the offset is overflow + ASSERT_NE(outputHapIn6->Slice(1, LLONG_MAX), nullptr); + + auto outputHapIn7 = std::make_shared(*outputHap, 0, 10); + // step7: make the offset is not equal to zero and the offset is not equal to RandomAccessFile's length + ASSERT_NE(outputHapIn7->Slice(1, 5), nullptr); +} + +/** + * @tc.name: Test CreateByteBuffer Function + * @tc.desc: Test function of RandomAccessFileInput::CreateByteBuffer() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputCreateByteBufferTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(WHOLE_HAP_PATH), true); + std::shared_ptr outputHapIn = std::make_shared(*outputHap); + std::pair eocdPair; + EXPECT_EQ(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair), true); + int64_t centralDirectoryOffset; + EXPECT_EQ(HapSignerBlockUtils::GetCentralDirectoryOffset(eocdPair.first, eocdPair.second, centralDirectoryOffset), + true); + DataSource* beforeCentralDir = outputHapIn->Slice(0, centralDirectoryOffset); + EXPECT_EQ(beforeCentralDir != nullptr, true); + long centralDirectorySize; + EXPECT_EQ(HapSignerBlockUtils::GetCentralDirectorySize(eocdPair.first, centralDirectorySize), true); + ByteBuffer centralDirBuffer = outputHapIn->CreateByteBuffer(centralDirectoryOffset, centralDirectorySize); + EXPECT_EQ(centralDirBuffer.GetCapacity() > 0, true); +} + +/** + * @tc.name: Test CreateByteBuffer Function + * @tc.desc: Test function of RandomAccessFileInput::CreateByteBuffer() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileInputCreateByteBufferTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + ASSERT_TRUE(outputHap->Init(WHOLE_HAP_PATH)); + std::shared_ptr outputHapIn = std::make_shared(*outputHap); + std::pair eocdPair; + ASSERT_TRUE(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair)); + ByteBuffer centralDirBuffer1 = outputHapIn->CreateByteBuffer(-1, 1); + ASSERT_EQ(centralDirBuffer1.GetCapacity(), 0); + + ByteBuffer centralDirBuffer2 = outputHapIn->CreateByteBuffer(1, 0); + ASSERT_EQ(centralDirBuffer2.GetCapacity(), 0); +} + +/** + * @tc.name: Test Write ByteBuffer Function + * @tc.desc: Test function of RandomAccessFileOutput::Write() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileOutputWriteTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(RAW_HAP_PATH), true); + std::pair eocdPair; + EXPECT_EQ(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair), true); + int64_t centralDirectoryOffset; + EXPECT_EQ(HapSignerBlockUtils::GetCentralDirectoryOffset(eocdPair.first, eocdPair.second, centralDirectoryOffset), + true); + std::shared_ptr outputHapOut = + std::make_shared(outputHap.get(), centralDirectoryOffset); + ByteBuffer signingBlock(1); + signingBlock.PutByte(1); + EXPECT_EQ(outputHapOut->Write(signingBlock), true); +} + +/** + * @tc.name: Test Write ByteBuffer Function + * @tc.desc: Test function of RandomAccessFileOutput::Write() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileOutputWriteTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(RAW_HAP_PATH), true); + std::pair eocdPair; + EXPECT_EQ(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair), true); + int64_t centralDirectoryOffset; + EXPECT_EQ(HapSignerBlockUtils::GetCentralDirectoryOffset(eocdPair.first, eocdPair.second, centralDirectoryOffset), + true); + std::shared_ptr outputHapOut = + std::make_shared(outputHap.get(), centralDirectoryOffset); + ByteBuffer signingBlock; + EXPECT_EQ(outputHapOut->Write(signingBlock), false); +} + +/** + * @tc.name: Test Write ByteBuffer Function + * @tc.desc: Test function of RandomAccessFileOutput() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileOutputTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(RAW_HAP_PATH), true); + std::shared_ptr outputHapOut = + std::make_shared(outputHap.get()); + EXPECT_EQ(outputHapOut != nullptr, true); +} + +/** + * @tc.name: Test Write ByteBuffer Function + * @tc.desc: Test function of RandomAccessFileOutput() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(RandomAccessFileInputOutputTest, RandomAccessFileOutputTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(RAW_HAP_PATH), true); + std::shared_ptr outputHapOut = + std::make_shared(outputHap.get(), -1); + EXPECT_EQ(outputHapOut != nullptr, true); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file diff --git a/hapsigntool_cpp/test/unittest/zip/zip_signer_test.cpp b/hapsigntool_cpp/test/unittest/zip/zip_signer_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5fdd4a6e27fae5897825f5287a95918e3d58fa5 --- /dev/null +++ b/hapsigntool_cpp/test/unittest/zip/zip_signer_test.cpp @@ -0,0 +1,801 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "file_utils.h" +#include "hap_signer_block_utils.h" +#include "zip_entry.h" +#include "zip_signer.h" +#include "zip_utils.h" + +namespace OHOS { +namespace SignatureTools { +const std::string RAW_HAP_PATH = "./zip/raw.hap"; +const std::string WHOLE_HAP_PATH = "./zip/whole.hap"; +const std::string EMPTY_HAP_PATH = "./zip/empty.hap"; +const std::string DATA_DESCRIPTOR_HAP_PATH = "./zip/data_descriptor_hap.hap"; +const std::string EOCD_ONLY_HAP_PATH = "./zip/eocd_only.hap"; +const std::string DUMMY_HAP_PATH = "./zip/dummy.hap"; +const std::string ZIP_ENTRIES_WRONG_HAP_V1_PATH = "./zip/zip_entries_wrong_v1.hap"; +const std::string ZIP_ENTRIES_WRONG_HAP_V2_PATH = "./zip/zip_entries_wrong_v2.hap"; +const std::string ZIP_ENTRIES_WRONG_HAP_V3_PATH = "./zip/zip_entries_wrong_v3.hap"; +const std::string ZIP_ENTRIES_WRONG_HAP_V4_PATH = "./zip/zip_entries_wrong_v4.hap"; +const std::string ZIP_ENTRY_DATA_WRONG_HAP_PATH = "./zip/zip_entry_data_wrong.hap"; +const std::string CD_ONLY_HAP_V1_PATH = "./zip/cd_only_v1.hap"; +const std::string CD_ONLY_HAP_V2_PATH = "./zip/cd_only_v2.hap"; +const std::string OUTPUT_WHOLE_HAP_PATH = "./zip/output_whole.hap"; +const std::string ZERO_HAP_PATH = "./zip/zero.hap"; +const static int ALIGNMENT = 4; +class ZipSignerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ZipSignerTest::SetUpTestCase(void) +{ + (void)rename("./zip/cd_only_v1.txt", CD_ONLY_HAP_V1_PATH.c_str()); + (void)rename("./zip/cd_only_v2.txt", CD_ONLY_HAP_V2_PATH.c_str()); + (void)rename("./zip/data_descriptor_hap.txt", DATA_DESCRIPTOR_HAP_PATH.c_str()); + (void)rename("./zip/raw.txt", RAW_HAP_PATH.c_str()); + (void)rename("./zip/whole.txt", WHOLE_HAP_PATH.c_str()); + (void)rename("./zip/zip_entries_wrong_v1.txt", ZIP_ENTRIES_WRONG_HAP_V1_PATH.c_str()); + (void)rename("./zip/zip_entries_wrong_v2.txt", ZIP_ENTRIES_WRONG_HAP_V2_PATH.c_str()); + (void)rename("./zip/zip_entries_wrong_v3.txt", ZIP_ENTRIES_WRONG_HAP_V3_PATH.c_str()); + (void)rename("./zip/zip_entries_wrong_v4.txt", ZIP_ENTRIES_WRONG_HAP_V4_PATH.c_str()); + (void)rename("./zip/zip_entry_data_wrong.txt", ZIP_ENTRY_DATA_WRONG_HAP_PATH.c_str()); + sync(); +} + +void ZipSignerTest::TearDownTestCase(void) +{ +} + +void ZipSignerTest::SetUp() +{ +} + +void ZipSignerTest::TearDown() +{ +} + +/** + * @tc.name: Test ZipSigner Full process + * @tc.desc: Test function of ZipSigner interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, FullProcessTest001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step0. test ZipSigner full process function + * @tc.expected: step0. the return will be true. + */ + std::ifstream rawInput(RAW_HAP_PATH, std::ios::binary); + std::ofstream rawOutput(OUTPUT_WHOLE_HAP_PATH, std::ios::binary | std::ios::trunc | std::ios::out); + auto zip0 = std::make_shared(); + ASSERT_TRUE(zip0->Init(rawInput)); + zip0->Alignment(ALIGNMENT); + zip0->RemoveSignBlock(); + ASSERT_TRUE(zip0->ToFile(rawInput, rawOutput)); + rawOutput.close(); + rawInput.close(); + + /* + * @tc.steps: step1. test ZipSigner full process function + * @tc.expected: step1. the return will be true. + */ + std::ifstream wholeInput(WHOLE_HAP_PATH, std::ios::binary); + std::ofstream wholeOutput(OUTPUT_WHOLE_HAP_PATH, std::ios::binary | std::ios::trunc | std::ios::out); + auto zip1 = std::make_shared(); + ASSERT_TRUE(zip1->Init(wholeInput)); + zip1->Alignment(ALIGNMENT); + zip1->RemoveSignBlock(); + ASSERT_TRUE(zip1->ToFile(wholeInput, wholeOutput)); + wholeOutput.close(); + wholeInput.close(); + + /* + * @tc.steps: step2. test ZipSigner full process function + * @tc.expected: step2. the return will be true. + */ + std::ifstream dataDescInput(DATA_DESCRIPTOR_HAP_PATH, std::ios::binary); + std::ofstream dataDescOutput(OUTPUT_WHOLE_HAP_PATH, std::ios::binary | std::ios::trunc | std::ios::out); + auto zip2 = std::make_shared(); + ASSERT_TRUE(zip2->Init(dataDescInput)); + zip2->Alignment(ALIGNMENT); + zip2->RemoveSignBlock(); + ASSERT_TRUE(zip2->ToFile(dataDescInput, dataDescOutput)); + dataDescOutput.close(); + dataDescInput.close(); +} + +/** + * @tc.name: Test ZipSigner Init Function + * @tc.desc: Test function of ZipSigner interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipSignerInitTest001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. test Init function + * @tc.expected: step1. make the zip original file is dummy, the return will be false. + */ + auto zip1 = std::make_shared(); + std::ifstream dummyInput(DUMMY_HAP_PATH, std::ios::binary); + ASSERT_FALSE(zip1->Init(dummyInput)); + /* + * @tc.steps: step2. test Init function + * @tc.expected: step2. make the zip original file is empty, the return will be false. + */ + std::ofstream emptyOuptut(EMPTY_HAP_PATH, std::ios::binary | std::ios::trunc | std::ios::out); + emptyOuptut << ""; + emptyOuptut.close(); + auto zip2 = std::make_shared(); + std::ifstream emptyInput(EMPTY_HAP_PATH, std::ios::binary); + ASSERT_FALSE(zip2->Init(emptyInput)); + emptyInput.close(); + + /* + * @tc.steps: step3. test Init function + * @tc.expected: step3. make the zip original file is ONLY have eocd block, the return will be false. + */ + std::ofstream eocdOutput(EOCD_ONLY_HAP_PATH, std::ios::binary | std::ios::trunc | std::ios::out); + char eocd[] = {0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x46, 0x02, 0x00, 0x00, 0x00, 0x00}; + eocdOutput.write(eocd, sizeof(eocd) / sizeof(eocd[0])); + eocdOutput.close(); + auto zip3 = std::make_shared(); + std::ifstream eocdInput(EOCD_ONLY_HAP_PATH, std::ios::binary); + ASSERT_FALSE(zip3->Init(eocdInput)); + eocdInput.close(); +} + +/** + * @tc.name: Test GetZipEntries Function + * @tc.desc: Test function of ZipSigner::GetZipEntries() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetZipEntriesTest001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. test GetZipEntries function + * @tc.expected: step1. make the cd offset int front of entry end, return will be false. + */ + std::ifstream inputFile(ZIP_ENTRIES_WRONG_HAP_V3_PATH, std::ios::binary); + auto zip = std::make_shared(); + ASSERT_FALSE(zip->Init(inputFile)); +} + +/** + * @tc.name: Test Alignment Function + * @tc.desc: Test function of ZipEntry::Alignment() interface. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, AlignmentTest001, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. test Alignment function + * @tc.expected: step1. make the alignment is equal to 0, return will be equal to -1. + */ + std::ifstream inputFile(WHOLE_HAP_PATH, std::ios::binary); + auto zip1 = std::make_shared(); + ASSERT_TRUE(zip1->Init(inputFile)); + auto zipEntries1 = zip1->GetZipEntries(); + int zeroAlignment = 0; + for (const auto& zipEntry : zipEntries1) { + ASSERT_EQ(zipEntry->Alignment(zeroAlignment), -1); + } + + /* + * @tc.steps: step2. test Alignment function + * @tc.expected: step2. make the alignment is equal to 4, return will be equal to 0. + */ + auto zip2 = std::make_shared(); + ASSERT_TRUE(zip2->Init(inputFile)); + auto zipEntries2 = zip2->GetZipEntries(); + for (const auto& zipEntry : zipEntries2) { + ASSERT_EQ(zipEntry->Alignment(ALIGNMENT), 0); + } + + /* + * @tc.steps: step3. test Alignment function + * @tc.expected: step3. make the alignment is equal to 4, return will be equal to 1. + */ + std::ifstream zipEntriesInput(ZIP_ENTRIES_WRONG_HAP_V4_PATH, std::ios::binary); + auto zip3 = std::make_shared(); + ASSERT_TRUE(zip3->Init(zipEntriesInput)); + auto zipEntries3 = zip3->GetZipEntries(); + for (const auto& zipEntry : zipEntries3) { + ASSERT_EQ(zipEntry->Alignment(ALIGNMENT), 1); + } + + zipEntriesInput.close(); + inputFile.close(); +} + +/** + * @tc.name: Test GetCDOffset Function + * @tc.desc: Test function of ZipSigner::GetCDOffset() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetCDOffsetTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool res = zip->Init(inputFile); + uint64_t cdOffset = zip->GetCDOffset(); + EXPECT_EQ(res && cdOffset != 0, true); +} + +/** + * @tc.name: Test GetEOCDOffset Function + * @tc.desc: Test function of ZipSigner::GetEOCDOffset() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetEOCDOffsetTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool res = zip->Init(inputFile); + uint64_t eocdOffset = zip->GetEOCDOffset(); + EXPECT_EQ(res && eocdOffset != 0, true); +} + +/** + * @tc.name: Test ToFile Function + * @tc.desc: Test function of ZipSigner::ToFile() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ToFileTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::ofstream outputFile(OUTPUT_WHOLE_HAP_PATH, std::ios::binary | std::ios::trunc); + std::shared_ptr zip = std::make_shared(); + bool initRes = zip->Init(inputFile); + bool toFileRes = zip->ToFile(inputFile, outputFile); + EXPECT_EQ(initRes && toFileRes, true); +} + +/** + * @tc.name: Test ToFile Function + * @tc.desc: Test function of ZipSigner::ToFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ToFileTest002, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::ofstream outputFile("", std::ios::binary | std::ios::trunc); + std::shared_ptr zip = std::make_shared(); + bool initRes = zip->Init(inputFile); + bool toFileRes = zip->ToFile(inputFile, outputFile); + EXPECT_EQ(initRes && !toFileRes, true); +} + +/** + * @tc.name: Test ToFile Function + * @tc.desc: Test function of ZipSigner::ToFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ToFileTest003, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::ofstream outputFile("", std::ios::binary | std::ios::trunc); + std::shared_ptr zip = std::make_shared(); + bool initRes = zip->Init(inputFile); + + std::ifstream bad("", std::ios::binary); + + bool toFileRes = zip->ToFile(bad, outputFile); + EXPECT_EQ(initRes && !toFileRes, true); +} + +/** + * @tc.name: Test ToFile Function + * @tc.desc: Test function of ZipSigner::ToFile() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ToFileTest004, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::ofstream outputFile(OUTPUT_WHOLE_HAP_PATH, std::ios::binary | std::ios::trunc); + std::shared_ptr zip = std::make_shared(); + ASSERT_TRUE(zip->Init(inputFile)); + ASSERT_TRUE(zip->ToFile(inputFile, outputFile)); +} + +/* + * @tc.name: Alignment_Test_001 + * @tc.desc: Test function of ZipEntry::Alignment() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipEntryAlignmentTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool res = zip->Init(inputFile); + std::vector zipEntries = zip->GetZipEntries(); + int alignment = 4; + for (auto& zipEntry : zipEntries) { + int add = zipEntry->Alignment(alignment); + EXPECT_EQ(res && add > 0, true); + } +} + +/** + * @tc.name: Test GetEOCDByBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::GetEOCDByBytes() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryGetEOCDByBytesTest001, testing::ext::TestSize.Level1) +{ + std::ifstream input(RAW_HAP_PATH, std::ios::binary); + input.seekg(0, std::ios::end); + uint64_t fileSize = input.tellg(); + input.seekg(0, std::ios::beg); + + int eocdLength = EndOfCentralDirectory::EOCD_LENGTH; + uint64_t eocdOffset = (uint64_t)(fileSize - eocdLength); + + std::string retStr; + int res = FileUtils::ReadFileByOffsetAndLength(input, eocdOffset, eocdLength, retStr); + std::optional eocdByBytes = EndOfCentralDirectory::GetEOCDByBytes(retStr); + EXPECT_EQ(res == 0 && eocdByBytes != std::nullopt, true); +} + +/** + * @tc.name: Test GetEOCDByBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::GetEOCDByBytes() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryGetEOCDByBytesTest002, testing::ext::TestSize.Level1) +{ + std::string str; + std::optional eocdByBytes = EndOfCentralDirectory::GetEOCDByBytes(str); + EXPECT_EQ(eocdByBytes == std::nullopt, true); +} + +/** + * @tc.name: Test GetEOCDByBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::GetEOCDByBytes() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryGetEOCDByBytesTest003, testing::ext::TestSize.Level1) +{ + std::string bytes(22, 0); + std::optional eocdByBytes = EndOfCentralDirectory::GetEOCDByBytes(bytes); + EXPECT_EQ(eocdByBytes == std::nullopt, true); +} + +/** + * @tc.name: Test GetEOCDByBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::GetEOCDByBytes() interface for FAIL with eocd length is wrong + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryGetEOCDByBytesTest004, testing::ext::TestSize.Level1) +{ + std::string bytes{ + 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + std::optional eocdByBytes = EndOfCentralDirectory::GetEOCDByBytes(bytes); + EXPECT_EQ(eocdByBytes == std::nullopt, true); +} + +/** + * @tc.name: Test GetEOCDByBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::GetEOCDByBytes() interface for SUCCESS with comment. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryGetEOCDByBytesTest005, testing::ext::TestSize.Level1) +{ + std::string bytes{ + 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 + }; + std::optional eocdByBytes = EndOfCentralDirectory::GetEOCDByBytes(bytes); + EXPECT_EQ(eocdByBytes != std::nullopt, true); + std::string eocdBytes = eocdByBytes.value()->ToBytes(); + EXPECT_EQ(eocdBytes.size() > 0, true); +} + +/** + * @tc.name: Test GetEOCDByBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::SetComment() interface. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectorySetCommentTest001, testing::ext::TestSize.Level1) +{ + std::string bytes{ + 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + std::optional eocdByBytes = EndOfCentralDirectory::GetEOCDByBytes(bytes); + std::string comment{1}; + eocdByBytes.value()->SetComment(comment); + EXPECT_EQ(eocdByBytes != std::nullopt, true); +} + +/** + * @tc.name: Test ToBytes Function + * @tc.desc: Test function of EndOfCentralDirectory::ToBytes() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryToBytesTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool initRes = zip->Init(inputFile); + EndOfCentralDirectory* eocd = zip->GetEndOfCentralDirectory(); + std::string eocdBytes = eocd->ToBytes(); + int signature = eocd->GetSIGNATURE(); + int diskNum = eocd->GetDiskNum(); + std::string comment = eocd->GetComment(); + EXPECT_EQ(initRes && eocd && eocdBytes.size() > 0 && signature != -1 && comment.size() == 0 && diskNum != -1, + true); +} + +/** + * @tc.name: Test EndOfCentralDirectory Class + * @tc.desc: Test function of EndOfCentralDirectory interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, EndOfCentralDirectoryTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool initRes = zip->Init(inputFile); + EndOfCentralDirectory* eocd = zip->GetEndOfCentralDirectory(); + int eocdLength = eocd->GetEocdLength(); + int cdStartDiskNum = eocd->GetcDStartDiskNum(); + int diskCDNum = eocd->GetThisDiskCDNum(); + int eocdLen = eocd->GetLength(); + EXPECT_EQ(initRes && eocd && eocdLength > 0 && cdStartDiskNum != -1 && diskCDNum != -1 && eocdLen != -1, + true); +} + +/** + * @tc.name: Test SetCentralDirectoryOffset Function + * @tc.desc: Test function of ZipUtils::SetCentralDirectoryOffset() interface for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipUtilsSetCentralDirectoryOffsetTest001, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(RAW_HAP_PATH), true); + std::pair eocdPair; + EXPECT_EQ(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair), true); + int64_t centralDirectoryOffset; + EXPECT_EQ(HapSignerBlockUtils::GetCentralDirectoryOffset(eocdPair.first, eocdPair.second, + centralDirectoryOffset), + true); + int64_t newCentralDirOffset = centralDirectoryOffset + 10; + eocdPair.first.SetPosition(0); + EXPECT_EQ(ZipUtils::SetCentralDirectoryOffset(eocdPair.first, newCentralDirOffset), true); +} + +/** + * @tc.name: Test SetCentralDirectoryOffset Function + * @tc.desc: Test function of ZipUtils::SetCentralDirectoryOffset() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipUtilsSetCentralDirectoryOffsetTest002, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + EXPECT_EQ(outputHap->Init(RAW_HAP_PATH), true); + std::pair eocdPair; + EXPECT_EQ(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair), true); + eocdPair.first.SetPosition(0); + EXPECT_EQ(ZipUtils::SetCentralDirectoryOffset(eocdPair.first, -1), false); +} + +/** + * @tc.name: Test SetCentralDirectoryOffset Function + * @tc.desc: Test function of ZipUtils::SetCentralDirectoryOffset() interface for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipUtilsSetCentralDirectoryOffsetTest003, testing::ext::TestSize.Level1) +{ + std::shared_ptr outputHap = std::make_shared(); + ASSERT_TRUE(outputHap->Init(RAW_HAP_PATH)); + std::pair eocdPair; + ASSERT_TRUE(HapSignerBlockUtils::FindEocdInHap(*outputHap, eocdPair)); + eocdPair.first.SetPosition(0); + ASSERT_FALSE(ZipUtils::SetCentralDirectoryOffset(eocdPair.first, 0x100000000LL)); +} + +/** + * @tc.name: Test ZipEntryHeader Class + * @tc.desc: Test function of ZipEntryHeader for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipEntryHeaderTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + auto zip = std::make_shared(); + ASSERT_TRUE(zip->Init(inputFile)); + + auto zipEntries = zip->GetZipEntries(); + ASSERT_NE(zipEntries.size(), 0); + + for (const auto& zipEntry : zipEntries) { + auto zipEntryData = zipEntry->GetZipEntryData(); + ASSERT_NE(zipEntryData, nullptr); + + int crc32 = zipEntryData->GetZipEntryHeader()->GetCrc32(); + ASSERT_NE(crc32, -1); + short lastTime = zipEntryData->GetZipEntryHeader()->GetLastTime(); + ASSERT_NE(lastTime, -1); + short lastData = zipEntryData->GetZipEntryHeader()->GetLastDate(); + ASSERT_NE(lastData, -1); + int64_t compressedSize = zipEntryData->GetZipEntryHeader()->GetCompressedSize(); + ASSERT_NE(compressedSize, -1); + int64_t unCompressedSize = zipEntryData->GetZipEntryHeader()->GetUnCompressedSize(); + ASSERT_NE(unCompressedSize, -1); + int headerLength = zipEntryData->GetZipEntryHeader()->GetHeaderLength(); + ASSERT_NE(headerLength, -1); + int signature = zipEntryData->GetZipEntryHeader()->GetSIGNATURE(); + ASSERT_NE(signature, -1); + short version = zipEntryData->GetZipEntryHeader()->GetVersion(); + ASSERT_NE(version, -1); + zipEntryData->GetZipEntryHeader()->SetFileName(""); + } +} + +/** + * @tc.name: Test ZipEntryHeader Class + * @tc.desc: Test function ToBytes of ZipEntryHeader for fail. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipEntryHeaderTest002, testing::ext::TestSize.Level1) +{ + ZipEntryHeader zipEntryHeader; + zipEntryHeader.ReadFileName(""); + zipEntryHeader.ReadExtra(""); + std::string bytes = zipEntryHeader.ToBytes(); + ASSERT_EQ(bytes.size(), 0); +} + +/** + * @tc.name: Test DataDescriptor Class + * @tc.desc: Test function of DataDescriptor for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, DataDescriptorTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(DATA_DESCRIPTOR_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool zipRes = zip->Init(inputFile); + std::vector zipEntries = zip->GetZipEntries(); + EXPECT_EQ(zipRes && zipEntries.size() > 0, true); + for (const auto& zipEntry : zipEntries) { + ZipEntryData* zipEntryData = zipEntry->GetZipEntryData(); + DataDescriptor* dataDescriptor = zipEntryData->GetDataDescriptor(); + if (dataDescriptor) { + uint64_t compressedSize = dataDescriptor->GetCompressedSize(); + uint64_t unCompressedSize = dataDescriptor->GetUnCompressedSize(); + int crc32 = dataDescriptor->GetCrc32(); + int signature = dataDescriptor->GetSIGNATURE(); + int desLength = dataDescriptor->GetDesLength(); + EXPECT_EQ(zipEntryData != nullptr && dataDescriptor != nullptr && compressedSize != -1 && + unCompressedSize != -1 && crc32 != -1 && signature != -1 && desLength != -1, true); + } else { + EXPECT_EQ(dataDescriptor == nullptr, true); + } + } +} + +/** + * @tc.name: Test DataDescriptor Class + * @tc.desc: Test function of GetDataDescriptor for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetDataDescriptorTest001, testing::ext::TestSize.Level1) +{ + std::string bytes1{1}; + ASSERT_EQ(DataDescriptor::GetDataDescriptor(bytes1), nullptr); + + std::string bytes2(16, 0); + ASSERT_EQ(DataDescriptor::GetDataDescriptor(bytes2), nullptr); +} + +/** + * @tc.name: Test CentralDirectory Class + * @tc.desc: Test function of CentralDirectory for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, CentralDirectoryTest001, testing::ext::TestSize.Level1) +{ + std::ifstream inputFile(RAW_HAP_PATH, std::ios::binary); + std::shared_ptr zip = std::make_shared(); + bool zipRes = zip->Init(inputFile); + std::vector zipEntries = zip->GetZipEntries(); + EXPECT_EQ(zipRes && zipEntries.size() > 0, true); + CentralDirectory* cd = zipEntries[0]->GetCentralDirectory(); + int cdLength = cd->GetCdLength(); + int signature = cd->GetSIGNATURE(); + short flag = cd->GetFlag(); + short lastTime = cd->GetLastTime(); + short lastDate = cd->GetLastDate(); + int crc32 = cd->GetCrc32(); + std::string fileName = cd->GetFileName(); + short version = cd->GetVersion(); + short versionExtra = cd->GetVersionExtra(); + int diskNumStart = cd->GetDiskNumStart(); + short internalFile = cd->GetInternalFile(); + int externalFile = cd->GetExternalFile(); + std::string comment = cd->GetComment(); + EXPECT_EQ(cd != nullptr && cdLength != -1 && signature != -1 && flag != -1 && lastTime != -1 && lastDate != -1 && + crc32 != -1 && fileName.size() > 0 && version != -1 && versionExtra != -1 && diskNumStart != -1 && + internalFile != -1 && externalFile != -1 && comment.size() == 0, true); +} + +/** + * @tc.name: Test CentralDirectory Class + * @tc.desc: Test function of CentralDirectory for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, CentralDirectoryTest002, testing::ext::TestSize.Level1) +{ + ByteBuffer bf(1); + CentralDirectory* cd = new CentralDirectory(); + EXPECT_EQ(CentralDirectory::GetCentralDirectory(bf, cd), false); + delete cd; +} + +/** + * @tc.name: Test CentralDirectory Class + * @tc.desc: Test function of CentralDirectory for SUCCESS with comment. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, CentralDirectoryTest003, testing::ext::TestSize.Level1) +{ + std::string str; + EXPECT_EQ(FileUtils::ReadFile(CD_ONLY_HAP_V1_PATH, str) == 0, true); + ByteBuffer bf(str.c_str(), str.size()); + CentralDirectory* cd = new CentralDirectory(); + EXPECT_EQ(CentralDirectory::GetCentralDirectory(bf, cd), true); + std::string cdBytes = cd->ToBytes(); + EXPECT_EQ(cdBytes.size() > 0, true); +} + +/** + * @tc.name: Test CentralDirectory Class + * @tc.desc: Test function of CentralDirectory for SUCCESS without fileNameLength. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, CentralDirectoryTest004, testing::ext::TestSize.Level1) +{ + std::string str; + EXPECT_EQ(FileUtils::ReadFile(CD_ONLY_HAP_V2_PATH, str) == 0, true); + ByteBuffer bf(str.c_str(), str.size()); + CentralDirectory* cd = new CentralDirectory(); + EXPECT_EQ(CentralDirectory::GetCentralDirectory(bf, cd), true); + std::string cdBytes = cd->ToBytes(); + EXPECT_EQ(cdBytes.size() > 0, true); +} + +/** + * @tc.name: Test ZipEntryHeader Class + * @tc.desc: Test function of GetZipEntryHeader for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetZipEntryHeaderTest001, testing::ext::TestSize.Level1) +{ + std::string headBytes{1}; + ZipEntryHeader* entryHeader = ZipEntryHeader::GetZipEntryHeader(headBytes); + EXPECT_EQ(entryHeader == nullptr, true); + delete entryHeader; +} + +/** + * @tc.name: Test ZipEntryData Class + * @tc.desc: Test function of GetZipEntry for FAIL. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetZipEntryTest001, testing::ext::TestSize.Level1) +{ + std::ofstream zeroOutput(ZERO_HAP_PATH, std::ios::binary | std::ios::trunc | std::ios::out); + std::string zeros(1024, 0x00); + zeroOutput.write(zeros.c_str(), zeros.size()); + zeroOutput.close(); + + std::ifstream inputFile(ZERO_HAP_PATH, std::ios::binary); + ZipEntryData* zipEntryData = ZipEntryData::GetZipEntry(inputFile, 0, 1024); + EXPECT_EQ(zipEntryData == nullptr, true); +} + +/** + * @tc.name: Test ZipEntryData Class + * @tc.desc: Test function of GetZipEntry for success. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, GetZipEntryTest002, testing::ext::TestSize.Level1) +{ + /* + * @tc.steps: step1. test ZipEntryData::ReadEntryFileNameAndExtraByOffset function + * @tc.expected: step1. FileNameLength and ExtraLength is zero + */ + std::ifstream inputFile(ZIP_ENTRY_DATA_WRONG_HAP_PATH, std::ios::binary); + ZipEntryData* zipEntryData = ZipEntryData::GetZipEntry(inputFile, 0, 1024); + ASSERT_EQ(zipEntryData != nullptr, true); +} + +/** + * @tc.name: Test ZipSigner Class + * @tc.desc: Test ZipSigner interfaces for SUCCESS. + * @tc.type: FUNC + * @tc.require: SR000H63TL + */ +HWTEST_F(ZipSignerTest, ZipSignerTest001, testing::ext::TestSize.Level1) +{ + ZipSigner zip; + std::ifstream ifs(ZIP_ENTRIES_WRONG_HAP_V2_PATH, std::ios::binary); + ASSERT_TRUE(zip.Init(ifs)); + std::vector zipEntries{nullptr}; + zip.SetZipEntries(zipEntries); + zip.SetSigningOffset(1); + int64_t offset = zip.GetSigningOffset(); + EXPECT_EQ(offset, 1); + std::string signingBlock{0x1, 0x1, 0x1, 0x1, 0x1}; + zip.SetSigningBlock(signingBlock); + signingBlock = zip.GetSigningBlock(); + EXPECT_NE(signingBlock.size(), 0); + zip.SetCDOffset(1); + zip.SetEOCDOffset(1); + zip.SetEndOfCentralDirectory(nullptr); +} +} // namespace SignatureTools +} // namespace OHOS \ No newline at end of file