diff --git a/frameworks/common/include/accesstoken_log.h b/frameworks/common/include/accesstoken_log.h index 43dbf3ad8da00bc436e3d93931cd0df868db5355..1d39a673db81cd442c05ea70c375df730f5b637a 100644 --- a/frameworks/common/include/accesstoken_log.h +++ b/frameworks/common/include/accesstoken_log.h @@ -57,14 +57,6 @@ static constexpr unsigned int SECURITY_DOMAIN_PRIVACY = 0xD005A02; return; \ } \ } while (0) - -#define IF_FALSE_RETURN_VAL_LOG(label, cond, ret, fmt, ...) \ - do { \ - if (!(cond)) { \ - ACCESSTOKEN_LOG_ERROR(label, fmt, ##__VA_ARGS__); \ - return ret; \ - } \ - } while (0) #else #include @@ -85,6 +77,14 @@ static constexpr unsigned int SECURITY_DOMAIN_PRIVACY = 0xD005A02; ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ } \ } while (0) + +#define IF_FALSE_RETURN_LOG(cond, fmt, ...) \ + do { \ + if (!(cond)) { \ + ACCESSTOKEN_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) #endif // HILOG_ENABLE #endif // ACCESSTOKEN_LOG_H diff --git a/frameworks/privacy/BUILD.gn b/frameworks/privacy/BUILD.gn index dc032de9122b1f0649ff829b3439cb482fa2331f..b452f0cda89a9310f87a1c980fb21a5b32c4ff2b 100644 --- a/frameworks/privacy/BUILD.gn +++ b/frameworks/privacy/BUILD.gn @@ -39,13 +39,20 @@ ohos_shared_library("privacy_communication_adapter_cxx") { ] sources = [ + "src/add_perm_param_info_parcel.cpp", "src/bundle_used_record_parcel.cpp", "src/perm_active_response_parcel.cpp", "src/permission_used_record_parcel.cpp", + "src/permission_used_request_parcel.cpp", "src/permission_used_result_parcel.cpp", "src/permission_used_type_info_parcel.cpp", "src/used_record_detail_parcel.cpp", ] external_deps = [ "c_utils:utils" ] + + if (security_component_enhance_enable) { + sources += [ "src/sec_comp_enhance_data_parcel.cpp" ] + external_deps += [ "ipc:ipc_single" ] + } } diff --git a/frameworks/privacy/include/add_perm_param_info_parcel.h b/frameworks/privacy/include/add_perm_param_info_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..abfc4ed24a640e54023d482045eeb460a55c66a3 --- /dev/null +++ b/frameworks/privacy/include/add_perm_param_info_parcel.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ADD_PERMISSION_PARAM_INFO_PARCEL_H +#define ADD_PERMISSION_PARAM_INFO_PARCEL_H + +#include "parcel.h" +#include "add_perm_param_info.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +struct AddPermParamInfoParcel final : public Parcelable { + AddPermParamInfoParcel() = default; + + ~AddPermParamInfoParcel() override = default; + + bool Marshalling(Parcel& out) const override; + + static AddPermParamInfoParcel* Unmarshalling(Parcel& in); + + AddPermParamInfo info; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // ADD_PERMISSION_PARAM_INFO_PARCEL_H diff --git a/frameworks/privacy/include/i_privacy_manager.h b/frameworks/privacy/include/i_privacy_manager.h index 1d3e0496b93bac3241a37dfea29770c157e74531..3d2d8ef6b0f5d85cc53a7e0293c7965a7be4f925 100644 --- a/frameworks/privacy/include/i_privacy_manager.h +++ b/frameworks/privacy/include/i_privacy_manager.h @@ -19,18 +19,18 @@ #include #include "access_token.h" -#include "add_perm_param_info.h" +#include "add_perm_param_info_parcel.h" #include "errors.h" #include "iremote_broker.h" #include "on_permission_used_record_callback.h" #include "privacy_service_ipc_interface_code.h" -#include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "permission_used_result_parcel.h" #include "permission_used_type_info_parcel.h" #include "privacy_param.h" #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE -#include "sec_comp_enhance_data.h" +#include "sec_comp_enhance_data_parcel.h" #endif /* SAID:3505 */ @@ -43,16 +43,16 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.accesstoken.IPrivacyManager"); - virtual int32_t AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode = false) = 0; + virtual int32_t AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode = false) = 0; virtual int32_t StartUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName) = 0; virtual int32_t StartUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName, const sptr& callback) = 0; virtual int32_t StopUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName) = 0; virtual int32_t RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) = 0; virtual int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, PermissionUsedResultParcel& result) = 0; + const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) = 0; virtual int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, const sptr& callback) = 0; + const PermissionUsedRequestParcel& request, const sptr& callback) = 0; virtual int32_t RegisterPermActiveStatusCallback( std::vector& permList, const sptr& callback) = 0; virtual int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) = 0; @@ -60,11 +60,11 @@ public: virtual int32_t SetMutePolicy(uint32_t policyType, uint32_t callerType, bool isMute) = 0; virtual int32_t SetHapWithFGReminder(uint32_t tokenId, bool isAllowed) = 0; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - virtual int32_t RegisterSecCompEnhance(const SecCompEnhanceData& enhance) = 0; + virtual int32_t RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) = 0; virtual int32_t UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) = 0; - virtual int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhance) = 0; + virtual int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceDataParcel& enhanceParcel) = 0; virtual int32_t GetSpecialSecCompEnhance(const std::string& bundleName, - std::vector& enhanceList) = 0; + std::vector& enhanceParcelList) = 0; #endif virtual int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, std::vector& resultsParcel) = 0; diff --git a/frameworks/privacy/include/permission_used_request_parcel.h b/frameworks/privacy/include/permission_used_request_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..e0146d5218af02289faf259cfe6414960ae48dce --- /dev/null +++ b/frameworks/privacy/include/permission_used_request_parcel.h @@ -0,0 +1,40 @@ +/* + * 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 PERMISSION_USED_REQUEST_PARCEL_H +#define PERMISSION_USED_REQUEST_PARCEL_H + +#include "parcel.h" +#include "permission_used_request.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +struct PermissionUsedRequestParcel final : public Parcelable { + PermissionUsedRequestParcel() = default; + + ~PermissionUsedRequestParcel() override = default; + + bool Marshalling(Parcel& out) const override; + + static PermissionUsedRequestParcel* Unmarshalling(Parcel& in); + + PermissionUsedRequest request; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // PERMISSION_USED_REQUEST_PARCEL_H diff --git a/frameworks/privacy/include/sec_comp_enhance_data_parcel.h b/frameworks/privacy/include/sec_comp_enhance_data_parcel.h new file mode 100644 index 0000000000000000000000000000000000000000..6110b06589dc181f8829adc651f9ae55b39d8ce8 --- /dev/null +++ b/frameworks/privacy/include/sec_comp_enhance_data_parcel.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SEC_COMP_ENHANCE_DATA_PARCEL_H +#define SEC_COMP_ENHANCE_DATA_PARCEL_H + +#include "parcel.h" +#include "sec_comp_enhance_data.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +struct SecCompEnhanceDataParcel final : public Parcelable { + SecCompEnhanceDataParcel() = default; + + ~SecCompEnhanceDataParcel() override = default; + + bool Marshalling(Parcel& out) const override; + + static SecCompEnhanceDataParcel* Unmarshalling(Parcel& in); + + SecCompEnhanceData enhanceData; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // SEC_COMP_ENHANCE_DATA_PARCEL_H diff --git a/frameworks/privacy/src/add_perm_param_info_parcel.cpp b/frameworks/privacy/src/add_perm_param_info_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd4f8ed482984926b0e0bb3d2b5d36997aa340db --- /dev/null +++ b/frameworks/privacy/src/add_perm_param_info_parcel.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "add_perm_param_info_parcel.h" +#include "parcel_utils.h" +#include "refbase.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool AddPermParamInfoParcel::Marshalling(Parcel& out) const +{ + RETURN_IF_FALSE(out.WriteUint32(this->info.tokenId)); + RETURN_IF_FALSE(out.WriteString(this->info.permissionName)); + RETURN_IF_FALSE(out.WriteInt32(this->info.successCount)); + RETURN_IF_FALSE(out.WriteInt32(this->info.failCount)); + RETURN_IF_FALSE(out.WriteUint32(static_cast(this->info.type))); + return true; +} + +AddPermParamInfoParcel* AddPermParamInfoParcel::Unmarshalling(Parcel& in) +{ + auto* infoParcel = new (std::nothrow) AddPermParamInfoParcel(); + if (infoParcel == nullptr) { + return nullptr; + } + + RELEASE_IF_FALSE(in.ReadUint32(infoParcel->info.tokenId), infoParcel); + RELEASE_IF_FALSE(in.ReadString(infoParcel->info.permissionName), infoParcel); + RELEASE_IF_FALSE(in.ReadInt32(infoParcel->info.successCount), infoParcel); + RELEASE_IF_FALSE(in.ReadInt32(infoParcel->info.failCount), infoParcel); + uint32_t type = 0; + RELEASE_IF_FALSE(in.ReadUint32(type), infoParcel); + infoParcel->info.type = static_cast(type); + + return infoParcel; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/frameworks/privacy/src/permission_used_request_parcel.cpp b/frameworks/privacy/src/permission_used_request_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f4a3fb4d07b40a8efeb3466677b1e4410c83765 --- /dev/null +++ b/frameworks/privacy/src/permission_used_request_parcel.cpp @@ -0,0 +1,68 @@ +/* + * 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 "permission_used_request_parcel.h" +#include "parcel_utils.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool PermissionUsedRequestParcel::Marshalling(Parcel& out) const +{ + RETURN_IF_FALSE(out.WriteUint32(this->request.tokenId)); + RETURN_IF_FALSE(out.WriteBool(this->request.isRemote)); + RETURN_IF_FALSE(out.WriteString(this->request.deviceId)); + RETURN_IF_FALSE(out.WriteString(this->request.bundleName)); + + RETURN_IF_FALSE(out.WriteUint32(this->request.permissionList.size())); + for (const auto& perm : this->request.permissionList) { + RETURN_IF_FALSE(out.WriteString(perm)); + } + RETURN_IF_FALSE(out.WriteInt64(this->request.beginTimeMillis)); + RETURN_IF_FALSE(out.WriteInt64(this->request.endTimeMillis)); + RETURN_IF_FALSE(out.WriteInt32(this->request.flag)); + return true; +} + +PermissionUsedRequestParcel* PermissionUsedRequestParcel::Unmarshalling(Parcel& in) +{ + auto* requestParcel = new (std::nothrow) PermissionUsedRequestParcel(); + if (requestParcel == nullptr) { + return nullptr; + } + + RELEASE_IF_FALSE(in.ReadUint32(requestParcel->request.tokenId), requestParcel); + RELEASE_IF_FALSE(in.ReadBool (requestParcel->request.isRemote), requestParcel); + RELEASE_IF_FALSE(in.ReadString(requestParcel->request.deviceId), requestParcel); + RELEASE_IF_FALSE(in.ReadString(requestParcel->request.bundleName), requestParcel); + + uint32_t permSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(permSize), requestParcel); + RELEASE_IF_FALSE(permSize <= MAX_PERMLIST_SIZE, requestParcel); + for (uint32_t i = 0; i < permSize; i++) { + std::string perm; + RELEASE_IF_FALSE(in.ReadString(perm), requestParcel); + requestParcel->request.permissionList.emplace_back(perm); + } + RELEASE_IF_FALSE(in.ReadInt64(requestParcel->request.beginTimeMillis), requestParcel); + RELEASE_IF_FALSE(in.ReadInt64(requestParcel->request.endTimeMillis), requestParcel); + int32_t flag; + RELEASE_IF_FALSE(in.ReadInt32(flag), requestParcel); + requestParcel->request.flag = static_cast(flag); + return requestParcel; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/frameworks/privacy/src/sec_comp_enhance_data_parcel.cpp b/frameworks/privacy/src/sec_comp_enhance_data_parcel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce60f7724b7d81fddfe88bd5815bd64598be1535 --- /dev/null +++ b/frameworks/privacy/src/sec_comp_enhance_data_parcel.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sec_comp_enhance_data_parcel.h" + +#include + +#include "parcel_utils.h" +#include "securec.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool SecCompEnhanceDataParcel::Marshalling(Parcel& out) const +{ + RETURN_IF_FALSE(out.WriteInt32(this->enhanceData.pid)); + RETURN_IF_FALSE(out.WriteUint32(this->enhanceData.token)); + RETURN_IF_FALSE(out.WriteUint64(this->enhanceData.challenge)); + RETURN_IF_FALSE(out.WriteUint32(this->enhanceData.sessionId)); + RETURN_IF_FALSE(out.WriteUint32(this->enhanceData.seqNum)); + RETURN_IF_FALSE(out.WriteBuffer(this->enhanceData.key, AES_KEY_STORAGE_LEN)); + RETURN_IF_FALSE((static_cast(&out))->WriteRemoteObject(this->enhanceData.callback)); + return true; +} + +SecCompEnhanceDataParcel* SecCompEnhanceDataParcel::Unmarshalling(Parcel& in) +{ + auto* enhanceDataParcel = new (std::nothrow) SecCompEnhanceDataParcel(); + if (enhanceDataParcel == nullptr) { + return nullptr; + } + + RELEASE_IF_FALSE(in.ReadInt32(enhanceDataParcel->enhanceData.pid), enhanceDataParcel); + RELEASE_IF_FALSE(in.ReadUint32(enhanceDataParcel->enhanceData.token), enhanceDataParcel); + RELEASE_IF_FALSE(in.ReadUint64(enhanceDataParcel->enhanceData.challenge), enhanceDataParcel); + RELEASE_IF_FALSE(in.ReadUint32(enhanceDataParcel->enhanceData.sessionId), enhanceDataParcel); + RELEASE_IF_FALSE(in.ReadUint32(enhanceDataParcel->enhanceData.seqNum), enhanceDataParcel); + const uint8_t* ptr = in.ReadBuffer(AES_KEY_STORAGE_LEN); + if (ptr == nullptr) { + delete enhanceDataParcel; + return nullptr; + } + if (memcpy_s(enhanceDataParcel->enhanceData.key, AES_KEY_STORAGE_LEN, ptr, AES_KEY_STORAGE_LEN) != EOK) { + delete enhanceDataParcel; + return nullptr; + } + + enhanceDataParcel->enhanceData.callback = (static_cast(&in))->ReadRemoteObject(); + if (enhanceDataParcel->enhanceData.callback == nullptr) { + delete enhanceDataParcel; + return nullptr; + } + + return enhanceDataParcel; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + diff --git a/frameworks/test/unittest/privacy_parcel_test.cpp b/frameworks/test/unittest/privacy_parcel_test.cpp index d4845934b55659d9f0c0abff2f95608db0ab3e08..ecfaa99471dba3a04b30e8fc5ca578b8c21b41c9 100644 --- a/frameworks/test/unittest/privacy_parcel_test.cpp +++ b/frameworks/test/unittest/privacy_parcel_test.cpp @@ -22,6 +22,7 @@ #include "parcel_utils.h" #include "perm_active_response_parcel.h" #include "permission_used_record_parcel.h" +#include "permission_used_request_parcel.h" #include "permission_used_result_parcel.h" #include "used_record_detail_parcel.h" @@ -240,6 +241,47 @@ HWTEST_F(PrivacyParcelTest, PermissionUsedRecordParcel001, TestSize.Level1) } } +/** + * @tc.name: PermissionUsedRequestParcel001 + * @tc.desc: Verify the PermissionUsedRequestParcel Marshalling and Unmarshalling function. + * @tc.type: FUNC + * @tc.require: issueI5RUP1 + */ +HWTEST_F(PrivacyParcelTest, PermissionUsedRequestParcel001, TestSize.Level1) +{ + PermissionUsedRequestParcel permissionUsedRequestParcel; + + permissionUsedRequestParcel.request = { + .tokenId = 100, + .isRemote = false, + .deviceId = "you guess", + .bundleName = "com.ohos.permissionmanager", + .beginTimeMillis = 0L, + .endTimeMillis = 0L, + .flag = FLAG_PERMISSION_USAGE_SUMMARY, + }; + permissionUsedRequestParcel.request.permissionList.emplace_back("ohos.permission.CAMERA"); + permissionUsedRequestParcel.request.permissionList.emplace_back("ohos.permission.LOCATION"); + + Parcel parcel; + EXPECT_EQ(true, permissionUsedRequestParcel.Marshalling(parcel)); + + std::shared_ptr readedData(PermissionUsedRequestParcel::Unmarshalling(parcel)); + EXPECT_EQ(true, readedData != nullptr); + + EXPECT_EQ(permissionUsedRequestParcel.request.tokenId, readedData->request.tokenId); + EXPECT_EQ(permissionUsedRequestParcel.request.isRemote, readedData->request.isRemote); + EXPECT_EQ(permissionUsedRequestParcel.request.deviceId, readedData->request.deviceId); + EXPECT_EQ(permissionUsedRequestParcel.request.bundleName, readedData->request.bundleName); + EXPECT_EQ(permissionUsedRequestParcel.request.beginTimeMillis, readedData->request.beginTimeMillis); + EXPECT_EQ(permissionUsedRequestParcel.request.endTimeMillis, readedData->request.endTimeMillis); + EXPECT_EQ(permissionUsedRequestParcel.request.flag, readedData->request.flag); + + for (uint32_t i = 0; i < permissionUsedRequestParcel.request.permissionList.size(); i++) { + EXPECT_EQ(permissionUsedRequestParcel.request.permissionList[i], readedData->request.permissionList[i]); + } +} + /** * @tc.name: PermissionUsedResultParcel001 * @tc.desc: Verify the PermissionUsedResultParcel Marshalling and Unmarshalling function. @@ -389,6 +431,40 @@ HWTEST_F(PrivacyParcelTest, PermissionUsedRecordParcel002, TestSize.Level1) EXPECT_EQ(true, readedData2 == nullptr); } +/** + * @tc.name: PermissionUsedRequestParcel002 + * @tc.desc: Verify the PermissionUsedRequestParcel Marshalling and Unmarshalling function. + * @tc.type: FUNC + * @tc.require: issueI5RUP1 + */ +HWTEST_F(PrivacyParcelTest, PermissionUsedRequestParcel002, TestSize.Level1) +{ + PermissionUsedRequestParcel permissionUsedRequestParcel; + + permissionUsedRequestParcel.request = { + .tokenId = 100, + .isRemote = false, + .deviceId = "deviceId", + .bundleName = "com.ohos.permissionmanager", + .beginTimeMillis = 0L, + .endTimeMillis = 0L, + .flag = FLAG_PERMISSION_USAGE_SUMMARY, + }; + for (uint32_t i = 0; i < MAX_PERMLIST_SIZE; i++) { + permissionUsedRequestParcel.request.permissionList.emplace_back("ohos.permission.CAMERA"); + } + + Parcel parcel; + EXPECT_EQ(true, permissionUsedRequestParcel.Marshalling(parcel)); + std::shared_ptr readedData(PermissionUsedRequestParcel::Unmarshalling(parcel)); + EXPECT_NE(readedData, nullptr); + + permissionUsedRequestParcel.request.permissionList.emplace_back("ohos.permission.CAMERA"); + Parcel parcel1; + EXPECT_EQ(true, permissionUsedRequestParcel.Marshalling(parcel1)); + std::shared_ptr readedData1(PermissionUsedRequestParcel::Unmarshalling(parcel1)); + EXPECT_EQ(readedData1, nullptr); +} /** * @tc.name: PermissionUsedResultParcel002 diff --git a/interfaces/innerkits/accesstoken/include/sec_comp_enhance_data.h b/interfaces/innerkits/accesstoken/include/sec_comp_enhance_data.h index 97c08c89e3baf264465196d54468c1b7e671375a..c5be2919cca3229dda34b492dfb652300c1f1946 100644 --- a/interfaces/innerkits/accesstoken/include/sec_comp_enhance_data.h +++ b/interfaces/innerkits/accesstoken/include/sec_comp_enhance_data.h @@ -51,6 +51,10 @@ struct SecCompEnhanceData { * callback remote object for checking security component valid. */ sptr callback; + /** + * pid for which used security component. + */ + int32_t pid; /** * token id for which used security component. */ diff --git a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp index 3ec4bc49f26b437cf3da88ff6c3e7cdef75ca9dd..944761a1235eee327ea2f8ef19a5f56705097e78 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp @@ -20,7 +20,7 @@ #include "privacy_error.h" #include "privacy_manager_proxy.h" #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE -#include "sec_comp_enhance_data.h" +#include "sec_comp_enhance_data_parcel.h" #endif namespace OHOS { @@ -65,7 +65,9 @@ int32_t PrivacyManagerClient::AddPermissionUsedRecord(const AddPermParamInfo& in ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); return PrivacyError::ERR_SERVICE_ABNORMAL; } - return proxy->AddPermissionUsedRecord(info, asyncMode); + AddPermParamInfoParcel infoParcel; + infoParcel.info = info; + return proxy->AddPermissionUsedRecord(infoParcel, asyncMode); } int32_t PrivacyManagerClient::StartUsingPermission( @@ -167,8 +169,10 @@ int32_t PrivacyManagerClient::GetPermissionUsedRecords( return PrivacyError::ERR_SERVICE_ABNORMAL; } + PermissionUsedRequestParcel requestParcel; PermissionUsedResultParcel resultParcel; - int32_t ret = proxy->GetPermissionUsedRecords(request, resultParcel); + requestParcel.request = request; + int32_t ret = proxy->GetPermissionUsedRecords(requestParcel, resultParcel); result = resultParcel.result; return ret; } @@ -182,7 +186,9 @@ int32_t PrivacyManagerClient::GetPermissionUsedRecords(const PermissionUsedReque return PrivacyError::ERR_SERVICE_ABNORMAL; } - return proxy->GetPermissionUsedRecords(request, callback); + PermissionUsedRequestParcel requestParcel; + requestParcel.request = request; + return proxy->GetPermissionUsedRecords(requestParcel, callback); } int32_t PrivacyManagerClient::CreateActiveStatusChangeCbk( @@ -283,7 +289,9 @@ int32_t PrivacyManagerClient::RegisterSecCompEnhance(const SecCompEnhanceData& e ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } - return proxy->RegisterSecCompEnhance(enhance); + SecCompEnhanceDataParcel registerParcel; + registerParcel.enhanceData = enhance; + return proxy->RegisterSecCompEnhance(registerParcel); } int32_t PrivacyManagerClient::UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) @@ -303,10 +311,12 @@ int32_t PrivacyManagerClient::GetSecCompEnhance(int32_t pid, SecCompEnhanceData& ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } - int32_t res = proxy->GetSecCompEnhance(pid, enhance); + SecCompEnhanceDataParcel parcel; + int32_t res = proxy->GetSecCompEnhance(pid, parcel); if (res != RET_SUCCESS) { return res; } + enhance = parcel.enhanceData; return RET_SUCCESS; } @@ -318,7 +328,15 @@ int32_t PrivacyManagerClient::GetSpecialSecCompEnhance(const std::string& bundle ACCESSTOKEN_LOG_ERROR(LABEL, "Proxy is null."); return PrivacyError::ERR_PARAM_INVALID; } - return proxy->GetSpecialSecCompEnhance(bundleName, enhanceList); + std::vector parcelList; + int32_t res = proxy->GetSpecialSecCompEnhance(bundleName, parcelList); + if (res != RET_SUCCESS) { + return res; + } + + std::transform(parcelList.begin(), parcelList.end(), std::back_inserter(enhanceList), + [](SecCompEnhanceDataParcel pair) { return pair.enhanceData; }); + return RET_SUCCESS; } #endif diff --git a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp index e85f89990445984d344b957371a7e593250c123e..d78aa95cd50b5a5e96143f1cec12209790768e48 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp @@ -16,9 +16,7 @@ #include "privacy_manager_proxy.h" #include "accesstoken_log.h" -#include "parcel_utils.h" #include "privacy_error.h" -#include "securec.h" namespace OHOS { namespace Security { @@ -42,24 +40,20 @@ PrivacyManagerProxy::PrivacyManagerProxy(const sptr& impl) PrivacyManagerProxy::~PrivacyManagerProxy() {} -int32_t PrivacyManagerProxy::AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode) +int32_t PrivacyManagerProxy::AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode) { - MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(info.tokenId), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteString(info.permissionName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInt32(info.successCount), ERR_WRITE_PARCEL_FAILED, "WriteInt32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInt32(info.failCount), ERR_WRITE_PARCEL_FAILED, "WriteInt32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(info.type), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); + MessageParcel addData; + addData.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!addData.WriteParcelable(&infoParcel)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(infoParcel)"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; - if (!SendRequest(PrivacyInterfaceCode::ADD_PERMISSION_USED_RECORD, data, reply, asyncMode)) { - return ERR_SERVICE_ABNORMAL; + if (!SendRequest(PrivacyInterfaceCode::ADD_PERMISSION_USED_RECORD, addData, reply, asyncMode)) { + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -67,20 +61,27 @@ int32_t PrivacyManagerProxy::AddPermissionUsedRecord(const AddPermParamInfo& inf int32_t PrivacyManagerProxy::StartUsingPermission( AccessTokenID tokenID, int32_t pid, const std::string& permissionName) { - MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenID), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(pid), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permissionName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); + MessageParcel startData; + startData.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!startData.WriteUint32(tokenID)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!startData.WriteInt32(pid)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!startData.WriteString(permissionName)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permissionName"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; - if (!SendRequest(PrivacyInterfaceCode::START_USING_PERMISSION, data, reply)) { - return ERR_SERVICE_ABNORMAL; + if (!SendRequest(PrivacyInterfaceCode::START_USING_PERMISSION, startData, reply)) { + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -90,22 +91,31 @@ int32_t PrivacyManagerProxy::StartUsingPermission( const sptr& callback) { MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenID), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(pid), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permissionName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteRemoteObject(callback), ERR_WRITE_PARCEL_FAILED, "WriteRemoteObject failed."); + data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!data.WriteUint32(tokenID)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteInt32(pid)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteString(permissionName)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permissionName"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteRemoteObject(callback)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; if (!SendRequest(PrivacyInterfaceCode::START_USING_PERMISSION_CALLBACK, data, reply)) { ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest fail"); - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -113,20 +123,27 @@ int32_t PrivacyManagerProxy::StartUsingPermission( int32_t PrivacyManagerProxy::StopUsingPermission( AccessTokenID tokenID, int32_t pid, const std::string& permissionName) { - MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenID), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(pid), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permissionName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); + MessageParcel stopData; + stopData.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!stopData.WriteUint32(tokenID)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write tokenID"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!stopData.WriteInt32(pid)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!stopData.WriteString(permissionName)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permissionName"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; - if (!SendRequest(PrivacyInterfaceCode::STOP_USING_PERMISSION, data, reply)) { - return ERR_SERVICE_ABNORMAL; + if (!SendRequest(PrivacyInterfaceCode::STOP_USING_PERMISSION, stopData, reply)) { + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -134,53 +151,42 @@ int32_t PrivacyManagerProxy::StopUsingPermission( int32_t PrivacyManagerProxy::RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) { MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenID), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(deviceID), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); + data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!data.WriteUint32(tokenID)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenID); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteString(deviceID)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteString(deviceID)"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; if (!SendRequest(PrivacyInterfaceCode::DELETE_PERMISSION_USED_RECORDS, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } -int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedRequest& request, +int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) { MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(request.tokenId), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteBool(request.isRemote), ERR_WRITE_PARCEL_FAILED, "WriteBool failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(request.deviceId), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteString(request.bundleName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); - - IF_FALSE_RETURN_VAL_LOG(LABEL, - data.WriteUint32(request.permissionList.size()), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - for (const auto& perm : request.permissionList) { - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteString(perm), ERR_WRITE_PARCEL_FAILED, "WriteString(%{public}s) failed.", perm.c_str()); - } - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteInt64(request.beginTimeMillis), ERR_WRITE_PARCEL_FAILED, "WriteInt64 failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteInt64(request.endTimeMillis), ERR_WRITE_PARCEL_FAILED, "WriteInt64 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInt32(request.flag), ERR_WRITE_PARCEL_FAILED, "WriteInt32 failed."); + data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!data.WriteParcelable(&request)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(request)"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; if (!SendRequest(PrivacyInterfaceCode::GET_PERMISSION_USED_RECORDS, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t ret = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(ret), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t ret = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", ret); if (ret != RET_SUCCESS) { return ret; @@ -188,45 +194,32 @@ int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedReques sptr resultSptr = reply.ReadParcelable(); if (resultSptr == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); - return ERR_READ_PARCEL_FAILED; + return PrivacyError::ERR_READ_PARCEL_FAILED; } result = *resultSptr; return ret; } -int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedRequest& request, +int32_t PrivacyManagerProxy::GetPermissionUsedRecords(const PermissionUsedRequestParcel& request, const sptr& callback) { MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(request.tokenId), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteBool(request.isRemote), ERR_WRITE_PARCEL_FAILED, "WriteBool failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(request.deviceId), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteString(request.bundleName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); - - IF_FALSE_RETURN_VAL_LOG(LABEL, - data.WriteUint32(request.permissionList.size()), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - for (const auto& permission : request.permissionList) { - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permission), - ERR_WRITE_PARCEL_FAILED, "WriteString(%{public}s) failed.", permission.c_str()); - } - IF_FALSE_RETURN_VAL_LOG(LABEL, - data.WriteInt64(request.beginTimeMillis), ERR_WRITE_PARCEL_FAILED, "WriteInt64 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, - data.WriteInt64(request.endTimeMillis), ERR_WRITE_PARCEL_FAILED, "WriteInt64 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInt32(request.flag), ERR_WRITE_PARCEL_FAILED, "WriteInt32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, - data.WriteRemoteObject(callback->AsObject()), ERR_WRITE_PARCEL_FAILED, "WriteRemoteObject failed."); + data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!data.WriteParcelable(&request)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(request)"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteRemoteObject(callback)"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; if (!SendRequest(PrivacyInterfaceCode::GET_PERMISSION_USED_RECORDS_ASYNC, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -235,25 +228,33 @@ int32_t PrivacyManagerProxy::RegisterPermActiveStatusCallback( std::vector& permList, const sptr& callback) { MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } uint32_t listSize = permList.size(); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(listSize), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); + if (!data.WriteUint32(listSize)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write listSize"); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } for (uint32_t i = 0; i < listSize; i++) { - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permList[i]), ERR_WRITE_PARCEL_FAILED, - "Failed to write permList[%{public}d], %{public}s", i, permList[i].c_str()); + if (!data.WriteString(permList[i])) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permList[%{public}d], %{public}s", i, permList[i].c_str()); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } } - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteRemoteObject(callback), ERR_WRITE_PARCEL_FAILED, "WriteRemoteObject failed."); + if (!data.WriteRemoteObject(callback)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; if (!SendRequest(PrivacyInterfaceCode::REGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -261,18 +262,21 @@ int32_t PrivacyManagerProxy::RegisterPermActiveStatusCallback( int32_t PrivacyManagerProxy::UnRegisterPermActiveStatusCallback(const sptr& callback) { MessageParcel data; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteRemoteObject(callback), ERR_WRITE_PARCEL_FAILED, "WriteRemoteObject failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteRemoteObject(callback)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } MessageParcel reply; if (!SendRequest( PrivacyInterfaceCode::UNREGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -281,43 +285,47 @@ bool PrivacyManagerProxy::IsAllowedUsingPermission(AccessTokenID tokenID, const { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), false, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenID), false, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permissionName), false, "WriteString failed."); - if (!SendRequest(PrivacyInterfaceCode::IS_ALLOWED_USING_PERMISSION, data, reply)) { + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return false; + } + if (!data.WriteUint32(tokenID)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenID); + return false; + } + if (!data.WriteString(permissionName)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteString(%{public}s)", permissionName.c_str()); return false; } + if (!SendRequest(PrivacyInterfaceCode::IS_ALLOWED_USING_PERMISSION, data, reply)) { + return PrivacyError::ERR_SERVICE_ABNORMAL; + } - bool result = false; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadBool(result), false, "ReadInt32 failed."); + bool result = reply.ReadBool(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE -int32_t PrivacyManagerProxy::RegisterSecCompEnhance(const SecCompEnhanceData& enhance) +int32_t PrivacyManagerProxy::RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhance) { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteUint32(enhance.token), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint64(enhance.challenge), ERR_WRITE_PARCEL_FAILED, "WriteUint64 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(enhance.sessionId), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(enhance.seqNum), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteBuffer(enhance.key, AES_KEY_STORAGE_LEN), ERR_WRITE_PARCEL_FAILED, "WriteBuffer failed."); - IF_FALSE_RETURN_VAL_LOG( - LABEL, data.WriteRemoteObject(enhance.callback), ERR_WRITE_PARCEL_FAILED, "WriteRemoteObject failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + + if (!data.WriteParcelable(&enhance)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write parcel."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } if (!SendRequest(PrivacyInterfaceCode::REGISTER_SEC_COMP_ENHANCE, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); return result; } @@ -326,95 +334,91 @@ int32_t PrivacyManagerProxy::UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInt32(pid), ERR_WRITE_PARCEL_FAILED, "WriteInt32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(seqNum), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - if (!SendRequest(PrivacyInterfaceCode::UPDATE_SEC_COMP_ENHANCE, data, reply)) { - return ERR_SERVICE_ABNORMAL; + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write GetDescriptor."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; } - - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); - ACCESSTOKEN_LOG_INFO(LABEL, "Result=%{public}d", result); - return result; -} - -static bool ReadEnhanceData(MessageParcel& in, SecCompEnhanceData& data) -{ - RETURN_IF_FALSE(in.ReadUint32(data.token)); - RETURN_IF_FALSE(in.ReadUint64(data.challenge)); - RETURN_IF_FALSE(in.ReadUint32(data.sessionId)); - RETURN_IF_FALSE(in.ReadUint32(data.seqNum)); - const uint8_t* ptr = in.ReadBuffer(AES_KEY_STORAGE_LEN); - if (ptr == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadBuffer failed."); + if (!data.WriteInt32(pid)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write pid=%{public}d.", pid); return false; } - if (memcpy_s(data.key, AES_KEY_STORAGE_LEN, ptr, AES_KEY_STORAGE_LEN) != EOK) { - ACCESSTOKEN_LOG_ERROR(LABEL, "memcpy_s failed."); + if (!data.WriteUint32(seqNum)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write seqNum=%{public}u.", seqNum); return false; } - - data.callback = in.ReadRemoteObject(); - if (data.callback == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "ReadBuffer failed."); - return false; + if (!SendRequest(PrivacyInterfaceCode::UPDATE_SEC_COMP_ENHANCE, data, reply)) { + return PrivacyError::ERR_SERVICE_ABNORMAL; } - return true; + + int32_t result = reply.ReadInt32(); + ACCESSTOKEN_LOG_INFO(LABEL, "Result=%{public}d", result); + return result; } -int32_t PrivacyManagerProxy::GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhance) +int32_t PrivacyManagerProxy::GetSecCompEnhance(int32_t pid, SecCompEnhanceDataParcel& enhanceParcel) { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInt32(pid), ERR_WRITE_PARCEL_FAILED, "WriteInt32 failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteInt32(pid)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteInt32(%{public}d)", pid); + return false; + } if (!SendRequest(PrivacyInterfaceCode::GET_SEC_COMP_ENHANCE, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); if (result != RET_SUCCESS) { return result; } - IF_FALSE_RETURN_VAL_LOG(LABEL, ReadEnhanceData(reply, enhance), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + + sptr parcel = reply.ReadParcelable(); + if (parcel != nullptr) { + enhanceParcel = *parcel; + } return result; } int32_t PrivacyManagerProxy::GetSpecialSecCompEnhance(const std::string& bundleName, - std::vector& enhanceList) + std::vector& enhanceParcelList) { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(bundleName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + + if (!data.WriteString(bundleName)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write string."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } if (!SendRequest(PrivacyInterfaceCode::GET_SPECIAL_SEC_COMP_ENHANCE, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server data = %{public}d", result); if (result != RET_SUCCESS) { return result; } - uint32_t size = 0; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadUint32(size), ERR_READ_PARCEL_FAILED, "ReadUint32 failed."); + uint32_t size = reply.ReadUint32(); if (size > MAX_SEC_COMP_ENHANCE_SIZE) { ACCESSTOKEN_LOG_ERROR(LABEL, "Size = %{public}d get from request is invalid", size); - return ERR_OVERSIZE; + return PrivacyError::ERR_OVERSIZE; } for (uint32_t i = 0; i < size; i++) { - SecCompEnhanceData tmp; - IF_FALSE_RETURN_VAL_LOG(LABEL, ReadEnhanceData(reply, tmp), ERR_READ_PARCEL_FAILED, "ReadUint32 failed."); - enhanceList.emplace_back(tmp); + sptr parcel = reply.ReadParcelable(); + if (parcel != nullptr) { + enhanceParcelList.emplace_back(*parcel); + } } return result; } @@ -425,27 +429,33 @@ int32_t PrivacyManagerProxy::GetPermissionUsedTypeInfos(const AccessTokenID toke { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenId), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteString(permissionName), ERR_WRITE_PARCEL_FAILED, "WriteString failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteUint32(tokenId)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenId); + return false; + } + if (!data.WriteString(permissionName)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteString(%{public}s)", permissionName.c_str()); + return false; + } if (!SendRequest(PrivacyInterfaceCode::GET_PERMISSION_USED_TYPE_INFOS, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server is %{public}d.", result); if (result != RET_SUCCESS) { return result; } - uint32_t size = 0; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadUint32(size), ERR_READ_PARCEL_FAILED, "ReadUint32 failed."); + uint32_t size = reply.ReadUint32(); if (size > MAX_PERMISSION_USED_TYPE_SIZE) { ACCESSTOKEN_LOG_ERROR(LABEL, "Failed, results oversize %{public}d, please add query params!", size); - return ERR_OVERSIZE; + return PrivacyError::ERR_OVERSIZE; } for (uint32_t i = 0; i < size; i++) { sptr parcel = reply.ReadParcelable(); @@ -460,17 +470,27 @@ int32_t PrivacyManagerProxy::SetMutePolicy(uint32_t policyType, uint32_t callerT { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(policyType), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(callerType), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteBool(isMute), ERR_WRITE_PARCEL_FAILED, "WriteBool failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteUint32(policyType)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", policyType); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteUint32(callerType)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", callerType); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteBool(isMute)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteBool(%{public}d)", isMute); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } if (!SendRequest(PrivacyInterfaceCode::SET_MUTE_POLICY, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "result from server is %{public}d.", result); return result; } @@ -479,16 +499,24 @@ int32_t PrivacyManagerProxy::SetHapWithFGReminder(uint32_t tokenId, bool isAllow { MessageParcel data; MessageParcel reply; - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteInterfaceToken( - IPrivacyManager::GetDescriptor()), ERR_WRITE_PARCEL_FAILED, "WriteInterfaceToken failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteUint32(tokenId), ERR_WRITE_PARCEL_FAILED, "WriteUint32 failed."); - IF_FALSE_RETURN_VAL_LOG(LABEL, data.WriteBool(isAllowed), ERR_WRITE_PARCEL_FAILED, "WriteBool failed."); + if (!data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write WriteInterfaceToken."); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + + if (!data.WriteUint32(tokenId)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteUint32(%{public}d)", tokenId); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } + if (!data.WriteBool(isAllowed)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteBool(%{public}d)", isAllowed); + return PrivacyError::ERR_WRITE_PARCEL_FAILED; + } if (!SendRequest(PrivacyInterfaceCode::SET_HAP_WITH_FOREGROUND_REMINDER, data, reply)) { - return ERR_SERVICE_ABNORMAL; + return PrivacyError::ERR_SERVICE_ABNORMAL; } - int32_t result = NO_ERROR; - IF_FALSE_RETURN_VAL_LOG(LABEL, reply.ReadInt32(result), ERR_READ_PARCEL_FAILED, "ReadInt32 failed."); + int32_t result = reply.ReadInt32(); ACCESSTOKEN_LOG_INFO(LABEL, "Result from server is %{public}d.", result); return result; } diff --git a/interfaces/innerkits/privacy/src/privacy_manager_proxy.h b/interfaces/innerkits/privacy/src/privacy_manager_proxy.h index a3cadbfa6eba794ce8926f18845cc0fc01085786..6674ba17e109bcf192cd610d994926fe21759423 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_proxy.h +++ b/interfaces/innerkits/privacy/src/privacy_manager_proxy.h @@ -29,26 +29,26 @@ public: explicit PrivacyManagerProxy(const sptr& impl); ~PrivacyManagerProxy() override; - int32_t AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode = false) override; + int32_t AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode = false) override; int32_t StartUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName) override; int32_t StartUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName, const sptr& callback) override; int32_t StopUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName) override; int32_t RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) override; int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, PermissionUsedResultParcel& result) override; - int32_t GetPermissionUsedRecords(const PermissionUsedRequest& request, + const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) override; + int32_t GetPermissionUsedRecords(const PermissionUsedRequestParcel& request, const sptr& callback) override; int32_t RegisterPermActiveStatusCallback( std::vector& permList, const sptr& callback) override; int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; bool IsAllowedUsingPermission(AccessTokenID tokenID, const std::string& permissionName) override; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - int32_t RegisterSecCompEnhance(const SecCompEnhanceData& enhance) override; + int32_t RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhance) override; int32_t UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) override; - int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhance) override; + int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceDataParcel& enhanceParcel) override; int32_t GetSpecialSecCompEnhance(const std::string& bundleName, - std::vector& enhanceList) override; + std::vector& enhanceParcelList) override; #endif int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, std::vector& resultsParcel) override; diff --git a/services/privacymanager/include/seccomp/privacy_sec_comp_enhance_agent.h b/services/privacymanager/include/seccomp/privacy_sec_comp_enhance_agent.h index 0b9ae7fd394ba94bec02f8373e076c257a839a4d..76896f7b09a8dd590c4f2bf27466a5be76a0683b 100644 --- a/services/privacymanager/include/seccomp/privacy_sec_comp_enhance_agent.h +++ b/services/privacymanager/include/seccomp/privacy_sec_comp_enhance_agent.h @@ -15,8 +15,8 @@ #ifndef PERMISSION_SEC_COMP_ENHANCE_AGENT_H #define PERMISSION_SEC_COMP_ENHANCE_AGENT_H -#include #include +#include #include "app_manager_death_callback.h" #include "app_status_change_callback.h" #include "nocopyable.h" @@ -65,7 +65,7 @@ private: sptr observer_ = nullptr; std::shared_ptr appManagerDeathCallback_ = nullptr; std::mutex secCompEnhanceMutex_; - std::map secCompEnhanceData_; + std::vector secCompEnhanceData_; }; } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/include/service/privacy_manager_service.h b/services/privacymanager/include/service/privacy_manager_service.h index 50f93d0d0765f431ebf69e9e32f9bcc59995710a..5ca6f068e68656bd905a5f7ac1d412eb71e35486 100644 --- a/services/privacymanager/include/service/privacy_manager_service.h +++ b/services/privacymanager/include/service/privacy_manager_service.h @@ -39,25 +39,25 @@ public: void OnStart() override; void OnStop() override; - int32_t AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode = false) override; + int32_t AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode = false) override; int32_t StartUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName) override; int32_t StartUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName, const sptr& callback) override; int32_t StopUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName) override; int32_t RemovePermissionUsedRecords(AccessTokenID tokenId, const std::string& deviceID) override; int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, PermissionUsedResultParcel& result) override; + const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) override; int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, const sptr& callback) override; + const PermissionUsedRequestParcel& request, const sptr& callback) override; int32_t RegisterPermActiveStatusCallback( std::vector& permList, const sptr& callback) override; int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - int32_t RegisterSecCompEnhance(const SecCompEnhanceData& enhance) override; + int32_t RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) override; int32_t UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) override; - int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhance) override; + int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceDataParcel& enhanceParcel) override; int32_t GetSpecialSecCompEnhance(const std::string& bundleName, - std::vector& enhanceList) override; + std::vector& enhanceParcelList) override; #endif bool IsAllowedUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, diff --git a/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp b/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp index 49de3de38e99af68b8babe9c911f5a513177e360..7c5ccc12bf08b7a98953843cf8219ae93bee8538 100644 --- a/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp +++ b/services/privacymanager/src/seccomp/privacy_sec_comp_enhance_agent.cpp @@ -101,13 +101,14 @@ void PrivacySecCompEnhanceAgent::OnAppMgrRemoteDiedHandle() void PrivacySecCompEnhanceAgent::RemoveSecCompEnhance(int pid) { std::lock_guard lock(secCompEnhanceMutex_); - auto iter = secCompEnhanceData_.find(pid); - if (iter == secCompEnhanceData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Not found pid %{public}d data.", pid); - return; + for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { + if (iter->pid == pid) { + secCompEnhanceData_.erase(iter); + ACCESSTOKEN_LOG_INFO(LABEL, "Remove pid %{public}d data.", pid); + return; + } } - ACCESSTOKEN_LOG_INFO(LABEL, "Remove pid %{public}d data.", pid); - secCompEnhanceData_.erase(iter); + ACCESSTOKEN_LOG_ERROR(LABEL, "Not found pid %{public}d data.", pid); return; } @@ -116,11 +117,22 @@ int32_t PrivacySecCompEnhanceAgent::RegisterSecCompEnhance(const SecCompEnhanceD std::lock_guard lock(secCompEnhanceMutex_); InitAppObserver(); int pid = IPCSkeleton::GetCallingPid(); - if (secCompEnhanceData_.find(pid) != secCompEnhanceData_.end()) { - ACCESSTOKEN_LOG_ERROR(LABEL, "Register sec comp enhance exist, pid %{public}d.", pid); + if (std::any_of(secCompEnhanceData_.begin(), secCompEnhanceData_.end(), + [pid](const auto& e) { return e.pid == pid; })) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Register sec comp enhance exist, pid %{public}d.", pid); + return PrivacyError::ERR_CALLBACK_ALREADY_EXIST; + } + SecCompEnhanceData enhance; + enhance.callback = enhanceData.callback; + enhance.pid = pid; + enhance.token = IPCSkeleton::GetCallingTokenID(); + enhance.challenge = enhanceData.challenge; + enhance.sessionId = enhanceData.sessionId; + enhance.seqNum = enhanceData.seqNum; + if (memcpy_s(enhance.key, AES_KEY_STORAGE_LEN, enhanceData.key, AES_KEY_STORAGE_LEN) != EOK) { return PrivacyError::ERR_CALLBACK_ALREADY_EXIST; } - secCompEnhanceData_[pid] = enhanceData; + secCompEnhanceData_.emplace_back(enhance); ACCESSTOKEN_LOG_INFO(LABEL, "Register sec comp enhance success, pid %{public}d, total %{public}u.", pid, static_cast(secCompEnhanceData_.size())); return RET_SUCCESS; @@ -130,27 +142,27 @@ int32_t PrivacySecCompEnhanceAgent::UpdateSecCompEnhance(int32_t pid, uint32_t s { std::lock_guard lock(secCompEnhanceMutex_); InitAppObserver(); - auto iter = secCompEnhanceData_.find(pid); - if (iter == secCompEnhanceData_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "pid %{public}d is noexist.", pid); - return ERR_PARAM_INVALID; + for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { + if (iter->pid == pid) { + iter->seqNum = seqNum; + ACCESSTOKEN_LOG_INFO(LABEL, "Update pid=%{public}d data successful.", pid); + return RET_SUCCESS; + } } - iter->second.seqNum = seqNum; - ACCESSTOKEN_LOG_INFO(LABEL, "Update pid=%{public}d data successful.", pid); - return RET_SUCCESS; + return ERR_PARAM_INVALID; } int32_t PrivacySecCompEnhanceAgent::GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhanceData) { std::lock_guard lock(secCompEnhanceMutex_); InitAppObserver(); - auto iter = secCompEnhanceData_.find(pid); - if (iter == secCompEnhanceData_.end()) { - ACCESSTOKEN_LOG_INFO(LABEL, "pid %{public}d is noexist.", pid); - return ERR_PARAM_INVALID; + for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { + if (iter->pid == pid) { + enhanceData = *iter; + ACCESSTOKEN_LOG_INFO(LABEL, "Get pid %{public}d data.", pid); + return RET_SUCCESS; + } } - enhanceData = iter->second; - ACCESSTOKEN_LOG_INFO(LABEL, "Get pid %{public}d data.", pid); return ERR_PARAM_INVALID; } @@ -158,11 +170,11 @@ int32_t PrivacySecCompEnhanceAgent::GetSpecialSecCompEnhance(const std::string& std::vector& enhanceList) { std::lock_guard lock(secCompEnhanceMutex_); - for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); ++iter) { + for (auto iter = secCompEnhanceData_.begin(); iter != secCompEnhanceData_.end(); iter++) { HapTokenInfo info; - if (AccessTokenKit::GetHapTokenInfo(iter->second.token, info) == AccessTokenKitRet::RET_SUCCESS) { + if (AccessTokenKit::GetHapTokenInfo(iter->token, info) == AccessTokenKitRet::RET_SUCCESS) { if (bundleName == info.bundleName) { - enhanceList.emplace_back(iter->second); + enhanceList.emplace_back(*iter); } } } diff --git a/services/privacymanager/src/service/privacy_manager_service.cpp b/services/privacymanager/src/service/privacy_manager_service.cpp index d795b5c3ed8ee88eae78b9ad282d91b90d5c6089..6995f6fab1f8869ac615aeca415fd407f86385d4 100644 --- a/services/privacymanager/src/service/privacy_manager_service.cpp +++ b/services/privacymanager/src/service/privacy_manager_service.cpp @@ -92,10 +92,13 @@ void PrivacyManagerService::OnStop() state_ = ServiceRunningState::STATE_NOT_START; } -int32_t PrivacyManagerService::AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode) +int32_t PrivacyManagerService::AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, + bool asyncMode) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d, perm: %{public}s, succCnt: %{public}d, failCnt: %{public}d," - " type: %{public}d", info.tokenId, info.permissionName.c_str(), info.successCount, info.failCount, info.type); + ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d, perm: %{public}s, succCnt: %{public}d," + " failCnt: %{public}d, type: %{public}d", infoParcel.info.tokenId, infoParcel.info.permissionName.c_str(), + infoParcel.info.successCount, infoParcel.info.failCount, infoParcel.info.type); + AddPermParamInfo info = infoParcel.info; return PermissionRecordManager::GetInstance().AddPermissionUsedRecord(info); } @@ -131,28 +134,28 @@ int32_t PrivacyManagerService::RemovePermissionUsedRecords(AccessTokenID tokenId } int32_t PrivacyManagerService::GetPermissionUsedRecords( - const PermissionUsedRequest& request, PermissionUsedResultParcel& result) + const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) { std::string permissionList; - for (const auto& perm : request.permissionList) { + for (const auto& perm : request.request.permissionList) { permissionList.append(perm); permissionList.append(" "); } ACCESSTOKEN_LOG_INFO(LABEL, "id: %{public}d, timestamp: [%{public}" PRId64 "-%{public}" PRId64 - "], flag: %{public}d, perm: %{public}s", request.tokenId, request.beginTimeMillis, - request.endTimeMillis, request.flag, permissionList.c_str()); + "], flag: %{public}d, perm: %{public}s", request.request.tokenId, request.request.beginTimeMillis, + request.request.endTimeMillis, request.request.flag, permissionList.c_str()); PermissionUsedResult permissionRecord; - int32_t ret = PermissionRecordManager::GetInstance().GetPermissionUsedRecords(request, permissionRecord); + int32_t ret = PermissionRecordManager::GetInstance().GetPermissionUsedRecords(request.request, permissionRecord); result.result = permissionRecord; return ret; } int32_t PrivacyManagerService::GetPermissionUsedRecords( - const PermissionUsedRequest& request, const sptr& callback) + const PermissionUsedRequestParcel& request, const sptr& callback) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d", request.tokenId); - return PermissionRecordManager::GetInstance().GetPermissionUsedRecordsAsync(request, callback); + ACCESSTOKEN_LOG_DEBUG(LABEL, "id: %{public}d", request.request.tokenId); + return PermissionRecordManager::GetInstance().GetPermissionUsedRecordsAsync(request.request, callback); } int32_t PrivacyManagerService::RegisterPermActiveStatusCallback( @@ -163,9 +166,10 @@ int32_t PrivacyManagerService::RegisterPermActiveStatusCallback( } #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE -int32_t PrivacyManagerService::RegisterSecCompEnhance(const SecCompEnhanceData& enhance) +int32_t PrivacyManagerService::RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) { - return PrivacySecCompEnhanceAgent::GetInstance().RegisterSecCompEnhance(enhance); + ACCESSTOKEN_LOG_INFO(LABEL, "Pid: %{public}d", enhanceParcel.enhanceData.pid); + return PrivacySecCompEnhanceAgent::GetInstance().RegisterSecCompEnhance(enhanceParcel.enhanceData); } int32_t PrivacyManagerService::UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) @@ -173,20 +177,30 @@ int32_t PrivacyManagerService::UpdateSecCompEnhance(int32_t pid, uint32_t seqNum return PrivacySecCompEnhanceAgent::GetInstance().UpdateSecCompEnhance(pid, seqNum); } -int32_t PrivacyManagerService::GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhance) +int32_t PrivacyManagerService::GetSecCompEnhance(int32_t pid, SecCompEnhanceDataParcel& enhanceParcel) { - int32_t res = PrivacySecCompEnhanceAgent::GetInstance().GetSecCompEnhance(pid, enhance); + SecCompEnhanceData enhanceData; + int32_t res = PrivacySecCompEnhanceAgent::GetInstance().GetSecCompEnhance(pid, enhanceData); if (res != RET_SUCCESS) { ACCESSTOKEN_LOG_WARN(LABEL, "Pid: %{public}d get enhance failed ", pid); return res; } + + enhanceParcel.enhanceData = enhanceData; return RET_SUCCESS; } int32_t PrivacyManagerService::GetSpecialSecCompEnhance(const std::string& bundleName, - std::vector& enhanceList) + std::vector& enhanceParcelList) { - return PrivacySecCompEnhanceAgent::GetInstance().GetSpecialSecCompEnhance(bundleName, enhanceList); + std::vector enhanceList; + PrivacySecCompEnhanceAgent::GetInstance().GetSpecialSecCompEnhance(bundleName, enhanceList); + for (const auto& enhance : enhanceList) { + SecCompEnhanceDataParcel parcel; + parcel.enhanceData = enhance; + enhanceParcelList.emplace_back(parcel); + } + return RET_SUCCESS; } #endif diff --git a/services/privacymanager/src/service/privacy_manager_stub.cpp b/services/privacymanager/src/service/privacy_manager_stub.cpp index 00f10c22ced63c67d8209d82619a93204b4e1278..1bba27f574179fdde8b59f8b7a58daa5fdb9cd37 100644 --- a/services/privacymanager/src/service/privacy_manager_stub.cpp +++ b/services/privacymanager/src/service/privacy_manager_stub.cpp @@ -20,9 +20,7 @@ #include "ipc_skeleton.h" #include "memory_guard.h" #include "on_permission_used_record_callback_proxy.h" -#include "parcel_utils.h" #include "privacy_error.h" -#include "securec.h" #include "string_ex.h" #include "tokenid_kit.h" #ifdef HICOLLIE_ENABLE @@ -123,13 +121,13 @@ void PrivacyManagerStub::AddPermissionUsedRecordInner(MessageParcel& data, Messa reply.WriteInt32(PrivacyError::ERR_PERMISSION_DENIED); return; } - AddPermParamInfo info; - info.tokenId = data.ReadUint32(); - info.permissionName = data.ReadString(); - info.successCount = data.ReadInt32(); - info.failCount = data.ReadInt32(); - info.type = static_cast(data.ReadUint32()); - reply.WriteInt32(this->AddPermissionUsedRecord(info)); + sptr infoParcel = data.ReadParcelable(); + if (infoParcel == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable faild"); + reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); + return; + } + reply.WriteInt32(this->AddPermissionUsedRecord(*infoParcel)); } void PrivacyManagerStub::StartUsingPermissionInner(MessageParcel& data, MessageParcel& reply) @@ -208,27 +206,13 @@ void PrivacyManagerStub::GetPermissionUsedRecordsInner(MessageParcel& data, Mess reply.WriteInt32(PrivacyError::ERR_PERMISSION_DENIED); return; } - PermissionUsedRequest request; - request.tokenId = data.ReadUint32(); - request.isRemote = data.ReadBool(); - request.deviceId = data.ReadString(); - request.bundleName = data.ReadString(); - - uint32_t permSize = data.ReadUint32(); - if (permSize > MAX_PERMLIST_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "permSize=%{public}d is over maxnum", permSize); - reply.WriteInt32(PrivacyError::ERR_OVERSIZE); + sptr requestParcel = data.ReadParcelable(); + if (requestParcel == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable faild"); + reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } - for (uint32_t i = 0; i < permSize; i++) { - std::string perm = data.ReadString(); - request.permissionList.emplace_back(perm); - } - request.beginTimeMillis = data.ReadInt64(); - request.endTimeMillis = data.ReadInt64(); - request.flag = static_cast(data.ReadInt32()); - - int32_t result = this->GetPermissionUsedRecords(request, responseParcel); + int32_t result = this->GetPermissionUsedRecords(*requestParcel, responseParcel); reply.WriteInt32(result); if (result != RET_SUCCESS) { ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 faild"); @@ -243,31 +227,19 @@ void PrivacyManagerStub::GetPermissionUsedRecordsAsyncInner(MessageParcel& data, reply.WriteInt32(PrivacyError::ERR_PERMISSION_DENIED); return; } - PermissionUsedRequest request; - request.tokenId = data.ReadUint32(); - request.isRemote = data.ReadBool(); - request.deviceId = data.ReadString(); - request.bundleName = data.ReadString(); - - uint32_t permSize = data.ReadUint32(); - if (permSize > MAX_PERMLIST_SIZE) { - ACCESSTOKEN_LOG_ERROR(LABEL, "permSize=%{public}d is over maxnum", permSize); - reply.WriteInt32(PrivacyError::ERR_OVERSIZE); + sptr requestParcel = data.ReadParcelable(); + if (requestParcel == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable failed"); + reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } - for (uint32_t i = 0; i < permSize; i++) { - request.permissionList.emplace_back(data.ReadString()); - } - request.beginTimeMillis = data.ReadInt64(); - request.endTimeMillis = data.ReadInt64(); - request.flag = static_cast(data.ReadInt32()); sptr callback = new OnPermissionUsedRecordCallbackProxy(data.ReadRemoteObject()); if (callback == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "Callback is null"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); return; } - reply.WriteInt32(this->GetPermissionUsedRecords(request, callback)); + reply.WriteInt32(this->GetPermissionUsedRecords(*requestParcel, callback)); } void PrivacyManagerStub::RegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply) @@ -339,38 +311,6 @@ void PrivacyManagerStub::IsAllowedUsingPermissionInner(MessageParcel& data, Mess } #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE -static bool ReadEnhanceData(MessageParcel& in, SecCompEnhanceData& data) -{ - RETURN_IF_FALSE(in.ReadUint32(data.token)); - RETURN_IF_FALSE(in.ReadUint64(data.challenge)); - RETURN_IF_FALSE(in.ReadUint32(data.sessionId)); - RETURN_IF_FALSE(in.ReadUint32(data.seqNum)); - const uint8_t* ptr = in.ReadBuffer(AES_KEY_STORAGE_LEN); - if (ptr == nullptr) { - return false; - } - if (memcpy_s(data.key, AES_KEY_STORAGE_LEN, ptr, AES_KEY_STORAGE_LEN) != EOK) { - return false; - } - - data.callback = (static_cast(&in))->ReadRemoteObject(); - if (data.callback == nullptr) { - return false; - } - return true; -} - -static bool WriteEnhanceData(const SecCompEnhanceData& data, MessageParcel& out) -{ - RETURN_IF_FALSE(out.WriteUint32(data.token)); - RETURN_IF_FALSE(out.WriteUint64(data.challenge)); - RETURN_IF_FALSE(out.WriteUint32(data.sessionId)); - RETURN_IF_FALSE(out.WriteUint32(data.seqNum)); - RETURN_IF_FALSE(out.WriteBuffer(data.key, AES_KEY_STORAGE_LEN)); - RETURN_IF_FALSE((static_cast(&out))->WriteRemoteObject(data.callback)); - return true; -} - void PrivacyManagerStub::RegisterSecCompEnhanceInner(MessageParcel& data, MessageParcel& reply) { #ifdef HICOLLIE_ENABLE @@ -378,8 +318,9 @@ void PrivacyManagerStub::RegisterSecCompEnhanceInner(MessageParcel& data, Messag int timerId = HiviewDFX::XCollie::GetInstance().SetTimer(name, TIMEOUT, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG); #endif // HICOLLIE_ENABLE - SecCompEnhanceData enhanceData; - if (!ReadEnhanceData(data, enhanceData)) { + + sptr requestParcel = data.ReadParcelable(); + if (requestParcel == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable faild"); reply.WriteInt32(PrivacyError::ERR_READ_PARCEL_FAILED); @@ -389,7 +330,7 @@ void PrivacyManagerStub::RegisterSecCompEnhanceInner(MessageParcel& data, Messag return; } - reply.WriteInt32(this->RegisterSecCompEnhance(enhanceData)); + reply.WriteInt32(this->RegisterSecCompEnhance(*requestParcel)); #ifdef HICOLLIE_ENABLE HiviewDFX::XCollie::GetInstance().CancelTimer(timerId); @@ -416,14 +357,14 @@ void PrivacyManagerStub::GetSecCompEnhanceInner(MessageParcel& data, MessageParc } int32_t pid = data.ReadInt32(); - SecCompEnhanceData enhance; - int32_t result = this->GetSecCompEnhance(pid, enhance); + SecCompEnhanceDataParcel parcel; + int32_t result = this->GetSecCompEnhance(pid, parcel); reply.WriteInt32(result); if (result != RET_SUCCESS) { return; } - (void)WriteEnhanceData(enhance, reply); + reply.WriteParcelable(&parcel); } void PrivacyManagerStub::GetSpecialSecCompEnhanceInner(MessageParcel& data, MessageParcel& reply) @@ -434,15 +375,15 @@ void PrivacyManagerStub::GetSpecialSecCompEnhanceInner(MessageParcel& data, Mess } std::string bundleName = data.ReadString(); - std::vector enhanceList; - int32_t result = this->GetSpecialSecCompEnhance(bundleName, enhanceList); + std::vector parcelList; + int32_t result = this->GetSpecialSecCompEnhance(bundleName, parcelList); reply.WriteInt32(result); if (result != RET_SUCCESS) { return; } - reply.WriteUint32(enhanceList.size()); - for (const auto& enc : enhanceList) { - (void)WriteEnhanceData(enc, reply); + reply.WriteUint32(parcelList.size()); + for (const auto& parcel : parcelList) { + reply.WriteParcelable(&parcel); } } diff --git a/services/privacymanager/test/unittest/privacy_manager_service_test.cpp b/services/privacymanager/test/unittest/privacy_manager_service_test.cpp index b39b56276f8076cc772785c9d2af7757b4f73049..69a974c3a91295665cd0b1253096cb732c64e955 100644 --- a/services/privacymanager/test/unittest/privacy_manager_service_test.cpp +++ b/services/privacymanager/test/unittest/privacy_manager_service_test.cpp @@ -189,19 +189,19 @@ HWTEST_F(PrivacyManagerServiceTest, Dump002, TestSize.Level1) ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); - AddPermParamInfo info; - info.tokenId = tokenId; - info.permissionName = "ohos.permission.CAMERA"; - info.successCount = 1; - info.failCount = 0; + AddPermParamInfoParcel infoParcel; + infoParcel.info.tokenId = tokenId; + infoParcel.info.permissionName = "ohos.permission.CAMERA"; + infoParcel.info.successCount = 1; + infoParcel.info.failCount = 0; for (int32_t i = 0; i < PERMISSION_USAGE_RECORDS_MAX_NUM; i++) { - privacyManagerService_->AddPermissionUsedRecord(info); + privacyManagerService_->AddPermissionUsedRecord(infoParcel); } ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); - privacyManagerService_->AddPermissionUsedRecord(info); + privacyManagerService_->AddPermissionUsedRecord(infoParcel); ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); } @@ -277,7 +277,7 @@ public: TestPrivacyManagerStub() = default; virtual ~TestPrivacyManagerStub() = default; - int32_t AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode = false) + int32_t AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode = false) { return RET_SUCCESS; } @@ -299,12 +299,12 @@ public: return RET_SUCCESS; } int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, PermissionUsedResultParcel& result) + const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) { return RET_SUCCESS; } int32_t GetPermissionUsedRecords( - const PermissionUsedRequest& request, const sptr& callback) + const PermissionUsedRequestParcel& request, const sptr& callback) { return RET_SUCCESS; } @@ -335,15 +335,15 @@ public: return RET_SUCCESS; } #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - int32_t RegisterSecCompEnhance(const SecCompEnhanceData& enhance) + int32_t RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) { return RET_SUCCESS; } - int32_t DepositSecCompEnhance(const std::vector& enhanceList) + int32_t DepositSecCompEnhance(const std::vector& enhanceParcelList) { return RET_SUCCESS; } - int32_t RecoverSecCompEnhance(std::vector& enhanceList) + int32_t RecoverSecCompEnhance(std::vector& enhanceParcelList) { return RET_SUCCESS; } @@ -393,11 +393,12 @@ HWTEST_F(PrivacyManagerServiceTest, AddPermissionUsedRecordInner001, TestSize.Le MessageOption option(MessageOption::TF_SYNC); ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); - ASSERT_EQ(true, data.WriteUint32(tokenID)); - ASSERT_EQ(true, data.WriteString(permissionName)); - ASSERT_EQ(true, data.WriteInt32(successCount)); - ASSERT_EQ(true, data.WriteInt32(failCount)); - ASSERT_EQ(true, data.WriteUint32(0)); + AddPermParamInfoParcel infoParcel; + infoParcel.info.tokenId = tokenID; + infoParcel.info.permissionName = permissionName; + infoParcel.info.successCount = successCount; + infoParcel.info.failCount = failCount; + ASSERT_EQ(true, data.WriteParcelable(&infoParcel)); ASSERT_EQ(RET_SUCCESS, testSub.OnRemoteRequest( static_cast(PrivacyInterfaceCode::ADD_PERMISSION_USED_RECORD), data, reply, option)); // callingTokenID is native token hdcd with need permission, but input tokenID is not a real hap @@ -428,11 +429,12 @@ HWTEST_F(PrivacyManagerServiceTest, AddPermissionUsedRecordInner002, TestSize.Le SetSelfTokenID(hapTokenID); // set self tokenID to hapTokenID ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); - ASSERT_EQ(true, data.WriteUint32(tokenID)); - ASSERT_EQ(true, data.WriteString(permissionName)); - ASSERT_EQ(true, data.WriteInt32(successCount)); - ASSERT_EQ(true, data.WriteInt32(failCount)); - ASSERT_EQ(true, data.WriteUint32(0)); + AddPermParamInfoParcel infoParcel; + infoParcel.info.tokenId = tokenID; + infoParcel.info.permissionName = permissionName; + infoParcel.info.successCount = successCount; + infoParcel.info.failCount = failCount; + ASSERT_EQ(true, data.WriteParcelable(&infoParcel)); ASSERT_EQ(RET_SUCCESS, testSub.OnRemoteRequest( static_cast(PrivacyInterfaceCode::ADD_PERMISSION_USED_RECORD), data, reply, option)); // callingTokenID is normal hap without need permission @@ -461,11 +463,12 @@ HWTEST_F(PrivacyManagerServiceTest, AddPermissionUsedRecordInner003, TestSize.Le SetSelfTokenID(g_tokenID.tokenIDEx); // set self tokenID to system app ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); - ASSERT_EQ(true, data.WriteUint32(tokenID)); - ASSERT_EQ(true, data.WriteString(permissionName)); - ASSERT_EQ(true, data.WriteInt32(successCount)); - ASSERT_EQ(true, data.WriteInt32(failCount)); - ASSERT_EQ(true, data.WriteUint32(0)); + AddPermParamInfoParcel infoParcel; + infoParcel.info.tokenId = tokenID; + infoParcel.info.permissionName = permissionName; + infoParcel.info.successCount = successCount; + infoParcel.info.failCount = failCount; + ASSERT_EQ(true, data.WriteParcelable(&infoParcel)); ASSERT_EQ(RET_SUCCESS, testSub.OnRemoteRequest( static_cast(PrivacyInterfaceCode::ADD_PERMISSION_USED_RECORD), data, reply, option)); // callingTokenID is system hap without need permission @@ -773,22 +776,6 @@ HWTEST_F(PrivacyManagerServiceTest, RemovePermissionUsedRecordsInner002, TestSiz ASSERT_EQ(PrivacyError::ERR_PERMISSION_DENIED, reply.ReadInt32()); } -static void WriteRequestParcelable(const PermissionUsedRequest& request, MessageParcel& data) -{ - ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); - ASSERT_EQ(true, data.WriteUint32(request.tokenId)); - ASSERT_EQ(true, data.WriteBool(request.isRemote)); - ASSERT_EQ(true, data.WriteString(request.deviceId)); - ASSERT_EQ(true, data.WriteString(request.bundleName)); - ASSERT_EQ(true, data.WriteUint32(request.permissionList.size())); - for (const auto& perm : request.permissionList) { - ASSERT_EQ(true, data.WriteString(perm)); - } - ASSERT_EQ(true, data.WriteInt64(request.beginTimeMillis)); - ASSERT_EQ(true, data.WriteInt64(request.endTimeMillis)); - ASSERT_EQ(true, data.WriteInt32(request.flag)); -} - /** * @tc.name: GetPermissionUsedRecordsInner001 * @tc.desc: GetPermissionUsedRecordsInner test. @@ -797,15 +784,16 @@ static void WriteRequestParcelable(const PermissionUsedRequest& request, Message */ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner001, TestSize.Level1) { - PermissionUsedRequest request; - request.isRemote = true; + PermissionUsedRequestParcel request; + request.request.isRemote = true; TestPrivacyManagerStub testSub; MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); - WriteRequestParcelable(request, data); + ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); + ASSERT_EQ(true, data.WriteParcelable(&request)); ASSERT_EQ(RET_SUCCESS, testSub.OnRemoteRequest(static_cast( PrivacyInterfaceCode::GET_PERMISSION_USED_RECORDS), data, reply, option)); // callingTokenID is native token hdcd with need permission, remote is true return ERR_PARAM_INVALID @@ -820,8 +808,8 @@ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner001, TestSize.L */ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner002, TestSize.Level1) { - PermissionUsedRequest request; - request.isRemote = true; + PermissionUsedRequestParcel request; + request.request.isRemote = true; TestPrivacyManagerStub testSub; MessageParcel data; @@ -833,7 +821,8 @@ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner002, TestSize.L ASSERT_NE(hapTokenID, static_cast(0)); SetSelfTokenID(hapTokenID); // set self tokenID to hapTokenID - WriteRequestParcelable(request, data); + ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); + ASSERT_EQ(true, data.WriteParcelable(&request)); ASSERT_EQ(RET_SUCCESS, testSub.OnRemoteRequest(static_cast( PrivacyInterfaceCode::GET_PERMISSION_USED_RECORDS), data, reply, option)); // callingTokenID is normal hap without need permission @@ -848,8 +837,8 @@ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner002, TestSize.L */ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner003, TestSize.Level1) { - PermissionUsedRequest request; - request.isRemote = true; + PermissionUsedRequestParcel request; + request.request.isRemote = true; TestPrivacyManagerStub testSub; MessageParcel data; @@ -859,7 +848,8 @@ HWTEST_F(PrivacyManagerServiceTest, GetPermissionUsedRecordsInner003, TestSize.L ASSERT_NE(g_tokenID.tokenIDEx, static_cast(0)); SetSelfTokenID(g_tokenID.tokenIDEx); // set self tokenID to system app - WriteRequestParcelable(request, data); + ASSERT_EQ(true, data.WriteInterfaceToken(IPrivacyManager::GetDescriptor())); + ASSERT_EQ(true, data.WriteParcelable(&request)); ASSERT_EQ(RET_SUCCESS, testSub.OnRemoteRequest(static_cast( PrivacyInterfaceCode::GET_PERMISSION_USED_RECORDS), data, reply, option)); // callingTokenID is system hap without need permission diff --git a/test/fuzztest/innerkits/privacy/registerseccompenhance_fuzzer/registerseccompenhance_fuzzer.cpp b/test/fuzztest/innerkits/privacy/registerseccompenhance_fuzzer/registerseccompenhance_fuzzer.cpp index 3bccaa761928ccf4c8dac7d8fdf0976a0e3a7835..dbd328e0994e540c6efdba24ac31fcdd769c3222 100644 --- a/test/fuzztest/innerkits/privacy/registerseccompenhance_fuzzer/registerseccompenhance_fuzzer.cpp +++ b/test/fuzztest/innerkits/privacy/registerseccompenhance_fuzzer/registerseccompenhance_fuzzer.cpp @@ -38,6 +38,7 @@ namespace OHOS { SecCompEnhanceData secData; secData.callback = nullptr; + secData.pid = fuzzData.GetData(); secData.token = static_cast(fuzzData.GetData()); secData.challenge = fuzzData.GetData(); secData.sessionId = fuzzData.GetData(); diff --git a/test/fuzztest/services/privacy/addpermissionusedrecordstub_fuzzer/addpermissionusedrecordstub_fuzzer.cpp b/test/fuzztest/services/privacy/addpermissionusedrecordstub_fuzzer/addpermissionusedrecordstub_fuzzer.cpp index 06f243b65966099a935cb9cf239013d596a01632..100aee308fb078155bf7423973b703fc27fffdb0 100644 --- a/test/fuzztest/services/privacy/addpermissionusedrecordstub_fuzzer/addpermissionusedrecordstub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/addpermissionusedrecordstub_fuzzer/addpermissionusedrecordstub_fuzzer.cpp @@ -39,19 +39,12 @@ namespace OHOS { MessageParcel datas; datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); - if (!datas.WriteUint32(fuzzData.GetData())) { - return false; - } - if (!datas.WriteString(fuzzData.GenerateRandomString())) { - return false; - } - if (!datas.WriteInt32(fuzzData.GetData())) { - return false; - } - if (!datas.WriteInt32(fuzzData.GetData())) { - return false; - } - if (!datas.WriteUint32(fuzzData.GetData())) { + AddPermParamInfoParcel infoParcel; + infoParcel.info.tokenId = static_cast(fuzzData.GetData()); + infoParcel.info.permissionName = fuzzData.GenerateRandomString(); + infoParcel.info.successCount = fuzzData.GetData(); + infoParcel.info.failCount = fuzzData.GetData(); + if (!datas.WriteParcelable(&infoParcel)) { return false; } diff --git a/test/fuzztest/services/privacy/getpermissionusedrecordsasyncstub_fuzzer/getpermissionusedrecordsasyncstub_fuzzer.cpp b/test/fuzztest/services/privacy/getpermissionusedrecordsasyncstub_fuzzer/getpermissionusedrecordsasyncstub_fuzzer.cpp index 6ca9a8db9180b9032ddd407bbe6f7f37885f7149..b6d387076d8394080a9edf709d2bd966dd6aecf3 100644 --- a/test/fuzztest/services/privacy/getpermissionusedrecordsasyncstub_fuzzer/getpermissionusedrecordsasyncstub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/getpermissionusedrecordsasyncstub_fuzzer/getpermissionusedrecordsasyncstub_fuzzer.cpp @@ -25,6 +25,7 @@ #include "i_privacy_manager.h" #include "on_permission_used_record_callback_stub.h" #include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "privacy_manager_service.h" using namespace std; @@ -59,26 +60,20 @@ namespace OHOS { .endTimeMillis = fuzzData.GetData(), .flag = fuzzData.GenerateRandomEnmu(FLAG_PERMISSION_USAGE_SUMMARY_IN_APP_FOREGROUND) }; + PermissionUsedRequestParcel requestParcel; + requestParcel.request = request; + MessageParcel datas; - if (!datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()) || !datas.WriteUint32(request.tokenId) || - !datas.WriteString(request.deviceId) || !datas.WriteString(request.bundleName) || - !datas.WriteUint32(request.permissionList.size())) { - return false; - } - for (const auto& permission : request.permissionList) { - if (!datas.WriteString(permission)) { - return false; - } - } - if (!datas.WriteInt64(request.beginTimeMillis) || !datas.WriteInt64(request.endTimeMillis) || - !datas.WriteInt32(request.flag) || !datas.WriteString(request.bundleName) || - !datas.WriteUint32(request.permissionList.size())) { + datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!datas.WriteParcelable(&requestParcel)) { return false; } + sptr callback(new TestCallBack()); if (!datas.WriteRemoteObject(callback->AsObject())) { return false; } + uint32_t code = static_cast(PrivacyInterfaceCode::GET_PERMISSION_USED_RECORDS_ASYNC); MessageParcel reply; diff --git a/test/fuzztest/services/privacy/getpermissionusedrecordsstub_fuzzer/getpermissionusedrecordsstub_fuzzer.cpp b/test/fuzztest/services/privacy/getpermissionusedrecordsstub_fuzzer/getpermissionusedrecordsstub_fuzzer.cpp index 6c71cc5a95bf920d579364c14d234761d390516f..cd263be468bde0b31ed71ef8ce24b4fe848052c4 100644 --- a/test/fuzztest/services/privacy/getpermissionusedrecordsstub_fuzzer/getpermissionusedrecordsstub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/getpermissionusedrecordsstub_fuzzer/getpermissionusedrecordsstub_fuzzer.cpp @@ -23,6 +23,7 @@ #undef private #include "i_privacy_manager.h" #include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "privacy_manager_service.h" using namespace std; @@ -49,20 +50,12 @@ namespace OHOS { .endTimeMillis = fuzzData.GetData(), .flag = fuzzData.GenerateRandomEnmu(FLAG_PERMISSION_USAGE_SUMMARY_IN_APP_FOREGROUND) }; + PermissionUsedRequestParcel requestParcel; + requestParcel.request = request; + MessageParcel datas; - if (!datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()) || !datas.WriteUint32(request.tokenId) || - !datas.WriteBool(request.isRemote) || !datas.WriteString(request.deviceId) || - !datas.WriteString(request.bundleName) || !datas.WriteUint32(request.permissionList.size())) { - return false; - } - for (const auto& permission : request.permissionList) { - if (!datas.WriteString(permission)) { - return false; - } - } - if (!datas.WriteInt64(request.beginTimeMillis) || !datas.WriteInt64(request.endTimeMillis) || - !datas.WriteInt32(request.flag) || !datas.WriteString(request.bundleName) || - !datas.WriteUint32(request.permissionList.size())) { + datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!datas.WriteParcelable(&requestParcel)) { return false; } diff --git a/test/fuzztest/services/privacy/getseccompenhancestub_fuzzer/getseccompenhancestub_fuzzer.cpp b/test/fuzztest/services/privacy/getseccompenhancestub_fuzzer/getseccompenhancestub_fuzzer.cpp index 5fa01a7d15016aa06bd92b4ada9175652428826c..3a5e4e063787ad25e39fe8faef328f33888bfb41 100644 --- a/test/fuzztest/services/privacy/getseccompenhancestub_fuzzer/getseccompenhancestub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/getseccompenhancestub_fuzzer/getseccompenhancestub_fuzzer.cpp @@ -25,6 +25,7 @@ #include "i_privacy_manager.h" #include "on_permission_used_record_callback_stub.h" #include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "privacy_manager_service.h" using namespace std; diff --git a/test/fuzztest/services/privacy/getspecialseccompenhancestub_fuzzer/getspecialseccompenhancestub_fuzzer.cpp b/test/fuzztest/services/privacy/getspecialseccompenhancestub_fuzzer/getspecialseccompenhancestub_fuzzer.cpp index c68a94fa96803c83ea84d5e6dff362d04b7daeca..e49d8230b1771af98535e3a19b5790b185578114 100644 --- a/test/fuzztest/services/privacy/getspecialseccompenhancestub_fuzzer/getspecialseccompenhancestub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/getspecialseccompenhancestub_fuzzer/getspecialseccompenhancestub_fuzzer.cpp @@ -25,6 +25,7 @@ #include "i_privacy_manager.h" #include "on_permission_used_record_callback_stub.h" #include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "privacy_manager_service.h" using namespace std; diff --git a/test/fuzztest/services/privacy/registerseccompenhancestub_fuzzer/registerseccompenhancestub_fuzzer.cpp b/test/fuzztest/services/privacy/registerseccompenhancestub_fuzzer/registerseccompenhancestub_fuzzer.cpp index 8d56af8b42596c6f33bab01cd4e506d57a7f1072..79a248074ec8d9161823b57e50f1bea024249d65 100644 --- a/test/fuzztest/services/privacy/registerseccompenhancestub_fuzzer/registerseccompenhancestub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/registerseccompenhancestub_fuzzer/registerseccompenhancestub_fuzzer.cpp @@ -27,6 +27,7 @@ #include "i_privacy_manager.h" #include "on_permission_used_record_callback_stub.h" #include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "privacy_manager_service.h" #include "securec.h" #include "token_sync_kit_interface.h" @@ -69,6 +70,7 @@ public: SecCompEnhanceData secData; secData.callback = callback->AsObject(); + secData.pid = fuzzData.GetData(); secData.token = static_cast(fuzzData.GetData()); secData.challenge = fuzzData.GetData(); secData.sessionId = fuzzData.GetData(); @@ -80,16 +82,17 @@ public: return false; } + SecCompEnhanceDataParcel enhance; + enhance.enhanceData = secData; + MessageParcel datas; - ; - if (!datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()) || !datas.WriteUint32(secData.token) || - !datas.WriteUint64(secData.challenge) || !datas.WriteUint32(secData.sessionId) || - !datas.WriteUint32(secData.seqNum) || !datas.WriteBuffer(secData.key, AES_KEY_STORAGE_LEN) || - !datas.WriteRemoteObject(secData.callback)) { + datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + if (!datas.WriteParcelable(&enhance)) { return false; } uint32_t code = static_cast(PrivacyInterfaceCode::REGISTER_SEC_COMP_ENHANCE); + MessageParcel reply; MessageOption option; DelayedSingleton::GetInstance()->OnRemoteRequest(code, datas, reply, option); diff --git a/test/fuzztest/services/privacy/updateseccompenhancestub_fuzzer/updateseccompenhancestub_fuzzer.cpp b/test/fuzztest/services/privacy/updateseccompenhancestub_fuzzer/updateseccompenhancestub_fuzzer.cpp index 4e837f1eab0f90e8e6d1e8b36325e63806e8adcd..28b4600067640545d551d64976c4d4042d17b57a 100644 --- a/test/fuzztest/services/privacy/updateseccompenhancestub_fuzzer/updateseccompenhancestub_fuzzer.cpp +++ b/test/fuzztest/services/privacy/updateseccompenhancestub_fuzzer/updateseccompenhancestub_fuzzer.cpp @@ -25,6 +25,7 @@ #include "i_privacy_manager.h" #include "on_permission_used_record_callback_stub.h" #include "permission_used_request.h" +#include "permission_used_request_parcel.h" #include "privacy_manager_service.h" using namespace std;