mirror of
https://github.com/openharmony/security_security_component_manager.git
synced 2026-08-24 14:33:25 -04:00
@@ -68,6 +68,9 @@ public:
|
||||
|
||||
// notify process died
|
||||
virtual void NotifyProcessDied(int32_t pid) = 0;
|
||||
|
||||
// notify process registered
|
||||
virtual void AddSecurityComponentProcess(int32_t pid) = 0;
|
||||
};
|
||||
|
||||
// for client
|
||||
@@ -105,6 +108,8 @@ public:
|
||||
static void RegisterScIdEnhance(int32_t scId);
|
||||
static void UnregisterScIdEnhance(int32_t scId);
|
||||
|
||||
static void AddSecurityComponentProcess(int32_t pid);
|
||||
|
||||
static SecCompInputEnhanceInterface* inputHandler;
|
||||
static bool isEnhanceInputHandlerInit;
|
||||
|
||||
|
||||
@@ -105,6 +105,16 @@ int32_t SecCompEnhanceAdapter::CheckExtraInfo(const SecCompClickEvent& clickInfo
|
||||
return SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE;
|
||||
}
|
||||
|
||||
void SecCompEnhanceAdapter::AddSecurityComponentProcess(int32_t pid)
|
||||
{
|
||||
if (!isEnhanceSrvHandlerInit) {
|
||||
InitEnhanceHandler(SEC_COMP_ENHANCE_SRV_INTERFACE);
|
||||
}
|
||||
if (srvHandler != nullptr) {
|
||||
srvHandler->AddSecurityComponentProcess(pid);
|
||||
}
|
||||
}
|
||||
|
||||
bool SecCompEnhanceAdapter::EnhanceDataPreprocess(std::string& componentInfo)
|
||||
{
|
||||
if (!isEnhanceClientHandlerInit) {
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken) = 0;
|
||||
virtual bool VerifySavePermission(AccessToken::AccessTokenID tokenId) = 0;
|
||||
virtual sptr<IRemoteObject> GetEnhanceRemoteObject() = 0;
|
||||
virtual int32_t PreRegisterSecCompProcess() = 0;
|
||||
};
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken);
|
||||
bool VerifySavePermission(AccessToken::AccessTokenID tokenId);
|
||||
sptr<IRemoteObject> GetEnhanceRemoteObject(bool doLoadSa);
|
||||
int32_t PreRegisterSecCompProcess();
|
||||
|
||||
void FinishStartSASuccess(const sptr<IRemoteObject>& remoteObject);
|
||||
void FinishStartSAFail();
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken = nullptr);
|
||||
static bool VerifySavePermission(AccessToken::AccessTokenID tokenId);
|
||||
static sptr<IRemoteObject> GetEnhanceRemoteObject(bool isLoad);
|
||||
static int32_t PreRegisterSecCompProcess();
|
||||
};
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken) override;
|
||||
bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override;
|
||||
sptr<IRemoteObject> GetEnhanceRemoteObject() override;
|
||||
int32_t PreRegisterSecCompProcess() override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<SecCompProxy> delegator_;
|
||||
|
||||
+1
-1
@@ -27,6 +27,7 @@ enum SecurityComponentServiceInterfaceCode {
|
||||
REPORT_SECURITY_COMPONENT_CLICK_EVENT = 3,
|
||||
GET_SECURITY_COMPONENT_ENHANCE_OBJECT = 4,
|
||||
VERIFY_TEMP_SAVE_PERMISSION = 5,
|
||||
PRE_REGISTER_PROCESS = 6,
|
||||
};
|
||||
|
||||
enum EnhanceInterfaceCode {
|
||||
@@ -41,4 +42,3 @@ enum EnhanceCallbackCheckCode {
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
#endif // SECURITY_COMPONENT_IPC_INTERFACE_CODE_H
|
||||
|
||||
|
||||
@@ -113,6 +113,17 @@ sptr<IRemoteObject> SecCompClient::GetEnhanceRemoteObject(bool doLoadSa)
|
||||
return proxy->GetEnhanceRemoteObject();
|
||||
}
|
||||
|
||||
int32_t SecCompClient::PreRegisterSecCompProcess()
|
||||
{
|
||||
auto proxy = GetProxy(true);
|
||||
if (proxy == nullptr) {
|
||||
SC_LOG_ERROR(LABEL, "Proxy is null");
|
||||
return SC_SERVICE_ERROR_VALUE_INVALID;
|
||||
}
|
||||
|
||||
return proxy->PreRegisterSecCompProcess();
|
||||
}
|
||||
|
||||
bool SecCompClient::StartLoadSecCompSa()
|
||||
{
|
||||
{
|
||||
|
||||
@@ -133,6 +133,11 @@ sptr<IRemoteObject> SecCompKit::GetEnhanceRemoteObject(bool isLoad)
|
||||
{
|
||||
return SecCompClient::GetInstance().GetEnhanceRemoteObject(isLoad);
|
||||
}
|
||||
|
||||
int32_t SecCompKit::PreRegisterSecCompProcess()
|
||||
{
|
||||
return SecCompClient::GetInstance().PreRegisterSecCompProcess();
|
||||
}
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -269,6 +269,36 @@ sptr<IRemoteObject> SecCompProxy::GetEnhanceRemoteObject()
|
||||
}
|
||||
return callback;
|
||||
}
|
||||
|
||||
int32_t SecCompProxy::PreRegisterSecCompProcess()
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) {
|
||||
SC_LOG_ERROR(LABEL, "PreRegister write descriptor fail");
|
||||
return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
SC_LOG_ERROR(LABEL, "PreRegister remote service is null");
|
||||
return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL;
|
||||
}
|
||||
int32_t requestResult = remote->SendRequest(
|
||||
static_cast<uint32_t>(SecurityComponentServiceInterfaceCode::PRE_REGISTER_PROCESS),
|
||||
data, reply, option);
|
||||
if (requestResult != SC_OK) {
|
||||
SC_LOG_ERROR(LABEL, "PreRegister request fail, result: %{public}d", requestResult);
|
||||
return requestResult;
|
||||
}
|
||||
int32_t res;
|
||||
if (!reply.ReadInt32(res)) {
|
||||
SC_LOG_ERROR(LABEL, "PreRegister read int32 fail");
|
||||
return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -155,7 +155,7 @@ SecCompEntity* SecCompManager::GetSecurityComponentFromList(int32_t pid, int32_t
|
||||
bool SecCompManager::IsForegroundCompExist()
|
||||
{
|
||||
return std::any_of(componentMap_.begin(), componentMap_.end(), [](const auto & iter) {
|
||||
return (iter.second.isForeground) && (iter.second.compList.size() > 0);
|
||||
return iter.second.isForeground;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -285,6 +285,29 @@ void SecCompManager::SendCheckInfoEnhanceSysEvent(int32_t scId,
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SecCompManager::AddSecurityComponentProcess(const SecCompCallerInfo& caller)
|
||||
{
|
||||
DelayExitTask::GetInstance().Stop();
|
||||
{
|
||||
OHOS::Utils::UniqueWriteGuard<OHOS::Utils::RWLock> lk(this->componentInfoLock_);
|
||||
if (isSaExit_) {
|
||||
SC_LOG_ERROR(LABEL, "SA is exiting, retry...");
|
||||
return SC_SERVICE_ERROR_SERVICE_NOT_EXIST;
|
||||
}
|
||||
|
||||
auto iter = componentMap_.find(caller.pid);
|
||||
if (iter != componentMap_.end()) {
|
||||
ProcessCompInfos newProcess;
|
||||
newProcess.isForeground = true;
|
||||
newProcess.tokenId = caller.tokenId;
|
||||
componentMap_[caller.pid] = newProcess;
|
||||
}
|
||||
SecCompEnhanceAdapter::EnableInputEnhance();
|
||||
}
|
||||
SecCompEnhanceAdapter::AddSecurityComponentProcess(caller.pid);
|
||||
return SC_OK;
|
||||
}
|
||||
|
||||
int32_t SecCompManager::RegisterSecurityComponent(SecCompType type,
|
||||
const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, int32_t& scId)
|
||||
{
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
bool Initialize();
|
||||
void ExitSaProcess();
|
||||
void ExitWhenAppMgrDied();
|
||||
int32_t AddSecurityComponentProcess(const SecCompCallerInfo& caller);
|
||||
|
||||
private:
|
||||
SecCompManager();
|
||||
|
||||
@@ -84,8 +84,6 @@ void SecCompService::OnStop()
|
||||
SC_LOG_INFO(LABEL, "Stop service");
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
UnregisterAppStateObserver();
|
||||
iAppMgr_ = nullptr;
|
||||
appStateObserver_ = nullptr;
|
||||
}
|
||||
|
||||
bool SecCompService::RegisterAppStateObserver()
|
||||
@@ -236,6 +234,16 @@ int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId,
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t SecCompService::PreRegisterSecCompProcess()
|
||||
{
|
||||
SecCompCallerInfo caller;
|
||||
if (!GetCallerInfo(caller)) {
|
||||
SC_LOG_ERROR(LABEL, "Check caller failed");
|
||||
return SC_SERVICE_ERROR_VALUE_INVALID;
|
||||
}
|
||||
return SecCompManager::GetInstance().AddSecurityComponentProcess(caller);
|
||||
}
|
||||
|
||||
bool SecCompService::VerifySavePermission(AccessToken::AccessTokenID tokenId)
|
||||
{
|
||||
return SecCompPermManager::GetInstance().VerifySavePermission(tokenId);
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken) override;
|
||||
bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override;
|
||||
sptr<IRemoteObject> GetEnhanceRemoteObject() override;
|
||||
int32_t PreRegisterSecCompProcess() override;
|
||||
|
||||
int Dump(int fd, const std::vector<std::u16string>& args) override;
|
||||
|
||||
|
||||
@@ -205,6 +205,16 @@ int32_t SecCompStub::GetEnhanceRemoteObjectInner(MessageParcel& data, MessagePar
|
||||
return SC_OK;
|
||||
}
|
||||
|
||||
int32_t SecCompStub::PreRegisterSecCompProcessInner(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
int32_t res = this->PreRegisterSecCompProcess();
|
||||
if (!reply.WriteInt32(res)) {
|
||||
SC_LOG_ERROR(LABEL, "preRegister write result fail");
|
||||
return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL;
|
||||
}
|
||||
return SC_OK;
|
||||
}
|
||||
|
||||
bool SecCompStub::IsMediaLibraryCalling()
|
||||
{
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
@@ -236,6 +246,9 @@ SecCompStub::SecCompStub()
|
||||
requestFuncMap_[static_cast<uint32_t>(
|
||||
SecurityComponentServiceInterfaceCode::GET_SECURITY_COMPONENT_ENHANCE_OBJECT)] =
|
||||
&SecCompStub::GetEnhanceRemoteObjectInner;
|
||||
requestFuncMap_[static_cast<uint32_t>(
|
||||
SecurityComponentServiceInterfaceCode::PRE_REGISTER_PROCESS)] =
|
||||
&SecCompStub::PreRegisterSecCompProcessInner;
|
||||
}
|
||||
|
||||
SecCompStub::~SecCompStub()
|
||||
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
int32_t ReportSecurityComponentClickEventInner(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t VerifySavePermissionInner(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t GetEnhanceRemoteObjectInner(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t PreRegisterSecCompProcessInner(MessageParcel& data, MessageParcel& reply);
|
||||
bool IsMediaLibraryCalling();
|
||||
|
||||
using RequestFuncType = int32_t (SecCompStub::*)(MessageParcel& data, MessageParcel& reply);
|
||||
|
||||
@@ -105,6 +105,11 @@ sptr<IRemoteObject> SecCompEnhanceAdapter::GetEnhanceRemoteObject()
|
||||
SC_LOG_DEBUG(LABEL, "GetEnhanceRemoteObject success");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SecCompEnhanceAdapter::AddSecurityComponentProcess(int32_t pid)
|
||||
{
|
||||
SC_LOG_DEBUG(LABEL, "AddSecurityComponentProcess success");
|
||||
}
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -570,14 +570,14 @@ HWTEST_F(SecCompManagerTest, ExitSaProcess001, TestSize.Level1)
|
||||
std::shared_ptr<SystemAbilityManagerClient> saClient = std::make_shared<SystemAbilityManagerClient>();
|
||||
ASSERT_NE(nullptr, saClient);
|
||||
SystemAbilityManagerClient::clientInstance = saClient.get();
|
||||
SystemAbilityManagerProxy proxy(nullptr);
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
sptr<SystemAbilityManagerProxy> proxy = new SystemAbilityManagerProxy(nullptr);
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
instance->ExitSaProcess();
|
||||
EXPECT_TRUE(instance->isSaExit_);
|
||||
instance->isSaExit_ = false;
|
||||
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
EXPECT_CALL(proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1));
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
EXPECT_CALL(*proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1));
|
||||
instance->ExitSaProcess();
|
||||
EXPECT_TRUE(instance->isSaExit_);
|
||||
}
|
||||
@@ -608,17 +608,17 @@ HWTEST_F(SecCompManagerTest, ExitWhenAppMgrDied001, TestSize.Level1)
|
||||
instance->ExitWhenAppMgrDied();
|
||||
EXPECT_TRUE(instance->isSaExit_);
|
||||
|
||||
SystemAbilityManagerProxy proxy(nullptr);
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
sptr<SystemAbilityManagerProxy> proxy = new SystemAbilityManagerProxy(nullptr);
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
instance->ExitWhenAppMgrDied();
|
||||
EXPECT_TRUE(instance->isSaExit_);
|
||||
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
instance->ExitWhenAppMgrDied();
|
||||
EXPECT_TRUE(instance->isSaExit_);
|
||||
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
EXPECT_CALL(proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1));
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
EXPECT_CALL(*proxy, UnloadSystemAbility(testing::_)).WillOnce(testing::Return(-1));
|
||||
instance->ExitWhenAppMgrDied();
|
||||
EXPECT_TRUE(instance->isSaExit_);
|
||||
}
|
||||
|
||||
@@ -114,15 +114,15 @@ HWTEST_F(SecCompServiceTest, RegisterAppStateObserver001, TestSize.Level1)
|
||||
|
||||
// GetSystemAbility get app mgr failed
|
||||
secCompService_->appStateObserver_ = nullptr;
|
||||
SystemAbilityManagerProxy proxy(nullptr);
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
sptr<SystemAbilityManagerProxy> proxy = new SystemAbilityManagerProxy(nullptr);
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
EXPECT_FALSE(secCompService_->RegisterAppStateObserver());
|
||||
|
||||
// RegisterApplicationStateObserver failed
|
||||
secCompService_->appStateObserver_ = nullptr;
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
MockIRemoteObject object;
|
||||
EXPECT_CALL(proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(&object));
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
sptr<MockIRemoteObject> object = new MockIRemoteObject();
|
||||
EXPECT_CALL(*proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(object));
|
||||
sptr<MockAppMgrProxy> appProxy = new (std::nothrow) MockAppMgrProxy(nullptr);
|
||||
MockAppMgrProxy::g_MockAppMgrProxy = appProxy;
|
||||
EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy,
|
||||
@@ -131,8 +131,8 @@ HWTEST_F(SecCompServiceTest, RegisterAppStateObserver001, TestSize.Level1)
|
||||
|
||||
// GetForegroundApplications failed
|
||||
secCompService_->appStateObserver_ = nullptr;
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
EXPECT_CALL(proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(&object));
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
EXPECT_CALL(*proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(object));
|
||||
EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy,
|
||||
RegisterApplicationStateObserver(testing::_, testing::_)).WillOnce(testing::Return(0));
|
||||
EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy,
|
||||
@@ -142,8 +142,8 @@ HWTEST_F(SecCompServiceTest, RegisterAppStateObserver001, TestSize.Level1)
|
||||
|
||||
// get one foreground app
|
||||
secCompService_->appStateObserver_ = nullptr;
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(&proxy));
|
||||
EXPECT_CALL(proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(&object));
|
||||
EXPECT_CALL(*saClient, GetSystemAbilityManager()).WillOnce(testing::Return(proxy));
|
||||
EXPECT_CALL(*proxy, GetSystemAbility(testing::_)).WillOnce(testing::Return(object));
|
||||
EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy,
|
||||
RegisterApplicationStateObserver(testing::_, testing::_)).WillOnce(testing::Return(0));
|
||||
EXPECT_CALL(*MockAppMgrProxy::g_MockAppMgrProxy, GetForegroundApplications(testing::_))
|
||||
|
||||
@@ -52,12 +52,17 @@ public:
|
||||
bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
sptr<IRemoteObject> GetEnhanceRemoteObject() override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
int32_t PreRegisterSecCompProcess() override
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
class SecCompStubTest : public testing::Test {
|
||||
|
||||
Reference in New Issue
Block a user