Merge pull request !105 from 马腾飞/master
This commit is contained in:
openharmony_ci
2022-03-21 07:25:07 +00:00
committed by Gitee
54 changed files with 610 additions and 819 deletions
-1
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
+12 -12
View File
@@ -4,7 +4,7 @@
## Introduction
As a basic component of the Identity & Access Management (IAM) subsystem, Authentication Executor Management (auth_executor_mgr) manages and schedules authentication resources in the system. Currently, password authentication and facial authentication are supported.
As a basic component of the User Identity & Access Management (IAM) subsystem, Authentication Executor Management (auth_executor_mgr) manages and schedules authentication resources in the system. Currently, password authentication and facial authentication are supported.
The user authentication unit on the device is called authentication executor.
@@ -16,19 +16,19 @@ The auth_executor_mgr module provides a set of resource management APIs. After i
The OpenHarmony framework implements the auth_executor_mgr service and has encapsulated the collaborative scheduling and resource management APIs. Device vendors need to adapt some functions of the authentication executor management component to meet higher security requirements. The APIs that need to be adapted by device vendors are defined in the IAM common HDI.
The OpenHarmony framework implements the auth_executor_mgr service and has encapsulated the collaborative scheduling and resource management APIs. Device vendors need to adapt some functions of the auth_executor_mgr component to meet higher security requirements. The APIs that need to be adapted by device vendors are defined in the IAM common HDI.
## Directory Structure
```undefined
//base/user_iam/auth_executor_mgr
├── common # Directory for storing the IAM common HDI
├── common # Directory for storing the IAM common HDI
├── frameworks # Framework code
├── interfaces # Directory for storing external interfaces
│ └── innerkits # Header files exposed to the internal subsystem
├── sa_profile # Profile of the Service Ability
├── services # Implementation of Service Ability services
├── test # Directory for storing test code
├── sa_profile # Profile of the Service ability
├── services # Implementation of the Service ability
├── test # Directory for storing test code
├── utils # Directory for storing utility code
├── auth_executor_mgr.gni # Build configuration
└── bundle.json # Component description file
@@ -67,17 +67,17 @@ The OpenHarmony framework implements the auth_executor_mgr service and has encap
### Usage Guidelines
- The auth_executor_mgr SA provides interconnection APIs for the authentication executors. The authentication executors call the related API to register with the auth_executor_mgr.
- The auth_executor_mgr Service ability provides interconnection APIs for the authentication executors. The authentication executors call the related API to register with the auth_executor_mgr.
- The APIs defined in the ```common\interface\coauth_interface.h``` header file must be implemented in a TEE. The authentication executor information cannot be tampered with, and the result returned by the authentication executor must be verified in the TEE.
## Repositories Involved
**[useriam_auth_executor_mgr](https://gitee.com/useriam_auth_executor_mgr/blob/master/README.md)**
**[useriam_auth_executor_mgr](https://gitee.com/openharmony-sig/useriam_coauth)**
[useriam_user_idm](https://gitee.com/openharmony/useriam_user_idm/blob/master/README.md)
[useriam_user_idm](https://gitee.com/openharmony-sig/useriam_useridm)
[useriam_user_auth](https://gitee.com/openharmony/useriam_user_auth/blob/master/README.md)
[useriam_user_auth](https://gitee.com/openharmony-sig/useriam_userauth)
[useriam_pin_auth](https://gitee.com/openharmony/useriam_pin_auth/blob/master/README.md)
[useriam_pin_auth](https://gitee.com/openharmony-sig/useriam_pinauth)
useriam_faceauth
[useriam_faceauth](https://gitee.com/openharmony/useriam_faceauth)
+3 -2
View File
@@ -30,6 +30,7 @@ ohos_shared_library("useriam_common_lib") {
"coauth/src/coauth_funcs.c",
"coauth/src/coauth_sign_centre.c",
"coauth/src/executor_message.c",
"coauth/src/pool.c",
"common/src/buffer.c",
"common/src/linked_list.c",
"common/src/tlv_base.c",
@@ -43,8 +44,8 @@ ohos_shared_library("useriam_common_lib") {
"hal_sdk/useridm_interface.cpp",
"idm/src/idm_session.c",
"idm/src/user_idm_funcs.c",
"key_mgr/src/token_key.c",
"lock/src/lock.c",
"pool/src/pool.c",
"user_auth/src/auth_level.c",
"user_auth/src/context_manager.c",
"user_auth/src/user_auth_funcs.c",
@@ -59,7 +60,7 @@ ohos_shared_library("useriam_common_lib") {
"common/inc",
"interface",
"idm/inc",
"pool/inc",
"key_mgr/inc",
"user_auth/inc",
"//third_party/openssl/include",
]
-2
View File
@@ -34,8 +34,6 @@ int32_t Ed25519Sign(const KeyPair *keyPair, const Buffer *data, Buffer **sign);
int32_t Ed25519Verify(const Buffer *pubKey, const Buffer *data, const Buffer *sign);
int32_t HmacSha256(const Buffer *hmacKey, const Buffer *data, Buffer **hmac);
int32_t HmacSha512(const Buffer *hmacKey, const Buffer *data, Buffer **hmac);
int32_t SecureRandom(uint8_t *buffer, uint32_t size);
#endif
+25 -51
View File
@@ -40,13 +40,13 @@ static KeyPair *CreateEd25519KeyPair()
}
keyPair->pubKey = CreateBuffer(ED25519_FIX_PUBKEY_BUFFER_SIZE);
if (keyPair->pubKey == NULL) {
LOG_ERROR("no memory for pub key");
LOG_ERROR("no memory for public key");
Free(keyPair);
return NULL;
}
keyPair->priKey = CreateBuffer(ED25519_FIX_PRIKEY_BUFFER_SIZE);
if (keyPair->priKey == NULL) {
LOG_ERROR("no memory for pri key");
LOG_ERROR("no memory for private key");
DestoryBuffer(keyPair->pubKey);
Free(keyPair);
return NULL;
@@ -75,11 +75,11 @@ bool IsEd25519KeyPairValid(const KeyPair *keyPair)
return false;
}
if (!CheckBufferWithSize(keyPair->pubKey, ED25519_FIX_PUBKEY_BUFFER_SIZE)) {
LOG_ERROR("invalid pub key");
LOG_ERROR("invalid public key");
return false;
}
if (!CheckBufferWithSize(keyPair->priKey, ED25519_FIX_PRIKEY_BUFFER_SIZE)) {
LOG_ERROR("invalid pri key");
LOG_ERROR("invalid private key");
return false;
}
return true;
@@ -89,32 +89,32 @@ KeyPair *GenerateEd25519KeyPair(void)
{
KeyPair *keyPair = CreateEd25519KeyPair();
if (keyPair == NULL) {
LOG_ERROR("create key pair fail");
LOG_ERROR("create key pair failed");
return NULL;
}
EVP_PKEY *key = NULL;
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, NULL);
if (ctx == NULL) {
LOG_ERROR("new ctx fail");
LOG_ERROR("new ctx failed");
goto ERROR;
}
if (EVP_PKEY_keygen_init(ctx) != OPENSSL_SUCCESS) {
LOG_ERROR("init ctx fail");
LOG_ERROR("init ctx failed");
goto ERROR;
}
if (EVP_PKEY_keygen(ctx, &key) != OPENSSL_SUCCESS) {
LOG_ERROR("generate key fail");
LOG_ERROR("generate key failed");
goto ERROR;
}
size_t pubKeySize = keyPair->pubKey->maxSize;
if (EVP_PKEY_get_raw_public_key(key, keyPair->pubKey->buf, &pubKeySize) != OPENSSL_SUCCESS) {
LOG_ERROR("get pub key fail");
LOG_ERROR("get public key failed");
goto ERROR;
}
keyPair->pubKey->contentSize = pubKeySize;
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");
LOG_ERROR("get private key failed");
goto ERROR;
}
keyPair->priKey->contentSize = priKeySize;
@@ -136,34 +136,34 @@ EXIT:
int32_t Ed25519Sign(const KeyPair *keyPair, const Buffer *data, Buffer **sign)
{
if (!IsEd25519KeyPairValid(keyPair) || !IsBufferValid(data) || sign == NULL) {
LOG_ERROR("bad param");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
int32_t ret = RESULT_GENERAL_ERROR;
EVP_PKEY *key = EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, NULL,
keyPair->priKey->buf, keyPair->priKey->contentSize);
if (key == NULL) {
LOG_ERROR("get pri key fail");
LOG_ERROR("get private key failed");
return ret;
}
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
if (ctx == NULL) {
LOG_ERROR("get ctx fail");
LOG_ERROR("get ctx failed");
EVP_PKEY_free(key);
return ret;
}
if (EVP_DigestSignInit(ctx, NULL, NULL, NULL, key) != OPENSSL_SUCCESS) {
LOG_ERROR("init sign fail");
LOG_ERROR("init sign failed");
goto EXIT;
}
*sign = CreateBuffer(ED25519_FIX_SIGN_BUFFER_SIZE);
if (!IsBufferValid(*sign)) {
LOG_ERROR("create buffer fail");
LOG_ERROR("create buffer failed");
goto EXIT;
}
size_t signSize = (*sign)->maxSize;
if (EVP_DigestSign(ctx, (*sign)->buf, &signSize, data->buf, data->contentSize) != OPENSSL_SUCCESS) {
LOG_ERROR("sign fail");
LOG_ERROR("sign failed");
DestoryBuffer(*sign);
*sign = NULL;
goto EXIT;
@@ -187,21 +187,21 @@ int32_t Ed25519Verify(const Buffer *pubKey, const Buffer *data, const Buffer *si
int32_t ret = RESULT_GENERAL_ERROR;
EVP_PKEY *key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, pubKey->buf, pubKey->contentSize);
if (key == NULL) {
LOG_ERROR("get pub key fail");
LOG_ERROR("get public key failed");
return ret;
}
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
if (ctx == NULL) {
LOG_ERROR("get ctx fail");
LOG_ERROR("get ctx failed");
EVP_PKEY_free(key);
return ret;
}
if (EVP_DigestVerifyInit(ctx, NULL, NULL, NULL, key) != OPENSSL_SUCCESS) {
LOG_ERROR("init verify fail");
LOG_ERROR("init verify failed");
goto EXIT;
}
if (EVP_DigestVerify(ctx, sign->buf, sign->contentSize, data->buf, data->contentSize) != OPENSSL_SUCCESS) {
LOG_ERROR("verify fail");
LOG_ERROR("verify failed");
goto EXIT;
}
ret = RESULT_SUCCESS;
@@ -212,8 +212,7 @@ EXIT:
return ret;
}
static int32_t IamHmac(const EVP_MD *alg,
const Buffer *hmacKey, const Buffer *data, Buffer *hmac)
static int32_t IamHmac(const EVP_MD *alg, const Buffer *hmacKey, const Buffer *data, Buffer *hmac)
{
if (!IsBufferValid(hmacKey) || hmacKey->contentSize > INT_MAX ||
!IsBufferValid(data) || !IsBufferValid(hmac) || hmac->maxSize > UINT_MAX) {
@@ -224,7 +223,7 @@ static int32_t IamHmac(const EVP_MD *alg,
uint8_t *hmacData = HMAC(alg, hmacKey->buf, (int)hmacKey->contentSize, data->buf, data->contentSize,
hmac->buf, &hmacSize);
if (hmacData == NULL) {
LOG_ERROR("hmac fail");
LOG_ERROR("hmac failed");
return RESULT_GENERAL_ERROR;
}
hmac->contentSize = hmacSize;
@@ -244,38 +243,13 @@ int32_t HmacSha256(const Buffer *hmacKey, const Buffer *data, Buffer **hmac)
}
*hmac = CreateBuffer(SHA256_DIGEST_SIZE);
if (*hmac == NULL) {
LOG_ERROR("create buffer fail");
LOG_ERROR("create buffer failed");
return RESULT_NO_MEMORY;
}
if (IamHmac(alg, hmacKey, data, *hmac) != RESULT_SUCCESS) {
DestoryBuffer(*hmac);
*hmac = NULL;
LOG_ERROR("hmac fail");
return RESULT_GENERAL_ERROR;
}
return RESULT_SUCCESS;
}
int32_t HmacSha512(const Buffer *hmacKey, const Buffer *data, Buffer **hmac)
{
if (hmac == NULL) {
LOG_ERROR("hmac is null");
return RESULT_BAD_PARAM;
}
const EVP_MD *alg = EVP_sha512();
if (alg == NULL) {
LOG_ERROR("no algo");
return RESULT_GENERAL_ERROR;
}
*hmac = CreateBuffer(SHA512_DIGEST_SIZE);
if (*hmac == NULL) {
LOG_ERROR("create buffer fail");
return RESULT_NO_MEMORY;
}
if (IamHmac(alg, hmacKey, data, *hmac) != RESULT_SUCCESS) {
DestoryBuffer(*hmac);
*hmac = NULL;
LOG_ERROR("hmac fail");
LOG_ERROR("hmac failed");
return RESULT_GENERAL_ERROR;
}
return RESULT_SUCCESS;
@@ -288,7 +262,7 @@ int32_t SecureRandom(uint8_t *buffer, uint32_t size)
return RESULT_BAD_PARAM;
}
if (RAND_bytes(buffer, (int)size) != OPENSSL_SUCCESS) {
LOG_ERROR("rand fail");
LOG_ERROR("rand failed");
return RESULT_GENERAL_ERROR;
}
return RESULT_SUCCESS;
+1 -1
View File
@@ -50,7 +50,7 @@ bool IsFileOperatorValid(const FileOperator *fileOperator)
FileOperator *GetFileOperator(const FileOperatorType type)
{
if (type == DEFAULT_FILE_OPERATOR) {
LOG_INFO("Get default file operator");
LOG_INFO("get default file operator");
return GetDefaultFileOperator();
}
return NULL;
+2 -2
View File
@@ -26,7 +26,7 @@ uint64_t GetRtcTime(void)
struct timespec curTime;
int res = clock_gettime(CLOCK_REALTIME, &curTime);
if (res != 0) {
LOG_ERROR("get time fail");
LOG_ERROR("get time failed");
return 0;
}
return curTime.tv_sec * MS_OF_S + curTime.tv_nsec / NS_OF_MS;
@@ -37,7 +37,7 @@ uint64_t GetSystemTime(void)
struct timespec curTime;
int res = clock_gettime(CLOCK_MONOTONIC, &curTime);
if (res != 0) {
LOG_ERROR("get time fail");
LOG_ERROR("get time failed");
return 0;
}
return curTime.tv_sec * MS_OF_S + curTime.tv_nsec / NS_OF_MS;
+8 -8
View File
@@ -41,12 +41,12 @@ static int32_t ReadFile(const char *fileName, uint8_t *buf, uint32_t len)
}
FILE *fileOperator = fopen(fileName, "rb");
if (fileOperator == NULL) {
LOG_ERROR("open file fail");
LOG_ERROR("open file failed");
return RESULT_BAD_PARAM;
}
size_t readLen = fread(buf, sizeof(uint8_t), len, fileOperator);
if (readLen != len) {
LOG_ERROR("read file fail");
LOG_ERROR("read file failed");
(void)fclose(fileOperator);
(void)memset_s(buf, len, 0, len);
return RESULT_BAD_READ;
@@ -63,12 +63,12 @@ static int32_t WriteFile(const char *fileName, const uint8_t *buf, uint32_t len)
}
FILE *fileOperator = fopen(fileName, "wb");
if (fileOperator == NULL) {
LOG_ERROR("open file fail");
LOG_ERROR("open file failed");
return RESULT_BAD_PARAM;
}
size_t writeLen = fwrite(buf, sizeof(uint8_t), len, fileOperator);
if (writeLen != len) {
LOG_ERROR("write file fail");
LOG_ERROR("write file failed");
(void)fclose(fileOperator);
return RESULT_BAD_WRITE;
}
@@ -85,17 +85,17 @@ static int32_t GetFileLen(const char *fileName, uint32_t *len)
*len = 0;
FILE *fileOperator = fopen(fileName, "rb");
if (fileOperator == NULL) {
LOG_ERROR("fopen file fail");
LOG_ERROR("fopen file failed");
return RESULT_BAD_PARAM;
}
if (fseek(fileOperator, 0L, SEEK_END) != 0) {
LOG_ERROR("seek file fail");
LOG_ERROR("seek file failed");
(void)fclose(fileOperator);
return RESULT_GENERAL_ERROR;
}
long fileLen = ftell(fileOperator);
if (fileLen < 0 || fileLen > UINT32_MAX) {
LOG_ERROR("tell file fail");
LOG_ERROR("tell file failed");
(void)fclose(fileOperator);
return RESULT_GENERAL_ERROR;
}
@@ -112,7 +112,7 @@ static int32_t DeleteFile(const char *fileName)
}
int ret = remove(fileName);
if (ret != 0) {
LOG_ERROR("delete file fail");
LOG_ERROR("delete file failed");
return RESULT_GENERAL_ERROR;
}
return RESULT_SUCCESS;
+6 -6
View File
@@ -80,13 +80,13 @@ ResultCode AddCoAuthSchedule(CoAuthSchedule *coAuthSchedule)
return RESULT_NO_MEMORY;
}
if (memcpy_s(schedule, sizeof(CoAuthSchedule), coAuthSchedule, sizeof(CoAuthSchedule)) != EOK) {
LOG_ERROR("copy fail");
LOG_ERROR("copy failed");
Free(schedule);
return RESULT_BAD_COPY;
}
ResultCode result = g_scheduleList->insert(g_scheduleList, schedule);
if (result != RESULT_SUCCESS) {
LOG_ERROR("insert fail");
LOG_ERROR("insert failed");
Free(schedule);
return result;
}
@@ -125,7 +125,7 @@ ResultCode GetCoAuthSchedule(CoAuthSchedule *coAuthSchedule)
}
LinkedListIterator *iterator = g_scheduleList->createIterator(g_scheduleList);
if (iterator == NULL) {
LOG_ERROR("create iterator fail");
LOG_ERROR("create iterator failed");
return RESULT_NO_MEMORY;
}
int32_t result = RESULT_BAD_MATCH;
@@ -135,7 +135,7 @@ ResultCode GetCoAuthSchedule(CoAuthSchedule *coAuthSchedule)
continue;
}
if (memcpy_s(coAuthSchedule, sizeof(CoAuthSchedule), schedule, sizeof(CoAuthSchedule)) != EOK) {
LOG_ERROR("memcpy fail");
LOG_ERROR("memcpy failed");
result = RESULT_BAD_COPY;
break;
}
@@ -230,7 +230,7 @@ CoAuthSchedule *GenerateAuthSchedule(uint64_t contextId, uint32_t authType, uint
return NULL;
}
if (memset_s(coAuthSchedule, sizeof(CoAuthSchedule), 0, sizeof(CoAuthSchedule)) != EOK) {
LOG_ERROR("reset coAuthSchedule fail");
LOG_ERROR("reset coAuthSchedule failed");
goto EXIT;
}
ResultCode ret = GenerateValidScheduleId(&coAuthSchedule->scheduleId);
@@ -265,7 +265,7 @@ CoAuthSchedule *GenerateIdmSchedule(uint64_t challenge, uint32_t authType, uint6
return NULL;
}
if (memset_s(coAuthSchedule, sizeof(CoAuthSchedule), 0, sizeof(CoAuthSchedule)) != EOK) {
LOG_ERROR("reset coAuthSchedule fail");
LOG_ERROR("reset coAuthSchedule failed");
goto EXIT;
}
ResultCode ret = GenerateValidScheduleId(&coAuthSchedule->scheduleId);
+2 -2
View File
@@ -152,12 +152,12 @@ bool IsExecutorExistFunc(uint32_t authType)
LinkedList *executorsQuery = NULL;
int32_t ret = QueryExecutor(authType, &executorsQuery);
if (ret != RESULT_SUCCESS || executorsQuery == NULL) {
LOG_ERROR("query executor fail");
LOG_ERROR("query executor failed");
return false;
}
if (executorsQuery->getSize(executorsQuery) == 0) {
LOG_ERROR("get size fail");
LOG_ERROR("get size failed");
DestroyLinkedList(executorsQuery);
return false;
}
+5 -12
View File
@@ -20,17 +20,10 @@
#include "adaptor_algorithm.h"
#include "adaptor_log.h"
#include "adaptor_time.h"
#include "token_key.h"
#define TOKEN_VALIDITY_PERIOD (10 * 60 * 1000)
// Key used for coauth signature.
static uint8_t g_coAuthTokenKey[SHA256_KEY_LEN] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
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 bool IsTimeValid(const ScheduleTokenHal *coAuthToken)
{
uint64_t currentTime = GetSystemTime();
@@ -46,13 +39,13 @@ static bool IsTimeValid(const ScheduleTokenHal *coAuthToken)
ResultCode CoAuthTokenSign(ScheduleTokenHal *coAuthToken)
{
if (coAuthToken == NULL) {
LOG_ERROR("coAuthToken is NULL");
LOG_ERROR("coAuthToken is null");
return RESULT_BAD_PARAM;
}
coAuthToken->version = TOKEN_VERSION;
ResultCode ret = RESULT_SUCCESS;
Buffer *data = CreateBufferByData((uint8_t *)coAuthToken, COAUTH_TOKEN_DATA_LEN);
Buffer *key = CreateBufferByData(g_coAuthTokenKey, SHA256_KEY_LEN);
Buffer *key = GetTokenKey();
Buffer *sign = NULL;
if (data == NULL || key == NULL) {
LOG_ERROR("lack of member");
@@ -81,7 +74,7 @@ EXIT:
ResultCode CoAuthTokenVerify(const ScheduleTokenHal *coAuthToken)
{
if (coAuthToken == NULL) {
LOG_ERROR("coAuthToken is NULL");
LOG_ERROR("coAuthToken is null");
return RESULT_BAD_PARAM;
}
@@ -91,7 +84,7 @@ ResultCode CoAuthTokenVerify(const ScheduleTokenHal *coAuthToken)
}
ResultCode ret = RESULT_SUCCESS;
Buffer *data = CreateBufferByData((uint8_t *)coAuthToken, COAUTH_TOKEN_DATA_LEN);
Buffer *key = CreateBufferByData(g_coAuthTokenKey, SHA256_KEY_LEN);
Buffer *key = GetTokenKey();
Buffer *sign = CreateBufferByData(coAuthToken->sign, SHA256_SIGN_LEN);
Buffer *rightSign = NULL;
if (data == NULL || key == NULL || sign == NULL) {
@@ -142,17 +142,17 @@ ResultCode RegisterExecutorToPool(ExecutorInfoHal *executorInfo)
}
ResultCode result = GenerateValidExecutorId(&executorInfo->executorId);
if (result != RESULT_SUCCESS) {
LOG_ERROR("get executorId fail");
LOG_ERROR("get executorId failed");
return result;
}
ExecutorInfoHal *executorCopy = CopyExecutorInfo(executorInfo);
if (executorCopy == NULL) {
LOG_ERROR("copy executor fail");
LOG_ERROR("copy executor failed");
return RESULT_NO_MEMORY;
}
result = g_poolList->insert(g_poolList, (void *)executorCopy);
if (result != RESULT_SUCCESS) {
LOG_ERROR("insert fail");
LOG_ERROR("insert failed");
DestroyExecutorInfo(executorCopy);
return result;
}
@@ -180,7 +180,7 @@ ExecutorInfoHal *CopyExecutorInfo(ExecutorInfoHal *src)
return NULL;
}
if (memcpy_s(dest, sizeof(ExecutorInfoHal), src, sizeof(ExecutorInfoHal)) != EOK) {
LOG_ERROR("copy executor info fail");
LOG_ERROR("copy executor info failed");
Free(dest);
return NULL;
}
@@ -199,12 +199,12 @@ ResultCode QueryExecutor(uint32_t authType, LinkedList **result)
}
*result = CreateLinkedList(DestroyExecutorInfo);
if (*result == NULL) {
LOG_ERROR("create result list fail");
LOG_ERROR("create result list failed");
return RESULT_NO_MEMORY;
}
LinkedListIterator *iterator = g_poolList->createIterator(g_poolList);
if (iterator == NULL) {
LOG_ERROR("create iterator fail");
LOG_ERROR("create iterator failed");
DestroyLinkedList(*result);
return RESULT_NO_MEMORY;
}
@@ -220,11 +220,11 @@ ResultCode QueryExecutor(uint32_t authType, LinkedList **result)
}
ExecutorInfoHal *copy = CopyExecutorInfo(executorInfo);
if (copy == NULL) {
LOG_ERROR("copy executor info fail");
LOG_ERROR("copy executor info failed");
continue;
}
if ((*result)->insert(*result, copy) != RESULT_SUCCESS) {
LOG_ERROR("insert executor info fail");
LOG_ERROR("insert executor info failed");
DestroyExecutorInfo(copy);
continue;
}
-1
View File
@@ -28,7 +28,6 @@ typedef struct {
bool IsBufferValid(const Buffer *buffer);
Buffer *CreateBuffer(const uint32_t size);
ResultCode InitBuffer(Buffer *buffer, const uint8_t *buf, const uint32_t bufSize);
void DestoryBuffer(Buffer *buffer);
Buffer *CopyBuffer(const Buffer *buffer);
bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2);
-3
View File
@@ -60,10 +60,7 @@ uint64_t Ntohll(uint64_t data);
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);
int32_t AddTlvNode(TlvListNode *list, const TlvObject *object);
#endif // TLV_BASE_H
-12
View File
@@ -24,9 +24,6 @@
#define MAX_BUFFER_SIZE 512000
#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);
@@ -38,16 +35,7 @@ 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
+13 -29
View File
@@ -45,19 +45,19 @@ bool CheckBufferWithSize(const Buffer *buffer, const uint32_t size)
Buffer *CreateBuffer(const uint32_t size)
{
if ((size == 0) || (size > MAX_BUFFER_SIZE)) {
LOG_ERROR("Bad param size:%u", size);
LOG_ERROR("invalid param, size: %u", size);
return NULL;
}
Buffer *buffer = (Buffer *)Malloc(sizeof(Buffer));
if (buffer == NULL) {
LOG_ERROR("Get buffer struct error");
LOG_ERROR("malloc buffer struct failed");
return NULL;
}
buffer->buf = (uint8_t *)Malloc(size);
if (buffer->buf == NULL) {
LOG_ERROR("Get buffer error");
LOG_ERROR("malloc buffer data failed");
Free(buffer);
return NULL;
}
@@ -76,25 +76,25 @@ Buffer *CreateBuffer(const uint32_t size)
Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize)
{
if ((data == NULL) || (dataSize == 0) || (dataSize > MAX_BUFFER_SIZE)) {
LOG_ERROR("Bad param size:%u", dataSize);
LOG_ERROR("invalid param, dataSize: %u", dataSize);
return NULL;
}
Buffer *buffer = (Buffer *)Malloc(sizeof(Buffer));
if (buffer == NULL) {
LOG_ERROR("Get buffer struct error");
LOG_ERROR("malloc buffer struct failed");
return NULL;
}
buffer->buf = (uint8_t *)Malloc(dataSize);
if (buffer->buf == NULL) {
LOG_ERROR("Get buffer error");
LOG_ERROR("malloc buffer data failed");
Free(buffer);
return NULL;
}
if (memcpy_s(buffer->buf, dataSize, data, dataSize) != EOK) {
LOG_ERROR("Cpy buffer error");
LOG_ERROR("copy buffer failed");
DestoryBuffer(buffer);
return NULL;
}
@@ -104,28 +104,12 @@ Buffer *CreateBufferByData(const uint8_t *data, const uint32_t dataSize)
return buffer;
}
ResultCode InitBuffer(Buffer *buffer, const uint8_t *buf, const uint32_t bufSize)
{
if (!IsBufferValid(buffer) || (buf == NULL) || (bufSize == 0)) {
LOG_ERROR("Bad param");
return RESULT_BAD_PARAM;
}
if (memcpy_s(buffer->buf, buffer->maxSize, buf, bufSize) != EOK) {
LOG_ERROR("Copy buffer fail");
return RESULT_BAD_COPY;
}
buffer->contentSize = bufSize;
return RESULT_SUCCESS;
}
void DestoryBuffer(Buffer *buffer)
{
if (buffer != NULL) {
if (buffer->buf != NULL) {
if (memset_s(buffer->buf, buffer->maxSize, 0, buffer->maxSize) != EOK) {
LOG_ERROR("DestoryBuffer memset fail!");
LOG_ERROR("meset failed");
}
Free(buffer->buf);
buffer->buf = NULL;
@@ -139,18 +123,18 @@ void DestoryBuffer(Buffer *buffer)
Buffer *CopyBuffer(const Buffer *buffer)
{
if (!IsBufferValid(buffer)) {
LOG_ERROR("Invalid buffer");
LOG_ERROR("invalid buffer");
return NULL;
}
Buffer *copyBuffer = CreateBuffer(buffer->maxSize);
if (copyBuffer == NULL) {
LOG_ERROR("Invalid buffer");
LOG_ERROR("create buffer failed");
return NULL;
}
if (memcpy_s(copyBuffer->buf, copyBuffer->maxSize, buffer->buf, buffer->contentSize) != EOK) {
LOG_ERROR("Copy buffer fail");
LOG_ERROR("copy buffer failed");
goto FAIL;
}
copyBuffer->contentSize = buffer->contentSize;
@@ -178,11 +162,11 @@ bool CompareBuffer(const Buffer *buffer1, const Buffer *buffer2)
ResultCode GetBufferData(const Buffer *buffer, uint8_t *data, uint32_t *dataSize)
{
if (!IsBufferValid(buffer) || (data == NULL) || (dataSize == NULL)) {
LOG_ERROR("Bad param");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
if (memcpy_s(data, *dataSize, buffer->buf, buffer->contentSize) != EOK) {
LOG_ERROR("Copy buffer fail");
LOG_ERROR("copy buffer failed");
return RESULT_BAD_COPY;
}
*dataSize = buffer->contentSize;
+11 -11
View File
@@ -23,7 +23,7 @@
static ResultCode InsertNode(LinkedList *list, void *data)
{
if (list == NULL) {
LOG_ERROR("get null list");
LOG_ERROR("list is null");
return RESULT_BAD_PARAM;
}
if (list->size == UINT32_MAX) {
@@ -45,11 +45,11 @@ static ResultCode InsertNode(LinkedList *list, void *data)
static ResultCode RemoveNode(LinkedList *list, void *condition, MatchFunc matchFunc, bool destroyNode)
{
if (list == NULL) {
LOG_ERROR("get null list");
LOG_ERROR("list is null");
return RESULT_BAD_PARAM;
}
if (matchFunc == NULL) {
LOG_ERROR("get null match func");
LOG_ERROR("matchFunc is null");
return RESULT_BAD_PARAM;
}
LinkedListNode *pre = NULL;
@@ -83,7 +83,7 @@ static ResultCode RemoveNode(LinkedList *list, void *condition, MatchFunc matchF
static uint32_t GetSize(LinkedList *list)
{
if (list == NULL) {
LOG_ERROR("get null list");
LOG_ERROR("list is null");
return 0;
}
return list->size;
@@ -92,7 +92,7 @@ static uint32_t GetSize(LinkedList *list)
static bool IteratorHasNext(LinkedListIterator *iterator)
{
if (iterator == NULL) {
LOG_ERROR("get null iterator");
LOG_ERROR("iterator is null");
return false;
}
return iterator->current != NULL;
@@ -112,12 +112,12 @@ static void *IteratorNext(LinkedListIterator *iterator)
static LinkedListIterator *CreateIterator(struct LinkedList *list)
{
if (list == NULL) {
LOG_ERROR("get null list");
LOG_ERROR("list is null");
return NULL;
}
LinkedListIterator *iterator = (LinkedListIterator *)Malloc(sizeof(LinkedListIterator));
if (iterator == NULL) {
LOG_ERROR("bad memory");
LOG_ERROR("malloc failed");
return NULL;
}
iterator->current = list->head;
@@ -129,7 +129,7 @@ static LinkedListIterator *CreateIterator(struct LinkedList *list)
static void DestroyIterator(LinkedListIterator *iterator)
{
if (iterator == NULL) {
LOG_ERROR("get null iterator");
LOG_ERROR("iterator is null");
return;
}
Free(iterator);
@@ -138,7 +138,7 @@ static void DestroyIterator(LinkedListIterator *iterator)
LinkedList *CreateLinkedList(DestroyDataFunc destroyDataFunc)
{
if (destroyDataFunc == NULL) {
LOG_ERROR("get null func");
LOG_ERROR("destroyDataFunc is null");
return NULL;
}
LinkedList *list = Malloc(sizeof(LinkedList));
@@ -160,7 +160,7 @@ LinkedList *CreateLinkedList(DestroyDataFunc destroyDataFunc)
static void DestroyLinkedListNode(const LinkedList *list, LinkedListNode *node)
{
if (node == NULL) {
LOG_ERROR("get null node");
LOG_ERROR("node is null");
return;
}
if ((list != NULL) && (list->destroyDataFunc != NULL)) {
@@ -172,7 +172,7 @@ static void DestroyLinkedListNode(const LinkedList *list, LinkedListNode *node)
void DestroyLinkedList(LinkedList *list)
{
if (list == NULL) {
LOG_ERROR("get null list");
LOG_ERROR("list is null");
return;
}
while (list->head != NULL) {
-61
View File
@@ -80,67 +80,6 @@ TlvType *CreateTlvType(int32_t type, uint32_t length, const void *value)
return tlv;
}
TlvObject *CreateTlvObject(int32_t type, uint32_t length, const void *value)
{
TlvObject *object = (TlvObject *)Malloc(sizeof(TlvListNode));
if (object == NULL) {
return NULL;
}
TlvType *tlv = CreateTlvType(type, length, value);
if (tlv == NULL) {
Free(object);
return NULL;
}
object->value = tlv;
return object;
}
static TlvType *CreateEmptyTlvType(int32_t type)
{
TlvType *tlv = (TlvType *)Malloc(sizeof(TlvType));
if (tlv == NULL) {
return NULL;
}
tlv->type = type;
tlv->length = 0;
tlv->value = NULL;
return tlv;
}
TlvObject *CreateEmptyTlvObject(int32_t type)
{
TlvObject *object = (TlvObject *)Malloc(sizeof(TlvListNode));
if (object == NULL) {
return NULL;
}
TlvType *tlv = CreateEmptyTlvType(type);
if (tlv == NULL) {
Free(object);
return NULL;
}
object->value = tlv;
return object;
}
void DestroyTlvObject(TlvObject *object)
{
if (object == NULL) {
return;
}
TlvType *tlv = object->value;
if (tlv == NULL) {
Free(object);
return;
}
if (tlv->value != NULL) {
Free(tlv->value);
tlv->value = NULL;
}
Free(tlv);
Free(object);
}
int32_t DestroyTlvList(TlvListNode *head)
{
if (head == NULL) {
-136
View File
@@ -67,40 +67,6 @@ static int32_t PutTlvObject(TlvListNode *head, int32_t type, uint32_t length, co
return ret;
}
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;
}
uint32_t offset = 0;
TlvListNode *node = head->next;
while (node != NULL) {
TlvType *tlv = node->data.value;
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(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(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;
}
offset += tlv->length;
node = node->next;
}
*contentSize = offset;
return OPERA_SUCC;
}
int32_t ParseGetHeadTag(const TlvListNode *node, int32_t *tag)
{
if (node == NULL || tag == NULL) {
@@ -144,49 +110,6 @@ int32_t ParseTlvWrapper(const uint8_t *buffer, uint32_t bufferSize, TlvListNode
return OPERA_SUCC;
}
int32_t TlvAppendByte(TlvListNode *head, int32_t type, const uint8_t *value, uint32_t length)
{
if (head == NULL || value == NULL) {
return PARAM_ERR;
}
return PutTlvObject(head, type, length, value);
}
int32_t TlvAppendShort(TlvListNode *head, int32_t type, short value)
{
if (head == NULL) {
return PARAM_ERR;
}
short tempValue = Ntohs(value);
return PutTlvObject(head, type, sizeof(short), &tempValue);
}
int32_t TlvAppendInt(TlvListNode *head, int32_t type, uint32_t value)
{
if (head == NULL) {
return PARAM_ERR;
}
uint32_t tempValue = Ntohl(value);
return PutTlvObject(head, type, sizeof(int32_t), &tempValue);
}
int32_t TlvAppendLong(TlvListNode *head, int32_t type, uint64_t value)
{
if (head == NULL) {
return PARAM_ERR;
}
uint64_t tempValue = Ntohll(value);
return PutTlvObject(head, type, sizeof(int64_t), &tempValue);
}
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;
}
return PutTlvObject(head, type, length, buffer);
}
static uint8_t *GetTlvValue(TlvListNode *node, int32_t msgType, uint32_t *len)
{
if ((node == NULL) || (len == NULL)) {
@@ -272,22 +195,6 @@ int32_t ParseInt32Para(TlvListNode *node, int32_t msgType, int32_t *retVal)
return OPERA_SUCC;
}
int32_t ParseShortPara(TlvListNode *node, int32_t msgType, short *retVal)
{
if ((node == NULL) || (retVal == NULL)) {
LOG_ERROR("ParseShortPara parameter check failed");
return PARAM_ERR;
}
uint32_t len = 0;
uint8_t *val = GetTlvValue(node, msgType, &len);
if ((val == NULL) || (len != sizeof(short))) {
LOG_ERROR("ParseInt32Para GetTlvValue failed");
return OPERA_FAIL;
}
*retVal = Ntohs(*(short *)val);
return OPERA_SUCC;
}
Buffer *ParseBuffPara(TlvListNode *node, int32_t msgType)
{
if (node == NULL) {
@@ -324,7 +231,6 @@ int32_t ParseUint8Para(TlvListNode *node, int32_t msgType, uint8_t *retVal)
return OPERA_SUCC;
}
int32_t GetUint64Para(TlvListNode *head, int32_t msgType, uint64_t *retVal)
{
if ((head == NULL) || (retVal == NULL)) {
@@ -346,27 +252,6 @@ int32_t GetUint64Para(TlvListNode *head, int32_t msgType, uint64_t *retVal)
return PARAM_ERR;
}
int32_t GetInt64Para(TlvListNode *head, int32_t msgType, int64_t *retVal)
{
if ((head == NULL) || (retVal == NULL)) {
LOG_ERROR("GetInt64Para parameter check failed");
return PARAM_ERR;
}
TlvListNode *node = head;
while (node != NULL) {
int32_t nodeType;
int32_t ret = ParseGetHeadTag(node, &nodeType);
if (ret != OPERA_SUCC) {
return ret;
}
if (nodeType == msgType) {
return ParseInt64Para(node, msgType, retVal);
}
node = node->next;
}
return PARAM_ERR;
}
int32_t GetUint32Para(TlvListNode *head, int32_t msgType, uint32_t *retVal)
{
if ((head == NULL) || (retVal == NULL)) {
@@ -428,25 +313,4 @@ Buffer *GetBuffPara(TlvListNode *head, int32_t msgType)
node = node->next;
}
return NULL;
}
int32_t GetUint8Para(TlvListNode *head, int32_t msgType, uint8_t *retVal)
{
if ((head == NULL) || (retVal == NULL)) {
LOG_ERROR("GetUint8Para parameter check failed");
return PARAM_ERR;
}
TlvListNode *node = head;
while (node != NULL) {
int32_t nodeType;
int32_t ret = ParseGetHeadTag(node, &nodeType);
if (ret != OPERA_SUCC) {
return ret;
}
if (nodeType == msgType) {
return ParseUint8Para(node, msgType, retVal);
}
node = node->next;
}
return PARAM_ERR;
}
+14 -12
View File
@@ -67,7 +67,7 @@ void DestroyUserInfoList(void)
static bool MatchUserInfo(void *data, void *condition)
{
if (data == NULL || condition == NULL) {
LOG_ERROR("Please check invalid node");
LOG_ERROR("please check invalid node");
return false;
}
UserInfo *userInfo = (UserInfo *)data;
@@ -103,7 +103,7 @@ ResultCode GetSecureUid(int32_t userId, uint64_t *secUid)
}
UserInfo *user = QueryUserInfo(userId);
if (user == NULL) {
LOG_ERROR("Can't find this user");
LOG_ERROR("can't find this user");
return RESULT_NOT_FOUND;
}
*secUid = user->secUid;
@@ -230,18 +230,19 @@ static ResultCode GetAllEnrolledInfoFromUser(UserInfo *userInfo, EnrolledInfoHal
LOG_ERROR("enrolledInfos malloc failed");
return RESULT_NO_MEMORY;
}
(void)memset_s(*enrolledInfos, sizeof(EnrolledInfoHal) * size, 0, sizeof(EnrolledInfoHal) * size);
LinkedListNode *temp = enrolledInfoList->head;
ResultCode result = RESULT_SUCCESS;
for (*num = 0; *num < size; (*num)++) {
if (temp == NULL) {
LOG_ERROR("Temp node is NULL, something wrong");
LOG_ERROR("temp node is null, something wrong");
result = RESULT_BAD_PARAM;
goto EXIT;
}
EnrolledInfoHal *tempInfo = (EnrolledInfoHal *)temp->data;
if (memcpy_s(*enrolledInfos + *num, sizeof(EnrolledInfoHal) * (size - *num),
tempInfo, sizeof(EnrolledInfoHal)) != EOK) {
LOG_ERROR("Failed to copy the %d information", *num);
LOG_ERROR("copy the %u information failed", *num);
result = RESULT_NO_MEMORY;
goto EXIT;
}
@@ -266,18 +267,19 @@ static ResultCode GetAllCredentialInfoFromUser(UserInfo *userInfo, CredentialInf
LOG_ERROR("credentialInfos malloc failed");
return RESULT_NO_MEMORY;
}
(void)memset_s(*credentialInfos, sizeof(CredentialInfoHal) * size, 0, sizeof(CredentialInfoHal) * size);
LinkedListNode *temp = credentialInfoList->head;
ResultCode result = RESULT_SUCCESS;
for (*num = 0; *num < size; (*num)++) {
if (temp == NULL) {
LOG_ERROR("Temp node is NULL, something wrong");
LOG_ERROR("temp node is NULL, something wrong");
result = RESULT_BAD_PARAM;
goto EXIT;
}
CredentialInfoHal *tempInfo = (CredentialInfoHal *)temp->data;
if (memcpy_s((*credentialInfos) + *num, sizeof(CredentialInfoHal) * (size - *num),
tempInfo, sizeof(CredentialInfoHal)) != EOK) {
LOG_ERROR("Failed to copy the %d information", *num);
LOG_ERROR("copy the %u information failed", *num);
result = RESULT_NO_MEMORY;
goto EXIT;
}
@@ -389,7 +391,7 @@ static ResultCode GenerateDeduplicateUint64(LinkedList *collection, uint64_t *de
}
}
LOG_ERROR("generate random fail");
LOG_ERROR("generate random failed");
return RESULT_GENERAL_ERROR;
}
@@ -594,7 +596,7 @@ ResultCode DeleteCredentialInfo(int32_t userId, uint64_t credentialId, Credentia
LinkedList *credentialList = user->credentialInfoList;
CredentialInfoHal *credentialQuery = QueryCredentialById(credentialId, credentialList);
if (credentialQuery == NULL) {
LOG_ERROR("don't have this credential");
LOG_ERROR("credentialQuery is null");
return RESULT_UNKNOWN;
}
if (memcpy_s(credentialInfo, sizeof(CredentialInfoHal), credentialQuery, sizeof(CredentialInfoHal)) != EOK) {
@@ -665,21 +667,21 @@ ResultCode QueryCredentialInfo(int32_t userId, uint32_t authType, CredentialInfo
{
UserInfo *user = QueryUserInfo(userId);
if (user == NULL) {
LOG_ERROR("Can't find this user, userId is %{public}d", userId);
LOG_ERROR("can't find this user, userId is %{public}d", userId);
return RESULT_NOT_FOUND;
}
LinkedList *credentialList = user->credentialInfoList;
if (credentialList == NULL) {
LOG_ERROR("CredentialList is null");
LOG_ERROR("credentialList is null");
return RESULT_NOT_FOUND;
}
CredentialInfoHal *credentialQuery = QueryCredentialByAuthType(authType, credentialList);
if (credentialQuery == NULL) {
LOG_ERROR("Don't have this credential");
LOG_ERROR("credentialQuery is null");
return RESULT_NOT_FOUND;
}
if (memcpy_s(credentialInfo, sizeof(CredentialInfoHal), credentialQuery, sizeof(CredentialInfoHal)) != EOK) {
LOG_ERROR("credentialInfo copy failed");
LOG_ERROR("copy credentialInfo failed");
return RESULT_BAD_COPY;
}
return RESULT_SUCCESS;
+27 -25
View File
@@ -42,7 +42,7 @@ static uint8_t *GetStreamAddress(const Buffer *object)
static ResultCode CapacityExpansion(Buffer *object, uint32_t targetCapacity)
{
if (!IsBufferValid(object) || object->maxSize > MAX_BUFFER_LEN / DEFAULT_EXPANSION_RATIO) {
LOG_ERROR("Params are invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
uint32_t targetSize = object->maxSize;
@@ -50,16 +50,16 @@ static ResultCode CapacityExpansion(Buffer *object, uint32_t targetCapacity)
targetSize = targetSize * DEFAULT_EXPANSION_RATIO;
}
if (targetSize < targetCapacity) {
LOG_ERROR("Target capacity can not reach");
LOG_ERROR("target capacity can not reach");
return RESULT_BAD_PARAM;
}
uint8_t *buf = Malloc(targetSize);
if (buf == NULL) {
LOG_ERROR("Malloc failed");
LOG_ERROR("malloc failed");
return RESULT_NO_MEMORY;
}
if (memcpy_s(buf, targetSize, object->buf, object->contentSize) != EOK) {
LOG_ERROR("Copy failed");
LOG_ERROR("copy failed");
Free(buf);
return RESULT_NO_MEMORY;
}
@@ -72,7 +72,7 @@ static ResultCode CapacityExpansion(Buffer *object, uint32_t targetCapacity)
static ResultCode StreamWrite(Buffer *parcel, void *from, uint32_t size)
{
if (!IsBufferValid(parcel) || from == NULL) {
LOG_ERROR("Param is invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
if (GetRemainSpace(parcel) < size) {
@@ -83,7 +83,7 @@ static ResultCode StreamWrite(Buffer *parcel, void *from, uint32_t size)
}
}
if (memcpy_s(GetStreamAddress(parcel), GetRemainSpace(parcel), from, size) != EOK) {
LOG_ERROR("Copy failed");
LOG_ERROR("copy failed");
return RESULT_NO_MEMORY;
}
parcel->contentSize += size;
@@ -93,7 +93,7 @@ static ResultCode StreamWrite(Buffer *parcel, void *from, uint32_t size)
static ResultCode StreamWriteEnrolledInfo(Buffer *parcel, LinkedList *enrolledList)
{
if (!IsBufferValid(parcel) || enrolledList == NULL) {
LOG_ERROR("Param is invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
uint32_t size = enrolledList->getSize(enrolledList);
@@ -105,11 +105,11 @@ static ResultCode StreamWriteEnrolledInfo(Buffer *parcel, LinkedList *enrolledLi
LinkedListNode *temp = enrolledList->head;
for (uint32_t i = 0; i < size; i++) {
if (temp == NULL) {
LOG_ERROR("ListSize is invalid");
LOG_ERROR("listSize is invalid");
return RESULT_BAD_PARAM;
}
if (StreamWrite(parcel, temp->data, sizeof(EnrolledInfoHal)) != RESULT_SUCCESS) {
LOG_ERROR("EnrolledInfo streamWrite failed");
LOG_ERROR("enrolledInfo streamWrite failed");
return RESULT_GENERAL_ERROR;
}
temp = temp->next;
@@ -120,7 +120,7 @@ static ResultCode StreamWriteEnrolledInfo(Buffer *parcel, LinkedList *enrolledLi
static ResultCode StreamWriteCredentialList(Buffer *parcel, LinkedList *credentialList)
{
if (!IsBufferValid(parcel) || credentialList == NULL) {
LOG_ERROR("Param is invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
uint32_t size = credentialList->getSize(credentialList);
@@ -132,11 +132,11 @@ static ResultCode StreamWriteCredentialList(Buffer *parcel, LinkedList *credenti
LinkedListNode *temp = credentialList->head;
for (uint32_t i = 0; i < size; i++) {
if (temp == NULL) {
LOG_ERROR("ListSize is invalid");
LOG_ERROR("listSize is invalid");
return RESULT_BAD_PARAM;
}
if (StreamWrite(parcel, temp->data, sizeof(CredentialInfoHal)) != RESULT_SUCCESS) {
LOG_ERROR("CredentialInfo streamWrite failed");
LOG_ERROR("credentialInfo streamWrite failed");
return RESULT_GENERAL_ERROR;
}
temp = temp->next;
@@ -147,7 +147,7 @@ static ResultCode StreamWriteCredentialList(Buffer *parcel, LinkedList *credenti
static ResultCode StreamWriteUserInfo(Buffer *parcel, UserInfo *userInfo)
{
if (!IsBufferValid(parcel) || userInfo == NULL) {
LOG_ERROR("Param is invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
ResultCode result;
@@ -176,7 +176,7 @@ static ResultCode StreamWriteUserInfo(Buffer *parcel, UserInfo *userInfo)
ResultCode UpdateFileInfo(LinkedList *userInfoList)
{
LOG_INFO("update begin");
LOG_INFO("start");
if (userInfoList == NULL) {
LOG_ERROR("userInfo list is null");
return RESULT_BAD_PARAM;
@@ -216,13 +216,15 @@ ResultCode UpdateFileInfo(LinkedList *userInfoList)
FileOperator *fileOperator = GetFileOperator(DEFAULT_FILE_OPERATOR);
if (!IsFileOperatorValid(fileOperator)) {
LOG_ERROR("Invalid file operation");
LOG_ERROR("invalid file operation");
ret = RESULT_BAD_WRITE;
goto EXIT;
}
// This is for example only. Should be implemented in trusted environment.
ret = fileOperator->writeFile(IDM_USER_INFO, parcel->buf, parcel->contentSize);
if (ret != RESULT_SUCCESS) {
LOG_ERROR("file write failed, %{public}u", parcel->contentSize);
LOG_ERROR("write file failed, %{public}u", parcel->contentSize);
}
EXIT:
@@ -233,11 +235,11 @@ EXIT:
static ResultCode StreamRead(Buffer *parcel, uint32_t *index, void *to, uint32_t size)
{
if (parcel->contentSize <= *index || parcel->contentSize - *index < size) {
LOG_ERROR("The buffer length is insufficient.");
LOG_ERROR("the buffer length is insufficient");
return RESULT_BAD_PARAM;
}
if (memcpy_s(to, size, parcel->buf + *index, size) != EOK) {
LOG_ERROR("Copy failed");
LOG_ERROR("copy failed");
return RESULT_NO_MEMORY;
}
*index += size;
@@ -247,7 +249,7 @@ static ResultCode StreamRead(Buffer *parcel, uint32_t *index, void *to, uint32_t
static ResultCode StreamReadCredentialList(Buffer *parcel, uint32_t *index, LinkedList *credentialList)
{
if (!IsBufferValid(parcel) || credentialList == NULL) {
LOG_ERROR("Param is invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
uint32_t credentialNum;
@@ -280,7 +282,7 @@ static ResultCode StreamReadCredentialList(Buffer *parcel, uint32_t *index, Link
static ResultCode StreamReadEnrolledList(Buffer *parcel, uint32_t *index, LinkedList *enrolledList)
{
if (!IsBufferValid(parcel) || enrolledList == NULL) {
LOG_ERROR("Param is invalid");
LOG_ERROR("invalid params");
return RESULT_BAD_PARAM;
}
uint32_t enrolledNum;
@@ -290,7 +292,7 @@ static ResultCode StreamReadEnrolledList(Buffer *parcel, uint32_t *index, Linked
return RESULT_BAD_READ;
}
if (enrolledNum > MAX_CREDENTIAL) {
LOG_ERROR("Bad enrolled num");
LOG_ERROR("bad enrolled num");
return RESULT_BAD_READ;
}
for (uint32_t i = 0; i < enrolledNum; i++) {
@@ -339,7 +341,7 @@ static Buffer *ReadFileInfo()
{
FileOperator *fileOperator = GetFileOperator(DEFAULT_FILE_OPERATOR);
if (!IsFileOperatorValid(fileOperator)) {
LOG_ERROR("Invalid file operation");
LOG_ERROR("invalid file operation");
return NULL;
}
uint32_t fileSize;
@@ -403,10 +405,10 @@ static bool StreamReadFileInfo(Buffer *parcel, LinkedList *userInfoList)
LinkedList *LoadFileInfo(void)
{
LOG_INFO("begin");
LOG_INFO("start");
FileOperator *fileOperator = GetFileOperator(DEFAULT_FILE_OPERATOR);
if (!IsFileOperatorValid(fileOperator)) {
LOG_ERROR("Invalid file operation");
LOG_ERROR("invalid file operation");
return NULL;
}
if (!fileOperator->isFileExist(IDM_USER_INFO)) {
@@ -421,7 +423,7 @@ LinkedList *LoadFileInfo(void)
LinkedList *userInfoList = CreateLinkedList(DestroyUserInfoNode);
if (userInfoList == NULL) {
LOG_ERROR("List create failed");
LOG_ERROR("list create failed");
DestoryBuffer(parcel);
return NULL;
}
+10 -10
View File
@@ -35,7 +35,7 @@ static ExecutorInfo CopyExecutorInfoOut(const ExecutorInfoHal &executorInfoHal)
executorInfo.esl = executorInfoHal.esl;
executorInfo.executorType = executorInfoHal.executorType;
if (memcpy_s(executorInfo.publicKey, PUBLIC_KEY_LEN, executorInfoHal.pubKey, PUBLIC_KEY_LEN) != EOK) {
LOG_ERROR("memcpy fail");
LOG_ERROR("memcpy failed");
}
return executorInfo;
}
@@ -48,14 +48,14 @@ static ExecutorInfoHal CopyExecutorInfoIn(const ExecutorInfo &executorInfo)
executorInfoHal.esl = executorInfo.esl;
executorInfoHal.executorType = executorInfo.executorType;
if (memcpy_s(executorInfoHal.pubKey, PUBLIC_KEY_LEN, executorInfo.publicKey, PUBLIC_KEY_LEN) != EOK) {
LOG_ERROR("memcpy fail");
LOG_ERROR("memcpy failed");
}
return executorInfoHal;
}
static void CopyScheduleInfoOut(ScheduleInfo &scheduleInfo, const ScheduleInfoHal &scheduleInfoHal)
{
LOG_INFO("begin");
LOG_INFO("start");
scheduleInfo.executors.clear();
scheduleInfo.authSubType = scheduleInfoHal.authSubType;
scheduleInfo.templateId = scheduleInfoHal.templateId;
@@ -68,7 +68,7 @@ static void CopyScheduleInfoOut(ScheduleInfo &scheduleInfo, const ScheduleInfoHa
int32_t GetScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
ScheduleInfoHal scheduleInfoHal;
int32_t ret = GetScheduleInfo(scheduleId, &scheduleInfoHal);
@@ -84,7 +84,7 @@ int32_t GetScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo)
int32_t DeleteScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
ScheduleInfoHal scheduleInfoHal;
int32_t ret = GetScheduleInfo(scheduleId, &scheduleInfoHal);
@@ -102,14 +102,14 @@ int32_t DeleteScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo)
static Buffer *CreateBufferByVector(std::vector<uint8_t> &executorFinishMsg)
{
LOG_INFO("executorFinishMsg size is %{public}u", executorFinishMsg.size());
LOG_INFO("executorFinishMsg size is %{public}zu", executorFinishMsg.size());
Buffer *data = CreateBufferByData(&executorFinishMsg[0], executorFinishMsg.size());
return data;
}
int32_t GetScheduleToken(std::vector<uint8_t> executorFinishMsg, ScheduleToken &scheduleToken)
{
LOG_INFO("begin");
LOG_INFO("start");
if (executorFinishMsg.empty()) {
LOG_ERROR("executorFinishMsg is empty");
ScheduleInfo scheduleInfo;
@@ -143,7 +143,7 @@ int32_t GetScheduleToken(std::vector<uint8_t> executorFinishMsg, ScheduleToken &
int32_t ExecutorRegister(ExecutorInfo executorInfo, uint64_t &executorId)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
ExecutorInfoHal executorInfoHal = CopyExecutorInfoIn(executorInfo);
int32_t ret = RegisterExecutor(&executorInfoHal, &executorId);
@@ -153,7 +153,7 @@ int32_t ExecutorRegister(ExecutorInfo executorInfo, uint64_t &executorId)
int32_t ExecutorUnRegister(uint64_t executorId)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
int32_t ret = UnRegisterExecutor(executorId);
GlobalUnLock();
@@ -162,7 +162,7 @@ int32_t ExecutorUnRegister(uint64_t executorId)
bool IsExecutorExist(uint32_t authType)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
bool ret = IsExecutorExistFunc(authType);
GlobalUnLock();
+4 -4
View File
@@ -30,7 +30,7 @@ namespace UserIAM {
namespace UserAuth {
int32_t GenerateSolution(AuthSolution param, std::vector<uint64_t> &scheduleIds)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
uint64_t *scheduleIdsGet = nullptr;
uint32_t scheduleIdNum = 0;
@@ -57,7 +57,7 @@ int32_t GenerateSolution(AuthSolution param, std::vector<uint64_t> &scheduleIds)
int32_t RequestAuthResult(uint64_t contextId, std::vector<uint8_t> &scheduleToken, UserAuthToken &authToken,
std::vector<uint64_t> &scheduleIds)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
if (scheduleToken.size() != sizeof(CoAuth::ScheduleToken)) {
LOG_ERROR("param is invalid");
@@ -98,7 +98,7 @@ int32_t RequestAuthResult(uint64_t contextId, std::vector<uint8_t> &scheduleToke
int32_t CancelContext(uint64_t contextId, std::vector<uint64_t> &scheduleIds)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
uint64_t *scheduleIdsGet = nullptr;
uint32_t scheduleIdNum = 0;
@@ -118,7 +118,7 @@ int32_t CancelContext(uint64_t contextId, std::vector<uint64_t> &scheduleIds)
int32_t GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
int32_t ret = SingleAuthTrustLevel(userId, authType, &authTrustLevel);
GlobalUnLock();
+6 -1
View File
@@ -25,6 +25,7 @@ extern "C" {
#include "context_manager.h"
#include "adaptor_log.h"
#include "lock.h"
#include "token_key.h"
}
namespace OHOS {
@@ -36,7 +37,7 @@ static bool g_isInitUserIAM = false;
int32_t Init()
{
GlobalLock();
LOG_INFO("check useriam folder exist or init it.");
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);
}
@@ -57,6 +58,10 @@ int32_t Init()
LOG_ERROR("init user auth failed");
goto FAIL;
}
if (InitTokenKey() != RESULT_SUCCESS) {
LOG_ERROR("init token key failed");
goto FAIL;
}
g_isInitUserIAM = true;
GlobalUnLock();
return RESULT_SUCCESS;
+9 -18
View File
@@ -53,7 +53,7 @@ int32_t CloseSession()
int32_t InitSchedulation(std::vector<uint8_t> authToken, int32_t userId, uint32_t authType, uint64_t authSubType,
uint64_t &scheduleId)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
if (authToken.size() != sizeof(UserAuth::UserAuthToken) && authType != PIN_AUTH) {
LOG_ERROR("authToken len is invalid");
@@ -74,21 +74,12 @@ int32_t InitSchedulation(std::vector<uint8_t> authToken, int32_t userId, uint32_
return ret;
}
int32_t DeleteScheduleId(uint64_t &scheduleId)
{
LOG_INFO("begin");
GlobalLock();
int32_t ret = CancelScheduleIdFunc(&scheduleId);
GlobalUnLock();
return ret;
}
int32_t AddCredential(std::vector<uint8_t> enrollToken, uint64_t &credentialId)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
if (enrollToken.size() != sizeof(CoAuth::ScheduleToken)) {
LOG_ERROR("enrollToken is invalid, size is %{public}u", enrollToken.size());
LOG_ERROR("enrollToken is invalid, size is %{public}zu", enrollToken.size());
GlobalUnLock();
return RESULT_BAD_PARAM;
}
@@ -106,7 +97,7 @@ int32_t AddCredential(std::vector<uint8_t> enrollToken, uint64_t &credentialId)
int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector<uint8_t> authToken,
CredentialInfo &credentialInfo)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
authToken.resize(sizeof(UserAuth::UserAuthToken));
if (authToken.size() != sizeof(UserAuth::UserAuthToken)) {
@@ -140,7 +131,7 @@ int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector<uint
int32_t QueryCredential(int32_t userId, uint32_t authType, std::vector<CredentialInfo> &credentialInfos)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
CredentialInfoHal *credentialInfoHals = nullptr;
uint32_t num = 0;
@@ -169,7 +160,7 @@ int32_t QueryCredential(int32_t userId, uint32_t authType, std::vector<Credentia
int32_t GetSecureUid(int32_t userId, uint64_t &secureUid, std::vector<EnrolledInfo> &enrolledInfos)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
EnrolledInfoHal *enrolledInfoHals = nullptr;
uint32_t num = 0;
@@ -197,7 +188,7 @@ int32_t GetSecureUid(int32_t userId, uint64_t &secureUid, std::vector<EnrolledIn
int32_t DeleteUserEnforce(int32_t userId, std::vector<CredentialInfo> &credentialInfos)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
CredentialInfoHal *credentialInfoHals = nullptr;
uint32_t num = 0;
@@ -227,7 +218,7 @@ int32_t DeleteUserEnforce(int32_t userId, std::vector<CredentialInfo> &credentia
int32_t DeleteUser(int32_t userId, std::vector<uint8_t> authToken, std::vector<CredentialInfo> &credentialInfos)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
authToken.resize(sizeof(UserAuthTokenHal));
if (authToken.size() != sizeof(UserAuthTokenHal)) {
@@ -260,7 +251,7 @@ int32_t DeleteUser(int32_t userId, std::vector<uint8_t> authToken, std::vector<C
int32_t UpdateCredential(std::vector<uint8_t> enrollToken, uint64_t &credentialId, CredentialInfo &deletedCredential)
{
LOG_INFO("begin");
LOG_INFO("start");
GlobalLock();
if (enrollToken.size() != sizeof(CoAuth::ScheduleToken)) {
LOG_ERROR("enrollToken is invalid");
-1
View File
@@ -40,7 +40,6 @@ int32_t OpenSession(int32_t userId, uint64_t &challenge);
int32_t CloseSession();
int32_t InitSchedulation(std::vector<uint8_t> authToken, int32_t userId, uint32_t authType, uint64_t authSubType,
uint64_t &scheduleId);
int32_t DeleteScheduleId(uint64_t &scheduleId);
int32_t AddCredential(std::vector<uint8_t> enrollToken, uint64_t &credentialId);
int32_t DeleteCredential(int32_t userId, uint64_t credentialId, std::vector<uint8_t> authToken,
CredentialInfo &credentialInfo);
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef USER_IAM_TOKEN_KEY
#define USER_IAM_TOKEN_KEY
#include "buffer.h"
#include "defines.h"
Buffer *GetTokenKey(void);
ResultCode InitTokenKey(void);
#endif
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "token_key.h"
#include <stddef.h>
#include "adaptor_algorithm.h"
#include "adaptor_log.h"
#include "buffer.h"
#include "defines.h"
#define SHA256_KEY_LEN 32
// This is for example only. Should be implemented in trusted environment.
static Buffer *g_tokenKey = NULL;
Buffer *GetTokenKey(void)
{
return CopyBuffer(g_tokenKey);
}
ResultCode InitTokenKey(void)
{
if (g_tokenKey != NULL) {
return RESULT_SUCCESS;
}
g_tokenKey = CreateBuffer(SHA256_KEY_LEN);
if (g_tokenKey == NULL) {
LOG_ERROR("g_tokenKey: create buffer failed");
return RESULT_NO_MEMORY;
}
if (SecureRandom(g_tokenKey->buf, g_tokenKey->maxSize) != RESULT_SUCCESS) {
LOG_ERROR("get random failed");
return RESULT_GENERAL_ERROR;
}
g_tokenKey->contentSize = g_tokenKey->maxSize;
return RESULT_SUCCESS;
}
+2 -2
View File
@@ -57,7 +57,7 @@ static void CopyParamToContext(UserAuthContext *context, AuthSolutionHal params)
UserAuthContext *GenerateContext(AuthSolutionHal params)
{
LOG_INFO("begin");
LOG_INFO("start");
if (g_contextList == NULL) {
LOG_ERROR("need init");
return NULL;
@@ -134,7 +134,7 @@ static void DestroyScheduleNode(void *data)
static ResultCode CreateSchedules(UserAuthContext *context)
{
LOG_INFO("begin");
LOG_INFO("start");
context->scheduleList = CreateLinkedList(DestroyScheduleNode);
if (context->scheduleList == NULL) {
LOG_ERROR("schedule list create failed");
+2 -2
View File
@@ -80,7 +80,7 @@ int32_t RequestAuthResultFunc(uint64_t contextId, const Buffer *scheduleToken, U
}
int32_t ret = CoAuthTokenVerify(&scheduleTokenStruct);
if (ret != RESULT_SUCCESS) {
LOG_ERROR("failed to verify the token");
LOG_ERROR("verify token failed");
return RESULT_BAD_SIGN;
}
@@ -120,7 +120,7 @@ int32_t CancelContextFunc(uint64_t contextId, uint64_t **scheduleIdArray, uint32
{
UserAuthContext *authContext = GetContext(contextId);
if (authContext == NULL) {
LOG_ERROR("don't have this context");
LOG_ERROR("get context failed");
return RESULT_NOT_FOUND;
}
int32_t ret = GetScheduleIds(authContext, scheduleIdArray, scheduleNum);
+6 -14
View File
@@ -20,18 +20,10 @@
#include "adaptor_algorithm.h"
#include "adaptor_log.h"
#include "adaptor_time.h"
#include "token_key.h"
#define TOKEN_VALIDITY_PERIOD (10 * 60 * 1000)
#define DEMO_KEY { \
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, \
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;
static bool IsTimeValid(const UserAuthTokenHal *userAuthToken)
{
uint64_t currentTime = GetSystemTime();
@@ -47,13 +39,13 @@ static bool IsTimeValid(const UserAuthTokenHal *userAuthToken)
ResultCode UserAuthTokenSign(UserAuthTokenHal *userAuthToken)
{
if (userAuthToken == NULL) {
LOG_ERROR("userAuthToken is NULL");
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 *key = GetTokenKey();
Buffer *sign = NULL;
if (data == NULL || key == NULL) {
LOG_ERROR("lack of member");
@@ -82,7 +74,7 @@ EXIT:
ResultCode UserAuthTokenVerify(const UserAuthTokenHal *userAuthToken)
{
if (userAuthToken == NULL) {
LOG_ERROR("userAuthToken is NULL");
LOG_ERROR("userAuthToken is null");
return RESULT_BAD_PARAM;
}
@@ -92,7 +84,7 @@ ResultCode UserAuthTokenVerify(const UserAuthTokenHal *userAuthToken)
}
ResultCode ret = RESULT_SUCCESS;
Buffer *data = CreateBufferByData((uint8_t *)userAuthToken, AUTH_TOKEN_DATA_LEN);
Buffer *key = CreateBufferByData(g_userAuthTokenKey, SHA256_KEY_LEN);
Buffer *key = GetTokenKey();
Buffer *sign = CreateBufferByData((uint8_t *)userAuthToken->sign, SHA256_SIGN_LEN);
Buffer *rightSign = NULL;
if (data == NULL || key == NULL || sign == NULL) {
@@ -107,7 +99,7 @@ ResultCode UserAuthTokenVerify(const UserAuthTokenHal *userAuthToken)
}
if (!CompareBuffer(rightSign, sign)) {
LOG_ERROR("sign compare failed ");
LOG_ERROR("sign compare failed");
ret = RESULT_BAD_SIGN;
}
@@ -35,29 +35,32 @@ sptr<CoAuth::ICoAuth> AuthExecutorRegistry::GetProxy()
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get system ability manager");
COAUTH_HILOGE(MODULE_INNERKIT, "get system ability manager failed");
return nullptr;
}
sptr<IRemoteObject> obj = sam->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR);
if (obj == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get coauth service");
COAUTH_HILOGE(MODULE_INNERKIT, "get coauth service failed");
return nullptr;
}
sptr<IRemoteObject::DeathRecipient> dr = new AuthExecutorRegistryDeathRecipient();
if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(dr))) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to add death recipient");
COAUTH_HILOGE(MODULE_INNERKIT, "add death recipient failed");
return nullptr;
}
proxy_ = iface_cast<CoAuth::ICoAuth>(obj);
deathRecipient_ = dr;
COAUTH_HILOGI(MODULE_INNERKIT, "Succeed to connect coauth service");
COAUTH_HILOGI(MODULE_INNERKIT, "connect coauth service success");
return proxy_;
}
void AuthExecutorRegistry::ResetProxy(const wptr<IRemoteObject>& remote)
{
std::lock_guard<std::mutex> lock(mutex_);
if (proxy_ == nullptr) {
return;
}
auto serviceRemote = proxy_->AsObject();
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
serviceRemote->RemoveDeathRecipient(deathRecipient_);
@@ -66,16 +69,16 @@ void AuthExecutorRegistry::ResetProxy(const wptr<IRemoteObject>& remote)
}
uint64_t AuthExecutorRegistry::Register(std::shared_ptr<AuthExecutor> executorInfo,
std::shared_ptr<ExecutorCallback> callback)
std::shared_ptr<ExecutorCallback> callback)
{
COAUTH_HILOGD(MODULE_INNERKIT, "Register enter");
COAUTH_HILOGD(MODULE_INNERKIT, "Register start");
if (executorInfo == nullptr || callback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Register failed,executorInfo or callback is nullptr");
COAUTH_HILOGE(MODULE_INNERKIT, "executorInfo or callback is nullptr");
return FAIL;
}
auto proxy = GetProxy();
if (proxy == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "GetProxy is nullptr");
COAUTH_HILOGE(MODULE_INNERKIT, "proxy is nullptr");
return FAIL;
}
sptr<IExecutorCallback> iExecutorCallback = new ExecutorCallbackStub(callback);
@@ -84,14 +87,14 @@ uint64_t AuthExecutorRegistry::Register(std::shared_ptr<AuthExecutor> executorIn
void AuthExecutorRegistry::QueryStatus(AuthExecutor &executorInfo, std::shared_ptr<QueryCallback> callback)
{
COAUTH_HILOGD(MODULE_INNERKIT, "QueryStatus enter");
COAUTH_HILOGD(MODULE_INNERKIT, "QueryStatus start");
if (callback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "QueryStatus failed, callback is nullptr");
COAUTH_HILOGE(MODULE_INNERKIT, "callback is nullptr");
return;
}
auto proxy = GetProxy();
if (proxy == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "GetProxy is nullptr");
COAUTH_HILOGE(MODULE_INNERKIT, "proxy is nullptr");
return;
}
sptr<IQueryCallback> iQueryCallback = new QueryCallbackStub(callback);
@@ -101,12 +104,12 @@ void AuthExecutorRegistry::QueryStatus(AuthExecutor &executorInfo, std::shared_p
void AuthExecutorRegistry::AuthExecutorRegistryDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "OnRemoteDied failed, remote is nullptr");
COAUTH_HILOGE(MODULE_INNERKIT, "remote is nullptr");
return;
}
AuthExecutorRegistry::GetInstance().ResetProxy(remote);
COAUTH_HILOGE(MODULE_INNERKIT, "CoAuthDeathRecipient::Recv death notice.");
COAUTH_HILOGE(MODULE_INNERKIT, "AuthExecutorRegistryDeathRecipient::Recv death notice");
}
} // namespace AuthResPool
} // namespace UserIAM
+8 -8
View File
@@ -36,23 +36,23 @@ sptr<ICoAuth> CoAuth::GetProxy()
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get system ability manager");
COAUTH_HILOGE(MODULE_INNERKIT, "get system ability manager failed");
return nullptr;
}
sptr<IRemoteObject> obj = sam->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR);
if (obj == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to get coauth manager service");
COAUTH_HILOGE(MODULE_INNERKIT, "get coauth manager service failed");
return nullptr;
}
sptr<IRemoteObject::DeathRecipient> dr = new CoAuthDeathRecipient();
if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(dr))) {
COAUTH_HILOGE(MODULE_INNERKIT, "Failed to add death recipient");
COAUTH_HILOGE(MODULE_INNERKIT, "add death recipient failed");
return nullptr;
}
proxy_ = iface_cast<ICoAuth>(obj);
deathRecipient_ = dr;
COAUTH_HILOGD(MODULE_INNERKIT, "Succeed to connect coauth manager service");
COAUTH_HILOGD(MODULE_INNERKIT, "connect coauth manager service success");
return proxy_;
}
@@ -72,7 +72,7 @@ void CoAuth::ResetProxy(const wptr<IRemoteObject>& remote)
void CoAuth::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, std::shared_ptr<CoAuthCallback> callback)
{
COAUTH_HILOGD(MODULE_INNERKIT, "BeginSchedule enter");
COAUTH_HILOGD(MODULE_INNERKIT, "BeginSchedule start");
if (callback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "BeginSchedule failed, callback is nullptr");
return;
@@ -93,7 +93,7 @@ void CoAuth::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, std::shared_
int32_t CoAuth::Cancel(uint64_t scheduleId)
{
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuth Cancel enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuth Cancel start");
auto proxy = GetProxy();
if (proxy == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Cancel failed, proxy is nullptr");
@@ -106,7 +106,7 @@ int32_t CoAuth::Cancel(uint64_t scheduleId)
int32_t CoAuth::GetExecutorProp(AuthResPool::AuthAttributes &conditions,
std::shared_ptr<AuthResPool::AuthAttributes> values)
{
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuth: GetExecutorProp enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuth: GetExecutorProp start");
auto proxy = GetProxy();
if (proxy == nullptr || values == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "GetExecutorProp failed, proxy or values is nullptr");
@@ -118,7 +118,7 @@ int32_t CoAuth::GetExecutorProp(AuthResPool::AuthAttributes &conditions,
void CoAuth::SetExecutorProp(AuthResPool::AuthAttributes &conditions, std::shared_ptr<SetPropCallback> callback)
{
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuth: SetExecutorProp enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuth: SetExecutorProp start");
auto proxy = GetProxy();
if (proxy == nullptr || callback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "SetExecutorProp failed, proxy or callback is nullptr");
@@ -28,16 +28,16 @@ void CoAuthCallbackProxy::OnFinish(uint32_t resultCode, std::vector<uint8_t> &sc
MessageParcel reply;
if (!data.WriteInterfaceToken(CoAuthCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
if (!data.WriteUint32(resultCode)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(resultCode).");
COAUTH_HILOGE(MODULE_INNERKIT, "write resultCode failed");
return;
}
if (!data.WriteUInt8Vector(scheduleToken)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUInt8Vector(scheduleToken).");
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleToken failed");
return;
}
@@ -51,11 +51,11 @@ void CoAuthCallbackProxy::OnAcquireInfo(uint32_t acquire)
{
MessageParcel data;
if (!data.WriteInterfaceToken(CoAuthCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
if (!data.WriteUint32(acquire)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(acquire).");
COAUTH_HILOGE(MODULE_INNERKIT, "write acquire failed");
return;
}
@@ -70,13 +70,13 @@ bool CoAuthCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, Messag
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get remote.");
COAUTH_HILOGE(MODULE_INNERKIT, "get remote failed");
return false;
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.result = %{public}d", result);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, result = %{public}d", result);
return false;
}
return true;
@@ -32,7 +32,7 @@ int32_t CoAuthCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
std::u16string descripter = CoAuthCallbackStub::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
if (descripter != remoteDescripter) {
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuthStub::OnRemoteRequest failed, descriptor is not matched!");
COAUTH_HILOGD(MODULE_INNERKIT, "descriptor is not matched");
return FAIL;
}
switch (code) {
@@ -47,18 +47,18 @@ int32_t CoAuthCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
int32_t CoAuthCallbackStub::OnFinishStub(MessageParcel &data, MessageParcel &reply)
{
(void)reply;
uint32_t resultCode = data.ReadUint32();
std::vector<uint8_t> scheduleToken;
data.ReadUInt8Vector(&scheduleToken);
OnFinish(resultCode, scheduleToken);
return SUCCESS;
}
int32_t CoAuthCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply)
{
(void)reply;
uint32_t acquire = data.ReadUint32();
OnAcquireInfo(acquire);
return SUCCESS;
}
@@ -66,7 +66,7 @@ int32_t CoAuthCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel
void CoAuthCallbackStub::OnFinish(uint32_t resultCode, std::vector<uint8_t> &scheduleToken)
{
if (callback_ == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "CoAuthCallback is null.");
COAUTH_HILOGE(MODULE_INNERKIT, "callback_ is null");
} else {
callback_->OnFinish(resultCode, scheduleToken);
}
@@ -75,7 +75,7 @@ void CoAuthCallbackStub::OnFinish(uint32_t resultCode, std::vector<uint8_t> &sch
void CoAuthCallbackStub::OnAcquireInfo(uint32_t acquire)
{
if (callback_ == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "CoAuthCallback is null.");
COAUTH_HILOGE(MODULE_INNERKIT, "callback_ is null");
} else {
callback_->OnAcquireInfo(acquire);
}
+49 -49
View File
@@ -67,57 +67,57 @@ uint32_t CoAuthProxy::WriteAuthExecutor(AuthResPool::AuthExecutor &executorInfo,
}
uint64_t CoAuthProxy::Register(std::shared_ptr<AuthResPool::AuthExecutor> executorInfo,
const sptr<AuthResPool::IExecutorCallback> &callback)
const sptr<AuthResPool::IExecutorCallback> &callback)
{
COAUTH_HILOGD(MODULE_INNERKIT, "Register enter");
COAUTH_HILOGD(MODULE_INNERKIT, "Register start");
if (executorInfo == nullptr || callback == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "Register failed, executorInfo or callback is nullptr");
COAUTH_HILOGE(MODULE_INNERKIT, "executorInfo or callback is nullptr");
return 0;
}
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return 0;
}
if (WriteAuthExecutor(*executorInfo, data) == FAIL) {
COAUTH_HILOGE(MODULE_INNERKIT, "write executorInfo failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write executorInfo failed");
return 0;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback).");
COAUTH_HILOGE(MODULE_INNERKIT, "write callback filed");
return 0;
}
uint64_t result = 0;
bool ret = SendRequest(static_cast<int32_t>(ICoAuth::COAUTH_EXECUTOR_REGIST), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
return 0;
}
if (!reply.ReadUint64(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint64.");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return 0;
}
return result;
}
void CoAuthProxy::QueryStatus(AuthResPool::AuthExecutor &executorInfo,
const sptr<AuthResPool::IQueryCallback> &callback)
const sptr<AuthResPool::IQueryCallback> &callback)
{
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
if (WriteAuthExecutor(executorInfo, data) == FAIL) {
COAUTH_HILOGE(MODULE_INNERKIT, "write executorInfo failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write executorInfo failed");
return;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback).");
COAUTH_HILOGE(MODULE_INNERKIT, "write callback failed");
return;
}
@@ -131,29 +131,29 @@ void CoAuthProxy::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const s
MessageParcel reply;
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
std::string GetPkgName;
authInfo.GetPkgName(GetPkgName);
if (!data.WriteString(GetPkgName)) {
COAUTH_HILOGE(MODULE_INNERKIT, "WriteString,GetPkgName failed");
std::string pkgName;
authInfo.GetPkgName(pkgName);
if (!data.WriteString(pkgName)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write pkgName failed");
return;
}
uint64_t GetCallerUid;
authInfo.GetCallerUid(GetCallerUid);
data.WriteUint64(GetCallerUid);
COAUTH_HILOGD(MODULE_INNERKIT, "WriteUint64,GetCallerUid:%{public}" PRIu64, GetCallerUid);
uint64_t callerUid;
authInfo.GetCallerUid(callerUid);
data.WriteUint64(callerUid);
COAUTH_HILOGD(MODULE_INNERKIT, "write callerUid: %{public}" PRIu64, callerUid);
if (!data.WriteUint64(scheduleId)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(scheduleId).");
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed");
return;
}
COAUTH_HILOGD(MODULE_INNERKIT, "WriteUint64,scheduleId:%{public}" PRIu64, scheduleId);
COAUTH_HILOGD(MODULE_INNERKIT, "write scheduleId: %{public}" PRIu64, scheduleId);
if (!data.WriteRemoteObject(callback->AsObject())) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback).");
COAUTH_HILOGE(MODULE_INNERKIT, "write callback failed");
return;
}
@@ -161,32 +161,32 @@ void CoAuthProxy::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, const s
if (ret) {
COAUTH_HILOGD(MODULE_INNERKIT, "ret = %{public}d", ret);
} else {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
}
}
int32_t CoAuthProxy::Cancel(uint64_t scheduleId)
{
MessageParcel data;
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: Cancel enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: Cancel start");
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
if (!data.WriteUint64(scheduleId)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(scheduleId).");
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed");
return FAIL;
}
MessageParcel reply;
bool ret = SendRequest(static_cast<int32_t>(ICoAuth::COAUTH_SCHEDULE_CANCEL), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, error code: %{public}d", ret);
return FAIL;
}
int32_t result = FAIL;
if (!reply.ReadInt32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "Read result fail!");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return FAIL;
}
COAUTH_HILOGD(MODULE_INNERKIT, "result = %{public}d", result);
@@ -194,44 +194,44 @@ int32_t CoAuthProxy::Cancel(uint64_t scheduleId)
}
int32_t CoAuthProxy::GetExecutorProp(AuthResPool::AuthAttributes &conditions,
std::shared_ptr<AuthResPool::AuthAttributes> values)
std::shared_ptr<AuthResPool::AuthAttributes> values)
{
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: GetExecutorProp enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: GetExecutorProp start");
int32_t result = SUCCESS;
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
if (values == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get valuesptr.");
COAUTH_HILOGE(MODULE_INNERKIT, "values is nullptr");
return FAIL;
}
std::vector<uint8_t> buffer;
if (conditions.Pack(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "conditions pack buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "conditions pack buffer failed");
return FAIL;
}
if (!data.WriteUInt8Vector(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "data WriteUInt8Vector buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed");
return FAIL;
}
std::vector<uint8_t> valuesReply;
bool ret = SendRequest(static_cast<int32_t>(ICoAuth::COAUTH_GET_PROPERTY), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, error code: %{public}d", ret);
return FAIL;
}
if (!reply.ReadInt32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return FAIL;
}
if (!reply.ReadUInt8Vector(&valuesReply)) {
COAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!");
COAUTH_HILOGE(MODULE_INNERKIT, "read valuesReply failed");
return FAIL;
} else {
values->Unpack(valuesReply);
@@ -240,49 +240,49 @@ int32_t CoAuthProxy::GetExecutorProp(AuthResPool::AuthAttributes &conditions,
}
void CoAuthProxy::SetExecutorProp(AuthResPool::AuthAttributes &conditions,
const sptr<ISetPropCallback> &callback)
const sptr<ISetPropCallback> &callback)
{
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: SetExecutorProp enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: SetExecutorProp start");
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
std::vector<uint8_t> buffer;
if (conditions.Pack(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "conditions pack buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "conditions pack buffer failed");
return;
}
if (!data.WriteUInt8Vector(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "data WriteUInt8Vector buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "data WriteUInt8Vector buffer failed");
return;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback).");
COAUTH_HILOGE(MODULE_INNERKIT, "write callback failed");
return;
}
bool ret = SendRequest(static_cast<int32_t>(ICoAuth::COAUTH_SET_PROPERTY), data, reply, false);
if (ret) {
COAUTH_HILOGD(MODULE_INNERKIT, "ret = %{public}d", ret);
} else {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
}
}
bool CoAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, bool isSync)
{
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: SendRequest enter");
COAUTH_HILOGD(MODULE_INNERKIT, "CoauthProxy: SendRequest start");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get remote.");
COAUTH_HILOGE(MODULE_INNERKIT, "get remote failed");
return false;
}
MessageOption option(isSync ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.result = %{public}d", result);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, result = %{public}d", result);
return false;
}
return true;
@@ -22,16 +22,16 @@ namespace UserIAM {
namespace AuthResPool {
void ExecutorCallbackProxy::OnMessengerReady(const sptr<IExecutorMessenger> &messenger)
{
COAUTH_HILOGD(MODULE_INNERKIT, "ExecutorCallbackProxy OnMessengerReady!");
COAUTH_HILOGD(MODULE_INNERKIT, "ExecutorCallbackProxy OnMessengerReady");
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
if (!data.WriteRemoteObject(messenger.GetRefPtr()->AsObject())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write RemoteObject failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write RemoteObject failed");
return;
}
bool ret = SendRequest(static_cast<int32_t>(IExecutorCallback::ON_MESSENGER_READY), data, reply);
@@ -39,45 +39,45 @@ void ExecutorCallbackProxy::OnMessengerReady(const sptr<IExecutorMessenger> &mes
}
int32_t ExecutorCallbackProxy::OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey,
std::shared_ptr<AuthAttributes> commandAttrs)
std::shared_ptr<AuthAttributes> commandAttrs)
{
if (commandAttrs == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "commandAttrs is null!");
COAUTH_HILOGE(MODULE_INNERKIT, "commandAttrs is nullptr");
return INVALID_PARAMETERS;
}
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
if (!data.WriteUint64(scheduleId)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed");
return FAIL;
}
if (!data.WriteUInt8Vector(publicKey)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write publicKey failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write publicKey failed");
return FAIL;
}
std::vector<uint8_t> buffer;
if (commandAttrs->Pack(buffer) != SUCCESS) {
COAUTH_HILOGE(MODULE_INNERKIT, "pack commandAttrs failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "pack commandAttrs failed");
return FAIL;
}
if (!data.WriteUInt8Vector(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed");
return FAIL;
}
bool ret = SendRequest(static_cast<int32_t>(IExecutorCallback::ON_BEGIN_EXECUTE), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
return FAIL;
}
int32_t result = FAIL;
if (!reply.ReadInt32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return FAIL;
}
COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result);
@@ -93,33 +93,33 @@ int32_t ExecutorCallbackProxy::OnEndExecute(uint64_t scheduleId, std::shared_ptr
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
if (!data.WriteUint64(scheduleId)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write scheduleId failed");
return FAIL;
}
std::vector<uint8_t> buffer;
if (consumerAttr->Pack(buffer) != SUCCESS) {
COAUTH_HILOGE(MODULE_INNERKIT, "pack consumerAttr failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "pack consumerAttr failed");
return FAIL;
}
if (!data.WriteUInt8Vector(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed");
return FAIL;
}
bool ret = SendRequest(static_cast<int32_t>(IExecutorCallback::ON_END_EXECUTE), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest fail");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
return FAIL;
}
int32_t result = FAIL;
if (!reply.ReadInt32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "read result fail");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return FAIL;
}
COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result);
@@ -135,26 +135,26 @@ int32_t ExecutorCallbackProxy::OnSetProperty(std::shared_ptr<AuthAttributes> pro
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
std::vector<uint8_t> buffer;
if (properties->Pack(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "pack properties failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "pack properties failed");
return FAIL;
}
if (!data.WriteUInt8Vector(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed");
return FAIL;
}
bool ret = SendRequest(static_cast<int32_t>(IExecutorCallback::ON_SET_PROPERTY), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
return FAIL;
}
int32_t result = FAIL;
if (!reply.ReadInt32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "read result fail");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return FAIL;
}
COAUTH_HILOGI(MODULE_INNERKIT, "result = %{public}d", result);
@@ -162,7 +162,7 @@ int32_t ExecutorCallbackProxy::OnSetProperty(std::shared_ptr<AuthAttributes> pro
}
int32_t ExecutorCallbackProxy::OnGetProperty(std::shared_ptr<AuthAttributes> conditions,
std::shared_ptr<AuthAttributes> values)
std::shared_ptr<AuthAttributes> values)
{
if (conditions == nullptr || values == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "param is null");
@@ -171,38 +171,38 @@ int32_t ExecutorCallbackProxy::OnGetProperty(std::shared_ptr<AuthAttributes> con
MessageParcel data;
MessageParcel reply;
if (values == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "ExecutorCallbackProxy values is null.");
COAUTH_HILOGE(MODULE_INNERKIT, "values is null.");
return FAIL;
}
if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
std::vector<uint8_t> buffer;
if (conditions->Pack(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "pack conditions failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "pack conditions failed");
return FAIL;
}
if (!data.WriteUInt8Vector(buffer)) {
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write buffer failed");
return FAIL;
}
std::vector<uint8_t> valuesReply;
bool ret = SendRequest(static_cast<int32_t>(IExecutorCallback::ON_GET_PROPERTY), data, reply); // must sync
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed");
return FAIL;
}
int32_t result = FAIL;
if (!reply.ReadInt32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "read result fail");
COAUTH_HILOGE(MODULE_INNERKIT, "read result failed");
return FAIL;
}
if (!reply.ReadUInt8Vector(&valuesReply)) {
COAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!");
COAUTH_HILOGE(MODULE_INNERKIT, "read valuesReply failed");
return FAIL;
} else {
values->Unpack(valuesReply);
@@ -216,13 +216,13 @@ bool ExecutorCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, Mess
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get remote.");
COAUTH_HILOGE(MODULE_INNERKIT, "get remote failed");
return false;
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.result = %{public}d", result);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, result = %{public}d", result);
return false;
}
return true;
@@ -28,13 +28,13 @@ ExecutorCallbackStub::ExecutorCallbackStub(const std::shared_ptr<ExecutorCallbac
}
int32_t ExecutorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
MessageParcel &reply, MessageOption &option)
{
COAUTH_HILOGD(MODULE_INNERKIT, "ExecutorCallbackStub::OnRemoteRequest!");
std::u16string descripter = ExecutorCallbackStub::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
if (descripter != remoteDescripter) {
COAUTH_HILOGE(MODULE_INNERKIT, "CoAuthStub::OnRemoteRequest failed, descriptor is not matched!");
COAUTH_HILOGE(MODULE_INNERKIT, "descriptor is not matched");
return FAIL;
}
@@ -62,7 +62,7 @@ int32_t ExecutorCallbackStub::OnMessengerReadyStub(MessageParcel &data, MessageP
COAUTH_HILOGE(MODULE_INNERKIT, "messenger is nullptr");
return FAIL;
}
COAUTH_HILOGD(MODULE_INNERKIT, "iface_cast right");
COAUTH_HILOGD(MODULE_INNERKIT, "iface_cast is right");
OnMessengerReady(messenger);
COAUTH_HILOGD(MODULE_INNERKIT, "OnMessengerReady GetRefPtr");
return SUCCESS;
@@ -78,7 +78,7 @@ int32_t ExecutorCallbackStub::OnBeginExecuteStub(MessageParcel &data, MessagePar
commandAttrs->Unpack(buffer);
int32_t ret = OnBeginExecute(scheduleId, publicKey, commandAttrs);
if (!reply.WriteInt32(ret)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)");
COAUTH_HILOGE(MODULE_INNERKIT, "write ret failed");
return FAIL;
}
return SUCCESS;
@@ -97,7 +97,7 @@ int32_t ExecutorCallbackStub::OnEndExecuteStub(MessageParcel &data, MessageParce
consumerAttr->Unpack(buffer);
int32_t ret = OnEndExecute(scheduleId, consumerAttr);
if (!reply.WriteInt32(ret)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)");
COAUTH_HILOGE(MODULE_INNERKIT, "write ret failed");
return FAIL;
}
return SUCCESS;
@@ -113,14 +113,14 @@ int32_t ExecutorCallbackStub::OnGetPropertyStub(MessageParcel &data, MessageParc
std::shared_ptr<AuthAttributes> values = std::make_shared<AuthAttributes>();
int32_t ret = OnGetProperty(conditions, values);
if (!reply.WriteInt32(ret)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)");
COAUTH_HILOGE(MODULE_INNERKIT, "write ret failed");
return FAIL;
}
std::vector<uint8_t> replyBuffer;
values->Pack(replyBuffer);
if (!reply.WriteUInt8Vector(replyBuffer)) {
COAUTH_HILOGE(MODULE_SERVICE, "failed to replyBuffer");
COAUTH_HILOGE(MODULE_SERVICE, "write replyBuffer failed");
return FAIL;
}
return SUCCESS;
@@ -135,7 +135,7 @@ int32_t ExecutorCallbackStub::OnSetPropertyStub(MessageParcel &data, MessageParc
int32_t ret = OnSetProperty(properties);
if (!reply.WriteInt32(ret)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)");
COAUTH_HILOGE(MODULE_INNERKIT, "write ret failed");
return FAIL;
}
return SUCCESS;
@@ -151,7 +151,7 @@ void ExecutorCallbackStub::OnMessengerReady(const sptr<IExecutorMessenger> &mess
}
int32_t ExecutorCallbackStub::OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey,
std::shared_ptr<AuthAttributes> commandAttrs)
std::shared_ptr<AuthAttributes> commandAttrs)
{
int32_t ret = FAIL;
if (callback_ == nullptr) {
@@ -185,7 +185,7 @@ int32_t ExecutorCallbackStub::OnSetProperty(std::shared_ptr<AuthAttributes> prop
}
int32_t ExecutorCallbackStub::OnGetProperty(std::shared_ptr<AuthAttributes> conditions,
std::shared_ptr<AuthAttributes> values)
std::shared_ptr<AuthAttributes> values)
{
int32_t ret = FAIL;
if (callback_ == nullptr) {
@@ -21,17 +21,17 @@ namespace OHOS {
namespace UserIAM {
namespace AuthResPool {
int32_t ExecutorMessengerProxy::SendData(uint64_t scheduleId, uint64_t transNum,
int32_t srcType, int32_t dstType, std::shared_ptr<AuthMessage> msg)
int32_t srcType, int32_t dstType, std::shared_ptr<AuthMessage> msg)
{
if (msg == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "AuthMessage is null!");
COAUTH_HILOGE(MODULE_INNERKIT, "msg is nullptr");
return INVALID_PARAMETERS;
}
MessageParcel data;
MessageParcel reply;
int32_t result = 0;
if (!data.WriteInterfaceToken(ExecutorMessengerProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
if (!data.WriteUint64(scheduleId)) {
@@ -62,16 +62,16 @@ int32_t ExecutorMessengerProxy::SendData(uint64_t scheduleId, uint64_t transNum,
int32_t ExecutorMessengerProxy::Finish(uint64_t scheduleId, int32_t srcType, int32_t resultCode,
std::shared_ptr<AuthAttributes> finalResult)
std::shared_ptr<AuthAttributes> finalResult)
{
if (finalResult == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "finalResult is null!");
COAUTH_HILOGE(MODULE_INNERKIT, "finalResult is nullptr");
return INVALID_PARAMETERS;
}
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(ExecutorMessengerProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return FAIL;
}
if (!data.WriteUint64(scheduleId)) {
@@ -98,17 +98,18 @@ int32_t ExecutorMessengerProxy::Finish(uint64_t scheduleId, int32_t srcType, int
}
return result;
}
bool ExecutorMessengerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get remote.");
COAUTH_HILOGE(MODULE_INNERKIT, "get remote failed");
return false;
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.result = %{public}d", result);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, result = %{public}d", result);
return false;
}
return true;
@@ -22,14 +22,13 @@ const std::string PERMISSION_AUTH_RESPOOL = "ohos.permission.ACCESS_AUTH_RESPOOL
const std::string PERMISSION_ACCESS_COAUTH = "ohos.permission.ACCESS_COAUTH";
int32_t ExecutorMessengerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
MessageParcel &reply, MessageOption &option)
{
COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest, cmd = %{public}u, flags= %{public}d",
code, option.GetFlags());
COAUTH_HILOGD(MODULE_SERVICE, "cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
std::u16string descripter = ExecutorMessengerStub::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
if (descripter != remoteDescripter) {
COAUTH_HILOGE(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest failed, descriptor is not matched!");
COAUTH_HILOGE(MODULE_SERVICE, "descriptor is not matched");
return FAIL;
}
@@ -42,6 +41,7 @@ int32_t ExecutorMessengerStub::OnRemoteRequest(uint32_t code, MessageParcel &dat
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
int32_t ExecutorMessengerStub::SendDataStub(MessageParcel& data, MessageParcel& reply)
{
uint64_t scheduleId = data.ReadUint64();
@@ -53,7 +53,7 @@ int32_t ExecutorMessengerStub::SendDataStub(MessageParcel& data, MessageParcel&
std::shared_ptr<AuthMessage> msg = std::make_shared<AuthMessage>(buffer);
int32_t ret = SendData(scheduleId, transNum, srcType, dstType, msg); // Call business function
if (!reply.WriteInt32(ret)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)");
COAUTH_HILOGE(MODULE_INNERKIT, "write ret failed");
return FAIL;
}
return SUCCESS;
@@ -72,7 +72,7 @@ int32_t ExecutorMessengerStub::FinishStub(MessageParcel& data, MessageParcel& re
int32_t ret = Finish(scheduleId, srcType, resultCode, finalResult);
if (!reply.WriteInt32(ret)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(ret)");
COAUTH_HILOGE(MODULE_INNERKIT, "write ret failed");
return FAIL;
}
return SUCCESS;
@@ -25,11 +25,11 @@ void QueryCallbackProxy::OnResult(uint32_t resultCode)
{
MessageParcel data;
if (!data.WriteInterfaceToken(QueryCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
if (!data.WriteUint32(resultCode)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(scheduleId).");
COAUTH_HILOGE(MODULE_INNERKIT, "write resultCode failed");
return;
}
MessageParcel reply;
@@ -43,13 +43,13 @@ bool QueryCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, Message
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get remote.");
COAUTH_HILOGE(MODULE_INNERKIT, "get remote failed");
return false;
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.result = %{public}d", result);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, result = %{public}d", result);
return false;
}
return true;
@@ -27,12 +27,12 @@ QueryCallbackStub::QueryCallbackStub(const std::shared_ptr<QueryCallback>& impl)
}
int32_t QueryCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
MessageParcel &reply, MessageOption &option)
{
std::u16string descripter = QueryCallbackStub::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
if (descripter != remoteDescripter) {
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuthStub::OnRemoteRequest failed, descriptor is not matched!");
COAUTH_HILOGD(MODULE_INNERKIT, "descriptor is not matched");
return FAIL;
}
switch (code) {
@@ -26,22 +26,22 @@ void SetPropCallbackProxy::OnResult(uint32_t result, std::vector<uint8_t> &extra
MessageParcel data;
MessageParcel reply;
if (!data.WriteInterfaceToken(SetPropCallbackProxy::GetDescriptor())) {
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
COAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed");
return;
}
if (!data.WriteUint32(result)) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(result).");
COAUTH_HILOGE(MODULE_INNERKIT, "write result failed");
return;
}
if (!data.WriteUInt8Vector(extraInfo)) {
COAUTH_HILOGE(MODULE_INNERKIT, "fail to write WriteUInt8Vector extraInfo");
COAUTH_HILOGE(MODULE_INNERKIT, "write extraInfo failed");
return;
}
bool ret = SendRequest(static_cast<int32_t>(ISetPropCallback::ONRESULT), data, reply);
if (!ret) {
COAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, error code: %{public}d", ret);
}
}
@@ -49,13 +49,13 @@ bool SetPropCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, Messa
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to get remote.");
COAUTH_HILOGE(MODULE_INNERKIT, "get remote failed");
return false;
}
MessageOption option(MessageOption::TF_SYNC);
int32_t result = remote->SendRequest(code, data, reply, option);
if (result != OHOS::NO_ERROR) {
COAUTH_HILOGE(MODULE_INNERKIT, "failed to SendRequest.result = %{public}d", result);
COAUTH_HILOGE(MODULE_INNERKIT, "send request failed, result = %{public}d", result);
return false;
}
return true;
@@ -25,13 +25,13 @@ SetPropCallbackStub::SetPropCallbackStub(const std::shared_ptr<SetPropCallback>&
callback_ = impl;
}
int32_t SetPropCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
int32_t SetPropCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
std::u16string descripter = SetPropCallbackStub::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
if (descripter != remoteDescripter) {
COAUTH_HILOGD(MODULE_INNERKIT, "CoAuthStub::OnRemoteRequest failed, descriptor is not matched!");
COAUTH_HILOGD(MODULE_INNERKIT, "descriptor is not matched");
return FAIL;
}
switch (code) {
+35 -54
View File
@@ -57,141 +57,123 @@ void AuthAttributes::clear()
int32_t AuthAttributes::GetBoolValue(AuthAttributeType attrType, bool &value)
{
int32_t ret = SUCCESS;
std::map<AuthAttributeType, bool>::iterator iter = boolValueMap_.find(attrType);
if (iter != boolValueMap_.end()) {
value = iter->second;
} else {
ret = FAIL;
if (iter == boolValueMap_.end()) {
return FAIL;
}
return ret;
value = iter->second;
return SUCCESS;
}
int32_t AuthAttributes::GetUint32Value(AuthAttributeType attrType, uint32_t &value)
{
int32_t ret = SUCCESS;
std::map<AuthAttributeType, uint32_t>::iterator iter = uint32ValueMap_.find(attrType);
if (iter != uint32ValueMap_.end()) {
value = iter->second;
} else {
ret = FAIL;
if (iter == uint32ValueMap_.end()) {
return FAIL;
}
return ret;
value = iter->second;
return SUCCESS;
}
int32_t AuthAttributes::GetUint64Value(AuthAttributeType attrType, uint64_t &value)
{
int32_t ret = SUCCESS;
std::map<AuthAttributeType, uint64_t>::iterator iter = uint64ValueMap_.find(attrType);
if (iter != uint64ValueMap_.end()) {
value = iter->second;
} else {
ret = FAIL;
if (iter == uint64ValueMap_.end()) {
return FAIL;
}
return ret;
value = iter->second;
return SUCCESS;
}
int32_t AuthAttributes::GetUint32ArrayValue(AuthAttributeType attrType, std::vector<uint32_t> &value)
{
int32_t ret = SUCCESS;
std::map<AuthAttributeType, std::vector<uint32_t>>::iterator iter = uint32ArraylValueMap_.find(attrType);
if (iter != uint32ArraylValueMap_.end()) {
value = iter->second;
} else {
ret = FAIL;
if (iter == uint32ArraylValueMap_.end()) {
return FAIL;
}
return ret;
value = iter->second;
return SUCCESS;
}
int32_t AuthAttributes::GetUint64ArrayValue(AuthAttributeType attrType, std::vector<uint64_t> &value)
{
int32_t ret = SUCCESS;
std::map<AuthAttributeType, std::vector<uint64_t>>::iterator iter = uint64ArraylValueMap_.find(attrType);
if (iter != uint64ArraylValueMap_.end()) {
value = iter->second;
} else {
ret = FAIL;
if (iter == uint64ArraylValueMap_.end()) {
return FAIL;
}
return ret;
value = iter->second;
return SUCCESS;
}
int32_t AuthAttributes::GetUint8ArrayValue(AuthAttributeType attrType, std::vector<uint8_t> &value)
{
int32_t ret = SUCCESS;
std::map<AuthAttributeType, std::vector<uint8_t>>::iterator iter = uint8ArrayValueMap_.find(attrType);
if (iter != uint8ArrayValueMap_.end()) {
value = iter->second;
} else {
ret = FAIL;
if (iter == uint8ArrayValueMap_.end()) {
return FAIL;
}
return ret;
value = iter->second;
return SUCCESS;
}
int32_t AuthAttributes::SetBoolValue(AuthAttributeType attrType, bool value)
{
int32_t ret = SUCCESS;
if (authAttributesPosition_[attrType] != BOOLTYPE) {
return FAIL;
}
boolValueMap_[attrType] = value;
existAttributes_.push_back(attrType);
return ret;
return SUCCESS;
}
int32_t AuthAttributes::SetUint32Value(AuthAttributeType attrType, uint32_t value)
{
int32_t ret = SUCCESS;
if (authAttributesPosition_[attrType] != UINT32TYPE) {
return FAIL;
}
uint32ValueMap_[attrType] = value;
existAttributes_.push_back(attrType);
COAUTH_HILOGD(MODULE_INNERKIT, "SetUint32Value : %{public}u.", value);
return ret;
return SUCCESS;
}
int32_t AuthAttributes::SetUint64Value(AuthAttributeType attrType, uint64_t value)
{
int32_t ret = SUCCESS;
if (authAttributesPosition_[attrType] != UINT64TYPE) {
return FAIL;
}
uint64ValueMap_[attrType] = value;
existAttributes_.push_back(attrType);
return ret;
return SUCCESS;
}
int32_t AuthAttributes::SetUint32ArrayValue(AuthAttributeType attrType, std::vector<uint32_t> &value)
{
int32_t ret = SUCCESS;
if (authAttributesPosition_[attrType] != UINT32ARRAYTYPE) {
return FAIL;
}
uint32ArraylValueMap_[attrType] = value;
existAttributes_.push_back(attrType);
return ret;
return SUCCESS;
}
int32_t AuthAttributes::SetUint64ArrayValue(AuthAttributeType attrType, std::vector<uint64_t> &value)
{
int32_t ret = SUCCESS;
if (authAttributesPosition_[attrType] != UINT64ARRAYTYPE) {
return FAIL;
}
uint64ArraylValueMap_[attrType] = value;
existAttributes_.push_back(attrType);
return ret;
return SUCCESS;
}
int32_t AuthAttributes::SetUint8ArrayValue(AuthAttributeType attrType, std::vector<uint8_t> &value)
{
int32_t ret = SUCCESS;
if (authAttributesPosition_[attrType] != UINT8ARRAYTYPE) {
return FAIL;
}
uint8ArrayValueMap_[attrType] = value;
existAttributes_.push_back(attrType);
return ret;
return SUCCESS;
}
void AuthAttributes::UnpackTag(AuthAttributeType &tag, std::vector<uint8_t> &buffer,
@@ -265,7 +247,7 @@ void AuthAttributes::UnpackUint8ArrayType(std::vector<uint8_t> &buffer, AuthAttr
AuthAttributes* AuthAttributes::Unpack(std::vector<uint8_t> &buffer)
{
if (buffer.size() == 0) {
if (buffer.empty()) {
return nullptr;
}
uint32_t dataLength;
@@ -413,7 +395,7 @@ int32_t AuthAttributes::Pack(std::vector<uint8_t> &buffer)
void AuthAttributes::Write32Array(std::vector<uint32_t> &uint32ArraylValue, uint8_t *writePointer,
std::vector<uint8_t> &buffer)
std::vector<uint8_t> &buffer)
{
for (std::size_t num = 0; num < uint32ArraylValue.size(); num++) {
writePointer = static_cast<uint8_t*>(static_cast<void *>(&uint32ArraylValue[num]));
@@ -421,7 +403,7 @@ void AuthAttributes::Write32Array(std::vector<uint32_t> &uint32ArraylValue, uint
}
}
void AuthAttributes::Write64Array(std::vector<uint64_t> &uint64ArraylValue, uint8_t *writePointer,
std::vector<uint8_t> &buffer)
std::vector<uint8_t> &buffer)
{
for (std::size_t num = 0; num < uint64ArraylValue.size(); num++) {
writePointer = static_cast<uint8_t*>(static_cast<void *>(&uint64ArraylValue[num]));
@@ -429,9 +411,8 @@ void AuthAttributes::Write64Array(std::vector<uint64_t> &uint64ArraylValue, uint
}
}
void AuthAttributes::PackToBuffer(std::map<AuthAttributeType, ValueType>::iterator iter,
uint32_t dataLength, uint8_t *writePointer,
std::vector<uint8_t> &buffer)
void AuthAttributes::PackToBuffer(std::map<AuthAttributeType, ValueType>::iterator iter,
uint32_t dataLength, uint8_t *writePointer, std::vector<uint8_t> &buffer)
{
bool boolValue;
uint32_t uint32Value;
@@ -37,6 +37,7 @@ int32_t AuthExecutor::GetAuthType(AuthType &value)
value = authTypeValue_;
return 0;
}
int32_t AuthExecutor::SetAuthType(AuthType value)
{
authTypeValue_ = value;
@@ -48,6 +49,7 @@ int32_t AuthExecutor::GetAuthAbility(uint64_t &value)
value = authAbilityValue_;
return 0;
}
int32_t AuthExecutor::SetAuthAbility(uint64_t value)
{
authAbilityValue_ = value;
@@ -59,6 +61,7 @@ int32_t AuthExecutor::GetExecutorSecLevel(ExecutorSecureLevel &value)
value = executorSecLevelValue_;
return 0;
}
int32_t AuthExecutor::SetExecutorSecLevel(ExecutorSecureLevel value)
{
executorSecLevelValue_ = value;
@@ -70,6 +73,7 @@ int32_t AuthExecutor::GetExecutorType(ExecutorType &value)
value = executorTypeValue_;
return 0;
}
int32_t AuthExecutor::SetExecutorType(ExecutorType value)
{
executorTypeValue_ = value;
@@ -81,6 +85,7 @@ int32_t AuthExecutor::GetPublicKey(std::vector<uint8_t> &value)
value = publicKeyValue_;
return 0;
}
int32_t AuthExecutor::SetPublicKey(std::vector<uint8_t> &value)
{
publicKeyValue_ = value;
@@ -92,6 +97,7 @@ int32_t AuthExecutor::GetDeviceId(std::vector<uint8_t> &value)
value = deviceIdValue_;
return 0;
}
int32_t AuthExecutor::SetDeviceId(std::vector<uint8_t> &value)
{
deviceIdValue_ = value;
+13
View File
@@ -1,3 +1,16 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
service useriam /system/bin/sa_main /system/profile/useriam.xml
class z_core
user system
+26 -30
View File
@@ -23,11 +23,9 @@ namespace CoAuth {
/* Register the executor, pass in the executor information and the callback returns the executor ID. */
uint64_t AuthResManager::Register(std::shared_ptr<ResAuthExecutor> executorInfo, sptr<ResIExecutorCallback> callback)
{
int32_t result = SUCCESS;
uint64_t executorId = INVALID_EXECUTOR_ID;
if (executorInfo == nullptr || callback == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "executorInfo or callback is nullptr");
return executorId;
return INVALID_EXECUTOR_ID;
}
ExecutorInfo info;
std::vector<uint8_t> publicKey;
@@ -44,32 +42,30 @@ uint64_t AuthResManager::Register(std::shared_ptr<ResAuthExecutor> executorInfo,
info.executorType = exeType;
if (publicKey.size() > PUBLIC_KEY_LEN) {
COAUTH_HILOGE(MODULE_SERVICE, "publicKey length too long");
return executorId;
} else {
for (std::size_t i = 0; i < publicKey.size(); i++) {
info.publicKey[i] = publicKey[i];
}
return INVALID_EXECUTOR_ID;
}
result = ExecutorRegister(info, executorId);
if (result == SUCCESS) {
sptr<IRemoteObject::DeathRecipient> dr = new ResIExecutorCallbackDeathRecipient(executorId, this);
if (!callback->AsObject()->AddDeathRecipient(dr)) {
COAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient ResIExecutorCallbackDeathRecipient");
return INVALID_EXECUTOR_ID;
}
coAuthResPool_.Insert(executorId, executorInfo, callback);
COAUTH_HILOGI(MODULE_SERVICE, "register is successfull!");
// Assign messenger
sptr<UserIAM::AuthResPool::IExecutorMessenger> messenger =
new UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_);
callback->OnMessengerReady(messenger);
COAUTH_HILOGD(MODULE_SERVICE, "register is successfull,exeID is XXXX%{public}04" PRIx64, executorId);
return executorId;
for (std::size_t i = 0; i < publicKey.size(); i++) {
info.publicKey[i] = publicKey[i];
}
if (result == FAIL) {
uint64_t executorId = INVALID_EXECUTOR_ID;
int32_t result = ExecutorRegister(info, executorId);
if (result != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "register is failure!");
return INVALID_EXECUTOR_ID;
}
sptr<IRemoteObject::DeathRecipient> dr = new ResIExecutorCallbackDeathRecipient(executorId, this);
if (!callback->AsObject()->AddDeathRecipient(dr)) {
COAUTH_HILOGE(MODULE_SERVICE, "add death recipient ResIExecutorCallbackDeathRecipient failed");
return INVALID_EXECUTOR_ID;
}
coAuthResPool_.Insert(executorId, executorInfo, callback);
// Assign messenger
sptr<UserIAM::AuthResPool::IExecutorMessenger> messenger =
new UserIAM::AuthResPool::ExecutorMessenger(&coAuthResPool_);
callback->OnMessengerReady(messenger);
COAUTH_HILOGD(MODULE_SERVICE, "register is successfull, exeID is XXXX%{public}04" PRIx64, executorId);
return executorId;
}
@@ -85,15 +81,15 @@ void AuthResManager::QueryStatus(ResAuthExecutor &executorInfo, sptr<ResIQueryCa
}
result = executorInfo.GetAuthType(authType);
if (result == SUCCESS) {
COAUTH_HILOGI(MODULE_SERVICE, "GetAuthType is success");
COAUTH_HILOGI(MODULE_SERVICE, "get AuthType success");
isExist = IsExecutorExist(authType); // call TA
} else {
COAUTH_HILOGE(MODULE_SERVICE, "GetAuthType is failure");
COAUTH_HILOGE(MODULE_SERVICE, "get AuthType failed");
}
if (isExist == false) {
COAUTH_HILOGE(MODULE_SERVICE, "query status executor register is not exist!");
COAUTH_HILOGE(MODULE_SERVICE, "query status executor register is not exist");
} else {
COAUTH_HILOGI(MODULE_SERVICE, "query status executor register is exist!");
COAUTH_HILOGI(MODULE_SERVICE, "query status executor register is exist");
}
callback->OnResult(isExist ? SUCCESS : FAIL);
}
@@ -148,9 +144,9 @@ void AuthResManager::ResIExecutorCallbackDeathRecipient::OnRemoteDied(const wptr
int32_t ret = ExecutorUnRegister(executorID_);
if (ret != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "executor unregister fail.");
COAUTH_HILOGE(MODULE_SERVICE, "executor unregister failed");
}
COAUTH_HILOGW(MODULE_SERVICE, "ResIExecutorCallbackDeathRecipient::Recv death notice.");
COAUTH_HILOGW(MODULE_SERVICE, "ResIExecutorCallbackDeathRecipient::Recv death notice");
}
} // namespace CoAuth
} // namespace UserIAM
+55 -74
View File
@@ -23,154 +23,135 @@ namespace CoAuth {
int32_t AuthResPool::Insert(uint64_t executorID, std::shared_ptr<ResAuthExecutor> executorInfo,
sptr<ResIExecutorCallback> callback)
{
int32_t resultCode = SUCCESS;
std::lock_guard<std::mutex> lock(authMutex_);
auto executorRegister = std::make_shared<ExecutorRegister>();
executorRegister->executorInfo = executorInfo;
executorRegister->callback = callback;
authResPool_.insert(std::make_pair(executorID, executorRegister));
if (authResPool_.begin() != authResPool_.end()) {
resultCode = SUCCESS;
COAUTH_HILOGI(MODULE_SERVICE, "authResPool_ insert success");
} else {
resultCode = FAIL;
if (authResPool_.begin() == authResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "authResPool_ is null");
return FAIL;
}
return resultCode;
COAUTH_HILOGI(MODULE_SERVICE, "authResPool_ insert success");
return SUCCESS;
}
int32_t AuthResPool::Insert(uint64_t scheduleId, uint64_t executorNum, sptr<ICoAuthCallback> callback)
{
int32_t resultCode = 0;
std::lock_guard<std::mutex> lock(scheMutex_);
auto scheduleRegister = std::make_shared<ScheduleRegister>();
scheduleRegister->executorNum = executorNum;
scheduleRegister->callback = callback;
scheResPool_.insert(std::make_pair(scheduleId, scheduleRegister));
if (scheResPool_.begin() != scheResPool_.end()) {
resultCode = SUCCESS;
COAUTH_HILOGI(MODULE_SERVICE, "scheResPool_ is not null");
} else {
resultCode = FAIL;
if (scheResPool_.begin() == scheResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "scheResPool_ is null");
return FAIL;
}
return resultCode;
COAUTH_HILOGI(MODULE_SERVICE, "scheResPool_ insert success");
return SUCCESS;
}
int32_t AuthResPool::FindExecutorCallback(uint64_t executorID, sptr<ResIExecutorCallback> &callback)
{
int32_t resultCode = 0;
std::lock_guard<std::mutex> lock(authMutex_);
std::map<uint64_t, std::shared_ptr<ExecutorRegister>>::iterator iter = authResPool_.find(executorID);
if (iter != authResPool_.end()) {
resultCode = SUCCESS;
callback = iter->second->callback;
COAUTH_HILOGI(MODULE_SERVICE, "callback is found");
} else {
resultCode = FAIL;
COAUTH_HILOGE(MODULE_SERVICE, "callback is not found, size is %{public}u", authResPool_.size());
if (iter == authResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "executorID is not found, size is %{public}zu", authResPool_.size());
return FAIL;
}
return resultCode;
callback = iter->second->callback;
COAUTH_HILOGI(MODULE_SERVICE, "find callback by executorID success");
return SUCCESS;
}
int32_t AuthResPool::FindExecutorCallback(uint32_t authType2Find, sptr<ResIExecutorCallback> &callback)
{
int32_t resultCode = SUCCESS;
AuthType authType;
std::lock_guard<std::mutex> lock(authMutex_);
std::map<uint64_t, std::shared_ptr<ExecutorRegister>>::iterator iter;
for (iter = authResPool_.begin(); iter != authResPool_.end(); ++iter) {
if (iter->second->executorInfo == nullptr) {
continue;
}
iter->second->executorInfo->GetAuthType(authType);
if ((AuthType)authType2Find == authType) {
callback = iter->second->callback;
COAUTH_HILOGI(MODULE_SERVICE, "Executor callback is found");
return resultCode;
COAUTH_HILOGI(MODULE_SERVICE, "find callback by authType success");
return SUCCESS;
}
}
COAUTH_HILOGE(MODULE_SERVICE, "Executor callback is not found, size is %{public}u", authResPool_.size());
COAUTH_HILOGE(MODULE_SERVICE, "authType is not found, size is %{public}zu", authResPool_.size());
callback = nullptr;
resultCode = FAIL;
return resultCode;
return FAIL;
}
int32_t AuthResPool::DeleteExecutorCallback(uint64_t executorID)
{
int32_t resultCode = SUCCESS;
std::lock_guard<std::mutex> lock(authMutex_);
std::map<uint64_t, std::shared_ptr<ExecutorRegister>>::iterator iter = authResPool_.find(executorID);
if (iter != authResPool_.end()) {
authResPool_.erase(iter);
resultCode = SUCCESS;
COAUTH_HILOGI(MODULE_SERVICE, "executor callback XXXX%{public}" PRIx64 " is deleted", executorID);
} else {
resultCode = FAIL;
COAUTH_HILOGE(MODULE_SERVICE, "executorID is not found and do not delete callback");
if (iter == authResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "executorID is not found and delete callback failed");
return FAIL;
}
return resultCode;
authResPool_.erase(iter);
COAUTH_HILOGI(MODULE_SERVICE, "delete executor callback XXXX%{public}" PRIx64 " success", executorID);
return SUCCESS;
}
int32_t AuthResPool::FindScheduleCallback(uint64_t scheduleId, sptr<ICoAuthCallback> &callback)
{
int32_t resultCode = SUCCESS;
std::lock_guard<std::mutex> lock(scheMutex_);
std::map<uint64_t, std::shared_ptr<ScheduleRegister>>::iterator iter = scheResPool_.find(scheduleId);
if (iter != scheResPool_.end()) {
resultCode = SUCCESS;
callback = iter->second->callback;
COAUTH_HILOGI(MODULE_SERVICE, "Schedule callback is found");
} else {
resultCode = FAIL;
COAUTH_HILOGE(MODULE_SERVICE, "Schedule callback is not found");
if (iter == scheResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "scheduleId is not found and find callback failed");
return FAIL;
}
return resultCode;
callback = iter->second->callback;
COAUTH_HILOGI(MODULE_SERVICE, "find shedule callback success");
return SUCCESS;
}
int32_t AuthResPool::ScheduleCountMinus(uint64_t scheduleId)
{
int32_t resultCode = SUCCESS;
std::lock_guard<std::mutex> lock(scheMutex_);
std::map<uint64_t, std::shared_ptr<ScheduleRegister>>::iterator iter = scheResPool_.find(scheduleId);
if (iter != scheResPool_.end()) {
iter->second->executorNum--;
resultCode = SUCCESS;
COAUTH_HILOGD(MODULE_SERVICE, "Schedule callback is found");
} else {
resultCode = FAIL;
COAUTH_HILOGE(MODULE_SERVICE, "Schedule callback is not found");
if (iter == scheResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "scheduleId is not found and count minus one failed");
return FAIL;
}
return resultCode;
if (iter->second->executorNum <= 0) {
COAUTH_HILOGE(MODULE_SERVICE, "executorNum is less than 1");
return FAIL;
}
iter->second->executorNum--;
COAUTH_HILOGD(MODULE_SERVICE, "schedule count minus one success");
return SUCCESS;
}
int32_t AuthResPool::GetScheduleCount(uint64_t scheduleId, uint64_t &scheduleCount)
{
int32_t resultCode = SUCCESS;
std::lock_guard<std::mutex> lock(scheMutex_);
std::map<uint64_t, std::shared_ptr<ScheduleRegister>>::iterator iter = scheResPool_.find(scheduleId);
if (iter != scheResPool_.end()) {
scheduleCount = iter->second->executorNum;
resultCode = SUCCESS;
COAUTH_HILOGD(MODULE_SERVICE, "Schedule callback is found");
} else {
resultCode = FAIL;
COAUTH_HILOGE(MODULE_SERVICE, "Schedule callback is not found");
if (iter == scheResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "scheduleId is not found and get executorNum failed");
return FAIL;
}
return resultCode;
scheduleCount = iter->second->executorNum;
COAUTH_HILOGD(MODULE_SERVICE, "get schedule count success");
return SUCCESS;
}
int32_t AuthResPool::DeleteScheduleCallback(uint64_t scheduleId)
{
int32_t resultCode = SUCCESS;
std::lock_guard<std::mutex> lock(scheMutex_);
std::map<uint64_t, std::shared_ptr<ScheduleRegister>>::iterator iter = scheResPool_.find(scheduleId);
if (iter != scheResPool_.end()) {
scheResPool_.erase(iter);
resultCode = SUCCESS;
COAUTH_HILOGD(MODULE_SERVICE, "Schedule callback is found");
} else {
resultCode = FAIL;
COAUTH_HILOGE(MODULE_SERVICE, "scheduleId is not found and do not delete callback");
if (iter == scheResPool_.end()) {
COAUTH_HILOGE(MODULE_SERVICE, "scheduleId is not found and delete callback failed");
return FAIL;
}
return resultCode;
scheResPool_.erase(iter);
COAUTH_HILOGD(MODULE_SERVICE, "delete schedule callback success");
return SUCCESS;
}
} // namespace CoAuth
} // namespace UserIAM
+36 -30
View File
@@ -29,7 +29,7 @@ void CoAuthManager::BeginSchedule(uint64_t scheduleId, AuthInfo &authInfo, sptr<
void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptr<ICoAuthCallback> callback)
{
if (callback == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "Schedule callback is null.");
COAUTH_HILOGE(MODULE_SERVICE, "schedule callback is null");
return;
}
int32_t executeRet = SUCCESS;
@@ -37,30 +37,33 @@ void CoAuthManager::CoAuthHandle(uint64_t scheduleId, AuthInfo &authInfo, sptr<I
std::vector<uint8_t> scheduleToken;
int32_t ret = GetScheduleInfo(scheduleId, scheduleInfo);
if (ret != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "Schedule failed.");
COAUTH_HILOGE(MODULE_SERVICE, "get schedule info failed");
return callback->OnFinish(ret, scheduleToken);
}
std::size_t executorNum = scheduleInfo.executors.size();
if (executorNum == 0) {
COAUTH_HILOGE(MODULE_SERVICE, "executorId does not exist.");
COAUTH_HILOGE(MODULE_SERVICE, "executorId does not exist");
return callback->OnFinish(FAIL, scheduleToken);
}
sptr<IRemoteObject::DeathRecipient> dr = new ResICoAuthCallbackDeathRecipient(scheduleId, this);
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
COAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient ResICoAuthCallbackDeathRecipient");
COAUTH_HILOGE(MODULE_SERVICE, "add death recipient ResICoAuthCallbackDeathRecipient failed");
}
if (coAuthResMgrPtr_ == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "coAuthResMgrPtr_ is nullptr");
return callback->OnFinish(FAIL, scheduleToken);
}
int32_t saveRet = coAuthResMgrPtr_->SaveScheduleCallback(scheduleId, executorNum, callback);
if (saveRet != SUCCESS) {
COAUTH_HILOGW(MODULE_SERVICE, "Save schedule callback error.");
COAUTH_HILOGW(MODULE_SERVICE, "save schedule callback failed");
return callback->OnFinish(saveRet, scheduleToken);
}
OHOS::AppExecFwk::InnerEvent::Callback task = std::bind(&CoAuthManager::TimeOut, this, scheduleId);
COAUTH_HILOGD(MODULE_SERVICE, "CoAuthManager::Excute MonitorCall");
CallMonitor::GetInstance().MonitorCall(delay_time, scheduleId, task);
BeginExecute(scheduleInfo, executorNum, scheduleId, authInfo, executeRet);
if (executeRet != SUCCESS) {
COAUTH_HILOGW(MODULE_SERVICE, "There are one or more failures in execution.");
COAUTH_HILOGW(MODULE_SERVICE, "there are one or more failures in execution");
callback->OnFinish(executeRet, scheduleToken);
coAuthResMgrPtr_->DeleteScheduleCallback(scheduleId);
CallMonitor::GetInstance().MonitorRemoveCall(scheduleId);
@@ -79,7 +82,7 @@ void CoAuthManager::BeginExecute(ScheduleInfo &scheduleInfo, std::size_t executo
scheduleInfo.executors[i].publicKey + PUBLIC_KEY_LEN);
int32_t findRet = coAuthResMgrPtr_->FindExecutorCallback(authType, executorCallback);
if ((findRet != SUCCESS) || (executorCallback == nullptr)) {
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found.");
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found");
continue;
}
auto commandAttrs = std::make_shared<ResAuthAttributes>();
@@ -120,13 +123,13 @@ int32_t CoAuthManager::Cancel(uint64_t scheduleId)
sptr<ResIExecutorCallback> callback = nullptr;
int32_t getRet = GetScheduleInfo(scheduleId, scheduleInfo); // call TA
if (getRet != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "cancel is failure");
COAUTH_HILOGE(MODULE_SERVICE, "get shedule info filed");
return FAIL;
}
COAUTH_HILOGI(MODULE_SERVICE, "cancel is successfull");
std::size_t executorNum = scheduleInfo.executors.size();
if (executorNum == 0) {
COAUTH_HILOGE(MODULE_SERVICE, "executorId does not exist.");
COAUTH_HILOGE(MODULE_SERVICE, "executorId does not exist");
return FAIL;
}
for (std::size_t i = 0; i < executorNum; i++) {
@@ -135,7 +138,7 @@ int32_t CoAuthManager::Cancel(uint64_t scheduleId)
COAUTH_HILOGD(MODULE_SERVICE, "get exeID = %{public}u", authType);
int32_t onceRet = coAuthResMgrPtr_->FindExecutorCallback(authType, executorCallback);
if ((onceRet != 0) || (executorCallback == nullptr)) {
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found.");
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found");
continue;
}
auto commandAttrs = std::make_shared<ResAuthAttributes>();
@@ -149,12 +152,12 @@ int32_t CoAuthManager::Cancel(uint64_t scheduleId)
}
}
if (executeRet != SUCCESS) {
COAUTH_HILOGW(MODULE_SERVICE, "There are one or more failures when canceling.");
COAUTH_HILOGW(MODULE_SERVICE, "there are one or more failures when canceling");
return executeRet;
}
int32_t deleteRet = DeleteScheduleInfo(scheduleId, scheduleInfo); // call TA
if (deleteRet != SUCCESS) {
COAUTH_HILOGW(MODULE_SERVICE, "Delete schedule info failed. ret = %{public}d", deleteRet);
COAUTH_HILOGW(MODULE_SERVICE, "delete schedule info failed, ret = %{public}d", deleteRet);
}
return executeRet;
}
@@ -180,7 +183,7 @@ void CoAuthManager::SetExecutorProp(ResAuthAttributes &conditions, sptr<ISetProp
COAUTH_HILOGD(MODULE_SERVICE, "get authType = XXXX%{public}u", authType);
coAuthResMgrPtr_->FindExecutorCallback(authType, execallback);
if (execallback == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found.");
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found");
return callback->OnResult(result, extraInfo);
}
std::vector<uint8_t> buffer;
@@ -189,7 +192,7 @@ void CoAuthManager::SetExecutorProp(ResAuthAttributes &conditions, sptr<ISetProp
properties->Unpack(buffer);
result = static_cast<uint32_t>(execallback->OnSetProperty(properties));
if (result != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "set properties failure");
COAUTH_HILOGE(MODULE_SERVICE, "set properties failed");
}
callback->OnResult(result, extraInfo);
}
@@ -203,20 +206,20 @@ int32_t CoAuthManager::GetExecutorProp(ResAuthAttributes &conditions, std::share
COAUTH_HILOGD(MODULE_SERVICE, "authType is %{public}u", authType);
coAuthResMgrPtr_->FindExecutorCallback(authType, execallback);
if (execallback == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found.");
COAUTH_HILOGE(MODULE_SERVICE, "executor callback not found");
return FAIL;
}
std::vector<uint8_t> buffer;
std::shared_ptr<ResAuthAttributes> properties = std::make_shared<ResAuthAttributes>();
if (properties == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "properties is null.");
COAUTH_HILOGE(MODULE_SERVICE, "properties is nullptr");
return FAIL;
}
conditions.Pack(buffer);
properties->Unpack(buffer);
retCode = execallback->OnGetProperty(properties, values);
if (retCode != SUCCESS) {
COAUTH_HILOGE(MODULE_SERVICE, "get properties failure");
COAUTH_HILOGE(MODULE_SERVICE, "get properties failed");
}
COAUTH_HILOGI(MODULE_SERVICE, "get properties end");
return retCode;
@@ -235,11 +238,10 @@ CoAuthManager::ResICoAuthCallbackDeathRecipient::ResICoAuthCallbackDeathRecipien
void CoAuthManager::ResICoAuthCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
if (remote == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "CoAuthCallback OnRemoteDied failed, remote is nullptr");
COAUTH_HILOGE(MODULE_SERVICE, "remote is nullptr");
return;
}
if (parent_ != nullptr) {
if (parent_ != nullptr && parent_->coAuthResMgrPtr_ != nullptr) {
parent_->coAuthResMgrPtr_->DeleteScheduleCallback(scheduleId);
}
COAUTH_HILOGW(MODULE_SERVICE, "ResICoAuthCallbackDeathRecipient::Recv death notice.");
@@ -248,16 +250,20 @@ void CoAuthManager::ResICoAuthCallbackDeathRecipient::OnRemoteDied(const wptr<IR
void CoAuthManager::TimeOut(uint64_t scheduleId)
{
sptr<UserIAM::CoAuth::ICoAuthCallback> callback;
int32_t findRet = coAuthResMgrPtr_->FindScheduleCallback(scheduleId, callback);
if (findRet == SUCCESS && callback != nullptr) {
std::vector<uint8_t> scheduleToken;
callback->OnFinish(TIMEOUT, scheduleToken);
Cancel(scheduleId); // cancel schedule
COAUTH_HILOGW(MODULE_SERVICE, "Schedule timeout");
coAuthResMgrPtr_->DeleteScheduleCallback(scheduleId);
} else {
COAUTH_HILOGD(MODULE_SERVICE, "Schedule has ended");
if (coAuthResMgrPtr_ == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "coAuthResMgrPtr_ is nullptr");
return;
}
int32_t findRet = coAuthResMgrPtr_->FindScheduleCallback(scheduleId, callback);
if (findRet != SUCCESS || callback == nullptr) {
COAUTH_HILOGD(MODULE_SERVICE, "Schedule has ended");
return;
}
std::vector<uint8_t> scheduleToken;
callback->OnFinish(TIMEOUT, scheduleToken);
Cancel(scheduleId);
COAUTH_HILOGW(MODULE_SERVICE, "Schedule timeout");
coAuthResMgrPtr_->DeleteScheduleCallback(scheduleId);
}
} // namespace CoAuth
} // namespace UserIAM
+4 -4
View File
@@ -30,7 +30,7 @@ int32_t CoAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
std::u16string descripter = CoAuthStub::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
if (descripter != remoteDescripter) {
COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub::OnRemoteRequest failed, descriptor is not matched!");
COAUTH_HILOGE(MODULE_SERVICE, "descriptor is not matched");
return E_GET_POWER_SERVICE_FAILED;
}
@@ -136,7 +136,7 @@ int32_t CoAuthStub::BeginScheduleStub(MessageParcel& data, MessageParcel& reply)
int32_t CoAuthStub::CancelStub(MessageParcel& data, MessageParcel& reply)
{
COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub: CancelStub enter");
COAUTH_HILOGI(MODULE_SERVICE, "CoAuthStub: CancelStub start");
uint64_t scheduleId = data.ReadUint64();
COAUTH_HILOGD(MODULE_SERVICE, "ReadUint64 scheduleId:%{public}" PRIu64, scheduleId);
@@ -151,7 +151,7 @@ int32_t CoAuthStub::CancelStub(MessageParcel& data, MessageParcel& reply)
int32_t CoAuthStub::GetExecutorPropStub(MessageParcel& data, MessageParcel& reply)
{
COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub: GetExecutorPropStub enter");
COAUTH_HILOGI(MODULE_SERVICE, "CoAuthStub: GetExecutorPropStub start");
std::vector<uint8_t> buffer;
AuthResPool::AuthAttributes conditions;
data.ReadUInt8Vector(&buffer);
@@ -179,7 +179,7 @@ int32_t CoAuthStub::GetExecutorPropStub(MessageParcel& data, MessageParcel& repl
int32_t CoAuthStub::SetExecutorPropStub(MessageParcel& data, MessageParcel& reply)
{
COAUTH_HILOGD(MODULE_SERVICE, "CoAuthStub: SetExecutorPropStub enter");
COAUTH_HILOGI(MODULE_SERVICE, "CoAuthStub: SetExecutorPropStub start");
std::vector<uint8_t> buffer;
std::shared_ptr<AuthResPool::AuthAttributes> conditions = std::make_shared<AuthResPool::AuthAttributes>();
+1 -1
View File
@@ -18,7 +18,7 @@
namespace OHOS {
namespace UserIAM {
namespace CoAuth {
const int32_t COAUTH_THREAD_NUM = 20;
constexpr int32_t COAUTH_THREAD_NUM = 20;
std::mutex CoAuthThreadPool::mutex_;
std::shared_ptr<CoAuthThreadPool> CoAuthThreadPool::instance_ = nullptr;
CoAuthThreadPool::CoAuthThreadPool()
+24 -23
View File
@@ -32,29 +32,30 @@ int32_t ExecutorMessenger::SendData(uint64_t scheduleId, uint64_t transNum, int3
if (ScheResPool_ == nullptr || msg == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "ScheResPool_ or msg is nullptr");
return FAIL;
} else {
sptr<UserIAM::CoAuth::ICoAuthCallback> callback;
int32_t findRet = ScheResPool_->FindScheduleCallback(scheduleId, callback);
if (findRet == SUCCESS && callback != nullptr) {
std::vector<uint8_t> message;
msg->FromUint8Array(message);
if (message.size() != sizeof(uint32_t)) {
COAUTH_HILOGE(MODULE_SERVICE, "message size not right");
return FAIL;
}
// trans to acquireCode
uint32_t acquire = 0;
if (memcpy_s(&acquire, sizeof(uint32_t), message.data(), message.size()) != EOK) {
COAUTH_HILOGE(MODULE_SERVICE, "message copy not right");
return FAIL;
}
callback->OnAcquireInfo(acquire);
COAUTH_HILOGD(MODULE_SERVICE, "feedback acquire info");
} else {
COAUTH_HILOGE(MODULE_SERVICE, "ScheduleCallback not find");
}
}
sptr<UserIAM::CoAuth::ICoAuthCallback> callback;
int32_t findRet = ScheResPool_->FindScheduleCallback(scheduleId, callback);
if (findRet != SUCCESS || callback == nullptr) {
COAUTH_HILOGE(MODULE_SERVICE, "ScheduleCallback not find");
return FAIL;
}
std::vector<uint8_t> message;
msg->FromUint8Array(message);
if (message.size() != sizeof(uint32_t)) {
COAUTH_HILOGE(MODULE_SERVICE, "message size not right");
return FAIL;
}
// trans to acquireCode
uint32_t acquire = 0;
if (memcpy_s(&acquire, sizeof(uint32_t), message.data(), message.size()) != EOK) {
COAUTH_HILOGE(MODULE_SERVICE, "message copy not right");
return FAIL;
}
callback->OnAcquireInfo(acquire);
COAUTH_HILOGD(MODULE_SERVICE, "feedback acquire info");
return SUCCESS;
}
@@ -110,7 +111,7 @@ int32_t ExecutorMessenger::Finish(uint64_t scheduleId, int32_t srcType, int32_t
int32_t findRet = ScheResPool_->FindScheduleCallback(scheduleId, callback);
if (findRet != SUCCESS || callback == nullptr) {
DeleteScheduleInfoById(scheduleId);
COAUTH_HILOGE(MODULE_SERVICE, "get schedule callback fail");
COAUTH_HILOGE(MODULE_SERVICE, "get schedule callback failed");
return FAIL;
}
std::vector<uint8_t> scheduleToken;