mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-12-04 22:27:12 +00:00
commit
12e59ce617
@ -21,6 +21,7 @@ group("iam_services_fuzztest") {
|
||||
"coauthstub_fuzzer:CoAuthStubFuzzTest",
|
||||
"context/contextcallbackimpl_fuzzer:ContextCallbackImplFuzzTest",
|
||||
"context/contextpoolimpl_fuzzer:ContextPoolImplFuzzTest",
|
||||
"context/remoteauthcontext_fuzzer:RemoteAuthContextFuzzTest",
|
||||
"core/remoteexecutorstub_fuzzer:RemoteExecutorStubFuzzTest",
|
||||
"servicecore_fuzzer:ServiceCoreFuzzTest",
|
||||
"softbus_fuzzer:SoftBusFuzzTest",
|
||||
|
@ -0,0 +1,91 @@
|
||||
# Copyright (c) 2024 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("RemoteAuthContextFuzzTest") {
|
||||
branch_protector_ret = "pac_ret"
|
||||
module_out_path = "user_auth_framework/user_auth"
|
||||
fuzz_config_file = "../remoteauthcontext_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../../../dummy",
|
||||
"../../../../../services/base/inc",
|
||||
"../../../../../services/core/inc",
|
||||
"../../../../../services/core/src",
|
||||
"../../../../../services/context/src",
|
||||
"../../../../../services/context/inc",
|
||||
"../../../../../services/remote_connect/inc",
|
||||
"../../../../../services/ipc/inc",
|
||||
"../../../../../interfaces/inner_api",
|
||||
"../../../../../frameworks/native/ipc/inc",
|
||||
"../../../../../frameworks/common/dfx/inc",
|
||||
"../../../../../frameworks/native/ipc/common_defines",
|
||||
"../../../../../common/utils",
|
||||
"../../../../../common/logs",
|
||||
]
|
||||
|
||||
sources = [ "remote_auth_context_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"../../../common_fuzzer:attributes_fuzzer",
|
||||
"../../../common_fuzzer:dfx_fuzzer",
|
||||
"../../../common_fuzzer:iam_test_fuzzer",
|
||||
"../../../common_fuzzer:userauth_service_context_fuzzer",
|
||||
"../../../common_fuzzer:userauth_service_core_fuzzer",
|
||||
"../../../common_fuzzer:userauth_services_ipc_fuzzer",
|
||||
]
|
||||
|
||||
remove_configs = [ "//build/config/compiler:no_exceptions" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"drivers_interface_user_auth:libuser_auth_proxy_2.0",
|
||||
"eventhandler:libeventhandler",
|
||||
"hdf_core:libhdi",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
external_deps += [
|
||||
"ability_base:base",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:extension_manager",
|
||||
"access_token:libtoken_setproc",
|
||||
"device_manager:devicemanagersdk",
|
||||
"dsoftbus:softbus_client",
|
||||
"hitrace:hitrace_meter",
|
||||
"init:libbegetutil",
|
||||
"napi:ace_napi",
|
||||
"openssl:libcrypto_shared",
|
||||
]
|
||||
|
||||
subsystem_name = "useriam"
|
||||
part_name = "user_auth_framework"
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2024 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) 2024 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>30</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "remote_auth_context_fuzzer.h"
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
#include "dummy_authentication.h"
|
||||
#include "dummy_context_pool.h"
|
||||
#include "dummy_iam_callback_interface.h"
|
||||
#include "dummy_executor_callback_interface.h"
|
||||
#include "dummy_schedule_node_callback.h"
|
||||
|
||||
#include "attributes.h"
|
||||
#include "context_pool.h"
|
||||
#include "context_callback_impl.h"
|
||||
#include "simple_auth_context.h"
|
||||
#include "iam_fuzz_test.h"
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "remote_auth_context.h"
|
||||
#include "remote_auth_invoker_context.h"
|
||||
#include "remote_iam_callback.h"
|
||||
#include "context_appstate_observer.h"
|
||||
|
||||
#define LOG_TAG "USER_AUTH_SA"
|
||||
|
||||
#undef private
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::UserIam::Common;
|
||||
using namespace OHOS::UserIam::UserAuth;
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
namespace {
|
||||
constexpr uint32_t OPERATION_TYPE = 1;
|
||||
|
||||
void ContextAppStateObserverFuzzTest(Parcel &parcel)
|
||||
{
|
||||
IAM_LOGI("begin");
|
||||
auto contextAppStateObserver = MakeShared<ContextAppStateObserverManager>();
|
||||
auto contextCallback = MakeShared<ContextCallbackImpl>(new (std::nothrow) DummyIamCallbackInterface(),
|
||||
static_cast<OperationType>(OPERATION_TYPE));
|
||||
uint64_t contextId = parcel.ReadUint64();
|
||||
|
||||
contextAppStateObserver->SubscribeAppState(contextCallback, contextId);
|
||||
std::string callerName = parcel.ReadString();
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
contextAppStateObserver->SubscribeAppState(contextCallback, contextId);
|
||||
|
||||
contextAppStateObserver->UnSubscribeAppState();
|
||||
|
||||
std::string bundleName = parcel.ReadString();
|
||||
auto contextApp = MakeShared<ContextAppStateObserver>(contextId, bundleName);
|
||||
AppStateData appStateData;
|
||||
appStateData.state = static_cast<int32_t>(ApplicationState::APP_STATE_BACKGROUND);
|
||||
appStateData.bundleName = "com.homs.settings";
|
||||
|
||||
contextApp->OnAppStateChanged(appStateData);
|
||||
|
||||
contextApp->OnForegroundApplicationChanged(appStateData);
|
||||
|
||||
AbilityStateData abilityStateData;
|
||||
abilityStateData.abilityState = static_cast<int32_t>(AbilityState::ABILITY_STATE_BACKGROUND);
|
||||
abilityStateData.bundleName = "com.homs.settings";
|
||||
contextApp->OnAbilityStateChanged(abilityStateData);
|
||||
|
||||
int32_t userId = parcel.ReadInt32();
|
||||
contextApp->ProcAppStateChanged(userId);
|
||||
IAM_LOGI("end");
|
||||
}
|
||||
|
||||
void RemoteAuthContextFuzzTest(Parcel &parcel)
|
||||
{
|
||||
IAM_LOGI("begin");
|
||||
const int32_t sdkVersion = 11;
|
||||
uint64_t newContextId = parcel.ReadUint64();
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = sdkVersion;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
auto auth = MakeShared<AuthenticationImpl>(newContextId, para);
|
||||
auto contextCallback = MakeShared<ContextCallbackImpl>(new (std::nothrow) DummyIamCallbackInterface(),
|
||||
static_cast<OperationType>(OPERATION_TYPE));
|
||||
RemoteAuthContextParam param;
|
||||
param.authType = ALL;
|
||||
param.connectionName = parcel.ReadString();
|
||||
param.collectorNetworkId = parcel.ReadString();
|
||||
param.executorInfoMsg = {};
|
||||
auto remoteAuthContext = MakeShared<RemoteAuthContext>(
|
||||
newContextId, auth, param, contextCallback
|
||||
);
|
||||
|
||||
remoteAuthContext->GetContextType();
|
||||
|
||||
std::vector<uint8_t> msg;
|
||||
FillFuzzUint8Vector(parcel, msg);
|
||||
remoteAuthContext->SetExecutorInfoMsg(msg);
|
||||
remoteAuthContext->OnStart();
|
||||
remoteAuthContext->OnTimeOut();
|
||||
std::string connectionName = parcel.ReadString();
|
||||
remoteAuthContext->OnConnectStatus(connectionName, ConnectStatus::DISCONNECTED);
|
||||
remoteAuthContext->OnConnectStatus(connectionName, ConnectStatus::CONNECTED);
|
||||
|
||||
IAM_LOGI("end");
|
||||
}
|
||||
|
||||
void RemoteAuthInvokerContextFuzzTest(Parcel &parcel)
|
||||
{
|
||||
IAM_LOGI("begin");
|
||||
|
||||
uint64_t contextId = parcel.ReadUint64();
|
||||
std::vector<uint8_t> challenge;
|
||||
FillFuzzUint8Vector(parcel, challenge);
|
||||
AuthParamInner authParam = {
|
||||
.userId = parcel.ReadInt32(),
|
||||
.challenge = challenge,
|
||||
.authType = static_cast<AuthType>(parcel.ReadInt32()),
|
||||
.authTrustLevel = static_cast<AuthTrustLevel>(parcel.ReadInt32()),
|
||||
};
|
||||
auto contextCallback = MakeShared<ContextCallbackImpl>(new (std::nothrow) DummyIamCallbackInterface(),
|
||||
static_cast<OperationType>(OPERATION_TYPE));
|
||||
|
||||
RemoteAuthInvokerContextParam param;
|
||||
param.connectionName = parcel.ReadString();
|
||||
param.verifierNetworkId = parcel.ReadString();
|
||||
param.collectorNetworkId = parcel.ReadString();
|
||||
param.tokenId = parcel.ReadUint32();
|
||||
param.collectorTokenId = parcel.ReadUint32();
|
||||
param.callerName = parcel.ReadString();
|
||||
param.callerType = parcel.ReadInt32();
|
||||
|
||||
auto remoteAuthInvokerContext = MakeShared<RemoteAuthInvokerContext>(
|
||||
contextId, authParam, param, contextCallback
|
||||
);
|
||||
remoteAuthInvokerContext->GetContextType();
|
||||
remoteAuthInvokerContext->GetTokenId();
|
||||
|
||||
std::string connectionName = parcel.ReadString();
|
||||
remoteAuthInvokerContext->OnConnectStatus(connectionName, ConnectStatus::DISCONNECTED);
|
||||
remoteAuthInvokerContext->OnConnectStatus(connectionName, ConnectStatus::CONNECTED);
|
||||
remoteAuthInvokerContext->SetVerifierContextId(contextId);
|
||||
remoteAuthInvokerContext->OnTimeOut();
|
||||
|
||||
std::string srcEndPoint = parcel.ReadString();
|
||||
auto request = MakeShared<Attributes>();
|
||||
auto reply = MakeShared<Attributes>();
|
||||
|
||||
remoteAuthInvokerContext->OnMessage(connectionName, srcEndPoint, request, reply);
|
||||
|
||||
int32_t resultCode = parcel.ReadInt32();
|
||||
auto scheduleResultAttr = MakeShared<Attributes>();
|
||||
|
||||
remoteAuthInvokerContext->OnResult(resultCode, scheduleResultAttr);
|
||||
|
||||
remoteAuthInvokerContext->OnStart();
|
||||
remoteAuthInvokerContext->OnStop();
|
||||
IAM_LOGI("end");
|
||||
}
|
||||
|
||||
void RemoteIamCallbackFuzzTest(Parcel &parcel)
|
||||
{
|
||||
IAM_LOGI("begin");
|
||||
std::string connectionName = parcel.ReadString();
|
||||
auto remoteCallback = MakeShared<RemoteIamCallback>(connectionName);
|
||||
int32_t result = parcel.ReadInt32();
|
||||
Attributes extraInfo;
|
||||
remoteCallback->OnResult(result, extraInfo);
|
||||
|
||||
int32_t module = parcel.ReadInt32();
|
||||
int32_t acquireInfo = parcel.ReadInt32();
|
||||
remoteCallback->OnAcquireInfo(module, acquireInfo, extraInfo);
|
||||
|
||||
remoteCallback->AsObject();
|
||||
IAM_LOGI("end");
|
||||
}
|
||||
|
||||
using FuzzFunc = decltype(ContextAppStateObserverFuzzTest);
|
||||
FuzzFunc *g_fuzzFuncs[] = {
|
||||
ContextAppStateObserverFuzzTest,
|
||||
RemoteAuthContextFuzzTest,
|
||||
RemoteAuthInvokerContextFuzzTest,
|
||||
RemoteIamCallbackFuzzTest,
|
||||
};
|
||||
|
||||
void RemoteAuthContextFuzzTest(const uint8_t *data, size_t size)
|
||||
{
|
||||
Parcel parcel;
|
||||
parcel.WriteBuffer(data, size);
|
||||
parcel.RewindRead(0);
|
||||
for (auto fuzzFunc : g_fuzzFuncs) {
|
||||
fuzzFunc(parcel);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
OHOS::UserIam::UserAuth::RemoteAuthContextFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 REMTOE_AUTH_CONTEXT_FUZZER_H
|
||||
#define REMTOE_AUTH_CONTEXT_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "RemoteAuthContextFuzzTest"
|
||||
|
||||
#endif // REMTOE_AUTH_CONTEXT_FUZZER_H
|
Loading…
Reference in New Issue
Block a user