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 void SetATPermission(void); 27 28 constexpr uint32_t CERT_INFO_LEN = sizeof(uint32_t) + MAX_LEN_CERTIFICATE + sizeof(uint32_t) + 29 MAX_LEN_CERT_ALIAS + sizeof(uint32_t); 30 31 constexpr uint32_t CERT_LIST_LEN = sizeof(uint32_t) + (sizeof(uint32_t) + MAX_LEN_SUBJECT_NAME + sizeof(uint32_t) + 32 sizeof(uint32_t) + MAX_LEN_URI + sizeof(uint32_t) + MAX_LEN_CERT_ALIAS) * MAX_COUNT_CERTIFICATE; 33 34 bool GetUintFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, uint32_t *outVal); 35 36 bool GetCmBlobFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, struct CmBlob *outBlob); 37 38 bool GetCertListFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, struct CertList *outList); 39 40 bool GetCertInfoFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset, struct CertInfo *outInfo); 41 42 bool TenPercentChanceOfBeingTrue(uint8_t *srcData, uint32_t *remSize, uint32_t *offset); 43 44 bool CopyMyData(const uint8_t *data, const size_t size, const uint32_t minSize, uint8_t **myData); 45 46 bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize, uint32_t *offset, 47 CertManagerInterfaceCode code, struct CmParamSet **paramSetOut); 48 49 bool IpcServiceApiFuzzerTest(const uint8_t *data, const size_t size, CertManagerInterfaceCode code, 50 bool isParamsetToBlob, void (*ipcServiceApi)(const struct CmBlob *, struct CmBlob *, const struct CmContext *)); 51 } // namespace CmFuzzTest 52 #endif /* CM_FUZZ_TEST_COMMON_H */ 53