mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 02:40:40 +00:00
fix:update ble createTime and update keyInfo when fastauth
Signed-off-by: fangdong7 <fangdong7@huawei.com>
This commit is contained in:
parent
e7bd61bb06
commit
b0fa1e724c
@ -35,6 +35,7 @@ auth_server_inc = [
|
|||||||
"$dsoftbus_root_path/core/common/dfx/interface/include",
|
"$dsoftbus_root_path/core/common/dfx/interface/include",
|
||||||
"$dsoftbus_root_path/core/adapter/authentication/include",
|
"$dsoftbus_root_path/core/adapter/authentication/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/heartbeat/include",
|
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/heartbeat/include",
|
||||||
|
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
|
||||||
"$dsoftbus_root_path/core/adapter/bus_center/include",
|
"$dsoftbus_root_path/core/adapter/bus_center/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/utils/include/",
|
"$dsoftbus_root_path/core/bus_center/utils/include/",
|
||||||
]
|
]
|
||||||
|
@ -85,6 +85,7 @@ bool AuthDeviceCheckConnInfo(const char* uuid, AuthLinkType type, bool checkConn
|
|||||||
void AuthDeviceGetLatestIdByUuid(const char *uuid, AuthLinkType type, AuthHandle *authHandle);
|
void AuthDeviceGetLatestIdByUuid(const char *uuid, AuthLinkType type, AuthHandle *authHandle);
|
||||||
int64_t AuthDeviceGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer);
|
int64_t AuthDeviceGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer);
|
||||||
int64_t AuthDeviceGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer);
|
int64_t AuthDeviceGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer);
|
||||||
|
int32_t AuthDeviceGetAuthHandleByIndex(const char *udid, bool isServer, int32_t index, AuthHandle *authHandle);
|
||||||
AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info);
|
AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info);
|
||||||
|
|
||||||
int32_t AuthDeviceEncrypt(AuthHandle *authHandle, const uint8_t *inData, uint32_t inLen, uint8_t *outData,
|
int32_t AuthDeviceEncrypt(AuthHandle *authHandle, const uint8_t *inData, uint32_t inLen, uint8_t *outData,
|
||||||
|
@ -50,6 +50,7 @@ int32_t DupSessionKeyList(const SessionKeyList *srcList, SessionKeyList *dstList
|
|||||||
|
|
||||||
uint64_t GetLatestAvailableSessionKeyTime(const SessionKeyList *list, AuthLinkType type);
|
uint64_t GetLatestAvailableSessionKeyTime(const SessionKeyList *list, AuthLinkType type);
|
||||||
bool HasSessionKey(const SessionKeyList *list);
|
bool HasSessionKey(const SessionKeyList *list);
|
||||||
|
AuthLinkType GetSessionKeyTypeByIndex(const SessionKeyList *list, int32_t index);
|
||||||
int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key, AuthLinkType type);
|
int32_t AddSessionKey(SessionKeyList *list, int32_t index, const SessionKey *key, AuthLinkType type);
|
||||||
int32_t SetSessionKeyAvailable(SessionKeyList *list, int32_t index);
|
int32_t SetSessionKeyAvailable(SessionKeyList *list, int32_t index);
|
||||||
int32_t GetLatestSessionKey(const SessionKeyList *list, AuthLinkType type, int32_t *index, SessionKey *key);
|
int32_t GetLatestSessionKey(const SessionKeyList *list, AuthLinkType type, int32_t *index, SessionKey *key);
|
||||||
|
@ -167,6 +167,8 @@ int32_t AuthGetLatestAuthSeqListByType(const char *udid, int64_t *seqList, uint6
|
|||||||
DiscoveryType type);
|
DiscoveryType type);
|
||||||
/* for ProxyChannel & P2P TcpDirectchannel */
|
/* for ProxyChannel & P2P TcpDirectchannel */
|
||||||
void AuthGetLatestIdByUuid(const char *uuid, AuthLinkType type, bool isMeta, AuthHandle *authHandle);
|
void AuthGetLatestIdByUuid(const char *uuid, AuthLinkType type, bool isMeta, AuthHandle *authHandle);
|
||||||
|
int32_t AuthGetAuthHandleByIndex(const AuthConnInfo *connInfo, bool isServer, int32_t index,
|
||||||
|
AuthHandle *authHandle);
|
||||||
int64_t AuthGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer, bool isMeta);
|
int64_t AuthGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer, bool isMeta);
|
||||||
int64_t AuthGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer, bool isMeta);
|
int64_t AuthGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer, bool isMeta);
|
||||||
int32_t AuthSetTcpKeepAlive(const AuthConnInfo *connInfo, ModeCycle cycle);
|
int32_t AuthSetTcpKeepAlive(const AuthConnInfo *connInfo, ModeCycle cycle);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "bus_center_manager.h"
|
#include "bus_center_manager.h"
|
||||||
#include "customized_security_protocol.h"
|
#include "customized_security_protocol.h"
|
||||||
#include "lnn_decision_db.h"
|
#include "lnn_decision_db.h"
|
||||||
|
#include "lnn_distributed_net_ledger.h"
|
||||||
#include "lnn_ohos_account.h"
|
#include "lnn_ohos_account.h"
|
||||||
#include "softbus_adapter_mem.h"
|
#include "softbus_adapter_mem.h"
|
||||||
#include "softbus_def.h"
|
#include "softbus_def.h"
|
||||||
@ -220,6 +221,55 @@ int64_t AuthGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer, bool
|
|||||||
return AuthDeviceGetIdByUuid(uuid, type, isServer);
|
return AuthDeviceGetIdByUuid(uuid, type, isServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t AuthGetAuthHandleByIndex(const AuthConnInfo *connInfo, bool isServer, int32_t index,
|
||||||
|
AuthHandle *authHandle)
|
||||||
|
{
|
||||||
|
if (connInfo == NULL || authHandle == NULL) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "param is null");
|
||||||
|
return SOFTBUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
int32_t ret = SOFTBUS_OK;
|
||||||
|
char networkId[NETWORK_ID_BUF_LEN] = { 0 };
|
||||||
|
NodeInfo info;
|
||||||
|
(void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
|
||||||
|
switch (connInfo->type) {
|
||||||
|
case AUTH_LINK_TYPE_WIFI:
|
||||||
|
ret = LnnGetRemoteNodeInfoByKey(connInfo->info.ipInfo.ip, &info);
|
||||||
|
if (ret != SOFTBUS_OK) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "get remote nodeInfo by ip failed, ret=%{public}d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AUTH_LINK_TYPE_BLE:
|
||||||
|
if (LnnGetNetworkIdByUdidHash(connInfo->info.bleInfo.deviceIdHash, UDID_HASH_LEN, networkId,
|
||||||
|
sizeof(networkId)) != SOFTBUS_OK) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "get networkId fail");
|
||||||
|
return SOFTBUS_NOT_FIND;
|
||||||
|
}
|
||||||
|
ret = LnnGetRemoteNodeInfoByKey(networkId, &info);
|
||||||
|
if (ret != SOFTBUS_OK) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "get remote nodeInfo by networkId failed, ret=%{public}d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AUTH_LINK_TYPE_BR:
|
||||||
|
ret = LnnGetRemoteNodeInfoByKey(connInfo->info.brInfo.brMac, &info);
|
||||||
|
if (ret != SOFTBUS_OK) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "get remote nodeInfo by brMac failed, ret=%{public}d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AUTH_LOGE(AUTH_CONN, "unknown connType. type=%{public}d", connInfo->type);
|
||||||
|
return SOFTBUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
if (!IsSupportFeatureByCapaBit(info.feature, BIT_SUPPORT_NORMALIZED_LINK)) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "not support normalize");
|
||||||
|
return SOFTBUS_AUTH_NOT_SUPPORT_NORMALIZE;
|
||||||
|
}
|
||||||
|
return AuthDeviceGetAuthHandleByIndex(info.deviceInfo.deviceUdid, isServer, index, authHandle);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t FillAuthSessionInfo(AuthSessionInfo *info, const NodeInfo *nodeInfo, uint32_t requestId,
|
static int32_t FillAuthSessionInfo(AuthSessionInfo *info, const NodeInfo *nodeInfo, uint32_t requestId,
|
||||||
AuthDeviceKeyInfo *keyInfo, const AuthConnInfo *connInfo)
|
AuthDeviceKeyInfo *keyInfo, const AuthConnInfo *connInfo)
|
||||||
{
|
{
|
||||||
|
@ -2148,6 +2148,35 @@ int64_t AuthDeviceGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer
|
|||||||
return authId;
|
return authId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t AuthDeviceGetAuthHandleByIndex(const char *udid, bool isServer, int32_t index, AuthHandle *authHandle)
|
||||||
|
{
|
||||||
|
if (udid == NULL || authHandle == NULL) {
|
||||||
|
AUTH_LOGE(AUTH_FSM, "param error");
|
||||||
|
return SOFTBUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
if (!RequireAuthLock()) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "RequireAuthLock fail");
|
||||||
|
return SOFTBUS_LOCK_ERR;
|
||||||
|
}
|
||||||
|
AuthManager *auth = FindNormalizedKeyAuthManagerByUdid(udid, isServer);
|
||||||
|
if (auth == NULL) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "not found auth manager, side=%{public}s", GetAuthSideStr(isServer));
|
||||||
|
ReleaseAuthLock();
|
||||||
|
return SOFTBUS_AUTH_NOT_FOUND;
|
||||||
|
}
|
||||||
|
AuthLinkType type = GetSessionKeyTypeByIndex(&auth->sessionKeyList, index);
|
||||||
|
ReleaseAuthLock();
|
||||||
|
if (type == AUTH_LINK_TYPE_MAX || type < AUTH_LINK_TYPE_WIFI) {
|
||||||
|
AUTH_LOGE(AUTH_CONN, "auth type error");
|
||||||
|
return SOFTBUS_AUTH_NOT_FOUND;
|
||||||
|
}
|
||||||
|
authHandle->authId = auth->authId;
|
||||||
|
authHandle->type = type;
|
||||||
|
AUTH_LOGI(AUTH_CONN, "found auth manager, side=%{public}s, type=%{public}d, authId=%{public}" PRId64,
|
||||||
|
GetAuthSideStr(isServer), type, auth->authId);
|
||||||
|
return SOFTBUS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t AuthGetEncryptSize(uint32_t inLen)
|
uint32_t AuthGetEncryptSize(uint32_t inLen)
|
||||||
{
|
{
|
||||||
return inLen + ENCRYPT_OVER_HEAD_LEN;
|
return inLen + ENCRYPT_OVER_HEAD_LEN;
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "auth_session_message.h"
|
#include "auth_session_message.h"
|
||||||
#include "bus_center_manager.h"
|
#include "bus_center_manager.h"
|
||||||
#include "lnn_event.h"
|
#include "lnn_event.h"
|
||||||
|
#include "lnn_distributed_net_ledger.h"
|
||||||
#include "softbus_adapter_hitrace.h"
|
#include "softbus_adapter_hitrace.h"
|
||||||
#include "softbus_adapter_mem.h"
|
#include "softbus_adapter_mem.h"
|
||||||
#include "softbus_def.h"
|
#include "softbus_def.h"
|
||||||
@ -36,7 +37,6 @@
|
|||||||
#define AUTH_TIMEOUT_MS (10 * 1000)
|
#define AUTH_TIMEOUT_MS (10 * 1000)
|
||||||
#define TO_AUTH_FSM(ptr) CONTAINER_OF(ptr, AuthFsm, fsm)
|
#define TO_AUTH_FSM(ptr) CONTAINER_OF(ptr, AuthFsm, fsm)
|
||||||
#define SHORT_UDID_HASH_LEN 8
|
#define SHORT_UDID_HASH_LEN 8
|
||||||
#define SHORT_UDID_HASH_HEX_LEN 17
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STATE_SYNC_DEVICE_ID = 0,
|
STATE_SYNC_DEVICE_ID = 0,
|
||||||
@ -190,8 +190,8 @@ static int32_t ProcAuthFsm(uint32_t requestId, bool isServer, AuthFsm *authFsm)
|
|||||||
AUTH_LOGE(AUTH_FSM, "get auth request fail");
|
AUTH_LOGE(AUTH_FSM, "get auth request fail");
|
||||||
return SOFTBUS_ERR;
|
return SOFTBUS_ERR;
|
||||||
}
|
}
|
||||||
char udidHash[SHORT_UDID_HASH_HEX_LEN] = {0};
|
char udidHash[SHORT_UDID_HASH_HEX_LEN + 1] = {0};
|
||||||
int32_t ret = ConvertBytesToHexString(udidHash, SHORT_UDID_HASH_HEX_LEN,
|
int32_t ret = ConvertBytesToHexString(udidHash, SHORT_UDID_HASH_HEX_LEN + 1,
|
||||||
(const unsigned char *)request.connInfo.info.bleInfo.deviceIdHash, SHORT_UDID_HASH_LEN);
|
(const unsigned char *)request.connInfo.info.bleInfo.deviceIdHash, SHORT_UDID_HASH_LEN);
|
||||||
if (ret == SOFTBUS_OK && LnnRetrieveDeviceInfo((const char *)udidHash, &nodeInfo) == SOFTBUS_OK &&
|
if (ret == SOFTBUS_OK && LnnRetrieveDeviceInfo((const char *)udidHash, &nodeInfo) == SOFTBUS_OK &&
|
||||||
IsNeedExchangeNetworkId(nodeInfo.authCapacity, BIT_SUPPORT_EXCHANGE_NETWORKID)) {
|
IsNeedExchangeNetworkId(nodeInfo.authCapacity, BIT_SUPPORT_EXCHANGE_NETWORKID)) {
|
||||||
@ -498,8 +498,8 @@ static int32_t RecoveryNormalizedDeviceKey(AuthFsm *authFsm)
|
|||||||
AUTH_LOGE(AUTH_FSM, "generate udidHash fail");
|
AUTH_LOGE(AUTH_FSM, "generate udidHash fail");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
char udidShortHash[SHORT_UDID_HASH_HEX_LEN] = {0};
|
char udidShortHash[SHORT_UDID_HASH_HEX_LEN + 1] = {0};
|
||||||
if (ConvertBytesToUpperCaseHexString(udidShortHash, SHORT_UDID_HASH_HEX_LEN,
|
if (ConvertBytesToUpperCaseHexString(udidShortHash, SHORT_UDID_HASH_HEX_LEN + 1,
|
||||||
hash, SHORT_UDID_HASH_LEN) != SOFTBUS_OK) {
|
hash, SHORT_UDID_HASH_LEN) != SOFTBUS_OK) {
|
||||||
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
|
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
|
||||||
return SOFTBUS_ERR;
|
return SOFTBUS_ERR;
|
||||||
@ -524,8 +524,8 @@ static int32_t RecoveryFastAuthKey(AuthFsm *authFsm)
|
|||||||
AUTH_LOGE(AUTH_FSM, "generate udidHash fail");
|
AUTH_LOGE(AUTH_FSM, "generate udidHash fail");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
char udidShortHash[SHORT_UDID_HASH_HEX_LEN] = {0};
|
char udidShortHash[SHORT_UDID_HASH_HEX_LEN + 1] = {0};
|
||||||
if (ConvertBytesToUpperCaseHexString(udidShortHash, SHORT_UDID_HASH_HEX_LEN,
|
if (ConvertBytesToUpperCaseHexString(udidShortHash, SHORT_UDID_HASH_HEX_LEN + 1,
|
||||||
hash, SHORT_UDID_HASH_LEN) != SOFTBUS_OK) {
|
hash, SHORT_UDID_HASH_LEN) != SOFTBUS_OK) {
|
||||||
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
|
AUTH_LOGE(AUTH_FSM, "convert bytes to string fail");
|
||||||
return SOFTBUS_ERR;
|
return SOFTBUS_ERR;
|
||||||
|
@ -153,6 +153,29 @@ bool HasSessionKey(const SessionKeyList *list)
|
|||||||
return !IsListEmpty(list);
|
return !IsListEmpty(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuthLinkType GetSessionKeyTypeByIndex(const SessionKeyList *list, int32_t index)
|
||||||
|
{
|
||||||
|
CHECK_NULL_PTR_RETURN_VALUE(list, AUTH_LINK_TYPE_MAX);
|
||||||
|
SessionKeyItem *item = NULL;
|
||||||
|
uint32_t type = 0;
|
||||||
|
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
|
||||||
|
if (item->index == index) {
|
||||||
|
type = item->type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type == 0) {
|
||||||
|
return AUTH_LINK_TYPE_MAX;
|
||||||
|
}
|
||||||
|
for (uint32_t i = AUTH_LINK_TYPE_WIFI; i < AUTH_LINK_TYPE_MAX; i++) {
|
||||||
|
if (SessionKeyHasAuthLinkType(type, (AuthLinkType)i)) {
|
||||||
|
AUTH_LOGI(AUTH_FSM, "auth link type=%{public}d", i);
|
||||||
|
return (AuthLinkType)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AUTH_LINK_TYPE_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t GetLatestAvailableSessionKeyTime(const SessionKeyList *list, AuthLinkType type)
|
uint64_t GetLatestAvailableSessionKeyTime(const SessionKeyList *list, AuthLinkType type)
|
||||||
{
|
{
|
||||||
CHECK_NULL_PTR_RETURN_VALUE(list, 0);
|
CHECK_NULL_PTR_RETURN_VALUE(list, 0);
|
||||||
|
@ -74,14 +74,15 @@ static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
|
|||||||
char softBusVersion[VERSION_MAX_LEN] = {0};
|
char softBusVersion[VERSION_MAX_LEN] = {0};
|
||||||
if (LnnGetLocalStrInfo(STRING_KEY_HICE_VERSION, softBusVersion, sizeof(softBusVersion)) == SOFTBUS_OK) {
|
if (LnnGetLocalStrInfo(STRING_KEY_HICE_VERSION, softBusVersion, sizeof(softBusVersion)) == SOFTBUS_OK) {
|
||||||
if (strcmp(softBusVersion, info->softBusVersion) != 0) {
|
if (strcmp(softBusVersion, info->softBusVersion) != 0) {
|
||||||
LNN_LOGW(LNN_LEDGER, "softbus version change, version:%s", softBusVersion);
|
LNN_LOGW(LNN_LEDGER, "softbus version change, version:%{public}s", softBusVersion);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint64_t softbusFeature = 0;
|
uint64_t softbusFeature = 0;
|
||||||
if (LnnGetLocalNumU64Info(NUM_KEY_FEATURE_CAPA, &softbusFeature) == SOFTBUS_OK) {
|
if (LnnGetLocalNumU64Info(NUM_KEY_FEATURE_CAPA, &softbusFeature) == SOFTBUS_OK) {
|
||||||
if (softbusFeature != info->feature) {
|
if (softbusFeature != info->feature) {
|
||||||
LNN_LOGW(LNN_LEDGER, "feature change, old:%" PRIu64 ", new:%" PRIu64, info->feature, softbusFeature);
|
LNN_LOGW(LNN_LEDGER, "feature change, old:%{public}" PRIu64 ", new:%{public}" PRIu64,
|
||||||
|
info->feature, softbusFeature);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,14 +96,15 @@ static bool IsBleDirectlyOnlineFactorChange(NodeInfo *info)
|
|||||||
int32_t osType = 0;
|
int32_t osType = 0;
|
||||||
if (LnnGetLocalNumInfo(NUM_KEY_OS_TYPE, &osType) == SOFTBUS_OK) {
|
if (LnnGetLocalNumInfo(NUM_KEY_OS_TYPE, &osType) == SOFTBUS_OK) {
|
||||||
if (osType != info->deviceInfo.osType) {
|
if (osType != info->deviceInfo.osType) {
|
||||||
LNN_LOGW(LNN_LEDGER, "osType change, old:%d, new:%d", info->deviceInfo.osType, osType);
|
LNN_LOGW(LNN_LEDGER, "osType change, old:%{public}d, new:%{public}d", info->deviceInfo.osType, osType);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t authCapacity = 0;
|
uint32_t authCapacity = 0;
|
||||||
if (LnnGetLocalNumInfo(NUM_KEY_AUTH_CAP, (int32_t *)&authCapacity) == SOFTBUS_OK) {
|
if (LnnGetLocalNumInfo(NUM_KEY_AUTH_CAP, (int32_t *)&authCapacity) == SOFTBUS_OK) {
|
||||||
if (authCapacity != info->authCapacity) {
|
if (authCapacity != info->authCapacity) {
|
||||||
LNN_LOGW(LNN_LEDGER, "authCapacity change, old:%d, new:%d", info->authCapacity, authCapacity);
|
LNN_LOGW(LNN_LEDGER, "authCapacity change, old:%{public}d, new:%{public}d",
|
||||||
|
info->authCapacity, authCapacity);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ static int32_t ConvertBleConnInfo2BrConnInfo(AuthConnInfo *connInfo)
|
|||||||
return SOFTBUS_OK;
|
return SOFTBUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t GetAuthIdByHandshakeMsg(uint32_t connId, uint8_t cipher, AuthHandle *authHandle)
|
static int32_t GetAuthIdByHandshakeMsg(uint32_t connId, uint8_t cipher, AuthHandle *authHandle, int32_t index)
|
||||||
{
|
{
|
||||||
AuthConnInfo connInfo;
|
AuthConnInfo connInfo;
|
||||||
if (TransProxyGetAuthConnInfo(connId, &connInfo) != SOFTBUS_OK) {
|
if (TransProxyGetAuthConnInfo(connId, &connInfo) != SOFTBUS_OK) {
|
||||||
@ -204,9 +204,34 @@ static int32_t GetAuthIdByHandshakeMsg(uint32_t connId, uint8_t cipher, AuthHand
|
|||||||
bool isAuthServer = !((cipher & AUTH_SERVER_SIDE) != 0);
|
bool isAuthServer = !((cipher & AUTH_SERVER_SIDE) != 0);
|
||||||
authHandle->type = connInfo.type;
|
authHandle->type = connInfo.type;
|
||||||
authHandle->authId = AuthGetIdByConnInfo(&connInfo, isAuthServer, false);
|
authHandle->authId = AuthGetIdByConnInfo(&connInfo, isAuthServer, false);
|
||||||
|
if (authHandle->authId == AUTH_INVALID_ID) {
|
||||||
|
if (AuthGetAuthHandleByIndex(&connInfo, isAuthServer, index, authHandle) != SOFTBUS_OK &&
|
||||||
|
AuthGetAuthHandleByIndex(&connInfo, !isAuthServer, index, authHandle) != SOFTBUS_OK) {
|
||||||
|
TRANS_LOGE(TRANS_CTRL, "get auth handle fail");
|
||||||
|
return SOFTBUS_NOT_FIND;
|
||||||
|
}
|
||||||
|
}
|
||||||
return SOFTBUS_OK;
|
return SOFTBUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t GetAuthIdReDecrypt(AuthHandle *authHandle, ProxyMessage *msg, uint8_t *decData, uint32_t *decDataLen)
|
||||||
|
{
|
||||||
|
AuthConnInfo connInfo;
|
||||||
|
(void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
|
||||||
|
int32_t ret = TransProxyGetAuthConnInfo(msg->connId, &connInfo);
|
||||||
|
if (ret != SOFTBUS_OK) {
|
||||||
|
TRANS_LOGE(TRANS_CTRL, "get connInfo fail connId=%{public}d", msg->connId);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int32_t index = (int32_t)SoftBusLtoHl(*(uint32_t *)msg->data);
|
||||||
|
if (AuthGetAuthHandleByIndex(&connInfo, false, index, authHandle) != SOFTBUS_OK &&
|
||||||
|
AuthGetAuthHandleByIndex(&connInfo, true, index, authHandle) != SOFTBUS_OK) {
|
||||||
|
TRANS_LOGE(TRANS_CTRL, "get auth handle fail");
|
||||||
|
return SOFTBUS_NOT_FIND;
|
||||||
|
}
|
||||||
|
return AuthDecrypt(authHandle, (uint8_t *)msg->data, (uint32_t)msg->dateLen, decData, decDataLen);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t GetBrMacFromConnInfo(uint32_t connId, char *peerBrMac, uint32_t len)
|
int32_t GetBrMacFromConnInfo(uint32_t connId, char *peerBrMac, uint32_t len)
|
||||||
{
|
{
|
||||||
AuthConnInfo connInfo;
|
AuthConnInfo connInfo;
|
||||||
@ -236,27 +261,28 @@ int32_t TransProxyParseMessage(char *data, int32_t len, ProxyMessage *msg)
|
|||||||
}
|
}
|
||||||
if ((msg->msgHead.cipher & ENCRYPTED) != 0) {
|
if ((msg->msgHead.cipher & ENCRYPTED) != 0) {
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
AuthHandle authHandle = { .authId = AUTH_INVALID_ID };
|
AuthHandle auth = { .authId = AUTH_INVALID_ID };
|
||||||
if (msg->msgHead.type == PROXYCHANNEL_MSG_TYPE_HANDSHAKE) {
|
if (msg->msgHead.type == PROXYCHANNEL_MSG_TYPE_HANDSHAKE) {
|
||||||
TRANS_LOGD(TRANS_CTRL, "prxoy recv handshake cipher=0x%{public}02x", msg->msgHead.cipher);
|
TRANS_LOGD(TRANS_CTRL, "prxoy recv handshake cipher=0x%{public}02x", msg->msgHead.cipher);
|
||||||
ret = GetAuthIdByHandshakeMsg(msg->connId, msg->msgHead.cipher, &authHandle);
|
ret = GetAuthIdByHandshakeMsg(msg->connId, msg->msgHead.cipher, &auth,
|
||||||
|
(int32_t)SoftBusLtoHl(*(uint32_t *)msg->data));
|
||||||
} else {
|
} else {
|
||||||
ret = TransProxyGetAuthId(msg->msgHead.myId, &authHandle);
|
ret = TransProxyGetAuthId(msg->msgHead.myId, &auth);
|
||||||
}
|
}
|
||||||
if (ret != SOFTBUS_OK || authHandle.authId == AUTH_INVALID_ID) {
|
if (ret != SOFTBUS_OK || auth.authId == AUTH_INVALID_ID) {
|
||||||
TRANS_LOGE(TRANS_CTRL, "get authId fail, connId=%{public}d, myChannelId=%{public}d, type=%{public}d",
|
TRANS_LOGE(TRANS_CTRL, "get authId fail, connId=%{public}d, myChannelId=%{public}d, type=%{public}d",
|
||||||
msg->connId, msg->msgHead.myId, msg->msgHead.type);
|
msg->connId, msg->msgHead.myId, msg->msgHead.type);
|
||||||
return SOFTBUS_AUTH_NOT_FOUND;
|
return SOFTBUS_AUTH_NOT_FOUND;
|
||||||
}
|
}
|
||||||
msg->authHandle = authHandle;
|
msg->authHandle = auth;
|
||||||
uint32_t decDataLen = AuthGetDecryptSize((uint32_t)msg->dateLen);
|
uint32_t decDataLen = AuthGetDecryptSize((uint32_t)msg->dateLen);
|
||||||
uint8_t *decData = (uint8_t *)SoftBusCalloc(decDataLen);
|
uint8_t *decData = (uint8_t *)SoftBusCalloc(decDataLen);
|
||||||
if (decData == NULL) {
|
if (decData == NULL) {
|
||||||
return SOFTBUS_MALLOC_ERR;
|
return SOFTBUS_MALLOC_ERR;
|
||||||
}
|
}
|
||||||
msg->keyIndex = (int32_t)SoftBusLtoHl(*(uint32_t *)msg->data);
|
msg->keyIndex = (int32_t)SoftBusLtoHl(*(uint32_t *)msg->data);
|
||||||
if (AuthDecrypt(&authHandle, (uint8_t *)msg->data, (uint32_t)msg->dateLen,
|
if (AuthDecrypt(&auth, (uint8_t *)msg->data, (uint32_t)msg->dateLen, decData, &decDataLen) != SOFTBUS_OK &&
|
||||||
decData, &decDataLen) != SOFTBUS_OK) {
|
GetAuthIdReDecrypt(&auth, msg, decData, &decDataLen) != SOFTBUS_OK) {
|
||||||
SoftBusFree(decData);
|
SoftBusFree(decData);
|
||||||
TRANS_LOGE(TRANS_CTRL, "parse msg decrypt fail");
|
TRANS_LOGE(TRANS_CTRL, "parse msg decrypt fail");
|
||||||
return SOFTBUS_DECRYPT_ERR;
|
return SOFTBUS_DECRYPT_ERR;
|
||||||
|
@ -292,6 +292,7 @@ enum SoftBusErrNo {
|
|||||||
SOFTBUS_AUTH_CONN_START_ERR,
|
SOFTBUS_AUTH_CONN_START_ERR,
|
||||||
SOFTBUS_AUTH_START_ERR,
|
SOFTBUS_AUTH_START_ERR,
|
||||||
SOFTBUS_AUTH_EXCHANGE_DEVICE_INFO_START_ERR,
|
SOFTBUS_AUTH_EXCHANGE_DEVICE_INFO_START_ERR,
|
||||||
|
SOFTBUS_AUTH_NOT_SUPPORT_NORMALIZE,
|
||||||
|
|
||||||
/* errno begin: -((203 << 21) | (4 << 16) | 0xFFFF) */
|
/* errno begin: -((203 << 21) | (4 << 16) | 0xFFFF) */
|
||||||
SOFTBUS_NETWORK_ERR_BASE = SOFTBUS_ERRNO(LNN_SUB_MODULE_CODE),
|
SOFTBUS_NETWORK_ERR_BASE = SOFTBUS_ERRNO(LNN_SUB_MODULE_CODE),
|
||||||
|
@ -30,6 +30,7 @@ ohos_unittest("AuthTest") {
|
|||||||
"$dsoftbus_root_path/core/bus_center/utils/include",
|
"$dsoftbus_root_path/core/bus_center/utils/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
||||||
|
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
|
||||||
"$dsoftbus_root_path/core/common/include",
|
"$dsoftbus_root_path/core/common/include",
|
||||||
"$dsoftbus_root_path/core/common/message_handler/include",
|
"$dsoftbus_root_path/core/common/message_handler/include",
|
||||||
"$dsoftbus_root_path/core/connection/interface",
|
"$dsoftbus_root_path/core/connection/interface",
|
||||||
|
@ -1617,6 +1617,7 @@ ohos_unittest("LNNDiscoveryInterfaceTest") {
|
|||||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/include",
|
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/include",
|
||||||
|
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/utils/include",
|
"$dsoftbus_root_path/core/bus_center/utils/include",
|
||||||
"$dsoftbus_root_path/core/bus_center/interface",
|
"$dsoftbus_root_path/core/bus_center/interface",
|
||||||
"$dsoftbus_root_path/core/bus_center/service/include",
|
"$dsoftbus_root_path/core/bus_center/service/include",
|
||||||
|
@ -976,7 +976,8 @@ HWTEST_F(SoftbusProxyChannelMessageTest, TransProxyGetAuthIdTest001, TestSize.Le
|
|||||||
msg.connId = 1;
|
msg.connId = 1;
|
||||||
msg.msgHead.cipher = 1;
|
msg.msgHead.cipher = 1;
|
||||||
AuthHandle authHandle = { 0 };
|
AuthHandle authHandle = { 0 };
|
||||||
int32_t ret = GetAuthIdByHandshakeMsg(msg.connId, msg.msgHead.cipher, &authHandle);
|
int32_t index = 1;
|
||||||
|
int32_t ret = GetAuthIdByHandshakeMsg(msg.connId, msg.msgHead.cipher, &authHandle, index);
|
||||||
EXPECT_NE(SOFTBUS_OK, ret);
|
EXPECT_NE(SOFTBUS_OK, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user