From 743a3812e5c15604210b0c031e12cbfefbef8c37 Mon Sep 17 00:00:00 2001 From: l00343967 Date: Mon, 28 Sep 2020 17:13:49 +0800 Subject: [PATCH] Description:Increase portability Reviewed-by:wanglechao Change-Id: Ia28bdf49434c72f36f77a66847f4947929c449b0 --- BUILD.gn | 7 +++-- include/app_common.h | 26 +---------------- include/app_verify_hal.h | 42 +++++++++++++++++++++++++++ products/default/app_verify_default.c | 23 +++++++++++++++ products/default/app_verify_default.h | 35 ++++++++++++++++++++++ products/ipcamera/BUILD.gn | 35 ++++++++++++++++++++++ products/ipcamera/app_verify_base.c | 21 ++++++++++++++ products/ipcamera/app_verify_base.h | 41 ++++++++++++++++++++++++++ src/app_file.c | 3 +- src/app_provision.c | 4 +-- src/app_verify_hal.c | 35 ++++++++++++++++++++++ 11 files changed, 241 insertions(+), 31 deletions(-) create mode 100644 include/app_verify_hal.h create mode 100644 products/default/app_verify_default.c create mode 100644 products/default/app_verify_default.h create mode 100644 products/ipcamera/BUILD.gn create mode 100644 products/ipcamera/app_verify_base.c create mode 100644 products/ipcamera/app_verify_base.h create mode 100644 src/app_verify_hal.c diff --git a/BUILD.gn b/BUILD.gn index 4b13374..32ade2d 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,9 +15,10 @@ config("app_verify_config") { include_dirs = [ "include", "//third_party/bounds_checking_function/include", - "//base/startup/interfaces/kits/syspara_lite", "//third_party/cJSON", "//base/security/interfaces/innerkits/app_verify", + "//base/security/frameworks/app_verify/products/default", + "//base/security/frameworks/app_verify/products/ipcamera", ] defines = [ "PARSE_PEM_FORMAT_SIGNED_DATA" @@ -36,13 +37,13 @@ shared_library("verify") { "src/app_centraldirectory.c", "src/app_file.c", "src/app_verify_hap.c", + "src/app_verify_hal.c", ] configs += [ ":app_verify_config" ] public_deps = [ "//third_party/bounds_checking_function:libsec_shared", "//third_party/mbedtls:mbedtls_shared", "//third_party/cJSON:cjson_shared", - "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", - "//base/startup/frameworks/syspara_lite/parameter:parameter", + "//base/security/frameworks/app_verify/products/ipcamera:verify_base", ] } diff --git a/include/app_common.h b/include/app_common.h index d2d4ac8..ecddba0 100755 --- a/include/app_common.h +++ b/include/app_common.h @@ -16,8 +16,8 @@ #ifndef SECURITY_APP_COMMON_H #define SECURITY_APP_COMMON_H +#include "app_verify_base.h" #include "app_verify_pub.h" -#include "log.h" #ifdef __cplusplus #if __cplusplus @@ -32,30 +32,6 @@ extern "C" { #define MAX_MALLOC_SIZE 0x100000 /* 1M */ #define MAX_HASH_SIZE 64 -#define LOG_INFO(fmt, args...) HILOG_INFO(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) -#define LOG_DEBUG(fmt, args...) HILOG_DEBUG(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) -#define LOG_WARN(fmt, args...) HILOG_WARN(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) -#define LOG_ERROR(fmt, args...) HILOG_ERROR(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) -#define LOG_PRINT_STR(fmt, args...) HILOG_INFO(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) - -typedef struct TagVMemStats { - void *buf; - int len; - int state; - const char *fileName; - int line; - struct TagVMemStats *next; -} AppVMemStats; - -typedef struct { - AppVMemStats *head; - int totalMem; - int totalMallocCnt; - int totalFree; - int totalFreeCnt; - int maxMemUsed; -} MemStastics; - #define P_NULL_RETURN_WTTH_LOG(v) \ do { \ if ((v) == NULL) { \ diff --git a/include/app_verify_hal.h b/include/app_verify_hal.h new file mode 100644 index 0000000..f9e0eac --- /dev/null +++ b/include/app_verify_hal.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 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 SECURITY_APP_VERIFY_HAL_H +#define SECURITY_APP_VERIFY_HAL_H + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +typedef char* (*GetDeviceUdid)(); + +typedef struct { + GetDeviceUdid devUdidFunc; +} ProductDiff; + +void RegistHalFunc(); +char *GetDevUdid(); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff --git a/products/default/app_verify_default.c b/products/default/app_verify_default.c new file mode 100644 index 0000000..f49d80c --- /dev/null +++ b/products/default/app_verify_default.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2020 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 "app_verify_default.h" +#include "parameter.h" + +void RegistBaseDefaultFunc(ProductDiff *productFunc) +{ + productFunc->devUdidFunc = GetSerial; +} + diff --git a/products/default/app_verify_default.h b/products/default/app_verify_default.h new file mode 100644 index 0000000..f0ad4c9 --- /dev/null +++ b/products/default/app_verify_default.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 SECURITY_APP_VERIFY_DEFAULT_H +#define SECURITY_APP_VERIFY_DEFAULT_H +#include +#include "app_verify_hal.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +void RegistBaseDefaultFunc(ProductDiff *productFunc); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif \ No newline at end of file diff --git a/products/ipcamera/BUILD.gn b/products/ipcamera/BUILD.gn new file mode 100644 index 0000000..1e9d76b --- /dev/null +++ b/products/ipcamera/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2020 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. + +config("verify_base_config") { + include_dirs = [ + "//base/security/frameworks/app_verify/include", + "//base/startup/interfaces/kits/syspara_lite", + "//base/security/frameworks/app_verify/products/ipcamera", + ] + cflags = [ + "-Wall", + ] +} + +shared_library("verify_base") { + sources = [ + "app_verify_base.c", + "../default/app_verify_default.c", + ] + configs += [ ":verify_base_config" ] + public_deps = [ + "//base/startup/frameworks/syspara_lite/parameter:parameter", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + ] +} diff --git a/products/ipcamera/app_verify_base.c b/products/ipcamera/app_verify_base.c new file mode 100644 index 0000000..d096c4a --- /dev/null +++ b/products/ipcamera/app_verify_base.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 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 "app_verify_base.h" + +void RegistProductFunc(ProductDiff *productFunc) +{ +} + diff --git a/products/ipcamera/app_verify_base.h b/products/ipcamera/app_verify_base.h new file mode 100644 index 0000000..6ada1df --- /dev/null +++ b/products/ipcamera/app_verify_base.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 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 SECURITY_APP_VERIFY_BASE_H +#define SECURITY_APP_VERIFY_BASE_H +#include +#include "app_verify_hal.h" +#include "log.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +#define LOG_INFO(fmt, args...) HILOG_INFO(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) +#define LOG_DEBUG(fmt, args...) HILOG_DEBUG(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) +#define LOG_WARN(fmt, args...) HILOG_WARN(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) +#define LOG_ERROR(fmt, args...) HILOG_ERROR(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) +#define LOG_PRINT_STR(fmt, args...) HILOG_INFO(LOG_CORE, "["__FILE__":%d] :"fmt, __LINE__, ##args) + +void RegistProductFunc(ProductDiff *productFunc); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif \ No newline at end of file diff --git a/src/app_file.c b/src/app_file.c index e096521..50cc18d 100755 --- a/src/app_file.c +++ b/src/app_file.c @@ -32,6 +32,7 @@ int InitVerify(FileRead *file, const char *filePath, int *handle) LOG_ERROR("invalid input"); return V_ERR_FILE_OPEN; } + RegistHalFunc(); char *path = APPV_MALLOC(PATH_MAX + 1); if (path == NULL) { LOG_ERROR("path malloc error"); @@ -80,7 +81,7 @@ int HapMMap(int bufCapacity, int offset, MmapInfo *mmapInfo, const FileRead *fil mmapInfo->readMoreLen = (int)(offset - mmapInfo->mmapPosition); mmapInfo->mmapSize = bufCapacity + mmapInfo->readMoreLen; mmapInfo->mapAddr = (char*)(mmap(NULL, mmapInfo->mmapSize, PROT_READ, - MAP_SHARED | MAP_POPULATE, file->fp, mmapInfo->mmapPosition)); + MAP_SHARED, file->fp, mmapInfo->mmapPosition)); if (mmapInfo->mapAddr == MAP_FAILED) { LOG_ERROR("MAP_FAILED"); return MMAP_FAILED; diff --git a/src/app_provision.c b/src/app_provision.c index c936aa5..ba8e386 100755 --- a/src/app_provision.c +++ b/src/app_provision.c @@ -18,8 +18,8 @@ #include #include #include "app_common.h" +#include "app_verify_hal.h" #include "cJSON.h" -#include "parameter.h" #include "securec.h" static void ProfInit(ProfileProf *pf) @@ -358,7 +358,7 @@ static int VerifyUdid(const ProfileProf *pf) LOG_ERROR("udid num exceed maximum"); return V_ERR; } - char *udid = GetSerial(); + char *udid = GetDevUdid(); if (udid == NULL) { LOG_ERROR("udid is null"); return V_ERR; diff --git a/src/app_verify_hal.c b/src/app_verify_hal.c new file mode 100644 index 0000000..089c9b3 --- /dev/null +++ b/src/app_verify_hal.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 "app_verify_hal.h" +#include "app_verify_base.h" +#include "app_verify_default.h" + +static ProductDiff g_productDiffFunc; + +void RegistHalFunc() +{ + RegistBaseDefaultFunc(&g_productDiffFunc); + RegistProductFunc(&g_productDiffFunc); +} + +char *GetDevUdid() +{ + if (g_productDiffFunc.devUdidFunc == NULL) { + return NULL; + } + return g_productDiffFunc.devUdidFunc(); +} + -- Gitee