/* * 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 TestGenerateSubCert(const uint8_t* data, size_t size) { 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 = "./generateCA/OpenHarmony.p12"; char keystorePwd[] = "123456"; std::string signAlg = "SHA256withECDSA"; std::string subject = std::string(reinterpret_cast(data), size); 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); X509_REQ* csr = CertTools::GenerateCsr(keyPair, signAlg, subject); CertTools::GenerateSubCert(keyPair, csr, params.get()); return true; } bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { bool ret = false; 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-root-ca-key-v1"; std::string keystoreFile = "./generateCA/OpenHarmony.p12"; std::string signAlg = "SHA256withECDSA"; std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; std::string issuer(reinterpret_cast(data), size); bool keyUsage = true; std::string basicConstraints = "true"; std::string basicConstraintsCritical = "true"; std::string basicConstraintsCa = "true"; bool keyUsageCritical = true; char secret[] = "123456"; char isksPwd[] = "123456"; char keystorePwd[] = "123456"; char issuerkeypwd[] = "123456"; int validity = 365; std::string outfile = "./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; api->GenerateCert(params.get()); ret = api->OutputString("hello world", "./generateCA/tmp.data"); return ret; } } } /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::SignatureTools::TestGenerateSubCert(data, size); OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size); return 0; }