From 0aedb30699e7f777af2d895e9505d0b7af3456b1 Mon Sep 17 00:00:00 2001 From: fuzikun Date: Sat, 27 Jan 2024 10:30:11 +0800 Subject: [PATCH] optimize string_util Signed-off-by: fuzikun --- common_lib/impl/src/string_util.c | 115 ------------------ common_lib/interfaces/string_util.h | 20 --- deps_adapter/BUILD.gn | 13 +- .../impl/inc/mbedtls_ec_adapter.h | 3 + .../impl/src/huks_adapter.c | 5 +- .../impl/src/mbedtls_ec_adapter.c | 58 +++++++++ .../interfaces/alg_defs.h | 8 ++ .../os_adapter/impl/src/linux/hc_thread.c | 2 + .../os_adapter/impl/src/liteos/hc_thread.c | 2 + .../os_adapter/interfaces/hal_error.h | 1 + deviceauth_env.gni | 16 +++ frameworks/src/ipc_sdk.c | 4 +- frameworks/src/lite/ipc_adapt.c | 2 + frameworks/src/lite/ipc_callback_stub.c | 1 + frameworks/src/lite/ipc_dev_auth_proxy.c | 1 + frameworks/src/standard/ipc_dev_auth_stub.cpp | 2 - services/BUILD.gn | 2 +- .../account_related_cred_plugin.c | 1 + services/deviceauth.gni | 3 - services/key_agree_sdk/key_agree_sdk.gni | 2 - .../auth/iso_auth_task/iso_auth_task_common.c | 4 +- .../pake_v2_auth_server_task.c | 8 +- .../account_related_group_auth.c | 4 +- .../expand_sub_session/expand_sub_session.c | 11 +- .../unit_test/source/common_lib_test.cpp | 32 ----- 25 files changed, 127 insertions(+), 193 deletions(-) diff --git a/common_lib/impl/src/string_util.c b/common_lib/impl/src/string_util.c index dbe71e72..3ac5b7a5 100644 --- a/common_lib/impl/src/string_util.c +++ b/common_lib/impl/src/string_util.c @@ -26,20 +26,6 @@ #define NUMBER_9_IN_DECIMAL 9 #define ASCII_CASE_DIFFERENCE_VALUE 32 -static const char * const g_base64CharacterTable = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -static const uint8_t g_base64DecodeTable[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, - 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 -}; - static char HexToChar(uint8_t hex) { return (hex > NUMBER_9_IN_DECIMAL) ? (hex + 0x37) : (hex + 0x30); /* Convert to the corresponding character */ @@ -108,107 +94,6 @@ int64_t StringToInt64(const char *cp) return strtoll(cp, NULL, DEC); } -static bool IsInvalidBase64Character(char c) -{ - if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) { - return false; - } - if ('0' <= c && c <= '9') { - return false; - } - if (c == '+' || c == '/') { - return false; - } - return true; -} - -int32_t Base64StringToByte(const char *base64Str, uint8_t *byte, uint32_t *byteLen) -{ - if (base64Str == NULL || byte == NULL || byteLen == NULL) { - return CLIB_ERR_NULL_PTR; - } - uint32_t strLen = strlen(base64Str); - if (strLen < BYTE_TO_BASE64_MULTIPLIER) { - return CLIB_ERR_INVALID_LEN; - } - uint32_t len = strLen / BYTE_TO_BASE64_MULTIPLIER * BYTE_TO_BASE64_DIVISOR; - int j = 0; - for (int i = 0; i < 2; i++) { // at most two end fillings '=' - if (base64Str[strLen - 1 - i] == '=') { - j++; - } - } - if (len - j > (*byteLen)) { - return CLIB_ERR_INVALID_LEN; - } - *byteLen = len - j; - - // 6 bits each character(first 2 bits pad 0), 4 characters as a group to decode - if (IsInvalidBase64Character(base64Str[0]) || IsInvalidBase64Character(base64Str[1]) || - IsInvalidBase64Character(base64Str[2])) { - return CLIB_ERR_INVALID_PARAM; - } - for (uint32_t i = 0, j = 0; i < strLen - 2; j += 3, i += 4) { - if (IsInvalidBase64Character(base64Str[i + 3]) && i + 3 < strLen - j) { - return CLIB_ERR_INVALID_PARAM; - } - /* splice the last 6 bits of the first character's value and the first 2 bits of the second character's value */ - byte[j] = (g_base64DecodeTable[(int)base64Str[i]] << 2) | (g_base64DecodeTable[(int)base64Str[i + 1]] >> 4); - /* splice the last 4 bits of the second character's value and the first 4 bits of the third character's value */ - byte[j + 1] = (g_base64DecodeTable[(int)base64Str[i + 1]] << 4) | - (g_base64DecodeTable[(int)base64Str[i + 2]] >> 2); - /* splice the last 2 bits of the third character's value and the first 6 bits of the forth character's value */ - byte[j + 2] = (g_base64DecodeTable[(int)base64Str[i + 2]] << 6) | (g_base64DecodeTable[(int)base64Str[i + 3]]); - } - return CLIB_SUCCESS; -} - -int32_t ByteToBase64String(const uint8_t *byte, uint32_t byteLen, char *base64Str, uint32_t strLen) -{ - if (byte == NULL || base64Str == NULL) { - return CLIB_ERR_NULL_PTR; - } - if (byteLen > (UINT32_MAX / BYTE_TO_BASE64_MULTIPLIER - 1) * BYTE_TO_BASE64_DIVISOR) { - return CLIB_ERR_INVALID_LEN; - } - uint32_t len = (byteLen / BYTE_TO_BASE64_DIVISOR + (byteLen % BYTE_TO_BASE64_DIVISOR != 0)) * - BYTE_TO_BASE64_MULTIPLIER; - if (len + 1 > strLen) { - return CLIB_ERR_INVALID_LEN; - } - - uint32_t i; - uint32_t j; - // 3 bytes as a group to encode - for (i = 0, j = 0; i < len - 2; j += 3, i += 4) { - /* take the first 6 bits of the first byte to map to base64 character */ - base64Str[i] = g_base64CharacterTable[byte[j] >> 2]; - /* - * splice the last 2 bits of the first byte and the first 4 bits of the second byte, - * and map to base64 character - */ - base64Str[i + 1] = g_base64CharacterTable[((byte[j] & 0x3) << 4) | (byte[j + 1] >> 4)]; - /* - * splice the last 4 bits of the second byte and the first 2 bits of the third byte, - * and map to base64 character - */ - base64Str[i + 2] = g_base64CharacterTable[((byte[j + 1] & 0xf) << 2) | (byte[j + 2] >> 6)]; - /* take the last 6 bits of the third byte to map to base64 character */ - base64Str[i + 3] = g_base64CharacterTable[byte[j + 2] & 0x3f]; - } - - // the lack of position fills '=' - if (byteLen % 3 == 1) { - base64Str[i - 2] = '='; - base64Str[i - 1] = '='; - } else if (byteLen % 3 == 2) { - base64Str[i - 1] = '='; - } - base64Str[len] = '\0'; - - return CLIB_SUCCESS; -} - int32_t ToUpperCase(const char *oriStr, char **desStr) { if (oriStr == NULL || desStr == NULL) { diff --git a/common_lib/interfaces/string_util.h b/common_lib/interfaces/string_util.h index d65e6768..b50f92c8 100644 --- a/common_lib/interfaces/string_util.h +++ b/common_lib/interfaces/string_util.h @@ -54,26 +54,6 @@ int32_t ByteToHexString(const uint8_t *byte, uint32_t byteLen, char *hexStr, uin */ int64_t StringToInt64(const char *cp); -/* - * Convert base64 string to byte. - * @param base64Str: base64 string - * @param byte: the converted result, need malloc by caller - * @param byteLen: the length of byte, must be not shorter than strlen(base64Str) / 4 * 3, - * and update it to the real length of the result written - * @result success(0), otherwise, failure. - */ -int32_t Base64StringToByte(const char *base64Str, uint8_t *byte, uint32_t *byteLen); - -/* - * Convert byte to base64 string. - * @param byte: byte to be converted - * @param byteLen: the length of byte - * @param base64Str: the converted result, need malloc by caller, and need malloc for '\0' - * @param strLen: length of base64Str, must be not shorter than (byteLen / 3 + (byteLen % 3 != 0)) * 4 + 1, with '\0' - * @result success(0), otherwise, failure. - */ -int32_t ByteToBase64String(const uint8_t *byte, uint32_t byteLen, char *base64Str, uint32_t strLen); - /* * Convert string to upper case. * @param oriStr: original string. diff --git a/deps_adapter/BUILD.gn b/deps_adapter/BUILD.gn index 91c6acd4..fe645998 100644 --- a/deps_adapter/BUILD.gn +++ b/deps_adapter/BUILD.gn @@ -50,13 +50,15 @@ if (defined(ohos_lite)) { sources += [ "${os_adapter_path}/impl/src/liteos/mini/hc_file.c" ] } - cflags = [ "-DHILOG_ENABLE" ] + cflags = build_flags + cflags += [ "-DHILOG_ENABLE" ] cflags += [ "-DAUTH_STORAGE_PATH=\"${deviceauth_storage_path}\"" ] if (board_toolchain_type == "iccarm") { cflags += [ "--diag_suppress", "Pe223,Pe226", "-DOHOS_MEM", + "-DSET_THREAD_NAME", ] } deps = [ @@ -102,7 +104,8 @@ if (defined(ohos_lite)) { ] } - cflags = [ "-DHILOG_ENABLE" ] + cflags = build_flags + cflags += [ "-DHILOG_ENABLE" ] defines += [ "LITE_DEVICE" ] deps = [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", @@ -150,7 +153,11 @@ if (defined(ohos_lite)) { sources += [ "${os_adapter_path}/impl/src/linux/dev_auth_dynamic_load.c" ] } - cflags = [ "-DHILOG_ENABLE" ] + cflags = build_flags + cflags += [ + "-DHILOG_ENABLE", + "-DSET_THREAD_NAME", + ] branch_protector_ret = "pac_ret" sanitize = { cfi = true diff --git a/deps_adapter/key_management_adapter/impl/inc/mbedtls_ec_adapter.h b/deps_adapter/key_management_adapter/impl/inc/mbedtls_ec_adapter.h index 1a5cb90a..8a139d0a 100644 --- a/deps_adapter/key_management_adapter/impl/inc/mbedtls_ec_adapter.h +++ b/deps_adapter/key_management_adapter/impl/inc/mbedtls_ec_adapter.h @@ -28,7 +28,10 @@ extern "C" { #endif int32_t MbedtlsHashToPoint(const Uint8Buff *hash, Uint8Buff *outEcPoint); +int32_t MbedtlsHashToPoint25519(const Uint8Buff *hash, Uint8Buff *outEcPoint); int32_t MbedtlsAgreeSharedSecret(const KeyBuff *priKey, const KeyBuff *pubKey, Uint8Buff *sharedKey); +int32_t MbedtlsBase64Encode(const uint8_t *byte, uint32_t byteLen, char *base64Str, uint32_t strLen, uint32_t *outLen); +int32_t MbedtlsBase64Decode(const char *base64Str, uint32_t strLen, uint8_t *byte, uint32_t byteLen, uint32_t *outLen); #ifdef __cplusplus } diff --git a/deps_adapter/key_management_adapter/impl/src/huks_adapter.c b/deps_adapter/key_management_adapter/impl/src/huks_adapter.c index 4c577228..3069c074 100644 --- a/deps_adapter/key_management_adapter/impl/src/huks_adapter.c +++ b/deps_adapter/key_management_adapter/impl/src/huks_adapter.c @@ -950,6 +950,7 @@ static int32_t ConstructSignParams(struct HksParamSet **paramSet, Algorithm algo static int32_t Sign(const Uint8Buff *keyAlias, const Uint8Buff *message, Algorithm algo, Uint8Buff *outSignature, bool isAlias) { + (void)isAlias; struct HksParamSet *paramSet = NULL; const Uint8Buff *inParams[] = { keyAlias, message, outSignature }; const char *paramTags[] = { "keyAlias", "message", "outSignature" }; @@ -1380,7 +1381,9 @@ static const AlgLoader g_huksLoader = { .importPublicKey = ImportPublicKey, .checkDlPublicKey = CheckDlPublicKey, .checkEcPublicKey = CheckEcPublicKey, - .bigNumCompare = BigNumCompare + .bigNumCompare = BigNumCompare, + .base64Encode = MbedtlsBase64Encode, + .base64Decode = MbedtlsBase64Decode }; const AlgLoader *GetRealLoaderInstance(void) diff --git a/deps_adapter/key_management_adapter/impl/src/mbedtls_ec_adapter.c b/deps_adapter/key_management_adapter/impl/src/mbedtls_ec_adapter.c index b801bbbd..ddf4fd84 100644 --- a/deps_adapter/key_management_adapter/impl/src/mbedtls_ec_adapter.c +++ b/deps_adapter/key_management_adapter/impl/src/mbedtls_ec_adapter.c @@ -15,6 +15,7 @@ #include "mbedtls_ec_adapter.h" +#include #include #include #include @@ -564,3 +565,60 @@ int32_t MbedtlsAgreeSharedSecret(const KeyBuff *priKey, const KeyBuff *pubKey, U } return HAL_SUCCESS; } + +int32_t MbedtlsBase64Encode(const uint8_t *byte, uint32_t byteLen, char *base64Str, uint32_t strLen, uint32_t *outLen) +{ + CHECK_PTR_RETURN_HAL_ERROR_CODE(byte, "byte"); + CHECK_LEN_ZERO_RETURN_ERROR_CODE(byteLen, "byteLen"); + CHECK_PTR_RETURN_HAL_ERROR_CODE(base64Str, "base64Str"); + CHECK_LEN_ZERO_RETURN_ERROR_CODE(strLen, "strLen"); + CHECK_PTR_RETURN_HAL_ERROR_CODE(outLen, "outLen"); + + size_t needBuffLen = 0; + (void)mbedtls_base64_encode(NULL, 0, &needBuffLen, byte, byteLen); + if (needBuffLen > strLen) { + LOGE("The content to be written is larger than the input buffer size. Need: %zd, Buffer: %u", + needBuffLen, strLen); + return HAL_ERR_SHORT_BUFFER; + } + + int res = mbedtls_base64_encode((unsigned char *)base64Str, strLen, &needBuffLen, byte, byteLen); + if (res != 0) { + LOGE("call mbedtls's mbedtls_base64_encode fail. res: %d", res); + return HAL_ERR_MBEDTLS; + } + + *outLen = needBuffLen; + return HAL_SUCCESS; +} + +int32_t MbedtlsBase64Decode(const char *base64Str, uint32_t strLen, uint8_t *byte, uint32_t byteLen, uint32_t *outLen) +{ + CHECK_PTR_RETURN_HAL_ERROR_CODE(base64Str, "base64Str"); + CHECK_LEN_ZERO_RETURN_ERROR_CODE(strLen, "strLen"); + CHECK_PTR_RETURN_HAL_ERROR_CODE(byte, "byte"); + CHECK_LEN_ZERO_RETURN_ERROR_CODE(byteLen, "byteLen"); + CHECK_PTR_RETURN_HAL_ERROR_CODE(outLen, "outLen"); + + size_t needBuffLen = 0; + int res = mbedtls_base64_decode(NULL, 0, &needBuffLen, (const unsigned char *)base64Str, strLen); + if (res == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) { + LOGE("The input string is not in base64 encoding format."); + return HAL_ERR_BASE64_FORMAT; + } + + if (needBuffLen > byteLen) { + LOGE("The content to be written is larger than the input buffer size. Need: %zd, Buffer: %u", + needBuffLen, byteLen); + return HAL_ERR_SHORT_BUFFER; + } + + res = mbedtls_base64_decode(byte, byteLen, &needBuffLen, (const unsigned char *)base64Str, strLen); + if (res != 0) { + LOGE("call mbedtls's mbedtls_base64_decode fail. res: %d", res); + return HAL_ERR_MBEDTLS; + } + + *outLen = (uint32_t)needBuffLen; + return HAL_SUCCESS; +} diff --git a/deps_adapter/key_management_adapter/interfaces/alg_defs.h b/deps_adapter/key_management_adapter/interfaces/alg_defs.h index f02b9a1a..6e6fe06d 100644 --- a/deps_adapter/key_management_adapter/interfaces/alg_defs.h +++ b/deps_adapter/key_management_adapter/interfaces/alg_defs.h @@ -129,6 +129,12 @@ typedef bool (*CheckDlPublicKeyFunc)(const Uint8Buff *key, const char *primeHex) typedef int32_t (*BigNumCompareFunc)(const Uint8Buff *x, const Uint8Buff *y); +typedef int32_t (*Base64EncodeFunc)(const uint8_t *byte, uint32_t byteLen, + char *base64Str, uint32_t strLen, uint32_t *outLen); + +typedef int32_t (*Base64DecodeFunc)(const char *base64Str, uint32_t strLen, + uint8_t *byte, uint32_t byteLen, uint32_t *outLen); + typedef struct { InitAlgFunc initAlg; Sha256Func sha256; @@ -153,6 +159,8 @@ typedef struct { CheckDlPublicKeyFunc checkDlPublicKey; CheckEcPublicKeyFunc checkEcPublicKey; BigNumCompareFunc bigNumCompare; + Base64EncodeFunc base64Encode; + Base64DecodeFunc base64Decode; } AlgLoader; #endif \ No newline at end of file diff --git a/deps_adapter/os_adapter/impl/src/linux/hc_thread.c b/deps_adapter/os_adapter/impl/src/linux/hc_thread.c index c1d62616..87dbce09 100644 --- a/deps_adapter/os_adapter/impl/src/linux/hc_thread.c +++ b/deps_adapter/os_adapter/impl/src/linux/hc_thread.c @@ -30,6 +30,7 @@ void *StaticThreadFunc(void *args) return NULL; } +#if defined(SET_THREAD_NAME) int res = pthread_setname_np(pthread_self(), StringGet(&thread->name)); if (res != 0) { LOGW("[OS]: pthread_setname_np fail. [Res]: %d", res); @@ -37,6 +38,7 @@ void *StaticThreadFunc(void *args) LOGI("[OS]: pthread_setname_np success. [StackSize]: %zu, [Name]: %s", thread->stackSize, StringGet(&thread->name)); } +#endif if (thread->threadFunc) { thread->threadFunc(args); diff --git a/deps_adapter/os_adapter/impl/src/liteos/hc_thread.c b/deps_adapter/os_adapter/impl/src/liteos/hc_thread.c index 55a13e9f..adac3ace 100644 --- a/deps_adapter/os_adapter/impl/src/liteos/hc_thread.c +++ b/deps_adapter/os_adapter/impl/src/liteos/hc_thread.c @@ -26,10 +26,12 @@ void *StaticThreadFunc(void *args) return NULL; } +#if defined(SET_THREAD_NAME) int res = pthread_setname_np(pthread_self(), StringGet(&thread->name)); if (res != 0) { LOGW("[OS]: pthread_setname_np fail. [Res]: %d", res); } +#endif if (thread->threadFunc) { thread->threadFunc(args); diff --git a/deps_adapter/os_adapter/interfaces/hal_error.h b/deps_adapter/os_adapter/interfaces/hal_error.h index b8959048..c5156ac7 100644 --- a/deps_adapter/os_adapter/interfaces/hal_error.h +++ b/deps_adapter/os_adapter/interfaces/hal_error.h @@ -36,5 +36,6 @@ enum { HAL_ERR_SHORT_BUFFER = -21, HAL_ERR_NOT_SUPPORTED = -22, HAL_ERR_MBEDTLS = -23, + HAL_ERR_BASE64_FORMAT = -24, }; #endif \ No newline at end of file diff --git a/deviceauth_env.gni b/deviceauth_env.gni index e79c9025..af2501aa 100644 --- a/deviceauth_env.gni +++ b/deviceauth_env.gni @@ -27,6 +27,22 @@ declare_args() { enable_soft_bus_channel = true } +build_flags = [ + "-O2", + "-ftrapv", + "-Wall", + "-Werror", + "-Wextra", + "-Wshadow", + "-fstack-protector-all", + "-FPIC", + "-FS", + "-D_FORTITY_SOURCE=2", + "-Wformat=2", + "-Wfloat-equal", + "-Wdate-time", +] + if (defined(ohos_lite)) { if (ohos_kernel_type == "liteos_m") { import("${deviceauth_feature_config}/mini/config.gni") diff --git a/frameworks/src/ipc_sdk.c b/frameworks/src/ipc_sdk.c index ff96ee35..5ed0d431 100644 --- a/frameworks/src/ipc_sdk.c +++ b/frameworks/src/ipc_sdk.c @@ -1920,7 +1920,7 @@ DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void) DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void) { - static GroupAuthManager gaInstCtx = {NULL}; + static GroupAuthManager gaInstCtx; static GroupAuthManager *gaInstPtr = NULL; if (gaInstPtr == NULL) { @@ -1932,7 +1932,7 @@ DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void) DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void) { - static DeviceGroupManager gmInstCtx = {NULL}; + static DeviceGroupManager gmInstCtx; static DeviceGroupManager *gmInstPtr = NULL; if (gmInstPtr == NULL) { diff --git a/frameworks/src/lite/ipc_adapt.c b/frameworks/src/lite/ipc_adapt.c index 1d747d42..267bed2c 100644 --- a/frameworks/src/lite/ipc_adapt.c +++ b/frameworks/src/lite/ipc_adapt.c @@ -1396,6 +1396,7 @@ int32_t SetCallRequestParamInfo(uintptr_t callCtx, int32_t type, const uint8_t * int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync) { + (void)withSync; int32_t ret; ProxyDevAuthData *dataCache = (ProxyDevAuthData *)(callCtx); @@ -1409,6 +1410,7 @@ int32_t DoBinderCall(uintptr_t callCtx, int32_t methodId, bool withSync) /* ipc service process adapter */ uint32_t SetIpcCallMap(uintptr_t ipcInstance, IpcServiceCall method, int32_t methodId) { + (void)ipcInstance; if ((method == NULL) || (methodId <= 0)) { return HC_ERR_INVALID_PARAMS; } diff --git a/frameworks/src/lite/ipc_callback_stub.c b/frameworks/src/lite/ipc_callback_stub.c index abfc528e..2239efc0 100644 --- a/frameworks/src/lite/ipc_callback_stub.c +++ b/frameworks/src/lite/ipc_callback_stub.c @@ -53,6 +53,7 @@ static void DoCallBack(int32_t callbackId, uintptr_t cbHook, IpcIo *data, IpcIo int32_t CbStubOnRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) { + (void)option; int32_t callbackId; uintptr_t cbHook = 0x0; diff --git a/frameworks/src/lite/ipc_dev_auth_proxy.c b/frameworks/src/lite/ipc_dev_auth_proxy.c index 3a1179ac..775bbcf8 100644 --- a/frameworks/src/lite/ipc_dev_auth_proxy.c +++ b/frameworks/src/lite/ipc_dev_auth_proxy.c @@ -103,6 +103,7 @@ int32_t FinalCallRequest(ProxyDevAuthData *dataCtx, int32_t methodId) static int32_t CliInvokeRetCallback(IOwner owner, int32_t code, IpcIo *reply) { + (void)code; IpcIo *dstReply = NULL; errno_t eno; diff --git a/frameworks/src/standard/ipc_dev_auth_stub.cpp b/frameworks/src/standard/ipc_dev_auth_stub.cpp index 9dc9bb6a..ea4adbec 100644 --- a/frameworks/src/standard/ipc_dev_auth_stub.cpp +++ b/frameworks/src/standard/ipc_dev_auth_stub.cpp @@ -325,10 +325,8 @@ void ServiceDevAuth::ActCallback(int32_t objIdx, int32_t callbackId, bool sync, return; } MessageOption option(MessageOption::TF_SYNC); - option.SetWaitTime(DEV_AUTH_CALL_WAIT_TIME); if (!sync) { option.SetFlags(MessageOption::TF_ASYNC); - option.SetWaitTime(0); } std::lock_guard autoLock(g_cBMutex); sptr proxy = iface_cast(g_cbStub[objIdx].cbStub); diff --git a/services/BUILD.gn b/services/BUILD.gn index a3d1f3fb..94b8b838 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -295,7 +295,7 @@ if (os_level == "mini" || os_level == "small") { "c_utils:utils", "hilog:libhilog", "init:libbegetutil", - "ipc:ipc_core", + "ipc:ipc_single", "samgr:samgr_proxy", ] } diff --git a/services/cred_manager/src/account_related/account_related_cred_plugin.c b/services/cred_manager/src/account_related/account_related_cred_plugin.c index 25d4735b..124e49c1 100644 --- a/services/cred_manager/src/account_related/account_related_cred_plugin.c +++ b/services/cred_manager/src/account_related/account_related_cred_plugin.c @@ -54,6 +54,7 @@ static int32_t ProcessAsyTokens(int32_t osAccountId, int32_t cmdId, CJson *in, C static int32_t ProcessSymTokens(int32_t osAccountId, int32_t cmdId, CJson *in, CJson *out) { + (void)out; switch (cmdId) { case IMPORT_SELF_CREDENTIAL: case IMPORT_TRUSTED_CREDENTIALS: diff --git a/services/deviceauth.gni b/services/deviceauth.gni index 1515d5c9..37eba280 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -424,9 +424,6 @@ if (defined(ohos_lite)) { deviceauth_files += security_label_adapter_files } -#build_flags = [ "-Wrestrict" ] -build_flags = [ "-Werror" ] - if (target_os == "linux") { build_flags += [ "-D__LINUX__" ] } diff --git a/services/key_agree_sdk/key_agree_sdk.gni b/services/key_agree_sdk/key_agree_sdk.gni index 4d3e108f..ee6deddf 100644 --- a/services/key_agree_sdk/key_agree_sdk.gni +++ b/services/key_agree_sdk/key_agree_sdk.gni @@ -72,8 +72,6 @@ if (enable_key_agree_pake_ec_prime_x25519 == true) { key_agree_defines += [ "P2P_PAKE_EC_PRIME_X25519" ] } -build_flags = [ "-Werror" ] - if (target_os == "linux") { build_flags += [ "-D__LINUX__" ] } diff --git a/services/legacy/authenticators/src/account_related/auth/iso_auth_task/iso_auth_task_common.c b/services/legacy/authenticators/src/account_related/auth/iso_auth_task/iso_auth_task_common.c index 48b9b886..e98374c1 100644 --- a/services/legacy/authenticators/src/account_related/auth/iso_auth_task/iso_auth_task_common.c +++ b/services/legacy/authenticators/src/account_related/auth/iso_auth_task/iso_auth_task_common.c @@ -119,7 +119,7 @@ static int32_t FillPayload(const CJson *in, IsoAuthParams *params) return HC_SUCCESS; } -static int32_t SetChallenge(IsoAuthParams *params, const CJson *in) +static int32_t SetChallenge(IsoAuthParams *params) { if (((uint32_t)params->credentialType & SYMMETRIC_CRED) == SYMMETRIC_CRED) { params->challenge.length = HcStrlen(KEY_INFO_PERSISTENT_TOKEN); @@ -242,7 +242,7 @@ int32_t InitIsoAuthParams(const CJson *in, IsoAuthParams *params, const AccountV goto CLEAN_UP; } if (params->localDevType == DEVICE_TYPE_ACCESSORY) { - res = SetChallenge(params, in); + res = SetChallenge(params); if (res != HC_SUCCESS) { LOGE("SetChallenge failed, res = %d.", res); goto CLEAN_UP; diff --git a/services/legacy/authenticators/src/account_related/auth/pake_v2_auth_task/pake_v2_auth_server_task.c b/services/legacy/authenticators/src/account_related/auth/pake_v2_auth_task/pake_v2_auth_server_task.c index 89a7f2fd..a72bd47f 100644 --- a/services/legacy/authenticators/src/account_related/auth/pake_v2_auth_task/pake_v2_auth_server_task.c +++ b/services/legacy/authenticators/src/account_related/auth/pake_v2_auth_task/pake_v2_auth_server_task.c @@ -50,7 +50,7 @@ static void DestroyAuthServerAuthTask(TaskBase *task) HcFree(innerTask); } -static int32_t DealAsyStepOneData(PakeV2AuthServerTask *task, const CJson *in) +static int32_t DealAsyStepOneData(PakeV2AuthServerTask *task) { int32_t res = VerifyPkSignPeer(&task->params); if (res != HC_SUCCESS) { @@ -73,7 +73,7 @@ static int32_t DealAsyStepOneData(PakeV2AuthServerTask *task, const CJson *in) return HC_SUCCESS; } -static int32_t PrepareAsyServerStepOneData(const PakeV2AuthServerTask *innerTask, const CJson *in, CJson *out) +static int32_t PrepareAsyServerStepOneData(const PakeV2AuthServerTask *innerTask, CJson *out) { CJson *sendToPeer = CreateJson(); if (sendToPeer == NULL) { @@ -141,8 +141,8 @@ static int32_t AsyAuthServerStepOne(TaskBase *task, const CJson *in, CJson *out, return HC_ERR_NULL_PTR; } innerTask->params.pkInfoSignPeer.length = HcStrlen(pkInfoSignPeerStr) / BYTE_TO_HEX_OPER_LENGTH; - GOTO_IF_ERR(DealAsyStepOneData(innerTask, in)); - GOTO_IF_ERR(PrepareAsyServerStepOneData(innerTask, in, out)); + GOTO_IF_ERR(DealAsyStepOneData(innerTask)); + GOTO_IF_ERR(PrepareAsyServerStepOneData(innerTask, out)); innerTask->taskBase.taskStatus = TASK_STATUS_PAKE_FOLLOW_STEP_TWO; *status = CONTINUE; diff --git a/services/legacy/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c b/services/legacy/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c index e23472b8..c1a165e4 100644 --- a/services/legacy/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c +++ b/services/legacy/group_auth/src/group_auth_manager/account_related_group_auth/account_related_group_auth.c @@ -559,7 +559,7 @@ static int32_t AccountOnFinishToPeer(int64_t requestId, const CJson *out, const } static int32_t PrepareTrustedDeviceInfo(const char *peerUdid, const char *groupId, - const CJson *authParam, const CJson *out, TrustedDeviceEntry *devEntry) + const CJson *out, TrustedDeviceEntry *devEntry) { devEntry->source = SELF_CREATED; const CJson *sendToSelf = GetObjFromJson(out, FIELD_SEND_TO_SELF); @@ -622,7 +622,7 @@ static int32_t AddTrustedDeviceForAccount(const CJson *authParam, const CJson *o } int32_t res; do { - res = PrepareTrustedDeviceInfo(peerUdid, groupId, authParam, out, devEntry); + res = PrepareTrustedDeviceInfo(peerUdid, groupId, out, devEntry); if (res != HC_SUCCESS) { LOGE("Failed to prepare trust device params!"); break; diff --git a/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c b/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c index 9f15216a..c3666a40 100644 --- a/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c +++ b/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c @@ -145,19 +145,21 @@ static int32_t GetRecvEncData(const CJson *receviedMsg, Uint8Buff *recvEncData) LOGE("get encData from json failed."); return HC_ERR_JSON_GET; } - uint32_t recvEncDataLen = HcStrlen(base64Str) / 4 * 3; + uint32_t recvEncDataLen = HcStrlen(base64Str) / BYTE_TO_BASE64_MULTIPLIER * BYTE_TO_BASE64_DIVISOR; uint8_t *recvEncDataVal = (uint8_t *)HcMalloc(recvEncDataLen, 0); if (recvEncDataVal == NULL) { LOGE("allocate recvEncDataVal memory fail."); return HC_ERR_ALLOC_MEMORY; } - if (Base64StringToByte(base64Str, recvEncDataVal, &recvEncDataLen) != HC_SUCCESS) { + uint32_t outLen = 0; + if (GetLoaderInstance()->base64Decode(base64Str, HcStrlen(base64Str), + recvEncDataVal, recvEncDataLen, &outLen) != HC_SUCCESS) { LOGE("base64 decode fail."); HcFree(recvEncDataVal); return HC_ERR_CONVERT_FAILED; } recvEncData->val = recvEncDataVal; - recvEncData->length = recvEncDataLen; + recvEncData->length = outLen; return HC_SUCCESS; } @@ -343,7 +345,8 @@ static int32_t BuildEncData(ExpandSubSessionImpl *impl, CJson *sendCmdList, CJso FreeUint8Buff(&sendEncData); return HC_ERR_ALLOC_MEMORY; } - res = ByteToBase64String(sendEncData.val, sendEncData.length, base64Str, base64StrLen); + uint32_t outLen = 0; + res = GetLoaderInstance()->base64Encode(sendEncData.val, sendEncData.length, base64Str, base64StrLen, &outLen); FreeUint8Buff(&sendEncData); if (res != HC_SUCCESS) { LOGE("base64 encode fail."); diff --git a/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp b/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp index c7abab5a..5c6eebde 100644 --- a/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp +++ b/test/unittest/deviceauth/unit_test/source/common_lib_test.cpp @@ -512,38 +512,6 @@ HWTEST_F(CommonLibTest, HcStringUtilTest001, TestSize.Level0) EXPECT_EQ(ret, 0); } -HWTEST_F(CommonLibTest, HcStringUtilTest002, TestSize.Level0) -{ - const uint8_t byteData[] = "1234"; - uint32_t byteSize = sizeof(byteData) / sizeof(byteData[0]); - uint32_t invalidByteLen = 0; - uint8_t byteStrBase64[TEST_BUFFER_SIZE] = { 0 }; - int32_t ret = Base64StringToByte(nullptr, nullptr, nullptr); - EXPECT_EQ(ret, CLIB_ERR_NULL_PTR); - ret = Base64StringToByte("a", byteStrBase64, &byteSize); - EXPECT_EQ(ret, CLIB_ERR_INVALID_LEN); - ret = Base64StringToByte("abcd", byteStrBase64, &invalidByteLen); - EXPECT_EQ(ret, CLIB_ERR_INVALID_LEN); - ret = Base64StringToByte("****", byteStrBase64, &byteSize); - EXPECT_EQ(ret, CLIB_ERR_INVALID_PARAM); - ret = Base64StringToByte("abcd", byteStrBase64, &byteSize); - EXPECT_EQ(ret, CLIB_SUCCESS); - char byte64Str[TEST_BUFFER_SIZE] = { 0 }; - ret = ByteToBase64String(nullptr, byteSize, nullptr, TEST_BUFFER_SIZE); - EXPECT_EQ(ret, CLIB_ERR_NULL_PTR); - ret = ByteToBase64String(byteData, UINT32_MAX, byte64Str, TEST_BUFFER_SIZE); - EXPECT_EQ(ret, CLIB_ERR_INVALID_LEN); - ret = ByteToBase64String(byteData, byteSize, byte64Str, TEST_LENGTH_ZERO); - EXPECT_EQ(ret, CLIB_ERR_INVALID_LEN); - ret = ByteToBase64String(byteData, byteSize, byte64Str, TEST_BUFFER_SIZE); - EXPECT_EQ(ret, CLIB_SUCCESS); - char *desStr = nullptr; - ret = ToUpperCase(nullptr, &desStr); - EXPECT_EQ(ret, CLIB_ERR_NULL_PTR); - ret = ToUpperCase("abcdefg", &desStr); - EXPECT_EQ(ret, CLIB_SUCCESS); -} - HWTEST_F(CommonLibTest, ParseTlvHeadTest001, TestSize.Level0) { HcParcel parcelWithData = CreateParcel(TEST_BUFFER_SIZE, TEST_BUFFER_SIZE); -- Gitee