sa模块code值标准化整改

Signed-off-by: zhao_zhen_zhou <zhaozhenzhou@huawei.com>
This commit is contained in:
zhao_zhen_zhou 2023-06-08 18:01:32 +08:00
parent c27889e9e8
commit ce1d18e576
24 changed files with 98 additions and 95 deletions

18
CODEOWNERS Normal file
View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2023 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.
*/
# any change to frameworks/cert_manager_standard/main/common/include/cert_manager_service_ipc_interface_code.h
# needs to be reviewed by @leonchan5
frameworks/cert_manager_standard/main/common/include/cert_manager_service_ipc_interface_code.h @leonchan5

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -20,8 +20,9 @@
extern "C" {
#endif
enum CmMessage {
CM_MSG_BASE = 0x3a400,
/* SAID: 3512 */
enum CertManagerInterfaceCode {
CM_MSG_BASE = 0,
CM_MSG_GEN_KEY = CM_MSG_BASE,
CM_MSG_GET_CERTIFICATE_LIST,
@ -54,4 +55,4 @@ enum CmMessage {
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -37,7 +37,7 @@ int32_t CmClientInstallAppCert(const struct CmBlob *appCert, const struct CmBlob
int32_t CmClientUninstallAppCert(const struct CmBlob *keyUri, const uint32_t store);
int32_t CmClientUninstallAllAppCert(enum CmMessage type);
int32_t CmClientUninstallAllAppCert(enum CertManagerInterfaceCode type);
int32_t CmClientGetAppCertList(const uint32_t store, struct CredentialList *certificateList);

View File

@ -24,7 +24,8 @@
class OnDemandLoadCertManagerCallback : public OHOS::SystemAbilityLoadCallbackStub {
public:
OnDemandLoadCertManagerCallback(std::string servers);
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const OHOS::sptr<IRemoteObject>& remoteObject) override;
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const OHOS::sptr<IRemoteObject>& remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
OHOS::sptr<IRemoteObject> Promise(void);
private:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -16,7 +16,7 @@
#ifndef CM_REQUEST_H
#define CM_REQUEST_H
#include "cm_ipc_msg_code.h"
#include "cert_manager_service_ipc_interface_code.h"
#include "cm_type_inner.h"
#ifdef __cplusplus
@ -30,7 +30,7 @@ extern "C" {
* @outBlob: the output serialized data blob, can be null.
*/
int32_t SendRequest(enum CmMessage type, const struct CmBlob *inBlob,
int32_t SendRequest(enum CertManagerInterfaceCode type, const struct CmBlob *inBlob,
struct CmBlob *outBlob);
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -51,7 +51,7 @@ static int32_t GetCertListInitOutData(struct CmBlob *outListBlob)
return CM_SUCCESS;
}
static int32_t GetCertificateList(enum CmMessage type, const uint32_t store,
static int32_t GetCertificateList(enum CertManagerInterfaceCode type, const uint32_t store,
struct CertList *certificateList)
{
int32_t ret;
@ -108,7 +108,7 @@ static int32_t GetCertInfoInitOutData(struct CmBlob *outInfoBlob)
return CM_SUCCESS;
}
static int32_t GetCertificateInfo(enum CmMessage type, const struct CmBlob *certUri,
static int32_t GetCertificateInfo(enum CertManagerInterfaceCode type, const struct CmBlob *certUri,
const uint32_t store, struct CertInfo *certificateInfo)
{
int32_t ret = CM_SUCCESS;
@ -156,7 +156,7 @@ int32_t CmClientGetCertInfo(const struct CmBlob *certUri, const uint32_t store,
return GetCertificateInfo(CM_MSG_GET_CERTIFICATE_INFO, certUri, store, certificateInfo);
}
static int32_t SetCertificateStatus(enum CmMessage type, const struct CmBlob *certUri,
static int32_t SetCertificateStatus(enum CertManagerInterfaceCode type, const struct CmBlob *certUri,
const uint32_t store, const uint32_t status)
{
int32_t ret = CM_SUCCESS;
@ -235,7 +235,8 @@ int32_t CmClientInstallAppCert(const struct CmBlob *appCert, const struct CmBlob
return InstallAppCert(appCert, appCertPwd, certAlias, store, keyUri);
}
static int32_t UninstallAppCert(enum CmMessage type, const struct CmBlob *keyUri, const uint32_t store)
static int32_t UninstallAppCert(enum CertManagerInterfaceCode type, const struct CmBlob *keyUri,
const uint32_t store)
{
int32_t ret;
struct CmParamSet *sendParamSet = NULL;
@ -275,7 +276,7 @@ int32_t CmClientUninstallAppCert(const struct CmBlob *keyUri, const uint32_t sto
return UninstallAppCert(CM_MSG_UNINSTALL_APP_CERTIFICATE, keyUri, store);
}
int32_t CmClientUninstallAllAppCert(enum CmMessage type)
int32_t CmClientUninstallAllAppCert(enum CertManagerInterfaceCode type)
{
int32_t ret;
char tempBuff[] = "uninstall all app cert";
@ -379,7 +380,8 @@ static int32_t CmAppCertListUnpackFromService(const struct CmBlob *outData,
return CM_SUCCESS;
}
static int32_t GetAppCertList(enum CmMessage type, const uint32_t store, struct CredentialList *certificateList)
static int32_t GetAppCertList(enum CertManagerInterfaceCode type, const uint32_t store,
struct CredentialList *certificateList)
{
int32_t ret;
struct CmBlob outBlob = { 0, NULL };
@ -533,7 +535,7 @@ static int32_t CmAppCertInfoUnpackFromService(const struct CmBlob *outData, stru
return CM_SUCCESS;
}
static int32_t GetAppCert(enum CmMessage type, const struct CmBlob *certUri, const uint32_t store,
static int32_t GetAppCert(enum CertManagerInterfaceCode type, const struct CmBlob *certUri, const uint32_t store,
struct Credential *certificate)
{
int32_t ret;
@ -586,7 +588,7 @@ int32_t CmClientGetAppCert(const struct CmBlob *keyUri, const uint32_t store, st
return GetAppCert(CM_MSG_GET_APP_CERTIFICATE, keyUri, store, certificate);
}
static int32_t ClientSerializationAndSend(enum CmMessage message, struct CmParam *params,
static int32_t ClientSerializationAndSend(enum CertManagerInterfaceCode message, struct CmParam *params,
uint32_t paramCount, struct CmBlob *outBlob)
{
struct CmParamSet *sendParamSet = NULL;
@ -814,7 +816,7 @@ int32_t CmClientAbort(const struct CmBlob *handle)
return ret;
}
static int32_t GetUserCertList(enum CmMessage type, const uint32_t store,
static int32_t GetUserCertList(enum CertManagerInterfaceCode type, const uint32_t store,
struct CertList *certificateList)
{
int32_t ret = CM_SUCCESS;
@ -861,7 +863,7 @@ int32_t CmClientGetUserCertList(const uint32_t store, struct CertList *certifica
return GetUserCertList(CM_MSG_GET_USER_CERTIFICATE_LIST, store, certificateList);
}
static int32_t GetUserCertInfo(enum CmMessage type, const struct CmBlob *certUri,
static int32_t GetUserCertInfo(enum CertManagerInterfaceCode type, const struct CmBlob *certUri,
const uint32_t store, struct CertInfo *userCertInfo)
{
int32_t ret = CM_SUCCESS;
@ -909,7 +911,7 @@ int32_t CmClientGetUserCertInfo(const struct CmBlob *certUri, const uint32_t sto
return GetUserCertInfo(CM_MSG_GET_USER_CERTIFICATE_INFO, certUri, store, certificateInfo);
}
static int32_t SetUserCertStatus(enum CmMessage type, const struct CmBlob *certUri,
static int32_t SetUserCertStatus(enum CertManagerInterfaceCode type, const struct CmBlob *certUri,
const uint32_t store, const uint32_t status)
{
int32_t ret = CM_SUCCESS;
@ -944,8 +946,8 @@ int32_t CmClientSetUserCertStatus(const struct CmBlob *certUri, const uint32_t s
return SetUserCertStatus(CM_MSG_SET_USER_CERTIFICATE_STATUS, certUri, store, status);
}
static int32_t InstallUserCert(enum CmMessage type, const struct CmBlob *userCert, const struct CmBlob *certAlias,
struct CmBlob *certUri)
static int32_t InstallUserCert(enum CertManagerInterfaceCode type, const struct CmBlob *userCert,
const struct CmBlob *certAlias, struct CmBlob *certUri)
{
int32_t ret = CM_SUCCESS;
struct CmBlob parcelBlob = {0, NULL};
@ -978,7 +980,7 @@ int32_t CmClientInstallUserTrustedCert(const struct CmBlob *userCert, const stru
return InstallUserCert(CM_MSG_INSTALL_USER_CERTIFICATE, userCert, certAlias, certUri);
}
static int32_t UninstallUserCert(enum CmMessage type, const struct CmBlob *certUri)
static int32_t UninstallUserCert(enum CertManagerInterfaceCode type, const struct CmBlob *certUri)
{
int32_t ret = CM_SUCCESS;
struct CmBlob parcelBlob = {0, NULL};
@ -1009,7 +1011,7 @@ int32_t CmClientUninstallUserTrustedCert(const struct CmBlob *certUri)
return UninstallUserCert(CM_MSG_UNINSTALL_USER_CERTIFICATE, certUri);
}
static int32_t UninstallAllUserCert(enum CmMessage type)
static int32_t UninstallAllUserCert(enum CertManagerInterfaceCode type)
{
int ret = CM_SUCCESS;
uint8_t temp[4] = {0}; /* only use to construct parcelBlob */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -98,7 +98,7 @@ static int32_t CmReadRequestReply(MessageParcel &reply, struct CmBlob *outBlob)
return CM_SUCCESS;
}
int32_t SendRequest(enum CmMessage type, const struct CmBlob *inBlob,
int32_t SendRequest(enum CertManagerInterfaceCode type, const struct CmBlob *inBlob,
struct CmBlob *outBlob)
{
uint32_t i = 0;
@ -128,7 +128,7 @@ int32_t SendRequest(enum CmMessage type, const struct CmBlob *inBlob,
data.WriteUint32(inBlob->size);
data.WriteBuffer(inBlob->data, static_cast<size_t>(inBlob->size));
int error = cmProxy->SendRequest(type, data, reply, option);
int error = cmProxy->SendRequest(static_cast<uint32_t>(type), data, reply, option);
if (error != 0) {
CM_LOG_E("SendRequest error:%d", error);
return error;
@ -153,4 +153,4 @@ void OnDemandLoadCertManagerCallback::OnLoadSystemAbilityFail(int32_t systemAbil
sptr<IRemoteObject> OnDemandLoadCertManagerCallback::Promise(void)
{
return promise_.get_future().get();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -47,7 +47,7 @@ using CmIpcAppHandlerFuncProc = void (*)(const struct CmBlob *msg, struct CmBlob
const CmContext *context);
struct CmIpcPoint {
enum CmMessage msgId;
CertManagerInterfaceCode msgId;
CmIpcAppHandlerFuncProc handler;
};
@ -114,7 +114,7 @@ static int32_t ProcessMessage(uint32_t code, uint32_t outSize, const struct CmBl
{
uint32_t size = sizeof(g_cmIpcHandler) / sizeof(g_cmIpcHandler[0]);
for (uint32_t i = 0; i < size; ++i) {
if (code != g_cmIpcHandler[i].msgId) {
if (code != static_cast<uint32_t>(g_cmIpcHandler[i].msgId)) {
continue;
}
struct CmBlob outData = { 0, nullptr };
@ -186,7 +186,7 @@ int CertManagerService::OnRemoteRequest(uint32_t code, MessageParcel &data,
CM_LOG_I("OnRemoteRequest code:%u", code);
// check the code is valid
if (code < MSG_CODE_BASE || code >= MSG_CODE_MAX) {
if (code < static_cast<uint32_t>(CM_MSG_BASE) || code >= static_cast<uint32_t>(CM_MSG_MAX)) {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -23,7 +23,7 @@
#include "nocopyable.h"
#include "system_ability.h"
#include "cm_ipc_msg_code.h"
#include "cert_manager_service_ipc_interface_code.h"
namespace OHOS {
namespace Security {
@ -43,35 +43,6 @@ constexpr int SA_ID_KEYSTORE_SERVICE = 3512;
class ICertManagerService : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.cm.service");
// message code
uint32_t MSG_CODE_BASE = CM_MSG_BASE;
uint32_t MSG_CODE_GEN_KEY = CM_MSG_GEN_KEY;
uint32_t MSG_CODE_GET_CERTIFICATE_LIST = CM_MSG_GET_CERTIFICATE_LIST;
uint32_t MSG_CODE_GET_CERTIFICATE_INFO = CM_MSG_GET_CERTIFICATE_INFO;
uint32_t MSG_CODE_SET_CERTIFICATE_STATUS = CM_MSG_SET_CERTIFICATE_STATUS;
uint32_t MSG_CODE_INSTALL_APP_CERTIFICATE = CM_MSG_INSTALL_APP_CERTIFICATE;
uint32_t MSG_CODE_UNINSTALL_APP_CERTIFICATE = CM_MSG_UNINSTALL_APP_CERTIFICATE;
uint32_t MSG_CODE_UNINSTALL_ALL_APP_CERTIFICATE = CM_MSG_UNINSTALL_ALL_APP_CERTIFICATE;
uint32_t MSG_CODE_GET_APP_CERTIFICATE_LIST = CM_MSG_GET_APP_CERTIFICATE_LIST;
uint32_t MSG_CODE_GET_APP_CERTIFICATE = CM_MSG_GET_APP_CERTIFICATE;
uint32_t MSG_CODE_GRANT_APP_CERT = CM_MSG_GRANT_APP_CERT;
uint32_t MSG_CODE_GET_AUTHED_LIST = CM_MSG_GET_AUTHED_LIST;
uint32_t MSG_CODE_CHECK_IS_AUTHED_APP = CM_MSG_CHECK_IS_AUTHED_APP;
uint32_t MSG_CODE_REMOVE_GRANT_APP = CM_MSG_REMOVE_GRANT_APP;
uint32_t MSG_CODE_INIT = CM_MSG_INIT;
uint32_t MSG_CODE_UPDATE = CM_MSG_UPDATE;
uint32_t MSG_CODE_FINISH = CM_MSG_FINISH;
uint32_t MSG_CODE_ABORT = CM_MSG_ABORT;
uint32_t MSG_CODE_GET_USER_CERTIFICATE_LIST = CM_MSG_GET_USER_CERTIFICATE_LIST;
uint32_t MSG_CODE_GET_USER_CERTIFICATE_INFO = CM_MSG_GET_USER_CERTIFICATE_INFO;
uint32_t MSG_CODE_SET_USER_CERTIFICATE_STATUS = CM_MSG_SET_USER_CERTIFICATE_STATUS;
uint32_t MSG_CODE_INSTALL_USER_CERTIFICATE = CM_MSG_INSTALL_USER_CERTIFICATE;
uint32_t MSG_CODE_UNINSTALL_USER_CERTIFICATE = CM_MSG_UNINSTALL_USER_CERTIFICATE;
uint32_t MSG_CODE_UNINSTALL_ALL_USER_CERTIFICATE = CM_MSG_UNINSTALL_ALL_USER_CERTIFICATE;
/* new cmd type must be added before CM_MSG_MAX */
uint32_t MSG_CODE_MAX = CM_MSG_MAX;
};
class CertManagerService : public SystemAbility, public IRemoteStub<ICertManagerService> {

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_APP_CERTIFICATE, false, CmIpcServiceGetAppCert)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_APP_CERTIFICATE,
false, CmIpcServiceGetAppCert)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_APP_CERTIFICATE_LIST, false, CmIpcServiceGetAppCertList)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_APP_CERTIFICATE_LIST,
false, CmIpcServiceGetAppCertList)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_AUTHED_LIST, false, CmIpcServiceGetAuthorizedAppList)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_AUTHED_LIST,
false, CmIpcServiceGetAuthorizedAppList)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_CERTIFICATE_INFO, false, CmIpcServiceGetCertificateInfo)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_CERTIFICATE_INFO,
false, CmIpcServiceGetCertificateInfo)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_CERTIFICATE_LIST, false, CmIpcServiceGetCertificateList)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GET_CERTIFICATE_LIST,
false, CmIpcServiceGetCertificateList)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GRANT_APP_CERT, false, CmIpcServiceGrantAppCertificate)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_GRANT_APP_CERT,
false, CmIpcServiceGrantAppCertificate)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_INSTALL_APP_CERTIFICATE, false, CmIpcServiceInstallAppCert)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_INSTALL_APP_CERTIFICATE,
false, CmIpcServiceInstallAppCert)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_INSTALL_USER_CERTIFICATE, false, CmIpcServiceInstallUserCert)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_INSTALL_USER_CERTIFICATE,
false, CmIpcServiceInstallUserCert)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_CHECK_IS_AUTHED_APP, false, CmIpcServiceIsAuthorizedApp)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_CHECK_IS_AUTHED_APP,
false, CmIpcServiceIsAuthorizedApp)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_REMOVE_GRANT_APP, false, CmIpcServiceRemoveGrantedApp)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_REMOVE_GRANT_APP,
false, CmIpcServiceRemoveGrantedApp)) {
return false;
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
CertmanagerTest::SetATPermission();
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_SET_CERTIFICATE_STATUS, false, CmIpcServiceSetCertStatus)) {
if (!IpcServiceApiFuzzerTest(data, size, CM_MSG_SET_CERTIFICATE_STATUS,
false, CmIpcServiceSetCertStatus)) {
return false;
}

View File

@ -49,7 +49,8 @@ namespace OHOS {
return false;
}
struct CmParamSet *paramSet = nullptr;
if (ConstructParamSet(myData, &remainSize, &offset, static_cast<enum CmMessage>(code), &paramSet) == false) {
if (ConstructParamSet(myData, &remainSize, &offset,
static_cast<CertManagerInterfaceCode>(code), &paramSet) == false) {
CmFree(myData);
return false;
}
@ -83,4 +84,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}

View File

@ -15,7 +15,6 @@
#include "cmsendrequest_fuzzer.h"
#include "cm_ipc_msg_code.h"
#include "cm_fuzz_test_common.h"
#include "cm_param.h"
#include "cm_request.h"
@ -25,7 +24,7 @@ using namespace CmFuzzTest;
namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
uint32_t minSize = sizeof(enum CmMessage) + sizeof(struct CmParamSet) + sizeof(struct CmBlob);
uint32_t minSize = sizeof(CertManagerInterfaceCode) + sizeof(struct CmParamSet) + sizeof(struct CmBlob);
uint8_t *myData = nullptr;
if (!CopyMyData(data, size, minSize, &myData)) {
return false;
@ -34,10 +33,10 @@ namespace OHOS {
uint32_t remainSize = static_cast<uint32_t>(size);
uint32_t offset = 0;
enum CmMessage type;
(void)memcpy_s(&type, sizeof(enum CmMessage), myData, sizeof(enum CmMessage));
type = static_cast<enum CmMessage>(
static_cast<uint32_t>(type) % static_cast<uint32_t>(CM_MSG_MAX - CM_MSG_BASE) +
CertManagerInterfaceCode type;
(void)memcpy_s(&type, sizeof(CertManagerInterfaceCode), myData, sizeof(CertManagerInterfaceCode));
type = static_cast<CertManagerInterfaceCode>(static_cast<uint32_t>(type) %
(static_cast<uint32_t>(CM_MSG_MAX) - static_cast<uint32_t>(CM_MSG_BASE)) +
static_cast<uint32_t>(CM_MSG_BASE));
offset += sizeof(uint32_t);
remainSize -= sizeof(uint32_t);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
@ -16,7 +16,7 @@
#ifndef CM_FUZZ_TEST_COMMON_H
#define CM_FUZZ_TEST_COMMON_H
#include "cm_ipc_msg_code.h"
#include "cert_manager_service_ipc_interface_code.h"
#include "cm_mem.h"
#include "cm_param.h"
#include "cm_type.h"
@ -33,10 +33,10 @@ bool GetCertInfoFromBuffer(uint8_t *srcData, uint32_t *remSize, uint32_t *offset
bool CopyMyData(const uint8_t *data, const size_t size, const uint32_t minSize, uint8_t **myData);
bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize, uint32_t *offset, enum CmMessage code,
struct CmParamSet **paramSetOut);
bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize, uint32_t *offset,
CertManagerInterfaceCode code, struct CmParamSet **paramSetOut);
bool IpcServiceApiFuzzerTest(const uint8_t *data, const size_t size, enum CmMessage code, bool isParamsetToBlob,
void (*ipcServiceApi)(const struct CmBlob *, struct CmBlob *, const struct CmContext *));
bool IpcServiceApiFuzzerTest(const uint8_t *data, const size_t size, CertManagerInterfaceCode code,
bool isParamsetToBlob, void (*ipcServiceApi)(const struct CmBlob *, struct CmBlob *, const struct CmContext *));
} // namespace CmFuzzTest
#endif /* CM_FUZZ_TEST_COMMON_H */

View File

@ -102,7 +102,7 @@ constexpr uint32_t PARAM_COUNT_THREE = 3;
constexpr uint32_t PARAM_COUNT_FOUR = 4;
struct CmFuzzerCodeParams {
enum CmMessage code;
CertManagerInterfaceCode code;
uint32_t paramCnt;
struct CmParam params[PARAM_COUNT_FOUR];
};
@ -257,8 +257,8 @@ constexpr struct CmFuzzerCodeParams g_codeParams[] = {
},
};
bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize, uint32_t *offset, enum CmMessage code,
struct CmParamSet **paramSetOut)
bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize,
uint32_t *offset, CertManagerInterfaceCode code, struct CmParamSet **paramSetOut)
{
struct CmParam params[PARAM_COUNT_FOUR] = {};
uint32_t paramCnt = 0;
@ -302,8 +302,8 @@ bool ConstructParamSet(uint8_t *srcData, uint32_t *remainSize, uint32_t *offset,
return true;
}
bool IpcServiceApiFuzzerTest(const uint8_t *data, const size_t size, enum CmMessage code, bool isParamsetToBlob,
void (*ipcServiceApi)(const struct CmBlob *, struct CmBlob *, const struct CmContext *))
bool IpcServiceApiFuzzerTest(const uint8_t *data, const size_t size, CertManagerInterfaceCode code,
bool isParamsetToBlob, void (*ipcServiceApi)(const struct CmBlob *, struct CmBlob *, const struct CmContext *))
{
uint32_t minSize = sizeof(struct CmBlob) + sizeof(struct CmBlob);
uint8_t *myData = nullptr;