From 1f88250a55018aa3408c6e4b019af642bb6247f1 Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Mon, 19 Sep 2022 11:08:25 +0800 Subject: [PATCH 1/3] tongbulite_master --- README.md | 40 ++++---- cert_mgr_service/BUILD.gn | 13 ++- .../common/include/cert_mgr_log.h | 2 +- .../common/include/cert_mgr_type.h | 28 ++++++ cert_mgr_service/framework/BUILD.gn | 56 ++++------- .../framework/include/cert_framework_client.h | 38 -------- .../{ => small}/cert_framework_define.h | 8 +- .../src/mini/cert_manager_interface.c | 2 +- .../cert_framework_client_proxy.c} | 94 ++++++++++--------- .../src/{ => small}/cert_framework_feature.c | 35 +++---- .../src/{ => small}/cert_framework_server.c | 9 +- .../src/{ => small}/cert_framework_service.c | 7 +- .../include}/cert_manager_interface.h | 12 +-- .../services/core/cert/cert_service_auth.c | 2 +- .../core/cert/cert_service_challenge.c | 2 +- cert_mgr_service/services/core/dfx/cert_dfx.c | 6 ++ .../services/core/include/cert_type.h | 1 + .../services/core/network/cert_network.c | 2 + cert_mgr_service/test/startup/BUILD.gn | 52 ++++++++++ .../startup}/cert_framework_client_start.c | 8 +- 20 files changed, 218 insertions(+), 199 deletions(-) create mode 100644 cert_mgr_service/common/include/cert_mgr_type.h delete mode 100644 cert_mgr_service/framework/include/cert_framework_client.h rename cert_mgr_service/framework/include/{ => small}/cert_framework_define.h (86%) rename cert_mgr_service/framework/src/{cert_framework_client.c => small/cert_framework_client_proxy.c} (79%) rename cert_mgr_service/framework/src/{ => small}/cert_framework_feature.c (88%) rename cert_mgr_service/framework/src/{ => small}/cert_framework_server.c (96%) rename cert_mgr_service/framework/src/{ => small}/cert_framework_service.c (96%) rename cert_mgr_service/{framework/include/mini => interfaces/include}/cert_manager_interface.h (79%) create mode 100644 cert_mgr_service/test/startup/BUILD.gn rename cert_mgr_service/{framework/src => test/startup}/cert_framework_client_start.c (89%) diff --git a/README.md b/README.md index ac89278..f6e8ed5 100644 --- a/README.md +++ b/README.md @@ -12,36 +12,34 @@ Open Harmony授权验证平台开发分支 | build(编译配置) | | certconfig.gni(编译目录等公共配置) | common(公共基础能力) - | | log - | | | ***log.h - | | ***errorno.h + | | include + | | | cert_mgr_log.h + | | | cert_mgr_type.h | framework(SA启动框架) | | src | | include | | BUILD.gn | interfaces(对外接口) - | | innerkits - | | | native_cpp - | | | | include - | | | | src - | | | | BUILD.gn - | | kits - | sample(示例) - | | client(客户端示例) + | | include + | | | cert_manager_interface.h | services(服务主体和业务逻辑代码) - | | certmanager_ability(服务框架) - | | | include - | | | src - | | | BUILD.gn - | | etc(启动配置文件) - | | sa_profile(进程配置文件) | | core(业务逻辑代码,暂时放在该目录) - | | | src + | | | adapter + | | | cert + | | | dfx | | | include - | | oem_adapter(合作伙伴适配接口) + | | | network + | | | security + | | | utils + | | | BUILD.gn + | | | cert_entry.c + | | | cert_entry.h | test(测试用例) - | BUILD.gn(组件编译) - | bundle.json(子系统编译) + | | data(测试用例数据) + | | startup(L1测试启动模块) + | | unittest(测试模块) + | BUILD.gn(编译脚本) + | bundle.json(编译描述文件) #### 安装教程 diff --git a/cert_mgr_service/BUILD.gn b/cert_mgr_service/BUILD.gn index 182e2c3..885d7af 100644 --- a/cert_mgr_service/BUILD.gn +++ b/cert_mgr_service/BUILD.gn @@ -17,18 +17,17 @@ lite_component("cert_mgr_service") { if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") { features += [ "framework:cert_framework_service", - "framework:cert_framework_client", - ] - - features += [ - #"services/oem_adapter:cert_mgr_oem_adapter", + "test/startup:cert_framework_client", ] } if (ohos_kernel_type == "liteos_m") { features += [ - "services/core:cert_mgr_core", - #"services/oem_adapter:cert_mgr_oem_adapter", + "framework:cert_mgr_sdk", ] } + + features += [ + #"services/oem_adapter:cert_mgr_oem_adapter", + ] } diff --git a/cert_mgr_service/common/include/cert_mgr_log.h b/cert_mgr_service/common/include/cert_mgr_log.h index f643597..684855e 100644 --- a/cert_mgr_service/common/include/cert_mgr_log.h +++ b/cert_mgr_service/common/include/cert_mgr_log.h @@ -1,5 +1,5 @@ #ifndef CERT_MGR_LOG_H -#define CERT_FRAMEWORK_CLIENT_H +#define CERT_MGR_LOG_H #include "hilog/log.h" diff --git a/cert_mgr_service/common/include/cert_mgr_type.h b/cert_mgr_service/common/include/cert_mgr_type.h new file mode 100644 index 0000000..8ffb5d3 --- /dev/null +++ b/cert_mgr_service/common/include/cert_mgr_type.h @@ -0,0 +1,28 @@ +#ifndef CERT_MGR_TYPE_H +#define CERT_MGR_TYPE_H + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +#define CERTMANAGER_FAIL (-1) + +#define CERTMANAGER_SUCCESS 0 + +typedef struct { + int32_t authResult; + int32_t softwareResult; + char* ticket; +} CertResultInfo; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif \ No newline at end of file diff --git a/cert_mgr_service/framework/BUILD.gn b/cert_mgr_service/framework/BUILD.gn index 611e1cf..dbb6e5b 100644 --- a/cert_mgr_service/framework/BUILD.gn +++ b/cert_mgr_service/framework/BUILD.gn @@ -28,13 +28,14 @@ cflags_common = [ ] include_common = [ - "include", + "include/small", "${certmanager_path}/services/core/include", + "${certmanager_path}/common/include", + "${certmanager_path}/interfaces/include", "//utils/native/lite/include", "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr", "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", - "${certmanager_path}/common/include", ] config("cert_mgr_framework_config") { @@ -47,8 +48,8 @@ config("cert_mgr_framework_config") { #L1 server shared_library("certserver") { sources = [ - "src/cert_framework_feature.c", - "src/cert_framework_server.c", + "src/small/cert_framework_feature.c", + "src/small/cert_framework_server.c", ] cflags = [ "-fPIC", ] @@ -74,7 +75,7 @@ shared_library("certserver") { #L1 client shared_library("certclient") { sources = [ - "src/cert_framework_client.c", + "src/small/cert_framework_client_proxy.c", ] cflags = [ "-fPIC", ] @@ -96,7 +97,7 @@ shared_library("certclient") { #L1 service bin executable("cert_framework_service") { sources = [ - "src/cert_framework_service.c", + "src/small/cert_framework_service.c", ] cflags = cflags_common cflags_cc = cflags @@ -113,38 +114,17 @@ executable("cert_framework_service") { ] } -#L1 client bin -executable("cert_framework_client") { - sources = [ - "src/cert_framework_client_start.c", - ] - cflags = cflags_common - cflags_cc = cflags - public_configs = [ - ":cert_mgr_framework_config", - ] - - include_dirs = [ - "include", - "${certmanager_path}/common/include", - ] - - deps = [ - ":certclient", - "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", - ] -} - #L0 interface static_library("cert_mgr_sdk") { - if (os_level == "mini") { - sources = [ "src/mini/cert_manager_interface.c" ] - include_dirs = [ - "include/mini", - "${certmanager_path}/services/core" - ] - deps = [ - "${certmanager_path}/services/core:cert_mgr_core", - ] - } + if (os_level == "mini") { + sources = [ "src/mini/cert_manager_interface.c" ] + include_dirs = [ + "${certmanager_path}/common/include", + "${certmanager_path}/interfaces/include", + "${certmanager_path}/services/core" + ] + deps = [ + "${certmanager_path}/services/core:cert_mgr_core", + ] + } } \ No newline at end of file diff --git a/cert_mgr_service/framework/include/cert_framework_client.h b/cert_mgr_service/framework/include/cert_framework_client.h deleted file mode 100644 index 1c77b02..0000000 --- a/cert_mgr_service/framework/include/cert_framework_client.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2022 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 CERT_FRAMEWORK_CLIENT_H -#define CERT_FRAMEWORK_CLIENT_H - -#include "cert_framework_define.h" - -#include - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif - -int32_t StartCertTask(void); - -int32_t GetCertStatus(CertResultInfo *certResultInfo); - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif - -#endif \ No newline at end of file diff --git a/cert_mgr_service/framework/include/cert_framework_define.h b/cert_mgr_service/framework/include/small/cert_framework_define.h similarity index 86% rename from cert_mgr_service/framework/include/cert_framework_define.h rename to cert_mgr_service/framework/include/small/cert_framework_define.h index d927625..62cf1cc 100644 --- a/cert_mgr_service/framework/include/cert_framework_define.h +++ b/cert_mgr_service/framework/include/small/cert_framework_define.h @@ -15,7 +15,7 @@ #ifndef CERT_FRAMEWORK_DEFINE_H #define CERT_FRAMEWORK_DEFINE_H -#include +#include "cert_mgr_type.h" #ifdef __cplusplus #if __cplusplus @@ -34,12 +34,6 @@ typedef enum { CERT_FRAMEWORK_MSG_MAX } CertFrameworkFuncID; -typedef struct { - int32_t authResult; - int32_t softwareResult; - char *ticket; -} CertResultInfo; - typedef struct { int32_t result; CertResultInfo *certResultInfo; diff --git a/cert_mgr_service/framework/src/mini/cert_manager_interface.c b/cert_mgr_service/framework/src/mini/cert_manager_interface.c index e137f5a..f7fba98 100644 --- a/cert_mgr_service/framework/src/mini/cert_manager_interface.c +++ b/cert_mgr_service/framework/src/mini/cert_manager_interface.c @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include #include "cmsis_os2.h" #include "ohos_init.h" diff --git a/cert_mgr_service/framework/src/cert_framework_client.c b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c similarity index 79% rename from cert_mgr_service/framework/src/cert_framework_client.c rename to cert_mgr_service/framework/src/small/cert_framework_client_proxy.c index 5cbd1a5..cbd74c6 100644 --- a/cert_mgr_service/framework/src/cert_framework_client.c +++ b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c @@ -12,20 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_framework_client.h" -#include "cert_mgr_log.h" +#include +#include +#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include -#include -#include +#include + +#include "cert_mgr_log.h" +#include "cert_framework_define.h" +#include "cert_manager_interface.h" typedef struct { INHERIT_CLIENT_IPROXY; @@ -43,23 +45,23 @@ static int32_t ReadCertResultInfo(IpcIo *reply, CertResultInfo **certStatus) { if ((certStatus == NULL) || (*certStatus == NULL) || (reply == NULL)) { HILOGE("[ReadCertResultInfo] Invalid parameter."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } CertResultInfo *certResult = *certStatus; if (!ReadInt32(reply, (int32_t *)&certResult->authResult) || !ReadInt32(reply, (int32_t *)&certResult->softwareResult)) { HILOGE("[ReadCertResultInfo] Failed to ReadInt32."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } HILOGD("[ReadCertResultInfo] authResult:%d, softwareResult:%d", certResult->authResult, certResult->softwareResult); size_t ticketLen = 0; certResult->ticket = (char *)ReadString(reply, &ticketLen); if ((certResult->ticket == NULL) || (ticketLen == 0)) { HILOGE("[ReadCertResultInfo] Failed to ReadString."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } HILOGD("[ReadCertResultInfo] ticketLen:%d, ticket:%s", ticketLen, certResult->ticket); - return EC_SUCCESS; + return CERTMANAGER_SUCCESS; } static int CertClientQueryStatusCb(void *owner, int code, IpcIo *reply) @@ -67,7 +69,7 @@ static int CertClientQueryStatusCb(void *owner, int code, IpcIo *reply) HILOGE("[CertClientQueryStatusCb] Begin."); if ((owner == NULL) || (reply == NULL)) { HILOGE("[CertClientQueryStatusCb] owner or reply is nullptr."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } int32_t ret = 0; @@ -75,11 +77,11 @@ static int CertClientQueryStatusCb(void *owner, int code, IpcIo *reply) if (!ReadInt32(reply, &respInfo->result)) { HILOGE("[CertClientQueryStatusCb] Failed to ReadInt32."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } - if (respInfo->result != EC_SUCCESS) { + if (respInfo->result != CERTMANAGER_SUCCESS) { HILOGE("[CertClientQueryStatusCb] Failed to QueryStatus, result:%d.", respInfo->result); - return EC_FAILURE; + return CERTMANAGER_FAIL; } ret = ReadCertResultInfo(reply, &respInfo->certResultInfo); HILOGD("[CertClientQueryStatusCb] End code:%d.", code); @@ -89,37 +91,37 @@ static int CertClientQueryStatusCb(void *owner, int code, IpcIo *reply) static int32_t StartProc(IUnknown *iUnknown) { if (iUnknown == NULL) { - return EC_FAILURE; + return CERTMANAGER_FAIL; } CertmgrClientProxy *proxy = (CertmgrClientProxy *)iUnknown; int32_t ret = proxy->Invoke((IClientProxy *)proxy, CERT_FRAMEWORK_MSG_PROC, NULL, NULL, NULL); HILOGD("[StartProc] Invoke funcId = %d, ret = %d.", CERT_FRAMEWORK_MSG_PROC, ret); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[StartProc] Invoke failed."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } - return EC_SUCCESS; + return CERTMANAGER_SUCCESS; } static int32_t QueryStatus(IUnknown *iUnknown, CertResultInfo *certResultInfo) { if (iUnknown == NULL) { - return EC_FAILURE; + return CERTMANAGER_FAIL; } ServiceRspMsg reply = {0}; reply.certResultInfo = certResultInfo; CertmgrClientProxy *proxy = (CertmgrClientProxy *)iUnknown; int32_t ret = proxy->Invoke((IClientProxy *)proxy, CERT_FRAMEWORK_MSG_QUERY, NULL, &reply, CertClientQueryStatusCb); HILOGD("[QueryStatus] Invoke funcId = %d, ret = %d.", CERT_FRAMEWORK_MSG_QUERY, ret); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[QueryStatus] Invoke failed."); - return EC_FAILURE; + return CERTMANAGER_FAIL; } - if (reply.result != EC_SUCCESS) { + if (reply.result != CERTMANAGER_SUCCESS) { HILOGE("[QueryStatus] Service return failed, result = %d", reply.result); - return EC_FAILURE; + return CERTMANAGER_FAIL; } - return EC_SUCCESS; + return CERTMANAGER_SUCCESS; } static void *CreateClient(const char *service, const char *feature, uint32 size) @@ -157,48 +159,48 @@ static void DestroyClient(const char *service, const char *feature, void *iproxy static int32_t ModuleSamgrInitialize(void) { int32_t ret = (int32_t)SAMGR_RegisterFactory(CERTMGR_SERVICE, CERTMGR_FEATURE, CreateClient, DestroyClient); - if (ret != EC_SUCCESS) { - return EC_FAILURE; + if (ret != CERTMANAGER_SUCCESS) { + return CERTMANAGER_FAIL; } - return EC_SUCCESS; + return CERTMANAGER_SUCCESS; } static int32_t GetModuleClientApi(void) { IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(CERTMGR_SERVICE, CERTMGR_FEATURE); if (iUnknown == NULL) { - return EC_FAILURE; + return CERTMANAGER_FAIL; } int32_t ret = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&g_clientProxy); - if (ret != EC_SUCCESS || g_clientProxy == NULL) { - return EC_FAILURE; + if (ret != CERTMANAGER_SUCCESS || g_clientProxy == NULL) { + return CERTMANAGER_FAIL; } - return EC_SUCCESS; + return CERTMANAGER_SUCCESS; } int32_t StartCertTask(void) { HILOGD("[StartCertTask] Begin."); int32_t ret = ModuleSamgrInitialize(); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[StartCertTask] Failed to Initialize!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } ret = GetModuleClientApi(); - if ((ret != EC_SUCCESS) || (g_clientProxy == NULL)) { + if ((ret != CERTMANAGER_SUCCESS) || (g_clientProxy == NULL)) { HILOGE("[StartCertTask] Get failed!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } if (g_clientProxy->StartProc == NULL) { HILOGE("[StartCertTask] Interface not found!"); (void)g_clientProxy->Release((IUnknown *)g_clientProxy); - return EC_FAILURE; + return CERTMANAGER_FAIL; } ret = g_clientProxy->StartProc((IUnknown *)g_clientProxy); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[StartCertTask] Interface execution failed!"); } (void)g_clientProxy->Release((IUnknown *)g_clientProxy); @@ -210,29 +212,29 @@ int32_t GetCertStatus(CertResultInfo *certResultInfo) { HILOGD("[GetCertStatus] Begin."); if (certResultInfo == NULL) { - return EC_FAILURE; + return CERTMANAGER_FAIL; } int32_t ret = ModuleSamgrInitialize(); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[GetCertStatus] Failed to Initialize!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } ret = GetModuleClientApi(); - if ((ret != EC_SUCCESS) || (g_clientProxy == NULL)) { + if ((ret != CERTMANAGER_SUCCESS) || (g_clientProxy == NULL)) { HILOGE("[GetCertStatus] Get failed!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } if (g_clientProxy->QueryStatus == NULL) { HILOGE("[GetCertStatus] Interface not found!"); (void)g_clientProxy->Release((IUnknown *)g_clientProxy); - return EC_FAILURE; + return CERTMANAGER_FAIL; } ret = g_clientProxy->QueryStatus((IUnknown *)g_clientProxy, certResultInfo); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[GetCertStatus] Interface execution failed!"); } (void)g_clientProxy->Release((IUnknown *)g_clientProxy); diff --git a/cert_mgr_service/framework/src/cert_framework_feature.c b/cert_mgr_service/framework/src/small/cert_framework_feature.c similarity index 88% rename from cert_mgr_service/framework/src/cert_framework_feature.c rename to cert_mgr_service/framework/src/small/cert_framework_feature.c index 7edfc59..402dcfb 100644 --- a/cert_mgr_service/framework/src/cert_framework_feature.c +++ b/cert_mgr_service/framework/src/small/cert_framework_feature.c @@ -12,21 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_framework_define.h" -#include "cert_entry.h" -#include "cert_mgr_log.h" -#include -#include -#include #include #include #include +#include +#include +#include #include #include #include #include +#include "cert_mgr_log.h" +#include "cert_framework_define.h" +#include "cert_entry.h" + typedef struct { INHERIT_SERVER_IPROXY; } CertFrameworkApi; @@ -90,32 +91,32 @@ static int32_t WriteCertResultInfo(IpcIo *reply, int32_t authResult, int32_t sof { if (reply == NULL) { HILOGE("[WriteCertResultInfo] reply is null!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } if (ticket == NULL) { HILOGE("[WriteCertResultInfo] ticket is NULL!"); - if (!WriteInt32(reply, EC_FAILURE)) { + if (!WriteInt32(reply, CERTMANAGER_FAIL)) { HILOGE("[WriteCertResultInfo] Write ret fail!"); } - return EC_FAILURE; + return CERTMANAGER_FAIL; } - if (!WriteInt32(reply, EC_SUCCESS) || !WriteInt32(reply, authResult) || + if (!WriteInt32(reply, CERTMANAGER_SUCCESS) || !WriteInt32(reply, authResult) || !WriteInt32(reply, softwareResult) || !WriteString(reply, ticket)) { HILOGE("[WriteCertResultInfo] Write Result fail!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } HILOGD("[WriteCertResultInfo] Success! authResult=%d, softwareResult=%d, ticket=%s", authResult, softwareResult, ticket); - return EC_SUCCESS; + return CERTMANAGER_SUCCESS; } static int32_t CertFeatureQueryCert(IpcIo *reply) { if (reply == NULL) { HILOGE("[CertFeatureQueryCert] reply is null!"); - return EC_FAILURE; + return CERTMANAGER_FAIL; } int32_t authResult = -1; @@ -123,12 +124,12 @@ static int32_t CertFeatureQueryCert(IpcIo *reply) char *ticket = ""; int32_t ret = QueryCert(&authResult, &softwareResult, &ticket); - if (ret != EC_SUCCESS) { + if (ret != CERTMANAGER_SUCCESS) { HILOGE("[CertFeatureQueryCert] Query status fail!"); if (!WriteInt32(reply, ret)) { HILOGE("[CertFeatureQueryCert] Write ret fail!"); } - return EC_FAILURE; + return CERTMANAGER_FAIL; } ret = WriteCertResultInfo(reply, authResult, softwareResult, ticket); @@ -140,9 +141,9 @@ static int32_t Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req (void)origin; (void)req; if (iProxy == NULL) { - return EC_FAILURE; + return CERTMANAGER_FAIL; } - int32_t ret = EC_SUCCESS; + int32_t ret = CERTMANAGER_SUCCESS; HILOGI("[FEATURE Invoke] funcId:%d", funcId); switch (funcId) { case CERT_FRAMEWORK_MSG_PROC: diff --git a/cert_mgr_service/framework/src/cert_framework_server.c b/cert_mgr_service/framework/src/small/cert_framework_server.c similarity index 96% rename from cert_mgr_service/framework/src/cert_framework_server.c rename to cert_mgr_service/framework/src/small/cert_framework_server.c index 54fa460..c10516e 100644 --- a/cert_mgr_service/framework/src/cert_framework_server.c +++ b/cert_mgr_service/framework/src/small/cert_framework_server.c @@ -12,15 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_framework_define.h" -#include "cert_mgr_log.h" -#include -#include #include +#include +#include #include #include +#include "cert_mgr_log.h" +#include "cert_framework_define.h" + typedef struct { INHERIT_SERVICE; Identity identity; diff --git a/cert_mgr_service/framework/src/cert_framework_service.c b/cert_mgr_service/framework/src/small/cert_framework_service.c similarity index 96% rename from cert_mgr_service/framework/src/cert_framework_service.c rename to cert_mgr_service/framework/src/small/cert_framework_service.c index f328aea..cc72f59 100644 --- a/cert_mgr_service/framework/src/cert_framework_service.c +++ b/cert_mgr_service/framework/src/small/cert_framework_service.c @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_mgr_log.h" -#include -#include #include +#include +#include + +#include "cert_mgr_log.h" int main(void) { diff --git a/cert_mgr_service/framework/include/mini/cert_manager_interface.h b/cert_mgr_service/interfaces/include/cert_manager_interface.h similarity index 79% rename from cert_mgr_service/framework/include/mini/cert_manager_interface.h rename to cert_mgr_service/interfaces/include/cert_manager_interface.h index 51d6ef9..da0328e 100644 --- a/cert_mgr_service/framework/include/mini/cert_manager_interface.h +++ b/cert_mgr_service/interfaces/include/cert_manager_interface.h @@ -15,7 +15,7 @@ #ifndef CERT_MANAGER_INTERFACE_H #define CERT_MANAGER_INTERFACE_H -#include +#include "cert_mgr_type.h" #ifdef __cplusplus #if __cplusplus @@ -23,16 +23,6 @@ extern "C" { #endif #endif /* __cplusplus */ -#define CERTMANAGER_FAIL (-1) - -#define CERTMANAGER_SUCCESS 0 - -typedef struct { - int32_t authResult; - int32_t softwareResult; - char* ticket; -} CertResultInfo; - int32_t StartCertTask(void); int32_t GetCertStatus(CertResultInfo* certResultInfo); diff --git a/cert_mgr_service/services/core/cert/cert_service_auth.c b/cert_mgr_service/services/core/cert/cert_service_auth.c index 010c9f3..832e6bc 100644 --- a/cert_mgr_service/services/core/cert/cert_service_auth.c +++ b/cert_mgr_service/services/core/cert/cert_service_auth.c @@ -695,7 +695,7 @@ int32_t GenAuthMsg(ChallengeResult* challengeResult, DevicePacket** devPacket) int32_t ret = PackProductInfo(&devicePacket->productInfo); if (ret != CERT_OK) { CERT_LOG_ERROR("[GenAuthMsg] Pack ProductInfo failed."); - DestroyDevicePacket(&devicePacket); + FREE_DEVICE_PACKET(devicePacket); return CERT_ERR; } *devPacket = devicePacket; diff --git a/cert_mgr_service/services/core/cert/cert_service_challenge.c b/cert_mgr_service/services/core/cert/cert_service_challenge.c index 6c6ad50..109565b 100644 --- a/cert_mgr_service/services/core/cert/cert_service_challenge.c +++ b/cert_mgr_service/services/core/cert/cert_service_challenge.c @@ -128,7 +128,7 @@ static int32_t SetChallenge(ChallengeResult* challengeResult, CERT_ACTION_TYPE a char* respMsg = NULL; ret = SendChallMsg(reqMsg, &respMsg, actionType); - DestroyDevicePacket(&reqMsg); + FREE_DEVICE_PACKET(reqMsg); if (ret != CERT_OK) { CERT_LOG_ERROR("[SetChallenge] Send Challenge Msg failed"); return ret; diff --git a/cert_mgr_service/services/core/dfx/cert_dfx.c b/cert_mgr_service/services/core/dfx/cert_dfx.c index 8fdeb4e..340040d 100644 --- a/cert_mgr_service/services/core/dfx/cert_dfx.c +++ b/cert_mgr_service/services/core/dfx/cert_dfx.c @@ -71,6 +71,12 @@ void PrintDevicePacket(DevicePacket* devicePacket) } else { CERT_LOG_INFO("randomUuid = %s;", devicePacket->randomUuid); } + + if (devicePacket->kitinfo == NULL) { + CERT_LOG_WARN("kitinfo = null;"); + } else { + CERT_LOG_INFO("kitinfo = %s;", devicePacket->kitinfo); + } PrintDeviceTokenInfo(&(devicePacket->tokenInfo)); PrintDeviceProductInfo(&(devicePacket->productInfo)); CERT_LOG_INFO("----------------------------"); diff --git a/cert_mgr_service/services/core/include/cert_type.h b/cert_mgr_service/services/core/include/cert_type.h index 9273898..a49f7c5 100644 --- a/cert_mgr_service/services/core/include/cert_type.h +++ b/cert_mgr_service/services/core/include/cert_type.h @@ -148,6 +148,7 @@ typedef struct DevicePacket { char *randomUuid; // uuid的长度 DeviceTokenInfo tokenInfo; DeviceProductInfo productInfo; + char *kitinfo; /* 可以重新定义一个新结构,然后做成链表 */ } DevicePacket; typedef enum { diff --git a/cert_mgr_service/services/core/network/cert_network.c b/cert_mgr_service/services/core/network/cert_network.c index 8e80833..1dd59c8 100644 --- a/cert_mgr_service/services/core/network/cert_network.c +++ b/cert_mgr_service/services/core/network/cert_network.c @@ -115,6 +115,7 @@ DevicePacket* CreateDevicePacket(void) devicePacket->productInfo.displayVersion = NULL; devicePacket->productInfo.rootHash = NULL; devicePacket->productInfo.patchTag = NULL; + devicePacket->kitinfo = NULL; return devicePacket; } @@ -140,6 +141,7 @@ void DestroyDevicePacket(DevicePacket** devPacket) CERT_MEM_FREE(devicePacket->productInfo.displayVersion); CERT_MEM_FREE(devicePacket->productInfo.rootHash); CERT_MEM_FREE(devicePacket->productInfo.patchTag); + CERT_MEM_FREE(devicePacket->kitinfo); CERT_MEM_FREE(*devPacket); } diff --git a/cert_mgr_service/test/startup/BUILD.gn b/cert_mgr_service/test/startup/BUILD.gn new file mode 100644 index 0000000..91c72b7 --- /dev/null +++ b/cert_mgr_service/test/startup/BUILD.gn @@ -0,0 +1,52 @@ + +# 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. + +import("//build/lite/config/component/lite_component.gni") +import("//base/cert_mgr_service/build/certconfig.gni") + +#L1 client bin +executable("cert_framework_client") { + sources = [ + "cert_framework_client_start.c", + ] + + cflags = [ + "-ftrapv", + "-Werror", + "-Wextra", + "-Wshadow", + "-fstack-protector-all", + "-D_FORTIFY_SOURCE=2", + "-Wformat=2", + "-Wfloat-equal", + "-Wdate-time", + ] + cflags_cc = cflags + + ldflags = [ "-pthread", ] + if (board_name != "omap_se") { + ldflags += [ "-Wl,-z,relro,-z,now", "-s" ] + } + + include_dirs = [ + "${certmanager_path}/common/include", + "${certmanager_path}/interfaces/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", + ] + + deps = [ + "${certmanager_path}/framework:certclient", + "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + ] +} diff --git a/cert_mgr_service/framework/src/cert_framework_client_start.c b/cert_mgr_service/test/startup/cert_framework_client_start.c similarity index 89% rename from cert_mgr_service/framework/src/cert_framework_client_start.c rename to cert_mgr_service/test/startup/cert_framework_client_start.c index eba19cc..cdad720 100644 --- a/cert_mgr_service/framework/src/cert_framework_client_start.c +++ b/cert_mgr_service/test/startup/cert_framework_client_start.c @@ -12,13 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_framework_client.h" -#include "cert_mgr_log.h" #include #include #include +#include "cert_mgr_type.h" +#include "cert_mgr_log.h" +#include "cert_manager_interface.h" + int main(void) { int32_t ret = StartCertTask(); @@ -29,7 +31,7 @@ int main(void) certResultInfo.ticket = NULL; ret = GetCertStatus(&certResultInfo); - if (ret != 0) { + if (ret != CERTMANAGER_SUCCESS) { HILOGI("[CLIENT MAIN] wrong"); } -- Gitee From bd29eab423ff6e0f88cbe3c3edf8a1cd5a78a791 Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Mon, 19 Sep 2022 15:30:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 +++++++++---------- cert_mgr_service/BUILD.gn | 4 ---- .../src/small/cert_framework_client_proxy.c | 3 +++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f6e8ed5..c630a01 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,15 @@ Open Harmony授权验证平台开发分支 | | certconfig.gni(编译目录等公共配置) | common(公共基础能力) | | include - | | | cert_mgr_log.h - | | | cert_mgr_type.h + | | | ***cert_mgr_log.h + | | | ***cert_mgr_type.h | framework(SA启动框架) | | src | | include | | BUILD.gn | interfaces(对外接口) | | include - | | | cert_manager_interface.h + | | | ***cert_manager_interface.h | services(服务主体和业务逻辑代码) | | core(业务逻辑代码,暂时放在该目录) | | | adapter @@ -32,14 +32,14 @@ Open Harmony授权验证平台开发分支 | | | security | | | utils | | | BUILD.gn - | | | cert_entry.c - | | | cert_entry.h + | | | ***cert_entry.c + | | | ***cert_entry.h | test(测试用例) - | | data(测试用例数据) - | | startup(L1测试启动模块) - | | unittest(测试模块) - | BUILD.gn(编译脚本) - | bundle.json(编译描述文件) + | | data(测试用例数据) + | | startup(L1测试启动模块) + | | unittest(测试模块) + | BUILD.gn(组件编译脚本) + | bundle.json(子系统编译描述文件) #### 安装教程 diff --git a/cert_mgr_service/BUILD.gn b/cert_mgr_service/BUILD.gn index 885d7af..4117b99 100644 --- a/cert_mgr_service/BUILD.gn +++ b/cert_mgr_service/BUILD.gn @@ -26,8 +26,4 @@ lite_component("cert_mgr_service") { "framework:cert_mgr_sdk", ] } - - features += [ - #"services/oem_adapter:cert_mgr_oem_adapter", - ] } diff --git a/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c index cbd74c6..7dad0a3 100644 --- a/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c +++ b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c @@ -135,6 +135,9 @@ static void *CreateClient(const char *service, const char *feature, uint32 size) } (void)memset_s(client, len, 0, len); CertmgrClientEntry *entry = (CertmgrClientEntry *)&client[size]; + if (entry == NULL) { + return NULL; + } entry->ver = ((uint16)SERVER_PROXY_VER | (uint16)DEFAULT_VERSION); entry->ref = 1; entry->iUnknown.QueryInterface = IUNKNOWN_QueryInterface; -- Gitee From c1ddfbb9d3874c8971567bdef88a74ee18820b2f Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Mon, 19 Sep 2022 17:49:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9L0=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/src/mini/cert_manager_interface.c | 2 -- .../framework/src/small/cert_framework_client_proxy.c | 10 +++++++++- cert_mgr_service/services/core/cert_entry.h | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cert_mgr_service/framework/src/mini/cert_manager_interface.c b/cert_mgr_service/framework/src/mini/cert_manager_interface.c index f7fba98..25fe5db 100644 --- a/cert_mgr_service/framework/src/mini/cert_manager_interface.c +++ b/cert_mgr_service/framework/src/mini/cert_manager_interface.c @@ -14,8 +14,6 @@ */ #include -#include "cmsis_os2.h" -#include "ohos_init.h" #include "cert_manager_interface.h" #include "cert_entry.h" diff --git a/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c index 7dad0a3..3dfcb14 100644 --- a/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c +++ b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c @@ -94,6 +94,10 @@ static int32_t StartProc(IUnknown *iUnknown) return CERTMANAGER_FAIL; } CertmgrClientProxy *proxy = (CertmgrClientProxy *)iUnknown; + if (proxy == NULL) { + HILOGE("[StartProc] Get proxy failed."); + return CERTMANAGER_FAIL; + } int32_t ret = proxy->Invoke((IClientProxy *)proxy, CERT_FRAMEWORK_MSG_PROC, NULL, NULL, NULL); HILOGD("[StartProc] Invoke funcId = %d, ret = %d.", CERT_FRAMEWORK_MSG_PROC, ret); if (ret != CERTMANAGER_SUCCESS) { @@ -108,9 +112,13 @@ static int32_t QueryStatus(IUnknown *iUnknown, CertResultInfo *certResultInfo) if (iUnknown == NULL) { return CERTMANAGER_FAIL; } + CertmgrClientProxy *proxy = (CertmgrClientProxy *)iUnknown; + if (proxy == NULL) { + HILOGE("[QueryStatus] Get proxy failed."); + return CERTMANAGER_FAIL; + } ServiceRspMsg reply = {0}; reply.certResultInfo = certResultInfo; - CertmgrClientProxy *proxy = (CertmgrClientProxy *)iUnknown; int32_t ret = proxy->Invoke((IClientProxy *)proxy, CERT_FRAMEWORK_MSG_QUERY, NULL, &reply, CertClientQueryStatusCb); HILOGD("[QueryStatus] Invoke funcId = %d, ret = %d.", CERT_FRAMEWORK_MSG_QUERY, ret); if (ret != CERTMANAGER_SUCCESS) { diff --git a/cert_mgr_service/services/core/cert_entry.h b/cert_mgr_service/services/core/cert_entry.h index 2775a24..dc81e3f 100644 --- a/cert_mgr_service/services/core/cert_entry.h +++ b/cert_mgr_service/services/core/cert_entry.h @@ -17,6 +17,11 @@ #include +#ifdef __LITEOS_M__ +#include "cmsis_os2.h" +#include "ohos_init.h" +#endif + #ifdef __cplusplus #if __cplusplus extern "C" { -- Gitee