!509 【新增插件功能】扩充插件功能

Merge pull request !509 from ansel/master
This commit is contained in:
openharmony_ci
2023-10-15 07:06:44 +00:00
committed by Gitee
11 changed files with 93 additions and 4 deletions
+2
View File
@@ -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;
/**
+1
View File
@@ -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",
]
@@ -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.");
@@ -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;
}
+17
View File
@@ -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);
+1
View File
@@ -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
@@ -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);
@@ -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) {
@@ -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)
{
}
@@ -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;
@@ -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,