diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index b17b597b186a7fcf4c7105f14860de42683ebb63..662f5d35f4db1a8e67d522190878884612c34275 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -49,6 +49,7 @@ typedef struct DmDeviceInfo { char deviceId[DM_MAX_DEVICE_ID_LEN]; char deviceName[DM_MAX_DEVICE_NAME_LEN]; uint16_t deviceTypeId; + char networkId[DM_MAX_DEVICE_ID_LEN]; } DmDeviceInfo; typedef struct DmAuthParam { diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 644386adf99511a04928c0371fd5ddd949158b53..a590b43b8fe3b9bf03f7764bd22fff86e9164ad3 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -398,6 +398,7 @@ void DeviceManagerNapi::OnDeviceStateChange(DmNapiDevStateChangeAction action, napi_value device = nullptr; napi_create_object(env_, &device); SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device); + SetValueUtf8String(env_, "networkId", deviceInfo.networkId, device); SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); @@ -415,6 +416,7 @@ void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo & napi_value device = nullptr; napi_create_object(env_, &device); SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device); + SetValueUtf8String(env_, "networkId", deviceInfo.networkId, device); SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index f3278fe8e811b45d325d7e0f0c53824a4297eced..230c3d2ffbef69b2d9bc9e19648de3e9ec3a905f 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -429,6 +429,12 @@ int32_t SoftbusConnector::CovertNodeBasicInfoToDmDevice(const NodeBasicInfo &nod std::min(sizeof(dmDeviceInfo.deviceId), sizeof(nodeBasicInfo.networkId))) != DM_OK) { LOGE("copy data failed"); } + + if (memcpy_s(dmDeviceInfo.networkId, sizeof(dmDeviceInfo.networkId), nodeBasicInfo.networkId, + std::min(sizeof(dmDeviceInfo.networkId), sizeof(nodeBasicInfo.networkId))) != DM_OK) { + LOGE("copy data failed"); + } + if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), nodeBasicInfo.deviceName, std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))) != DM_OK) { LOGE("copy data failed"); @@ -444,6 +450,12 @@ void SoftbusConnector::CovertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))) != DM_OK) { LOGE("copy data failed"); } + + if (memcpy_s(dmDeviceInfo.networkId, sizeof(dmDeviceInfo.networkId), 0, + sizeof(dmDeviceInfo.networkId)) != DM_OK) { + LOGE("copy data failed"); + } + if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), deviceInfo.devName, std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))) != DM_OK) { LOGE("copy data failed"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index f1c17e3ee2f1143d05d16b027856d0a19f8340e0..97f5c361e461e48393454d1ae35bfcdfed7537d9 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -31,12 +31,14 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "include/permission/standard", + "//third_party/mbedtls/include/mbedtls", ] } ohos_shared_library("devicemanagerutils") { sources = [ "src/dm_anonymous.cpp", + "src/dm_hash.cpp", "src/dm_log.cpp", "src/dm_random.cpp", "src/ipc/standard/ipc_cmd_register.cpp", diff --git a/utils/include/dm_hash.h b/utils/include/dm_hash.h new file mode 100644 index 0000000000000000000000000000000000000000..851e5bfe99c0cfa160071eee3085719c1f86be4d --- /dev/null +++ b/utils/include/dm_hash.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#ifndef OHOS_DM_HASH_H +#define OHOS_DM_HASH_H + +#include +#include "base64.h" +#include "ctr_drbg.h" +#include "entropy.h" +#include "gcm.h" +#include "md.h" +#include "platform.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t GetUdidHash(uint8_t *udid, int32_t udiddataLen, uint8_t outudiddData[32]); +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_HASH_H \ No newline at end of file diff --git a/utils/src/dm_hash.cpp b/utils/src/dm_hash.cpp new file mode 100644 index 0000000000000000000000000000000000000000..82eee581e027637d90d47a4a9b308f9f90a698fa --- /dev/null +++ b/utils/src/dm_hash.cpp @@ -0,0 +1,74 @@ +/* + * 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 "dm_log.h" +#include "dm_constants.h" +#include "dm_hash.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t GetUdidHash(uint8_t *udid, int32_t udidDataLen, uint8_t outudidData[32]) +{ + LOGI("GetUdidHash"); + if (udid == nullptr || *udid < 0) { + LOGE("udid is nullptr or dataLen: %d", udidDataLen); + return DM_POINT_NULL; + } + mbedtls_md_context_t ctx; + const mbedtls_md_info_t *info; + + mbedtls_md_init(&ctx); + info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256); + if (info == nullptr) { + LOGE("info is nullptr"); + return DM_POINT_NULL; + } + int32_t ret = DM_OK; + do { + ret = mbedtls_md_setup(&ctx, info, 0); + if (ret != 0) { + LOGE("mbedtls_md_setup is fail"); + ret = DM_FAILED; + break; + } + + ret = mbedtls_md_starts(&ctx); + if (ret != 0) { + LOGE("mbedtls_md_starts is fail"); + ret = DM_FAILED; + break; + } + + ret = mbedtls_md_update(&ctx, udid, udidDataLen); + if (ret != 0) { + LOGE("mbedtls_md_update is fail"); + ret = DM_FAILED; + break; + } + + ret = mbedtls_md_finish(&ctx, outudidData); + if (ret != 0) { + LOGE("mbedtls_md_finish is fail"); + ret = DM_FAILED; + break; + } + ret = DM_OK; + } while (0); + + mbedtls_md_free(&ctx); + return ret; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file