diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 1206f3909740ac8325d19fdcb5f1a940afb2e817..913e73f82a279d4159d2a6aa4ad9da8d98248ed8 100644 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -140,6 +140,7 @@ const std::string AUTH_TYPE = "authType"; const std::string TOKEN = "token"; const std::string PIN_TOKEN = "pinToken"; const std::string PIN_CODE_KEY = "pinCode"; +const std::string TAG_CERTIFIED_PARAM = "certifiedParam"; const int32_t AUTH_TYPE_PIN = 1; const int32_t AUTH_TYPE_SCAN = 2; const int32_t AUTH_TYPE_TOUCH = 3; diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index dca2e7e7f9e12b4679d778c7d4a9b893f46c129d..df761c07ad026f4632e9e7aafeec94443319f85f 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -30,12 +30,10 @@ class PinAuth : public IAuthentication { public: PinAuth(); ~PinAuth(); - int32_t ShowAuthInfo(int32_t code, std::shared_ptr authManager) override; - int32_t StartAuth(int32_t code, std::shared_ptr authManager) override; - int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) override; - + int32_t ShowAuthInfo(std::string &certifiedParam, std::shared_ptr authManager) override; + int32_t StartAuth(std::string &certifiedParam, std::shared_ptr authManager) override; + int32_t VerifyAuthentication(std::string &certifiedParam, const std::string &authParam) override; private: - int32_t times_ = 0; std::shared_ptr pinAuthUi_; }; } // namespace DistributedHardware diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 0bbadd15f7aa503e771432a132e9512f1834eec8..8ac99974ec2bf17a1e359e15da0be252aa8321a9 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -23,7 +23,6 @@ namespace OHOS { namespace DistributedHardware { -const int32_t MAX_VERIFY_TIMES = 3; PinAuth::PinAuth() { LOGI("PinAuth constructor"); @@ -33,37 +32,22 @@ PinAuth::~PinAuth() { } -int32_t PinAuth::ShowAuthInfo(int32_t code, std::shared_ptr authManager) +int32_t PinAuth::ShowAuthInfo(std::string &certifiedParam, std::shared_ptr authManager) { - return pinAuthUi_->ShowPinDialog(code, authManager); + return pinAuthUi_->ShowPinDialog(atoi(certifiedParam.c_str()), authManager); } -int32_t PinAuth::StartAuth(int32_t code, std::shared_ptr authManager) +int32_t PinAuth::StartAuth(std::string &certifiedParam, std::shared_ptr authManager) { - return pinAuthUi_->InputPinDialog(code, authManager); + return pinAuthUi_->InputPinDialog(atoi(certifiedParam.c_str()), authManager); } -int32_t PinAuth::VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) +int32_t PinAuth::VerifyAuthentication(std::string &certifiedParam, const std::string &authParam) { - times_ += 1; - nlohmann::json jsonObject = nlohmann::json::parse(authParam, nullptr, false); - if (jsonObject.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return DM_FAILED; - } - if (!jsonObject.contains(PIN_CODE_KEY) && !jsonObject.contains(PIN_TOKEN)) { - LOGE("err json string, first time"); - return DM_FAILED; - } - int32_t inputPinCode = jsonObject[PIN_CODE_KEY]; - int32_t inputPinToken = jsonObject[PIN_TOKEN]; - if (code == inputPinCode && stoi(pinToken) == inputPinToken) { + if (authParam == "0") { return DM_OK; - } else if (code != inputPinCode && times_ < MAX_VERIFY_TIMES) { - return DM_AUTH_INPUT_FAILED; - } else { - return DM_FAILED; } + return DM_FAILED; } extern "C" IAuthentication *CreatePinAuthObject(void) diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/pin_auth_ui.cpp index 9fc3459cda10a015720e9c8184833825b398c14f..eb976a67898c97ed963f8228bf400323baa920f8 100644 --- a/ext/pin_auth/src/pin_auth_ui.cpp +++ b/ext/pin_auth/src/pin_auth_ui.cpp @@ -43,7 +43,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authManager](int32_t id, const std::string& event, const std::string& params) { if (strcmp(params.c_str(), "0") == 0) { - authManager->ClosePage(id); + authManager->SetPageId(id); } if (strcmp(params.c_str(), "1") == 0) { LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); @@ -69,12 +69,12 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, [authManager](int32_t id, const std::string& event, const std::string& params) { if (strcmp(params.c_str(), "2") == 0) { - authManager->ClosePage(id); + authManager->SetPageId(id); } if (strcmp(params.c_str(), "0") == 0 || strcmp(params.c_str(), "1") == 0) { Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - authManager->VerifyPinAuthAuthentication(params.c_str()); + authManager->VerifyAuthentication(params.c_str()); } }); LOGI("ShowConfigDialog end"); diff --git a/ext/profile/BUILD.gn b/ext/profile/BUILD.gn index 552653a03c2077c3eea4b5b85534e18fc34c5e57..9dfe54e45e01efe71194329923d12f68c5167a08 100644 --- a/ext/profile/BUILD.gn +++ b/ext/profile/BUILD.gn @@ -30,7 +30,15 @@ if (defined(ohos_lite)) { "${ext_path}/profile/include", "${services_path}/include", "${services_path}/include/adapter", + "${services_path}/include/authentication", + "${services_path}/include/ability", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "${services_path}/include/discovery", + "${services_path}/include/dependency/commonevent", + "${services_path}/include/dependency/hichain", "${services_path}/include/dependency/softbus", + "${services_path}/include/dependency/timer", "${services_path}/include/ipc/standard", "${services_path}/include/devicestate", "${utils_path}/include", @@ -38,11 +46,12 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", "${innerkits_path}/native_cpp/include/ipc", "${innerkits_path}/native_cpp/include/ipc/standard", - "//foundation/communication/dsoftbus/interfaces/kits/bus_center", - "//foundation/communication/dsoftbus/interfaces/kits/common", - "//foundation/communication/dsoftbus/interfaces/kits/discovery", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + + "//base/notification/ces_standard/frameworks/core/include", + "//base/notification/ces_standard/interfaces/innerkits/native/include", + "//base/security/deviceauth/interfaces/innerkits", + "//base/startup/syspara_lite/interfaces/kits", + "//base/startup/syspara_lite/adapter/native/syspara/include", ] sources = [ @@ -60,6 +69,7 @@ if (defined(ohos_lite)) { "device_profile_core:distributed_device_profile_client", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "dsoftbus_standard:softbus_client" ] defines = [ diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 9e76a136103750e228535c364432533b4e55de33..f88a3f15515143314ecc1c4c4fb1361abbe290e7 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -50,8 +50,6 @@ public: virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr callback) = 0; virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) = 0; - virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) = 0; - virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action) = 0; virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) = 0; virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &uuid) = 0; }; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 46d8c3222c242a4e50e3d987e67de17c24e3c86d..74ab2e674f69dcd291819d4a47110108024d6f0b 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -49,8 +49,6 @@ public: virtual int32_t RegisterDeviceManagerFaCallback(const std::string &packageName, std::shared_ptr callback) override; virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) override; - virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &faParam) override; - virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action) override; virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) override; virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId, diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 811a6d7f49c9bacdfd17d18f177127b3dcd7b8a6..a32102c3ad82502bfae810743bf9362381c5e2a8 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -448,52 +448,6 @@ int32_t DeviceManagerImpl::VerifyAuthentication(const std::string &pkgName, cons return DM_OK; } -int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &dmFaParam) -{ - LOGI("DeviceManager::GetFaParam start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - LOGE("VerifyAuthentication failed, pkgName is empty"); - return DM_INVALID_VALUE; - } - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - - if (ipcClientProxy_->SendRequest(SERVER_GET_DMFA_INFO, req, rsp) != DM_OK) { - LOGI("DeviceManagerImpl::GetFaParam start 2"); - return DM_IPC_SEND_REQUEST_FAILED; - } - dmFaParam = rsp->GetDmAuthParam(); - LOGI("GetFaParam completed, pkgName: %s", pkgName.c_str()); - return DM_OK; -} - -int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action) -{ - LOGI("DeviceManager::SetUserOperation start, pkgName: %s", pkgName.c_str()); - if (pkgName.empty()) { - LOGE("VerifyAuthentication failed, pkgName is empty"); - return DM_INVALID_VALUE; - } - - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetOperation(action); - - if (ipcClientProxy_->SendRequest(SERVER_USER_AUTH_OPERATION, req, rsp) != DM_OK) { - return DM_IPC_SEND_REQUEST_FAILED; - } - int32_t ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("CheckAuthentication Failed with ret %d", ret); - return ret; - } - LOGI("SetUserOperation completed, pkgName: %s", pkgName.c_str()); - return DM_OK; -} - int32_t DeviceManagerImpl::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index be759e55e1057e56de3f5f2561f2fa21f8947279..ef11689db37c2d4aca0b0fb9a44e098472fd5ed4 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -298,57 +298,6 @@ ON_IPC_READ_RESPONSE(VERIFY_AUTHENTICATION, MessageParcel &reply, std::shared_pt return DM_OK; } -ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO, std::shared_ptr pBaseReq, MessageParcel &data) -{ - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string packagename = pReq->GetPkgName(); - if (!data.WriteString(packagename)) { - LOGE("write pkgName failed"); - return DM_IPC_FLATTEN_OBJECT; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - DmAuthParam authParam; - authParam.direction = reply.ReadInt32(); - authParam.authType = reply.ReadInt32(); - authParam.authToken = reply.ReadString(); - authParam.packageName = reply.ReadString(); - authParam.appName = reply.ReadString(); - authParam.appDescription = reply.ReadString(); - authParam.business = reply.ReadInt32(); - authParam.pincode = reply.ReadInt32(); - pRsp->SetDmAuthParam(authParam); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr pBaseReq, MessageParcel &data) -{ - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t action = pReq->GetOperation(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return DM_IPC_TRANSACTION_FAILED; - } - if (!data.WriteInt32(action)) { - LOGE("write action failed"); - return DM_WRITE_FAILED; - } - - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 71cb995b4f81a9ffcb6fd2b857fbecaeb4e5c78b..dbba19a6a465752818bfc919216a0c0066e4b2ac 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -167,7 +167,6 @@ public: static napi_value Constructor(napi_env env, napi_callback_info info); static napi_value CreateDeviceManager(napi_env env, napi_callback_info info); static napi_value ReleaseDeviceManager(napi_env env, napi_callback_info info); - static napi_value SetUserOperationSync(napi_env env, napi_callback_info info); static napi_value GetTrustedDeviceListSync(napi_env env, napi_callback_info info); static napi_value GetTrustedDeviceList(napi_env env, napi_callback_info info); static napi_value GetLocalDeviceInfoSync(napi_env env, napi_callback_info info); @@ -179,7 +178,6 @@ public: static napi_value VerifyAuthInfo(napi_env env, napi_callback_info info); static napi_value JsOn(napi_env env, napi_callback_info info); static napi_value JsOff(napi_env env, napi_callback_info info); - static napi_value GetAuthenticationParamSync(napi_env env, napi_callback_info info); static void HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo); static DeviceManagerNapi *GetDeviceManagerNapi(std::string &buldleName); static void CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType); @@ -187,8 +185,6 @@ public: static void DeviceInfoToJsArray(const napi_env &env, const std::vector &vecDevInfo, const int32_t idx, napi_value &arrayResult); - static void DmAuthParamToJsAuthParam(const napi_env &env, const OHOS::DistributedHardware::DmAuthParam &authParam, - napi_value ¶mResult); static void SetValueInt32(const napi_env &env, const std::string &fieldStr, const int32_t intValue, napi_value &result); static void SetValueUtf8String(const napi_env &env, const std::string &fieldStr, const std::string &str, diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index bb96c37a7044c5a55a282bc3077f4f9ed3ee30f6..1ab6a4f68ddf72b95abb4c4206088d0f98af5a53 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -526,12 +526,6 @@ void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env &env, const std::vect } } -void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAuthParam &authParam, - napi_value ¶mResult) -{ - return; -} - void DeviceManagerNapi::JsObjectToString(const napi_env &env, const napi_value &object, const std::string &fieldStr, char *dest, const int32_t destLen) { @@ -908,50 +902,6 @@ void DeviceManagerNapi::ReleaseDmCallback(std::string &bundleName, std::string & } } -napi_value DeviceManagerNapi::GetAuthenticationParamSync(napi_env env, napi_callback_info info) -{ - LOGI("GetAuthenticationParamSync in"); - size_t argc = 0; - napi_value thisVar = nullptr; - napi_value resultParam = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); - NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - DmAuthParam authParam; - int32_t ret = DeviceManager::GetInstance().GetFaParam(deviceManagerWrapper->bundleName_, authParam); - if (ret != 0) { - LOGE("GetAuthenticationParam for %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret); - napi_get_undefined(env, &resultParam); - return resultParam; - } - napi_create_object(env, &resultParam); - DmAuthParamToJsAuthParam(env, authParam, resultParam); - return resultParam; -} - -napi_value DeviceManagerNapi::SetUserOperationSync(napi_env env, napi_callback_info info) -{ - LOGI("SetUserOperationSync in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); - napi_valuetype valueType; - napi_typeof(env, argv[0], &valueType); - NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Object expected."); - - int32_t action = 0; - napi_get_value_int32(env, argv[0], &action); - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - int32_t ret = DeviceManager::GetInstance().SetUserOperation(deviceManagerWrapper->bundleName_, action); - if (ret != 0) { - LOGE("SetUserOperation for bunderName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret); - } - napi_value result = nullptr; - napi_get_undefined(env, &result); - return result; -} - void DeviceManagerNapi::CallGetTrustedDeviceListStatusSync(napi_env env, napi_status &status, DeviceInfoAsyncCallbackInfo *deviceInfoAsyncCallbackInfo) { @@ -1491,8 +1441,8 @@ napi_value DeviceManagerNapi::AuthenticateDevice(napi_env env, napi_callback_inf JsToDmDeviceInfo(env, argv[0], deviceInfo); std::string extraString; JsToDmExtra(env, argv[PARAM_INDEX_ONE], extraString, authAsyncCallbackInfo_.authType); - int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(deviceManagerWrapper->bundleName_, 1, deviceInfo, - extraString, authCallback); + int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(deviceManagerWrapper->bundleName_, + authAsyncCallbackInfo_.authType, deviceInfo, extraString, authCallback); if (ret != 0) { LOGE("AuthenticateDevice for bundleName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret); } @@ -1824,9 +1774,6 @@ napi_value DeviceManagerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("unAuthenticateDevice", UnAuthenticateDevice), DECLARE_NAPI_FUNCTION("authenticateDevice", AuthenticateDevice), DECLARE_NAPI_FUNCTION("verifyAuthInfo", VerifyAuthInfo), - DECLARE_NAPI_FUNCTION("setUserOperation", SetUserOperationSync), - DECLARE_NAPI_FUNCTION("getFaParam", GetAuthenticationParamSync), - DECLARE_NAPI_FUNCTION("getAuthenticationParam", GetAuthenticationParamSync), DECLARE_NAPI_FUNCTION("on", JsOn), DECLARE_NAPI_FUNCTION("off", JsOff)}; diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h index 67ca0c3ee86b1e0fccae4eb20927cda40dc3a829..b0176fb9abb6e56753924533cf1361ec51382765 100644 --- a/services/devicemanagerservice/include/authentication/authentication.h +++ b/services/devicemanagerservice/include/authentication/authentication.h @@ -16,17 +16,15 @@ #ifndef OHOS_DM_AUTHENTICATION_H #define OHOS_DM_AUTHENTICATION_H -#include "dm_ability_manager.h" - namespace OHOS { namespace DistributedHardware { class DmAuthManager; class IAuthentication { public: virtual ~IAuthentication() = default; - virtual int32_t ShowAuthInfo(int32_t code, std::shared_ptr authManager) = 0; - virtual int32_t StartAuth(int32_t code, std::shared_ptr authManager) = 0; - virtual int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) = 0; + virtual int32_t ShowAuthInfo(std::string &certifiedParam, std::shared_ptr authManager) = 0; + virtual int32_t StartAuth(std::string &certifiedParam, std::shared_ptr authManager) = 0; + virtual int32_t VerifyAuthentication(std::string &certifiedParam, const std::string &authParam) = 0; }; using CreateIAuthAdapterFuncPtr = IAuthentication *(*)(void); diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 6a7ae6b85aeb7a5a7f90f58e97bf559765801835..f8e88a158a605e1900dbe87914d6147bee0a0d4a 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -86,7 +86,6 @@ typedef struct DmAuthRequestContext { std::string appThumbnail; std::string token; int32_t reason; - int32_t aceId; std::vector syncGroupList; } DmAuthRequestContext; @@ -110,10 +109,11 @@ typedef struct DmAuthResponseContext { std::string appIcon; std::string appThumbnail; std::string token; + std::string certifiedParam; + int32_t pageId; int64_t requestId; int32_t code; int32_t state; - int32_t aceId; std::vector syncGroupList; } DmAuthResponseContext; @@ -131,7 +131,6 @@ public: const std::string &extra); int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId); int32_t VerifyAuthentication(const std::string &authParam); - void VerifyPinAuthAuthentication(const std::string &action); void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result); void OnSessionClosed(int32_t sessionId); void OnDataReceived(int32_t sessionId, std::string message); @@ -156,15 +155,12 @@ public: int32_t GetPinCode(); std::string GenerateGroupName(); int32_t HandleAuthenticateTimeout(); - void CancelDisplay(); int32_t GeneratePincode(); void ShowConfigDialog(); void ShowAuthInfoDialog(); void ShowStartAuthDialog(); - int32_t GetAuthenticationParam(DmAuthParam &authParam); - int32_t OnUserOperation(int32_t action); + int32_t SetPageId(int32_t pageId); void UserSwitchEventCallback(int32_t userId); - void ClosePage(const int32_t &id); private: std::shared_ptr softbusConnector_; diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 9ba556f4a188c3e4bf57fd6ff8f48da531b2ad7a..8f5228f3702dfaf50e49140302ae421fb93f9f20 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -146,6 +146,7 @@ void AuthMessageProcessor::CreateResponseAuthMessage(nlohmann::json &json) json[TAG_REQUEST_ID] = authResponseContext_->requestId; json[TAG_GROUP_ID] = groupId; json[TAG_GROUP_NAME] = authResponseContext_->groupName; + json[TAG_CERTIFIED_PARAM] = authResponseContext_->certifiedParam; LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s,%s", groupId.c_str(), authResponseContext_->groupName.c_str()); } @@ -225,6 +226,7 @@ void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) authResponseContext_->requestId = json[TAG_REQUEST_ID]; authResponseContext_->groupId = json[TAG_GROUP_ID]; authResponseContext_->groupName = json[TAG_GROUP_NAME]; + authResponseContext_->certifiedParam = json[TAG_CERTIFIED_PARAM]; LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s,%s", authResponseContext_->groupId.c_str(), authResponseContext_->groupName.c_str()); } diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index de210e85d6399e8e313c24fdea4ea7ff03a6d014..ffadefedb9185332a620b5a451d3d27943e27d4a 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -48,7 +48,6 @@ const int32_t INPUT_TIMEOUT = 60; const int32_t ADD_TIMEOUT = 10; const int32_t WAIT_NEGOTIATE_TIMEOUT = 10; const int32_t WAIT_REQUEST_TIMEOUT = 10; -const int32_t CANCEL_PIN_CODE_DISPLAY = 1; const int32_t DEVICE_ID_HALF = 2; static void TimeOut(void *data, DmTimer& timer) @@ -80,7 +79,7 @@ DmAuthManager::~DmAuthManager() int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - LOGE("DmAuthManager::AuthenticateDevice start"); + LOGE("DmAuthManager::AuthenticateDevice start auth type %d", authType); std::shared_ptr authentication = authenticationMap_[authType]; if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); @@ -178,22 +177,18 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); std::shared_ptr ptr; - if (authenticationMap_.find(1) == authenticationMap_.end()) { + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return DM_FAILED; } - ptr = authenticationMap_[1]; - int32_t ret = ptr->VerifyAuthentication(authRequestContext_->token, authResponseContext_->code, authParam); + + ptr = authenticationMap_[authResponseContext_->authType]; + int32_t ret = ptr->VerifyAuthentication(authResponseContext_->certifiedParam, authParam); switch (ret) { case DM_OK: authRequestState_->TransitionTo(std::make_shared()); break; - case DM_AUTH_INPUT_FAILED: - listener_->OnVerifyAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, - DM_AUTH_INPUT_FAILED, ""); - break; default: - CancelDisplay(); authRequestContext_->reason = DM_AUTH_INPUT_FAILED; authResponseContext_->state = authRequestState_->GetStateType(); authRequestState_->TransitionTo(std::make_shared()); @@ -304,6 +299,7 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) authResponseState_->TransitionTo(std::make_shared()); } else if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { + authResponseContext_->state = authRequestState_->GetStateType(); authRequestState_->TransitionTo(std::make_shared()); } break; @@ -326,6 +322,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); return; } + authResponseContext_->certifiedParam = GenerateGroupName(); authResponseContext_->code = GeneratePincode(); authResponseContext_->groupId = groupId; authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -520,7 +517,7 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) return DM_FAILED; } LOGI("DmAuthManager::authRequestContext CancelDisplay start"); - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->aceId); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); return DM_OK; } @@ -547,7 +544,13 @@ void DmAuthManager::AuthenticateFinish() LOGI("DmAuthManager::AuthenticateFinish start"); if (authResponseState_ != nullptr) { if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->aceId); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); + } + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW + && authResponseContext_->authType != 1) { + authMessageProcessor_->SetResponseContext(authResponseContext_); + std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE); + softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } if (!timerMap_.empty()) { for (auto &iter : timerMap_) { @@ -569,7 +572,7 @@ void DmAuthManager::AuthenticateFinish() } if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->aceId); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); } listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, @@ -591,16 +594,6 @@ void DmAuthManager::AuthenticateFinish() LOGI("DmAuthManager::AuthenticateFinish complete"); } -void DmAuthManager::CancelDisplay() -{ - LOGI("DmAuthManager::CancelDisplay start"); - nlohmann::json jsonObj; - jsonObj[CANCEL_DISPLAY_KEY] = CANCEL_PIN_CODE_DISPLAY; - std::string paramJson = jsonObj.dump(); - std::string pkgName = "com.ohos.devicemanagerui"; - listener_->OnFaCall(pkgName, paramJson); -} - int32_t DmAuthManager::GeneratePincode() { return GenRandInt(MIN_PIN_CODE, MAX_PIN_CODE); @@ -680,74 +673,37 @@ void DmAuthManager::ShowConfigDialog() void DmAuthManager::ShowAuthInfoDialog() { LOGI("DmAuthManager::ShowAuthInfoDialog start"); + if (authResponseContext_->authType == 1) { + authResponseContext_->certifiedParam = std::to_string(authResponseContext_->code); + } else { + authResponseContext_->certifiedParam = GenerateGroupName(); + } + std::shared_ptr ptr; - if (authenticationMap_.find(1) == authenticationMap_.end()) { + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return; } - ptr = authenticationMap_[1]; + ptr = authenticationMap_[authResponseContext_->authType]; LOGI("ShowAuthInfoDialog code:%d", authResponseContext_->code); - ptr->ShowAuthInfo(authResponseContext_->code, shared_from_this()); + ptr->ShowAuthInfo(authResponseContext_->certifiedParam, shared_from_this()); } void DmAuthManager::ShowStartAuthDialog() { LOGI("DmAuthManager::ShowStartAuthDialog start"); std::shared_ptr ptr; - if (authenticationMap_.find(1) == authenticationMap_.end()) { + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return; } - ptr = authenticationMap_[1]; - ptr->StartAuth(authResponseContext_->code, shared_from_this()); -} - -int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) -{ - if (dmAbilityMgr_ == nullptr) { - LOGI("dmAbilityMgr_ is nullptr"); - return DM_POINT_NULL; - } - - dmAbilityMgr_->StartAbilityDone(); - AbilityRole role = dmAbilityMgr_->GetAbilityRole(); - authParam.direction = (int32_t)role; - authParam.authType = AUTH_TYPE_PIN; - authParam.authToken = authResponseContext_->token; - - if (role == AbilityRole::ABILITY_ROLE_PASSIVE) { - authResponseContext_->code = GeneratePincode(); - authParam.packageName = authResponseContext_->targetPkgName; - authParam.appName = authResponseContext_->appName; - authParam.appDescription = authResponseContext_->appDesc; - authParam.business = BUSINESS_FA_MIRGRATION; - authParam.pincode = authResponseContext_->code; - } - return DM_OK; + ptr = authenticationMap_[authResponseContext_->authType]; + ptr->StartAuth(authResponseContext_->certifiedParam, shared_from_this()); } -int32_t DmAuthManager::OnUserOperation(int32_t action) +int32_t DmAuthManager::SetPageId(int32_t pageId) { - switch (action) { - case USER_OPERATION_TYPE_ALLOW_AUTH: - case USER_OPERATION_TYPE_CANCEL_AUTH: - StartAuthProcess(action); - break; - case USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT: - AuthenticateFinish(); - break; - case USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY: - CancelDisplay(); - break; - case USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT: - authRequestContext_->reason = DM_AUTH_DONT_AUTH; - authResponseContext_->state = authRequestState_->GetStateType(); - AuthenticateFinish(); - break; - default: - LOGE("this action id not support"); - break; - } + authResponseContext_->pageId = pageId; return DM_OK; } @@ -783,25 +739,5 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) } } } - -void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) -{ - LOGI("DmAuthManager::VerifyPinAuthAuthentication"); - timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); - if (action == "0") { - authRequestState_->TransitionTo(std::make_shared()); - } - if (action == "1") { - authRequestContext_->reason = DM_AUTH_INPUT_FAILED; - authResponseContext_->state = authRequestState_->GetStateType(); - authRequestState_->TransitionTo(std::make_shared()); - } - LOGI("DmAuthManager::VerifyAuthentication complete"); -} - -void DmAuthManager::ClosePage(const int32_t &id) -{ - authResponseContext_->aceId = id; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 88541338f4102005d69adf7b9ed465ce023482a4..fea0f3e582cd45077f07a729092f1211dbd0af6c 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -244,25 +244,5 @@ int32_t DeviceManagerService::VerifyAuthentication(const std::string &authParam) } return authMgr_->VerifyAuthentication(authParam); } - -int32_t DeviceManagerService::GetFaParam(std::string &pkgName, DmAuthParam &authParam) -{ - if (pkgName.empty()) { - LOGE("GetFaParam failed, pkgName is empty"); - return DM_INPUT_PARA_EMPTY; - } - authMgr_->GetAuthenticationParam(authParam); - return DM_OK; -} - -int32_t DeviceManagerService::SetUserOperation(std::string &pkgName, int32_t action) -{ - if (pkgName.empty()) { - LOGE("SetUserOperation failed, pkgName is empty"); - return DM_INPUT_PARA_EMPTY; - } - authMgr_->OnUserOperation(action); - return DM_OK; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp index 2a61266b53f6988a4c8f1df2a628f3bd1d931ed2..c858a408223835240e44cadc510b5251d29e9333 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -386,50 +386,5 @@ ON_IPC_CMD(GET_UUID_BY_NETWORK, MessageParcel &data, MessageParcel &reply) } return DM_OK; } - -ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply) -{ - std::string packName = data.ReadString(); - DmAuthParam authParam; - int32_t ret = DM_OK; - ret = DeviceManagerService::GetInstance().GetFaParam(packName, authParam); - int32_t appIconLen = authParam.imageinfo.GetAppIconLen(); - int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); - - if (!reply.WriteInt32(authParam.direction) || !reply.WriteInt32(authParam.authType) || - !reply.WriteString(authParam.authToken) || !reply.WriteString(authParam.packageName) || - !reply.WriteString(authParam.appName) || !reply.WriteString(authParam.appDescription) || - !reply.WriteInt32(authParam.business) || !reply.WriteInt32(authParam.pincode) || - !reply.WriteInt32(appIconLen) || !reply.WriteInt32(appThumbnailLen)) { - LOGE("write reply failed"); - return DM_IPC_FLATTEN_OBJECT; - } - - if (appIconLen > 0 && authParam.imageinfo.GetAppIcon() != nullptr) { - if (!reply.WriteRawData(authParam.imageinfo.GetAppIcon(), appIconLen)) { - LOGE("write appIcon failed"); - return DM_IPC_FLATTEN_OBJECT; - } - } - if (appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) { - if (!reply.WriteRawData(authParam.imageinfo.GetAppThumbnail(), appThumbnailLen)) { - LOGE("write appThumbnail failed"); - return DM_IPC_FLATTEN_OBJECT; - } - } - return DM_OK; -} - -ON_IPC_CMD(SERVER_USER_AUTH_OPERATION, MessageParcel &data, MessageParcel &reply) -{ - std::string packageName = data.ReadString(); - int32_t action = data.ReadInt32(); - int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action); - if (!reply.WriteInt32(action)) { - LOGE("write result failed"); - return DM_WRITE_FAILED; - } - return result; -} } // namespace DistributedHardware } // namespace OHOS