!4628 [新需求]: gengeate irk文件管理

Merge pull request !4628 from 范妮娜/master
This commit is contained in:
openharmony_ci 2023-12-11 06:56:07 +00:00 committed by Gitee
commit dd0601b581
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 28 additions and 21 deletions

View File

@ -789,35 +789,35 @@ static void PackWifiDirectInfo(JsonObj *json, const NodeInfo *info, const char *
static int32_t PackCipherRpaInfo(JsonObj *json, const NodeInfo *info)
{
unsigned char cipherKey[SESSION_KEY_STR_LEN] = {0};
unsigned char cipherIv[BROADCAST_IV_STR_LEN] = {0};
unsigned char peerIrk[LFINDER_IRK_STR_LEN] = {0};
unsigned char pubMac[LFINDER_MAC_ADDR_STR_LEN] = {0};
char cipherKey[SESSION_KEY_STR_LEN] = {0};
char cipherIv[BROADCAST_IV_STR_LEN] = {0};
char peerIrk[LFINDER_IRK_STR_LEN] = {0};
char pubMac[LFINDER_MAC_ADDR_STR_LEN] = {0};
if (ConvertBytesToHexString((char *)cipherKey, SESSION_KEY_STR_LEN,
if (ConvertBytesToHexString(cipherKey, SESSION_KEY_STR_LEN,
info->cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert cipher key to string fail.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString((char *)cipherIv, BROADCAST_IV_STR_LEN,
if (ConvertBytesToHexString(cipherIv, BROADCAST_IV_STR_LEN,
info->cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert cipher iv to string fail.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString((char *)peerIrk, LFINDER_IRK_STR_LEN,
if (ConvertBytesToHexString(peerIrk, LFINDER_IRK_STR_LEN,
info->rpaInfo.peerIrk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert peerIrk to string fail.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString((char *)pubMac, LFINDER_MAC_ADDR_STR_LEN,
if (ConvertBytesToHexString(pubMac, LFINDER_MAC_ADDR_STR_LEN,
info->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert publicAddress to string fail.");
return SOFTBUS_ERR;
}
(void)JSON_AddStringToObject(json, BROADCAST_CIPHER_KEY, (const char *)cipherKey);
(void)JSON_AddStringToObject(json, BROADCAST_CIPHER_IV, (const char *)cipherIv);
(void)JSON_AddStringToObject(json, IRK, (const char *)peerIrk);
(void)JSON_AddStringToObject(json, PUB_MAC, (const char *)pubMac);
(void)JSON_AddStringToObject(json, BROADCAST_CIPHER_KEY, cipherKey);
(void)JSON_AddStringToObject(json, BROADCAST_CIPHER_IV, cipherIv);
(void)JSON_AddStringToObject(json, IRK, peerIrk);
(void)JSON_AddStringToObject(json, PUB_MAC, pubMac);
AUTH_LOGI(AUTH_FSM, "pack cipher and rpa info success!");
BroadcastCipherKey broadcastKey;
@ -945,7 +945,6 @@ static int32_t PackCommon(JsonObj *json, const NodeInfo *info, SoftBusVersion ve
if (PackCipherRpaInfo(json, info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "pack CipherRpaInfo of device key fail.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}

View File

@ -555,6 +555,10 @@ static void TryCancelJoinProcedure(LnnConnectionFsm *connFsm)
static int32_t LnnRecoveryBroadcastKey()
{
if (LnnLoadLocalBroadcastCipherKey() != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "load BroadcastCipherInfo fail");
return SOFTBUS_ERR;
}
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
if (LnnGetLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
@ -566,7 +570,6 @@ static int32_t LnnRecoveryBroadcastKey()
LNN_LOGE(LNN_BUILDER, "set key failed");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV, broadcastKey.cipherInfo.iv,
BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set iv failed");

View File

@ -1521,24 +1521,30 @@ static int32_t LnnGenBroadcastCipherInfo(void)
return SOFTBUS_OK;
}
unsigned char cipherKey[SESSION_KEY_LENGTH] = {0};
unsigned char cipherIv[BROADCAST_IV_LEN] = {0};
if (SoftBusGenerateRandomArray(cipherKey, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
BroadcastCipherKey broadcastKey;
(void)memset_s(&broadcastKey, sizeof(BroadcastCipherKey), 0, sizeof(BroadcastCipherKey));
if (SoftBusGenerateRandomArray(broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "generate broadcast key error.");
return SOFTBUS_ERR;
}
if (SoftBusGenerateRandomArray(cipherIv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
if (SoftBusGenerateRandomArray(broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "generate broadcast iv error.");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY, cipherKey, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_KEY,
broadcastKey.cipherInfo.key, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set key error.");
return SOFTBUS_ERR;
}
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV, cipherIv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
if (LnnSetLocalByteInfo(BYTE_KEY_BROADCAST_CIPHER_IV,
broadcastKey.cipherInfo.iv, BROADCAST_IV_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set iv error.");
return SOFTBUS_ERR;
}
if (LnnUpdateLocalBroadcastCipherKey(&broadcastKey) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "update local broadcast key failed");
return SOFTBUS_ERR;
}
LNN_LOGI(LNN_LEDGER, "generate BroadcastCipherInfo success!");
return SOFTBUS_OK;
}
@ -1686,7 +1692,6 @@ int32_t LnnInitLocalLedger(void)
}
if (LnnGenBroadcastCipherInfo() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "generate cipher fail");
goto EXIT;
}
g_localNetLedger.status = LL_INIT_SUCCESS;