diff --git a/interfaces/inner_api/device_auth_ext.h b/interfaces/inner_api/device_auth_ext.h index d828a4d8..7d6900b1 100644 --- a/interfaces/inner_api/device_auth_ext.h +++ b/interfaces/inner_api/device_auth_ext.h @@ -85,6 +85,8 @@ typedef struct { int32_t (*createSession)(int32_t *sessionId, const cJSON *in, cJSON *out); /** This function is used to process authentication dat. */ int32_t (*processSession)(int32_t *sessionId, const cJSON *in, cJSON *out, int32_t *status); + /** This function is used to destroy authentication dat. */ + int32_t (*destroySession)(int32_t sessionId); } AccountAuthExtPlug; /** diff --git a/services/BUILD.gn b/services/BUILD.gn index 2a599326..f7d181f6 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -103,6 +103,7 @@ if (os_level == "mini" || os_level == "small") { sources = deviceauth_ipc_files sources += [ + "${dev_frameworks_path}/src/plugin_adapter_mock/account_auth_plugin_proxy_mock.c", "${frameworks_path}/src/ipc_service.c", "${frameworks_path}/src/lite/ipc_service_init.c", ] diff --git a/services/authenticators/src/account_related/account_module.c b/services/authenticators/src/account_related/account_module.c index 1d054a4a..4ad6bf32 100644 --- a/services/authenticators/src/account_related/account_module.c +++ b/services/authenticators/src/account_related/account_module.c @@ -14,6 +14,7 @@ */ #include "account_module.h" +#include "account_auth_plugin_proxy.h" #include "account_module_defines.h" #include "account_multi_task_manager.h" #include "account_version_util.h" @@ -67,6 +68,9 @@ static int32_t CreateAccountTask(int32_t *taskId, const CJson *in, CJson *out) if (IsAccountMsgNeedIgnore(in)) { return HC_ERR_IGNORE_MSG; } + if (HasAccountAuthPlugin() == HC_SUCCESS) { + return CreateAuthSession(taskId, in, out); + } AccountMultiTaskManager *authManager = GetAccountMultiTaskManager(); if (authManager == NULL) { LOGE("Get multi auth manager instance failed."); @@ -91,6 +95,9 @@ static int32_t CreateAccountTask(int32_t *taskId, const CJson *in, CJson *out) static int32_t ProcessAccountTask(int32_t taskId, const CJson *in, CJson *out, int32_t *status) { + if (HasAccountAuthPlugin() == HC_SUCCESS) { + return ProcessAuthSession(&taskId, in, out, status); + } AccountMultiTaskManager *authManager = GetAccountMultiTaskManager(); if (authManager == NULL) { LOGE("Get multi auth manager instance failed."); @@ -107,6 +114,10 @@ static int32_t ProcessAccountTask(int32_t taskId, const CJson *in, CJson *out, i static void DestroyAccountTask(int32_t taskId) { + if (HasAccountAuthPlugin() == HC_SUCCESS) { + (void)DestroyAuthSession(taskId); + return; + } AccountMultiTaskManager *authManager = GetAccountMultiTaskManager(); if (authManager == NULL) { LOGE("Get multi auth manager instance failed."); diff --git a/services/creds_manager/src/creds_manager.c b/services/creds_manager/src/creds_manager.c index ebe2b96b..79ede2f0 100644 --- a/services/creds_manager/src/creds_manager.c +++ b/services/creds_manager/src/creds_manager.c @@ -15,6 +15,7 @@ #include "creds_manager.h" +#include "account_auth_plugin_proxy.h" #include "account_module_defines.h" #include "account_related_creds_manager.h" #include "account_related_group_auth.h" @@ -41,6 +42,24 @@ static int32_t GetAccountRelatedCandidateGroups(int32_t osAccountId, const CJson queryParams.groupVisibility = GROUP_VISIBILITY_PUBLIC; } ((AccountRelatedGroupAuth *)groupAuth)->getAccountCandidateGroup(osAccountId, in, &queryParams, vec); + // All return success, only notify the plugin. + if (HasAccountAuthPlugin() == HC_SUCCESS && vec->size(vec) == 0) { + CJson *input = CreateJson(); + if (input == NULL) { + return HC_SUCCESS; + } + CJson *output = CreateJson(); + if (output == NULL) { + FreeJson(input); + return HC_SUCCESS; + } + int32_t ret = ExcuteCredMgrCmd(osAccountId, QUERY_SELF_CREDENTIAL_INFO, input, output); + if (ret != HC_SUCCESS) { + LOGE("Account cred is empty."); + } + FreeJson(input); + FreeJson(output); + } return HC_SUCCESS; } diff --git a/services/device_auth.c b/services/device_auth.c index 3265c4c2..adaddcc5 100644 --- a/services/device_auth.c +++ b/services/device_auth.c @@ -15,6 +15,7 @@ #include "device_auth.h" +#include "account_auth_plugin_proxy.h" #include "alg_loader.h" #include "callback_manager.h" #include "channel_manager.h" @@ -441,6 +442,15 @@ static int32_t PushStartSessionTask(int64_t sessionId) return HC_SUCCESS; } +static int32_t AddOriginDataForPlugin(CJson *receivedMsg, const uint8_t *data) +{ + if ((receivedMsg == NULL) || (data == NULL)) { + LOGE("Invalid params"); + return HC_ERR_INVALID_PARAMS; + } + return AddStringToJson(receivedMsg, FIELD_PLUGIN_EXT_DATA, (const char *)data); +} + static int32_t PushProcSessionTask(int64_t sessionId, CJson *receivedMsg) { ProcSessionTask *task = (ProcSessionTask *)HcMalloc(sizeof(ProcSessionTask), 0); @@ -911,6 +921,13 @@ static int32_t ProcessData(int64_t authReqId, const uint8_t *data, uint32_t data return res; } } + if (HasAccountAuthPlugin() == HC_SUCCESS) { + res = AddOriginDataForPlugin(receivedMsg, data); + if (res != HC_SUCCESS) { + FreeJson(receivedMsg); + return res; + } + } res = PushProcSessionTask(authReqId, receivedMsg); if (res != HC_SUCCESS) { FreeJson(receivedMsg); diff --git a/services/frameworks/inc/common_defs.h b/services/frameworks/inc/common_defs.h index f5e4ff7c..afc7a2e3 100644 --- a/services/frameworks/inc/common_defs.h +++ b/services/frameworks/inc/common_defs.h @@ -126,6 +126,7 @@ #define FIELD_AUTH_PK_INFO_SIGN "authPkInfoSign" #define FIELD_AUTH_RESULT_MAC "authResultMac" #define FIELD_LOCAL_DEVICE_TYPE "localDeviceType" +#define FIELD_PLUGIN_EXT_DATA "originPeerData" #define INVALID_MODULE_TYPE (-1) #define GROUP_ERR_MSG 0x8080 diff --git a/services/frameworks/inc/plugin_adapter/account_auth_plugin_proxy.h b/services/frameworks/inc/plugin_adapter/account_auth_plugin_proxy.h index 938c2f2e..ef7f2652 100644 --- a/services/frameworks/inc/plugin_adapter/account_auth_plugin_proxy.h +++ b/services/frameworks/inc/plugin_adapter/account_auth_plugin_proxy.h @@ -28,6 +28,7 @@ int32_t SetAccountAuthPlugin(const CJson *inputParams, AccountAuthExtPlug *accou int32_t ExcuteCredMgrCmd(int32_t osAccountId, int32_t cmdId, const CJson *in, CJson *out); int32_t CreateAuthSession(int32_t *sessionId, const CJson *in, CJson *out); int32_t ProcessAuthSession(int32_t *sessionId, const CJson *in, CJson *out, int32_t *status); +int32_t DestroyAuthSession(int32_t sessionId); void DestoryAccountAuthPlugin(void); int32_t HasAccountAuthPlugin(void); diff --git a/services/frameworks/src/plugin_adapter/account_auth_plugin_proxy.c b/services/frameworks/src/plugin_adapter/account_auth_plugin_proxy.c index c82ab55a..0da8024d 100644 --- a/services/frameworks/src/plugin_adapter/account_auth_plugin_proxy.c +++ b/services/frameworks/src/plugin_adapter/account_auth_plugin_proxy.c @@ -37,7 +37,8 @@ int32_t SetAccountAuthPlugin(const CJson *inputParams, AccountAuthExtPlug *accou { g_accountAuthPlugin = accountAuthPlugin; if (g_accountAuthPlugin == NULL || g_accountAuthPlugin->createSession == NULL || - g_accountAuthPlugin->excuteCredMgrCmd == NULL || g_accountAuthPlugin->processSession == NULL) { + g_accountAuthPlugin->excuteCredMgrCmd == NULL || g_accountAuthPlugin->processSession == NULL || + g_accountAuthPlugin->destroySession == NULL) { LOGE("[ACCOUNT_AUTH_PLUGIN]: SetAccountAuthPlugin:Input params is invalid."); return HC_ERR_INVALID_PARAMS; } @@ -77,6 +78,15 @@ int32_t ProcessAuthSession(int32_t *sessionId, const CJson *in, CJson *out, int3 return g_accountAuthPlugin->processSession(sessionId, in, out, status); } +int32_t DestroyAuthSession(int32_t sessionId) +{ + if (g_accountAuthPlugin == NULL || g_accountAuthPlugin->destroySession == NULL) { + LOGE("[ACCOUNT_AUTH_PLUGIN]: destroySession: Input params is invalid."); + return HC_ERR_INVALID_PARAMS; + } + return g_accountAuthPlugin->destroySession(sessionId); +} + void DestoryAccountAuthPlugin(void) { if (g_accountAuthPlugin != NULL && g_accountAuthPlugin->base.destroy != NULL) { diff --git a/services/frameworks/src/plugin_adapter_mock/account_auth_plugin_proxy_mock.c b/services/frameworks/src/plugin_adapter_mock/account_auth_plugin_proxy_mock.c index c198aab5..6fbefab5 100644 --- a/services/frameworks/src/plugin_adapter_mock/account_auth_plugin_proxy_mock.c +++ b/services/frameworks/src/plugin_adapter_mock/account_auth_plugin_proxy_mock.c @@ -50,6 +50,12 @@ int32_t ProcessAuthSession(int32_t *sessionId, const CJson *in, CJson *out, int3 return HC_ERR_NOT_SUPPORT; } +int32_t DestroyAuthSession(int32_t sessionId) +{ + (void)sessionId; + return HC_ERR_NOT_SUPPORT; +} + void DestoryAccountAuthPlugin(void) { } diff --git a/services/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c b/services/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c index df78513c..87ca0ac2 100644 --- a/services/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c +++ b/services/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c @@ -14,6 +14,7 @@ */ #include "account_related_group_auth.h" +#include "account_auth_plugin_proxy.h" #include "common_defs.h" #include "device_auth_defines.h" #include "group_auth_data_operation.h" @@ -508,7 +509,7 @@ static int32_t GetAuthParamsVecForServer(const CJson *dataFromClient, ParamsVecF return HC_ERR_JSON_FAIL; } - if (AddSelfAccountInfoForServer(dupData) != HC_SUCCESS) { + if ((HasAccountAuthPlugin() != HC_SUCCESS) && (AddSelfAccountInfoForServer(dupData) != HC_SUCCESS)) { LOGE("Failed to add account info for server!"); FreeJson(dupData); return HC_ERR_GROUP_NOT_EXIST; diff --git a/services/session_manager/src/session/v1/compatible_auth_sub_session/compatible_auth_sub_session_common.c b/services/session_manager/src/session/v1/compatible_auth_sub_session/compatible_auth_sub_session_common.c index 2c7c7937..9e93dda6 100644 --- a/services/session_manager/src/session/v1/compatible_auth_sub_session/compatible_auth_sub_session_common.c +++ b/services/session_manager/src/session/v1/compatible_auth_sub_session/compatible_auth_sub_session_common.c @@ -15,6 +15,7 @@ #include "compatible_auth_sub_session_common.h" +#include "account_auth_plugin_proxy.h" #include "account_related_group_auth.h" #include "compatible_auth_sub_session_util.h" #include "data_manager.h" @@ -40,9 +41,28 @@ static void GetAccountRelatedCandidateGroups(int32_t osAccountId, const CJson *p return; } ((AccountRelatedGroupAuth *)groupAuth)->getAccountCandidateGroup(osAccountId, param, &queryParams, vec); - if (vec->size(vec) == 0) { - LOGI("Account related groups not found!"); + if (vec->size(vec) != 0) { + return; } + LOGI("Account related groups not found!"); + if (HasAccountAuthPlugin() != HC_SUCCESS) { + return; + } + CJson *input = CreateJson(); + if (input == NULL) { + return; + } + CJson *output = CreateJson(); + if (output == NULL) { + FreeJson(input); + return; + } + int32_t ret = ExcuteCredMgrCmd(osAccountId, QUERY_SELF_CREDENTIAL_INFO, input, output); + if (ret != HC_SUCCESS) { + LOGE("Account cred is empty."); + } + FreeJson(input); + FreeJson(output); } static void GetAccountUnrelatedCandidateGroups(int32_t osAccountId, bool isDeviceLevel, bool isClient,