• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 #ifndef CM_FUZZ_TEST_COMMON_H
17 #define CM_FUZZ_TEST_COMMON_H
18 
19 #include "cert_manager_service_ipc_interface_code.h"
20 #include "cm_mem.h"
21 #include "cm_param.h"
22 #include "cm_type.h"
23 #include "securec.h"
24 
25 namespace CmFuzzTest {
26 
27 constexpr uint32_t CERT_INFO_LEN = sizeof(uint32_t) + MAX_LEN_CERTIFICATE + sizeof(uint32_t) +
28     MAX_LEN_CERT_ALIAS + sizeof(uint32_t);
29 
30 constexpr uint32_t CERT_LIST_LEN = sizeof(uint32_t) + (sizeof(uint32_t) + MAX_LEN_SUBJECT_NAME + sizeof(uint32_t) +
31     sizeof(uint32_t) + MAX_LEN_URI + sizeof(uint32_t) + MAX_LEN_CERT_ALIAS) * MAX_COUNT_CERTIFICATE;
32 
33 bool GetUintFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, uint32_t *outVal);
34 
35 bool GetCmBlobFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, struct CmBlob *outBlob);
36 
37 bool GetCertListFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, struct CertList *outList);
38 
39 bool GetCertInfoFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, struct CertInfo *outInfo);
40 
41 bool TenPercentChanceOfBeingTrue(uint8_t *srcData, uint32_t *remSize, uint32_t *offset);
42 
43 bool CopyMyData(const uint8_t *data, const size_t size, const uint32_t minSize, uint8_t **myData);
44 
45 bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize, uint32_t *offset,
46     CertManagerInterfaceCode code, struct CmParamSet **paramSetOut);
47 
48 bool IpcServiceApiFuzzerTest(const uint8_t *data, const size_t size, CertManagerInterfaceCode code,
49     bool isParamsetToBlob, void (*ipcServiceApi)(const struct CmBlob *, struct CmBlob *, const struct CmContext *));
50 } // namespace CmFuzzTest
51 #endif /* CM_FUZZ_TEST_COMMON_H */
52