diff --git a/bundle.json b/bundle.json index 5407eee174ea2c9bac9247eb4f2f51d3edefa53f..462bda7bb20bf7501d7345e837553b30494672c9 100644 --- a/bundle.json +++ b/bundle.json @@ -79,8 +79,13 @@ "//base/security/access_token/interfaces/innerkits/accesstoken/test:unittest", "//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/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" ] } } -} +} \ No newline at end of file diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..92743d205ee20c87f6ae03a3d1a969aa8877e955 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn @@ -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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("GetDefPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/getdefpermission_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/frameworks/common/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "getdefpermission_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", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":GetDefPermissionFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/corpus/init b/test/fuzztest/access_token/getdefpermission_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_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/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa3218083b20ce0b7a5879a895933fbab5a40c03 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "getdefpermission_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" +#include "permission_def.h" + +using namespace std; +using namespace OHOS; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool GetDefPermissionFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + PermissionDef PERMISSIONDEF = { + .permissionName = reinterpret_cast(data), + .bundleName = reinterpret_cast(data), + .grantMode = 1, + .label = reinterpret_cast(data), + .labelId = 1, + .description = reinterpret_cast(data), + .availableLevel = APL_NORMAL, + .descriptionId = 1 + }; + result = AccessTokenKit::GetDefPermission(reinterpret_cast(data), PERMISSIONDEF); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GetDefPermissionFuzzTest(data, size); + return 0; +} + \ No newline at end of file diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.h b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5d8983a592458abc0ff65f186080a583908986bb --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_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_GETDEFPERMISSION_FUZZER_H +#define TEST_FUZZTEST_GETDEFPERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "getdefpermission_fuzzer" + +#endif // TEST_FUZZTEST_GETDEFPERMISSION_FUZZER_H diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/project.xml b/test/fuzztest/access_token/getdefpermission_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9a70902d003d75d724b07a7d6f7389255c74b733 --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn @@ -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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("GetPermissionFlagsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/getpermissionflags_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 = [ "getpermissionflags_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", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":GetPermissionFlagsFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/corpus/init b/test/fuzztest/access_token/getpermissionflags_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_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/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9175d62dd4c63ebcaf8b08ee0c5ef42639fdd93a --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_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 "getpermissionflags_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool GetPermissionFlagsFuzzTest(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::GetPermissionFlag(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::GetPermissionFlagsFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.h b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8d7b1d347a41cddd8ce30aad40d1daf3564689b4 --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_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_GETPERMISSIONFLAGS_FUZZER_H +#define TEST_FUZZTEST_GETPERMISSIONFLAGS_FUZZER_H + +#define FUZZ_PROJECT_NAME "getpermissionflags_fuzzer" + +#endif // TEST_FUZZTEST_GETPERMISSIONFLAGS_FUZZER_H diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml b/test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..987aa46ac8ea8d1129c9580245fea714f5c9e80b --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn @@ -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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("GrantPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/grantpermission_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 = [ "grantpermission_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", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":GrantPermissionFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/corpus/init b/test/fuzztest/access_token/grantpermission_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_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/grantpermission_fuzzer/grantpermission_fuzzer.cpp b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b821ba9744ec018eb45bb31217aea99ec792b8ec --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_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 "grantpermission_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool GrantPermissionFuzzTest(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::GrantPermission(TOKENID, reinterpret_cast(data), 0); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GrantPermissionFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.h b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..64a6c5498d555a76646ea90f7b5686c8105815e1 --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_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_GRANTPERMISSION_FUZZER_H +#define TEST_FUZZTEST_GRANTPERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "grantpermission_fuzzer" + +#endif // TEST_FUZZTEST_GRANTPERMISSION_FUZZER_H diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/project.xml b/test/fuzztest/access_token/grantpermission_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ba5d208a14e4a88b0fcb6d1c5b3fdc49fd363a8a --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn @@ -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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/revokeusergrantedpermission_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 = [ "revokeusergrantedpermission_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", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":RevokeUserGrantedPermissionFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/corpus/init b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_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/revokeusergrantedpermission_fuzzer/project.xml b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2a1dc550d10526de2c9cc44bbac700a3e70ff93 --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_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 "revokeusergrantedpermission_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool RevokeUserGrantedPermissionFuzzTest(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::RevokePermission(TOKENID, reinterpret_cast(data), 0); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::RevokeUserGrantedPermissionFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.h b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..3324007c9e059a6d0aa176f42a5d0fbcb21ccbdb --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_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_REVOKEUSERGRANTEDPERMISSION_FUZZER_H +#define TEST_FUZZTEST_REVOKEUSERGRANTEDPERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "revokeusergrantedpermission_fuzzer" + +#endif // TEST_FUZZTEST_REVOKEUSERGRANTEDPERMISSION_FUZZER_H diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3357958b6692e855f8525232544502bc4fe6e595 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn @@ -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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("VerifyAccessTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken_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 = [ "verifyaccesstoken_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", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":VerifyAccessTokenFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/corpus/init b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_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/verifyaccesstoken_fuzzer/project.xml b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de192b189201ad65264335e22dc077c2acc86a1a --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_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 "verifyaccesstoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool VerifyAccessTokenFuzzTest(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, 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::VerifyAccessTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.h b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c754140f295aef50c4d264d537690ab566d88359 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_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_VERIFYACCESSTOKEN_FUZZER_H +#define TEST_FUZZTEST_VERIFYACCESSTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "verifyaccesstoken_fuzzer" + +#endif // TEST_FUZZTEST_VERIFYACCESSTOKEN_FUZZER_H