diff --git a/bundle.json b/bundle.json index 462bda7bb20bf7501d7345e837553b30494672c9..c9ae366e58c1a49941f55634472d442226dfb1e4 100644 --- a/bundle.json +++ b/bundle.json @@ -80,11 +80,7 @@ "//base/security/access_token/interfaces/innerkits/nativetoken/test:unittest", "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", "//base/security/access_token/interfaces/kits/accesstoken/test/benchmarktest:benchmarktest", - "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken_fuzzer:fuzztest", - "//base/security/access_token/test/fuzztest/access_token/getdefpermission_fuzzer:fuzztest", - "//base/security/access_token/test/fuzztest/access_token/getpermissionflags_fuzzer:fuzztest", - "//base/security/access_token/test/fuzztest/access_token/grantpermission_fuzzer:fuzztest", - "//base/security/access_token/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer:fuzztest" + "//base/security/access_token/test/fuzztest/access_token:fuzztest" ] } } diff --git a/test/fuzztest/access_token/BUILD.gn b/test/fuzztest/access_token/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e37d93e7fd00f66c53dffb8f732c8a25e0625d94 --- /dev/null +++ b/test/fuzztest/access_token/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + "allochaptoken_fuzzer:AllocHapTokenFuzzTest", + "alloclocaltokenid_fuzzer:AllocLocalTokenIDFuzzTest", + "checknativedcap_fuzzer:CheckNativeDCapFuzzTest", + "clearusergrantedpermissionstate_fuzzer:ClearUserGrantedPermissionStateFuzzTest", + "deleteremotedevicetokens_fuzzer:DeleteRemoteDeviceTokensFuzzTest", + "deleteremotetoken_fuzzer:DeleteRemoteTokenFuzzTest", + "deletetoken_fuzzer:DeleteTokenFuzzTest", + "getdefpermission_fuzzer:GetDefPermissionFuzzTest", + "getpermissionflags_fuzzer:GetPermissionFlagsFuzzTest", + "grantpermission_fuzzer:GrantPermissionFuzzTest", + "revokeusergrantedpermission_fuzzer:RevokeUserGrantedPermissionFuzzTest", + "setremotehaptokeninfo_fuzzer:SetRemoteHapTokenInfoFuzzTest", + "setremotenativetokeninfo_fuzzer:SetRemoteNativeTokenInfoFuzzTest", + "updatehaptoken_fuzzer:UpdateHapTokenFuzzTest", + "verifyaccesstoken001_fuzzer:VerifyAccessToken001FuzzTest", + "verifyaccesstoken_fuzzer:VerifyAccessTokenFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..904b51553a13b2a80502d0d8b662a7bf626b677f --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("AllocHapTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/allochaptoken_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "allochaptoken_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..094fa5d6e8dd6b6588426bacbb3488f68b7f2148 --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp @@ -0,0 +1,80 @@ +/* + * 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 "allochaptoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool AllocHapTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + std::string testdata; + AccessTokenIDEx tokenIdEx = {0}; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + testdata = reinterpret_cast(data); + PermissionDef TestPermDef = { + .permissionName = testdata, + .bundleName = testdata, + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = testdata, + .labelId = 1, + .description = testdata, + .descriptionId = 1 + }; + PermissionStateFull TestState = { + .permissionName = testdata, + .isGeneral = true, + .resDeviceID = {testdata}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1}, + }; + HapInfoParams TestInfoParms = { + .userID = 1, + .bundleName = testdata, + .instIndex = 0, + .appIDDesc = testdata + }; + HapPolicyParams TestPolicyPrams = { + .apl = APL_NORMAL, + .domain = testdata, + .permList = {TestPermDef}, + .permStateList = {TestState} + }; + + tokenIdEx = AccessTokenKit::AllocHapToken(TestInfoParms, TestPolicyPrams); + } + return tokenIdEx.tokenIdExStruct.tokenID != 0; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AllocHapTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.h b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e2ceda0b5b0fcb02fe4b6c07d4c59682b1f1b18f --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.h @@ -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 TEST_FUZZTEST_ALLOCHAPTOKEN_FUZZER_H +#define TEST_FUZZTEST_ALLOCHAPTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "allochaptoken_fuzzer" + +#endif // TEST_FUZZTEST_ALLOCHAPTOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/corpus/init b/test/fuzztest/access_token/allochaptoken_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/project.xml b/test/fuzztest/access_token/allochaptoken_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c79db1085857927556ea7303ff668692e31c075b --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("AllocLocalTokenIDFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/alloclocaltokenid_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "alloclocaltokenid_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..993f3a07938bbae6ef1bdab63c4ccaec2e23436f --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "alloclocaltokenid_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool AllocLocalTokenIDFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + AccessTokenID TOKENID = 0; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID REMOTETOKENID = static_cast(size); + TOKENID = AccessTokenKit::AllocLocalTokenID(reinterpret_cast(data), REMOTETOKENID); + } + return TOKENID != 0; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AllocLocalTokenIDFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.h b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..24cc378703d5973c520e029cf01aceb85f15fd0b --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.h @@ -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 TEST_FUZZTEST_ALLOCLOCALTOKENID_FUZZER_H +#define TEST_FUZZTEST_ALLOCLOCALTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "alloclocaltokenid_fuzzer" + +#endif // TEST_FUZZTEST_ALLOCLOCALTOKENID_FUZZER_H diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/corpus/init b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/project.xml b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn b/test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0cf9f230725215f7a079b882481cb9bc82bf3693 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("CheckNativeDCapFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/checknativedcap_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "checknativedcap_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.cpp b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b22eff366e08c8fe672982153d7381f79c3e6a7 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "checknativedcap_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool CheckNativeDCapFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::CheckNativeDCap(TOKENID, reinterpret_cast(data)); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CheckNativeDCapFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.h b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4da892de7e41726fbeb1d151f7b75ef36a587110 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.h @@ -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 TEST_FUZZTEST_CHECKNATIVEDCAP_FUZZER_H +#define TEST_FUZZTEST_CHECKNATIVEDCAP_FUZZER_H + +#define FUZZ_PROJECT_NAME "checknativedcap_fuzzer" + +#endif // TEST_FUZZTEST_CHECKNATIVEDCAP_FUZZER_H diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/corpus/init b/test/fuzztest/access_token/checknativedcap_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/project.xml b/test/fuzztest/access_token/checknativedcap_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fc80c90eb71c2b3d62e4544b9172982cc8f0670c --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("ClearUserGrantedPermissionStateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "clearusergrantedpermissionstate_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.cpp b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18f55fbd262993a1389e19297175a8f8de7cfa73 --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "clearusergrantedpermissionstate_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool ClearUserGrantedPermissionStateFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::ClearUserGrantedPermissionState(TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::ClearUserGrantedPermissionStateFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.h b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..042746200706452c14ec304c48aba56d289943c4 --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.h @@ -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 TEST_FUZZTEST_CLEARUSERGRANTEDPERMISSIONSTATE_FUZZER_H +#define TEST_FUZZTEST_CLEARUSERGRANTEDPERMISSIONSTATE_FUZZER_H + +#define FUZZ_PROJECT_NAME "clearusergrantedpermissionstate_fuzzer" + +#endif // TEST_FUZZTEST_CLEARUSERGRANTEDPERMISSIONSTATE_FUZZER_H diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/corpus/init b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/project.xml b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..97bd5ba28f1d235384f0cc859c532ed2072e20ae --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("DeleteRemoteDeviceTokensFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "deleteremotedevicetokens_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/corpus/init b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3350c7640ad7b6e7298d5745323369c6e5abd0ec --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "deleteremotedevicetokens_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + + +namespace OHOS { + bool DeleteRemoteDeviceTokensFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + +#ifdef TOKEN_SYNC_ENABLE + + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + result = AccessTokenKit::DeleteRemoteDeviceTokens(reinterpret_cast(data)); + } + +#endif + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + + OHOS::DeleteRemoteDeviceTokensFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.h b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..efd039c24f6f323db433554f182097556c6991af --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.h @@ -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 TEST_FUZZTEST_DELETEREMOTEDEVICETOKENS_FUZZER_H +#define TEST_FUZZTEST_DELETEREMOTEDEVICETOKENS_FUZZER_H + +#define FUZZ_PROJECT_NAME "deleteremotedevicetokens_fuzzer" + +#endif // TEST_FUZZTEST_DELETEREMOTEDEVICETOKENS_FUZZER_H diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9ff378294d1d0eacefd2fcebeb246dc318824791 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("DeleteRemoteTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/deleteremotetoken_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "deleteremotetoken_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/corpus/init b/test/fuzztest/access_token/deleteremotetoken_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bcd031a6b9b30fb70605e526d33b19fa692ed059 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "deleteremotetoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool DeleteRemoteTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + +#ifdef TOKEN_SYNC_ENABLE + + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::DeleteRemoteToken(reinterpret_cast(data), TOKENID); + } + +#endif + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DeleteRemoteTokenFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.h b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..59403459468e450c202b7554d39020ce27f2bac0 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.h @@ -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 TEST_FUZZTEST_DELETEREMOTETOKEN_FUZZER_H +#define TEST_FUZZTEST_DELETEREMOTETOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "deleteremotetoken_fuzzer" + +#endif // TEST_FUZZTEST_DELETEREMOTETOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml b/test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1f0cc35a521958433abc7965e1d0bba5590a8aef --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("DeleteTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/deletetoken_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "deletetoken_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/corpus/init b/test/fuzztest/access_token/deletetoken_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.cpp b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93cd4c843549dcad49abf15d9631e1d4f9efec15 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "deletetoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool DeleteTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::DeleteToken(TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DeleteTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.h b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1f0a40115558ed89cd88cc0524604e04c711ccc0 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.h @@ -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 TEST_FUZZTEST_DELETETOKEN_FUZZER_H +#define TEST_FUZZTEST_DELETETOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "deletetoken_fuzzer" + +#endif // TEST_FUZZTEST_DELETETOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/project.xml b/test/fuzztest/access_token/deletetoken_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn index 92743d205ee20c87f6ae03a3d1a969aa8877e955..6b4f7ae032a80008cbf29a43dbbf8b4cb297a805 100644 --- a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("GetDefPermissionFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":GetDefPermissionFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp index aa3218083b20ce0b7a5879a895933fbab5a40c03..38fbe3a3ddc46e595bc1ac7e530a02c15ea8d463 100644 --- a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp @@ -30,21 +30,23 @@ namespace OHOS { bool GetDefPermissionFuzzTest(const uint8_t* data, size_t size) { bool result = false; + std::string testdata; if ((data == nullptr) || (size <= 0)) { return result; } if (size > 0) { + testdata = reinterpret_cast(data); PermissionDef PERMISSIONDEF = { - .permissionName = reinterpret_cast(data), - .bundleName = reinterpret_cast(data), + .permissionName = testdata, + .bundleName = testdata, .grantMode = 1, - .label = reinterpret_cast(data), + .label = testdata, .labelId = 1, - .description = reinterpret_cast(data), + .description = testdata, .availableLevel = APL_NORMAL, .descriptionId = 1 }; - result = AccessTokenKit::GetDefPermission(reinterpret_cast(data), PERMISSIONDEF); + result = AccessTokenKit::GetDefPermission(testdata, PERMISSIONDEF); } return result; } diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn index 9a70902d003d75d724b07a7d6f7389255c74b733..0ee9e2ade010101dfb207cddfc879e977f88896e 100644 --- a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("GetPermissionFlagsFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":GetPermissionFlagsFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn index 987aa46ac8ea8d1129c9580245fea714f5c9e80b..54534c61e163bc5c765facbcfe9e975ac979e142 100644 --- a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("GrantPermissionFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":GrantPermissionFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn index ba5d208a14e4a88b0fcb6d1c5b3fdc49fd363a8a..b12e589984b4c50f700257335b7d380c1be63b95 100644 --- a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":RevokeUserGrantedPermissionFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8160aaf1f38ca7b609c94fe263640db29eb3b3dd --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("SetRemoteHapTokenInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "setremotehaptokeninfo_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/corpus/init b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/project.xml b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4b69c86f24236a6ac91dd1280f76f0d2a58e8cc --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * 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 "setremotehaptokeninfo_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool SetRemoteHapTokenInfoFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; +#ifdef TOKEN_SYNC_ENABLE + std::string testdata; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + testdata = reinterpret_cast(data); + AccessTokenID TOKENID = static_cast(size); + HapTokenInfo baseInfo = { + .apl = APL_NORMAL, + .ver = 1, + .userID = 1, + .bundleName = testdata, + .instIndex = 1, + .appID = testdata, + .deviceID = testdata, + .tokenID = TOKENID, + .tokenAttr = 0 + }; + PermissionStateFull infoManagerTestState = { + .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .isGeneral = true, + .permissionName = testdata, + .resDeviceID = {testdata}}; + std::vector permStateList; + permStateList.emplace_back(infoManagerTestState); + HapTokenInfoForSync remoteTokenInfo = { + .baseInfo = baseInfo, + .permStateList = permStateList + }; + + result = AccessTokenKit::SetRemoteHapTokenInfo(reinterpret_cast(data), remoteTokenInfo); + } +#endif + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetRemoteHapTokenInfoFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.h b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2a06877e6d6647dc4690b022a93572043f7ee10e --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.h @@ -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 TEST_FUZZTEST_SETREMOTEHAPTOKENINFO_FUZZER_H +#define TEST_FUZZTEST_SETREMOTEHAPTOKENINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "setremotehaptokeninfo_fuzzer" + +#endif // TEST_FUZZTEST_SETREMOTEHAPTOKENINFO_FUZZER_H diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c9db092dcbc067b3e666d178a325f59b1035cce6 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("SetRemoteNativeTokenInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "setremotenativetokeninfo_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/corpus/init b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/project.xml b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60f33a71144027afb6122c3a324c2bd77cc758a0 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * 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 "setremotenativetokeninfo_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool SetRemoteNativeTokenInfoFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + +#ifdef TOKEN_SYNC_ENABLE + + std::string testdata; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + testdata = reinterpret_cast(data); + AccessTokenID TOKENID = static_cast(size); + NativeTokenInfoForSync native1 = { + .baseInfo.apl = APL_NORMAL, + .baseInfo.ver = 1, + .baseInfo.processName = testdata, + .baseInfo.dcap = {testdata, testdata}, + .baseInfo.tokenID = TOKENID, + .baseInfo.tokenAttr = 0, + .baseInfo.nativeAcls = {testdata}, + }; + + std::vector nativeTokenInfoList; + nativeTokenInfoList.emplace_back(native1); + + result = AccessTokenKit::SetRemoteNativeTokenInfo(reinterpret_cast(data), nativeTokenInfoList); + } + +#endif + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetRemoteNativeTokenInfoFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.h b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4c681fd784522931fb9ccbd1c7bd34410d6f7f42 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.h @@ -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 TEST_FUZZTEST_SETREMOTENATIVETOKENINFO_FUZZER_H +#define TEST_FUZZTEST_SETREMOTENATIVETOKENINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "setremotenativetokeninfo_fuzzer" + +#endif // TEST_FUZZTEST_SETREMOTENATIVETOKENINFO_FUZZER_H diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9a7c0c830d71f10a3f342868a9ac63443f6a9750 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("UpdateHapTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/updatehaptoken_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "updatehaptoken_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/corpus/init b/test/fuzztest/access_token/updatehaptoken_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/project.xml b/test/fuzztest/access_token/updatehaptoken_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fcdd1c352671d7f0e66154459457980e20e3a42 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp @@ -0,0 +1,74 @@ +/* + * 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 "updatehaptoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool UpdateHapTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + std::string testdata; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + testdata = reinterpret_cast(data); + PermissionDef TestPermDef = { + .permissionName = testdata, + .bundleName = testdata, + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = testdata, + .labelId = 1, + .description = testdata, + .descriptionId = 1 + }; + PermissionStateFull TestState = { + .permissionName = testdata, + .isGeneral = true, + .resDeviceID = {testdata}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1}, + }; + HapPolicyParams TestPolicyPrams = { + .apl = APL_NORMAL, + .domain = testdata, + .permList = {TestPermDef}, + .permStateList = {TestState} + }; + + result = AccessTokenKit::UpdateHapToken(TOKENID, testdata, TestPolicyPrams); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::UpdateHapTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.h b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5eb0c5ea1c58c45db5117f4cf9765a1d673c294b --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.h @@ -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 TEST_FUZZTEST_UPDATEHAPTOKEN_FUZZER_H +#define TEST_FUZZTEST_UPDATEHAPTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "updatehaptoken_fuzzer" + +#endif // TEST_FUZZTEST_UPDATEHAPTOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..77851ad1b8cbbbe1e724b8d20a0ac59a0896f8bb --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("VerifyAccessToken001FuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken001_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "verifyaccesstoken001_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/corpus/init b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/project.xml b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.cpp b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec6ff93689895931158108758bef7fe98290192e --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "verifyaccesstoken001_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool VerifyAccessToken001FuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::VerifyAccessToken(TOKENID, TOKENID, reinterpret_cast(data)); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::VerifyAccessToken001FuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.h b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..78473a298a95afcf1683d9bf8739044c035b4547 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.h @@ -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 TEST_FUZZTEST_VERIFYACCESSTOKEN001_FUZZER_H +#define TEST_FUZZTEST_VERIFYACCESSTOKEN001_FUZZER_H + +#define FUZZ_PROJECT_NAME "verifyaccesstoken001_fuzzer" + +#endif // TEST_FUZZTEST_VERIFYACCESSTOKEN001_FUZZER_H diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn index 3357958b6692e855f8525232544502bc4fe6e595..cc08fd4fc856304db56ebb5f9382610f5fd8dcb4 100644 --- a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("VerifyAccessTokenFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":VerifyAccessTokenFuzzTest", - ] -}