From 9acbf932b639d4600b5821381c355504d75ebe99 Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Fri, 16 Sep 2022 09:17:10 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=95=B4=E5=90=88L0L1=E5=AF=B9=E5=A4=96?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/include/cert_mgr_log.h | 2 +- .../common/include/cert_mgr_type.h | 28 +++++++ cert_mgr_service/framework/BUILD.gn | 56 +++++-------- .../{ => small}/cert_framework_client.h | 0 .../{ => small}/cert_framework_define.h | 12 +-- .../src/mini/cert_manager_interface.c | 8 +- .../cert_framework_client_proxy.c} | 80 ++++++++++--------- .../{ => small}/cert_framework_client_start.c | 4 +- .../src/{ => small}/cert_framework_feature.c | 22 ++--- .../src/{ => small}/cert_framework_server.c | 0 .../src/{ => small}/cert_framework_service.c | 0 .../include}/cert_manager_interface.h | 12 +-- .../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 | 3 + cert_mgr_service/test/startup/BUILD.gn | 52 ++++++++++++ .../startup/cert_framework_client_start.c | 52 ++++++++++++ 18 files changed, 228 insertions(+), 112 deletions(-) create mode 100644 cert_mgr_service/common/include/cert_mgr_type.h rename cert_mgr_service/framework/include/{ => small}/cert_framework_client.h (100%) rename cert_mgr_service/framework/include/{ => small}/cert_framework_define.h (85%) 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_client_start.c (89%) rename cert_mgr_service/framework/src/{ => small}/cert_framework_feature.c (88%) rename cert_mgr_service/framework/src/{ => small}/cert_framework_server.c (100%) rename cert_mgr_service/framework/src/{ => small}/cert_framework_service.c (100%) rename cert_mgr_service/{framework/include/mini => interfaces/include}/cert_manager_interface.h (79%) create mode 100644 cert_mgr_service/test/startup/BUILD.gn create mode 100644 cert_mgr_service/test/startup/cert_framework_client_start.c 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/small/cert_framework_client.h similarity index 100% rename from cert_mgr_service/framework/include/cert_framework_client.h rename to cert_mgr_service/framework/include/small/cert_framework_client.h 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 85% 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..5d7b2bf 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,11 +34,11 @@ typedef enum { CERT_FRAMEWORK_MSG_MAX } CertFrameworkFuncID; -typedef struct { - int32_t authResult; - int32_t softwareResult; - char *ticket; -} CertResultInfo; +// typedef struct { +// int32_t authResult; +// int32_t softwareResult; +// char *ticket; +// } CertResultInfo; typedef struct { int32_t result; 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..2006f48 100644 --- a/cert_mgr_service/framework/src/mini/cert_manager_interface.c +++ b/cert_mgr_service/framework/src/mini/cert_manager_interface.c @@ -12,14 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include - -#include "cmsis_os2.h" -#include "ohos_init.h" #include "cert_manager_interface.h" #include "cert_entry.h" +#include +#include "cmsis_os2.h" +#include "ohos_init.h" + int32_t StartCertTask(void) { osThreadAttr_t attr = {0}; 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..dfdc9f8 100644 --- a/cert_mgr_service/framework/src/cert_framework_client.c +++ b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c @@ -12,7 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_framework_client.h" +//#include "cert_framework_client.h" +#include "cert_manager_interface.h" +#include "cert_framework_define.h" #include "cert_mgr_log.h" #include @@ -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_client_start.c b/cert_mgr_service/framework/src/small/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/framework/src/small/cert_framework_client_start.c index eba19cc..9bfa770 100644 --- a/cert_mgr_service/framework/src/cert_framework_client_start.c +++ b/cert_mgr_service/framework/src/small/cert_framework_client_start.c @@ -12,7 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_framework_client.h" +//#include "cert_framework_client.h" +#include "cert_manager_interface.h" +#include "cert_framework_define.h" #include "cert_mgr_log.h" #include 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..57d0256 100644 --- a/cert_mgr_service/framework/src/cert_framework_feature.c +++ b/cert_mgr_service/framework/src/small/cert_framework_feature.c @@ -90,32 +90,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 +123,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 +140,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 100% rename from cert_mgr_service/framework/src/cert_framework_server.c rename to cert_mgr_service/framework/src/small/cert_framework_server.c 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 100% rename from cert_mgr_service/framework/src/cert_framework_service.c rename to cert_mgr_service/framework/src/small/cert_framework_service.c 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_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..2cf9bbd 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); } @@ -835,6 +837,7 @@ static int32_t RecvCoapMsg(const TLSSession* session, char **respData, size_t *r CERT_LOG_ERROR("[RecvCoapMsg] Mem malloc failed."); return ERR_NET_MEM_MALLOC; } + (void)memset_s(coapMessage, (coapMessageLen * sizeof(char)), 0, coapMessageLen * sizeof(char)); do { if (TLSRead(session, (unsigned char*)coapMessage, coapMessageLen) != 0) { CERT_LOG_ERROR("[RecvCoapMsg] Receive message fail, ret = %d.", ret); diff --git a/cert_mgr_service/test/startup/BUILD.gn b/cert_mgr_service/test/startup/BUILD.gn new file mode 100644 index 0000000..01a2d83 --- /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}/framework/include/small", + "${certmanager_path}/common/include", + "${certmanager_path}/interfaces/include", + ] + + deps = [ + "${certmanager_path}/framework:certclient", + "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", + ] +} diff --git a/cert_mgr_service/test/startup/cert_framework_client_start.c b/cert_mgr_service/test/startup/cert_framework_client_start.c new file mode 100644 index 0000000..9bfa770 --- /dev/null +++ b/cert_mgr_service/test/startup/cert_framework_client_start.c @@ -0,0 +1,52 @@ +/* + * 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. + */ +//#include "cert_framework_client.h" +#include "cert_manager_interface.h" +#include "cert_framework_define.h" +#include "cert_mgr_log.h" + +#include +#include +#include + +int main(void) +{ + int32_t ret = StartCertTask(); + if (ret == 0) { + sleep(5); + + CertResultInfo certResultInfo = { 0 }; + certResultInfo.ticket = NULL; + + ret = GetCertStatus(&certResultInfo); + if (ret != 0) { + HILOGI("[CLIENT MAIN] wrong"); + } + + if (certResultInfo.ticket != NULL) { + HILOGI("[CLIENT MAIN] auth:%d, software:%d, ticket:%s", + certResultInfo.authResult, certResultInfo.softwareResult, certResultInfo.ticket); + + free(certResultInfo.ticket); + certResultInfo.ticket = NULL; + } + } + HILOGI("[CLIENT MAIN] end"); + //(void)StartCertTask(); + while (1) { + pause(); + } + return 0; +} -- Gitee From c3c9b5ff9f9198a655b7394c99434a8c68eae1b7 Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Fri, 16 Sep 2022 09:24:29 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=88=A0=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/small/cert_framework_client.h | 38 -------------- .../include/small/cert_framework_define.h | 6 --- .../src/small/cert_framework_client_proxy.c | 1 - .../src/small/cert_framework_client_start.c | 52 ------------------- .../startup/cert_framework_client_start.c | 1 - 5 files changed, 98 deletions(-) delete mode 100644 cert_mgr_service/framework/include/small/cert_framework_client.h delete mode 100644 cert_mgr_service/framework/src/small/cert_framework_client_start.c diff --git a/cert_mgr_service/framework/include/small/cert_framework_client.h b/cert_mgr_service/framework/include/small/cert_framework_client.h deleted file mode 100644 index 1c77b02..0000000 --- a/cert_mgr_service/framework/include/small/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/small/cert_framework_define.h b/cert_mgr_service/framework/include/small/cert_framework_define.h index 5d7b2bf..62cf1cc 100644 --- a/cert_mgr_service/framework/include/small/cert_framework_define.h +++ b/cert_mgr_service/framework/include/small/cert_framework_define.h @@ -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/small/cert_framework_client_proxy.c b/cert_mgr_service/framework/src/small/cert_framework_client_proxy.c index dfdc9f8..7f51c33 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 @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -//#include "cert_framework_client.h" #include "cert_manager_interface.h" #include "cert_framework_define.h" #include "cert_mgr_log.h" diff --git a/cert_mgr_service/framework/src/small/cert_framework_client_start.c b/cert_mgr_service/framework/src/small/cert_framework_client_start.c deleted file mode 100644 index 9bfa770..0000000 --- a/cert_mgr_service/framework/src/small/cert_framework_client_start.c +++ /dev/null @@ -1,52 +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. - */ -//#include "cert_framework_client.h" -#include "cert_manager_interface.h" -#include "cert_framework_define.h" -#include "cert_mgr_log.h" - -#include -#include -#include - -int main(void) -{ - int32_t ret = StartCertTask(); - if (ret == 0) { - sleep(5); - - CertResultInfo certResultInfo = { 0 }; - certResultInfo.ticket = NULL; - - ret = GetCertStatus(&certResultInfo); - if (ret != 0) { - HILOGI("[CLIENT MAIN] wrong"); - } - - if (certResultInfo.ticket != NULL) { - HILOGI("[CLIENT MAIN] auth:%d, software:%d, ticket:%s", - certResultInfo.authResult, certResultInfo.softwareResult, certResultInfo.ticket); - - free(certResultInfo.ticket); - certResultInfo.ticket = NULL; - } - } - HILOGI("[CLIENT MAIN] end"); - //(void)StartCertTask(); - while (1) { - pause(); - } - return 0; -} diff --git a/cert_mgr_service/test/startup/cert_framework_client_start.c b/cert_mgr_service/test/startup/cert_framework_client_start.c index 9bfa770..5626ba4 100644 --- a/cert_mgr_service/test/startup/cert_framework_client_start.c +++ b/cert_mgr_service/test/startup/cert_framework_client_start.c @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -//#include "cert_framework_client.h" #include "cert_manager_interface.h" #include "cert_framework_define.h" #include "cert_mgr_log.h" -- Gitee From 44dc9443c63a11e8eeca3afaee1a9710c76b5acb Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Fri, 16 Sep 2022 10:35:32 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cert_mgr_service/services/core/network/cert_network.c | 1 - 1 file changed, 1 deletion(-) diff --git a/cert_mgr_service/services/core/network/cert_network.c b/cert_mgr_service/services/core/network/cert_network.c index 2cf9bbd..1dd59c8 100644 --- a/cert_mgr_service/services/core/network/cert_network.c +++ b/cert_mgr_service/services/core/network/cert_network.c @@ -837,7 +837,6 @@ static int32_t RecvCoapMsg(const TLSSession* session, char **respData, size_t *r CERT_LOG_ERROR("[RecvCoapMsg] Mem malloc failed."); return ERR_NET_MEM_MALLOC; } - (void)memset_s(coapMessage, (coapMessageLen * sizeof(char)), 0, coapMessageLen * sizeof(char)); do { if (TLSRead(session, (unsigned char*)coapMessage, coapMessageLen) != 0) { CERT_LOG_ERROR("[RecvCoapMsg] Receive message fail, ret = %d.", ret); -- Gitee From d3a1a429133ac636b33c2b4f40d6b2ad16d6c27c Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Fri, 16 Sep 2022 11:33:27 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cert_mgr_service/BUILD.gn | 2 +- cert_mgr_service/services/core/cert/cert_service_auth.c | 2 +- cert_mgr_service/test/startup/BUILD.gn | 4 ++-- cert_mgr_service/test/startup/cert_framework_client_start.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cert_mgr_service/BUILD.gn b/cert_mgr_service/BUILD.gn index c5ce338..84fbb19 100644 --- a/cert_mgr_service/BUILD.gn +++ b/cert_mgr_service/BUILD.gn @@ -17,7 +17,7 @@ lite_component("cert_mgr_service") { if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") { features += [ "framework:cert_framework_service", - "framework:cert_framework_client", + "test/startup:cert_framework_client" ] features += [ 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/test/startup/BUILD.gn b/cert_mgr_service/test/startup/BUILD.gn index 01a2d83..91c72b7 100644 --- a/cert_mgr_service/test/startup/BUILD.gn +++ b/cert_mgr_service/test/startup/BUILD.gn @@ -40,13 +40,13 @@ executable("cert_framework_client") { } include_dirs = [ - "${certmanager_path}/framework/include/small", "${certmanager_path}/common/include", "${certmanager_path}/interfaces/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", ] deps = [ "${certmanager_path}/framework:certclient", - "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", + "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", ] } diff --git a/cert_mgr_service/test/startup/cert_framework_client_start.c b/cert_mgr_service/test/startup/cert_framework_client_start.c index 5626ba4..0bf9ce3 100644 --- a/cert_mgr_service/test/startup/cert_framework_client_start.c +++ b/cert_mgr_service/test/startup/cert_framework_client_start.c @@ -13,7 +13,7 @@ * limitations under the License. */ #include "cert_manager_interface.h" -#include "cert_framework_define.h" +#include "cert_mgr_type.h" #include "cert_mgr_log.h" #include @@ -30,7 +30,7 @@ int main(void) certResultInfo.ticket = NULL; ret = GetCertStatus(&certResultInfo); - if (ret != 0) { + if (ret != CERTMANAGER_SUCCESS) { HILOGI("[CLIENT MAIN] wrong"); } -- Gitee From 397b9df8976ab59b62b94c85b399edb2698cf820 Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Fri, 16 Sep 2022 14:56:08 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=BC=95=E7=94=A8=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/mini/cert_manager_interface.c | 6 +++--- .../src/small/cert_framework_client_proxy.c | 19 ++++++++++--------- .../src/small/cert_framework_feature.c | 13 +++++++------ .../src/small/cert_framework_server.c | 9 +++++---- .../src/small/cert_framework_service.c | 7 ++++--- .../startup/cert_framework_client_start.c | 7 ++++--- 6 files changed, 33 insertions(+), 28 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 2006f48..344ac88 100644 --- a/cert_mgr_service/framework/src/mini/cert_manager_interface.c +++ b/cert_mgr_service/framework/src/mini/cert_manager_interface.c @@ -13,13 +13,13 @@ * limitations under the License. */ -#include "cert_manager_interface.h" -#include "cert_entry.h" - #include #include "cmsis_os2.h" #include "ohos_init.h" +#include "cert_entry.h" +#include "cert_manager_interface.h" + int32_t StartCertTask(void) { osThreadAttr_t attr = {0}; 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 7f51c33..cbd74c6 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 @@ -12,21 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_manager_interface.h" -#include "cert_framework_define.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; diff --git a/cert_mgr_service/framework/src/small/cert_framework_feature.c b/cert_mgr_service/framework/src/small/cert_framework_feature.c index 57d0256..402dcfb 100644 --- a/cert_mgr_service/framework/src/small/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; diff --git a/cert_mgr_service/framework/src/small/cert_framework_server.c b/cert_mgr_service/framework/src/small/cert_framework_server.c index 54fa460..c10516e 100644 --- a/cert_mgr_service/framework/src/small/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/small/cert_framework_service.c b/cert_mgr_service/framework/src/small/cert_framework_service.c index f328aea..cc72f59 100644 --- a/cert_mgr_service/framework/src/small/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/test/startup/cert_framework_client_start.c b/cert_mgr_service/test/startup/cert_framework_client_start.c index 0bf9ce3..cdad720 100644 --- a/cert_mgr_service/test/startup/cert_framework_client_start.c +++ b/cert_mgr_service/test/startup/cert_framework_client_start.c @@ -12,14 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "cert_manager_interface.h" -#include "cert_mgr_type.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(); -- Gitee From 0c273e8cb442861834643370b4289a08f82c8bd7 Mon Sep 17 00:00:00 2001 From: Kemin <541416002@qq.com> Date: Fri, 16 Sep 2022 14:58:20 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=BC=95=E7=94=A8=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cert_mgr_service/framework/src/mini/cert_manager_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 344ac88..f7fba98 100644 --- a/cert_mgr_service/framework/src/mini/cert_manager_interface.c +++ b/cert_mgr_service/framework/src/mini/cert_manager_interface.c @@ -17,8 +17,8 @@ #include "cmsis_os2.h" #include "ohos_init.h" -#include "cert_entry.h" #include "cert_manager_interface.h" +#include "cert_entry.h" int32_t StartCertTask(void) { -- Gitee