feat: L0软总线接口变动,使用新随机数生成函数和多用户适配

Close #I4TRXR

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: Ib4f62a0687b315048c1293ea7e89bea8b3b7fce3
This commit is contained in:
zhushengle
2022-02-15 18:33:29 +08:00
parent 34a1ddcd40
commit 659bba39bd
5 changed files with 86 additions and 13 deletions
@@ -37,6 +37,7 @@
#include "softbus_session.h"
#include "auth_manager.h"
#include "dm_ability_manager.h"
#include "multiple_user_connector.h"
namespace OHOS {
namespace DistributedHardware {
@@ -109,6 +110,7 @@ int64_t HichainConnector::GenRequestId()
int32_t HichainConnector::CreateGroup(int64_t requestId, const std::string &groupName)
{
int32_t ret;
if (deviceGroupManager_ == nullptr) {
DMLOG(DM_LOG_ERROR, "HichainConnector::CreateGroup group manager is null, requestId %lld.", requestId);
return FAIL;
@@ -131,7 +133,13 @@ int32_t HichainConnector::CreateGroup(int64_t requestId, const std::string &grou
jsonObj[FIELD_USER_TYPE] = 0;
jsonObj[FIELD_GROUP_VISIBILITY] = GROUP_VISIBILITY_PUBLIC;
jsonObj[FIELD_EXPIRE_TIME] = FIELD_EXPIRE_TIME_VALUE;
int32_t ret = deviceGroupManager_->createGroup(requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str());
int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
if (userId < 0) {
DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId);
return FAIL;
}
ret = deviceGroupManager_->createGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str());
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "Faild to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId);
return ret;
@@ -157,10 +165,16 @@ int32_t HichainConnector::IsGroupCreated(std::string groupName, GroupInfo &group
int32_t HichainConnector::GetGroupInfo(std::string queryParams, std::vector<GroupInfo> &groupList)
{
int32_t ret;
char *groupVec = nullptr;
uint32_t num = 0;
int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
if (userId < 0) {
DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId);
return false;
}
int32_t ret = deviceGroupManager_->getGroupInfo(DEVICE_MANAGER_APP.c_str(), queryParams.c_str(), &groupVec, &num);
ret = deviceGroupManager_->getGroupInfo(userId, DEVICE_MANAGER_APP.c_str(), queryParams.c_str(), &groupVec, &num);
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo faild , ret: %d.", ret);
return false;
@@ -263,9 +277,13 @@ int32_t HichainConnector::AddMemeber(std::string deviceId, std::shared_ptr<MsgRe
jsonObj[FIELD_GROUP_NAME] = msgResponseAuth->GetGroupName();
jsonObj[FIELD_CONNECT_PARAMS] = connectInfo.c_str();
std::string tmpStr = jsonObj.dump();
int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
if (userId < 0) {
DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId);
return -1;
}
DMLOG(DM_LOG_INFO, "HichainConnector::AddMemeber completed");
return deviceGroupManager_->addMemberToGroup(msgResponseAuth->GetRequestId(), DEVICE_MANAGER_APP.c_str(),
return deviceGroupManager_->addMemberToGroup(userId, msgResponseAuth->GetRequestId(), DEVICE_MANAGER_APP.c_str(),
tmpStr.c_str());
}
@@ -306,7 +324,13 @@ void HichainConnector::GetRelatedGroups(std::string deviceId, std::vector<GroupI
DMLOG(DM_LOG_INFO, "HichainConnector::GetRelatedGroups Start to get local related groups.");
uint32_t groupNum = 0;
char *returnGroups = nullptr;
int32_t ret = deviceGroupManager_->getRelatedGroups(DEVICE_MANAGER_APP.c_str(), deviceId.c_str(),
int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
if (userId < 0) {
DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId);
return;
}
int32_t ret = deviceGroupManager_->getRelatedGroups(userId, DEVICE_MANAGER_APP.c_str(), deviceId.c_str(),
&returnGroups, &groupNum);
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups faild , ret: %d.", ret);
@@ -389,8 +413,13 @@ int32_t HichainConnector::DelMemberFromGroup(std::string groupId, std::string de
jsonObj[FIELD_GROUP_ID] = groupId;
jsonObj[FIELD_DELETE_ID] = deviceId;
std::string deleteParams = jsonObj.dump();
int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
if (userId < 0) {
DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId);
return userId;
}
int32_t ret = deviceGroupManager_->deleteMemberFromGroup(requestId, DEVICE_MANAGER_APP.c_str(),
int32_t ret = deviceGroupManager_->deleteMemberFromGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(),
deleteParams.c_str());
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::DelMemberFromGroup faild , ret: %d.", ret);
@@ -401,12 +430,18 @@ int32_t HichainConnector::DelMemberFromGroup(std::string groupId, std::string de
void HichainConnector::DeleteGroup(std::string &groupId)
{
int32_t ret;
int64_t requestId = GenRequestId();
nlohmann::json jsonObj;
jsonObj[FIELD_GROUP_ID] = groupId;
std::string disbandParams = jsonObj.dump();
int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
if (userId < 0) {
DMLOG(DM_LOG_ERROR, "get current process account user id failed, userId: %ld", userId);
return;
}
int32_t ret = deviceGroupManager_->deleteGroup(requestId, DEVICE_MANAGER_APP.c_str(), disbandParams.c_str());
ret = deviceGroupManager_->deleteGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), disbandParams.c_str());
if (ret != 0) {
DMLOG(DM_LOG_ERROR, "HichainConnector::DeleteGroup faild , ret: %d.", ret);
}
@@ -0,0 +1,37 @@
/*
* 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 "multiple_user_connector.h"
namespace OHOS {
namespace DistributedHardware {
int32_t MultipleUserConnector::oldUserId_ = -1;
int32_t MultipleUserConnector::GetCurrentAccountUserID(void)
{
return 0;
}
void MultipleUserConnector::SetSwitchOldUserId(int32_t userId)
{
oldUserId_ = userId;
}
int32_t MultipleUserConnector::GetSwitchOldUserId(void)
{
return oldUserId_;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -46,10 +46,7 @@ RequestSession::RequestSession(std::string &hostPkgName, std::string &targetPkgN
#if (defined(__LINUX__) || defined(__LITEOS_A__))
mPinToken_ = IpcServerAdapter::GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN);
#else
std::random_device randDevice;
std::mt19937 genRand(randDevice());
std::uniform_int_distribution<int> disRand(MIN_PIN_TOKEN, MAX_PIN_TOKEN);
mPinToken_ = disRand(genRand);
mPinToken_ = MIN_PIN_TOKEN + random() % (MAX_PIN_TOKEN - MIN_PIN_TOKEN);
#endif
char randStr[TOKEN_LEN] = {0};
bool res = EncryptUtils::MbedtlsGenRandomStr(randStr, sizeof(randStr), false);
@@ -124,7 +124,7 @@ void SoftbusAdapter::OnSoftBusDeviceOnline(NodeBasicInfo *info)
#endif
uint8_t udid[UDID_BUF_LEN] = {0};
int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), info->networkId,
NodeDeivceInfoKey::NODE_KEY_UDID, udid, sizeof(udid));
NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid));
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "GetNodeKeyInfo failed");
return;
@@ -428,7 +428,7 @@ bool SoftbusAdapter::IsDeviceOnLine(std::string &deviceId)
}
uint8_t udid[UDID_BUF_LEN] = {0};
int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), networkId.c_str(),
NodeDeivceInfoKey::NODE_KEY_UDID, udid, sizeof(udid));
NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid));
if (ret != DEVICEMANAGER_OK) {
DMLOG(DM_LOG_ERROR, "DM_IsDeviceOnLine GetNodeKeyInfo failed");
break;
@@ -45,10 +45,14 @@ int32_t EncryptUtils::MbedtlsBase64Decode(uint8_t *dst, size_t dlen, size_t *ole
int32_t EncryptUtils::GenRandInt(int32_t randMin, int32_t randMax)
{
#if (defined(__LINUX__) || defined(__LITEOS_A__))
std::random_device randDevice;
std::mt19937 genRand(randDevice());
std::uniform_int_distribution<int> disRand(randMin, randMax);
return disRand(genRand);
#else
return (randMin + random() % (randMax - randMin));
#endif
}
int64_t EncryptUtils::GenRandLongLong(int64_t randMin, int64_t randMax)