!83 fscrypt: add fscrypt storage manager ipc

Merge pull request !83 from qilongzhang/for_merge_0210
This commit is contained in:
openharmony_ci 2022-02-11 10:12:37 +00:00 committed by Gitee
commit e4f34f2ac0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
17 changed files with 675 additions and 8 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

@ -78,11 +78,19 @@ config("sdc_config") {
"//utils/system/safwk/native/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include/",
"client/include",
"../../interfaces/innerkits/storage_manager/native",
"../storage_manager/include",
"//foundation/appexecfwk/standard/services/bundlemgr/include",
]
}
ohos_executable("sdc") {
sources = [
"../storage_manager/client/storage_manager_client.cpp",
"../storage_manager/innerkits_impl/src/disk.cpp",
"../storage_manager/innerkits_impl/src/volume_core.cpp",
"../storage_manager/innerkits_impl/src/volume_external.cpp",
"../storage_manager/ipc/src/storage_manager_proxy.cpp",
"client/storage_daemon_client.cpp",
"ipc/src/storage_daemon_proxy.cpp",
"sdc.cpp",
@ -98,6 +106,7 @@ ohos_executable("sdc") {
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
]

View File

@ -20,6 +20,7 @@
#include "storage_daemon_client.h"
#include "storage_service_log.h"
#include "utils/file_utils.h"
#include "client/storage_manager_client.h"
static void HandleFileCrypt(const std::string &cmd, const std::vector<std::string> &args)
{
@ -50,7 +51,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
LOGE("Parameter input error, please retry");
return;
}
int32_t ret = OHOS::StorageDaemon::StorageDaemonClient::GenerateUserKeys(userId, flags);
int32_t ret = OHOS::StorageManager::StorageManagerClient::GenerateUserKeys(userId, flags);
if (ret) {
LOGE("Create user %{public}u el failed ret %{public}d", userId, ret);
return;
@ -68,7 +69,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
return;
}
std::string volumId = "";
int32_t ret = OHOS::StorageDaemon::StorageDaemonClient::PrepareUserSpace(userId, volumId, flags);
int32_t ret = OHOS::StorageManager::StorageManagerClient::PrepareAddUser(userId, volumId, flags);
if (ret) {
LOGE("Prepare user %{public}u storage failed ret %{public}d", userId, ret);
return;
@ -84,7 +85,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
LOGE("Parameter input error, please retry");
return;
}
int ret = OHOS::StorageDaemon::StorageDaemonClient::DeleteUserKeys(userId);
int ret = OHOS::StorageManager::StorageManagerClient::DeleteUserKeys(userId);
if (ret) {
LOGE("Delete user %{public}u key failed ret %{public}d", userId, ret);
return;
@ -102,7 +103,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
return;
}
std::string volumId = "";
int ret = OHOS::StorageDaemon::StorageDaemonClient::DestroyUserSpace(userId, volumId, flags);
int ret = OHOS::StorageManager::StorageManagerClient::RemoveUser(userId, volumId, flags);
if (ret) {
LOGE("Destroy user %{public}u space failed ret %{public}d", userId, ret);
return;
@ -120,7 +121,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
}
std::string token = args[4];
std::string secret = args[5];
int ret = OHOS::StorageDaemon::StorageDaemonClient::UpdateUserAuth(userId, token, secret);
int ret = OHOS::StorageManager::StorageManagerClient::UpdateUserAuth(userId, token, secret);
if (ret) {
LOGE("Update user %{public}u auth failed ret %{public}d", userId, ret);
return;
@ -138,7 +139,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
}
std::string token = args[4];
std::string secret = args[5];
int ret = OHOS::StorageDaemon::StorageDaemonClient::ActiveUserKey(userId, token, secret);
int ret = OHOS::StorageManager::StorageManagerClient::ActiveUserKey(userId, token, secret);
if (ret) {
LOGE("Active user %{public}u key failed ret %{public}d", userId, ret);
return;
@ -154,7 +155,7 @@ static void HandleFileCrypt(const std::string &cmd, const std::vector<std::strin
LOGE("Parameter input error, please retry");
return;
}
int ret = OHOS::StorageDaemon::StorageDaemonClient::InactiveUserKey(userId);
int ret = OHOS::StorageManager::StorageManagerClient::InactiveUserKey(userId);
if (ret) {
LOGE("Inactive user %{public}u key failed %{public}d", userId, ret);
return;

View File

@ -29,6 +29,7 @@ config("storage_manager_config") {
ohos_shared_library("storage_manager") {
sources = [
"crypto/filesystem_crypto.cpp",
"disk/src/disk_manager_service.cpp",
"ipc/src/storage_manager.cpp",
"ipc/src/storage_manager_stub.cpp",

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::PrepareAddUser(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::RemoveUser(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,113 @@
/*
* 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 "crypto/filesystem_crypto.h"
#include "os_account_constants.h"
#include "storage_daemon_communication/storage_daemon_communication.h"
#include "storage_service_log.h"
#include "storage_service_errno.h"
namespace OHOS {
namespace StorageManager {
FileSystemCrypto::FileSystemCrypto()
{
LOGI("DEBUG FileSystemCrypto constructer");
}
FileSystemCrypto::~FileSystemCrypto()
{
LOGI("DEBUG ~FileSystemCrypto destructer ~");
}
int32_t FileSystemCrypto::CheckUserIdRange(int32_t userId)
{
if (userId < AccountSA::Constants::START_USER_ID || userId > AccountSA::Constants::MAX_USER_ID) {
LOGE("FileSystemCrypto: userId:%{public}d is out of range", userId);
return E_USERID_RANGE;
}
return E_OK;
}
int32_t FileSystemCrypto::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 FileSystemCrypto::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 FileSystemCrypto::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 FileSystemCrypto::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 FileSystemCrypto::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;
}
}
}

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 PrepareAddUser(uint32_t userId, const std::string &volumId, uint32_t flags);
static int32_t RemoveUser(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

@ -0,0 +1,38 @@
/*
* 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 OHOS_STORAGE_MANAGER_FILE_SYSTEM_CRYPTO_H
#define OHOS_STORAGE_MANAGER_FILE_SYSTEM_CRYPTO_H
#include <unordered_map>
#include <singleton.h>
#include <nocopyable.h>
namespace OHOS {
namespace StorageManager {
class FileSystemCrypto final : public NoCopyable {
DECLARE_DELAYED_SINGLETON(FileSystemCrypto);
public:
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);
};
} // StorageManager
} // OHOS
#endif // OHOS_STORAGE_MANAGER_FILE_SYSTEM_CRYPTO_H

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,7 @@ public:
int32_t RemoveUser(int32_t userId);
int32_t PrepareStartUser(int32_t userId);
int32_t StopUser(int32_t userId);
private:
int32_t CheckUserIdRange(int32_t userId);
};

View File

@ -23,6 +23,7 @@
#include "user/multi_user_manager_service.h"
#include "volume/volume_manager_service.h"
#include "disk/disk_manager_service.h"
#include "crypto/filesystem_crypto.h"
namespace OHOS {
@ -162,5 +163,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<FileSystemCrypto> fsCrypto = DelayedSingleton<FileSystemCrypto>::GetInstance();
int32_t err = fsCrypto->GenerateUserKeys(userId, flags);
return err;
}
int32_t StorageManager::DeleteUserKeys(uint32_t userId)
{
LOGI("UserId: %{public}u", userId);
std::shared_ptr<FileSystemCrypto> fsCrypto = DelayedSingleton<FileSystemCrypto>::GetInstance();
int32_t err = fsCrypto->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<FileSystemCrypto> fsCrypto = DelayedSingleton<FileSystemCrypto>::GetInstance();
int32_t err = fsCrypto->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<FileSystemCrypto> fsCrypto = DelayedSingleton<FileSystemCrypto>::GetInstance();
int32_t err = fsCrypto->ActiveUserKey(userId, auth, compSecret);
return err;
}
int32_t StorageManager::InactiveUserKey(uint32_t userId)
{
LOGI("UserId: %{public}u", userId);
std::shared_ptr<FileSystemCrypto> fsCrypto = DelayedSingleton<FileSystemCrypto>::GetInstance();
int32_t err = fsCrypto->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

@ -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