mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-17 01:30:02 +00:00
fix same account bug
Signed-off-by: fushuchang <fushuchang2@huawei.com>
This commit is contained in:
parent
5be38cb78d
commit
8b71339dd9
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -16,6 +16,8 @@
|
||||
#ifndef AUTH_DEVICEPROFILE_H
|
||||
#define AUTH_DEVICEPROFILE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@ -23,7 +25,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
bool IsPotentialTrustedDeviceDp(const char *deviceIdHash);
|
||||
void UpdateDpSameAccount(const char *accountHash, const char *deviceId);
|
||||
void UpdateDpSameAccount(int64_t accountId, const char *deviceId);
|
||||
void DelNotTrustDevice(const char *udid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -15,13 +15,14 @@
|
||||
|
||||
#include "auth_deviceprofile.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "access_control_profile.h"
|
||||
#include "anonymizer.h"
|
||||
#include "auth_interface.h"
|
||||
@ -41,9 +42,9 @@
|
||||
#include "trust_device_profile.h"
|
||||
|
||||
using DpClient = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient;
|
||||
static constexpr uint32_t ACCOUNT_HASH_SHORT_LEN = 2;
|
||||
static std::set<std::string> g_notTrustedDevices;
|
||||
static std::mutex g_mutex;
|
||||
static constexpr const int32_t LONG_TO_STRING_MAX_LEN = 21;
|
||||
|
||||
static bool IsNotTrustDevice(std::string deviceIdHash)
|
||||
{
|
||||
@ -150,20 +151,42 @@ bool IsPotentialTrustedDeviceDp(const char *deviceIdHash)
|
||||
AnonymizeFree(anonyDeviceIdHash);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsSameAccount(const std::string accountHashStr)
|
||||
static void DumpAccountId(int64_t localAccountId, int64_t peerAccountId)
|
||||
{
|
||||
uint8_t localAccountHash[SHA_256_HASH_LEN] = {0};
|
||||
if (LnnGetLocalByteInfo(BYTE_KEY_ACCOUNT_HASH, localAccountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_STATE, "get local accountHash fail");
|
||||
char localAccountString[LONG_TO_STRING_MAX_LEN] = {0};
|
||||
if (sprintf_s(localAccountString, LONG_TO_STRING_MAX_LEN, "%" PRId64, localAccountId) == -1) {
|
||||
LNN_LOGE(LNN_STATE, "long to string fail");
|
||||
return;
|
||||
}
|
||||
|
||||
char peerAccountString[LONG_TO_STRING_MAX_LEN] = {0};
|
||||
if (sprintf_s(peerAccountString, LONG_TO_STRING_MAX_LEN, "%" PRId64, peerAccountId) == -1) {
|
||||
LNN_LOGE(LNN_STATE, "long to string fail");
|
||||
return;
|
||||
}
|
||||
|
||||
char *anonyLocalAccountId = nullptr;
|
||||
char *anonyPeerAccountId = nullptr;
|
||||
Anonymize(localAccountString, &anonyLocalAccountId);
|
||||
Anonymize(peerAccountString, &anonyPeerAccountId);
|
||||
LNN_LOGI(LNN_STATE, "localAccountId=%{public}s, peerAccountId=%{public}s",
|
||||
AnonymizeWrapper(anonyLocalAccountId), AnonymizeWrapper(anonyPeerAccountId));
|
||||
AnonymizeFree(anonyLocalAccountId);
|
||||
AnonymizeFree(anonyPeerAccountId);
|
||||
}
|
||||
|
||||
static bool IsSameAccount(int64_t accountId)
|
||||
{
|
||||
int64_t localAccountId = 0;
|
||||
int32_t ret = LnnGetLocalNum64Info(NUM_KEY_ACCOUNT_LONG, &localAccountId);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_STATE, "get local accountId fail");
|
||||
return false;
|
||||
}
|
||||
if (memcmp(localAccountHash, accountHashStr.c_str(), ACCOUNT_HASH_SHORT_LEN) == 0 && !LnnIsDefaultOhosAccount()) {
|
||||
LNN_LOGI(LNN_STATE, "accountHash=%{public}02x%{public}02x is same", localAccountHash[0], localAccountHash[1]);
|
||||
DumpAccountId(localAccountId, accountId);
|
||||
if (localAccountId == accountId && !LnnIsDefaultOhosAccount()) {
|
||||
return true;
|
||||
}
|
||||
LNN_LOGI(LNN_STATE, "localAccountHash=%{public}02x%{public}02x, peeraccountHash=%{public}02x%{public}02x",
|
||||
localAccountHash[0], localAccountHash[1], accountHashStr[0], accountHashStr[1]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -233,15 +256,14 @@ static void InsertDpSameAccount(const std::string udid)
|
||||
AnonymizeFree(anonyUdid);
|
||||
}
|
||||
|
||||
void UpdateDpSameAccount(const char *accountHash, const char *deviceId)
|
||||
void UpdateDpSameAccount(int64_t accountId, const char *deviceId)
|
||||
{
|
||||
if (accountHash == nullptr || deviceId == nullptr) {
|
||||
LNN_LOGE(LNN_STATE, "accountHash or deviceId is null");
|
||||
if (deviceId == nullptr) {
|
||||
LNN_LOGE(LNN_STATE, "deviceId is null");
|
||||
return;
|
||||
}
|
||||
std::string accountHashStr(accountHash);
|
||||
std::string udid(deviceId);
|
||||
if (IsSameAccount(accountHashStr)) {
|
||||
if (IsSameAccount(accountId)) {
|
||||
InsertDpSameAccount(udid);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -21,9 +21,9 @@ bool IsPotentialTrustedDeviceDp(const char *deviceIdHash)
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateDpSameAccount(const char *accountHash, const char *deviceId)
|
||||
void UpdateDpSameAccount(int64_t accountId, const char *deviceId)
|
||||
{
|
||||
(void)accountHash;
|
||||
(void)accountId;
|
||||
(void)deviceId;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ static void OnReAuthVerifyPassed(uint32_t requestId, AuthHandle authHandle, cons
|
||||
NodeInfo nodeInfo;
|
||||
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
|
||||
(void)LnnGetRemoteNodeInfoById(info->deviceInfo.deviceUdid, CATEGORY_UDID, &nodeInfo);
|
||||
UpdateDpSameAccount(nodeInfo.accountHash, nodeInfo.deviceInfo.deviceUdid);
|
||||
UpdateDpSameAccount(nodeInfo.accountId, nodeInfo.deviceInfo.deviceUdid);
|
||||
}
|
||||
} else {
|
||||
connFsm = StartNewConnectionFsm(&addr, DEFAULT_PKG_NAME, true);
|
||||
|
@ -702,7 +702,7 @@ int32_t LnnUpdateNodeInfo(NodeInfo *newInfo)
|
||||
char deviceName[DEVICE_NAME_BUF_LEN] = { 0 };
|
||||
|
||||
UpdateNewNodeAccountHash(newInfo);
|
||||
UpdateDpSameAccount(newInfo->accountHash, newInfo->deviceInfo.deviceUdid);
|
||||
UpdateDpSameAccount(newInfo->accountId, newInfo->deviceInfo.deviceUdid);
|
||||
udid = LnnGetDeviceUdid(newInfo);
|
||||
map = &g_distributedNetLedger.distributedInfo;
|
||||
if (SoftBusMutexLock(&g_distributedNetLedger.lock) != 0) {
|
||||
@ -1179,7 +1179,7 @@ ReportCategory LnnAddOnlineNode(NodeInfo *info)
|
||||
}
|
||||
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
|
||||
NodeOnlineProc(info);
|
||||
UpdateDpSameAccount(info->accountHash, info->deviceInfo.deviceUdid);
|
||||
UpdateDpSameAccount(info->accountId, info->deviceInfo.deviceUdid);
|
||||
if (infoAbility.isNetworkChanged) {
|
||||
UpdateNetworkInfo(info->deviceInfo.deviceUdid);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user