mirror of
https://github.com/openharmony/useriam_user_auth.git
synced 2026-07-18 20:34:38 -04:00
增加 user_idm 的FUZZ测试
Signed-off-by: shipengtao9579 <shipengtao@huawei.com>
This commit is contained in:
+2
-1
@@ -119,7 +119,8 @@
|
||||
],
|
||||
"test": [
|
||||
"//base/user_iam/user_auth/test/user_idm:user_idm_unittest",
|
||||
"//base/user_iam/user_auth/test/user_auth:user_auth_unittest"
|
||||
"//base/user_iam/user_auth/test/user_auth:user_auth_unittest",
|
||||
"//base/user_iam/user_auth/test/user_idm/fuzztest/user_idm_fuzzer:UserIdmFuzzTest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
ohos_fuzztest("UserIdmFuzzTest") {
|
||||
module_out_path = "user_iam/user_auth/user_idm"
|
||||
fuzz_config_file =
|
||||
"//base/user_iam/user_auth/test/user_idm/fuzztest/user_idm_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//base/user_iam/user_auth/common/logs/user_idm",
|
||||
"//base/user_iam/user_auth/frameworks/user_idm/inc",
|
||||
"//base/user_iam/user_auth/services/user_idm/inc",
|
||||
"//base/user_iam/user_auth/interfaces/inner_api/user_idm",
|
||||
"//base/user_iam/user_auth/common/logs",
|
||||
]
|
||||
|
||||
sources = [ "user_idm_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"//base/user_iam/user_auth/common:iam_test",
|
||||
"//base/user_iam/user_auth/services:userauthservice",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
FUZZ
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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.
|
||||
-->
|
||||
<fuzz_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>2000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "user_idm_fuzzer.h"
|
||||
#include "parcel.h"
|
||||
#include "securec.h"
|
||||
#include "iam_fuzz_test.h"
|
||||
#include "useridm_service.h"
|
||||
#include "useridm_hilog_wrapper.h"
|
||||
|
||||
|
||||
#undef private
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::UserIAM::Common;
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserIDM {
|
||||
namespace {
|
||||
class GetInfoCallbackFuzzer : public IRemoteStub<IGetInfoCallback> {
|
||||
public:
|
||||
virtual ~GetInfoCallbackFuzzer() = default;
|
||||
void OnGetInfo(std::vector<CredentialInfo> &info) override
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "GetInfoCallbackFuzzer OnGetInfo");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
class GetSecInfoCallbackFuzzer : public IRemoteStub<IGetSecInfoCallback> {
|
||||
public:
|
||||
virtual ~GetSecInfoCallbackFuzzer() = default;
|
||||
void OnGetSecInfo(SecInfo &info) override
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "GetSecInfoCallbackFuzzer OnGetSecInfo");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
class IdmCallbackFuzzer : public IRemoteStub<IIDMCallback> {
|
||||
public:
|
||||
virtual ~IdmCallbackFuzzer() = default;
|
||||
void OnResult(int32_t result, RequestResult reqRet) override
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "IdmCallbackFuzzer OnResult");
|
||||
return;
|
||||
}
|
||||
|
||||
void OnAcquireInfo(int32_t module, int32_t acquire, RequestResult reqRet) override
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "IdmCallbackFuzzer OnAcquireInfo");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
void FillFuzzAddCredInfo(Parcel &parcel, AddCredInfo &credInfo)
|
||||
{
|
||||
credInfo.authType = static_cast<AuthType>(parcel.ReadUint32());
|
||||
credInfo.authSubType = static_cast<AuthSubType>(parcel.ReadUint64());
|
||||
FillFuzzUint8Vector(parcel, credInfo.token);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "success");
|
||||
}
|
||||
|
||||
UserIDMService g_userIdmService(SUBSYS_USERIAM_SYS_ABILITY_USERIDM, true);
|
||||
|
||||
void FuzzOnStart(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
static_cast<void>(parcel);
|
||||
g_userIdmService.OnStart();
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzOnStop(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
static_cast<void>(parcel);
|
||||
g_userIdmService.OnStop();
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzOpenSession(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
static_cast<void>(parcel);
|
||||
g_userIdmService.OpenSession();
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzCloseSession(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
static_cast<void>(parcel);
|
||||
g_userIdmService.CloseSession();
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzGetAuthInfo_a(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
AuthType authType = static_cast<AuthType>(parcel.ReadUint32());
|
||||
sptr<IGetInfoCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) GetInfoCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.GetAuthInfo(authType, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzGetAuthInfo_b(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
int32_t userId = parcel.ReadInt32();
|
||||
AuthType authType = static_cast<AuthType>(parcel.ReadUint32());
|
||||
sptr<IGetInfoCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) GetInfoCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.GetAuthInfo(userId, authType, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzGetSecInfo(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
int32_t userId = parcel.ReadInt32();
|
||||
sptr<IGetSecInfoCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) GetSecInfoCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.GetSecInfo(userId, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzAddCredential(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
AddCredInfo credInfo;
|
||||
FillFuzzAddCredInfo(parcel, credInfo);
|
||||
sptr<IIDMCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) IdmCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.AddCredential(credInfo, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzUpdateCredential(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
AddCredInfo credInfo;
|
||||
FillFuzzAddCredInfo(parcel, credInfo);
|
||||
sptr<IIDMCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) IdmCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.UpdateCredential(credInfo, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzCancel(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
uint64_t challenge = parcel.ReadUint64();
|
||||
g_userIdmService.Cancel(challenge);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzEnforceDelUser(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
uint32_t userId = parcel.ReadUint32();
|
||||
sptr<IIDMCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) IdmCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.EnforceDelUser(userId, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzDelUser(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
std::vector<uint8_t> authToken;
|
||||
FillFuzzUint8Vector(parcel, authToken);
|
||||
sptr<IIDMCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) IdmCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.DelUser(authToken, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
void FuzzDelCred(Parcel &parcel)
|
||||
{
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "begin");
|
||||
uint64_t credentialId = parcel.ReadUint64();
|
||||
std::vector<uint8_t> authToken;
|
||||
FillFuzzUint8Vector(parcel, authToken);
|
||||
sptr<IIDMCallback> callback = nullptr;
|
||||
if (parcel.ReadBool()) {
|
||||
callback = new (std::nothrow) IdmCallbackFuzzer();
|
||||
}
|
||||
g_userIdmService.DelCred(credentialId, authToken, callback);
|
||||
USERIDM_HILOGI(MODULE_SERVICE, "end");
|
||||
}
|
||||
|
||||
using FuzzFunc = decltype(FuzzDelCred);
|
||||
FuzzFunc *g_fuzzFuncs[] = {
|
||||
FuzzOnStart,
|
||||
FuzzOnStop,
|
||||
FuzzOpenSession,
|
||||
FuzzCloseSession,
|
||||
FuzzGetAuthInfo_a,
|
||||
FuzzGetAuthInfo_b,
|
||||
FuzzGetSecInfo,
|
||||
FuzzAddCredential,
|
||||
FuzzUpdateCredential,
|
||||
FuzzCancel,
|
||||
FuzzEnforceDelUser,
|
||||
FuzzDelUser,
|
||||
FuzzDelCred,
|
||||
};
|
||||
|
||||
void UserIdmFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
parcel.RewindRead(0);
|
||||
uint32_t index = parcel.ReadUint32() % (sizeof(g_fuzzFuncs) / sizeof(FuzzFunc *));
|
||||
auto fuzzFunc = g_fuzzFuncs[index];
|
||||
fuzzFunc(parcel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace UserIDM
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::UserIAM::UserIDM::UserIdmFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#ifndef USER_IDM_FUZZER_H
|
||||
#define USER_IDM_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "UserIdmFuzzTest"
|
||||
|
||||
#endif // USER_IDM_FUZZER_H
|
||||
Reference in New Issue
Block a user