diff --git a/services/implementation/include/authentication_v2/dm_auth_state.h b/services/implementation/include/authentication_v2/dm_auth_state.h index 50df8617b39b450a72233a1ab83772f121739cca..3015dcd65bcd81699a64e4384cc9d25290c08711 100644 --- a/services/implementation/include/authentication_v2/dm_auth_state.h +++ b/services/implementation/include/authentication_v2/dm_auth_state.h @@ -231,6 +231,7 @@ private: void GetSrcProxyCredTypeForP2P(std::shared_ptr context, std::vector &deleteCredInfo); void GetCustomDescBySinkLanguage(std::shared_ptr context); void ResetBindLevel(std::shared_ptr context); + void NegotiateUltrasonic(std::shared_ptr context); }; class AuthSinkStatePinAuthComm { diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 30e80b08f0081220b72c1081d9f8f46f6ee94667..70ffbf6638367ef46282878ed574890f5c286f9c 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -43,6 +43,10 @@ #include "ffrt.h" #include "json_object.h" +#ifdef SUPPORT_MSDP +#include "spatial_awareness_mgr_client.h" +#endif + namespace OHOS { namespace DistributedHardware { namespace { @@ -493,9 +497,26 @@ void AuthManager::ParseUltrasonicSide(const JsonObject &jsonObject) context_->ultrasonicInfo = DmUltrasonicInfo::DM_Ultrasonic_Forward; } else { context_->ultrasonicInfo = DmUltrasonicInfo::DM_Ultrasonic_Invalid; + return; } } } + bool isSupport = true; + if (context_->ultrasonicInfo == DM_Ultrasonic_Forward) { +#ifdef SUPPORT_MSDP + isSupport = Msdp::SpatialAwarenessMgrClient::GetInstance().IsPinCodeAbilitySupport( + Msdp::PinCodeMode::MODE_PIN_RECEIVE_CODE); +#endif + } + if (context_->ultrasonicInfo == DM_Ultrasonic_Reverse) { +#ifdef SUPPORT_MSDP + isSupport = Msdp::SpatialAwarenessMgrClient::GetInstance().IsPinCodeAbilitySupport( + Msdp::PinCodeMode::MODE_PIN_SEND_CODE); +#endif + } + if (!isSupport) { + context_->authType = AUTH_TYPE_PIN; + } } bool CheckBindLevel(const JsonItemObject &jsonObj, const std::string &key, int32_t &bindLevel) diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp index 411188a111cfa394ede55ddaf1702caaa657e0f9..7918ad77a5ee6558d3643a2aa99387358cf73408 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp @@ -41,6 +41,7 @@ constexpr const char* TAG_CUSTOM_DESCRIPTION = "CUSTOMDESC"; constexpr const char* TAG_LOCAL_DEVICE_TYPE = "LOCALDEVICETYPE"; constexpr const char* TAG_REQUESTER = "REQUESTER"; constexpr const char* UNVALID_CREDTID = "invalidCredId"; +constexpr const char* TAG_IS_SUPPORT_ULTRASONIC = "isSupportUltrasonic"; // authType fallback table using FallBackKey = std::pair; // accessee.bundleName, authType static std::map g_pinAuthTypeFallBackMap = { @@ -638,6 +639,7 @@ int32_t AuthSrcConfirmState::Action(std::shared_ptr context) NegotiateAcl(context, aclNegoResult); context->accesser.aclTypeList = aclNegoResult.Dump(); NegotiateProxyAcl(context); + NegotiateUltrasonic(context); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_REQ_USER_CONFIRM, context); context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, static_cast(STATUS_DM_SHOW_AUTHORIZE_UI), DM_OK); @@ -651,6 +653,32 @@ int32_t AuthSrcConfirmState::Action(std::shared_ptr context) return DM_OK; } +void AuthSrcConfirmState::NegotiateUltrasonic(std::shared_ptr context) +{ + CHECK_NULL_VOID(context); + if (context->authType != AUTH_TYPE_PIN_ULTRASONIC) { + LOGE("auth type not ultrasonic."); + return; + } + if (context->accessee.extraInfo.empty()) { + LOGE("extraInfo empty."); + return; + } + JsonObject json; + json.Parse(context->accessee.extraInfo); + if (json.IsDiscarded()) { + LOGE("extraInfo invalid."); + return; + } + bool isSupportUltrasonic = true; + if (IsBool(json, TAG_IS_SUPPORT_ULTRASONIC)) { + isSupportUltrasonic = json[TAG_IS_SUPPORT_ULTRASONIC].Get(); + } + if (!isSupportUltrasonic) { + context->authType = AUTH_TYPE_PIN; + } +} + void AuthSrcConfirmState::ResetBindLevel(std::shared_ptr context) { CHECK_NULL_VOID(context); diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 9884946db15eb6da7007a18c9f5c9a590e622ce8..2394a4f42954a1160cf73516fa272a55df489d09 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -35,6 +35,10 @@ #include "dm_auth_state_machine.h" #include "dm_crypto.h" +#ifdef SUPPORT_MSDP +#include "spatial_awareness_mgr_client.h" +#endif + namespace OHOS { namespace DistributedHardware { @@ -100,6 +104,8 @@ const char* TAG_CERT_INFO = "certInfo"; const char* TAG_LANGUAGE = "language"; const char* TAG_ULTRASONIC_SIDE = "ultrasonicSide"; const char* TAG_REMAINING_FROZEN_TIME = "remainingFrozenTime"; +const char* TAG_IS_SUPPORT_ULTRASONIC = "isSupportUltrasonic"; + constexpr const char* TAG_CUSTOM_DESCRIPTION = "CUSTOMDESC"; namespace { @@ -1508,7 +1514,24 @@ void DmAuthMessageProcessor::ParseUltrasonicSide( context->ultrasonicInfo = DmUltrasonicInfo::DM_Ultrasonic_Forward; } else { context->ultrasonicInfo = DmUltrasonicInfo::DM_Ultrasonic_Invalid; + return; } + bool isSupport = true; + if (context->ultrasonicInfo == DM_Ultrasonic_Forward) { +#ifdef SUPPORT_MSDP + isSupport = Msdp::SpatialAwarenessMgrClient::GetInstance().IsPinCodeAbilitySupport( + Msdp::PinCodeMode::MODE_PIN_SEND_CODE); +#endif + } + if (context->ultrasonicInfo == DM_Ultrasonic_Reverse) { +#ifdef SUPPORT_MSDP + isSupport = Msdp::SpatialAwarenessMgrClient::GetInstance().IsPinCodeAbilitySupport( + Msdp::PinCodeMode::MODE_PIN_RECEIVE_CODE); +#endif + } + JsonObject json; + json[TAG_IS_SUPPORT_ULTRASONIC] = isSupport; + context->accessee.extraInfo = json.Dump(); } int32_t DmAuthMessageProcessor::ParseMessageRespAclNegotiate(const JsonObject &jsonObject, diff --git a/test/unittest/UTTest_auth_manager.cpp b/test/unittest/UTTest_auth_manager.cpp index e6f47720529629b1b77b6b30e13080cce50bff89..0e6a8cf857f6c67b583d0d96147ef8ae1b171ba2 100644 --- a/test/unittest/UTTest_auth_manager.cpp +++ b/test/unittest/UTTest_auth_manager.cpp @@ -356,5 +356,45 @@ HWTEST_F(AuthManagerTest, IsAuthCodeReady_004, testing::ext::TestSize.Level1) bool ret = authManager->IsAuthCodeReady(pkgName); ASSERT_EQ(ret, true); } + +HWTEST_F(AuthManagerTest, ParseUltrasonicSide_001, testing::ext::TestSize.Level1) +{ + JsonObject jsonObject; + jsonObject[TAG_ULTRASONIC_SIDE] = "0"; + authManager->ParseUltrasonicSide(jsonObject); + jsonObject[TAG_ULTRASONIC_SIDE] = "1"; + authManager->ParseUltrasonicSide(jsonObject); + EXPECT_NE(authManager->context_, nullptr); +} + +HWTEST_F(AuthManagerTest, AuthSrcConfirmState_NegotiateUltrasonic_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + std::shared_ptr context = authManager->GetAuthContext(); + + context->authType = DmAuthType::AUTH_TYPE_IMPORT_AUTH_CODE; + authState->NegotiateUltrasonic(nullptr); + authState->NegotiateUltrasonic(context); + + context->authType = DmAuthType::AUTH_TYPE_PIN_ULTRASONIC; + authState->NegotiateUltrasonic(context); + + context->accessee.extraInfo = "123456"; + authState->NegotiateUltrasonic(context); + + JsonObject json; + json["isSupportUltrasonic"] = "123456"; + context->accessee.extraInfo = json.Dump(); + authState->NegotiateUltrasonic(context); + + json["isSupportUltrasonic"] = true; + context->accessee.extraInfo = json.Dump(); + authState->NegotiateUltrasonic(context); + + json["isSupportUltrasonic"] = false; + context->accessee.extraInfo = json.Dump(); + authState->NegotiateUltrasonic(context); + EXPECT_EQ(context->authType, DmAuthType::AUTH_TYPE_PIN); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_auth_message_processor.cpp b/test/unittest/UTTest_dm_auth_message_processor.cpp index 43793179d304a2c4e7c3944b74c31978bb44c990..94ed79026b013795ebaa7211e4072bc751b4f190 100644 --- a/test/unittest/UTTest_dm_auth_message_processor.cpp +++ b/test/unittest/UTTest_dm_auth_message_processor.cpp @@ -195,6 +195,21 @@ HWTEST_F(DmAuthMessageProcessorTest, ParseNegotiateMessage_006, testing::ext::Te EXPECT_EQ(ret, DM_OK); EXPECT_EQ(context->businessId, "testBusinessId"); } + +HWTEST_F(DmAuthMessageProcessorTest, ParseNegotiateMessage_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + context->authStateMachine = std::make_shared(context); + std::shared_ptr processor = std::make_shared(); + JsonObject jsonObj; + jsonObj["ultrasonicSide"] = 0; + int32_t ret = processor->ParseNegotiateMessage(jsonObj, context); + jsonObj["ultrasonicSide"] = 1; + ret = processor->ParseNegotiateMessage(jsonObj, context); + + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(context->accessee.extraInfo.empty(), false); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file