!8211 fix ptk mismatch

Merge pull request !8211 from zona/1028
This commit is contained in:
openharmony_ci 2024-10-31 04:14:34 +00:00 committed by Gitee
commit ee0b2f2b6f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 41 additions and 2 deletions

View File

@ -445,12 +445,12 @@ int32_t SoftBusDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *inpu
if (memcpy_s(cipherKey->iv, sizeof(cipherKey->iv), input, GCM_IV_LEN) != EOK) {
COMM_LOGE(COMM_ADAPTER, "copy iv failed.");
return SOFTBUS_ENCRYPT_ERR;
return SOFTBUS_MEM_ERR;
}
uint32_t outLen = inLen - OVERHEAD_LEN;
int32_t result = SslAesGcmDecrypt(cipherKey, input, inLen, decryptData, outLen);
if (result <= 0) {
return SOFTBUS_ENCRYPT_ERR;
return SOFTBUS_DECRYPT_ERR;
}
*decryptLen = (uint32_t)result;
return SOFTBUS_OK;

View File

@ -71,6 +71,7 @@ InfoContainer<NegotiateMessageKey>::KeyTypeTable InfoContainer<NegotiateMessageK
{ NegotiateMessageKey::CHANNEL_5G_LIST, Serializable::ValueType::STRING },
{ NegotiateMessageKey::CHANNEL_5G_SCORE, Serializable::ValueType::STRING },
{ NegotiateMessageKey::CHALLENGE_CODE, Serializable::ValueType::UINT },
{ NegotiateMessageKey::REMOTE_NETWORK_ID, Serializable::ValueType::STRING },
/* old p2p */
{ NegotiateMessageKey::GC_CHANNEL_LIST, Serializable::ValueType::STRING },
@ -121,6 +122,7 @@ static std::map<NegotiateMessageType, std::string> g_messageNameMap = {
{ NegotiateMessageType::CMD_V3_RSP, "CMD_V3_RSP" },
{ NegotiateMessageType::CMD_V3_CUSTOM_PORT_REQ, "CMD_V3_CUSTOM_PORT_REQ" },
{ NegotiateMessageType::CMD_V3_CUSTOM_PORT_RSP, "CMD_V3_CUSTOM_PORT_RSP" },
{ NegotiateMessageType::CMD_ERROR_NOTIFICATION, "CMD_ERROR_NOTIFICATION" },
};
static std::map<LegacyCommandType, std::string> g_legacyMessageNameMap = {
@ -480,6 +482,16 @@ std::string NegotiateMessage::GetRemoteDeviceId() const
return Get(NegotiateMessageKey::REMOTE_DEVICE_ID, std::string());
}
void NegotiateMessage::SetRemoteNetworkId(const std::string &value)
{
Set(NegotiateMessageKey::REMOTE_NETWORK_ID, value);
}
std::string NegotiateMessage::GetRemoteNetworkId() const
{
return Get(NegotiateMessageKey::REMOTE_NETWORK_ID, std::string());
}
void NegotiateMessage::SetExtraData(const std::vector<uint8_t> &value)
{
Set(NegotiateMessageKey::EXTRA_DATA_ARRAY, value);

View File

@ -85,6 +85,7 @@ enum class NegotiateMessageType {
CMD_V3_RSP = 101,
CMD_V3_CUSTOM_PORT_REQ = 102,
CMD_V3_CUSTOM_PORT_RSP = 103,
CMD_ERROR_NOTIFICATION = 104,
};
enum class NegotiateMessageKey {
@ -109,6 +110,7 @@ enum class NegotiateMessageKey {
CHANNEL_5G_SCORE = 18,
CHALLENGE_CODE = 19,
NEW_PTK_FRAME = 20,
REMOTE_NETWORK_ID = 21,
/* old p2p */
GC_CHANNEL_LIST = 200,
@ -184,6 +186,9 @@ public:
void SetRemoteDeviceId(const std::string &value);
std::string GetRemoteDeviceId() const;
void SetRemoteNetworkId(const std::string &value);
std::string GetRemoteNetworkId() const;
void SetExtraData(const std::vector<uint8_t> &value);
std::vector<uint8_t> GetExtraData() const;

View File

@ -40,12 +40,18 @@ static std::recursive_mutex g_listenerModuleIdLock;
static bool g_listenerModuleIds[AUTH_ENHANCED_P2P_NUM];
static WifiDirectEnhanceManager g_enhanceManager;
static SyncPtkListener g_syncPtkListener;
static PtkMismatchListener g_ptkMismatchListener;
static uint32_t GetRequestId(void)
{
return g_requestId++;
}
static void AddPtkMismatchListener(PtkMismatchListener listener)
{
g_ptkMismatchListener = listener;
}
static void SetBootLinkTypeByAuthHandle(WifiDirectConnectInfo &info)
{
auto type = info.negoChannel.handle.authHandle.type;
@ -550,6 +556,16 @@ static void NotifyPtkSyncResult(const char *remoteDeviceId, int result)
g_syncPtkListener(remoteDeviceId, result);
}
static void NotifyPtkMismatch(const char *remoteNetworkId, uint32_t len, int32_t reason)
{
CONN_LOGI(CONN_WIFI_DIRECT, "enter");
if (g_ptkMismatchListener == nullptr) {
CONN_LOGW(CONN_WIFI_DIRECT, "listener is null");
return;
}
g_ptkMismatchListener(remoteNetworkId, len, reason);
}
static int32_t Init(void)
{
CONN_LOGI(CONN_INIT, "init enter");
@ -575,6 +591,7 @@ static struct WifiDirectManager g_manager = {
.savePTK = SavePtk,
.syncPTK = SyncPtk,
.addSyncPtkListener = AddSyncPtkListener,
.addPtkMismatchListener = AddPtkMismatchListener,
.isDeviceOnline = IsDeviceOnline,
.getLocalIpByUuid = GetLocalIpByUuid,
@ -596,6 +613,7 @@ static struct WifiDirectManager g_manager = {
.notifyDisconnectedForSink = NotifyDisconnectedForSink,
.registerEnhanceManager = RegisterEnhanceManager,
.notifyPtkSyncResult = NotifyPtkSyncResult,
.notifyPtkMismatch = NotifyPtkMismatch,
};
struct WifiDirectManager *GetWifiDirectManager(void)

View File

@ -31,6 +31,7 @@ struct WifiDirectStatusListener {
};
typedef void (*SyncPtkListener)(const char *remoteDeviceId, int result);
typedef void (*PtkMismatchListener)(const char *remoteNetworkId, uint32_t len, int32_t reason);
struct WifiDirectEnhanceManager {
int32_t (*savePTK)(const char *remoteDeviceId, const char *ptk);
int32_t (*syncPTK)(const char *remoteDeviceId);
@ -56,6 +57,7 @@ struct WifiDirectManager {
int32_t (*savePTK)(const char *remoteDeviceId, const char *ptk);
int32_t (*syncPTK)(const char *remoteDeviceId);
void (*addSyncPtkListener)(SyncPtkListener listener);
void (*addPtkMismatchListener)(PtkMismatchListener listener);
bool (*isDeviceOnline)(const char *remoteMac);
int32_t (*getLocalIpByUuid)(const char *uuid, char *localIp, int32_t localIpSize);
@ -80,6 +82,7 @@ struct WifiDirectManager {
void (*notifyDisconnectedForSink)(const struct WifiDirectSinkLink *link);
void (*registerEnhanceManager)(struct WifiDirectEnhanceManager *manager);
void (*notifyPtkSyncResult)(const char *remoteDeviceId, int result);
void (*notifyPtkMismatch)(const char *remoteNetworkId, uint32_t len, int32_t reason);
};
/* singleton */

View File

@ -960,6 +960,7 @@ enum SoftBusErrNo {
SOFTBUS_CONN_ACTION_STATUS_NO_ACK = SOFTBUS_CONN_ERR_BASE + 717,
SOFTBUS_CONN_ACTION_STATUS_CHBA_SYNC = SOFTBUS_CONN_ERR_BASE + 718,
SOFTBUS_CONN_CONNECT_DHCP_TIMEOUT = SOFTBUS_CONN_ERR_BASE + 719,
SOFTBUS_CONN_GET_PTK_FAIL = SOFTBUS_CONN_ERR_BASE + 720,
/* soft bus connection mapping short range conflict error code */
SOFTBUS_CONN_SHORT_RANGE_BASE = SOFTBUS_CONN_ERR_BASE + 1000,