1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstddef>
17 #include <cstdint>
18 #include <cstdio>
19 #include <fstream>
20
21 #include "signature_algorithm_helper.h"
22 #include "verify_hap_openssl_utils.h"
23 #include "hash_utils.h"
24 #include "params.h"
25
26 namespace OHOS {
27 namespace SignatureTools {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)28 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
29 {
30 if (!data || !size) {
31 return true;
32 }
33
34 Params param;
35 std::string str(reinterpret_cast<const char*>(data), size);
36 std::string algName(reinterpret_cast<const char*>(data), size);
37 int algId = 256;
38 std::vector<std::string> paramFields;
39 std::vector<int8_t> fileBytes;
40 int64_t length = 0;
41 SignatureAlgorithmHelper out;
42 CertChain certsChain;
43 Pkcs7Context pkcs7Context;
44
45 param.SetMethod(str);
46 param.GetMethod();
47 param.GetOptions();
48 param.InitParamField(paramFields);
49 param.GetSignatureAlgorithm(str, out);
50 algName = HashUtils::GetHashAlgName(algId);
51 HashUtils::GetDigestFromBytes(fileBytes, length, algName);
52 VerifyCertOpensslUtils::VerifyCrl(certsChain, nullptr, pkcs7Context);
53 VerifyCertOpensslUtils::GetCrlBySignedCertIssuer(nullptr, nullptr);
54 VerifyCertOpensslUtils::GetIssuerFromX509(nullptr, str);
55
56 return true;
57 }
58 } // namespace SignatureTools
59 } // namespace OHOS
60
61 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
63 {
64 /* Run your code on data */
65 OHOS::SignatureTools::DoSomethingInterestingWithMyAPI(data, size);
66 return 0;
67 }