From d9319d430c0c8eea235d3e9ca39bc96a0a9cb61d Mon Sep 17 00:00:00 2001 From: wangxu43 Date: Wed, 19 Jan 2022 00:06:35 +0800 Subject: [PATCH 1/2] Update structure Signed-off-by: wangxu43 --- OAT.xml | 2 +- coauth.gni => auth_executor_mgr.gni | 4 +- bundle.json | 68 ++++++++++ common/BUILD.gn | 3 +- common/adaptor/inc/adaptor_algorithm.h | 10 +- common/adaptor/inc/adaptor_file.h | 8 -- common/adaptor/inc/adaptor_log.h | 17 +-- common/adaptor/inc/adaptor_memory.h | 8 -- common/adaptor/inc/adaptor_time.h | 12 +- common/adaptor/inc/file_operator.h | 10 +- common/adaptor/src/adaptor_algorithm.c | 7 +- common/adaptor/src/adaptor_memory.c | 1 - common/adaptor/src/adaptor_time.c | 4 +- common/adaptor/src/file_operator.c | 19 ++- common/bundle.json | 40 ++++++ common/coauth/inc/coauth.h | 12 +- common/coauth/inc/coauth_funcs.h | 8 -- common/coauth/inc/coauth_sign_centre.h | 14 +- common/coauth/inc/executor_message.h | 8 -- common/coauth/src/coauth.c | 12 +- common/coauth/src/coauth_funcs.c | 14 +- common/coauth/src/executor_message.c | 2 - common/common/inc/bitwise_operation.h | 16 +-- common/common/inc/buffer.h | 9 -- common/common/inc/defines.h | 8 -- common/common/inc/linked_list.h | 8 -- common/common/inc/tlv_base.h | 26 ++-- common/common/inc/tlv_wrapper.h | 62 ++++----- common/common/src/tlv_base.c | 16 +-- common/common/src/tlv_wrapper.c | 94 ++++++------- common/database/inc/idm_common.h | 17 +-- common/database/inc/idm_database.h | 20 +-- common/database/inc/idm_file_manager.h | 16 +-- common/database/src/idm_common.c | 2 +- common/database/src/idm_database.c | 41 +++--- common/database/src/idm_file_manager.c | 2 +- common/hal_sdk/coauth_interface.cpp | 52 ++++--- common/hal_sdk/userauth_interface.cpp | 35 +++-- common/hal_sdk/useriam_common.cpp | 26 +++- common/hal_sdk/useridm_interface.cpp | 128 ++++++++++++------ common/idm/inc/idm_session.h | 12 +- common/idm/inc/user_idm_funcs.h | 11 +- common/idm/src/idm_session.c | 6 +- common/idm/src/user_idm_funcs.c | 43 +++--- common/interface/coauth_interface.h | 4 - common/interface/userauth_interface.h | 14 +- common/interface/useriam_common.h | 8 +- common/interface/useridm_interface.h | 14 +- common/lock/inc/lock.h | 22 +++ .../src/adaptor_log.c => lock/src/lock.c} | 69 ++++------ common/ohos.build | 10 -- common/pool/inc/pool.h | 12 +- common/pool/src/pool.c | 10 +- common/user_auth/inc/auth_level.h | 14 +- common/user_auth/inc/context_manager.h | 16 +-- common/user_auth/inc/user_auth_funcs.h | 8 -- common/user_auth/inc/user_sign_centre.h | 14 +- common/user_auth/src/auth_level.c | 3 +- common/user_auth/src/context_manager.c | 5 +- common/user_auth/src/user_auth_funcs.c | 3 +- common/user_auth/src/user_sign_centre.c | 18 +-- .../kitsimpl/include/coauth_callback_proxy.h | 0 .../kitsimpl/include/coauth_callback_stub.h | 0 .../include/executor_callback_proxy.h | 0 .../kitsimpl/include/executor_callback_stub.h | 0 .../include/executor_messenger_proxy.h | 0 .../include/executor_messenger_stub.h | 0 .../kitsimpl/include/icoauth_callback.h | 0 .../kitsimpl/include/iexecutor_messenger.h | 0 frameworks/kitsimpl/include/iquery_callback.h | 0 .../kitsimpl/include/iset_prop_callback.h | 0 .../kitsimpl/include/query_callback_proxy.h | 0 .../kitsimpl/include/query_callback_stub.h | 0 .../include/set_prop_callback_proxy.h | 0 .../kitsimpl/include/set_prop_callback_stub.h | 0 .../kitsimpl/src/auth_executor_registry.cpp | 2 +- frameworks/kitsimpl/src/auth_info.cpp | 0 frameworks/kitsimpl/src/coauth.cpp | 2 +- .../kitsimpl/src/coauth_callback_proxy.cpp | 0 .../kitsimpl/src/coauth_callback_stub.cpp | 0 frameworks/kitsimpl/src/coauth_proxy.cpp | 21 +-- .../kitsimpl/src/executor_callback_proxy.cpp | 30 ++-- .../kitsimpl/src/executor_callback_stub.cpp | 16 ++- .../kitsimpl/src/executor_messenger_proxy.cpp | 0 .../kitsimpl/src/executor_messenger_stub.cpp | 0 .../kitsimpl/src/query_callback_proxy.cpp | 0 .../kitsimpl/src/query_callback_stub.cpp | 0 .../kitsimpl/src/set_prop_callback_proxy.cpp | 0 .../kitsimpl/src/set_prop_callback_stub.cpp | 0 interfaces/innerkits/BUILD.gn | 4 +- .../innerkits/include/auth_attributes.h | 0 interfaces/innerkits/include/auth_executor.h | 0 .../include/auth_executor_registry.h | 0 interfaces/innerkits/include/auth_info.h | 0 interfaces/innerkits/include/auth_message.h | 0 .../innerkits/include/coauth_callback.h | 0 .../innerkits/include/coauth_info_define.h | 0 .../innerkits/include/executor_callback.h | 0 .../innerkits/include/executor_messenger.h | 0 interfaces/innerkits/include/query_callback.h | 0 .../innerkits/include/set_prop_callback.h | 0 interfaces/innerkits/src/auth_attributes.cpp | 5 +- interfaces/innerkits/src/auth_executor.cpp | 0 interfaces/innerkits/src/auth_message.cpp | 0 ohos.build | 23 ---- sa_profile/{5203.xml => 923.xml} | 2 +- sa_profile/BUILD.gn | 8 +- sa_profile/useriam.cfg | 0 sa_profile/useriam.rc | 0 services/BUILD.gn | 8 +- services/src/auth_res_pool.cpp | 2 +- services/src/coauth_manager.cpp | 3 +- services/src/coauth_service.cpp | 4 +- services/src/coauth_stub.cpp | 9 +- test/BUILD.gn | 5 +- test/unittest/BUILD.gn | 8 +- test/unittest/include/coauth_test.h | 3 +- test/unittest/src/coauth_test.cpp | 0 utils/BUILD.gn | 2 +- 119 files changed, 651 insertions(+), 683 deletions(-) rename coauth.gni => auth_executor_mgr.gni (89%) create mode 100644 bundle.json create mode 100644 common/bundle.json create mode 100644 common/lock/inc/lock.h rename common/{adaptor/src/adaptor_log.c => lock/src/lock.c} (49%) delete mode 100644 common/ohos.build mode change 100644 => 100755 frameworks/kitsimpl/include/coauth_callback_proxy.h mode change 100644 => 100755 frameworks/kitsimpl/include/coauth_callback_stub.h mode change 100644 => 100755 frameworks/kitsimpl/include/executor_callback_proxy.h mode change 100644 => 100755 frameworks/kitsimpl/include/executor_callback_stub.h mode change 100644 => 100755 frameworks/kitsimpl/include/executor_messenger_proxy.h mode change 100644 => 100755 frameworks/kitsimpl/include/executor_messenger_stub.h mode change 100644 => 100755 frameworks/kitsimpl/include/icoauth_callback.h mode change 100644 => 100755 frameworks/kitsimpl/include/iexecutor_messenger.h mode change 100644 => 100755 frameworks/kitsimpl/include/iquery_callback.h mode change 100644 => 100755 frameworks/kitsimpl/include/iset_prop_callback.h mode change 100644 => 100755 frameworks/kitsimpl/include/query_callback_proxy.h mode change 100644 => 100755 frameworks/kitsimpl/include/query_callback_stub.h mode change 100644 => 100755 frameworks/kitsimpl/include/set_prop_callback_proxy.h mode change 100644 => 100755 frameworks/kitsimpl/include/set_prop_callback_stub.h mode change 100644 => 100755 frameworks/kitsimpl/src/auth_executor_registry.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/auth_info.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/coauth_callback_proxy.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/coauth_callback_stub.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/executor_callback_proxy.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/executor_callback_stub.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/executor_messenger_proxy.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/executor_messenger_stub.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/query_callback_proxy.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/query_callback_stub.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/set_prop_callback_proxy.cpp mode change 100644 => 100755 frameworks/kitsimpl/src/set_prop_callback_stub.cpp mode change 100644 => 100755 interfaces/innerkits/include/auth_attributes.h mode change 100644 => 100755 interfaces/innerkits/include/auth_executor.h mode change 100644 => 100755 interfaces/innerkits/include/auth_executor_registry.h mode change 100644 => 100755 interfaces/innerkits/include/auth_info.h mode change 100644 => 100755 interfaces/innerkits/include/auth_message.h mode change 100644 => 100755 interfaces/innerkits/include/coauth_callback.h mode change 100644 => 100755 interfaces/innerkits/include/coauth_info_define.h mode change 100644 => 100755 interfaces/innerkits/include/executor_callback.h mode change 100644 => 100755 interfaces/innerkits/include/executor_messenger.h mode change 100644 => 100755 interfaces/innerkits/include/query_callback.h mode change 100644 => 100755 interfaces/innerkits/include/set_prop_callback.h mode change 100644 => 100755 interfaces/innerkits/src/auth_attributes.cpp mode change 100644 => 100755 interfaces/innerkits/src/auth_executor.cpp mode change 100644 => 100755 interfaces/innerkits/src/auth_message.cpp delete mode 100755 ohos.build rename sa_profile/{5203.xml => 923.xml} (97%) mode change 100644 => 100755 sa_profile/useriam.cfg mode change 100644 => 100755 sa_profile/useriam.rc mode change 100644 => 100755 test/unittest/include/coauth_test.h mode change 100644 => 100755 test/unittest/src/coauth_test.cpp diff --git a/OAT.xml b/OAT.xml index 55211e7..131151b 100755 --- a/OAT.xml +++ b/OAT.xml @@ -18,7 +18,7 @@ - + diff --git a/coauth.gni b/auth_executor_mgr.gni similarity index 89% rename from coauth.gni rename to auth_executor_mgr.gni index c3fbfa7..284ff75 100755 --- a/coauth.gni +++ b/auth_executor_mgr.gni @@ -13,9 +13,9 @@ import("//build/ohos.gni") -coauth_native_part_name = "coauthmgr" +coauth_native_part_name = "auth_executor_mgr" -coauth_root_path = "//base/useriam/coauth/" +coauth_root_path = "//base/user_iam/auth_executor_mgr/" coauth_service_path = "${coauth_root_path}/services" diff --git a/bundle.json b/bundle.json new file mode 100644 index 0000000..5bc0b2e --- /dev/null +++ b/bundle.json @@ -0,0 +1,68 @@ +{ + "name": "@openharmony/auth_executor_mgr", + "version": "3.1.0", + "description": "Auth executor manager", + "homePage": "https://gitee.com/openharmony", + "author": {}, + "repository": "", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath" : "base/user_iam/auth_executor_mgr" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "auth_executor_mgr", + "subsystem": "useriam", + "adapted_system_type": [ "standard" ], + "syscap": ["SystemCapability.UserIAM.AuthExecutorMgr"], + "features": [], + "rom": "1024KB", + "ram": "2500KB", + "deps": { + "components": [ + "hiviewdfx_hilog_native", + "ipc", + "safwk", + "samgr_standard" + ], + "third_party": [ + "openssl" + ] + }, + "build": { + "sub_component": [ + "//base/user_iam/auth_executor_mgr/sa_profile:coauth_sa_profile", + "//base/user_iam/auth_executor_mgr/services:coauthservice", + "//base/user_iam/auth_executor_mgr/sa_profile:useriam.init" + ], + "inner_kits": [ + { + "type": "so", + "name": "//base/user_iam/auth_executor_mgr/interfaces/innerkits:coauth_framework", + "header": { + "header_files": [ + "auth_attributes.h", + "auth_executor.h", + "auth_executor_registry.h", + "auth_info.h", + "auth_message.h", + "co_auth.h", + "coauth_callback.h", + "coauth_info_define.h", + "executor_callback.h", + "executor_messenger.h", + "query_callback.h", + "set_prop_callback.h" + ], + "header_base": "//base/user_iam/auth_executor_mgr/interfaces/innerkits/include" + } + } + ], + "test": [ + "//base/user_iam/auth_executor_mgr/test:coauth_unittest_test" + ] + } + } + } diff --git a/common/BUILD.gn b/common/BUILD.gn index 0343e67..df0d01c 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -23,7 +23,6 @@ ohos_shared_library("useriam_common_lib") { sources = [ "adaptor/src/adaptor_algorithm.c", "adaptor/src/adaptor_file.c", - "adaptor/src/adaptor_log.c", "adaptor/src/adaptor_memory.c", "adaptor/src/adaptor_time.c", "adaptor/src/file_operator.c", @@ -47,6 +46,7 @@ ohos_shared_library("useriam_common_lib") { "hal_sdk/userauth_interface.cpp", "hal_sdk/useriam_common.cpp", "hal_sdk/useridm_interface.cpp", + "lock/src/lock.c", "idm/src/idm_session.c", "idm/src/user_idm_funcs.c", @@ -60,6 +60,7 @@ ohos_shared_library("useriam_common_lib") { ] include_dirs = [ + "lock/inc", "adaptor/inc", "coauth/inc", "database/inc", diff --git a/common/adaptor/inc/adaptor_algorithm.h b/common/adaptor/inc/adaptor_algorithm.h index 14e1893..bc6805d 100644 --- a/common/adaptor/inc/adaptor_algorithm.h +++ b/common/adaptor/inc/adaptor_algorithm.h @@ -20,10 +20,6 @@ #include #include "buffer.h" -#ifdef __cplusplus -extern "C" { -#endif - #define ED25519_FIX_SIGN_BUFFER_SIZE 64 typedef struct { @@ -33,7 +29,7 @@ typedef struct { bool IsEd25519KeyPairValid(const KeyPair *keyPair); void DestoryKeyPair(KeyPair *keyPair); -KeyPair *GenerateEd25519KeyPair(); +KeyPair *GenerateEd25519KeyPair(void); int32_t Ed25519Sign(const KeyPair *keyPair, const Buffer *data, Buffer **sign); int32_t Ed25519Verify(const Buffer *pubKey, const Buffer *data, const Buffer *sign); @@ -42,9 +38,5 @@ int32_t HmacSha512(const Buffer *hmacKey, const Buffer *data, Buffer **hmac); int32_t SecureRandom(uint8_t *buffer, uint32_t size); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/adaptor/inc/adaptor_file.h b/common/adaptor/inc/adaptor_file.h index 4c9a79b..bed5d5f 100644 --- a/common/adaptor/inc/adaptor_file.h +++ b/common/adaptor/inc/adaptor_file.h @@ -19,10 +19,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - typedef enum FileOperatorType { DEFAULT_FILE_OPERATOR, } FileOperatorType; @@ -38,8 +34,4 @@ typedef struct FileOperator { bool IsFileOperatorValid(const FileOperator *fileOperator); FileOperator *GetFileOperator(const FileOperatorType type); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/adaptor/inc/adaptor_log.h b/common/adaptor/inc/adaptor_log.h index 89045b1..e1dc7a5 100644 --- a/common/adaptor/inc/adaptor_log.h +++ b/common/adaptor/inc/adaptor_log.h @@ -16,10 +16,6 @@ #ifndef ADAPTOR_LOG_H #define ADAPTOR_LOG_H -#ifdef __cplusplus -extern "C" { -#endif - #include "hilog/log_c.h" #ifndef LOG_DOMAIN @@ -29,14 +25,9 @@ extern "C" { #define APP_LOG_TAG "IamBase" #endif -#define LOG_INFO(format, args...) HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, "%{public}s: " format "", __func__, ##args); -#define LOG_ERROR(format, args...) HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, "%{public}s: " format "", __func__, ##args); +#define LOG_INFO(format, args...) HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, \ + "%{public}s: " format "", __func__, ##args) +#define LOG_ERROR(format, args...) HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, \ + "%{public}s: " format "", __func__, ##args) -void LogInfo(const char *format, ...); -void LogError(const char *format, ...); - -#ifdef __cplusplus -} #endif - -#endif \ No newline at end of file diff --git a/common/adaptor/inc/adaptor_memory.h b/common/adaptor/inc/adaptor_memory.h index ea5ff03..04d3ad2 100644 --- a/common/adaptor/inc/adaptor_memory.h +++ b/common/adaptor/inc/adaptor_memory.h @@ -18,16 +18,8 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - void *Malloc(const size_t size); void Free(void *ptr); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/adaptor/inc/adaptor_time.h b/common/adaptor/inc/adaptor_time.h index 64c0e2c..608bf32 100644 --- a/common/adaptor/inc/adaptor_time.h +++ b/common/adaptor/inc/adaptor_time.h @@ -18,15 +18,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - -uint64_t GetSystemTime(); -uint64_t GetRtcTime(); +uint64_t GetSystemTime(void); +uint64_t GetRtcTime(void); -#ifdef __cplusplus -} #endif - -#endif \ No newline at end of file diff --git a/common/adaptor/inc/file_operator.h b/common/adaptor/inc/file_operator.h index e40056b..6360e60 100644 --- a/common/adaptor/inc/file_operator.h +++ b/common/adaptor/inc/file_operator.h @@ -18,14 +18,6 @@ #include "adaptor_file.h" -#ifdef __cplusplus -extern "C" { -#endif - -FileOperator *GetDefaultFileOperator(); - -#ifdef __cplusplus -} -#endif +FileOperator *GetDefaultFileOperator(void); #endif diff --git a/common/adaptor/src/adaptor_algorithm.c b/common/adaptor/src/adaptor_algorithm.c index fee2093..7bc9a13 100644 --- a/common/adaptor/src/adaptor_algorithm.c +++ b/common/adaptor/src/adaptor_algorithm.c @@ -85,7 +85,7 @@ bool IsEd25519KeyPairValid(const KeyPair *keyPair) return true; } -KeyPair *GenerateEd25519KeyPair() +KeyPair *GenerateEd25519KeyPair(void) { KeyPair *keyPair = CreateEd25519KeyPair(); if (keyPair == NULL) { @@ -112,7 +112,7 @@ KeyPair *GenerateEd25519KeyPair() goto ERROR; } keyPair->pubKey->contentSize = pubKeySize; - size_t priKeySize = keyPair->priKey->maxSize;; + size_t priKeySize = keyPair->priKey->maxSize; if (EVP_PKEY_get_raw_private_key(key, keyPair->priKey->buf, &priKeySize) != OPENSSL_SUCCESS) { LOG_ERROR("get pri key fail"); goto ERROR; @@ -221,7 +221,8 @@ static int32_t IamHmac(const EVP_MD *alg, return RESULT_BAD_PARAM; } unsigned int hmacSize = hmac->maxSize; - uint8_t *hmacData = HMAC(alg, hmacKey->buf, (int)hmacKey->contentSize, data->buf, data->contentSize, hmac->buf, &hmacSize); + uint8_t *hmacData = HMAC(alg, hmacKey->buf, (int)hmacKey->contentSize, data->buf, data->contentSize, + hmac->buf, &hmacSize); if (hmacData == NULL) { LOG_ERROR("hmac fail"); return RESULT_GENERAL_ERROR; diff --git a/common/adaptor/src/adaptor_memory.c b/common/adaptor/src/adaptor_memory.c index 2e5dd3d..b9a316f 100644 --- a/common/adaptor/src/adaptor_memory.c +++ b/common/adaptor/src/adaptor_memory.c @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "adaptor_memory.h" #include diff --git a/common/adaptor/src/adaptor_time.c b/common/adaptor/src/adaptor_time.c index e3c6410..041ef70 100644 --- a/common/adaptor/src/adaptor_time.c +++ b/common/adaptor/src/adaptor_time.c @@ -21,7 +21,7 @@ #define MS_OF_S 1000 #define NS_OF_MS 1000000 -uint64_t GetRtcTime() +uint64_t GetRtcTime(void) { struct timespec curTime; int res = clock_gettime(CLOCK_REALTIME, &curTime); @@ -32,7 +32,7 @@ uint64_t GetRtcTime() return curTime.tv_sec * MS_OF_S + curTime.tv_nsec / NS_OF_MS; } -uint64_t GetSystemTime() +uint64_t GetSystemTime(void) { struct timespec curTime; int res = clock_gettime(CLOCK_MONOTONIC, &curTime); diff --git a/common/adaptor/src/file_operator.c b/common/adaptor/src/file_operator.c index 29781f6..5cabd50 100644 --- a/common/adaptor/src/file_operator.c +++ b/common/adaptor/src/file_operator.c @@ -28,7 +28,7 @@ static bool IsFileExist(const char *fileName) if (fileOperator == NULL) { return false; } - fclose(fileOperator); + (void)fclose(fileOperator); return true; } @@ -46,10 +46,10 @@ static int32_t ReadFile(const char *fileName, uint8_t *buf, uint32_t len) size_t readLen = fread(buf, sizeof(uint8_t), len, fileOperator); if (readLen != len) { LOG_ERROR("read file fail"); - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_BAD_READ; } - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_SUCCESS; } @@ -65,13 +65,12 @@ static int32_t WriteFile(const char *fileName, const uint8_t *buf, uint32_t len) return RESULT_BAD_PARAM; } size_t writeLen = fwrite(buf, sizeof(uint8_t), len, fileOperator); - LOG_ERROR("write file writeLen = %{public}u", writeLen); if (writeLen != len) { LOG_ERROR("write file fail"); - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_BAD_WRITE; } - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_SUCCESS; } @@ -88,17 +87,17 @@ static int32_t GetFileLen(const char *fileName, uint32_t *len) } if (fseek(fileOperator, 0L, SEEK_END) != 0) { LOG_ERROR("seek file fail"); - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_GENERAL_ERROR; } long fileLen = ftell(fileOperator); if (fileLen < 0 || fileLen > UINT32_MAX) { LOG_ERROR("tell file fail"); - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_GENERAL_ERROR; } *len = fileLen; - fclose(fileOperator); + (void)fclose(fileOperator); return RESULT_SUCCESS; } @@ -116,7 +115,7 @@ static int32_t DeleteFile(const char *fileName) return RESULT_SUCCESS; } -FileOperator *GetDefaultFileOperator() +FileOperator *GetDefaultFileOperator(void) { static FileOperator fileOperator = { .isFileExist = IsFileExist, diff --git a/common/bundle.json b/common/bundle.json new file mode 100644 index 0000000..aa0d325 --- /dev/null +++ b/common/bundle.json @@ -0,0 +1,40 @@ +{ + "name": "@openharmony/useriam_common", + "version": "3.1.0", + "description": "Useriam common", + "homePage": "https://gitee.com/openharmony", + "author": {}, + "repository": "", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath" : "base/useriam/coauth/common" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "useriam_common", + "subsystem": "useriam", + "adapted_system_type": [ "standard" ], + "syscap": [], + "features": [], + "rom": "800KB", + "ram": "2000KB", + "deps": { + "components": [ + "hiviewdfx_hilog_native" + ], + "third_party": [ + ] + }, + "build": { + "sub_component": [ + "//base/user_iam/auth_executor_mgr/common:useriam_common_lib" + ], + "inner_kits": [ + ], + "test": [ + ] + } + } + } diff --git a/common/coauth/inc/coauth.h b/common/coauth/inc/coauth.h index 100cad5..6f70679 100644 --- a/common/coauth/inc/coauth.h +++ b/common/coauth/inc/coauth.h @@ -18,10 +18,6 @@ #include "pool.h" -#ifdef __cplusplus -extern "C" { -#endif - #define INAVLID_SESSION_ID 0 #define MAX_EXECUTOR_SIZE 2 @@ -45,8 +41,8 @@ typedef struct CoAuthSchedule { ExecutorInfoHal executors[MAX_EXECUTOR_SIZE]; } CoAuthSchedule; -ResultCode InitCoAuth(); -void DestoryCoAuth(); +ResultCode InitCoAuth(void); +void DestoryCoAuth(void); CoAuthSchedule *GenerateAuthSchedule(uint64_t contextId, uint32_t authType, uint64_t authSubType, uint64_t templateId); @@ -57,8 +53,4 @@ ResultCode RemoveCoAuthSchedule(uint64_t scheduleId); ResultCode GetCoAuthSchedule(CoAuthSchedule *coAuthSchedule); void DestroyCoAuthSchedule(CoAuthSchedule *coAuthSchedule); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/coauth/inc/coauth_funcs.h b/common/coauth/inc/coauth_funcs.h index ab7fdd2..38ba416 100644 --- a/common/coauth/inc/coauth_funcs.h +++ b/common/coauth/inc/coauth_funcs.h @@ -22,10 +22,6 @@ #include "coauth_sign_centre.h" #include "pool.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { ExecutorInfoHal executorInfos[MAX_EXECUTOR_SIZE]; uint32_t executorInfoNum; @@ -42,8 +38,4 @@ int32_t UnRegisterExecutor(uint64_t executorId); bool IsExecutorExistFunc(uint32_t authType); -#ifdef __cplusplus -} -#endif - #endif // COAUTH_FUNCS_H diff --git a/common/coauth/inc/coauth_sign_centre.h b/common/coauth/inc/coauth_sign_centre.h index 5bc55f0..d6b6508 100644 --- a/common/coauth/inc/coauth_sign_centre.h +++ b/common/coauth/inc/coauth_sign_centre.h @@ -13,18 +13,14 @@ * limitations under the License. */ -#ifndef USERIAMTA_COAUTH_SIGN_CENTRE_H -#define USERIAMTA_COAUTH_SIGN_CENTRE_H +#ifndef COAUTH_SIGN_CENTRE_H +#define COAUTH_SIGN_CENTRE_H #include #include "buffer.h" #include "defines.h" -#ifdef __cplusplus -extern "C" { -#endif - #define SHA256_SIGN_LEN 32 #define COAUTH_TOKEN_LEN sizeof(ScheduleTokenHal) #define COAUTH_TOKEN_DATA_LEN (COAUTH_TOKEN_LEN - SHA256_SIGN_LEN) @@ -47,8 +43,4 @@ typedef struct { ResultCode CoAuthTokenSign(ScheduleTokenHal *userAuthToken); ResultCode CoAuthTokenVerify(const ScheduleTokenHal *userAuthToken); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_COAUTH_SIGN_CENTRE_H \ No newline at end of file +#endif // COAUTH_SIGN_CENTRE_H \ No newline at end of file diff --git a/common/coauth/inc/executor_message.h b/common/coauth/inc/executor_message.h index 61773fd..10f708e 100644 --- a/common/coauth/inc/executor_message.h +++ b/common/coauth/inc/executor_message.h @@ -21,10 +21,6 @@ #include "buffer.h" #include "defines.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef enum AuthAttributeType { AUTH_INVALID = 0, AUTH_ROOT = 1000000, @@ -58,8 +54,4 @@ typedef struct ExecutorResultInfo { ExecutorResultInfo *GetExecutorResultInfo(const Buffer *executorResultInfo); void DestoryExecutorResultInfo(ExecutorResultInfo *result); -#ifdef __cplusplus -} -#endif - #endif // USERIAM_EXECUTOR_MESSAGE_H \ No newline at end of file diff --git a/common/coauth/src/coauth.c b/common/coauth/src/coauth.c index 3ee4541..13e1e98 100644 --- a/common/coauth/src/coauth.c +++ b/common/coauth/src/coauth.c @@ -47,7 +47,7 @@ void DestroyCoAuthSchedule(CoAuthSchedule *coAuthSchedule) DestroySchedule(coAuthSchedule); } -ResultCode InitCoAuth() +ResultCode InitCoAuth(void) { if (!IsCoAuthInit()) { g_scheduleList = CreateLinkedList(DestroySchedule); @@ -58,7 +58,7 @@ ResultCode InitCoAuth() return RESULT_SUCCESS; } -void DestoryCoAuth() +void DestoryCoAuth(void) { DestroyLinkedList(g_scheduleList); g_scheduleList = NULL; @@ -141,7 +141,7 @@ ResultCode GetCoAuthSchedule(CoAuthSchedule *coAuthSchedule) g_scheduleList->destroyIterator(iterator); return RESULT_SUCCESS; } - LOG_ERROR("can't find schedule"); //del + g_scheduleList->destroyIterator(iterator); return result; } @@ -175,8 +175,7 @@ static ResultCode GenerateValidScheduleId(uint64_t *scheduleId) return RESULT_GENERAL_ERROR; } if (!IsScheduleIdDuplicate(tempRandom)) { - //mock *scheduleId = tempRandom; - *scheduleId = 10; + *scheduleId = tempRandom; return RESULT_SUCCESS; } } @@ -207,7 +206,8 @@ static ResultCode MountExecutor(uint32_t authType, CoAuthSchedule *coAuthSchedul ret = RESULT_UNKNOWN; goto EXIT; } - if (memcpy_s(coAuthSchedule->executors + i, sizeof(ExecutorInfoHal), tempNode->data, sizeof(ExecutorInfoHal)) != EOK) { + if (memcpy_s(coAuthSchedule->executors + i, sizeof(ExecutorInfoHal), + tempNode->data, sizeof(ExecutorInfoHal)) != EOK) { LOG_ERROR("copy executorinfo failed"); ret = RESULT_UNKNOWN; goto EXIT; diff --git a/common/coauth/src/coauth_funcs.c b/common/coauth/src/coauth_funcs.c index 5bb7afe..8d79492 100644 --- a/common/coauth/src/coauth_funcs.c +++ b/common/coauth/src/coauth_funcs.c @@ -71,15 +71,8 @@ int32_t ScheduleFinish(const Buffer *executorMsg, ScheduleTokenHal *scheduleToke return RESULT_BAD_PARAM; } scheduleToken->scheduleResult = RESULT_GENERAL_ERROR; - // ExecutorResultInfo *resultInfo = Malloc(sizeof(ExecutorResultInfo)); - ExecutorResultInfo *resultInfo = GetExecutorResultInfo(executorMsg); - // // mock - - // resultInfo->authSubType = 1; - // resultInfo->result = 0; - // resultInfo->scheduleId = 10; - // resultInfo->capabilityLevel = 3; - // resultInfo->templateId = 10001; + ExecutorResultInfo *resultInfo = Malloc(sizeof(ExecutorResultInfo)); + resultInfo = GetExecutorResultInfo(executorMsg); if (resultInfo == NULL) { LOG_ERROR("tlv parse failed"); return RESULT_BAD_PARAM; @@ -117,7 +110,7 @@ int32_t ScheduleFinish(const Buffer *executorMsg, ScheduleTokenHal *scheduleToke LOG_ERROR("remove failed"); } ret = TokenDataGetAndSign(coAuthSchedule.executors[0].authType, resultInfo, scheduleToken); - // DestoryBuffer(publicKey); + DestoryBuffer(publicKey); EXIT: DestoryExecutorResultInfo(resultInfo); @@ -133,7 +126,6 @@ int32_t RegisterExecutor(const ExecutorInfoHal *registerInfo, uint64_t *executor } ExecutorInfoHal executorInfo = *registerInfo; - LOG_ERROR("authType is %{public}d", executorInfo.authType); int32_t ret = RegisterExecutorToPool(&executorInfo); if (ret != RESULT_SUCCESS) { LOG_ERROR("register failed"); diff --git a/common/coauth/src/executor_message.c b/common/coauth/src/executor_message.c index 0b42b35..5d9816a 100644 --- a/common/coauth/src/executor_message.c +++ b/common/coauth/src/executor_message.c @@ -180,8 +180,6 @@ ExecutorResultInfo *GetExecutorResultInfo(const Buffer *tlv) return NULL; } - LOG_ERROR("ParseTlvWrapper end"); - ExecutorResultInfo *result = Malloc(sizeof(ExecutorResultInfo)); if (result == NULL) { LOG_ERROR("malloc failed"); diff --git a/common/common/inc/bitwise_operation.h b/common/common/inc/bitwise_operation.h index d95673f..10fd495 100644 --- a/common/common/inc/bitwise_operation.h +++ b/common/common/inc/bitwise_operation.h @@ -13,22 +13,12 @@ * limitations under the License. */ -#ifndef USERIAMTA_BITWISE_OPERATION_H -#define USERIAMTA_BITWISE_OPERATION_H +#ifndef BITWISE_OPERATION_H +#define BITWISE_OPERATION_H -#include -#include #include -#ifdef __cplusplus -extern "C" { -#endif - uint64_t GetUint64(uint32_t high, uint32_t low); void SplitUint64(uint64_t number, uint32_t *high, uint32_t *low); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_BITWISE_OPERATION_H +#endif // BITWISE_OPERATION_H diff --git a/common/common/inc/buffer.h b/common/common/inc/buffer.h index d135d0a..fcf88ad 100644 --- a/common/common/inc/buffer.h +++ b/common/common/inc/buffer.h @@ -16,12 +16,7 @@ #ifndef COMMON_BUFFER_H #define COMMON_BUFFER_H -#ifdef __cplusplus -extern "C" { -#endif - #include "stdbool.h" -#include "stddef.h" #include "stdint.h" #include "defines.h" @@ -41,8 +36,4 @@ Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize); ResultCode GetBufferData(const Buffer *buffer, uint8_t *data, uint32_t *dataSize); bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size); -#ifdef __cplusplus -} #endif - -#endif \ No newline at end of file diff --git a/common/common/inc/defines.h b/common/common/inc/defines.h index 0df5645..f737a39 100644 --- a/common/common/inc/defines.h +++ b/common/common/inc/defines.h @@ -16,10 +16,6 @@ #ifndef COMMON_DEFINES_H #define COMMON_DEFINES_H -#ifdef __cplusplus -extern "C" { -#endif - typedef enum ResultCode { RESULT_SUCCESS = 0x0, RESULT_GENERAL_ERROR = 0x1, @@ -58,8 +54,4 @@ typedef enum AuthSubType { #define MAX_DULPLICATE_CHECK 100 -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/common/inc/linked_list.h b/common/common/inc/linked_list.h index 4643ee2..816c5c9 100644 --- a/common/common/inc/linked_list.h +++ b/common/common/inc/linked_list.h @@ -20,10 +20,6 @@ #include "stdint.h" #include "defines.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef void (*DESTROY_DATA_FUNC)(void *data); typedef bool (*MATCH_FUNC)(void *data, void *condition); typedef bool (*HANDLE_DATA_FUNC)(void *data, void *arg); @@ -53,8 +49,4 @@ typedef struct LinkedList { LinkedList *CreateLinkedList(DESTROY_DATA_FUNC destroyDataFunc); void DestroyLinkedList(LinkedList *list); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/common/inc/tlv_base.h b/common/common/inc/tlv_base.h index fcef35f..48910db 100644 --- a/common/common/inc/tlv_base.h +++ b/common/common/inc/tlv_base.h @@ -18,10 +18,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - typedef enum { OPERA_SUCC = 0, PARAM_ERR = 1001, @@ -33,9 +29,9 @@ typedef enum { } ErrCode; typedef struct { - int type; - unsigned int length; - unsigned char *value; + int32_t type; + uint32_t length; + uint8_t *value; } TlvType; typedef struct { @@ -62,16 +58,12 @@ uint32_t Ntohl(uint32_t data); // uint64 convert endian uint64_t Ntohll(uint64_t data); -TlvListNode *CreateTlvList(); -int DestroyTlvList(TlvListNode *list); -TlvObject *CreateTlvObject(int type, unsigned int length, const void *value); -TlvObject *CreateEmptyTlvObject(int type); -TlvType *CreateTlvType(int type, unsigned int length, const void *value); +TlvListNode *CreateTlvList(void); +int32_t DestroyTlvList(TlvListNode *list); +TlvObject *CreateTlvObject(int32_t type, uint32_t length, const void *value); +TlvObject *CreateEmptyTlvObject(int32_t type); +TlvType *CreateTlvType(int32_t type, uint32_t length, const void *value); void DestroyTlvObject(TlvObject *object); -int AddTlvNode(TlvListNode *list, const TlvObject *object); - -#ifdef __cplusplus -} -#endif +int32_t AddTlvNode(TlvListNode *list, const TlvObject *object); #endif // TLV_BASE_H \ No newline at end of file diff --git a/common/common/inc/tlv_wrapper.h b/common/common/inc/tlv_wrapper.h index ea586cc..23666ce 100644 --- a/common/common/inc/tlv_wrapper.h +++ b/common/common/inc/tlv_wrapper.h @@ -21,41 +21,33 @@ #include "tlv_base.h" #include "buffer.h" -#ifdef __cplusplus -extern "C" { -#endif - #define MAX_BUFFER_SIZE 512000 -#define TLV_HEADER_LEN (sizeof(int) + sizeof(unsigned int)) - -int SerializeTlvWrapper(const TlvListNode *head, unsigned char *buffer, - unsigned int maxSize, unsigned int *contentSize); - -int ParseTlvWrapper(const unsigned char *buffer, unsigned int bufferSize, TlvListNode *head); -int ParseGetHeadTag(const TlvListNode *node, int *tag); - -int32_t ParseUint64Para(TlvListNode *node, int msgType, uint64_t *retVal); -int32_t ParseInt64Para(TlvListNode *node, int msgType, int64_t *retVal); -int32_t ParseUint32Para(TlvListNode *node, int msgType, uint32_t *retVal); -int32_t ParseInt32Para(TlvListNode *node, int msgType, int32_t *retVal); -Buffer *ParseBuffPara(TlvListNode *node, int msgType); -int32_t ParseUint8Para(TlvListNode *node, int msgType, uint8_t *retVal); - -int32_t GetUint64Para(TlvListNode *head, int msgType, uint64_t *retVal); -int32_t GetInt64Para(TlvListNode *head, int msgType, int64_t *retVal); -int32_t GetUint32Para(TlvListNode *head, int msgType, uint32_t *retVal); -int32_t GetInt32Para(TlvListNode *head, int msgType, int32_t *retVal); -Buffer *GetBuffPara(TlvListNode *head, int msgType); -int32_t GetUint8Para(TlvListNode *head, int msgType, uint8_t *retVal); - -int TlvAppendByte(TlvListNode *head, int type, const unsigned char *value, unsigned int length); -int TlvAppendShort(TlvListNode *head, int type, short value); -int TlvAppendInt(TlvListNode *head, int type, uint32_t value); -int TlvAppendLong(TlvListNode *head, int type, uint64_t value); -int TlvAppendObject(TlvListNode *head, int type, const unsigned char *buffer, unsigned int length); - -#ifdef __cplusplus -} -#endif +#define TLV_HEADER_LEN (sizeof(int32_t) + sizeof(uint32_t)) + +int32_t SerializeTlvWrapper(const TlvListNode *head, uint8_t*buffer, + uint32_t maxSize, uint32_t *contentSize); + +int32_t ParseTlvWrapper(const uint8_t*buffer, uint32_t bufferSize, TlvListNode *head); +int32_t ParseGetHeadTag(const TlvListNode *node, int32_t *tag); + +int32_t ParseUint64Para(TlvListNode *node, int32_t msgType, uint64_t *retVal); +int32_t ParseInt64Para(TlvListNode *node, int32_t msgType, int64_t *retVal); +int32_t ParseUint32Para(TlvListNode *node, int32_t msgType, uint32_t *retVal); +int32_t ParseInt32Para(TlvListNode *node, int32_t msgType, int32_t *retVal); +Buffer *ParseBuffPara(TlvListNode *node, int32_t msgType); +int32_t ParseUint8Para(TlvListNode *node, int32_t msgType, uint8_t *retVal); + +int32_t GetUint64Para(TlvListNode *head, int32_t msgType, uint64_t *retVal); +int32_t GetInt64Para(TlvListNode *head, int32_t msgType, int64_t *retVal); +int32_t GetUint32Para(TlvListNode *head, int32_t msgType, uint32_t *retVal); +int32_t GetInt32Para(TlvListNode *head, int32_t msgType, int32_t *retVal); +Buffer *GetBuffPara(TlvListNode *head, int32_t msgType); +int32_t GetUint8Para(TlvListNode *head, int32_t msgType, uint8_t *retVal); + +int32_t TlvAppendByte(TlvListNode *head, int32_t type, const uint8_t*value, uint32_t length); +int32_t TlvAppendShort(TlvListNode *head, int32_t type, short value); +int32_t TlvAppendInt(TlvListNode *head, int32_t type, uint32_t value); +int32_t TlvAppendLong(TlvListNode *head, int32_t type, uint64_t value); +int32_t TlvAppendObject(TlvListNode *head, int32_t type, const uint8_t*buffer, uint32_t length); #endif // TLV_WRAPPER_H \ No newline at end of file diff --git a/common/common/src/tlv_base.c b/common/common/src/tlv_base.c index d5dcc28..04df822 100644 --- a/common/common/src/tlv_base.c +++ b/common/common/src/tlv_base.c @@ -42,7 +42,7 @@ uint64_t Ntohll(uint64_t data) return data; } -TlvListNode *CreateTlvList() +TlvListNode *CreateTlvList(void) { TlvListNode *node = (TlvListNode *)Malloc(sizeof(TlvListNode)); if (node == NULL) { @@ -52,7 +52,7 @@ TlvListNode *CreateTlvList() return node; } -TlvType *CreateTlvType(int type, unsigned int length, const void *value) +TlvType *CreateTlvType(int32_t type, uint32_t length, const void *value) { if (value == NULL || length == 0) { return NULL; @@ -64,7 +64,7 @@ TlvType *CreateTlvType(int type, unsigned int length, const void *value) tlv->type = type; tlv->length = length; - tlv->value = (unsigned char *)Malloc(length); + tlv->value = (uint8_t *)Malloc(length); if (tlv->value == NULL) { Free(tlv); return NULL; @@ -79,7 +79,7 @@ TlvType *CreateTlvType(int type, unsigned int length, const void *value) return tlv; } -TlvObject *CreateTlvObject(int type, unsigned int length, const void *value) +TlvObject *CreateTlvObject(int32_t type, uint32_t length, const void *value) { TlvObject *object = (TlvObject *)Malloc(sizeof(TlvListNode)); if (object == NULL) { @@ -94,7 +94,7 @@ TlvObject *CreateTlvObject(int type, unsigned int length, const void *value) return object; } -static TlvType *CreateEmptyTlvType(int type) +static TlvType *CreateEmptyTlvType(int32_t type) { TlvType *tlv = (TlvType *)Malloc(sizeof(TlvType)); if (tlv == NULL) { @@ -107,7 +107,7 @@ static TlvType *CreateEmptyTlvType(int type) return tlv; } -TlvObject *CreateEmptyTlvObject(int type) +TlvObject *CreateEmptyTlvObject(int32_t type) { TlvObject *object = (TlvObject *)Malloc(sizeof(TlvListNode)); if (object == NULL) { @@ -140,7 +140,7 @@ void DestroyTlvObject(TlvObject *object) Free(object); } -int DestroyTlvList(TlvListNode *head) +int32_t DestroyTlvList(TlvListNode *head) { if (head == NULL) { return PARAM_ERR; @@ -164,7 +164,7 @@ int DestroyTlvList(TlvListNode *head) return OPERA_SUCC; } -int AddTlvNode(TlvListNode *head, const TlvObject *object) +int32_t AddTlvNode(TlvListNode *head, const TlvObject *object) { if (head == NULL || object == NULL) { return PARAM_ERR; diff --git a/common/common/src/tlv_wrapper.c b/common/common/src/tlv_wrapper.c index 4973db5..14dac0a 100644 --- a/common/common/src/tlv_wrapper.c +++ b/common/common/src/tlv_wrapper.c @@ -22,7 +22,7 @@ #include "adaptor_log.h" #include "adaptor_memory.h" -static int PutTlvObject(TlvListNode *head, int type, unsigned int length, const void *value) +static int32_t PutTlvObject(TlvListNode *head, int32_t type, uint32_t length, const void *value) { if ((head == NULL) || (value == NULL) || (length > MAX_BUFFER_SIZE)) { return PARAM_ERR; @@ -37,7 +37,7 @@ static int PutTlvObject(TlvListNode *head, int type, unsigned int length, const tlv->length = length; tlv->value = NULL; if (length > 0) { - tlv->value = (unsigned char *)Malloc(length); + tlv->value = (uint8_t *)Malloc(length); if (tlv->value == NULL) { Free(tlv); tlv = NULL; @@ -55,7 +55,7 @@ static int PutTlvObject(TlvListNode *head, int type, unsigned int length, const TlvObject object; object.value = tlv; - int ret = AddTlvNode(head, &object); + int32_t ret = AddTlvNode(head, &object); if (ret != OPERA_SUCC) { if (object.value != NULL) { Free(tlv->value); @@ -67,28 +67,28 @@ static int PutTlvObject(TlvListNode *head, int type, unsigned int length, const return ret; } -int SerializeTlvWrapper(const TlvListNode *head, unsigned char *buffer, unsigned int maxSize, unsigned int *contentSize) +int32_t SerializeTlvWrapper(const TlvListNode *head, uint8_t *buffer, uint32_t maxSize, uint32_t *contentSize) { if (head == NULL || buffer == NULL || contentSize == NULL || maxSize == 0) { return PARAM_ERR; } - unsigned int offset = 0; + uint32_t offset = 0; TlvListNode *node = head->next; while (node != NULL) { TlvType *tlv = node->data.value; - int type = Ntohl(tlv->type); - if ((offset > UINT32_MAX - sizeof(int)) || (offset + sizeof(int) > maxSize) || - (memcpy_s(buffer + offset, sizeof(int), &type, sizeof(int)) != EOK)) { + int32_t type = Ntohl(tlv->type); + if ((offset > UINT32_MAX - sizeof(int32_t)) || (offset + sizeof(int32_t) > maxSize) || + (memcpy_s(buffer + offset, sizeof(int32_t), &type, sizeof(int32_t)) != EOK)) { return MEMCPY_ERR; } - offset += sizeof(int); - unsigned int len = Ntohl(tlv->length); - if ((offset > UINT32_MAX - sizeof(int)) || (offset + sizeof(int) > maxSize) || - (memcpy_s(buffer + offset, sizeof(int), &len, sizeof(int)) != EOK)) { + offset += sizeof(int32_t); + uint32_t len = Ntohl(tlv->length); + if ((offset > UINT32_MAX - sizeof(int32_t)) || (offset + sizeof(int32_t) > maxSize) || + (memcpy_s(buffer + offset, sizeof(int32_t), &len, sizeof(int32_t)) != EOK)) { return MEMCPY_ERR; } - offset += sizeof(int); + offset += sizeof(int32_t); if ((offset > UINT32_MAX - tlv->length) || (offset + tlv->length > maxSize) || ((tlv->length != 0) && (memcpy_s(buffer + offset, maxSize - offset, tlv->value, tlv->length) != EOK))) { return MEMCPY_ERR; @@ -101,7 +101,7 @@ int SerializeTlvWrapper(const TlvListNode *head, unsigned char *buffer, unsigned return OPERA_SUCC; } -int ParseGetHeadTag(const TlvListNode *node, int *tag) +int32_t ParseGetHeadTag(const TlvListNode *node, int32_t *tag) { if (node == NULL || tag == NULL) { return PARAM_ERR; @@ -114,27 +114,27 @@ int ParseGetHeadTag(const TlvListNode *node, int *tag) return OPERA_SUCC; } -int ParseTlvWrapper(const unsigned char *buffer, unsigned int bufferSize, TlvListNode *head) +int32_t ParseTlvWrapper(const uint8_t *buffer, uint32_t bufferSize, TlvListNode *head) { if (buffer == NULL || bufferSize == 0 || bufferSize > MAX_BUFFER_SIZE || head == NULL) { return PARAM_ERR; } - unsigned int offset = 0; + uint32_t offset = 0; while (offset < bufferSize) { - if ((bufferSize - offset) < (sizeof(int) + sizeof(int))) { + if ((bufferSize - offset) < (sizeof(int32_t) + sizeof(int32_t))) { LOG_ERROR("bufferSize = %{public}u, offset = %{public}u", bufferSize, offset); return OPERA_FAIL; } - int type = Ntohl(*(int *)(buffer + offset)); - offset += sizeof(int); - unsigned int length = Ntohl(*(int *)(buffer + offset)); - offset += sizeof(int); + int32_t type = Ntohl(*(int32_t *)(buffer + offset)); + offset += sizeof(int32_t); + uint32_t length = Ntohl(*(int32_t *)(buffer + offset)); + offset += sizeof(int32_t); if (length > (bufferSize - offset)) { LOG_ERROR("bufferSize = %{public}u, offset = %{public}u, length = %{public}u", bufferSize, offset, length); return OPERA_FAIL; } - int ret = PutTlvObject(head, type, length, buffer + offset); + int32_t ret = PutTlvObject(head, type, length, buffer + offset); if (ret != 0) { return ret; } @@ -144,7 +144,7 @@ int ParseTlvWrapper(const unsigned char *buffer, unsigned int bufferSize, TlvLis return OPERA_SUCC; } -int TlvAppendByte(TlvListNode *head, int type, const unsigned char *value, unsigned int length) +int32_t TlvAppendByte(TlvListNode *head, int32_t type, const uint8_t *value, uint32_t length) { if (head == NULL || value == NULL) { return PARAM_ERR; @@ -152,7 +152,7 @@ int TlvAppendByte(TlvListNode *head, int type, const unsigned char *value, unsig return PutTlvObject(head, type, length, value); } -int TlvAppendShort(TlvListNode *head, int type, short value) +int32_t TlvAppendShort(TlvListNode *head, int32_t type, short value) { if (head == NULL) { return PARAM_ERR; @@ -161,7 +161,7 @@ int TlvAppendShort(TlvListNode *head, int type, short value) return PutTlvObject(head, type, sizeof(short), &tempValue); } -int TlvAppendInt(TlvListNode *head, int type, uint32_t value) +int32_t TlvAppendInt(TlvListNode *head, int32_t type, uint32_t value) { if (head == NULL) { return PARAM_ERR; @@ -170,7 +170,7 @@ int TlvAppendInt(TlvListNode *head, int type, uint32_t value) return PutTlvObject(head, type, sizeof(int32_t), &tempValue); } -int TlvAppendLong(TlvListNode *head, int type, uint64_t value) +int32_t TlvAppendLong(TlvListNode *head, int32_t type, uint64_t value) { if (head == NULL) { return PARAM_ERR; @@ -179,7 +179,7 @@ int TlvAppendLong(TlvListNode *head, int type, uint64_t value) return PutTlvObject(head, type, sizeof(int64_t), &tempValue); } -int TlvAppendObject(TlvListNode *head, int type, const unsigned char *buffer, unsigned int length) +int32_t TlvAppendObject(TlvListNode *head, int32_t type, const uint8_t *buffer, uint32_t length) { if (head == NULL || buffer == NULL || length == 0 || length > MAX_BUFFER_SIZE) { return PARAM_ERR; @@ -187,7 +187,7 @@ int TlvAppendObject(TlvListNode *head, int type, const unsigned char *buffer, un return PutTlvObject(head, type, length, buffer); } -static uint8_t *GetTlvValue(TlvListNode *head, int msgType, uint32_t *len) +static uint8_t *GetTlvValue(TlvListNode *head, int32_t msgType, uint32_t *len) { if ((head == NULL) || (len == NULL)) { LOG_ERROR("GetTlvValue input invalid"); @@ -209,7 +209,7 @@ static uint8_t *GetTlvValue(TlvListNode *head, int msgType, uint32_t *len) return tlv->value; } -int32_t ParseUint64Para(TlvListNode *node, int msgType, uint64_t *retVal) +int32_t ParseUint64Para(TlvListNode *node, int32_t msgType, uint64_t *retVal) { if ((node == NULL) || (retVal == NULL)) { LOG_ERROR("ParseUint64Para parameter check failed"); @@ -225,7 +225,7 @@ int32_t ParseUint64Para(TlvListNode *node, int msgType, uint64_t *retVal) return OPERA_SUCC; } -int32_t ParseInt64Para(TlvListNode *node, int msgType, int64_t *retVal) +int32_t ParseInt64Para(TlvListNode *node, int32_t msgType, int64_t *retVal) { if ((node == NULL) || (retVal == NULL)) { LOG_ERROR("ParseInt64Para parameter check failed"); @@ -241,7 +241,7 @@ int32_t ParseInt64Para(TlvListNode *node, int msgType, int64_t *retVal) return OPERA_SUCC; } -int32_t ParseUint32Para(TlvListNode *node, int msgType, uint32_t *retVal) +int32_t ParseUint32Para(TlvListNode *node, int32_t msgType, uint32_t *retVal) { if ((node == NULL) || (retVal == NULL)) { LOG_ERROR("ParseUint32Para parameter check failed"); @@ -257,7 +257,7 @@ int32_t ParseUint32Para(TlvListNode *node, int msgType, uint32_t *retVal) return OPERA_SUCC; } -int32_t ParseInt32Para(TlvListNode *node, int msgType, int32_t *retVal) +int32_t ParseInt32Para(TlvListNode *node, int32_t msgType, int32_t *retVal) { if ((node == NULL) || (retVal == NULL)) { LOG_ERROR("ParseInt32Para parameter check failed"); @@ -273,7 +273,7 @@ int32_t ParseInt32Para(TlvListNode *node, int msgType, int32_t *retVal) return OPERA_SUCC; } -int32_t ParseShortPara(TlvListNode *node, int msgType, short *retVal) +int32_t ParseShortPara(TlvListNode *node, int32_t msgType, short *retVal) { if ((node == NULL) || (retVal == NULL)) { LOG_ERROR("ParseInt32Para parameter check failed"); @@ -289,7 +289,7 @@ int32_t ParseShortPara(TlvListNode *node, int msgType, short *retVal) return OPERA_SUCC; } -Buffer *ParseBuffPara(TlvListNode *node, int msgType) +Buffer *ParseBuffPara(TlvListNode *node, int32_t msgType) { if (node == NULL) { LOG_ERROR("ParseBuffPara parameter check failed"); @@ -309,7 +309,7 @@ Buffer *ParseBuffPara(TlvListNode *node, int msgType) return buff; } -int32_t ParseUint8Para(TlvListNode *node, int msgType, uint8_t *retVal) +int32_t ParseUint8Para(TlvListNode *node, int32_t msgType, uint8_t *retVal) { if ((node == NULL) || (retVal == NULL)) { LOG_ERROR("ParseUint8Para parameter check failed"); @@ -326,7 +326,7 @@ int32_t ParseUint8Para(TlvListNode *node, int msgType, uint8_t *retVal) } -int32_t GetUint64Para(TlvListNode *head, int msgType, uint64_t *retVal) +int32_t GetUint64Para(TlvListNode *head, int32_t msgType, uint64_t *retVal) { if ((head == NULL) || (retVal == NULL)) { LOG_ERROR("GetUint64Para parameter check failed"); @@ -334,7 +334,7 @@ int32_t GetUint64Para(TlvListNode *head, int msgType, uint64_t *retVal) } TlvListNode *node = head; while (node != NULL) { - int nodeType; + int32_t nodeType; int32_t ret = ParseGetHeadTag(node, &nodeType); if (ret != OPERA_SUCC) { return ret; @@ -347,7 +347,7 @@ int32_t GetUint64Para(TlvListNode *head, int msgType, uint64_t *retVal) return PARAM_ERR; } -int32_t GetInt64Para(TlvListNode *head, int msgType, int64_t *retVal) +int32_t GetInt64Para(TlvListNode *head, int32_t msgType, int64_t *retVal) { if ((head == NULL) || (retVal == NULL)) { LOG_ERROR("GetInt64Para parameter check failed"); @@ -355,7 +355,7 @@ int32_t GetInt64Para(TlvListNode *head, int msgType, int64_t *retVal) } TlvListNode *node = head; while (node != NULL) { - int nodeType; + int32_t nodeType; int32_t ret = ParseGetHeadTag(node, &nodeType); if (ret != OPERA_SUCC) { return ret; @@ -368,7 +368,7 @@ int32_t GetInt64Para(TlvListNode *head, int msgType, int64_t *retVal) return PARAM_ERR; } -int32_t GetUint32Para(TlvListNode *head, int msgType, uint32_t *retVal) +int32_t GetUint32Para(TlvListNode *head, int32_t msgType, uint32_t *retVal) { if ((head == NULL) || (retVal == NULL)) { LOG_ERROR("GetUint32Para parameter check failed"); @@ -376,7 +376,7 @@ int32_t GetUint32Para(TlvListNode *head, int msgType, uint32_t *retVal) } TlvListNode *node = head; while (node != NULL) { - int nodeType; + int32_t nodeType; int32_t ret = ParseGetHeadTag(node, &nodeType); if (ret != OPERA_SUCC) { return ret; @@ -389,7 +389,7 @@ int32_t GetUint32Para(TlvListNode *head, int msgType, uint32_t *retVal) return PARAM_ERR; } -int32_t GetInt32Para(TlvListNode *head, int msgType, int32_t *retVal) +int32_t GetInt32Para(TlvListNode *head, int32_t msgType, int32_t *retVal) { if ((head == NULL) || (retVal == NULL)) { LOG_ERROR("GetInt32Para parameter check failed"); @@ -397,7 +397,7 @@ int32_t GetInt32Para(TlvListNode *head, int msgType, int32_t *retVal) } TlvListNode *node = head; while (node != NULL) { - int nodeType; + int32_t nodeType; int32_t ret = ParseGetHeadTag(node, &nodeType); if (ret != OPERA_SUCC) { return ret; @@ -410,7 +410,7 @@ int32_t GetInt32Para(TlvListNode *head, int msgType, int32_t *retVal) return PARAM_ERR; } -Buffer *GetBuffPara(TlvListNode *head, int msgType) +Buffer *GetBuffPara(TlvListNode *head, int32_t msgType) { if (head == NULL) { LOG_ERROR("GetBuffPara parameter check failed"); @@ -418,7 +418,7 @@ Buffer *GetBuffPara(TlvListNode *head, int msgType) } TlvListNode *node = head; while (node != NULL) { - int nodeType; + int32_t nodeType; int32_t ret = ParseGetHeadTag(node, &nodeType); if (ret != OPERA_SUCC) { return NULL; @@ -431,7 +431,7 @@ Buffer *GetBuffPara(TlvListNode *head, int msgType) return NULL; } -int32_t GetUint8Para(TlvListNode *head, int msgType, uint8_t *retVal) +int32_t GetUint8Para(TlvListNode *head, int32_t msgType, uint8_t *retVal) { if ((head == NULL) || (retVal == NULL)) { LOG_ERROR("GetUint8Para parameter check failed"); @@ -439,7 +439,7 @@ int32_t GetUint8Para(TlvListNode *head, int msgType, uint8_t *retVal) } TlvListNode *node = head; while (node != NULL) { - int nodeType; + int32_t nodeType; int32_t ret = ParseGetHeadTag(node, &nodeType); if (ret != OPERA_SUCC) { return ret; diff --git a/common/database/inc/idm_common.h b/common/database/inc/idm_common.h index 925df6c..2ed7950 100644 --- a/common/database/inc/idm_common.h +++ b/common/database/inc/idm_common.h @@ -13,17 +13,12 @@ * limitations under the License. */ -#ifndef USERIAMTA_IDM_COMMON_H -#define USERIAMTA_IDM_COMMON_H +#ifndef IDM_COMMON_H +#define IDM_COMMON_H #include - #include "linked_list.h" -#ifdef __cplusplus -extern "C" { -#endif - #define MAX_USER 1000 #define MAX_CREDENTIAL 5 @@ -50,10 +45,6 @@ typedef struct { void DestroyUserInfoNode(void *userInfo); void DestroyCredentialNode(void *credential); void DestroyEnrolledNode(void *enrolled); -UserInfo *InitUserInfoNode(); - -#ifdef __cplusplus -} -#endif +UserInfo *InitUserInfoNode(void); -#endif // USERIAMTA_IDM_COMMON_H \ No newline at end of file +#endif // IDM_COMMON_H \ No newline at end of file diff --git a/common/database/inc/idm_database.h b/common/database/inc/idm_database.h index 85c9c5a..9e27031 100644 --- a/common/database/inc/idm_database.h +++ b/common/database/inc/idm_database.h @@ -13,12 +13,8 @@ * limitations under the License. */ -#ifndef USERIAMTA_IDM_DATABASE_H -#define USERIAMTA_IDM_DATABASE_H - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef IDM_DATABASE_H +#define IDM_DATABASE_H #include @@ -26,9 +22,9 @@ extern "C" { #include "adaptor_memory.h" #include "idm_common.h" -ResultCode InitUserInfoList(); -void DestroyUserInfoList(); -UserInfo *InitUserInfoNode(); +ResultCode InitUserInfoList(void); +void DestroyUserInfoList(void); +UserInfo *InitUserInfoNode(void); ResultCode GetSecureUid(int32_t userId, uint64_t *secUid); ResultCode GetEnrolledInfo(int32_t userId, EnrolledInfoHal **enrolledInfos, uint32_t *num); @@ -40,8 +36,4 @@ ResultCode QueryCredentialInfoAll(int32_t userId, CredentialInfoHal **credential ResultCode QueryCredentialInfo(int32_t userId, uint32_t authType, CredentialInfoHal *credentialInfo); ResultCode DeleteCredentialInfo(int32_t userId, uint64_t credentialId, CredentialInfoHal *credentialInfo); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_IDM_DATABASE_H \ No newline at end of file +#endif // IDM_DATABASE_H \ No newline at end of file diff --git a/common/database/inc/idm_file_manager.h b/common/database/inc/idm_file_manager.h index 202ae85..3e6755e 100644 --- a/common/database/inc/idm_file_manager.h +++ b/common/database/inc/idm_file_manager.h @@ -13,24 +13,16 @@ * limitations under the License. */ -#ifndef USERIAMTA_IDM_FILE_MANAGER_H -#define USERIAMTA_IDM_FILE_MANAGER_H - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef IDM_FILE_MANAGER_H +#define IDM_FILE_MANAGER_H #include "stdint.h" #include "defines.h" #include "linked_list.h" -LinkedList *LoadFileInfo(); +LinkedList *LoadFileInfo(void); ResultCode UpdateFileInfo(LinkedList *userInfoList); ResultCode DeleteFile(); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_IDM_FILE_MANAGER_H \ No newline at end of file +#endif // IDM_FILE_MANAGER_H \ No newline at end of file diff --git a/common/database/src/idm_common.c b/common/database/src/idm_common.c index fcb9477..46c4f5a 100644 --- a/common/database/src/idm_common.c +++ b/common/database/src/idm_common.c @@ -48,7 +48,7 @@ void DestroyEnrolledNode(void *enrolled) Free(enrolled); } -UserInfo *InitUserInfoNode() +UserInfo *InitUserInfoNode(void) { UserInfo *userInfo = Malloc(sizeof(UserInfo)); if (userInfo == NULL) { diff --git a/common/database/src/idm_database.c b/common/database/src/idm_database.c index f81f6f2..2e43b8b 100644 --- a/common/database/src/idm_database.c +++ b/common/database/src/idm_database.c @@ -40,7 +40,7 @@ static CredentialInfoHal *QueryCredentialByAuthType(uint32_t authType, LinkedLis static bool MatchCredentialById(void *data, void *condition); static ResultCode GenerateDeduplicateUint64(LinkedList *collection, uint64_t *destValue, DuplicateCheckFunc func); -ResultCode InitUserInfoList() +ResultCode InitUserInfoList(void) { if (g_userInfoList != NULL) { DestroyUserInfoList(); @@ -55,7 +55,7 @@ ResultCode InitUserInfoList() return RESULT_SUCCESS; } -void DestroyUserInfoList() +void DestroyUserInfoList(void) { DestroyLinkedList(g_userInfoList); g_userInfoList = NULL; @@ -202,11 +202,7 @@ static UserInfo *QueryUserInfo(int32_t userId) LinkedListNode *temp = g_userInfoList->head; while (temp != NULL) { user = (UserInfo *)temp->data; - if (user == NULL) { - break; - } - LOG_ERROR("user->userId = %{public}d userId = %{public}d", user->userId, userId); - if (user->userId == userId) { + if (user != NULL && user->userId == userId) { break; } temp = temp->next; @@ -226,7 +222,7 @@ static ResultCode GetAllEnrolledInfoFromUser(UserInfo *userInfo, EnrolledInfoHal LinkedList *enrolledInfoList = userInfo->enrolledInfoList; uint32_t size = enrolledInfoList->getSize(enrolledInfoList); *enrolledInfos = Malloc(sizeof(EnrolledInfoHal) * size); - if (*enrolledInfos == NULL) { + if (enrolledInfos == NULL) { LOG_ERROR("enrolledInfos malloc failed"); return RESULT_NO_MEMORY; } @@ -262,7 +258,7 @@ static ResultCode GetAllCredentialInfoFromUser(UserInfo *userInfo, CredentialInf LinkedList *credentialInfoList = userInfo->credentialInfoList; uint32_t size = credentialInfoList->getSize(credentialInfoList); *credentialInfos = Malloc(sizeof(CredentialInfoHal) * size); - if (*credentialInfos == NULL) { + if (credentialInfos == NULL) { LOG_ERROR("credentialInfos malloc failed"); return RESULT_NO_MEMORY; } @@ -511,28 +507,33 @@ FAIL: ResultCode AddCredentialInfo(int32_t userId, CredentialInfoHal *credentialInfo) { - LOG_INFO("add begin"); if (credentialInfo == NULL) { LOG_ERROR("credentialInfo is null"); return RESULT_BAD_PARAM; } - if (credentialInfo->authType == PIN_AUTH) { + UserInfo *user = QueryUserInfo(userId); + if (user == NULL && credentialInfo->authType == PIN_AUTH) { ResultCode ret = AddUser(userId, credentialInfo); if (ret != RESULT_SUCCESS) { - LOG_ERROR("add user failed"); + LOG_ERROR("add user failed"); } ret = UpdateFileInfo(g_userInfoList); if (ret != RESULT_SUCCESS) { - LOG_ERROR("UpdateFileInfo failed"); - return ret; + LOG_ERROR("updateFileInfo failed"); } return ret; } - UserInfo *user = QueryUserInfo(userId); if (user == NULL) { - LOG_ERROR("Don't have this user"); + LOG_ERROR("user is null"); return RESULT_BAD_PARAM; } + if (credentialInfo->authType == PIN_AUTH) { + ResultCode ret = QueryCredentialInfo(userId, PIN_AUTH, credentialInfo); + if (ret != RESULT_NOT_FOUND) { + LOG_ERROR("double pin"); + return RESULT_BAD_PARAM; + } + } ResultCode ret = AddCredentialToUser(user, credentialInfo); if (ret != RESULT_SUCCESS) { LOG_ERROR("add credential to user failed"); @@ -540,7 +541,7 @@ ResultCode AddCredentialInfo(int32_t userId, CredentialInfoHal *credentialInfo) } ret = UpdateFileInfo(g_userInfoList); if (ret != RESULT_SUCCESS) { - LOG_ERROR("UpdateFileInfo failed"); + LOG_ERROR("updateFileInfo failed"); return ret; } return ret; @@ -565,8 +566,8 @@ static bool MatchEnrolledInfoByType(void *data, void *condition) return false; } EnrolledInfoHal *enrolledInfo = (EnrolledInfoHal *)data; - uint64_t enrolledId = *(uint64_t *)condition; - if (enrolledInfo->enrolledId == enrolledId) { + uint32_t authType = *(uint32_t *)condition; + if (enrolledInfo->authType == authType) { return true; } return false; @@ -574,7 +575,7 @@ static bool MatchEnrolledInfoByType(void *data, void *condition) ResultCode DeleteCredentialInfo(int32_t userId, uint64_t credentialId, CredentialInfoHal *credentialInfo) { - if (credentialInfo == NULL || credentialInfo->authType == PIN_AUTH) { + if (credentialInfo == NULL) { LOG_ERROR("param is invalid"); return RESULT_BAD_PARAM; } diff --git a/common/database/src/idm_file_manager.c b/common/database/src/idm_file_manager.c index 1a01ccc..ab04711 100644 --- a/common/database/src/idm_file_manager.c +++ b/common/database/src/idm_file_manager.c @@ -346,7 +346,7 @@ static Buffer *ReadFileInfo() return parcel; } -LinkedList *LoadFileInfo() +LinkedList *LoadFileInfo(void) { LOG_INFO("begin"); FileOperator *fileOperator = GetFileOperator(DEFAULT_FILE_OPERATOR); diff --git a/common/hal_sdk/coauth_interface.cpp b/common/hal_sdk/coauth_interface.cpp index 6309f6b..a9ae129 100644 --- a/common/hal_sdk/coauth_interface.cpp +++ b/common/hal_sdk/coauth_interface.cpp @@ -14,17 +14,19 @@ */ #include "coauth_interface.h" -#include "coauth_funcs.h" #include "securec.h" +extern "C" { +#include "coauth_funcs.h" #include "defines.h" #include "adaptor_log.h" +#include "lock.h" +} namespace OHOS { namespace UserIAM { namespace CoAuth { - static ExecutorInfo CopyExecutorInfoOut(const ExecutorInfoHal &executorInfoHal) { ExecutorInfo executorInfo; @@ -54,8 +56,7 @@ static ScheduleInfo CopyScheduleInfoOut(const ScheduleInfoHal &scheduleInfoHal) scheduleInfo.authSubType = scheduleInfoHal.authSubType; scheduleInfo.templateId = scheduleInfoHal.templateId; scheduleInfo.scheduleMode = scheduleInfoHal.scheduleMode; - LOG_ERROR("executorInfoNum %{public}d", scheduleInfoHal.executorInfoNum); - for (int i = 0; i < scheduleInfoHal.executorInfoNum; i++) { + for (uint32_t i = 0; i < scheduleInfoHal.executorInfoNum; i++) { ExecutorInfo executorInfo = CopyExecutorInfoOut(scheduleInfoHal.executorInfos[i]); scheduleInfo.executors.push_back(executorInfo); } @@ -65,47 +66,53 @@ static ScheduleInfo CopyScheduleInfoOut(const ScheduleInfoHal &scheduleInfoHal) int32_t GetScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo) { LOG_INFO("begin"); + GlobalLock(); if (!scheduleInfo.executors.empty()) { LOG_ERROR("param is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } ScheduleInfoHal scheduleInfoHal; int32_t ret = GetScheduleInfo(scheduleId, &scheduleInfoHal); if (ret != RESULT_SUCCESS) { LOG_ERROR("get schedule info failed"); + GlobalUnLock(); return ret; } scheduleInfo = CopyScheduleInfoOut(scheduleInfoHal); - LOG_ERROR("get schedule info schedule = %{public}llu", scheduleInfo.templateId); + GlobalUnLock(); return RESULT_SUCCESS; } int32_t DeleteScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo) { LOG_INFO("begin"); + GlobalLock(); if (!scheduleInfo.executors.empty()) { LOG_ERROR("param is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } ScheduleInfoHal scheduleInfoHal; int32_t ret = GetScheduleInfo(scheduleId, &scheduleInfoHal); if (ret != RESULT_SUCCESS) { LOG_ERROR("get schedule info failed"); + GlobalUnLock(); return ret; } scheduleInfo = CopyScheduleInfoOut(scheduleInfoHal); (void)RemoveCoAuthSchedule(scheduleId); + GlobalUnLock(); return RESULT_SUCCESS; } static Buffer *CreateBufferByVector(std::vector &executorFinishMsg) { - if (executorFinishMsg.empty() || executorFinishMsg.size() == 0) { + if (executorFinishMsg.empty()) { LOG_ERROR("vector is empty"); - LOG_ERROR("size is %{public}u", executorFinishMsg.size()); return nullptr; } - LOG_INFO("size is %{public}u", executorFinishMsg.size()); + LOG_INFO("executorFinishMsg size is %{public}u", executorFinishMsg.size()); Buffer *data = CreateBufferByData(&executorFinishMsg[0], executorFinishMsg.size()); return data; } @@ -113,44 +120,55 @@ static Buffer *CreateBufferByVector(std::vector &executorFinishMsg) int32_t GetScheduleToken(std::vector executorFinishMsg, ScheduleToken &scheduleToken) { LOG_INFO("begin"); + GlobalLock(); Buffer *executorMsg = CreateBufferByVector(executorFinishMsg); if (executorMsg == nullptr) { LOG_ERROR("create msg failed"); + GlobalUnLock(); return RESULT_NO_MEMORY; } ScheduleTokenHal scheduleTokenHal; int32_t ret = ScheduleFinish(executorMsg, &scheduleTokenHal); if (ret != RESULT_SUCCESS) { + GlobalUnLock(); return ret; } if (memcpy_s(&scheduleToken, sizeof(ScheduleToken), &scheduleTokenHal, sizeof(ScheduleTokenHal)) != EOK) { LOG_ERROR("copy scheduleToken failed"); + GlobalUnLock(); return RESULT_BAD_COPY; } - LOG_INFO("done"); + GlobalUnLock(); return RESULT_SUCCESS; } int32_t ExecutorRegister(ExecutorInfo executorInfo, uint64_t &executorId) { LOG_INFO("begin"); + GlobalLock(); ExecutorInfoHal executorInfoHal = CopyExecutorInfoIn(executorInfo); - LOG_ERROR("authType is %{public}d", executorInfoHal.authType); - return RegisterExecutor(&executorInfoHal, &executorId); + int32_t ret = RegisterExecutor(&executorInfoHal, &executorId); + GlobalUnLock(); + return ret; } int32_t ExecutorUnRegister(uint64_t executorId) { LOG_INFO("begin"); - return UnRegisterExecutor(executorId); + GlobalLock(); + int32_t ret = UnRegisterExecutor(executorId); + GlobalUnLock(); + return ret; } bool IsExecutorExist(uint32_t authType) { LOG_INFO("begin"); - return IsExecutorExistFunc(authType); -} - -} + GlobalLock(); + bool ret = IsExecutorExistFunc(authType); + GlobalUnLock(); + return ret; } -} \ No newline at end of file +} // CoAuth +} // UserIAM +} // OHOS \ No newline at end of file diff --git a/common/hal_sdk/userauth_interface.cpp b/common/hal_sdk/userauth_interface.cpp index 645f07d..1145b19 100644 --- a/common/hal_sdk/userauth_interface.cpp +++ b/common/hal_sdk/userauth_interface.cpp @@ -17,36 +17,40 @@ #include "securec.h" +extern "C" { #include "adaptor_log.h" #include "user_auth_funcs.h" #include "coauth_interface.h" #include "auth_level.h" +#include "lock.h" +} namespace OHOS { namespace UserIAM { namespace UserAuth { - int32_t GenerateSolution(AuthSolution param, std::vector &scheduleIds) { LOG_INFO("begin"); + GlobalLock(); uint64_t *scheduleIdsGet = nullptr; uint32_t scheduleIdNum = 0; AuthSolutionHal solutionIn; - param.userId = 0; - LOG_ERROR("contextId = %{public}lld, userId = %{public}d", param.contextId, param.userId); if (memcpy_s(&solutionIn, sizeof(AuthSolutionHal), ¶m, sizeof(AuthSolution)) != EOK) { LOG_ERROR("copy failed"); + GlobalUnLock(); return RESULT_BAD_COPY; } int32_t ret = GenerateSolutionFunc(solutionIn, &scheduleIdsGet, &scheduleIdNum); if (ret != RESULT_SUCCESS) { LOG_ERROR("generate solution failed"); + GlobalUnLock(); return ret; } for (uint32_t i = 0; i < scheduleIdNum; i++) { scheduleIds.push_back(scheduleIdsGet[i]); } free(scheduleIdsGet); + GlobalUnLock(); return RESULT_SUCCESS; } @@ -54,13 +58,16 @@ int32_t RequestAuthResult(uint64_t contextId, std::vector &scheduleToke std::vector &scheduleIds) { LOG_INFO("begin"); + GlobalLock(); if (scheduleToken.size() != sizeof(CoAuth::ScheduleToken)) { LOG_ERROR("param is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } Buffer *scheduleTokenBuffer = CreateBufferByData(&scheduleToken[0], scheduleToken.size()); if (scheduleTokenBuffer == nullptr) { LOG_ERROR("scheduleTokenBuffer is null"); + GlobalUnLock(); return RESULT_NO_MEMORY; } UserAuthTokenHal authTokenHal; @@ -70,39 +77,51 @@ int32_t RequestAuthResult(uint64_t contextId, std::vector &scheduleToke if (ret != RESULT_SUCCESS) { LOG_ERROR("execute func failed"); DestoryBuffer(scheduleTokenBuffer); + GlobalUnLock(); return ret; } + if (memcpy_s(&authToken, sizeof(UserAuthToken), &authTokenHal, sizeof(UserAuthTokenHal)) != EOK) { + LOG_ERROR("copy authToken failed"); + GlobalUnLock(); + return RESULT_BAD_COPY; + } for (uint32_t i = 0; i < scheduleIdNum; i++) { scheduleIds.push_back(scheduleIdsGet[i]); } free(scheduleIdsGet); DestoryBuffer(scheduleTokenBuffer); + GlobalUnLock(); return RESULT_SUCCESS; } int32_t CancelContext(uint64_t contextId, std::vector &scheduleIds) { LOG_INFO("begin"); + GlobalLock(); uint64_t *scheduleIdsGet = nullptr; uint32_t scheduleIdNum = 0; int32_t ret = CancelContextFunc(contextId, &scheduleIdsGet, &scheduleIdNum); if (ret != RESULT_SUCCESS) { LOG_ERROR("execute func failed"); + GlobalUnLock(); return ret; } for (uint32_t i = 0; i < scheduleIdNum; i++) { scheduleIds.push_back(scheduleIdsGet[i]); } free(scheduleIdsGet); + GlobalUnLock(); return RESULT_SUCCESS; } int32_t GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel) { LOG_INFO("begin"); - return SingleAuthTrustLevel(userId, authType, &authTrustLevel); -} - -} + GlobalLock(); + int32_t ret = SingleAuthTrustLevel(userId, authType, &authTrustLevel); + GlobalUnLock(); + return ret; } -} \ No newline at end of file +} // UserAuth +} // UserIAM +} // OHOS \ No newline at end of file diff --git a/common/hal_sdk/useriam_common.cpp b/common/hal_sdk/useriam_common.cpp index bc65033..f64231d 100644 --- a/common/hal_sdk/useriam_common.cpp +++ b/common/hal_sdk/useriam_common.cpp @@ -15,20 +15,31 @@ #include "useriam_common.h" +extern "C" { +#include +#include + #include "pool.h" #include "idm_database.h" #include "coauth.h" #include "context_manager.h" #include "adaptor_log.h" +#include "lock.h" +} namespace OHOS { namespace UserIAM { namespace Common { - -bool g_isInitUserIAM = false; +static const char *IDM_USER_FOLDER = "/data/useriam"; +static bool g_isInitUserIAM = false; int32_t Init() { + GlobalLock(); + LOG_INFO("check useriam folder exist or init it."); + if (IDM_USER_FOLDER && access(IDM_USER_FOLDER, 0) == -1) { + mkdir(IDM_USER_FOLDER, S_IRWXU); + } if (InitUserAuthContextList() != RESULT_SUCCESS) { LOG_ERROR("init user auth failed"); goto FAIL; @@ -46,20 +57,24 @@ int32_t Init() goto FAIL; } g_isInitUserIAM = true; + GlobalUnLock(); return RESULT_SUCCESS; FAIL: Close(); + GlobalUnLock(); return RESULT_UNKNOWN; } int32_t Close() { + GlobalLock(); DestoryUserAuthContextList(); DestoryCoAuth(); DestroyUserInfoList(); DestroyResorcePool(); g_isInitUserIAM = false; + GlobalUnLock(); return RESULT_SUCCESS; } @@ -67,7 +82,6 @@ bool IsIAMInited() { return g_isInitUserIAM; } - -} -} -} \ No newline at end of file +} // Common +} // UserIAM +} // OHOS \ No newline at end of file diff --git a/common/hal_sdk/useridm_interface.cpp b/common/hal_sdk/useridm_interface.cpp index 7a404f0..da126ba 100644 --- a/common/hal_sdk/useridm_interface.cpp +++ b/common/hal_sdk/useridm_interface.cpp @@ -17,95 +17,117 @@ #include "securec.h" +extern "C" { #include "idm_session.h" #include "user_idm_funcs.h" #include "adaptor_log.h" #include "coauth_interface.h" #include "coauth_sign_centre.h" #include "idm_database.h" +#include "lock.h" +} namespace OHOS { namespace UserIAM { namespace UserIDM { namespace Hal { - -typedef struct { +struct CredentialInfo { uint64_t credentialId; uint32_t authType; uint64_t authSubType; uint64_t templateId; -} CredentialInfo; +}; -typedef struct { +struct EnrolledInfo { uint32_t authType; uint64_t enrolledId; -} EnrolledInfo; +}; int32_t OpenSession(int32_t userId, uint64_t &challenge) { - return OpenEditSession(userId, &challenge); + GlobalLock(); + int32_t ret = OpenEditSession(userId, &challenge); + LOG_INFO("challenge is %{public}llu", challenge); + GlobalUnLock(); + return ret; } int32_t CloseSession() { - return CloseEditSession(); + GlobalLock(); + int32_t ret = CloseEditSession(); + GlobalUnLock(); + return ret; } -int32_t GetScheduleId(std::vector authToken, int32_t userId, uint32_t authType, uint64_t authSubType, +int32_t InitSchedulation(std::vector authToken, int32_t userId, uint32_t authType, uint64_t authSubType, uint64_t &scheduleId) { LOG_INFO("begin"); + GlobalLock(); if (authToken.size() != sizeof(UserAuth::UserAuthToken) && authType != PIN_AUTH) { LOG_ERROR("authToken len is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } - LOG_ERROR("1111"); PermissionCheckParam param; - if (authToken.size() == sizeof(UserAuth::UserAuthToken) && + if (authToken.size() == sizeof(UserAuth::UserAuthToken) && memcpy_s(param.token, AUTH_TOKEN_LEN, &authToken[0], authToken.size()) != EOK) { - LOG_ERROR("1111"); + GlobalUnLock(); return RESULT_BAD_COPY; } - LOG_ERROR("1111"); param.authType = authType; param.userId = userId; param.authSubType = authSubType; - return CheckEnrollPermission(param, &scheduleId); + int32_t ret = CheckEnrollPermission(param, &scheduleId); + GlobalUnLock(); + return ret; } -int32_t CancelScheduleId(uint64_t &scheduleId) +int32_t DeleteScheduleId(uint64_t &scheduleId) { LOG_INFO("begin"); - return CancelScheduleIdFunc(&scheduleId); + GlobalLock(); + int32_t ret = CancelScheduleIdFunc(&scheduleId); + GlobalUnLock(); + return ret; } int32_t AddCredential(std::vector enrollToken, uint64_t &credentialId) { LOG_INFO("begin"); + GlobalLock(); if (enrollToken.size() != sizeof(CoAuth::ScheduleToken)) { - LOG_ERROR("enrollToken is invalid %{public}u", enrollToken.size()); + LOG_ERROR("enrollToken is invalid, size is %{public}u", enrollToken.size()); + GlobalUnLock(); return RESULT_BAD_PARAM; } uint8_t enrollTokenIn[sizeof(ScheduleTokenHal)]; if (memcpy_s(enrollTokenIn, sizeof(ScheduleTokenHal), &enrollToken[0], enrollToken.size()) != EOK) { LOG_ERROR("enrollToken copy failed"); + GlobalUnLock(); return RESULT_BAD_COPY; } - return AddCredentialFunc(enrollTokenIn, (uint32_t)sizeof(ScheduleTokenHal), &credentialId); + int32_t ret = AddCredentialFunc(enrollTokenIn, (uint32_t)sizeof(ScheduleTokenHal), &credentialId); + GlobalUnLock(); + return ret; } int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector authToken, CredentialInfo &credentialInfo) { LOG_INFO("begin"); + GlobalLock(); authToken.resize(sizeof(UserAuth::UserAuthToken)); if (authToken.size() != sizeof(UserAuth::UserAuthToken)) { LOG_ERROR("authToken len is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } CredentialDeleteParam param; if (memcpy_s(param.token, AUTH_TOKEN_LEN, &authToken[0], authToken.size()) != EOK) { LOG_ERROR("param token copy failed"); + GlobalUnLock(); return RESULT_BAD_COPY; } param.userId = userId; @@ -114,48 +136,57 @@ int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector &credentialInfos) { LOG_INFO("begin"); + GlobalLock(); CredentialInfoHal *credentialInfoHals = nullptr; uint32_t num = 0; int32_t ret = QueryCredentialFunc(userId, authType, &credentialInfoHals, &num); if (ret != RESULT_SUCCESS) { LOG_ERROR("query credential failed"); + GlobalUnLock(); return ret; } for (int i = 0; i < num; i++) { CredentialInfo credentialInfo; - if (memcpy_s(&credentialInfo, sizeof(CredentialInfo), + if (memcpy_s(&credentialInfo, sizeof(CredentialInfo), &credentialInfoHals[i], sizeof(CredentialInfoHal)) != EOK) { LOG_ERROR("credentialInfo copy failed"); free(credentialInfoHals); credentialInfos.clear(); + GlobalUnLock(); return RESULT_BAD_COPY; } credentialInfos.push_back(credentialInfo); } free(credentialInfoHals); + GlobalUnLock(); return RESULT_SUCCESS; } int32_t GetSecureUid(int32_t userId, uint64_t &secureUid, std::vector &enrolledInfos) { LOG_INFO("begin"); + GlobalLock(); EnrolledInfoHal *enrolledInfoHals = nullptr; uint32_t num = 0; int32_t ret = GetUserSecureUidFunc(userId, &secureUid, &enrolledInfoHals, &num); if (ret != RESULT_SUCCESS) { LOG_ERROR("get user secureUid failed"); + GlobalUnLock(); return ret; } for (int i = 0; i < num; i++) { @@ -164,92 +195,109 @@ int32_t GetSecureUid(int32_t userId, uint64_t &secureUid, std::vector &credentialInfos) { LOG_INFO("begin"); + GlobalLock(); CredentialInfoHal *credentialInfoHals = nullptr; uint32_t num = 0; int32_t ret = DeleteUserInfo(userId, &credentialInfoHals, &num); if (ret != RESULT_SUCCESS) { LOG_ERROR("query credential failed"); + GlobalUnLock(); return ret; } for (int i = 0; i < num; i++) { CredentialInfo credentialInfo; - if (memcpy_s(&credentialInfo, sizeof(CredentialInfo), + if (memcpy_s(&credentialInfo, sizeof(CredentialInfo), &credentialInfoHals[i], sizeof(CredentialInfoHal)) != EOK) { LOG_ERROR("credentialInfo copy failed"); free(credentialInfoHals); credentialInfos.clear(); + GlobalUnLock(); return RESULT_BAD_COPY; } credentialInfos.push_back(credentialInfo); } free(credentialInfoHals); + GlobalUnLock(); return RESULT_SUCCESS; } int32_t DeleteUser(int32_t userId, std::vector authToken, std::vector &credentialInfos) { LOG_INFO("begin"); + GlobalLock(); authToken.resize(sizeof(UserAuthTokenHal)); if (authToken.size() != sizeof(UserAuthTokenHal)) { LOG_ERROR("authToken is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } - // UserAuthTokenHal authTokenStruct; - // if (memcpy_s(&authTokenStruct, sizeof(UserAuthTokenHal), &authToken[0], authToken.size()) != EOK) { - // LOG_ERROR("authTokenStruct copy failed"); - // return RESULT_BAD_COPY; - // } - // uint64_t challenge; - // int32_t ret = GetChallenge(&challenge); - // if (ret != RESULT_SUCCESS) { - // LOG_ERROR("get challenge failed"); - // return ret; - // } - // if (challenge != authTokenStruct.challenge || UserAuthTokenVerify(&authTokenStruct) != RESULT_SUCCESS) { - // LOG_ERROR("verify token failed"); - // return RESULT_BAD_SIGN; - // } + UserAuthTokenHal authTokenStruct; + if (memcpy_s(&authTokenStruct, sizeof(UserAuthTokenHal), &authToken[0], authToken.size()) != EOK) { + LOG_ERROR("authTokenStruct copy failed"); + GlobalUnLock(); + return RESULT_BAD_COPY; + } + uint64_t challenge; + int32_t ret = GetChallenge(&challenge); + if (ret != RESULT_SUCCESS) { + LOG_ERROR("get challenge failed"); + GlobalUnLock(); + return ret; + } + if (challenge != authTokenStruct.challenge || UserAuthTokenVerify(&authTokenStruct) != RESULT_SUCCESS) { + LOG_ERROR("verify token failed"); + GlobalUnLock(); + return RESULT_BAD_SIGN; + } + GlobalUnLock(); return DeleteUserEnforce(userId, credentialInfos); } int32_t UpdateCredential(std::vector enrollToken, uint64_t &credentialId, CredentialInfo &deletedCredential) { LOG_INFO("begin"); + GlobalLock(); if (enrollToken.size() != sizeof(CoAuth::ScheduleToken)) { LOG_ERROR("enrollToken is invalid"); + GlobalUnLock(); return RESULT_BAD_PARAM; } uint8_t enrollTokenIn[sizeof(ScheduleTokenHal)]; if (memcpy_s(enrollTokenIn, sizeof(ScheduleTokenHal), &enrollToken[0], enrollToken.size()) != EOK) { LOG_ERROR("enrollToken copy failed"); + GlobalUnLock(); return RESULT_BAD_COPY; } CredentialInfoHal credentialInfoHal; - int32_t ret = + int32_t ret = UpdateCredentialFunc(enrollTokenIn, (uint32_t)sizeof(ScheduleTokenHal), &credentialId, &credentialInfoHal); if (ret != RESULT_SUCCESS) { LOG_ERROR("update failed"); + GlobalUnLock(); return ret; } if (memcpy_s(&deletedCredential, sizeof(CredentialInfo), &credentialInfoHal, sizeof(CredentialInfoHal)) != EOK) { LOG_ERROR("copy failed"); + GlobalUnLock(); return RESULT_BAD_COPY; } + GlobalUnLock(); return RESULT_SUCCESS; } - -} -} -} -} \ No newline at end of file +} // Hal +} // UserIDM +} // UserIAM +} // OHOS \ No newline at end of file diff --git a/common/idm/inc/idm_session.h b/common/idm/inc/idm_session.h index 3cb81f8..e0acda7 100644 --- a/common/idm/inc/idm_session.h +++ b/common/idm/inc/idm_session.h @@ -20,23 +20,15 @@ #include "stdint.h" #include "stdbool.h" -#ifdef __cplusplus -extern "C" { -#endif - ResultCode OpenEditSession(int32_t userId, uint64_t *challenge); ResultCode CloseEditSession(); ResultCode AssociateCoauthSchedule(uint64_t scheduleId); -void BreakOffCoauthSchedule(); +void BreakOffCoauthSchedule(void); -bool IsSessionTimeout(); +bool IsSessionTimeout(void); ResultCode GetUserId(int32_t *userId); ResultCode GetChallenge(uint64_t *challenge); ResultCode GetScheduleId(uint64_t *scheduleId); -#ifdef __cplusplus -} -#endif - #endif // USER_IDM_SESSION_H \ No newline at end of file diff --git a/common/idm/inc/user_idm_funcs.h b/common/idm/inc/user_idm_funcs.h index a9b0715..4702d0c 100644 --- a/common/idm/inc/user_idm_funcs.h +++ b/common/idm/inc/user_idm_funcs.h @@ -20,10 +20,6 @@ #include "idm_session.h" #include "user_sign_centre.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { uint8_t token[AUTH_TOKEN_LEN]; int32_t userId; @@ -42,13 +38,10 @@ int32_t AddCredentialFunc(const uint8_t *enrollToken, uint32_t tokenLen, uint64_ int32_t DeleteCredentialFunc(CredentialDeleteParam param, CredentialInfoHal *credentialInfo); int32_t QueryCredentialFunc(int32_t userId, uint32_t authType, CredentialInfoHal **credentialInfoArray, uint32_t *credentialNum); -int32_t GetUserSecureUidFunc(int32_t userId, uint64_t *secureUid, EnrolledInfoHal **enrolledInfoArray, uint32_t *enrolledNum); +int32_t GetUserSecureUidFunc(int32_t userId, uint64_t *secureUid, EnrolledInfoHal **enrolledInfoArray, + uint32_t *enrolledNum); int32_t CancelScheduleIdFunc(uint64_t *scheduleId); int32_t UpdateCredentialFunc(const uint8_t *enrollToken, uint32_t tokenLen, uint64_t *credentialId, CredentialInfoHal *deletedCredential); - -#ifdef __cplusplus -} -#endif #endif // USER_IDM_FUNCS_H diff --git a/common/idm/src/idm_session.c b/common/idm/src/idm_session.c index 7520082..d01a83a 100644 --- a/common/idm/src/idm_session.c +++ b/common/idm/src/idm_session.c @@ -79,7 +79,6 @@ ResultCode OpenEditSession(int32_t userId, uint64_t *challenge) LOG_ERROR("challenge is invalid"); Free(g_session); g_session = NULL; - return RESULT_GENERAL_ERROR; } g_session->time = GetSystemTime(); @@ -128,7 +127,7 @@ ResultCode AssociateCoauthSchedule(uint64_t scheduleId) return RESULT_SUCCESS; } -void BreakOffCoauthSchedule() +void BreakOffCoauthSchedule(void) { if (!IsSessionExist()) { return; @@ -149,7 +148,7 @@ ResultCode GetScheduleId(uint64_t *scheduleId) return RESULT_SUCCESS; } -bool IsSessionTimeout() +bool IsSessionTimeout(void) { if (!IsSessionExist()) { return RESULT_NEED_INIT; @@ -159,6 +158,5 @@ bool IsSessionTimeout() LOG_ERROR("timeout, %{public}llu, %{public}llu", currentTime, g_session->time); return true; } - LOG_ERROR("time not out, %{public}llu, %{public}llu", currentTime, g_session->time); return false; } \ No newline at end of file diff --git a/common/idm/src/user_idm_funcs.c b/common/idm/src/user_idm_funcs.c index dd4bc74..2aa0fa7 100644 --- a/common/idm/src/user_idm_funcs.c +++ b/common/idm/src/user_idm_funcs.c @@ -145,7 +145,6 @@ int32_t AddCredentialFunc(const uint8_t *enrollToken, uint32_t tokenLen, uint64_ if (ret == RESULT_SUCCESS) { *credentialId = credentialInfo.credentialId; } - LOG_ERROR("credentialId = %{public}llu", *credentialId); return ret; } @@ -155,25 +154,25 @@ int32_t DeleteCredentialFunc(CredentialDeleteParam param, CredentialInfoHal *cre LOG_ERROR("param is null"); return RESULT_BAD_PARAM; } - // UserAuthTokenHal token; - // if (memcpy_s(&token, sizeof(UserAuthTokenHal), param.token, AUTH_TOKEN_LEN) != EOK) { - // LOG_ERROR("token copy failed"); - // return RESULT_BAD_COPY; - // } + UserAuthTokenHal token; + if (memcpy_s(&token, sizeof(UserAuthTokenHal), param.token, AUTH_TOKEN_LEN) != EOK) { + LOG_ERROR("token copy failed"); + return RESULT_BAD_COPY; + } - // uint64_t challenge; - // int32_t ret = GetChallenge(&challenge); - // if (ret != RESULT_SUCCESS || challenge != token.challenge || IsSessionTimeout()) { - // LOG_ERROR("check challenge failed"); - // return RESULT_BAD_SIGN; - // } + uint64_t challenge; + int32_t ret = GetChallenge(&challenge); + if (ret != RESULT_SUCCESS || challenge != token.challenge || IsSessionTimeout()) { + LOG_ERROR("check challenge failed"); + return RESULT_BAD_SIGN; + } - // ret = UserAuthTokenVerify(&token); - // if (ret != RESULT_SUCCESS) { - // LOG_ERROR("failed to verify the token"); - // return RESULT_BAD_SIGN; - // } - int32_t ret = DeleteCredentialInfo(param.userId, param.credentialId, credentialInfo); + ret = UserAuthTokenVerify(&token); + if (ret != RESULT_SUCCESS) { + LOG_ERROR("failed to verify the token"); + return RESULT_BAD_SIGN; + } + ret = DeleteCredentialInfo(param.userId, param.credentialId, credentialInfo); if (ret != RESULT_SUCCESS) { LOG_ERROR("delete database info failed"); return RESULT_BAD_SIGN; @@ -198,7 +197,7 @@ int32_t QueryCredentialFunc(int32_t userId, uint32_t authType, } *credentialInfoArray = Malloc(sizeof(CredentialInfoHal)); - if (*credentialInfoArray == NULL) { + if (credentialInfoArray == NULL) { LOG_ERROR("credentialInfoArray malloc failed"); return RESULT_NO_MEMORY; } @@ -212,7 +211,8 @@ int32_t QueryCredentialFunc(int32_t userId, uint32_t authType, return RESULT_SUCCESS; } -int32_t GetUserSecureUidFunc(int32_t userId, uint64_t *secureUid, EnrolledInfoHal **enrolledInfoArray, uint32_t *enrolledNum) +int32_t GetUserSecureUidFunc(int32_t userId, uint64_t *secureUid, EnrolledInfoHal **enrolledInfoArray, + uint32_t *enrolledNum) { if (secureUid == NULL || enrolledInfoArray == NULL || enrolledNum == NULL) { LOG_ERROR("param is null"); @@ -245,7 +245,8 @@ int32_t CancelScheduleIdFunc(uint64_t *scheduleId) int32_t UpdateCredentialFunc(const uint8_t *enrollToken, uint32_t tokenLen, uint64_t *credentialId, CredentialInfoHal *deletedCredential) { - if (enrollToken == NULL || credentialId == NULL || tokenLen != sizeof(ScheduleTokenHal) || deletedCredential == NULL) { + if (enrollToken == NULL || credentialId == NULL || tokenLen != sizeof(ScheduleTokenHal) || + deletedCredential == NULL) { LOG_ERROR("param is invalid"); return RESULT_BAD_PARAM; } diff --git a/common/interface/coauth_interface.h b/common/interface/coauth_interface.h index 350e60d..090b470 100644 --- a/common/interface/coauth_interface.h +++ b/common/interface/coauth_interface.h @@ -12,18 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifndef USER_IAM_COAUTH_INTERFACE #define USER_IAM_COAUTH_INTERFACE -#include "stdint.h" #include "vector" #include "common_defines.h" namespace OHOS { namespace UserIAM { namespace CoAuth { - typedef struct { uint32_t scheduleResult; uint64_t scheduleId; @@ -60,7 +57,6 @@ int32_t GetScheduleToken(std::vector executorFinishMsg, ScheduleToken & int32_t ExecutorRegister(ExecutorInfo executorInfo, uint64_t &executorId); int32_t ExecutorUnRegister(uint64_t executorId); bool IsExecutorExist(uint32_t authType); - } } } diff --git a/common/interface/userauth_interface.h b/common/interface/userauth_interface.h index 499d620..4d987e2 100644 --- a/common/interface/userauth_interface.h +++ b/common/interface/userauth_interface.h @@ -24,7 +24,6 @@ namespace OHOS { namespace UserIAM { namespace UserAuth { - typedef struct { uint64_t contextId; int32_t userId; @@ -35,7 +34,11 @@ typedef struct { typedef struct { int32_t authResult; - AuthSolution authSolution; + uint64_t contextId; + int32_t userId; + uint64_t challenge; + uint32_t authType; + uint32_t authTrustLevel; uint64_t enrolledId; uint32_t version; uint64_t time; @@ -47,9 +50,8 @@ int32_t RequestAuthResult(uint64_t contextId, std::vector &scheduleToke std::vector &scheduleIds); int32_t CancelContext(uint64_t contextId, std::vector &scheduleIds); int32_t GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel); - -} -} -} +} // UserAuth +} // UserIAM +} // OHOS #endif // USER_IAM_USERAUTH_INTERFACE \ No newline at end of file diff --git a/common/interface/useriam_common.h b/common/interface/useriam_common.h index 18fe0cd..ec86c1e 100644 --- a/common/interface/useriam_common.h +++ b/common/interface/useriam_common.h @@ -22,13 +22,11 @@ namespace OHOS { namespace UserIAM { namespace Common { - int32_t Init(); int32_t Close(); bool IsIAMInited(); - -} -} -} +} // Common +} // UserIAM +} // OHOS #endif // USER_IAM_COMMON_INTERFACE \ No newline at end of file diff --git a/common/interface/useridm_interface.h b/common/interface/useridm_interface.h index 2b5b0bf..e73dcc0 100644 --- a/common/interface/useridm_interface.h +++ b/common/interface/useridm_interface.h @@ -23,7 +23,6 @@ namespace OHOS { namespace UserIAM { namespace UserIDM { namespace Hal { - typedef struct { uint64_t credentialId; uint32_t authType; @@ -39,9 +38,9 @@ typedef struct { int32_t OpenSession(int32_t userId, uint64_t &challenge); int32_t CloseSession(); -int32_t GetScheduleId(std::vector authToken, int32_t userId, uint32_t authType, uint64_t authSubType, +int32_t InitSchedulation(std::vector authToken, int32_t userId, uint32_t authType, uint64_t authSubType, uint64_t &scheduleId); -int32_t CancelScheduleId(uint64_t &scheduleId); +int32_t DeleteScheduleId(uint64_t &scheduleId); int32_t AddCredential(std::vector enrollToken, uint64_t &credentialId); int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector authToken, CredentialInfo &credentialInfo); @@ -50,10 +49,9 @@ int32_t GetSecureUid(int32_t userId, uint64_t &secureUid, std::vector authToken, std::vector &credentialInfos); int32_t DeleteUserEnforce(int32_t userId, std::vector &credentialInfos); int32_t UpdateCredential(std::vector enrollToken, uint64_t &credentialId, CredentialInfo &deletedCredential); - -} -} -} -} +} // Hal +} // UserIDM +} // UserIAM +} // OHOS #endif // USER_IAM_USERIDM_INTERFACE \ No newline at end of file diff --git a/common/lock/inc/lock.h b/common/lock/inc/lock.h new file mode 100644 index 0000000..a861bb5 --- /dev/null +++ b/common/lock/inc/lock.h @@ -0,0 +1,22 @@ +/* + * 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. + */ + +#ifndef USER_IAM_LOCK +#define USER_IAM_LOCK + +void GlobalLock(void); +void GlobalUnLock(void); + +#endif \ No newline at end of file diff --git a/common/adaptor/src/adaptor_log.c b/common/lock/src/lock.c similarity index 49% rename from common/adaptor/src/adaptor_log.c rename to common/lock/src/lock.c index bc962bb..7900241 100644 --- a/common/adaptor/src/adaptor_log.c +++ b/common/lock/src/lock.c @@ -1,41 +1,30 @@ -/* - * 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. - */ - -#include "adaptor_log.h" - -#include "hilog/log_c.h" - -#ifndef LOG_DOMAIN -#define LOG_DOMAIN 0xD002422 -#endif -#ifndef APP_LOG_TAG -#define APP_LOG_TAG "IamBase" -#endif - -void LogInfo(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, format, ap); - va_end(ap); -} - -void LogError(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, format, ap); - va_end(ap); +/* + * 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. + */ + +#include "lock.h" + +#include "pthread.h" + +static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; + +void GlobalLock(void) +{ + (void)pthread_mutex_lock(&g_mutex); +} + +void GlobalUnLock(void) +{ + (void)pthread_mutex_unlock(&g_mutex); } \ No newline at end of file diff --git a/common/ohos.build b/common/ohos.build deleted file mode 100644 index 5fdb323..0000000 --- a/common/ohos.build +++ /dev/null @@ -1,10 +0,0 @@ -{ - "subsystem": "useriam", - "parts": { - "useriam_common": { - "module_list": [ - "//base/useriam/coauth/common:useriam_common_lib" - ] - } - } -} \ No newline at end of file diff --git a/common/pool/inc/pool.h b/common/pool/inc/pool.h index 31011e4..c246391 100644 --- a/common/pool/inc/pool.h +++ b/common/pool/inc/pool.h @@ -19,10 +19,6 @@ #include "buffer.h" #include "linked_list.h" -#ifdef __cplusplus -extern "C" { -#endif - #define PUBLIC_KEY_LEN 32 typedef enum ExecutorType { @@ -40,15 +36,11 @@ typedef struct ExecutorInfoHal { uint8_t pubKey[PUBLIC_KEY_LEN]; } ExecutorInfoHal; -ResultCode InitResorcePool(); -void DestroyResorcePool(); +ResultCode InitResorcePool(void); +void DestroyResorcePool(void); ResultCode RegisterExecutorToPool(ExecutorInfoHal *executorInfo); ResultCode UnregisterExecutorToPool(uint64_t executorId); ResultCode QueryExecutor(uint32_t authType, LinkedList **result); ExecutorInfoHal *CopyExecutorInfo(ExecutorInfoHal *src); -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/pool/src/pool.c b/common/pool/src/pool.c index edff8cf..ad1ffad 100644 --- a/common/pool/src/pool.c +++ b/common/pool/src/pool.c @@ -51,7 +51,7 @@ static bool IsInit() return g_poolList != NULL; } -ResultCode InitResorcePool() +ResultCode InitResorcePool(void) { if (!IsInit()) { g_poolList = CreateLinkedList(DestroyExecutorInfo); @@ -62,7 +62,7 @@ ResultCode InitResorcePool() return RESULT_SUCCESS; } -void DestroyResorcePool() +void DestroyResorcePool(void) { DestroyLinkedList(g_poolList); g_poolList = NULL; @@ -136,7 +136,6 @@ ResultCode RegisterExecutorToPool(ExecutorInfoHal *executorInfo) return RESULT_NO_MEMORY; } result = g_poolList->insert(g_poolList, (void *)executorCopy); - LOG_ERROR("CopyExecutorInfo done authType is %{public}d", ((ExecutorInfoHal *)g_poolList->head->data)->authType); if (result != RESULT_SUCCESS) { LOG_ERROR("insert fail"); DestroyExecutorInfo(executorCopy); @@ -170,7 +169,6 @@ ExecutorInfoHal *CopyExecutorInfo(ExecutorInfoHal *src) Free(dest); return NULL; } - LOG_ERROR("CopyExecutorInfo done authType is %{public}d", dest->authType); return dest; } @@ -195,15 +193,13 @@ ResultCode QueryExecutor(uint32_t authType, LinkedList **result) DestroyLinkedList(*result); return RESULT_NO_MEMORY; } - - LOG_ERROR("execute num %{public}d", g_poolList->getSize(g_poolList)); //del + while (iterator->hasNext(iterator)) { ExecutorInfoHal *executorInfo = (ExecutorInfoHal *)iterator->next(iterator); if (!IsExecutorValid(executorInfo)) { LOG_ERROR("get invalid executor info"); continue; } - LOG_ERROR("get invalid executor info %{public}d, %{public}d", executorInfo->authType, authType); //del if (executorInfo->authType != authType) { continue; } diff --git a/common/user_auth/inc/auth_level.h b/common/user_auth/inc/auth_level.h index 52cb1be..effd66c 100644 --- a/common/user_auth/inc/auth_level.h +++ b/common/user_auth/inc/auth_level.h @@ -13,21 +13,13 @@ * limitations under the License. */ -#ifndef USERIAMTA_TRUST_LEVEL_H -#define USERIAMTA_TRUST_LEVEL_H +#ifndef USERIAM_TRUST_LEVEL_H +#define USERIAM_TRUST_LEVEL_H #include #include "defines.h" -#ifdef __cplusplus -extern "C" { -#endif - ResultCode SingleAuthTrustLevel(uint32_t userId, uint32_t authType, uint32_t *atl); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_TRUST_LEVEL_H \ No newline at end of file +#endif // USERIAM_TRUST_LEVEL_H \ No newline at end of file diff --git a/common/user_auth/inc/context_manager.h b/common/user_auth/inc/context_manager.h index fb6770c..1756d01 100644 --- a/common/user_auth/inc/context_manager.h +++ b/common/user_auth/inc/context_manager.h @@ -13,15 +13,11 @@ * limitations under the License. */ -#ifndef USERIAMTA_CONTEXT_MANAGER_H -#define USERIAMTA_CONTEXT_MANAGER_H +#ifndef USERIAM_CONTEXT_MANAGER_H +#define USERIAM_CONTEXT_MANAGER_H #include "linked_list.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct UserAuthContext { uint64_t contextId; int32_t userId; @@ -40,7 +36,7 @@ typedef struct { } AuthSolutionHal; ResultCode InitUserAuthContextList(); -void DestoryUserAuthContextList(); +void DestoryUserAuthContextList(void); UserAuthContext *GenerateContext(AuthSolutionHal params); UserAuthContext *GetContext(uint64_t contextId); @@ -48,8 +44,4 @@ ResultCode ScheduleOnceFinish(UserAuthContext *context, uint64_t scheduleId); void DestoryContext(UserAuthContext *context); ResultCode GetScheduleIds(UserAuthContext *context, uint64_t **scheduleIds, uint32_t *scheduleNum); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_CONTEXT_MANAGER_H \ No newline at end of file +#endif // USERIAM_CONTEXT_MANAGER_H \ No newline at end of file diff --git a/common/user_auth/inc/user_auth_funcs.h b/common/user_auth/inc/user_auth_funcs.h index e480e56..4c6dbf6 100644 --- a/common/user_auth/inc/user_auth_funcs.h +++ b/common/user_auth/inc/user_auth_funcs.h @@ -21,10 +21,6 @@ #include "user_sign_centre.h" #include "context_manager.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { uint64_t scheduleId; uint8_t ExecutorSign[SHA256_SIGN_LEN]; @@ -35,8 +31,4 @@ int32_t RequestAuthResultFunc(uint64_t contextId, const Buffer *scheduleToken, U uint64_t **scheduleIdArray, uint32_t *scheduleNum); int32_t CancelContextFunc(uint64_t contextId, uint64_t **scheduleIdArray, uint32_t *scheduleNum); -#ifdef __cplusplus -} -#endif - #endif // USER_AUTH_FUNCS_H diff --git a/common/user_auth/inc/user_sign_centre.h b/common/user_auth/inc/user_sign_centre.h index 877c7c1..9a43f53 100644 --- a/common/user_auth/inc/user_sign_centre.h +++ b/common/user_auth/inc/user_sign_centre.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef USERIAMTA_USER_SIGN_CENTRE_H -#define USERIAMTA_USER_SIGN_CENTRE_H +#ifndef USERIAM_USER_SIGN_CENTRE_H +#define USERIAM_USER_SIGN_CENTRE_H #include @@ -22,10 +22,6 @@ #include "defines.h" #include "user_sign_centre.h" -#ifdef __cplusplus -extern "C" { -#endif - #define SHA256_SIGN_LEN 32 #define AUTH_TOKEN_LEN sizeof(UserAuthTokenHal) #define AUTH_TOKEN_DATA_LEN (AUTH_TOKEN_LEN - SHA256_SIGN_LEN) @@ -48,8 +44,4 @@ typedef struct { ResultCode UserAuthTokenSign(UserAuthTokenHal *userAuthToken); ResultCode UserAuthTokenVerify(const UserAuthTokenHal *userAuthToken); -#ifdef __cplusplus -} -#endif - -#endif // USERIAMTA_USER_SIGN_CENTRE_H \ No newline at end of file +#endif // USERIAM_USER_SIGN_CENTRE_H \ No newline at end of file diff --git a/common/user_auth/src/auth_level.c b/common/user_auth/src/auth_level.c index 159caf7..097cf89 100644 --- a/common/user_auth/src/auth_level.c +++ b/common/user_auth/src/auth_level.c @@ -118,13 +118,12 @@ ResultCode SingleAuthTrustLevel(uint32_t userId, uint32_t authType, uint32_t *at return ret; } - for (uint32_t i = 0; i < sizeof(g_generationAtl) / sizeof(AtlGeneration); i++) { + for (uint32_t i = 0; i < sizeof(g_generationAtl) / sizeof(g_generationAtl); i++) { if (authSecureLevel == g_generationAtl[i].asl && authCapabilityLevel == g_generationAtl[i].acl) { *atl = g_generationAtl[i].atl; return RESULT_SUCCESS; } } - LOG_ERROR("can't find the atl"); return RESULT_NOT_FOUND; } \ No newline at end of file diff --git a/common/user_auth/src/context_manager.c b/common/user_auth/src/context_manager.c index 8c21a37..dfa172a 100644 --- a/common/user_auth/src/context_manager.c +++ b/common/user_auth/src/context_manager.c @@ -40,7 +40,7 @@ ResultCode InitUserAuthContextList() return RESULT_SUCCESS; } -void DestoryUserAuthContextList() +void DestoryUserAuthContextList(void) { DestroyLinkedList(g_contextList); g_contextList = NULL; @@ -67,7 +67,6 @@ UserAuthContext *GenerateContext(AuthSolutionHal params) return NULL; } uint32_t authTypeATL; - LOG_INFO("params.userId = %{public}u, params.authType = %{public}u", params.userId, params.authType); params.authType = 1; ResultCode ret = SingleAuthTrustLevel(params.userId, params.authType, &authTypeATL); if (ret != RESULT_SUCCESS || authTypeATL < params.authTrustLevel) { @@ -210,7 +209,7 @@ ResultCode GetScheduleIds(UserAuthContext *context, uint64_t **scheduleIds, uint LinkedList *schedules = context->scheduleList; *scheduleNum = schedules->getSize(schedules); *scheduleIds = Malloc(*scheduleNum * sizeof(uint64_t)); - if (*scheduleIds == NULL) { + if (scheduleIds == NULL) { LOG_ERROR("scheduleIds malloc failed"); return RESULT_NO_MEMORY; } diff --git a/common/user_auth/src/user_auth_funcs.c b/common/user_auth/src/user_auth_funcs.c index 7f33a36..8b5e927 100644 --- a/common/user_auth/src/user_auth_funcs.c +++ b/common/user_auth/src/user_auth_funcs.c @@ -73,7 +73,8 @@ int32_t RequestAuthResultFunc(uint64_t contextId, const Buffer *scheduleToken, U return RESULT_BAD_PARAM; } ScheduleTokenHal scheduleTokenStruct; - if (memcpy_s(&scheduleTokenStruct, sizeof(ScheduleTokenHal), scheduleToken->buf, scheduleToken->contentSize) != EOK) { + if (memcpy_s(&scheduleTokenStruct, sizeof(ScheduleTokenHal), scheduleToken->buf, + scheduleToken->contentSize) != EOK) { LOG_ERROR("scheduleTokenStruct copy failed"); return RESULT_BAD_COPY; } diff --git a/common/user_auth/src/user_sign_centre.c b/common/user_auth/src/user_sign_centre.c index 070fe23..45cf0c1 100644 --- a/common/user_auth/src/user_sign_centre.c +++ b/common/user_auth/src/user_sign_centre.c @@ -28,7 +28,7 @@ 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, \ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, \ 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, \ -}; +} static uint8_t g_userAuthTokenKey[SHA256_KEY_LEN] = DEMO_KEY; @@ -50,31 +50,23 @@ ResultCode UserAuthTokenSign(UserAuthTokenHal *userAuthToken) LOG_ERROR("userAuthToken is NULL"); return RESULT_BAD_PARAM; } - userAuthToken->version = TOKEN_VERSION; ResultCode ret = RESULT_SUCCESS; Buffer *data = CreateBufferByData((uint8_t *)userAuthToken, AUTH_TOKEN_DATA_LEN); Buffer *key = CreateBufferByData(g_userAuthTokenKey, SHA256_KEY_LEN); - Buffer *rightSign = NULL; + Buffer *sign = NULL; if (data == NULL || key == NULL) { LOG_ERROR("lack of member"); ret = RESULT_NO_MEMORY; goto EXIT; } - if (memcpy_s(data->buf, data->maxSize, userAuthToken, AUTH_TOKEN_DATA_LEN) != EOK) { - LOG_ERROR("data copy failed"); - ret = RESULT_BAD_COPY; - goto EXIT; - } - data->contentSize = SHA256_KEY_LEN; - - if (HmacSha256(key, data, &rightSign) != RESULT_SUCCESS || !IsBufferValid(rightSign)) { + if (HmacSha256(key, data, &sign) != RESULT_SUCCESS || !IsBufferValid(sign)) { ret = RESULT_GENERAL_ERROR; goto EXIT; } - if (memcpy_s(userAuthToken->sign, SHA256_SIGN_LEN, rightSign->buf, rightSign->contentSize) != EOK) { + if (memcpy_s(userAuthToken->sign, SHA256_SIGN_LEN, sign->buf, sign->contentSize) != EOK) { LOG_ERROR("sign copy failed"); ret = RESULT_BAD_COPY; goto EXIT; @@ -83,7 +75,7 @@ ResultCode UserAuthTokenSign(UserAuthTokenHal *userAuthToken) EXIT: DestoryBuffer(data); DestoryBuffer(key); - DestoryBuffer(rightSign); + DestoryBuffer(sign); return ret; } diff --git a/frameworks/kitsimpl/include/coauth_callback_proxy.h b/frameworks/kitsimpl/include/coauth_callback_proxy.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/coauth_callback_stub.h b/frameworks/kitsimpl/include/coauth_callback_stub.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/executor_callback_proxy.h b/frameworks/kitsimpl/include/executor_callback_proxy.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/executor_callback_stub.h b/frameworks/kitsimpl/include/executor_callback_stub.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/executor_messenger_proxy.h b/frameworks/kitsimpl/include/executor_messenger_proxy.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/executor_messenger_stub.h b/frameworks/kitsimpl/include/executor_messenger_stub.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/icoauth_callback.h b/frameworks/kitsimpl/include/icoauth_callback.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/iexecutor_messenger.h b/frameworks/kitsimpl/include/iexecutor_messenger.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/iquery_callback.h b/frameworks/kitsimpl/include/iquery_callback.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/iset_prop_callback.h b/frameworks/kitsimpl/include/iset_prop_callback.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/query_callback_proxy.h b/frameworks/kitsimpl/include/query_callback_proxy.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/query_callback_stub.h b/frameworks/kitsimpl/include/query_callback_stub.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/set_prop_callback_proxy.h b/frameworks/kitsimpl/include/set_prop_callback_proxy.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/include/set_prop_callback_stub.h b/frameworks/kitsimpl/include/set_prop_callback_stub.h old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/auth_executor_registry.cpp b/frameworks/kitsimpl/src/auth_executor_registry.cpp old mode 100644 new mode 100755 index ec1d48c..3c79ac2 --- a/frameworks/kitsimpl/src/auth_executor_registry.cpp +++ b/frameworks/kitsimpl/src/auth_executor_registry.cpp @@ -37,7 +37,7 @@ sptr AuthExecutorRegistry::GetProxy() COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get system ability manager"); return nullptr; } - sptr obj = sam->CheckSystemAbility(COOPERATION_AUTHENTICATION_SERVICE_SA_ID); + sptr obj = sam->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR); if (obj == nullptr) { COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get coauth service"); return nullptr; diff --git a/frameworks/kitsimpl/src/auth_info.cpp b/frameworks/kitsimpl/src/auth_info.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/coauth.cpp b/frameworks/kitsimpl/src/coauth.cpp index d095f4f..bd50f18 100755 --- a/frameworks/kitsimpl/src/coauth.cpp +++ b/frameworks/kitsimpl/src/coauth.cpp @@ -38,7 +38,7 @@ sptr CoAuth::GetProxy() COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get system ability manager"); return nullptr; } - sptr obj = sam->CheckSystemAbility(COOPERATION_AUTHENTICATION_SERVICE_SA_ID); + sptr obj = sam->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR); if (obj == nullptr) { COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get coauth manager service"); return nullptr; diff --git a/frameworks/kitsimpl/src/coauth_callback_proxy.cpp b/frameworks/kitsimpl/src/coauth_callback_proxy.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/coauth_callback_stub.cpp b/frameworks/kitsimpl/src/coauth_callback_stub.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/coauth_proxy.cpp b/frameworks/kitsimpl/src/coauth_proxy.cpp index 18fde2d..9fa998b 100755 --- a/frameworks/kitsimpl/src/coauth_proxy.cpp +++ b/frameworks/kitsimpl/src/coauth_proxy.cpp @@ -176,9 +176,10 @@ int32_t CoAuthProxy::Cancel(uint64_t scheduleId) } MessageParcel reply; + int32_t result = 0; bool ret = SendRequest(static_cast(ICoAuth::COAUTH_SCHEDULE_CANCEL), data, reply); if (ret) { - int32_t result = reply.ReadInt32(); + result = reply.ReadInt32(); COAUTH_HILOGD(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -210,15 +211,8 @@ int32_t CoAuthProxy::GetExecutorProp(AuthResPool::AuthAttributes &conditions, COAUTH_HILOGE(MODULE_INNERKIT, "data WriteUInt8Vector buffer failed!"); return FAIL; } - if (values->Pack(buffer)) { - COAUTH_HILOGE(MODULE_INNERKIT, "values pack buffer failed!"); - return FAIL; - } - if (!data.WriteUInt8Vector(buffer)) { - COAUTH_HILOGE(MODULE_INNERKIT, "data WriteUInt8Vector buffer failed!"); - return FAIL; - } + std::vector valuesReply; bool ret = SendRequest(static_cast(ICoAuth::COAUTH_GET_PROPERTY), data, reply); if (!ret) { COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); @@ -228,6 +222,12 @@ int32_t CoAuthProxy::GetExecutorProp(AuthResPool::AuthAttributes &conditions, COAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!"); return FAIL; } + if (!reply.ReadUInt8Vector(&valuesReply)) { + COAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return FAIL; + } else { + values->Unpack(valuesReply); + } return result; } @@ -235,6 +235,7 @@ void CoAuthProxy::SetExecutorProp(AuthResPool::AuthAttributes &conditions, const sptr &callback) { COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: SetExecutorProp enter"); + int result = false; MessageParcel data; MessageParcel reply; @@ -256,7 +257,7 @@ void CoAuthProxy::SetExecutorProp(AuthResPool::AuthAttributes &conditions, } bool ret = SendRequest(static_cast(ICoAuth::COAUTH_SET_PROPERTY), data, reply, false); if (ret) { - COAUTH_HILOGD(MODULE_INNERKIT, "ret = %{public}d", ret); + COAUTH_HILOGD(MODULE_INNERKIT, "ret = %{public}d", result); } else { COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest."); } diff --git a/frameworks/kitsimpl/src/executor_callback_proxy.cpp b/frameworks/kitsimpl/src/executor_callback_proxy.cpp old mode 100644 new mode 100755 index f697a66..b09d03c --- a/frameworks/kitsimpl/src/executor_callback_proxy.cpp +++ b/frameworks/kitsimpl/src/executor_callback_proxy.cpp @@ -45,6 +45,7 @@ int32_t ExecutorCallbackProxy::OnBeginExecute(uint64_t scheduleId, std::vector(IExecutorCallback::ON_BEGIN_EXECUTE), data, reply); if (ret) { - int32_t result = reply.ReadInt32(); + result = reply.ReadInt32(); COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -75,6 +76,7 @@ int32_t ExecutorCallbackProxy::OnEndExecute(uint64_t scheduleId, std::shared_ptr { MessageParcel data; MessageParcel reply; + int32_t result = 0; if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); return FAIL; @@ -94,7 +96,7 @@ int32_t ExecutorCallbackProxy::OnEndExecute(uint64_t scheduleId, std::shared_ptr bool ret = SendRequest(static_cast(IExecutorCallback::ON_END_EXECUTE), data, reply); if (ret) { - int32_t result = reply.ReadInt32(); + result = reply.ReadInt32(); COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -104,6 +106,7 @@ int32_t ExecutorCallbackProxy::OnSetProperty(std::shared_ptr pro { MessageParcel data; MessageParcel reply; + int32_t result = 0; if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); return FAIL; @@ -117,7 +120,7 @@ int32_t ExecutorCallbackProxy::OnSetProperty(std::shared_ptr pro } bool ret = SendRequest(static_cast(IExecutorCallback::ON_SET_PROPERTY), data, reply); if (ret) { - int32_t result = reply.ReadInt32(); + result = reply.ReadInt32(); COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -129,6 +132,11 @@ int32_t ExecutorCallbackProxy::OnGetProperty(std::shared_ptr con MessageParcel data; MessageParcel reply; int32_t result = 0; + if (values == nullptr) { + COAUTH_HILOGE(MODULE_INNERKIT, "ExecutorCallbackProxy values is null."); + return FAIL; + } + if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); return FAIL; @@ -141,15 +149,17 @@ int32_t ExecutorCallbackProxy::OnGetProperty(std::shared_ptr con if (!data.WriteUInt8Vector(buffer)) { return FAIL; } - if (values->Pack(buffer)) { - return FAIL; - } - if (!data.WriteUInt8Vector(buffer)) { - return FAIL; - } - bool ret = SendRequest(static_cast(IExecutorCallback::ON_GET_PROPERTY), data, reply); + + std::vector valuesReply; + bool ret = SendRequest(static_cast(IExecutorCallback::ON_GET_PROPERTY), data, reply); // must sync if (ret) { result = reply.ReadInt32(); + if (!reply.ReadUInt8Vector(&valuesReply)) { + COAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return FAIL; + } else { + values->Unpack(valuesReply); + } COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return result; diff --git a/frameworks/kitsimpl/src/executor_callback_stub.cpp b/frameworks/kitsimpl/src/executor_callback_stub.cpp old mode 100644 new mode 100755 index 6731eb3..abbc91a --- a/frameworks/kitsimpl/src/executor_callback_stub.cpp +++ b/frameworks/kitsimpl/src/executor_callback_stub.cpp @@ -104,15 +104,20 @@ int32_t ExecutorCallbackStub::OnGetPropertyStub(MessageParcel& data, MessageParc std::shared_ptr conditions = std::make_shared(); data.ReadUInt8Vector(&buffer); conditions->Unpack(buffer); - buffer.clear(); + std::shared_ptr values = std::make_shared(); - data.ReadUInt8Vector(&buffer); - values->Unpack(buffer); int32_t ret = OnGetProperty(conditions, values); if (!reply.WriteInt32(ret)) { COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)"); return FAIL; } + + std::vector replyBuffer; + values->Pack(replyBuffer); + if (!reply.WriteUInt8Vector(replyBuffer)) { + COAUTH_HILOGE(MODULE_SERVICE, "failed to replyBuffer"); + return FAIL; + } return SUCCESS; } int32_t ExecutorCallbackStub::OnSetPropertyStub(MessageParcel& data, MessageParcel& reply) @@ -176,6 +181,11 @@ int32_t ExecutorCallbackStub::OnGetProperty(std::shared_ptr cond if (callback_ == nullptr) { return FAIL; } else { + if (values == nullptr) { + COAUTH_HILOGE(MODULE_INNERKIT, "ExecutorCallbackStub::OnGetProperty values is null."); + } else { + COAUTH_HILOGE(MODULE_INNERKIT, "ExecutorCallbackStub::OnGetProperty values is not null."); + } ret = callback_->OnGetProperty(conditions, values); } return ret; diff --git a/frameworks/kitsimpl/src/executor_messenger_proxy.cpp b/frameworks/kitsimpl/src/executor_messenger_proxy.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/executor_messenger_stub.cpp b/frameworks/kitsimpl/src/executor_messenger_stub.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/query_callback_proxy.cpp b/frameworks/kitsimpl/src/query_callback_proxy.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/query_callback_stub.cpp b/frameworks/kitsimpl/src/query_callback_stub.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/set_prop_callback_proxy.cpp b/frameworks/kitsimpl/src/set_prop_callback_proxy.cpp old mode 100644 new mode 100755 diff --git a/frameworks/kitsimpl/src/set_prop_callback_stub.cpp b/frameworks/kitsimpl/src/set_prop_callback_stub.cpp old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index ac64308..5d8ae48 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -11,12 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//base/useriam/coauth/coauth.gni") +import("//base/user_iam/auth_executor_mgr/auth_executor_mgr.gni") config("coauth_private_config") { include_dirs = [ "${coauth_service_path}/include", - "//utils/system/safwk/napi/include", + "//utils/system/safwk/native/include", "${coauth_frameworks_path}/kitsimpl/include", "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include", ] diff --git a/interfaces/innerkits/include/auth_attributes.h b/interfaces/innerkits/include/auth_attributes.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/auth_executor.h b/interfaces/innerkits/include/auth_executor.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/auth_executor_registry.h b/interfaces/innerkits/include/auth_executor_registry.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/auth_info.h b/interfaces/innerkits/include/auth_info.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/auth_message.h b/interfaces/innerkits/include/auth_message.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/coauth_callback.h b/interfaces/innerkits/include/coauth_callback.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/coauth_info_define.h b/interfaces/innerkits/include/coauth_info_define.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/executor_callback.h b/interfaces/innerkits/include/executor_callback.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/executor_messenger.h b/interfaces/innerkits/include/executor_messenger.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/query_callback.h b/interfaces/innerkits/include/query_callback.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/include/set_prop_callback.h b/interfaces/innerkits/include/set_prop_callback.h old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/src/auth_attributes.cpp b/interfaces/innerkits/src/auth_attributes.cpp old mode 100644 new mode 100755 index c5d7266..c5ecdfb --- a/interfaces/innerkits/src/auth_attributes.cpp +++ b/interfaces/innerkits/src/auth_attributes.cpp @@ -67,6 +67,8 @@ int32_t AuthAttributes::GetBoolValue(AuthAttributeType attrType, bool &value) int32_t AuthAttributes::GetUint32Value(AuthAttributeType attrType, uint32_t &value) { int32_t ret = SUCCESS; + COAUTH_HILOGD(MODULE_INNERKIT, "uint32ValueMap size : %{public}04u.", uint32ValueMap_.size()); + uint32ValueMap_.size(); std::map::iterator iter = uint32ValueMap_.find(attrType); if (iter != uint32ValueMap_.end()) { value = iter->second; @@ -195,16 +197,15 @@ void AuthAttributes::UnpackTag(AuthAttributeType &tag, std::vector &buf uint32_t &authDataLength, uint32_t &dataLength) { tag = GetUint32FromUint8(buffer, authDataLength); - COAUTH_HILOGD(MODULE_INNERKIT, "buffer read tag : %{public}d.", tag); authDataLength += sizeof(uint32_t); dataLength = static_cast(GetUint32FromUint8(buffer, authDataLength)); - COAUTH_HILOGD(MODULE_INNERKIT, "buffer read dataLength : %{public}d.", dataLength); authDataLength += sizeof(uint32_t); } AuthAttributes* AuthAttributes::Unpack(std::vector &buffer) { if (buffer.size() == 0) { + COAUTH_HILOGD(MODULE_INNERKIT, ">>>>>>>>>>>>>>>>> Unpack size is 0"); return nullptr; } uint32_t dataLength, authDataLength = 0; diff --git a/interfaces/innerkits/src/auth_executor.cpp b/interfaces/innerkits/src/auth_executor.cpp old mode 100644 new mode 100755 diff --git a/interfaces/innerkits/src/auth_message.cpp b/interfaces/innerkits/src/auth_message.cpp old mode 100644 new mode 100755 diff --git a/ohos.build b/ohos.build deleted file mode 100755 index ac08519..0000000 --- a/ohos.build +++ /dev/null @@ -1,23 +0,0 @@ -{ - "subsystem": "useriam", - "parts": { - "coauthmgr": { - "variants": [ - "wearable", - "phone" - ], - "module_list": [ - "//base/useriam/coauth/sa_profile:coauth_sa_profile", - "//base/useriam/coauth/services:coauthservice", - "//base/useriam/coauth/interfaces/innerkits:coauth_framework", - "//base/useriam/coauth/sa_profile:useriam.init" - ], - "inner_kits": [ - - ], - "test_list": [ - "//base/useriam/coauth/test:coauth_unittest_test" - ] - } - } -} diff --git a/sa_profile/5203.xml b/sa_profile/923.xml similarity index 97% rename from sa_profile/5203.xml rename to sa_profile/923.xml index d3050af..1bbc946 100755 --- a/sa_profile/5203.xml +++ b/sa_profile/923.xml @@ -15,7 +15,7 @@ useriam - 5203 + 923 libcoauthservice.z.so true false diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn index 860cb12..4a70262 100755 --- a/sa_profile/BUILD.gn +++ b/sa_profile/BUILD.gn @@ -11,11 +11,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//base/useriam/coauth/coauth.gni") +import("//base/user_iam/auth_executor_mgr/auth_executor_mgr.gni") import("//build/ohos/sa_profile/sa_profile.gni") ohos_sa_profile("coauth_sa_profile") { - sources = [ "5203.xml" ] + sources = [ "923.xml" ] part_name = "${coauth_native_part_name}" } ohos_prebuilt_etc("useriam.init") { @@ -25,6 +25,6 @@ ohos_prebuilt_etc("useriam.init") { source = "useriam.rc" } relative_install_dir = "init" - part_name = "coauthmgr" - subsystem_name = "coauth" + part_name = "auth_executor_mgr" + subsystem_name = "useriam" } \ No newline at end of file diff --git a/sa_profile/useriam.cfg b/sa_profile/useriam.cfg old mode 100644 new mode 100755 diff --git a/sa_profile/useriam.rc b/sa_profile/useriam.rc old mode 100644 new mode 100755 diff --git a/services/BUILD.gn b/services/BUILD.gn index a12469c..0968b83 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -11,14 +11,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//base/useriam/coauth/coauth.gni") +import("//base/user_iam/auth_executor_mgr/auth_executor_mgr.gni") config("coauth_private_config") { include_dirs = [ "//utils/system/safwk/native/include", - "//base/useriam/coauth/frameworks/innerkitsimpl/distributeddatafwk/include", + "//base/user_iam/auth_executor_mgr/frameworks/innerkitsimpl/distributeddatafwk/include", "${coauth_frameworks_path}/kitsimpl/include", - "//base/useriam/coauth/common/interface", + "//base/user_iam/auth_executor_mgr/common/interface", ] } @@ -51,7 +51,7 @@ ohos_shared_library("coauthservice") { "//drivers/peripheral/display/hal:hdi_display_device", "//utils/native/base:utils", "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", - "//base/useriam/coauth/common:useriam_common_lib", + "//base/user_iam/auth_executor_mgr/common:useriam_common_lib", ] external_deps = [ diff --git a/services/src/auth_res_pool.cpp b/services/src/auth_res_pool.cpp index e03a6a9..a1a8eb1 100755 --- a/services/src/auth_res_pool.cpp +++ b/services/src/auth_res_pool.cpp @@ -77,7 +77,7 @@ int32_t AuthResPool::FindExecutorCallback(uint32_t authType, sptr lock(authMutex_); std::map> ::iterator iter; - for (iter = authResPool_.begin(); iter != authResPool_.end(); ++iter) { + for (iter = authResPool_.begin(); iter != authResPool_.end(); iter++) { iter->second->executorInfo->GetAuthType(getAuthType); if (getAuthType == (int32_t)authType) { callback = iter->second->callback; diff --git a/services/src/coauth_manager.cpp b/services/src/coauth_manager.cpp index 6604548..58bdbdb 100755 --- a/services/src/coauth_manager.cpp +++ b/services/src/coauth_manager.cpp @@ -94,10 +94,11 @@ void CoAuthManager::SetAuthAttributes(std::shared_ptr command /* Cancel collaborative schedule */ int32_t CoAuthManager::Cancel(uint64_t scheduleId) { + int32_t cancelRet = SUCCESS; int32_t executeRet = SUCCESS; ScheduleInfo scheduleInfo; sptr callback = nullptr; - int32_t cancelRet = DeleteScheduleInfo(scheduleId, scheduleInfo); // call TA + cancelRet = DeleteScheduleInfo(scheduleId, scheduleInfo); // call TA if (cancelRet != SUCCESS) { COAUTH_HILOGE(MODULE_SERVICE, "cancel is failure"); return FAIL; diff --git a/services/src/coauth_service.cpp b/services/src/coauth_service.cpp index 131cd41..a923d6f 100755 --- a/services/src/coauth_service.cpp +++ b/services/src/coauth_service.cpp @@ -36,7 +36,7 @@ void CheckSystemAbility() } for (int i = 0; i < CHECK_TIMES; i++) { bool isExist = false; - sam->CheckSystemAbility(PIN_AUTH_SERVICE_SA_ID, isExist); + sam->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_PINAUTH, isExist); if (!isExist) { COAUTH_HILOGI(MODULE_INNERKIT, "PIN_AUTH_SERVICE is not exist, start pin auth ability failed, to do next"); } else { @@ -50,7 +50,7 @@ void CheckSystemAbility() COAUTH_HILOGI(MODULE_INNERKIT, "start pin auth ability all failed"); } -REGISTER_SYSTEM_ABILITY_BY_ID(CoAuthService, COOPERATION_AUTHENTICATION_SERVICE_SA_ID, true); +REGISTER_SYSTEM_ABILITY_BY_ID(CoAuthService, SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true); CoAuthService::CoAuthService(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) { diff --git a/services/src/coauth_stub.cpp b/services/src/coauth_stub.cpp index 41e472a..143b9de 100755 --- a/services/src/coauth_stub.cpp +++ b/services/src/coauth_stub.cpp @@ -159,9 +159,6 @@ int32_t CoAuthStub::GetExecutorPropStub(MessageParcel& data, MessageParcel& repl COAUTH_HILOGE(MODULE_SERVICE, "GetExecutorPropStub failed, values is nullptr"); return FAIL; } - buffer.clear(); - data.ReadUInt8Vector(&buffer); - values->Unpack(buffer); int32_t ret = GetExecutorProp(conditions, values); if (!reply.WriteInt32(ret)) { @@ -169,6 +166,12 @@ int32_t CoAuthStub::GetExecutorPropStub(MessageParcel& data, MessageParcel& repl return FAIL; } + std::vector replyBuffer; + values->Pack(replyBuffer); + if (!reply.WriteUInt8Vector(replyBuffer)) { + COAUTH_HILOGE(MODULE_SERVICE, "failed to replyBuffer"); + return FAIL; + } return SUCCESS; } diff --git a/test/BUILD.gn b/test/BUILD.gn index ea1d917..afa54cf 100755 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -10,9 +10,8 @@ # 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/ohos.gni") -import("//base/useriam/coauth/coauth.gni") -#import("//foundation/distributeddatamgr/distributedgallery/distributedgallery.gni") + +import("//base/user_iam/auth_executor_mgr/auth_executor_mgr.gni") import("//build/test.gni") group("coauth_unittest_test") { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index e1b1bf2..9b3cf34 100755 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -13,21 +13,21 @@ import("//build/ohos.gni") import("//build/test.gni") -import("//base/useriam/coauth/coauth.gni") +import("//base/user_iam/auth_executor_mgr/auth_executor_mgr.gni") -module_output_path = "coauthmgr/coauth_UT_test" +module_output_path = "auth_executor_mgr/coauth_UT_test" ohos_unittest("coauth_UT_test") { module_out_path = module_output_path sources = [ - "//base/useriam/coauth/test/unittest/src/coauth_test.cpp", + "//base/user_iam/auth_executor_mgr/test/unittest/src/coauth_test.cpp", ] include_dirs = [ "include", - "//base/useriam/coauth/interfaces/innerkits/include", + "//base/user_iam/auth_executor_mgr/interfaces/innerkits/include", "${coauth_service_path}/include", "//utils/system/safwk/napi/include", "${coauth_frameworks_path}/kitsimpl/include", diff --git a/test/unittest/include/coauth_test.h b/test/unittest/include/coauth_test.h old mode 100644 new mode 100755 index 4238228..e303f5b --- a/test/unittest/include/coauth_test.h +++ b/test/unittest/include/coauth_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifndef COAUTH_TEST_H #define COAUTH_TEST_H #include "auth_executor.h" diff --git a/test/unittest/src/coauth_test.cpp b/test/unittest/src/coauth_test.cpp old mode 100644 new mode 100755 diff --git a/utils/BUILD.gn b/utils/BUILD.gn index fc7fd4c..54f9132 100755 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//base/useriam/coauth/coauth.gni") +import("//base/user_iam/auth_executor_mgr/auth_executor_mgr.gni") config("utils_config") { include_dirs = [ -- Gitee From 67556f1ba486a5df67b3056d8d50ab4932ad2057 Mon Sep 17 00:00:00 2001 From: wangxu43 Date: Wed, 19 Jan 2022 09:48:51 +0800 Subject: [PATCH 2/2] Buf fix Signed-off-by: wangxu43 --- common/coauth/src/coauth_funcs.c | 4 ++-- common/coauth/src/executor_message.c | 18 +++++++++--------- common/database/src/idm_database.c | 4 ++-- common/idm/src/idm_session.c | 1 + common/idm/src/user_idm_funcs.c | 2 +- common/user_auth/src/auth_level.c | 2 +- common/user_auth/src/context_manager.c | 2 +- frameworks/kitsimpl/src/coauth_proxy.cpp | 6 ++---- .../kitsimpl/src/executor_callback_proxy.cpp | 9 +++------ services/src/auth_res_pool.cpp | 2 +- services/src/coauth_manager.cpp | 3 +-- 11 files changed, 24 insertions(+), 29 deletions(-) mode change 100755 => 100644 frameworks/kitsimpl/src/coauth_proxy.cpp mode change 100755 => 100644 frameworks/kitsimpl/src/executor_callback_proxy.cpp mode change 100755 => 100644 services/src/auth_res_pool.cpp mode change 100755 => 100644 services/src/coauth_manager.cpp diff --git a/common/coauth/src/coauth_funcs.c b/common/coauth/src/coauth_funcs.c index 8d79492..e73dd39 100644 --- a/common/coauth/src/coauth_funcs.c +++ b/common/coauth/src/coauth_funcs.c @@ -71,8 +71,8 @@ int32_t ScheduleFinish(const Buffer *executorMsg, ScheduleTokenHal *scheduleToke return RESULT_BAD_PARAM; } scheduleToken->scheduleResult = RESULT_GENERAL_ERROR; - ExecutorResultInfo *resultInfo = Malloc(sizeof(ExecutorResultInfo)); - resultInfo = GetExecutorResultInfo(executorMsg); + // ExecutorResultInfo *resultInfo = Malloc(sizeof(ExecutorResultInfo)); + ExecutorResultInfo *resultInfo = GetExecutorResultInfo(executorMsg); if (resultInfo == NULL) { LOG_ERROR("tlv parse failed"); return RESULT_BAD_PARAM; diff --git a/common/coauth/src/executor_message.c b/common/coauth/src/executor_message.c index 5d9816a..126974f 100644 --- a/common/coauth/src/executor_message.c +++ b/common/coauth/src/executor_message.c @@ -86,27 +86,27 @@ static ResultCode ParseExecutorResultData(ExecutorResultInfo *result, TlvListNod LOG_ERROR("ParseTlvWrapper failed"); goto EXIT; } - ret = ParseExecutorResultAcl(result, parseBody); + ret = ParseExecutorResultAcl(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseExecutorResultAcl failed"); goto EXIT; } - ret = ParseExecutorResultTemplateId(result, parseBody); + ret = ParseExecutorResultTemplateId(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseExecutorResultTemplateId failed"); goto EXIT; } - ret = ParseExecutorResultAuthSubType(result, parseBody); + ret = ParseExecutorResultAuthSubType(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseExecutorResultAuthSubType failed"); goto EXIT; } - ret = ParseExecutorResultCode(result, parseBody); + ret = ParseExecutorResultCode(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseExecutorResultCode failed"); goto EXIT; } - ret = ParseExecutorResultScheduleId(result, parseBody); + ret = ParseExecutorResultScheduleId(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseExecutorResultScheduleId failed"); goto EXIT; @@ -144,12 +144,12 @@ static ResultCode ParseRoot(ExecutorResultInfo *result, TlvListNode *body) LOG_ERROR("ParseTlvWrapper failed"); goto EXIT; } - ret = ParseExecutorResultData(result, parseBody); + ret = ParseExecutorResultData(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseTlvWrapper failed"); goto EXIT; } - ret = ParseExecutorResultSign(result, parseBody); + ret = ParseExecutorResultSign(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseTlvWrapper failed"); goto EXIT; @@ -185,7 +185,7 @@ ExecutorResultInfo *GetExecutorResultInfo(const Buffer *tlv) LOG_ERROR("malloc failed"); goto EXIT; } - ret = ParseRoot(result, parseBody); + ret = ParseRoot(result, parseBody->next); if (ret != RESULT_SUCCESS) { LOG_ERROR("ParseExecutorResult failed"); goto EXIT; @@ -209,4 +209,4 @@ void DestoryExecutorResultInfo(ExecutorResultInfo *result) DestoryBuffer(result->sign); result->sign = NULL; Free(result); -} \ No newline at end of file +} diff --git a/common/database/src/idm_database.c b/common/database/src/idm_database.c index 2e43b8b..73a9b9c 100644 --- a/common/database/src/idm_database.c +++ b/common/database/src/idm_database.c @@ -222,7 +222,7 @@ static ResultCode GetAllEnrolledInfoFromUser(UserInfo *userInfo, EnrolledInfoHal LinkedList *enrolledInfoList = userInfo->enrolledInfoList; uint32_t size = enrolledInfoList->getSize(enrolledInfoList); *enrolledInfos = Malloc(sizeof(EnrolledInfoHal) * size); - if (enrolledInfos == NULL) { + if (*enrolledInfos == NULL) { LOG_ERROR("enrolledInfos malloc failed"); return RESULT_NO_MEMORY; } @@ -258,7 +258,7 @@ static ResultCode GetAllCredentialInfoFromUser(UserInfo *userInfo, CredentialInf LinkedList *credentialInfoList = userInfo->credentialInfoList; uint32_t size = credentialInfoList->getSize(credentialInfoList); *credentialInfos = Malloc(sizeof(CredentialInfoHal) * size); - if (credentialInfos == NULL) { + if (*credentialInfos == NULL) { LOG_ERROR("credentialInfos malloc failed"); return RESULT_NO_MEMORY; } diff --git a/common/idm/src/idm_session.c b/common/idm/src/idm_session.c index d01a83a..e44511f 100644 --- a/common/idm/src/idm_session.c +++ b/common/idm/src/idm_session.c @@ -79,6 +79,7 @@ ResultCode OpenEditSession(int32_t userId, uint64_t *challenge) LOG_ERROR("challenge is invalid"); Free(g_session); g_session = NULL; + return RESULT_GENERAL_ERROR; } g_session->time = GetSystemTime(); diff --git a/common/idm/src/user_idm_funcs.c b/common/idm/src/user_idm_funcs.c index 2aa0fa7..fd1af40 100644 --- a/common/idm/src/user_idm_funcs.c +++ b/common/idm/src/user_idm_funcs.c @@ -197,7 +197,7 @@ int32_t QueryCredentialFunc(int32_t userId, uint32_t authType, } *credentialInfoArray = Malloc(sizeof(CredentialInfoHal)); - if (credentialInfoArray == NULL) { + if (*credentialInfoArray == NULL) { LOG_ERROR("credentialInfoArray malloc failed"); return RESULT_NO_MEMORY; } diff --git a/common/user_auth/src/auth_level.c b/common/user_auth/src/auth_level.c index 097cf89..6b1db0b 100644 --- a/common/user_auth/src/auth_level.c +++ b/common/user_auth/src/auth_level.c @@ -118,7 +118,7 @@ ResultCode SingleAuthTrustLevel(uint32_t userId, uint32_t authType, uint32_t *at return ret; } - for (uint32_t i = 0; i < sizeof(g_generationAtl) / sizeof(g_generationAtl); i++) { + for (uint32_t i = 0; i < sizeof(g_generationAtl) / sizeof(AtlGeneration); i++) { if (authSecureLevel == g_generationAtl[i].asl && authCapabilityLevel == g_generationAtl[i].acl) { *atl = g_generationAtl[i].atl; return RESULT_SUCCESS; diff --git a/common/user_auth/src/context_manager.c b/common/user_auth/src/context_manager.c index dfa172a..3588dbb 100644 --- a/common/user_auth/src/context_manager.c +++ b/common/user_auth/src/context_manager.c @@ -209,7 +209,7 @@ ResultCode GetScheduleIds(UserAuthContext *context, uint64_t **scheduleIds, uint LinkedList *schedules = context->scheduleList; *scheduleNum = schedules->getSize(schedules); *scheduleIds = Malloc(*scheduleNum * sizeof(uint64_t)); - if (scheduleIds == NULL) { + if (*scheduleIds == NULL) { LOG_ERROR("scheduleIds malloc failed"); return RESULT_NO_MEMORY; } diff --git a/frameworks/kitsimpl/src/coauth_proxy.cpp b/frameworks/kitsimpl/src/coauth_proxy.cpp old mode 100755 new mode 100644 index 9fa998b..4d788af --- a/frameworks/kitsimpl/src/coauth_proxy.cpp +++ b/frameworks/kitsimpl/src/coauth_proxy.cpp @@ -176,10 +176,9 @@ int32_t CoAuthProxy::Cancel(uint64_t scheduleId) } MessageParcel reply; - int32_t result = 0; bool ret = SendRequest(static_cast(ICoAuth::COAUTH_SCHEDULE_CANCEL), data, reply); if (ret) { - result = reply.ReadInt32(); + int32_t result = reply.ReadInt32(); COAUTH_HILOGD(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -235,7 +234,6 @@ void CoAuthProxy::SetExecutorProp(AuthResPool::AuthAttributes &conditions, const sptr &callback) { COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: SetExecutorProp enter"); - int result = false; MessageParcel data; MessageParcel reply; @@ -257,7 +255,7 @@ void CoAuthProxy::SetExecutorProp(AuthResPool::AuthAttributes &conditions, } bool ret = SendRequest(static_cast(ICoAuth::COAUTH_SET_PROPERTY), data, reply, false); if (ret) { - COAUTH_HILOGD(MODULE_INNERKIT, "ret = %{public}d", result); + COAUTH_HILOGD(MODULE_INNERKIT, "ret = %{public}d", ret); } else { COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest."); } diff --git a/frameworks/kitsimpl/src/executor_callback_proxy.cpp b/frameworks/kitsimpl/src/executor_callback_proxy.cpp old mode 100755 new mode 100644 index b09d03c..6080ca8 --- a/frameworks/kitsimpl/src/executor_callback_proxy.cpp +++ b/frameworks/kitsimpl/src/executor_callback_proxy.cpp @@ -45,7 +45,6 @@ int32_t ExecutorCallbackProxy::OnBeginExecute(uint64_t scheduleId, std::vector(IExecutorCallback::ON_BEGIN_EXECUTE), data, reply); if (ret) { - result = reply.ReadInt32(); + int32_t result = reply.ReadInt32(); COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -76,7 +75,6 @@ int32_t ExecutorCallbackProxy::OnEndExecute(uint64_t scheduleId, std::shared_ptr { MessageParcel data; MessageParcel reply; - int32_t result = 0; if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); return FAIL; @@ -96,7 +94,7 @@ int32_t ExecutorCallbackProxy::OnEndExecute(uint64_t scheduleId, std::shared_ptr bool ret = SendRequest(static_cast(IExecutorCallback::ON_END_EXECUTE), data, reply); if (ret) { - result = reply.ReadInt32(); + int32_t result = reply.ReadInt32(); COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; @@ -106,7 +104,6 @@ int32_t ExecutorCallbackProxy::OnSetProperty(std::shared_ptr pro { MessageParcel data; MessageParcel reply; - int32_t result = 0; if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); return FAIL; @@ -120,7 +117,7 @@ int32_t ExecutorCallbackProxy::OnSetProperty(std::shared_ptr pro } bool ret = SendRequest(static_cast(IExecutorCallback::ON_SET_PROPERTY), data, reply); if (ret) { - result = reply.ReadInt32(); + int32_t result = reply.ReadInt32(); COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result); } return SUCCESS; diff --git a/services/src/auth_res_pool.cpp b/services/src/auth_res_pool.cpp old mode 100755 new mode 100644 index a1a8eb1..e03a6a9 --- a/services/src/auth_res_pool.cpp +++ b/services/src/auth_res_pool.cpp @@ -77,7 +77,7 @@ int32_t AuthResPool::FindExecutorCallback(uint32_t authType, sptr lock(authMutex_); std::map> ::iterator iter; - for (iter = authResPool_.begin(); iter != authResPool_.end(); iter++) { + for (iter = authResPool_.begin(); iter != authResPool_.end(); ++iter) { iter->second->executorInfo->GetAuthType(getAuthType); if (getAuthType == (int32_t)authType) { callback = iter->second->callback; diff --git a/services/src/coauth_manager.cpp b/services/src/coauth_manager.cpp old mode 100755 new mode 100644 index 58bdbdb..6604548 --- a/services/src/coauth_manager.cpp +++ b/services/src/coauth_manager.cpp @@ -94,11 +94,10 @@ void CoAuthManager::SetAuthAttributes(std::shared_ptr command /* Cancel collaborative schedule */ int32_t CoAuthManager::Cancel(uint64_t scheduleId) { - int32_t cancelRet = SUCCESS; int32_t executeRet = SUCCESS; ScheduleInfo scheduleInfo; sptr callback = nullptr; - cancelRet = DeleteScheduleInfo(scheduleId, scheduleInfo); // call TA + int32_t cancelRet = DeleteScheduleInfo(scheduleId, scheduleInfo); // call TA if (cancelRet != SUCCESS) { COAUTH_HILOGE(MODULE_SERVICE, "cancel is failure"); return FAIL; -- Gitee