fscrypt:add fscrypt storage manager ipc

Signed-off-by: zhangqilong <zhangqilong3@huawei.com>
Change-Id: Ie7559401682c36fb4aa9511315f72c4778aebf3b
This commit is contained in:
zhangqilong 2022-02-10 11:35:16 +08:00
parent 73f88c8493
commit 5501852c9b
15 changed files with 790 additions and 1 deletions

View File

@ -43,6 +43,14 @@ public:
virtual void NotifyDiskDestroyed(std::string diskId) = 0;
virtual int32_t Partition(std::string diskId, int32_t type) = 0;
virtual std::vector<Disk> GetAllDisks() = 0;
// fscrypt api
virtual int32_t GenerateUserKeys(uint32_t userId, uint32_t flags) = 0;
virtual int32_t DeleteUserKeys(uint32_t userId) = 0;
virtual int32_t UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret) = 0;
virtual int32_t ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret) = 0;
virtual int32_t InactiveUserKey(uint32_t userId) = 0;
enum {
PREPARE_ADD_USER = 1,
REMOVE_USER,
@ -60,7 +68,12 @@ public:
NOTIFY_DISK_CREATED,
NOTIFY_DISK_DESTROYED,
PARTITION,
GET_ALL_DISKS
GET_ALL_DISKS,
CREATE_USER_KEYS,
DELETE_USER_KEYS,
UPDATE_USER_AUTH,
ACTIVE_USER_KEY,
INACTIVE_USER_KEY,
};
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.StorageManager.IStorageManager");

View File

@ -43,6 +43,7 @@ ohos_shared_library("storage_manager") {
configs = [ ":storage_manager_config" ]
deps = [
":smc",
"../../interfaces/innerkits/storage_manager/native:storage_manager_sa_proxy",
"//base/account/os_account/frameworks/common:libaccount_common",
"//foundation/appexecfwk/standard/services/bundlemgr:libbms",
@ -65,3 +66,44 @@ ohos_shared_library("storage_manager") {
part_name = "storage_service"
install_enable = true
}
config("smc_config") {
include_dirs = [
"include",
"../storage_daemon/include",
"../../interfaces/innerkits/storage_manager/native",
"//utils/system/safwk/native/include",
"//utils/native/base/include",
"//foundation/filemanagement/storage_service/utils/include",
"//foundation/appexecfwk/standard/services/bundlemgr/include",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
]
}
ohos_executable("smc") {
sources = [
"client/storage_manager_client.cpp",
"ipc/src/storage_manager_proxy.cpp",
"smc.cpp",
"../storage_daemon/utils/file_utils.cpp",
"innerkits_impl/src/volume_core.cpp",
"innerkits_impl/src/volume_external.cpp",
"innerkits_impl/src/disk.cpp",
]
configs = [ ":smc_config" ]
public_deps = [ "//utils/native/base:utils" ]
external_deps = [
"bundle_framework:appexecfwk_base",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"os_account_standard:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
]
subsystem_name = "filemanagement"
part_name = "storage_service"
install_enable = true
}

View File

@ -0,0 +1,119 @@
/*
* Copyright (c) 2021 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 "client/storage_manager_client.h"
#include "iremote_object.h"
#include "iremote_proxy.h"
#include "iservice_registry.h"
#include "storage_service_log.h"
#include "system_ability_definition.h"
namespace OHOS {
namespace StorageManager {
sptr<IStorageManager> StorageManagerClient::GetStorageManagerProxy(void)
{
auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
LOGE("samgr empty error");
return nullptr;
}
sptr<IRemoteObject> object = samgr->GetSystemAbility(OHOS::STORAGE_MANAGER_MANAGER_ID);
if (object == nullptr) {
LOGE("storage manager client samgr ablity empty error");
return nullptr;
}
return iface_cast<IStorageManager>(object);
}
int32_t StorageManagerClient::PrepareUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->PrepareAddUser(userId);
}
int32_t StorageManagerClient::DestroyUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->RemoveUser(userId);
}
int32_t StorageManagerClient::GenerateUserKeys(uint32_t userId, uint32_t flags)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->GenerateUserKeys(userId, flags);
}
int32_t StorageManagerClient::DeleteUserKeys(uint32_t userId)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->DeleteUserKeys(userId);
}
int32_t StorageManagerClient::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->UpdateUserAuth(userId, auth, compSecret);
}
int32_t StorageManagerClient::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->ActiveUserKey(userId, auth, compSecret);
}
int32_t StorageManagerClient::InactiveUserKey(uint32_t userId)
{
sptr<IStorageManager> client = GetStorageManagerProxy();
if (client == nullptr) {
LOGE("get storage manager service failed");
return -EFAULT;
}
return client->InactiveUserKey(userId);
}
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2021 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 STORAGE_MANAGER_CILENT_H
#define STORAGE_MANAGER_CILENT_H
#include "iremote_proxy.h"
#include "istorage_manager.h"
#include "ipc/storage_manager.h"
#include "ipc/storage_manager_proxy.h"
namespace OHOS {
namespace StorageManager {
class StorageManagerClient {
public:
static int32_t PrepareUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags);
static int32_t DestroyUserSpace(uint32_t userId, const std::string &volumId, uint32_t flags);
static int32_t GenerateUserKeys(uint32_t userId, uint32_t flags);
static int32_t DeleteUserKeys(uint32_t userId);
static int32_t UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret);
static int32_t ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret);
static int32_t InactiveUserKey(uint32_t userId);
private:
static sptr<IStorageManager> GetStorageManagerProxy(void);
};
}
}
#endif

View File

@ -54,6 +54,13 @@ public:
void NotifyDiskDestroyed(std::string diskId) override;
int32_t Partition(std::string diskId, int32_t type) override;
std::vector<Disk> GetAllDisks() override;
// fscrypt api
int32_t GenerateUserKeys(uint32_t userId, uint32_t flags) override;
int32_t DeleteUserKeys(uint32_t userId) override;
int32_t UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret) override;
int32_t ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret) override;
int32_t InactiveUserKey(uint32_t userId) override;
private:
StorageManager();
static sptr<StorageManager> instance_;

View File

@ -45,6 +45,14 @@ public:
void NotifyDiskDestroyed(std::string diskId) override;
int32_t Partition(std::string diskId, int32_t type) override;
std::vector<Disk> GetAllDisks() override;
// fscrypt api
int32_t GenerateUserKeys(uint32_t userId, uint32_t flags) override;
int32_t DeleteUserKeys(uint32_t userId) override;
int32_t UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret) override;
int32_t ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret) override;
int32_t InactiveUserKey(uint32_t userId) override;
private:
static inline BrokerDelegator<StorageManagerProxy> delegator_;
};

View File

@ -43,6 +43,13 @@ private:
int32_t HandleNotifyDiskDestroyed(MessageParcel &data, MessageParcel &reply);
int32_t HandlePartition(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetAllDisks(MessageParcel &data, MessageParcel &reply);
// fscrypt api
int32_t HandleGenerateUserKeys(MessageParcel &data, MessageParcel &reply);
int32_t HandleDeleteUserKeys(MessageParcel &data, MessageParcel &reply);
int32_t HandleUpdateUserAuth(MessageParcel &data, MessageParcel &reply);
int32_t HandleActiveUserKey(MessageParcel &data, MessageParcel &reply);
int32_t HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply);
};
} // StorageManager
} // OHOS

View File

@ -42,6 +42,14 @@ public:
int32_t Unmount(std::string volumeId);
int32_t Check(std::string volumeId);
int32_t Partition(std::string diskId, int32_t type);
// fscrypt api
int32_t GenerateUserKeys(uint32_t userId, uint32_t flags);
int32_t DeleteUserKeys(uint32_t userId);
int32_t UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret);
int32_t ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret);
int32_t InactiveUserKey(uint32_t userId);
private:
sptr<OHOS::StorageDaemon::IStorageDaemon> storageDaemon_;
};

View File

@ -29,6 +29,13 @@ public:
int32_t RemoveUser(int32_t userId);
int32_t PrepareStartUser(int32_t userId);
int32_t StopUser(int32_t userId);
// fscrypt api
int32_t GenerateUserKeys(uint32_t userId, uint32_t flags);
int32_t DeleteUserKeys(uint32_t userId);
int32_t UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret);
int32_t ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret);
int32_t InactiveUserKey(uint32_t userId);
private:
int32_t CheckUserIdRange(int32_t userId);
};

View File

@ -162,5 +162,45 @@ std::vector<Disk> StorageManager::GetAllDisks()
std::vector<Disk> result = DelayedSingleton<DiskManagerService>::GetInstance()->GetAllDisks();
return result;
}
int32_t StorageManager::GenerateUserKeys(uint32_t userId, uint32_t flags)
{
LOGI("UserId: %{public}u, flags: %{public}u", userId, flags);
std::shared_ptr<MultiUserManagerService> userManager = DelayedSingleton<MultiUserManagerService>::GetInstance();
int32_t err = userManager->GenerateUserKeys(userId, flags);
return err;
}
int32_t StorageManager::DeleteUserKeys(uint32_t userId)
{
LOGI("UserId: %{public}u", userId);
std::shared_ptr<MultiUserManagerService> userManager = DelayedSingleton<MultiUserManagerService>::GetInstance();
int32_t err = userManager->DeleteUserKeys(userId);
return err;
}
int32_t StorageManager::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("UserId: %{public}u", userId);
std::shared_ptr<MultiUserManagerService> userManager = DelayedSingleton<MultiUserManagerService>::GetInstance();
int32_t err = userManager->UpdateUserAuth(userId, auth, compSecret);
return err;
}
int32_t StorageManager::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("UserId: %{public}u", userId);
std::shared_ptr<MultiUserManagerService> userManager = DelayedSingleton<MultiUserManagerService>::GetInstance();
int32_t err = userManager->ActiveUserKey(userId, auth, compSecret);
return err;
}
int32_t StorageManager::InactiveUserKey(uint32_t userId)
{
LOGI("UserId: %{public}u", userId);
std::shared_ptr<MultiUserManagerService> userManager = DelayedSingleton<MultiUserManagerService>::GetInstance();
int32_t err = userManager->InactiveUserKey(userId);
return err;
}
}
}

View File

@ -103,6 +103,136 @@ int32_t StorageManagerProxy::StopUser(int32_t userId)
return reply.ReadUint32();
}
int32_t StorageManagerProxy::GenerateUserKeys(uint32_t userId, uint32_t flags)
{
LOGI("user ID: %{public}u, flags: %{public}u", userId, flags);
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
LOGE("WriteInterfaceToken failed");
return E_IPC_ERROR;
}
if (!data.WriteUint32(userId)) {
LOGE("Write user ID failed");
return E_IPC_ERROR;
}
if (!data.WriteUint32(flags)) {
LOGE("Write key flags failed");
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(CREATE_USER_KEYS, data, reply, option);
if (err != E_OK) {
LOGE("SendRequest failed");
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageManagerProxy::DeleteUserKeys(uint32_t userId)
{
LOGI("user ID: %{public}u", userId);
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
LOGE("WriteInterfaceToken failed");
return E_IPC_ERROR;
}
if (!data.WriteUint32(userId)) {
LOGE("Write user ID failed");
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(DELETE_USER_KEYS, data, reply, option);
if (err != E_OK) {
LOGE("SendRequest failed");
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageManagerProxy::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("user ID: %{public}u", userId);
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
LOGE("WriteInterfaceToken failed");
return E_IPC_ERROR;
}
if (!data.WriteUint32(userId)) {
LOGE("Write user ID failed");
return E_IPC_ERROR;
}
if (!data.WriteString(auth)) {
LOGE("Write user auth failed");
return E_IPC_ERROR;
}
if (!data.WriteString(compSecret)) {
LOGE("Write user secret failed");
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(UPDATE_USER_AUTH, data, reply, option);
if (err != E_OK) {
LOGE("SendRequest failed");
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageManagerProxy::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("user ID: %{public}u", userId);
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
LOGE("WriteInterfaceToken failed");
return E_IPC_ERROR;
}
if (!data.WriteUint32(userId)) {
LOGE("Write user ID failed");
return E_IPC_ERROR;
}
if (!data.WriteString(auth)) {
LOGE("Write user auth failed");
return E_IPC_ERROR;
}
if (!data.WriteString(compSecret)) {
LOGE("Write user secret failed");
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(ACTIVE_USER_KEY, data, reply, option);
if (err != E_OK) {
LOGE("SendRequest failed");
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int32_t StorageManagerProxy::InactiveUserKey(uint32_t userId)
{
LOGI("user ID: %{public}u", userId);
MessageParcel data, reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(StorageManagerProxy::GetDescriptor())) {
LOGE("WriteInterfaceToken failed");
return E_IPC_ERROR;
}
if (!data.WriteUint32(userId)) {
LOGE("Write user ID failed");
return E_IPC_ERROR;
}
int err = Remote()->SendRequest(INACTIVE_USER_KEY, data, reply, option);
if (err != E_OK) {
LOGE("SendRequest failed");
return E_IPC_ERROR;
}
return reply.ReadInt32();
}
int64_t StorageManagerProxy::GetFreeSizeOfVolume(std::string volumeUuid)
{
LOGI("StorageManagerProxy::GetFreeSizeOfVolume, volumeUuid:%{public}s", volumeUuid.c_str());

View File

@ -80,6 +80,21 @@ int32_t StorageManagerStub::OnRemoteRequest(uint32_t code,
case GET_ALL_DISKS:
HandleGetAllDisks(data, reply);
break;
case CREATE_USER_KEYS:
HandleGenerateUserKeys(data, reply);
break;
case DELETE_USER_KEYS:
HandleDeleteUserKeys(data, reply);
break;
case UPDATE_USER_AUTH:
HandleUpdateUserAuth(data, reply);
break;
case ACTIVE_USER_KEY:
HandleActiveUserKey(data, reply);
break;
case INACTIVE_USER_KEY:
HandleInactiveUserKey(data, reply);
break;
default: {
LOGI("use IPCObjectStub default OnRemoteRequest");
err = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@ -295,5 +310,70 @@ int32_t StorageManagerStub::HandleGetAllDisks(MessageParcel &data, MessageParcel
}
return E_OK;
}
int32_t StorageManagerStub::HandleGenerateUserKeys(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
uint32_t flags = data.ReadUint32();
int32_t err = GenerateUserKeys(userId, flags);
if (!reply.WriteInt32(err)) {
LOGE("Write reply error code failed");
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageManagerStub::HandleDeleteUserKeys(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
int32_t err = DeleteUserKeys(userId);
if (!reply.WriteInt32(err)) {
LOGE("Write reply error code failed");
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageManagerStub::HandleUpdateUserAuth(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
std::string auth = data.ReadString();
std::string compSecret = data.ReadString();
int32_t err = UpdateUserAuth(userId, auth, compSecret);
if (!reply.WriteInt32(err)) {
LOGE("Write reply error code failed");
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageManagerStub::HandleActiveUserKey(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
std::string auth = data.ReadString();
std::string compSecret = data.ReadString();
int32_t err = ActiveUserKey(userId, auth, compSecret);
if (!reply.WriteInt32(err)) {
LOGE("Write reply error code failed");
return E_IPC_ERROR;
}
return E_OK;
}
int32_t StorageManagerStub::HandleInactiveUserKey(MessageParcel &data, MessageParcel &reply)
{
uint32_t userId = data.ReadUint32();
int32_t err = InactiveUserKey(userId);
if (!reply.WriteInt32(err)) {
LOGE("Write reply error code failed");
return E_IPC_ERROR;
}
return E_OK;
}
} // StorageManager
} // OHOS

View File

@ -0,0 +1,167 @@
/*
* Copyright (C) 2021 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 <iostream>
#include <string>
#include <vector>
#include "client/storage_manager_client.h"
#include "storage_service_log.h"
#include "utils/file_utils.h"
static void HandleFileCrypt(const std::string &cmd, const std::vector<std::string> &args)
{
LOGI("fscrypt cmd: %{public}s", cmd.c_str());
if (cmd == "generate_user_keys") {
// smc filecrypt generate_user_keys userId flag
if (args.size() < 5) { // para.5: parameter nums
LOGE("Parameter nums is less than 5, please retry");
return;
}
uint32_t userId, flags;
if ((OHOS::StorageDaemon::StringToUint32(args[3], userId) == false) || // para.3: user id str
(OHOS::StorageDaemon::StringToUint32(args[4], flags) == false)) { // para.4: flags str
LOGE("Parameter input error, please retry");
return;
}
int32_t ret = OHOS::StorageManager::StorageManagerClient::GenerateUserKeys(userId, flags);
if (ret) {
LOGE("Create user %{public}u el failed ret %{public}d", userId, ret);
return;
}
} else if (cmd == "prepare_user_space") {
// smc filecrypt prepare_user_space userId flag
if (args.size() < 5) { // para.5: parameter nums
LOGE("Parameter nums is less than 5, please retry");
return;
}
uint32_t userId, flags;
if ((OHOS::StorageDaemon::StringToUint32(args[3], userId) == false) || // para.3: user id str
(OHOS::StorageDaemon::StringToUint32(args[4], flags) == false)) { // para.4: flags str
LOGE("Parameter input error, please retry");
return;
}
std::string volumId = "";
int32_t ret = OHOS::StorageManager::StorageManagerClient::PrepareUserSpace(userId, volumId, flags);
if (ret) {
LOGE("Prepare user %{public}u storage failed ret %{public}d", userId, ret);
return;
}
} else if (cmd == "delete_user_keys") {
// smc filecrypt delete_user_keys userId
if (args.size() < 4) { // para.4: parameter nums
LOGE("Parameter nums is less than 4, please retry");
return;
}
uint32_t userId;
if (OHOS::StorageDaemon::StringToUint32(args[3], userId) == false) { // para.3: user id str
LOGE("Parameter input error, please retry");
return;
}
int ret = OHOS::StorageManager::StorageManagerClient::DeleteUserKeys(userId);
if (ret) {
LOGE("Delete user %{public}u key failed ret %{public}d", userId, ret);
return;
}
} else if (cmd == "destroy_user_space") {
// smc filecrypt destory_user_space userId flags
if (args.size() < 5) { // para.5: parameter nums
LOGE("Parameter nums is less than 4, please retry");
return;
}
uint32_t userId, flags;
if (OHOS::StorageDaemon::StringToUint32(args[3], userId) == false || // para.3: user id str
OHOS::StorageDaemon::StringToUint32(args[4], flags) == false) { // para.4: flags str
LOGE("Parameter input error, please retry");
return;
}
std::string volumId = "";
int ret = OHOS::StorageManager::StorageManagerClient::DestroyUserSpace(userId, volumId, flags);
if (ret) {
LOGE("Destroy user %{public}u space failed ret %{public}d", userId, ret);
return;
}
} else if (cmd == "update_user_auth") {
// smc filecrypt update_user_auth userId token secret
if (args.size() < 6) { // para.6: parameter nums
LOGE("Parameter nums is less than 4, please retry");
return;
}
uint32_t userId;
if (OHOS::StorageDaemon::StringToUint32(args[3], userId) == false) { // para.3: user id str
LOGE("Parameter input error, please retry");
return;
}
std::string token = args[4]; // para.4: token str
std::string secret = args[5]; // para.5: secret str
int ret = OHOS::StorageManager::StorageManagerClient::UpdateUserAuth(userId, token, secret);
if (ret) {
LOGE("Update user %{public}u auth failed ret %{public}d", userId, ret);
return;
}
} else if (cmd == "active_user_key") {
// smc filecrypt active_user_key userId token secret
if (args.size() < 6) { // para.6: parameter nums
LOGE("Parameter nums is less than 4, please retry");
return;
}
uint32_t userId;
if (OHOS::StorageDaemon::StringToUint32(args[3], userId) == false) { // para.3: user id str
LOGE("Parameter input error, please retry");
return;
}
std::string token = args[4]; // para.4: token str
std::string secret = args[5]; // para.5: secert str
int ret = OHOS::StorageManager::StorageManagerClient::ActiveUserKey(userId, token, secret);
if (ret) {
LOGE("Active user %{public}u key failed ret %{public}d", userId, ret);
return;
}
} else if (cmd == "inactive_user_key") {
// smc filecrypt inactive_user_key userId
if (args.size() < 4) { // para.4: parameter nums
LOGE("Parameter nums is less than 4, please retry");
return;
}
uint32_t userId;
if (OHOS::StorageDaemon::StringToUint32(args[3], userId) == false) { // para.3: user id str
LOGE("Parameter input error, please retry");
return;
}
int ret = OHOS::StorageManager::StorageManagerClient::InactiveUserKey(userId);
if (ret) {
LOGE("Inactive user %{public}u key failed %{public}d", userId, ret);
return;
}
}
}
int main(int argc, char **argv)
{
LOGI("smc start");
std::vector<std::string> args(argv, argv + argc);
if (argc < 2) { // param.2: minum parameters
LOGE("usage: smc <subsystem> [cmd]");
return 0;
}
if (args[1] == "filecrypt") {
HandleFileCrypt(args[2], args); // no.2 param is the cmd
}
LOGI("smc end");
return 0;
}

View File

@ -140,5 +140,55 @@ int32_t StorageDaemonCommunication::Partition(std::string diskId, int32_t type)
}
return E_OK;
}
int32_t StorageDaemonCommunication::GenerateUserKeys(uint32_t userId, uint32_t flags)
{
LOGI("enter");
if (Connect() != E_OK) {
LOGE("Connect failed");
return E_IPC_ERROR;
}
return storageDaemon_->GenerateUserKeys(userId, flags);
}
int32_t StorageDaemonCommunication::DeleteUserKeys(uint32_t userId)
{
LOGI("enter");
if (Connect() != E_OK) {
LOGE("Connect failed");
return E_IPC_ERROR;
}
return storageDaemon_->DeleteUserKeys(userId);
}
int32_t StorageDaemonCommunication::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("enter");
if (Connect() != E_OK) {
LOGE("Connect failed");
return E_IPC_ERROR;
}
return storageDaemon_->UpdateUserAuth(userId, auth, compSecret);
}
int32_t StorageDaemonCommunication::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("enter");
if (Connect() != E_OK) {
LOGE("Connect failed");
return E_IPC_ERROR;
}
return storageDaemon_->ActiveUserKey(userId, auth, compSecret);
}
int32_t StorageDaemonCommunication::InactiveUserKey(uint32_t userId)
{
LOGI("enter");
if (Connect() != E_OK) {
LOGE("Connect failed");
return E_IPC_ERROR;
}
return storageDaemon_->InactiveUserKey(userId);
}
} // StorageManager
} // OHOS

View File

@ -95,5 +95,75 @@ int32_t MultiUserManagerService::StopUser(int32_t userId)
err = sdCommunication->StopUser(userId);
return err;
}
int32_t MultiUserManagerService::GenerateUserKeys(uint32_t userId, uint32_t flags)
{
LOGI("UserId: %{public}u, flags: %{public}u", userId, flags);
int32_t err = CheckUserIdRange(userId);
if (err != E_OK) {
LOGE("User ID out of range");
return err;
}
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
err = sdCommunication->GenerateUserKeys(userId, flags);
return err;
}
int32_t MultiUserManagerService::DeleteUserKeys(uint32_t userId)
{
LOGI("UserId: %{public}u", userId);
int32_t err = CheckUserIdRange(userId);
if (err != E_OK) {
LOGE("User ID out of range");
return err;
}
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
err = sdCommunication->DeleteUserKeys(userId);
return err;
}
int32_t MultiUserManagerService::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("UserId: %{public}u", userId);
int32_t err = CheckUserIdRange(userId);
if (err != E_OK) {
LOGE("User ID out of range");
return err;
}
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
err = sdCommunication->UpdateUserAuth(userId, auth, compSecret);
return err;
}
int32_t MultiUserManagerService::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
{
LOGI("UserId: %{public}u", userId);
int32_t err = CheckUserIdRange(userId);
if (err != E_OK) {
LOGE("User ID out of range");
return err;
}
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
err = sdCommunication->ActiveUserKey(userId, auth, compSecret);
return err;
}
int32_t MultiUserManagerService::InactiveUserKey(uint32_t userId)
{
LOGI("UserId: %{public}u", userId);
int32_t err = CheckUserIdRange(userId);
if (err != E_OK) {
LOGE("User ID out of range");
return err;
}
std::shared_ptr<StorageDaemonCommunication> sdCommunication;
sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
err = sdCommunication->InactiveUserKey(userId);
return err;
}
} // StorageManager
} // OHOS